#!/bin/sh
-#$Id: snom.pl,v 1.14 2006-05-21 22:11:53 sithglan Exp $
+#$Id: snom.pl,v 1.38 2006-05-22 12:22:53 michael Exp $
+
+# http://developer.gnome.org/doc/API/2.2/gtk/gtk-migrating-GtkComboBox.html
PATH=/opt/csw/bin:/opt/local/bin:/usr/bin:/bin exec perl -w -x "$0" "$@"
#!perl
-use Glib qw/TRUE FALSE/;
-use Gtk2 '-init';
-use Gtk2::Gdk::Keysyms;
use strict;
use warnings FATAL => 'all';
+use Glib qw/TRUE FALSE/;
+use Gtk2 '-init';
+use Gtk2::Gdk::Keysyms;
use LWP::UserAgent;
-my $ua = LWP::UserAgent->new;
-#$ua->credentials("${ARGV[0]}:80","snom","root","geheim");
+
my %g_key = ();
+my $g_host = Gtk2::ComboBox->new_text();
+my $g_identity = Gtk2::ComboBox->new_text();
+my $ua = LWP::UserAgent->new;
+
+open(INIFILE,"<$ENV{HOME}/.snomrc") || die("can't open config: $ENV{HOME}/.snomrc: $!");
+my %Config = ();
+my @sections = ();
+while(<INIFILE>) {
+ chomp;
+
+ next if (m/^#/);
+
+ if (m/^\s*\[(.*)\]\s*$/) {
+ push @sections, $1;
+ next;
+ }
+
+ if (@sections) {
+ if (m/^\s*(.+)\s*=\s*(.*)\s*$/) {
+ ${$Config{$sections[$#sections]}}{$1} = $2;
+ }
+ }
+}
+close(INIFILE);
+
+for my $section (@sections) {
+ if (defined(${$Config{$section}}{host})) {
+ $g_host->append_text($section);
+ if (defined(${$Config{$section}}{login}) &&
+ defined(${$Config{$section}}{password})) {
+ $ua->credentials(${$Config{$section}}{host}.":80",
+ "snom",
+ ${$Config{$section}}{login},
+ ${$Config{$section}}{password});
+ }
+ }
+}
+$g_host->set_active(0);
+UpdatePhoneInfo();
+$g_host->signal_connect(changed => \&UpdatePhoneInfo);
+$g_host->show();
+$g_identity->signal_connect(changed => \&SwitchIdentity);
+$g_identity->show();
set_locale Gtk2;
sub snom_key {
my $key = shift;
$key='%23' if ($key eq '#');
- my $req = HTTP::Request->new(GET => "http://${ARGV[0]}/command.htm?key=${key}");
+ my $req = HTTP::Request->new(GET => "http://".${$Config{$sections[$g_host->get_active]}}{host}."/command.htm?key=${key}");
$ua->request($req);
}
sub snom_number {
my $number = shift;
- my $req = HTTP::Request->new(GET => "http://${ARGV[0]}/command.htm?number=${number}");
+ my $req = HTTP::Request->new(GET => "http://".${$Config{$sections[$g_host->get_active]}}{host}."/command.htm?number=${number}");
$ua->request($req);
}
$table;
}
-if (!defined($ARGV[0])) {
- print STDERR "Usage: ${0} snom.phone.address\n";
- exit 1
-}
-
my $window = Gtk2::Window->new('toplevel');
$window->set_title("snom");
$window->signal_connect(delete_event => \&CloseAppWindow);
$display->signal_connect(leave_notify_event => \&DisplayMouseOver, FALSE);
$display->show();
-my $host = Gtk2::ComboBox->new();
-$host->show();
-
my $dispbox = Gtk2::VBox->new(0, 5);
$dispbox->pack_start($display, 0, 0, 0);
$dispbox->pack_start($softkeys, 0, 0, 0);
$dispbox->show();
my $outbox = Gtk2::VBox->new(0, 0);
-$outbox->pack_start($host, 0, 0, 0);
+$outbox->pack_start($g_host, 0, 0, 0);
$outbox->pack_end($output, 0, 0, 0);
$outbox->show();
my $specialbox = Gtk2::VBox->new(0, 0);
+$specialbox->pack_start($g_identity, 0, 0, 0);
$specialbox->pack_end($special, 0, 0, 0);
$specialbox->show();
return FALSE;
}
+sub UpdatePhoneInfo
+{
+ my $req = HTTP::Request->new(GET => "http://".${$Config{$sections[$g_host->get_active]}}{host}."/");
+ my $response = $ua->request($req);
+
+ $g_identity->set_active(0);
+ while($g_identity->get_active() == 0) {
+ $g_identity->remove_text(0);
+ $g_identity->set_active(0);
+ }
+ my @lines=split("\n", $response->content());
+ foreach (@lines) {
+ chomp;
+ #<option value="1" selected>51@stargate.gernoth.loc</option>
+ #<option value="2">89@asterix.ear-projekt.de</option>
+ #<option value="3">41@grumpy.gernoth.loc</option>
+ if (m/^\<option value=\"(.+)\"( selected)?\>([^<]*)\<\/option\>$/) {
+ $g_identity->append_text("${3}");
+ $g_identity->set_active(${1}-1) if(defined($2));
+ }
+ }
+}
+
+sub SwitchIdentity
+{
+ print "TODO: Switch Identity on <".${$Config{$sections[$g_host->get_active]}}{host}."> to ".$g_identity->get_active."!\n";
+}
+
sub CloseAppWindow
{
$window->destroy;