Use param instead of global for entry
[clawsker.git] / clawsker
index 497b42aed8277b3de5b3fee6c9db7c93de865cf3..1903211138bf9686c540fc380d06bf0f34909b72 100755 (executable)
--- a/clawsker
+++ b/clawsker
@@ -386,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;
 }
@@ -442,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});
@@ -468,7 +464,7 @@ sub new_text_box_for_int {
     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 //= $type[1];
+    $value //= $$hash{$key}[CMDEF];
     $gentry->set_numeric (TRUE);
     $gentry->set_value ($value);
     $$hash{$key}[GUI] = $gentry;
@@ -485,8 +481,8 @@ sub new_text_box_for_int {
     return $hbox;
 }
 
-sub new_text_box_for_nchar {
-    my ($hash, $key) = @_;
+sub new_text_box_for_nchar($$$) {
+    my ($hash, $key, $vhash) = @_;
     my $name = $$hash{$key}[NAME];
     my $label = $$hash{$key}[LABEL];
     my @type = split (/,/, $$hash{$key}[TYPE]); # char,minlen,maxlen
@@ -495,11 +491,13 @@ 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 = $$vhash{$name};
+    $value //= $$hash{$key}[CMDEF];
+    $gentry->set_text ($value);
     $$hash{$key}[GUI] = $gentry;
     $gentry->signal_connect('key-release-event' => sub {
             my ($w, $e) = @_;
-            handle_nchar_value ($w, $e, \$HPVALUE{$name}, $type[1]);
+            handle_nchar_value ($w, $e, \$$vhash{$name}, $type[1]);
         });
     set_widget_hint ($gentry, $$hash{$key}[DESC]);
     set_widget_sens ($gentry, $$hash{$key}[CMVER]);
@@ -515,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);
@@ -553,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);
@@ -843,7 +845,7 @@ sub new_gui_page() {
 
     my $cb_dot_lines = new_check_button_for (\%pr::gui, 'dot_lines');
     my $cb_toolbar_d = new_check_button_for (\%pr::gui, 'toolbar_d');
-    my $tb_zero_char = new_text_box_for_nchar (\%pr::gui, 'zero_char');
+    my $tb_zero_char = new_text_box_for_nchar (\%pr::gui, 'zero_char', \%HPVALUE);
 
     $gf->pack_start (new_subpage_frame (
                          new_vbox_pack (