Enable parsing menurc
[clawsker.git] / clawsker
index 13a0d993d858d709e456c885758a8d39b6a5a6ee..57356352cec6bd3f61c93dd2eed452f608b67109 100755 (executable)
--- a/clawsker
+++ b/clawsker
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 #
 # Clawsker :: A Claws Mail Tweaker
-# Copyright 2007-2016 Ricardo Mones <ricardo@mones.org>
+# Copyright 2007-2017 Ricardo Mones <ricardo@mones.org>
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -95,9 +95,11 @@ sub _ {
 
     l_oth_use_dlg => _('Use detached address book edit dialogue'),
     h_oth_use_dlg => _('If true use a separate dialogue to edit a person\'s details. Otherwise will use a form embedded in the address book\'s main window.'),
-    l_oth_max_use => _('Maximum memory for message cache (kB)'),
+    l_oth_max_use => _('Maximum memory for message cache'),
+    l_oth_max_use_units => _('kilobytes'),
     h_oth_max_use => _('The maximum amount of memory to use to cache messages, in kilobytes.'),
-    l_oth_min_time => _('Minimun time for cache elements (minutes)'),
+    l_oth_min_time => _('Minimun time for cache elements'),
+    l_oth_min_time_units => _('minutes'),
     h_oth_min_time => _('The minimum time in minutes to keep a cache in memory. Caches more recent than this time will not be freed, even if the memory usage is too high.'),
     l_oth_use_netm => _('Use NetworkManager'),
     h_oth_use_netm => _('Use NetworkManager to switch offline automatically.'),
@@ -145,13 +147,13 @@ sub _ {
     l_gui_type_any => _('Editable headers'),
     h_gui_type_any => _('Allows to manually type any value in Compose Window header entries or just select from the available choices in the associated dropdown list.'),
     l_gui_warn_send_multi => _('Warn when sending to more than'),
-    h_gui_warn_send_multi => _('Warn when sending to multiple recipients.'),
-    l_gui_warn_send_multi_threshold => _('recipients'),
-    h_gui_warn_send_multi_threshold => _('Warn when sending to multiple recipients.'),
+    l_gui_warn_send_multi_units => _('recipients'),
+    h_gui_warn_send_multi => _('Show a warning dialogue when sending to more recipients than specified. Use 0 to disable this check.'),
     l_gui_next_del => _('Select next message on delete'),
     h_gui_next_del => _('When deleting a message, toggles between selecting the next one (newer message) or the previous one (older message).'),
 
-    l_beh_hover_t => _('Drag \'n\' drop hover timeout (ms)'),
+    l_beh_hover_t => _('Drag \'n\' drop hover timeout'),
+    l_beh_hover_t_units => _('milliseconds'),
     h_beh_hover_t => _('Time in milliseconds that will cause a folder tree to expand when the mouse cursor is held over it during drag and drop.'),
     l_beh_dangerous => _('Don\'t confirm deletions (dangerous!)'),
     h_beh_dangerous => _('Don\'t ask for confirmation before definitive deletion of emails.'),
@@ -161,9 +163,11 @@ sub _ {
     h_beh_parts_rw => _('Saves temporary files when opening attachment with write bit set.'),
     l_beh_skip_ssl => _('Don\'t check SSL certificates'),
     h_beh_skip_ssl => _('Disables the verification of SSL certificates.'),
-    l_beh_up_step => _('Progress bar update step (items)'),
+    l_beh_up_step => _('Progress bar update step every'),
+    l_beh_up_step_units => _('items'),
     h_beh_up_step => _('Update stepping in progress bars.'),
-    l_beh_thread_a => _('Maximum age when threading by subject (days)'),
+    l_beh_thread_a => _('Maximum age when threading by subject'),
+    l_beh_thread_a_units => _('days'),
     h_beh_thread_a => _('Number of days to include a message in a thread when using "Thread using subject in addition to standard headers".'),
     l_beh_unsafe_ssl => _('Allow unsafe SSL certificates'),
     h_beh_unsafe_ssl => _('Allows Claws Mail to remember multiple SSL certificates for a given server/port.'),
@@ -296,6 +300,8 @@ use constant PAGE_SPC => 5;
 
 sub version_greater_or_equal {
     my ($version, $refvers) = @_;
+    return TRUE if (length($version) == 0 and length($refvers) >= 0);
+    return FALSE if (length($version) >= 0 and length($refvers) == 0);
     return TRUE if (version->parse($version) >= version->parse($refvers));
     return FALSE;
 }
@@ -395,6 +401,10 @@ sub get_ac_rc_filename {
     return $CONFIGDIR . $ACCOUNTRC;
 }
 
+sub get_menurc_filename {
+    return $CONFIGDIR . "menurc";
+}
+
 sub set_rc_filename {
     my ($fullname) = @_;
     my @parts = split ('/', $fullname);
@@ -511,6 +521,11 @@ sub new_text_box_for_int($$$) {
     my @type = split (/,/, $$hash{$key}[TYPE]);
     push (@type, 0), push (@type, 10000) unless ($#type > 0);
     #
+    my $gunits = undef;
+    if (ref $label eq 'ARRAY') {
+        $gunits = Gtk2::Label->new ($label->[1]);
+        $label = $label->[0];
+    }
     my $glabel = Gtk2::Label->new ($label);
     my $pagei = int (($type[2] - $type[1]) / 10);
     my $gentry = Gtk2::SpinButton->new_with_range ($type[1], $type[2], $pagei);
@@ -525,57 +540,12 @@ sub new_text_box_for_int($$$) {
     set_widget_hint ($gentry, $$hash{$key}[DESC]);
     set_widget_sens ($gentry, $$hash{$key}[CMVER]);
     $glabel->set_sensitive ($gentry->sensitive);
+    $gunits->set_sensitive ($gentry->sensitive) if ($gunits);
     #
+    return new_hbox_spaced_pack ($glabel, $gentry, $gunits) if ($gunits);
     return new_hbox_spaced_pack ($glabel, $gentry);
 }
 
-sub check_button_and_text_box_update_sens($$$) {
-    my ($cb, $gentry, $glabel) = @_;
-    $gentry->set_sensitive ($cb->get_active);
-    $glabel->set_sensitive ($cb->get_active);
-}
-
-sub new_check_button_and_text_box_for_int($$$$) {
-    my ($hash, $key, $key2, $vhash) = @_;
-    my $name = $$hash{$key}[NAME];
-    my $label = $$hash{$key}[LABEL];
-    #
-    my $cb = Gtk2::CheckButton->new ($label);
-    my $value = $$vhash{$name};
-    $value //= $$hash{$key}[CMDEF];
-    $cb->set_active ($value eq '1');
-    set_widget_hint ($cb, $$hash{$key}[DESC]);
-    set_widget_sens ($cb, $$hash{$key}[CMVER]);
-       #
-    my $name2 = $$hash{$key2}[NAME];
-    my $label2 = $$hash{$key2}[LABEL];
-    my @type = split (/,/, $$hash{$key2}[TYPE]);
-    push (@type, 0), push (@type, 10000) unless ($#type > 0);
-    #
-    my $pagei = int (($type[2] - $type[1]) / 10);
-    my $gentry = Gtk2::SpinButton->new_with_range ($type[1], $type[2], $pagei);
-    my $value2 = $$vhash{$name2};
-    my $glabel = Gtk2::Label->new ($label2);
-    $value2 //= $$hash{$key2}[CMDEF];
-    $gentry->set_numeric (TRUE);
-    $gentry->set_value ($value2);
-    $gentry->signal_connect('value-changed' => sub {
-            my ($w, $e) = @_;
-            handle_int_value ($w, $e, \$$vhash{$name});
-        });
-    set_widget_hint ($gentry, $$hash{$key2}[DESC]);
-    set_widget_sens ($gentry, $$hash{$key2}[CMVER]);
-       check_button_and_text_box_update_sens($cb, $gentry, $glabel);
-    #
-    $cb->signal_connect ('clicked' => sub {
-                   my ($w, $e) = @_;
-            handle_bool_value ($w, $e, \$$vhash{$name});
-                       check_button_and_text_box_update_sens($w, $gentry, $glabel);
-       });
-       #
-    return new_hbox_spaced_pack ($cb, $gentry, $glabel);
-}
-
 sub new_text_box_for_nchar($$$) {
     my ($hash, $key, $vhash) = @_;
     my $name = $$hash{$key}[NAME];
@@ -709,7 +679,7 @@ sub new_subpage_frame {
     ],
     max_use => [
         'cache_max_mem_usage',
-        $xl::s{l_oth_max_use},
+        [ $xl::s{l_oth_max_use}, $xl::s{l_oth_max_use_units} ],
         $xl::s{h_oth_max_use},
         'int,0,262144', # 0 Kb - 256 Mb
         '0.7.8.36',
@@ -717,7 +687,7 @@ sub new_subpage_frame {
     ],
     min_time => [
         'cache_min_keep_time',
-        $xl::s{l_oth_min_time},
+        [ $xl::s{l_oth_min_time}, $xl::s{l_oth_min_time_units} ],
         $xl::s{h_oth_min_time},
         'int,0,120', # 0 minutes - 2 hours
         '0.7.8.36',
@@ -901,20 +871,12 @@ sub new_other_page() {
         '0',
     ],
     warn_send_multi => [
-        'warn_sending_many_recipients',
-        $xl::s{l_gui_warn_send_multi},
-        $xl::s{l_gui_warn_send_multi},
-        'bool',
-        '3.14.1.125',
-        '0',
-    ],
-    warn_send_multi_threshold => [
         'warn_sending_many_recipients_num',
-        $xl::s{l_gui_warn_send_multi_threshold},
-        $xl::s{l_gui_warn_send_multi_threshold},
-        'int,1,1000',
+        [ $xl::s{l_gui_warn_send_multi}, $xl::s{l_gui_warn_send_multi_units} ],
+        $xl::s{h_gui_warn_send_multi},
+        'int,0,1000',
         '3.14.1.125',
-        '2',
+        '0',
     ],
     next_del => [
         'next_on_delete',
@@ -957,11 +919,12 @@ sub new_gui_page() {
                          $xl::s{mview_frame}, 'not-packed'),
                      FALSE, FALSE, FRAME_SPC);
     $gf->pack_start (new_subpage_frame (
-                         new_hbox_pack (
-                             new_check_button_for (\%pr::gui, 'no_markup', \%HPVALUE),
-                             new_check_button_for (\%pr::gui, 'margin_co', \%HPVALUE),
-                             new_check_button_for (\%pr::gui, 'type_any', \%HPVALUE),
-                             new_check_button_and_text_box_for_int (\%pr::gui, 'warn_send_multi', 'warn_send_multi_threshold', \%HPVALUE)),
+                         new_vbox_pack (
+                             new_hbox_pack_compact (
+                                 new_check_button_for (\%pr::gui, 'no_markup', \%HPVALUE),
+                                 new_check_button_for (\%pr::gui, 'margin_co', \%HPVALUE),
+                                 new_check_button_for (\%pr::gui, 'type_any', \%HPVALUE)),
+                             new_text_box_for_int (\%pr::gui, 'warn_send_multi', \%HPVALUE)),
                          $xl::s{compo_frame}, 'not-packed'),
                      FALSE, FALSE, FRAME_SPC);
     $gf->pack_start ($cb_dot_lines, FALSE, FALSE, 0);
@@ -980,7 +943,7 @@ sub new_gui_page() {
 %pr::beh = ( # tweak some behaviour
     hover_t => [
         'hover_timeout',
-        $xl::s{l_beh_hover_t},
+        [ $xl::s{l_beh_hover_t}, $xl::s{l_beh_hover_t_units} ],
         $xl::s{h_beh_hover_t},
         'int,100,3000', # 0.1 seconds - 3 seconds
         '0.0.0',
@@ -1020,7 +983,7 @@ sub new_gui_page() {
     ],
     up_step => [
         'statusbar_update_step',
-        $xl::s{l_beh_up_step},
+        [ $xl::s{l_beh_up_step}, $xl::s{l_beh_up_step_units} ],
         $xl::s{h_beh_up_step},
         'int,1,200', # 1 item - 200 items
         '0.0.0',
@@ -1028,7 +991,7 @@ sub new_gui_page() {
     ],
     thread_a => [
         'thread_by_subject_max_age',
-        $xl::s{l_beh_thread_a},
+        [ $xl::s{l_beh_thread_a}, $xl::s{l_beh_thread_a_units} ],
         $xl::s{h_beh_thread_a},
         'int,1,30', # 1 day - 30 days
         '0.0.0',
@@ -2403,6 +2366,31 @@ sub save_resource {
     close (RCF);
 }
 
+# specific loaders
+sub load_menurc {
+    my $rc = shift;
+    open (RCF, '<:encoding(utf8)', $rc)
+        or die _("Error: opening '{file}' for reading", file => $rc) . ": $!\n";
+    my %groups = ();
+    my $line = 0;
+    while (<RCF>) {
+        chomp;
+        ++$line;
+        if (/^; \(gtk_accel_path "<([A-Za-z]+)>([^"]+)" ([^\)]+)\)$/) {
+            my %data = ('key' => $3, 'enabled' => FALSE);
+            $groups{$1}{$2} = \%data;
+            # say "group -> $1 | path -> $2 | key -> $3";
+        }
+        if (/^\(gtk_accel_path "<([A-Za-z]+)>([^"]+)" ([^\)]+)\)$/) {
+            my %data = ('key' => $3, 'enabled' => TRUE);
+            $groups{$1}{$2} = \%data;
+            # say "group -> $1 | path -> $2 | key -> $3";
+        }
+    }
+    close (RCF);
+    return \%groups;
+}
+
 # load current status from disc
 sub load_rc_preferences {
     my $rc = get_rc_filename ();
@@ -2522,7 +2510,7 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.";
-    my $year = "2007-2016";
+    my $year = "2007-2017";
     my $holder = "Ricardo Mones &lt;ricardo\@mones.org&gt;";
     my $url = "http://www.claws-mail.org/clawsker.php";