Author: bdonlan
Date: 2004-07-05 22:57:03 -0400 (Mon, 05 Jul 2004)
New Revision: 303

Added:
   trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ServerEditDialog.pm
   trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ServerSelectDialog.pm
Removed:
   trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ServerDialog.pm
Modified:
   trunk/clients/haver-gtk/bin/serverdlg-test.pl
Log:
* haver-gtk/lib/Haver/UI/Gtk/ServerDialog.pm,
  haver-gtk/lib/Haver/UI/Gtk/ServerSelectDialog.pm,
  haver-gtk/lib/Haver/UI/Gtk/ServerEditDialog.pm
  
  Split ServerDialog into ServerSelectDialog and ServerEditDialog, and redid
  much of the UI.

* haver-gtk/bin/serverdlg-test.pl
  
  Update to use ServerSelectDialog instead of ServerDialog


Modified: trunk/clients/haver-gtk/bin/serverdlg-test.pl
===================================================================
--- trunk/clients/haver-gtk/bin/serverdlg-test.pl       2004-07-06 01:19:15 UTC 
(rev 302)
+++ trunk/clients/haver-gtk/bin/serverdlg-test.pl       2004-07-06 02:57:03 UTC 
(rev 303)
@@ -25,7 +25,7 @@
 use POE;
 use Haver::Config;
 use Haver::OS;
-use Haver::UI::Gtk::ServerDialog;
+use Haver::UI::Gtk::ServerSelectDialog;
 
 my ($user, $confdir, $config);
 
@@ -72,7 +72,7 @@
        $heap->{killbtn}->show;
        $heap->{toplevel}->show;
        $heap->{killbtn}->signal_connect("clicked", $session->postback("kill"));
-       $heap->{serverdlg} = new Haver::UI::Gtk::ServerDialog($session, 
$config);
+       $heap->{serverdlg} = new Haver::UI::Gtk::ServerSelectDialog($session, 
$config);
 }
 
 sub connectwin_connect {

Deleted: trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ServerDialog.pm
===================================================================
--- trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ServerDialog.pm    2004-07-06 
01:19:15 UTC (rev 302)
+++ trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ServerDialog.pm    2004-07-06 
02:57:03 UTC (rev 303)
@@ -1,244 +0,0 @@
-# vim: set ft=perl ts=4 sw=4:
-# Haver::UI::Gtk::ServerDialog - server connect window   
-# 
-# Copyright (C) 2004 Bryan Donlan, Dylan William Hardison.
-# 
-# This module is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This module is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this module; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-package Haver::UI::Gtk::ServerDialog;
-use strict;
-use warnings;
-
-use constant {
-       FALSE => 0,
-       TRUE => 1,
-};
-
-use Gtk;
-use Data::Dumper;
-#use POE; 
-
-sub new {
-       my ($class, $parent, $config) = @_;
-       $class = ref $class || $class;
-       my $self = {
-               close_callback => $parent->postback('connectwin_close'),
-               connect_callback => $parent->postback('connectwin_connect'),
-               config => $config,
-       };
-       bless $self, $class;
-
-       $self->{window} = new Gtk::Window();
-       $self->{window}->set_title("Connect to server");
-       
-       $self->{outer_box} = new Gtk::HBox(FALSE, 5);
-       $self->{window}->add(fixpad($self->{outer_box}, 5));
-       
-       $self->{editbox} = $self->mkedit();
-       $self->{slistbox} = $self->mkslist();
-       $self->{slistbox}->show;
-       $self->{editbox}->show;
-
-       # XXX: slidable?
-#      $self->{outer_box}->pack_start($self->{editbox}, FALSE, FALSE, 0);
-#      $self->{outer_box}->pack_start($self->{slist}, TRUE, TRUE, 0);
-
-       $self->{editframe} = new Gtk::Frame('Server configuration');
-       $self->{editframe}->add(fixpad($self->{editbox}, 5));
-       $self->{editframe}->show;
-       
-       $self->{listframe} = new Gtk::Frame('Server list');
-       $self->{listframe}->add(fixpad($self->{slistbox}, 5));
-       $self->{listframe}->show;
-
-       $self->{outer_box}->pack_start($self->{editframe}, FALSE, FALSE, 0);
-       $self->{outer_box}->pack_start($self->{listframe}, TRUE, TRUE, 0);
-       
-       $self->{outer_box}->show;
-
-       $self->populate();
-       
-       $self->{window}->show;
-       $self->{window}->signal_connect('delete_event', sub { delete 
$self->{window}; $self->destroy(); });
-       
-       return $self;
-}
-
-sub mkedit {
-       my $self = shift;
-       my @fieldlist = qw(UID Address Password);
-       my $fields = $self->{fields} = {};
-
-       $fields->{outer_box} = new Gtk::VBox(FALSE, 0);
-       
-       $fields->{table} = new Gtk::Table(scalar @fieldlist + 1, 0, FALSE);
-       $fields->{outer_box}->pack_start($fields->{table}, FALSE, FALSE, 0);
-       my $i;
-       for ($i = 0; $i < @fieldlist; $i++) {
-               my $field = $fieldlist[$i];
-               my $label = new Gtk::Label("$field: ");
-               my $input = new Gtk::Entry();
-
-               # This dosen't work:
-#              $label->set_justify('right');
-
-               my $hacky_box = new Gtk::HBox(FALSE, 0);
-               $hacky_box->pack_end($label, FALSE, FALSE, 0);
-               $hacky_box->show;
-               
-               $fields->{$field} = $input;
-               $fields->{table}->attach(
-                       $hacky_box,     # $child
-                       0,                      # $left_attach
-                       1,                      # $right_attach
-                       $i,                     # $top_attach
-                       $i + 1,         # $bottom_attach
-                       [qw(fill shrink expand)],       # $xoptions
-                       [qw(fill shrink expand)],       # $yoptions
-                       0,                      # $xpadding
-                       0,                      # $ypadding
-               );
-               $label->show;
-               $fields->{table}->attach(
-                       $input,         # $child
-                       1,                      # $left_attach
-                       2,                      # $right_attach
-                       $i,                     # $top_attach
-                       $i + 1,         # $bottom_attach
-                       [qw(fill shrink expand)],       # $xoptions
-                       [qw(fill shrink expand)],       # $yoptions
-                       0,                      # $xpadding
-                       0,                      # $ypadding
-               );
-               $input->show;
-       }
-
-       $fields->{Password}->set_visibility(FALSE);
-
-       $fields->{savepass} = new Gtk::CheckButton('Save Password');
-       $fields->{table}->attach(
-                       $fields->{savepass},            # $child
-                       0,                                                      
# $left_attach
-                       2,                                                      
# $right_attach
-                       $i,                                                     
# $top_attach
-                       $i + 1,                                         # 
$bottom_attach
-                       [qw(fill shrink expand)],       # $xoptions
-                       [qw(fill shrink expand)],       # $yoptions
-                       0,                                                      
# $xpadding
-                       0,                                                      
# $ypadding
-               );
-       $fields->{savepass}->show;
-
-       $fields->{table}->show;
-
-       $fields->{btn_box} = new Gtk::HBox(TRUE, 0);
-       $fields->{outer_box}->pack_end($fields->{btn_box}, FALSE, FALSE, 0);
-       $fields->{btn_box}->show;
-       
-       $fields->{btn_connect} = new Gtk::Button('Connect');
-       $fields->{btn_box}->pack_start($fields->{btn_connect}, TRUE, TRUE, 0);
-       $fields->{btn_connect}->show; 
-       $fields->{btn_connect}->signal_connect('clicked', sub { 
$self->btn_connect(); });
-       
-       $fields->{btn_close} = new Gtk::Button('Close');
-       $fields->{btn_box}->pack_start($fields->{btn_close}, TRUE, TRUE, 0);
-       $fields->{btn_close}->show; 
-       $fields->{btn_close}->signal_connect('clicked', sub { 
$self->btn_close(); });
-       
-       return $fields->{outer_box};
-}
-
-sub mkslist {
-       my $self = shift;
-       my $slist = $self->{slist} = {};
-
-       $slist->{outer_box} = new Gtk::VBox(FALSE, 0);
-
-       $slist->{top_box} = new Gtk::HBox(FALSE, 0);
-       $slist->{outer_box}->pack_start($slist->{top_box}, FALSE, FALSE, 0);
-       $slist->{top_box}->show;
-       
-       $slist->{sname} = new Gtk::Entry();
-       $slist->{top_box}->pack_start($slist->{sname}, TRUE, TRUE, 0);
-       $slist->{sname}->show;
-       
-       $slist->{btn_add} = new Gtk::Button("Add");
-       $slist->{top_box}->pack_start($slist->{btn_add}, FALSE, FALSE, 0);
-       $slist->{btn_add}->show;
-       $slist->{btn_add}->signal_connect("clicked", sub { 
$self->slist_btn_add(); });
-       
-       $slist->{btn_del} = new Gtk::Button("Del");
-       $slist->{top_box}->pack_start($slist->{btn_del}, FALSE, FALSE, 0);
-       $slist->{btn_del}->show;
-       $slist->{btn_del}->signal_connect("clicked", sub { 
$self->slist_btn_del(); });
-
-       $slist->{list} = new Gtk::List();
-       $slist->{list}->set_selection_mode('single');
-       $slist->{list}->show;
-       $slist->{list}->signal_connect('selection_changed', sub { 
$self->slist_select(); });
-
-       $slist->{sw} = new Gtk::ScrolledWindow(undef, undef);
-       $slist->{sw}->set_usize(250, 150); # XXX
-       $slist->{sw}->add_with_viewport($slist->{list});
-       $slist->{sw}->show;
-       
-       $slist->{outer_box}->pack_start($slist->{sw}, TRUE, TRUE, 0);
-       # TODO: signal
-       
-       return $slist->{outer_box};
-}
-
-sub fixpad {
-       my ($object, $pad) = @_;
-       my $vbox = new Gtk::VBox(FALSE, 0);
-       my $hbox = new Gtk::HBox(FALSE, 0);
-       $hbox->pack_start($object, TRUE, TRUE, $pad);
-       $vbox->pack_start($hbox, TRUE, TRUE, $pad);
-       $hbox->show;
-       $vbox->show;
-       return $vbox;
-}
-
-sub populate {
-       my $self = shift;
-       $self->{servers} = [sort keys %{$self->{config}{Servers}}];
-       
-       $self->{slist}{list}->clear_items(0, -1);
-       for (@{$self->{servers}}) {
-               my $item = new Gtk::ListItem($_);
-               $item->show;
-               $self->{slist}{list}->add($item);
-       }
-}
-
-sub slist_btn_add {}
-sub slist_btn_del {}
-sub slist_select  {}
-sub btn_connect   {}
-sub btn_close     {
-       my $self = shift;
-       $self->destroy();
-}
-
-sub destroy {
-       my $self = shift;
-       $self->{close_callback}();
-       $self->{window}->destroy() if $self->{window};
-       # Break circular references between signal closures and $self. This 
might
-       # not be needed, but better safe than sorry.
-       %$self = ();
-}
-
-1;

Copied: trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ServerEditDialog.pm (from rev 
302, trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ServerDialog.pm)
===================================================================
--- trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ServerDialog.pm    2004-07-06 
01:19:15 UTC (rev 302)
+++ trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ServerEditDialog.pm        
2004-07-06 02:57:03 UTC (rev 303)
@@ -0,0 +1,211 @@
+# vim: set ft=perl ts=4 sw=4:
+# Haver::UI::Gtk::ServerDialog - server connect window   
+# 
+# Copyright (C) 2004 Bryan Donlan, Dylan William Hardison.
+# 
+# This module is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This module is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this module; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+package Haver::UI::Gtk::ServerEditDialog;
+use strict;
+use warnings;
+
+use constant {
+       FALSE => 0,
+       TRUE => 1,
+};
+
+use Gtk;
+use Data::Dumper;
+#use POE; 
+
+my @fieldlist = qw(Name UID Address Password);
+
+sub new {
+       my ($class, $parent, $config) = @_;
+       $class = ref $class || $class;
+       my $self = {
+               parent => $parent,
+               config => $config,
+       };
+       bless $self, $class;
+
+       $self->{window} = new Gtk::Dialog();
+       if (defined $config->{Name}) {
+               $self->{window}->set_title("Editing server ".$config->{Name});
+       } else {
+               $self->{window}->set_title("New server");
+       }
+       $self->{window}->set_modal(TRUE);
+       
+       $self->{editbox} = $self->mkedit();
+       $self->{editbox}->show;
+
+       $self->{window}->vbox->pack_start(fixpad($self->{editbox}, 5), TRUE, 
TRUE, 0);
+
+       for my $btn_name (qw(OK Cancel)) {
+               $self->{"btn_$btn_name"} = new Gtk::Button($btn_name);
+               
$self->{window}->action_area->pack_start($self->{"btn_$btn_name"}, TRUE, TRUE, 
0);
+               $self->{"btn_$btn_name"}->show;
+               $self->{"btn_$btn_name"}->signal_connect("clicked",
+                       sub {
+                               no strict 'refs';
+                               # Hack?
+                               &{"btn_$btn_name"}($self);
+                       }
+               );
+       }
+       
+       $self->load;
+       $self->{window}->show;
+       $self->{window}->signal_connect('delete_event', sub { delete 
$self->{window}; $self->destroy(); });
+       
+       return $self;
+}
+
+sub mkedit {
+       my $self = shift;
+       my $fields = $self->{fields} = {};
+       
+       $fields->{table} = new Gtk::Table(scalar @fieldlist + 1, 0, FALSE);
+
+       my $i;
+       for ($i = 0; $i < @fieldlist; $i++) {
+               my $field = $fieldlist[$i];
+               my $label = new Gtk::Label("$field: ");
+               my $input = new Gtk::Entry();
+
+               # This dosen't work:
+#              $label->set_justify('right');
+
+               my $hacky_box = new Gtk::HBox(FALSE, 0);
+               $hacky_box->pack_end($label, FALSE, FALSE, 0);
+               $hacky_box->show;
+               
+               $fields->{$field} = $input;
+               $fields->{table}->attach(
+                       $hacky_box,     # $child
+                       0,                      # $left_attach
+                       1,                      # $right_attach
+                       $i,                     # $top_attach
+                       $i + 1,         # $bottom_attach
+                       [qw(fill shrink expand)],       # $xoptions
+                       [qw(fill shrink expand)],       # $yoptions
+                       0,                      # $xpadding
+                       0,                      # $ypadding
+               );
+               $label->show;
+               $fields->{table}->attach(
+                       $input,         # $child
+                       1,                      # $left_attach
+                       2,                      # $right_attach
+                       $i,                     # $top_attach
+                       $i + 1,         # $bottom_attach
+                       [qw(fill shrink expand)],       # $xoptions
+                       [qw(fill shrink expand)],       # $yoptions
+                       0,                      # $xpadding
+                       0,                      # $ypadding
+               );
+               $input->show;
+       }
+
+       $fields->{Password}->set_visibility(FALSE);
+
+       $fields->{savepass} = new Gtk::CheckButton('Save Password');
+
+       $fields->{table}->attach(
+                       $fields->{savepass},            # $child
+                       0,                                                      
# $left_attach
+                       2,                                                      
# $right_attach
+                       $i,                                                     
# $top_attach
+                       $i + 1,                                         # 
$bottom_attach
+                       [qw(fill shrink expand)],       # $xoptions
+                       [qw(fill shrink expand)],       # $yoptions
+                       0,                                                      
# $xpadding
+                       0,                                                      
# $ypadding
+               );
+       $fields->{savepass}->show;
+
+       $fields->{table}->show;
+
+       return $fields->{table};
+}
+
+sub fixpad {
+       my ($object, $pad) = @_;
+       my $vbox = new Gtk::VBox(FALSE, 0);
+       my $hbox = new Gtk::HBox(FALSE, 0);
+       $hbox->pack_start($object, TRUE, TRUE, $pad);
+       $vbox->pack_start($hbox, TRUE, TRUE, $pad);
+       $hbox->show;
+       $vbox->show;
+       return $vbox;
+}
+
+sub load {
+       my $self = shift;
+       my $fields = $self->{fields};
+       for (@fieldlist) {
+               my $d = $self->{config}{$_};
+               $d = '' unless defined $d;
+               $fields->{$_}->set_text($d);
+       }
+       if (!defined $self->{config}{Password}) {
+               $fields->{savepass}->set_active(FALSE);
+               $self->pass_enable(FALSE);
+       } else {
+               $fields->{savepass}->set_active(TRUE);
+               $self->pass_enable(TRUE);
+       }
+}
+
+sub pass_enable {
+       my $self = shift;
+       my $enable = shift;
+       my $pass = $self->{fields}{Password};
+       $pass->set_editable($enable);
+       # TODO: change bg color for disabled
+}
+
+sub save {
+       my $self = shift;
+       my $fields = $self->{fields};
+       my $savepass = $fields->{savepass}->get_active();
+       for (@fieldlist) {
+               $self->{config}{$_} = $fields->{$_}->get_text();
+       }
+       delete $self->{config}{Password} unless $savepass;
+}
+
+sub btn_OK {
+       my $self = shift;
+       $self->save;
+       $self->{parent}->server_save($self->{config});
+}
+
+sub btn_Cancel {
+       my $self = shift;
+       $self->destroy;
+}
+
+sub destroy {
+       my $self = shift;
+       $self->{parent}->edit_done();
+       $self->{window}->destroy() if $self->{window};
+       # Break circular references between signal closures and $self. This 
might
+       # not be needed, but better safe than sorry.
+       %$self = ();
+}
+
+1;

Copied: trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ServerSelectDialog.pm (from 
rev 302, trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ServerDialog.pm)
===================================================================
--- trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ServerDialog.pm    2004-07-06 
01:19:15 UTC (rev 302)
+++ trunk/clients/haver-gtk/lib/Haver/UI/Gtk/ServerSelectDialog.pm      
2004-07-06 02:57:03 UTC (rev 303)
@@ -0,0 +1,262 @@
+# vim: set ft=perl ts=4 sw=4:
+# Haver::UI::Gtk::ServerSelectDialog - server selection window   
+# 
+# Copyright (C) 2004 Bryan Donlan, Dylan William Hardison.
+# 
+# This module is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This module is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this module; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+package Haver::UI::Gtk::ServerSelectDialog;
+use strict;
+use warnings;
+
+use constant {
+       FALSE => 0,
+       TRUE => 1,
+};
+
+use Gtk;
+use Haver::UI::Gtk::ServerEditDialog;
+#use POE; 
+
+sub new {
+       my ($class, $parent, $config) = @_;
+       $class = ref $class || $class;
+       my $self = {
+               close_callback => $parent->postback('connectwin_close'),
+               connect_callback => $parent->postback('connectwin_connect'),
+               config => $config,
+               servers => $config->{Servers},
+       };
+       bless $self, $class;
+
+       $self->{window} = new Gtk::Window();
+       $self->{window}->set_title("Connect to server");
+       
+       $self->{slistbox} = $self->mkslist();
+       $self->{slistbox}->show;
+
+       $self->populate();
+
+       $self->{window}->add(fixpad($self->{slistbox}, 5));
+       $self->{window}->show;
+       $self->{window}->signal_connect('delete_event', sub { delete 
$self->{window}; $self->destroy(); });
+       
+       return $self;
+}
+
+sub mkslist {
+       my $self = shift;
+       my $slist = $self->{slist} = {};
+
+       $slist->{outer_box} = new Gtk::VBox(FALSE, 0);
+
+       $slist->{list} = new Gtk::List();
+       $slist->{list}->set_selection_mode('single');
+       $slist->{list}->show;
+
+       $slist->{sw} = new Gtk::ScrolledWindow(undef, undef);
+       $slist->{sw}->set_usize(250, 150); # XXX
+       $slist->{sw}->add_with_viewport($slist->{list});
+       $slist->{sw}->show;
+       
+       $slist->{outer_box}->pack_start($slist->{sw}, TRUE, TRUE, 0);
+
+       $slist->{btn_box} = new Gtk::HBox(FALSE, 0);
+       $slist->{outer_box}->pack_start($slist->{btn_box}, FALSE, FALSE, 0);
+
+       for my $btn_name (qw(Connect New Edit Delete Close)) {
+               $slist->{"btn_$btn_name"} = new Gtk::Button($btn_name);
+               $slist->{btn_box}->pack_start($slist->{"btn_$btn_name"}, TRUE, 
TRUE, 0);
+               $slist->{"btn_$btn_name"}->show;
+               $slist->{"btn_$btn_name"}->signal_connect("clicked",
+                       sub {
+                               no strict 'refs';
+                               # Hack?
+                               &{"btn_$btn_name"}($self);
+                       }
+               );
+       }
+       
+       $slist->{btn_box}->show;
+       
+       return $slist->{outer_box};
+}
+
+sub fixpad {
+       my ($object, $pad) = @_;
+       my $vbox = new Gtk::VBox(FALSE, 0);
+       my $hbox = new Gtk::HBox(FALSE, 0);
+       $hbox->pack_start($object, TRUE, TRUE, $pad);
+       $vbox->pack_start($hbox, TRUE, TRUE, $pad);
+       $hbox->show;
+       $vbox->show;
+       return $vbox;
+}
+
+sub populate {
+       my $self = shift;
+       my @servers = sort keys %{$self->{servers}};
+       $self->{sitemref} = {};
+       $self->{sitemname} = {};
+       $self->{slist}{list}->clear_items(0, -1);
+       for (my $i = 0; $i < @servers; $i++) {
+               my $server = $servers[$i];
+               my $item = new Gtk::ListItem($server);
+               my $struct = [$server, $item, $i];
+               $item->show;
+               $self->{slist}{list}->add($item);
+               $self->{sitemref}{$item} = $struct;
+               $self->{sitemname}{$server} = $struct;
+       }
+}
+
+sub set_server {
+       my ($self, $config) = @_;
+       my $newconfig = {};
+       for (qw(UID Address Password)) {
+               $newconfig->{$_} = $config->{$_} if defined $config->{$_};
+       }
+       $self->{servers}{$config->{Name}} = $newconfig;
+}
+
+sub select_server {
+       my ($self, $server) = @_;
+       my @selected = $self->{slist}{list}->selection;
+       for (@selected) {
+               $_->deselect;
+       }
+       $self->{sitemname}{$server}[1]->select;
+}
+
+sub get_selected {
+       my $self = shift;
+       my @selected = $self->{slist}{list}->selection;
+       return undef unless @selected;
+       my $item = $selected[0];
+       my $sname = $self->{sitemref}{$item}[0];
+       return $sname;
+}
+
+sub btn_Connect                {
+       my $self = shift;
+       my $server = $self->get_selected;
+       $server or return;
+       $self->{connect_callback}($self->{servers}{$server});
+       $self->destroy;
+}
+
+sub btn_New                    {
+       my $self = shift;
+       $self->{editdlg} = new Haver::UI::Gtk::ServerEditDialog($self, {});
+}
+
+sub btn_Edit           {
+       my $self = shift;
+       my $server = $self->get_selected or return;
+       my $config = {
+               %{$self->{servers}{$server}},
+               Oldname => $server,
+               Name => $server,
+       };
+       $self->{editdlg} = new Haver::UI::Gtk::ServerEditDialog($self, $config);
+}
+
+sub btn_Delete         {
+       my $self = shift;
+       my $server = $self->get_selected or return;
+       delete $self->{servers}{$server};
+       $self->populate;
+}
+
+sub btn_Close          {
+       my $self = shift;
+       $self->destroy;
+}
+
+sub destroy {
+       my $self = shift;
+       $self->{close_callback}();
+       $self->{window}->destroy() if $self->{window};
+       # Break circular references between signal closures and $self. This 
might
+       # not be needed, but better safe than sorry.
+       %$self = ();
+}
+
+sub server_save {
+       my ($self, $config) = @_;
+       return if ($config->{Name} eq '');
+       if (!exists($config->{Oldname}) or $config->{Name} ne 
$config->{Oldname}) {
+               if (exists $self->{servers}{$config->{Name}}) {
+                       my $confirm = new Gtk::Dialog();
+
+                       $confirm->set_title('Confirm replace');
+                       $confirm->set_modal(TRUE);
+
+                       my $message = new Gtk::Label('Are you sure you want to 
replace server "' . $config->{Name} . '"?');
+
+                       my $yes = new Gtk::Button('Yes');
+                       my $no = new Gtk::Button('No');
+
+                       my $bb = new Gtk::HButtonBox();
+                       $bb->set_layout_default('end');
+                       $bb->set_spacing_default(10);
+
+                       $confirm->vbox->pack_start(fixpad($message, 20), TRUE, 
FALSE, 0);
+                       #       $confirm->action_area->pack_end($yes, FALSE, 
FALSE, 0);
+                       #       $confirm->action_area->pack_end($no, FALSE, 
FALSE, 0);
+                       $bb->add($yes);
+                       $bb->add($no);
+                       $confirm->action_area->pack_start($bb, TRUE, TRUE, 0);
+
+                       $yes->signal_connect('clicked',
+                               sub {
+                                       delete 
$self->{servers}{$config->{Name}};
+                                       $self->server_save($config);
+                                       $confirm->destroy;
+                                       undef $confirm; # Break possible 
circular ref
+                               }
+                       );
+
+                       $no->signal_connect('clicked',
+                               sub {
+                                       $confirm->destroy;
+                                       undef $confirm;
+                               }
+                       );
+
+                       $message->show;
+                       $yes->show;
+                       $no->show;
+                       $bb->show;
+                       $confirm->show;
+
+                       return;
+               }
+               delete $self->{servers}{$config->{Oldname}} if defined 
$config->{Oldname};
+               $self->set_server($config);
+               $self->populate;
+       } else {
+               $self->set_server($config);
+       }
+       $self->select_server($config->{Name});
+       $self->{editdlg}->destroy;
+}
+
+sub edit_done {
+       my $self = shift;
+       delete $self->{editdlg};
+}
+
+1;


Reply via email to