Author: bdonlan
Date: 2004-07-05 23:27:03 -0400 (Mon, 05 Jul 2004)
New Revision: 305

Removed:
   trunk/clients/haver-gtk/bin/serverdlg-test.pl
Modified:
   trunk/clients/haver-gtk/TODO
   trunk/clients/haver-gtk/bin/haver-gtk.pl
Log:
* TODO: updated todo list

* haver-gtk.pl: Integrated new server select dialog

* serverdlg-test.pl: removed as it is no longer needed


Modified: trunk/clients/haver-gtk/TODO
===================================================================
--- trunk/clients/haver-gtk/TODO        2004-07-06 03:22:15 UTC (rev 304)
+++ trunk/clients/haver-gtk/TODO        2004-07-06 03:27:03 UTC (rev 305)
@@ -1,9 +1,11 @@
 TODO:
+* Validation in server editing dialog
+* Framework for confirmation dialogs?
+* Password prompt dialog
 * Compositing command parser
 * Hilight active tabs
 * Move cmd_* and haver_* to separate files
 * Pages.pm should not care about page names
-* Server list
 * Preferences
 * Timestamps
 * Logging

Modified: trunk/clients/haver-gtk/bin/haver-gtk.pl
===================================================================
--- trunk/clients/haver-gtk/bin/haver-gtk.pl    2004-07-06 03:22:15 UTC (rev 
304)
+++ trunk/clients/haver-gtk/bin/haver-gtk.pl    2004-07-06 03:27:03 UTC (rev 
305)
@@ -30,8 +30,8 @@
 # For data needed by page handlers as well as main code
 our %globals;
 
-#sub POE::Kernel::ASSERT_DEFAULT {1}
-#sub POE::Kernel::TRACE_DEFAULT {1}
+#sub POE::Kernel::ASSERT_DEFAULT {TRUE}
+#sub POE::Kernel::TRACE_DEFAULT {TRUE}
 
 use Haver::Preprocessor '-assert', '-debug', '-verbose';
 use Gtk;
@@ -48,6 +48,7 @@
 use Haver::UI::Gtk::Page::Query;
 use Haver::UI::Gtk::Page::Rawlog;
 use Haver::UI::Gtk::Page::Server;
+use Haver::UI::Gtk::ServerSelectDialog;
 use Data::Dumper;
 use Carp;
 
@@ -111,9 +112,12 @@
        $globals{config} = $config = Haver::Config->new(
                file => "$confdir/config",
                default => {
-                       UID => lc $user,
-                       Address => 'hardison.net:7070',
                        Alias => {},
+                       Servers => {
+                               'Experimental server' => {
+                                       Address => 'hardison.net:7071',
+                               }
+                       }
                },
        );
 };
@@ -151,8 +155,6 @@
        _start
        input
        entry_key_pressed
-       connect_win
-       do_connect
        quit
        haver_connect_fail
        haver_disconnected
@@ -169,6 +171,9 @@
        cmd_query
        cmd_close
        cmd_say
+       connectwin_connect
+       connectwin_close
+       open_connect
        }]]);
 
 eval {
@@ -210,24 +215,46 @@
                }
        );
        
-       my $vbox = Gtk::VBox->new(0,0);
+       my $vbox = Gtk::VBox->new(FALSE,0);
+
+       $gui{menubar} = new Gtk::MenuBar();
+       $vbox->pack_start($gui{menubar}, FALSE, FALSE, 0);
+       $gui{menubar}->show;
+
+       my $fileitem = $gui{FileItem} = new Gtk::MenuItem('File');
+       $gui{menubar}->append($fileitem);
+       $fileitem->show;
+
+       my $filemenu = $gui{FileMenu} = new Gtk::Menu();
+       $fileitem->set_submenu($filemenu);
+       
+       my $cwinitem = new Gtk::MenuItem('Server list...');
+       $filemenu->append($cwinitem);
+       $cwinitem->show;
+       $cwinitem->signal_connect('activate', 
$session->postback('open_connect'));
+
+       my $exititem = new Gtk::MenuItem('Exit');
+       $filemenu->append($exititem);
+       $exititem->show;
+       $exititem->signal_connect('activate', $session->postback('quit'));
+       
        $pages = new Haver::UI::Gtk::Pages;
        $pages->register_notify(\&notify_sub);
-       $vbox->pack_start($pages->get_gui(), 1, 1, 0);
+       $vbox->pack_start($pages->get_gui(), TRUE, TRUE, 0);
        $pages->get_gui()->show;
 
        my $entrybox = $gui{entrybox} = Gtk::HBox->new(FALSE, 0);
-       $vbox->pack_start($entrybox, 0, 1, 0);
+       $vbox->pack_start($entrybox, FALSE, TRUE, 0);
        $entrybox->show;
        
        my $entry = $gui{entry} = Gtk::Entry->new();
        $entry->signal_connect("key-press-event", 
$session->postback("entry_key_pressed"));
-       $entrybox->pack_start($entry, 1, 1, 0);
+       $entrybox->pack_start($entry, TRUE, TRUE, 0);
        $entry->show;
 
        my $send = $gui{sendbtn} = Gtk::Button->new("Send");
        $send->signal_connect("clicked", $session->postback("input"));
-       $entrybox->pack_start($send, 0, 1, 0);
+       $entrybox->pack_start($send, FALSE, TRUE, 0);
        $send->show;
        
        $gui{main_window}->add($vbox);
@@ -254,6 +281,7 @@
 
 sub input {
        my ($kernel, $heap) = @_[KERNEL,HEAP];
+       return unless $heap->{ready};
        my $text = $gui{entry}->get_text;
        $gui{entry}->set_text('');
        eval {
@@ -274,88 +302,6 @@
        # TODO: history
 }
 
-sub connect_win {
-       my ($heap, $session) = @_[HEAP,SESSION];
-       if(defined $gui{connect_win} || $heap->{exiting}) {
-               return;
-       }
-       my %cw;
-       $gui{connect_win} = \%cw;
-       
-       $cw{window} = Gtk::Window->new("toplevel");
-       $cw{window}->set_modal(TRUE);
-       $cw{window}->set_title("Connect to Haver server");
-       $cw{window}->set_position("mouse");
-       
-       my $table = Gtk::Table->new(scalar(@fields) + 1, 2, FALSE);
-       my $opts = [qw{fill shrink expand}];
-       
-       for my $i (0..$#fields) {
-               my $label = Gtk::Label->new($fields[$i]);
-               my $text = $cw{"field_$fields[$i]"} = Gtk::Entry->new();
-
-               $table->attach($label, 0, 1, $i, $i + 1, $opts, $opts, 0, 0);
-               $table->attach($text, 1, 2, $i, $i + 1, $opts, $opts, 0, 0);
-
-               $label->show;
-               $text->show;
-       }
-
-       $cw{"field_Password"}->set_visibility(FALSE);
-
-       my $cbtn = $cw{connect_btn} = Gtk::Button->new("Connect");
-       $cbtn->signal_connect("clicked", $session->postback("do_connect"));
-       $table->attach($cbtn, 0, 1, scalar(@fields), scalar(@fields) + 1,
-               $opts, $opts, 0, 0);
-       $cbtn->show;
-
-       my $qbtn = $cw{quit_btn} = Gtk::Button->new("Quit");
-       $qbtn->signal_connect("clicked", $session->postback("quit"));
-       $table->attach($qbtn, 1, 2, scalar(@fields), scalar(@fields) + 1,
-               $opts, $opts, 0, 0);
-       $qbtn->show;
-
-       for(@saved_fields) {
-               my $value = $config->{$_};
-               if($value) {
-                       $cw{"field_$_"}->set_text($value);
-               }
-       }
-       
-       $cw{window}->add($table);
-       $table->show;
-       $cw{window}->show;
-}
-
-sub do_connect {
-       my ($kernel, $heap) = @_[KERNEL,HEAP];
-       my $info = {};
-       if(!$gui{connect_win}) {
-               carp "Eep! do_connect without connect_win";
-               return;
-       }
-       for(@fields) {
-               $info->{$_} = $gui{connect_win}->{"field_$_"}->get_text();
-       }
-       for(@required_fields) {
-               return if (!defined $info->{$_} || $info->{$_} =~ /^\s*$/);
-       }
-       for(@saved_fields) {
-               $config->{$_} = $info->{$_};
-       }
-       $info->{Address} =~ /^([^:]+)(?::(\d+))?$/ or return;
-       $kernel->post("haver", "connect",
-               Host => $1,
-               Port => $2 || 7070,
-               UID  => $info->{UID},
-               Password => $info->{Password},
-       );
-       $status->print_page("Connecting to $info->{Address}...");
-       $gui{connect_win}{window}->destroy;
-       delete $gui{connect_win};
-       %globals = %$info;
-}
-
 sub quit {
        my ($kernel,$heap) = @_[KERNEL,HEAP];
        $gui{main_window}->destroy;
@@ -364,15 +310,49 @@
        $kernel->post("haver", "destroy");
        undef $cmd;
        undef $pages;
+       $config->save;
 }
 
+sub connectwin_connect {
+       my ($kernel, $config) = @_[KERNEL,ARG1];
+       # XXX: don't use postback so this won't be a problem
+       $config = $config->[0]; # Postback does strange things with parameters
+       my $pass = $config->{Password};
+       if (!defined $pass) {
+               $pass = ''; # TODO: prompt
+       }
+       # TODO: validation in ServerEditDialog
+       $config->{Address} =~ /^([^:]+)(?::(\d+))?$/ or return;
+       $kernel->post('haver', 'connect',
+               Host => $1,
+               Port => $2,
+               UID => $config->{UID} || $user,
+               Password => $pass,
+       );
+       %globals = %$config;
+}
+
+sub connectwin_close {
+       delete $_[HEAP]{cwin};
+}
+
+sub open_connect {
+       my ($kernel, $heap, $session) = @_[KERNEL,HEAP,SESSION];
+       if ($heap->{cwin}) {
+               $heap->{cwin}->activate_default();
+       } else {
+               $heap->{cwin} = new 
Haver::UI::Gtk::ServerSelectDialog($session, $config);
+       }
+}
+
 sub haver_connect_fail {
-       my $kernel = $_[KERNEL];
+       my ($kernel, $heap) = @_[KERNEL,HEAP];
        $kernel->yield('connect_win');
 }
 
 sub haver_disconnected {
        my ($kernel, $heap) = @_[KERNEL,HEAP];
+       $heap->{ready} = 0;
        $status->print_page("Disconnected");
        foreach my $page (values %channels, values %queries) {
                $pages->del_page($page);

Deleted: trunk/clients/haver-gtk/bin/serverdlg-test.pl
===================================================================
--- trunk/clients/haver-gtk/bin/serverdlg-test.pl       2004-07-06 03:22:15 UTC 
(rev 304)
+++ trunk/clients/haver-gtk/bin/serverdlg-test.pl       2004-07-06 03:27:03 UTC 
(rev 305)
@@ -1,86 +0,0 @@
-#!/usr/bin/perl
-# vim: set ft=perl ts=4 sw=4:
-# serverdlg-test.pl - ServerDialog test script. delete once it's in 
haver-gtk.pl
-# 
-# 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
-
-use strict;
-use warnings;
-
-use Gtk;
-use POE;
-use Haver::Config;
-use Haver::OS;
-use Haver::UI::Gtk::ServerSelectDialog;
-
-my ($user, $confdir, $config);
-
-eval {
-       $user = Haver::OS->current_user();
-       $confdir = Haver::OS->config_find(
-               scope => 'user',
-               name => 'haver-gtk',
-               type => 'dir',
-       );
-
-       $config = Haver::Config->new(
-               file => "$confdir/config",
-               default => {
-                       Alias => {},
-                       Servers => {
-                               'hardison.net' => {
-                                       Address => 'hardison.net:7071',
-                               }
-                       }
-               },
-       );
-};
-
-POE::Session->create(
-       package_states => [
-       main => [qw{
-               _start
-               connectwin_connect
-               connectwin_close
-               kill
-               }]
-       ]
-);
-
-sub _start {
-       my ($kernel, $heap, $session) = @_[KERNEL,HEAP,SESSION];
-       $kernel->alias_set("main");
-       $heap->{toplevel} = new Gtk::Window("toplevel");
-       $kernel->signal_ui_destroy($heap->{toplevel});
-       $heap->{toplevel}->set_title('serverdlg-test');
-       $heap->{killbtn} = new Gtk::Button("Close");
-       $heap->{toplevel}->add($heap->{killbtn});
-       $heap->{killbtn}->show;
-       $heap->{toplevel}->show;
-       $heap->{killbtn}->signal_connect("clicked", $session->postback("kill"));
-       $heap->{serverdlg} = new Haver::UI::Gtk::ServerSelectDialog($session, 
$config);
-}
-
-sub connectwin_connect {
-       print "connectwin_connect\n";
-}
-sub connectwin_close {
-       print "connectwin_close\n";
-}
-sub kill { exit 0; }
-
-POE::Kernel->run();


Reply via email to