Use default value for missing preferences
[clawsker.git] / clawsker
index 5b20714bcc9bbf7650c56409670a86275123df2d..efc7a6837efecc1b3c99930d47322100122607f5 100755 (executable)
--- a/clawsker
+++ b/clawsker
@@ -1,7 +1,7 @@
 #!/usr/bin/perl -w
 #
 # Clawsker :: A Claws Mail Tweaker
-# Copyright 2007-2014 Ricardo Mones <ricardo@mones.org>
+# Copyright 2007-2016 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
@@ -14,6 +14,7 @@
 
 binmode STDOUT, ":encoding(utf8)";
 
+use 5.010_000;
 use strict;
 use utf8;
 use Glib qw(TRUE FALSE);
@@ -27,6 +28,7 @@ use Getopt::Long;
 my $NAME = 'clawsker';
 my $PREFIX = '@PREFIX@';
 my $LIBDIR = '@LIBDIR@';
+my $DATADIR = '@DATADIR@';
 my $VERSION = '@VERSION@';
 my $VERBOSE = FALSE;
 my $CLAWSV = undef;
@@ -82,6 +84,7 @@ sub _ {
     compo_frame => _('Compose window'),
     netm_frame => _('NetworkManager'),
     diff_frame => _('Viewing patches'),
+    mpass_frame => _('Master passphrase'),
 
     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.'),
@@ -91,10 +94,12 @@ sub _ {
     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.'),
+    l_oth_mp_rounds => _('Rounds for PBKDF2 function'),
+    h_oth_mp_rounds => _('Specify the number of iterations the key derivation function will be applied on master passphrase computation. Does not modify currently stored passphrase, only master passphrases computed after changing this value are affected.'),
     
     l_gui_b_unread => _('Show unread messages with bold font'),
     h_gui_b_unread => _('Show unread messages in the Message List using a bold font.'),
-    l_gui_no_markup => _('Don\'t use markup in compose window'),
+    l_gui_no_markup => _('Don\'t use markup'),
     h_gui_no_markup => _('Don\'t use bold and italic text in Compose dialogue\'s account selector.'),
     l_gui_dot_lines => _('Use dotted lines in tree view components'),
     h_gui_dot_lines => _('Use the old dotted line look in the main window tree views (Folder, Message and other lists) instead of the modern lineless look.'),
@@ -108,7 +113,7 @@ sub _ {
     l_gui_v_scroll_auto => _('Automatic'),
     l_gui_v_scroll_hide => _('Hide always'),
     l_gui_from_show => _('From column displays'),
-    h_gui_from_show => _('Selects the data displayed in the From column of the Message List: name, address or both'),
+    h_gui_from_show => _('Selects the data displayed in the From column of the Message List: name, address or both.'),
     l_gui_from_show_name => _('Name only'),
     l_gui_from_show_addr => _('Address only'),
     l_gui_from_show_both => _('Both name and address'),
@@ -124,12 +129,16 @@ sub _ {
     h_gui_strip_sum => _('Enable alternately coloured lines in Message List and Folder List.'),
     l_gui_two_line_v => _('2 lines per Message List item in 3-column layout'),
     h_gui_two_line_v => _('Spread Message List information over two lines when using the three column mode.'),
-    l_gui_margin_co => _('Show compose margin'),
+    l_gui_margin_co => _('Show margin'),
     h_gui_margin_co => _('Shows a small margin in the Compose View.'),
     l_gui_mview_date => _('Don\'t display localized date'),
-    h_gui_mview_date => _('Toggles localization of date format in Message View'),
+    h_gui_mview_date => _('Toggles localization of date format in Message View.'),
     l_gui_zero_char => _('Zero replacement character'),
-    h_gui_zero_char => _('Replaces \'0\' with the given character in Folder List'),
+    h_gui_zero_char => _('Replaces \'0\' with the given character in Folder List.'),
+    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_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)'),
     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.'),
@@ -156,11 +165,11 @@ sub _ {
     l_beh_pp_unsel => _('Primary paste unselects selection'),
     h_beh_pp_unsel => _('Controls how pasting using middle-click changes the selected text and insertion point.'),
     l_beh_inline_at => _('Show inline attachments'),
-    h_beh_inline_at => _('Allows hiding inline attachments already shown in mail structure view'),
+    h_beh_inline_at => _('Allows hiding inline attachments already shown in mail structure view.'),
     l_beh_addr_swc => _('Address search in compose window matches any'),
-    h_beh_addr_swc => _('On Tab-key completion, address text will match any part of the string or only the from the start'),
+    h_beh_addr_swc => _('On Tab-key completion, address text will match any part of the string or only from the start.'),
     l_beh_fold_swc => _('Folder search in folder selector matches any'),
-    h_beh_fold_swc => _('On folder name completion text will match any part of the string or only from the start'),
+    h_beh_fold_swc => _('On folder name completion text will match any part of the string or only from the start.'),
 
     l_col_emphasis => _('X-Mailer header'),
     h_col_emphasis => _('The colour used for the X-Mailer line when its value is Claws Mail.'),
@@ -261,7 +270,7 @@ sub get_claws_version {
     my @ver = split (/\./, $fver[3]);
     $res .= "$ver[0].";
     $res .= "$ver[1].";
-    if ($ver[2] =~ /(\d+)cvs(\d+)/) {
+    if ($ver[2] =~ /(\d+)git(\d+)/) {
         $res .= "$1.$2";
     }
     else {
@@ -377,16 +386,12 @@ sub claws_is_running {
 sub check_claws_not_running {
     my $tmpdir = (defined $ENV{TMPDIR})? $ENV{TMPDIR}: '/tmp';
     $tmpdir = '/tmp' if ($tmpdir eq '');
-    my $socket = (not $ALTCONFIGDIR)? $tmpdir: $CONFIGDIR;
-    $socket .= "/claws-mail-$<";
-    -S $socket and return claws_is_running ();
-    # since 3.9.0cvs36
     my $lockdir = "$tmpdir/claws-mail-$<";
     -d $lockdir and do { 
-       $_ = $CONFIGDIR;
-       s/\/$//;
-        $socket = "$lockdir/" . md5_hex ($_);
-       -S $socket and return claws_is_running ();
+        $_ = $CONFIGDIR;
+        s/\/$//;
+        my $socket = "$lockdir/" . md5_hex ($_);
+        -S $socket and return claws_is_running ();
     };
     return TRUE;
 }
@@ -433,9 +438,9 @@ sub new_check_button_for {
     my $hbox = Gtk2::HBox->new (FALSE, 5);
     my $cb = Gtk2::CheckButton->new ($label);
     $$hash{$key}[GUI] = $cb;
-    if (defined ($HPVALUE{$name})) {
-        $cb->set_active ($HPVALUE{$name} eq '1');
-    }
+    my $value = $HPVALUE{$name};
+    $value //= $$hash{$key}[CMDEF];
+    $cb->set_active ($value eq '1');
     $cb->signal_connect (clicked => sub {
             my ($w, $e) = @_;
             handle_bool_value ($w, $e, \$HPVALUE{$name});
@@ -458,8 +463,10 @@ sub new_text_box_for_int {
     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);
+    my $value = $HPVALUE{$name};
+    $value //= $$hash{$key}[CMDEF];
     $gentry->set_numeric (TRUE);
-    $gentry->set_value ($HPVALUE{$name});
+    $gentry->set_value ($value);
     $$hash{$key}[GUI] = $gentry;
     $gentry->signal_connect('value-changed' => sub {
             my ($w, $e) = @_;
@@ -484,7 +491,9 @@ sub new_text_box_for_nchar {
     my $gentry = Gtk2::Entry->new ();
     $gentry->set_max_length($type[2]) if defined ($type[2]);
     $gentry->set_width_chars(int ($type[2]) + 2) if defined ($type[2]);
-    $gentry->set_text ($HPVALUE{$name});
+    my $value = $HPVALUE{$name};
+    $value //= $$hash{$key}[CMDEF];
+    $gentry->set_text ($value);
     $$hash{$key}[GUI] = $gentry;
     $gentry->signal_connect('key-release-event' => sub {
             my ($w, $e) = @_;
@@ -504,7 +513,9 @@ sub new_color_button_for {
     my $name = $$hash{$key}[NAME];
     my $label = $$hash{$key}[LABEL];
     #
-    my $col = gdk_color_from_str ($HPVALUE{$name});
+    my $value = $HPVALUE{$name};
+    $value //= $$hash{$key}[CMDEF];
+    my $col = gdk_color_from_str ($value);
     my $hbox = Gtk2::HBox->new (FALSE, 5);
     my $glabel = Gtk2::Label->new ($label);
     my $button = Gtk2::ColorButton->new_with_color ($col);
@@ -542,7 +553,9 @@ sub new_selection_box_for {
             my ($w, $e) = @_;
             handle_selection_value ($w, $e, \$HPVALUE{$name});
         });
-    $combo->set_active ($HPVALUE{$name});
+    my $value = $HPVALUE{$name};
+    $value //= $$hash{$key}[CMDEF];
+    $combo->set_active ($value);
     set_widget_hint ($combo, $$hash{$key}[DESC]);
     set_widget_sens ($combo, $$hash{$key}[CMVER]);
     $glabel->set_sensitive ($combo->sensitive);
@@ -628,6 +641,15 @@ sub new_subpage_frame {
         '1',
         undef,
     ],
+    mp_rounds => [
+        'master_passphrase_pbkdf2_rounds',
+        $xl::s{l_oth_mp_rounds},
+        $xl::s{h_oth_mp_rounds},
+        'int,50000,1000000',
+        '3.13.2.110',
+        '50000',
+        undef,
+    ],
 );
 
 sub new_other_page() {
@@ -644,7 +666,11 @@ sub new_other_page() {
                new_subpage_frame (
                    new_vbox_pack (
                        new_check_button_for(\%pr::oth, 'use_netm')),
-                   $xl::s{netm_frame}, 'not-packed')
+                   $xl::s{netm_frame}, 'not-packed'),
+               new_subpage_frame (
+                   new_vbox_pack (
+                       new_text_box_for_int(\%pr::oth, 'mp_rounds')),
+                   $xl::s{mpass_frame}, 'not-packed')
            );
 }
 
@@ -793,6 +819,24 @@ sub new_other_page() {
         '0',
         undef,
     ],
+    type_any => [
+        'type_any_header',
+        $xl::s{l_gui_type_any},
+        $xl::s{h_gui_type_any},
+        'bool',
+        '3.12.0.44',
+        '0',
+        undef,
+    ],
+    next_del => [
+        'next_on_delete',
+        $xl::s{l_gui_next_del},
+        $xl::s{h_gui_next_del},
+        'bool',
+        '3.13.0.5',
+        '0',
+        undef,
+    ],
 );
 
 sub new_gui_page() {
@@ -815,6 +859,7 @@ sub new_gui_page() {
                              new_check_button_for (\%pr::gui, 'b_unread'),
                              new_check_button_for (\%pr::gui, 'swp_from'),
                              new_check_button_for (\%pr::gui, 'two_linev'),
+                             new_check_button_for (\%pr::gui, 'next_del'),
                              new_selection_box_for (\%pr::gui, 'from_show')),
                          $xl::s{mlist_frame}, 'not-packed'), 
                      FALSE, FALSE, FRAME_SPC);
@@ -827,7 +872,8 @@ sub new_gui_page() {
     $gf->pack_start (new_subpage_frame (
                          new_hbox_pack (
                              new_check_button_for (\%pr::gui, 'no_markup'),
-                             new_check_button_for (\%pr::gui, 'margin_co')),
+                             new_check_button_for (\%pr::gui, 'margin_co'),
+                             new_check_button_for (\%pr::gui, 'type_any')),
                          $xl::s{compo_frame}, 'not-packed'), 
                      FALSE, FALSE, FRAME_SPC);
     $gf->pack_start ($cb_dot_lines, FALSE, FALSE, 0);
@@ -964,7 +1010,7 @@ sub new_gui_page() {
     addr_swc => [
         'address_search_wildcard',
         $xl::s{l_beh_addr_swc},
-        $xl::s{h_beh_addr_sw1},
+        $xl::s{h_beh_addr_swc},
         'bool',
         '3.9.3.18',
         '0',
@@ -973,7 +1019,7 @@ sub new_gui_page() {
     fold_swc => [
         'folder_search_wildcard',
         $xl::s{l_beh_fold_swc},
-        $xl::s{h_beh_fold_sw1},
+        $xl::s{h_beh_fold_swc},
         'bool',
         '3.9.3.18',
         '0',
@@ -1934,7 +1980,7 @@ sub opt_alternate_config_dir {
 
 sub opt_clawsrc {
     my ($name, $value) = @_;
-    die _("Error: '{value}' is not a file or does not exist", value => $value)
+    die _("Error: '{value}' is not a file or does not exist\n", value => $value)
         unless -f $value;
     set_rc_filename ($value);
 }
@@ -2027,7 +2073,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-2014";
+    my $year = "2007-2016";
     my $holder = "Ricardo Mones &lt;ricardo\@mones.org&gt;";
     my $url = "http://www.claws-mail.org/clawsker.php";
 
@@ -2068,6 +2114,20 @@ sub new_button_box {
     return $hbox;
 }
 
+sub get_app_icons {
+    my $dir = $DATADIR . '/icons/hicolor';
+    my @names = map {
+      join ('/', ($dir, , $_ . 'x' . $_, 'apps', $NAME . '.png'))
+    } (64, 128);
+    my @icons = ();
+    foreach (@names) {
+        my $icon = undef;
+        $icon = Gtk2::Gdk::Pixbuf->new_from_file($_) if (-f $_);
+        push @icons, $icon if ($icon);
+    }
+    return @icons;
+}
+
 # initialise
 exit unless parse_command_line ();
 Gtk2->init;
@@ -2082,6 +2142,7 @@ $box->pack_start (new_notebook (), FALSE, FALSE, 0);
 $box->pack_end (new_button_box ($main_window, $about), FALSE, FALSE, 0);
 $main_window->signal_connect (delete_event => sub { Gtk2->main_quit });
 $main_window->set_title ($xl::s{win_title});
+$main_window->set_icon_list (get_app_icons ());
 $main_window->add ($box);
 $main_window->show_all;
 Gtk2->main;