Use File::Which for searching binary
[clawsker.git] / clawsker
index 8949d35d6fe9de248680d6105e24d2b9fbdcf85e..6c256b3477bd1d7352604f5160d8efd11ad919b7 100755 (executable)
--- a/clawsker
+++ b/clawsker
@@ -20,6 +20,7 @@ use utf8;
 use version 0.77;
 use Glib qw(TRUE FALSE);
 use Gtk3;
+use File::Which;
 use POSIX qw(setlocale);
 use Locale::gettext;
 use Encode;
@@ -66,16 +67,6 @@ sub _ {
     exit_fact => _('There are unapplied modifications.'),
     exit_question => _('Do you really want to quit?'),
 
-    tab_colours => _('Colours'),
-    tab_behaviour => _('Behaviour'),
-    tab_gui => _('GUI'),
-    tab_other => _('Other'),
-    tab_winpos => _('Windows'),
-    tab_accounts => _('Accounts'),
-    tab_plugins => _('Plugins'),
-    tab_hotkeys => _('Hotkeys'),
-    tab_info => _('Info'),
-
     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'),
@@ -271,23 +262,28 @@ my @APPICONS = ();
 # modification flag
 my $MODIFIED = 0;
 
-# index constants for preference arrays
-use constant NAME  => 0; # the name on the rc file
-use constant LABEL => 1; # the label on the GUI
-use constant DESC  => 2; # the description for the hint/help
-use constant TYPE  => 3; # data type: bool, int, float, string, color
-use constant CMVER => 4; # lowest[,highest] Claws Mail version(s) the feature exists
-use constant CMDEF => 5; # default value for the preference in Claws Mail
-use constant PLUGIN => 6; # plugin section (only in plugin preferences)
-
-# constants for GUI spacing
-use constant HBOX_PAD => 5;
-use constant FRAME_SPC => 2;
-use constant PAGE_SPC => 5;
-
-# for data references indexing
-use constant VALUE => 0;
-use constant IVALUE => 1;
+use constant {
+    # index constants for preference arrays
+    NAME  => 0, # the name on the rc file
+    LABEL => 1, # the label on the GUI
+    DESC  => 2, # the description for the hint/help
+    TYPE  => 3, # data type: bool, int, float, string, color
+    CMVER => 4, # lowest[,highest] Claws Mail version(s) the feature exists
+    CMDEF => 5, # default value for the preference in Claws Mail
+    PLUGIN => 6, # plugin section (only in plugin preferences)
+    # constants for GUI spacing
+    HBOX_PAD => 5,
+    GRID_SPC => 10,
+    # for data references indexing
+    VALUE => 0,
+    IVALUE => 1,
+    # hotkey list store columns
+    C_LABEL => 0,
+    C_HOTKEY => 1,
+    C_GROUP => 2,
+    C_ACCEL => 3,
+    C_ODDITY => 4,
+};
 
 # version functions
 
@@ -300,9 +296,8 @@ sub version_greater_or_equal {
 }
 
 sub get_claws_version {
-    $_ = qx/which claws-mail/;
-    chomp;
-    return "" unless ($_); # not installed
+    $_ = which ('claws-mail');
+    return "" unless defined $_; # not installed
     my $res = "";
     $_ = qx/$_ -v/;
     chomp;
@@ -345,13 +340,6 @@ sub handle_int_value {
         if defined $$dataref->[IVALUE];
 }
 
-sub handle_string_value {
-    my ($widget, $event, $dataref) = @_;
-    $$dataref->[VALUE] = $widget->get_text ();
-    $MODIFIED += $$dataref->[VALUE] ne $$dataref->[IVALUE]? 1: -1
-        if defined $$dataref->[IVALUE];
-}
-
 sub handle_nchar_value {
     my ($widget, $event, $dataref, $minlen, $maxlen) = @_;
     $_ = substr ($widget->get_text (), 0, $maxlen);
@@ -651,55 +639,11 @@ sub new_selection_box_for($$$) {
 
 # more graphic helpers
 
-sub new_hbox_pack {
-    my $hbox = Gtk3::HBox->new (FALSE);
-    $hbox->set_border_width (PAGE_SPC);
-    foreach (@_) {
-        $hbox->pack_start ($_, FALSE, FALSE, 0);
-    }
-    return $hbox;
-}
-
-sub new_hbox_pack_compact {
-    my $hbox = Gtk3::HBox->new (FALSE);
-    $hbox->set_border_width (0);
-    foreach (@_) {
-        $hbox->pack_start ($_, FALSE, FALSE, 0);
-    }
-    return $hbox;
-}
-
-sub new_vbox_pack {
-    my $vbox = Gtk3::VBox->new (FALSE, 5);
-    $vbox->set_border_width (PAGE_SPC);
-    foreach (@_) {
-        $vbox->pack_start ($_, FALSE, FALSE, 0);
-    }
-    return $vbox;
-}
-
-sub new_vbox_pack_compact {
-    my $vbox = Gtk3::VBox->new (FALSE, 0);
-    $vbox->set_border_width (0);
-    foreach (@_) {
-        $vbox->pack_start ($_, FALSE, FALSE, 0);
-    }
-    return $vbox;
-}
-
-sub new_subpage_frame {
-    my ($box, $title, $notpacked) = @_;
-    my $frame = Gtk3::Frame->new ($title);
-    $frame->add ($box);
-    return new_vbox_pack ($frame) unless defined ($notpacked);
-    return $frame;
-}
-
 sub new_grid {
     my ($border_w, $row_s, $col_s) = @_;
-    $border_w //= 10;
-    $row_s //= 10;
-    $col_s //= 10;
+    $border_w //= GRID_SPC;
+    $row_s //= GRID_SPC;
+    $col_s //= GRID_SPC;
     my $grid = Gtk3::Grid->new;
     $grid->set_border_width ($border_w);
     $grid->set_row_spacing ($row_s);
@@ -1973,26 +1917,16 @@ sub new_winpos_subpage_misc() {
 sub new_winpos_page() {
     my $winbook = Gtk3::Notebook->new;
     $winbook->set_tab_pos ('right');
-    $winbook->append_page (new_winpos_subpage_main,
-        Gtk3::Label->new (_('Main')));
-    $winbook->append_page (new_winpos_subpage_msgs,
-        Gtk3::Label->new (_('Message')));
-    $winbook->append_page (new_winpos_subpage_sendrecv,
-        Gtk3::Label->new (_('Send/Receive')));
-    $winbook->append_page (new_winpos_subpage_fold,
-        Gtk3::Label->new (_('Folder')));
-    $winbook->append_page (new_winpos_subpage_addrbook,
-        Gtk3::Label->new (_('Addressbook')));
-    $winbook->append_page (new_winpos_subpage_accounts,
-        Gtk3::Label->new (_('Accounts')));
-    $winbook->append_page (new_winpos_subpage_filtering,
-        Gtk3::Label->new (_('Filtering')));
-    $winbook->append_page (new_winpos_subpage_useractions,
-        Gtk3::Label->new (_('User Actions')));
-    $winbook->append_page (new_winpos_subpage_prefs,
-        Gtk3::Label->new (_('Preferences')));
-    $winbook->append_page (new_winpos_subpage_misc,
-        Gtk3::Label->new (_('Other')));
+    $winbook->append_page (&new_winpos_subpage_main, new_label (_('Main')));
+    $winbook->append_page (&new_winpos_subpage_msgs, new_label (_('Message')));
+    $winbook->append_page (&new_winpos_subpage_sendrecv, new_label (_('Send/Receive')));
+    $winbook->append_page (&new_winpos_subpage_fold, new_label (_('Folder')));
+    $winbook->append_page (&new_winpos_subpage_addrbook, new_label (_('Addressbook')));
+    $winbook->append_page (&new_winpos_subpage_accounts, new_label (_('Accounts')));
+    $winbook->append_page (&new_winpos_subpage_filtering, new_label (_('Filtering')));
+    $winbook->append_page (&new_winpos_subpage_useractions, new_label (_('User Actions')));
+    $winbook->append_page (&new_winpos_subpage_prefs, new_label (_('Preferences')));
+    $winbook->append_page (&new_winpos_subpage_misc, new_label (_('Other')));
     return $winbook;
 }
 
@@ -2147,14 +2081,6 @@ sub new_plugins_page() {
     ]);
 }
 
-use constant {
-    C_LABEL => 0,
-    C_HOTKEY => 1,
-    C_GROUP => 2,
-    C_ACCEL => 3,
-    C_ODDITY => 4,
-};
-
 sub new_hotkeys_list_label {
     my $renderer = Gtk3::CellRendererText->new ();
     $renderer->set_property('alignment' => 'left');
@@ -2669,25 +2595,16 @@ sub save_preferences {
 # create notebook
 sub new_notebook {
     my $nb = Gtk3::Notebook->new;
-    #
-    $nb->append_page (new_behaviour_page (),
-        Gtk3::Label->new ($xl::s{tab_behaviour}));
-    $nb->append_page (new_colours_page (),
-        Gtk3::Label->new ($xl::s{tab_colours}));
-    $nb->append_page (new_gui_page (),
-        Gtk3::Label->new ($xl::s{tab_gui}));
-    $nb->append_page (new_other_page (),
-        Gtk3::Label->new ($xl::s{tab_other}));
-    $nb->append_page (new_winpos_page (),
-        Gtk3::Label->new ($xl::s{tab_winpos}));
-    $nb->append_page (new_accounts_page (),
-        Gtk3::Label->new ($xl::s{tab_accounts}));
-    $nb->append_page (new_plugins_page (),
-        Gtk3::Label->new ($xl::s{tab_plugins}));
-    $nb->append_page (new_hotkeys_page (),
-        Gtk3::Label->new ($xl::s{tab_hotkeys}));
-    $nb->append_page (new_info_page (),
-        Gtk3::Label->new ($xl::s{tab_info}));
+
+    $nb->append_page (&new_behaviour_page, Gtk3::Label->new (_('Behaviour')));
+    $nb->append_page (&new_colours_page, Gtk3::Label->new (_('Colours')));
+    $nb->append_page (&new_gui_page, Gtk3::Label->new (_('GUI')));
+    $nb->append_page (&new_other_page, Gtk3::Label->new (_('Other')));
+    $nb->append_page (&new_winpos_page, Gtk3::Label->new (_('Windows')));
+    $nb->append_page (&new_accounts_page, Gtk3::Label->new (_('Accounts')));
+    $nb->append_page (&new_plugins_page, Gtk3::Label->new (_('Plugins')));
+    $nb->append_page (&new_hotkeys_page, Gtk3::Label->new (_('Hotkeys')));
+    $nb->append_page (&new_info_page, Gtk3::Label->new (_('Info')));
 
     return $nb;
 }