some more shortcuts
[snom-frontend] / snom.pl
CommitLineData
a3855c1d 1#!/bin/sh
d625d09e 2#$Id: snom.pl,v 1.11 2006-05-21 21:20:19 michael Exp $
a3855c1d 3
4PATH=/opt/csw/bin:/opt/local/bin:/usr/bin:/bin exec perl -w -x "$0" "$@"
5
6#!perl
7
8use Glib qw/TRUE FALSE/;
9use Gtk2 '-init';
10use Gtk2::Gdk::Keysyms;
11use strict;
12
13use LWP::UserAgent;
14my $ua = LWP::UserAgent->new;
ee7ae952 15#$ua->credentials("${ARGV[0]}:80","snom","root","geheim");
a3855c1d 16
ee7ae952 17set_locale Gtk2;
a3855c1d 18
19sub snom_key(@) {
20 (my $key) = @_;
21 $key='%23' if ($key eq '#');
22 my $req = HTTP::Request->new(GET => "http://${ARGV[0]}/command.htm?key=${key}");
23 $ua->request($req);
24}
25
26sub snom_number(@) {
27 (my $number) = @_;
28 my $req = HTTP::Request->new(GET => "http://${ARGV[0]}/command.htm?number=${number}");
29 $ua->request($req);
30}
31
32if (!defined($ARGV[0])) {
33 print STDERR "Usage: ${0} snom.phone.address\n";
34 exit 1
35}
36
37my $window = Gtk2::Window->new('toplevel');
38$window->set_title("snom");
39$window->signal_connect(delete_event => \&CloseAppWindow);
40$window->signal_connect(destroy => sub { Gtk2->main_quit; });
41my $kphandler = $window->signal_connect(key_press_event => \&KBDInput);
42$window->set_border_width(15);
43$window->set_resizable(FALSE);
44
45my $keypad = Gtk2::Table->new(4, 3, 1);
46$keypad->set_row_spacings(2);
47$keypad->set_col_spacings(2);
48my %key = ();
49my $n = 0;
50foreach my $i (1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#') {
51 $key{$i} = Gtk2::Button->new(" ${i} ");
52 $key{$i}->signal_connect(clicked => \&KeyPressed, $i);
53 $keypad->attach_defaults($key{$i}, (($n)%3), (($n)%3)+1, int(($n)/3), int((($n)/3)+1));
54 $key{$i}->show();
55 $n++;
56}
57$keypad->show();
58
59my $fkeys = Gtk2::Table->new(6, 2, 1);
60$fkeys->set_row_spacings(2);
61$fkeys->set_col_spacings(2);
62$n = 0;
d625d09e 63foreach my $i qw(_Redial S_ettings Director_y Hel_p Men_u snom _ _ _Conference _Transfer H_old _DND) {
a3855c1d 64 if ($i ne '_') {
65 $key{$i} = Gtk2::Button->new("${i}");
66 $key{$i}->signal_connect(clicked => \&KeyPressed, $i);
67 $fkeys->attach_defaults($key{$i}, (($n)%2), (($n)%2)+1, int(($n)/2), int((($n)/2)+1));
68 $key{$i}->show();
69 }
70 $n++;
71}
72$fkeys->show();
73
74my $pkeys = Gtk2::Table->new(6, 2, 1);
75$pkeys->set_row_spacings(2);
76$pkeys->set_col_spacings(2);
77$n = 0;
78foreach my $i qw(P7 P1 P8 P2 P9 P3 P10 P4 P11 P5 P12 P6) {
79 $key{$i} = Gtk2::Button->new("${i}");
80 $key{$i}->signal_connect(clicked => \&KeyPressed, $i);
81 $pkeys->attach_defaults($key{$i}, (($n+1)%2), (($n+1)%2)+1, int($n/2), int($n/2)+1);
82 $key{$i}->show();
83 $n++;
84}
85$pkeys->show();
86
87my $softkeys = Gtk2::Table->new(1, 4);
88$softkeys->set_col_spacings(6);
89$n = 0;
90foreach my $i qw(F1 F2 F3 F4) {
91 $key{$i} = Gtk2::Button->new("${i}");
92 $key{$i}->signal_connect(clicked => \&KeyPressed, $i);
93 $softkeys->attach_defaults($key{$i}, $n, $n+1, 0, 1);
94 $key{$i}->show();
95 $n++;
96}
97$softkeys->show();
98
99my $navi = Gtk2::Table->new(3, 5);
100$n = 0;
101foreach my $i qw(_ _ ^ _ _ X < _ > OK _ _ V _ _) {
102 if ( $i ne '_' ) {
103 $key{$i} = Gtk2::Button->new("${i}");
104 $key{$i}->signal_connect(clicked => \&KeyPressed, $i);
105 $navi->attach_defaults($key{$i}, (($n)%5), (($n)%5)+1, int(($n)/5), int((($n)/5)+1));
106 $key{$i}->show();
107 }
108 $n++;
109}
110$navi->show();
111
112my $output = Gtk2::Table->new(2, 3);
113$output->set_row_spacings(2);
114$output->set_col_spacings(2);
115$n = 0;
7829dff4 116foreach my $i qw(- + _ _Mute _Speaker _Headset) {
a3855c1d 117 if ( $i ne '_' ) {
118 $key{$i} = Gtk2::Button->new("${i}");
119 $key{$i}->signal_connect(clicked => \&KeyPressed, $i);
120 $output->attach_defaults($key{$i}, (($n)%3), (($n)%3)+1, int(($n)/3), int((($n)/3)+1));
121 $key{$i}->show();
122 }
123 $n++;
124}
125$output->show();
126
127my $special= Gtk2::Table->new(1, 2);
128$special->set_col_spacings(2);
129$n = 0;
130foreach my $i qw(Record Retrieve) {
131 $key{$i} = Gtk2::Button->new("${i}");
132 $key{$i}->signal_connect(clicked => \&KeyPressed, $i);
133 $special->attach_defaults($key{$i}, $n, $n+1, 0, 1);
134 $key{$i}->show();
135 $n++;
136}
137$special->show();
138
139my $display = Gtk2::Entry->new();
140$display->signal_connect(activate => \&DialNumber);
141my $kph_blocked = FALSE;
a3855c1d 142$display->signal_connect(enter_notify_event => \&DisplayMouseOver, TRUE);
a3855c1d 143$display->signal_connect(leave_notify_event => \&DisplayMouseOver, FALSE);
144$display->show();
145
146my $dispbox = Gtk2::VBox->new(0, 5);
147$dispbox->pack_start($display, 0, 0, 0);
148$dispbox->pack_start($softkeys, 0, 0, 0);
149$dispbox->pack_start($navi, 0, 0, 0);
150$dispbox->show();
151
152my $outbox = Gtk2::VBox->new(0, 0);
153$outbox->pack_end($output, 0, 0, 0);
154$outbox->show();
155
156my $specialbox = Gtk2::VBox->new(0, 0);
157$specialbox->pack_end($special, 0, 0, 0);
158$specialbox->show();
159
160my $ubox = Gtk2::HBox->new(0, 30);
161$ubox->pack_start($outbox, 0, 0, 0);
162$ubox->pack_start($dispbox, 0, 0, 0);
163$ubox->pack_start($specialbox, 0, 0, 0);
164$ubox->show();
165
166
167my $kbbox = Gtk2::HBox->new(0, 30);
168$kbbox->pack_start($keypad, 1, 1, 0);
169$kbbox->pack_start($fkeys, 0, 0, 0);
170$kbbox->show();
171
172my $kvbox = Gtk2::VBox->new(0, 5);
173$kvbox->pack_end($kbbox, 0, 0, 0);
174$kvbox->show();
175
176my $lbox = Gtk2::HBox->new(0, 30);
177$lbox->pack_start($kvbox, 1, 1, 0);
178$lbox->pack_start($pkeys, 0, 0, 0);
179$lbox->show();
180
181my $mainbox = Gtk2::VBox->new(0,5);
182$mainbox->pack_start($ubox, 0, 0, 0);
183$mainbox->pack_start($lbox, 0, 0, 0);
184$mainbox->show();
185
186$window->add($mainbox);
187$window->show();
188
bfe77af1 189$key{OK}->grab_focus();
190
a3855c1d 191# Gtk2 event loop
192Gtk2->main;
193
194# Should never get here
195exit( 0 );
196
197
198sub KeyPressed
199{
200 my ($button, $text) = @_;
7829dff4 201 $text=~ s/_//g;
a3855c1d 202 foreach my $i (1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#',
203 'F1', 'F2', 'F3', 'F4',
204 'P1', 'P2', 'P3', 'P4', 'P5', 'P6',
205 'P7', 'P8', 'P9', 'P10', 'P11', 'P12') {
206 if ($i eq $text) {
207 snom_key($i);
f73d9f87 208 return TRUE;
a3855c1d 209 }
210 }
211
212 snom_key("REDIAL") if ( $text eq "Redial" );
213 snom_key("SETTINGS") if ( $text eq "Settings" );
214 snom_key("F_ADR_BOOK") if ( $text eq "Directory" );
215 snom_key("HELP") if ( $text eq "Help" );
216 snom_key("MENU") if ( $text eq "Menu" );
217 snom_key("SNOM") if ( $text eq "snom" );
218 snom_key("CONFERENCE") if ( $text eq "Conference" );
219 snom_key("TRANSFER") if ( $text eq "Transfer" );
220 snom_key("F_R") if ( $text eq "Hold" );
221 snom_key("DND") if ( $text eq "DND" );
222
223 snom_key("MUTE") if ( $text eq "Mute" );
224 snom_key("SPEAKER") if ( $text eq "Speaker" );
225 snom_key("HEADSET") if ( $text eq "Headset" );
226
227 snom_key("CANCEL") if ( $text eq "X" );
228 snom_key("ENTER") if ( $text eq "OK" );
229 snom_key("UP") if ( $text eq "^" );
230 snom_key("DOWN") if ( $text eq "V" );
231 snom_key("LEFT") if ( $text eq "<" );
232 snom_key("RIGHT") if ( $text eq ">" );
233
234 snom_key("F_REC") if ( $text eq "Record" );
235 snom_key("F_RETRIEVE") if ( $text eq "Retrieve" );
236
237 snom_key("VOLUME_UP") if ( $text eq "+" );
238 snom_key("VOLUME_DOWN") if ( $text eq "-" );
f73d9f87 239 return TRUE;
a3855c1d 240}
241
242sub DialNumber
243{
244 my ($entry) = @_;
f73d9f87 245
a3855c1d 246 snom_number($entry->get_text());
f73d9f87 247 return TRUE;
a3855c1d 248}
249
250sub DisplayMouseOver
251{
252 my ($widget, $event, $active) = @_;
253
254 if ($active) {
255 $widget->grab_focus();
256 if (!$kph_blocked) {
257 $window->signal_handler_block($kphandler);
258 $kph_blocked=TRUE;
259 }
260 } else {
261 $key{OK}->grab_focus();
262 if ($kph_blocked) {
263 $window->signal_handler_unblock($kphandler);
264 $kph_blocked=FALSE;
265 }
266 }
267
268 return TRUE;
269}
270
271sub KBDInput
272{
273 my ($widget, $event) = @_;
274
275 my $keyval = $event->keyval;
824f34a5 276
a0365ad7 277 for (my $i=0; $i<10; $i++) {
190de48a 278 if ($keyval == $Gtk2::Gdk::Keysyms{$i} || $keyval == $Gtk2::Gdk::Keysyms{"KP_${i}"}) {
a3855c1d 279 snom_key($i);
280 return TRUE;
281 }
282 }
283
7829dff4 284 if (!$event->state || $event->state eq 'shift-mask') {
285 if ($keyval == $Gtk2::Gdk::Keysyms{asterisk}) {snom_key('*'); return TRUE;}
286 if ($keyval == $Gtk2::Gdk::Keysyms{KP_Multiply}) {snom_key('*'); return TRUE;}
287 if ($keyval == $Gtk2::Gdk::Keysyms{numbersign}) {snom_key('#'); return TRUE;}
288 if ($keyval == $Gtk2::Gdk::Keysyms{KP_Add}) {snom_key('VOLUME_UP'); return TRUE;}
289 if ($keyval == $Gtk2::Gdk::Keysyms{plus}) {snom_key('VOLUME_UP'); return TRUE;}
290 if ($keyval == $Gtk2::Gdk::Keysyms{KP_Subtract}) {snom_key('VOLUME_DOWN'); return TRUE;}
291 if ($keyval == $Gtk2::Gdk::Keysyms{minus}) {snom_key('VOLUME_DOWN'); return TRUE;}
292 if ($keyval == $Gtk2::Gdk::Keysyms{Return}) {snom_key("ENTER"); return TRUE;}
293 if ($keyval == $Gtk2::Gdk::Keysyms{KP_Enter}) {snom_key("ENTER"); return TRUE;}
294 if ($keyval == $Gtk2::Gdk::Keysyms{Escape}) {snom_key("CANCEL"); return TRUE;}
295 if ($keyval == $Gtk2::Gdk::Keysyms{Left}) {snom_key("LEFT"); return TRUE;}
296 if ($keyval == $Gtk2::Gdk::Keysyms{KP_Left}) {snom_key("LEFT"); return TRUE;}
297 if ($keyval == $Gtk2::Gdk::Keysyms{Right}) {snom_key("RIGHT"); return TRUE;}
298 if ($keyval == $Gtk2::Gdk::Keysyms{KP_Right}) {snom_key("RIGHT"); return TRUE;}
299 if ($keyval == $Gtk2::Gdk::Keysyms{Up}) {snom_key("UP"); return TRUE;}
300 if ($keyval == $Gtk2::Gdk::Keysyms{KP_Up}) {snom_key("UP"); return TRUE;}
301 if ($keyval == $Gtk2::Gdk::Keysyms{Down}) {snom_key("DOWN"); return TRUE;}
302 if ($keyval == $Gtk2::Gdk::Keysyms{KP_Down}) {snom_key("DOWN"); return TRUE;}
303 if ($keyval == $Gtk2::Gdk::Keysyms{M}) {snom_key('MUTE'); return TRUE;}
304 if ($keyval == $Gtk2::Gdk::Keysyms{m}) {snom_key('MUTE'); return TRUE;}
305 if ($keyval == $Gtk2::Gdk::Keysyms{S}) {snom_key('SPEAKER'); return TRUE;}
306 if ($keyval == $Gtk2::Gdk::Keysyms{s}) {snom_key('SPEAKER'); return TRUE;}
307 if ($keyval == $Gtk2::Gdk::Keysyms{H}) {snom_key('HEADSET'); return TRUE;}
308 if ($keyval == $Gtk2::Gdk::Keysyms{h}) {snom_key('HEADSET'); return TRUE;}
309 if ($keyval == $Gtk2::Gdk::Keysyms{C}) {snom_key('CONFERENCE'); return TRUE;}
310 if ($keyval == $Gtk2::Gdk::Keysyms{c}) {snom_key('CONFERENCE'); return TRUE;}
311 if ($keyval == $Gtk2::Gdk::Keysyms{T}) {snom_key('TRANSFER'); return TRUE;}
312 if ($keyval == $Gtk2::Gdk::Keysyms{t}) {snom_key('TRANSFER'); return TRUE;}
313 if ($keyval == $Gtk2::Gdk::Keysyms{O}) {snom_key('F_R'); return TRUE;}
314 if ($keyval == $Gtk2::Gdk::Keysyms{o}) {snom_key('F_R'); return TRUE;}
315 if ($keyval == $Gtk2::Gdk::Keysyms{D}) {snom_key('DND'); return TRUE;}
316 if ($keyval == $Gtk2::Gdk::Keysyms{d}) {snom_key('DND'); return TRUE;}
d625d09e 317 if ($keyval == $Gtk2::Gdk::Keysyms{R}) {snom_key('REDIAL'); return TRUE;}
318 if ($keyval == $Gtk2::Gdk::Keysyms{r}) {snom_key('REDIAL'); return TRUE;}
319 if ($keyval == $Gtk2::Gdk::Keysyms{E}) {snom_key('SETTINGS'); return TRUE;}
320 if ($keyval == $Gtk2::Gdk::Keysyms{e}) {snom_key('SETTINGS'); return TRUE;}
321 if ($keyval == $Gtk2::Gdk::Keysyms{Y}) {snom_key('F_ADR_BOOK'); return TRUE;}
322 if ($keyval == $Gtk2::Gdk::Keysyms{y}) {snom_key('F_ADR_BOOK'); return TRUE;}
323 if ($keyval == $Gtk2::Gdk::Keysyms{P}) {snom_key('HELP'); return TRUE;}
324 if ($keyval == $Gtk2::Gdk::Keysyms{p}) {snom_key('HELP'); return TRUE;}
325 if ($keyval == $Gtk2::Gdk::Keysyms{U}) {snom_key('MENU'); return TRUE;}
326 if ($keyval == $Gtk2::Gdk::Keysyms{u}) {snom_key('MENU'); return TRUE;}
7829dff4 327 }
190de48a 328
329 if (!$event->state) {
330 for (my $i=1; $i<5; $i++) {
331 if ($keyval == $Gtk2::Gdk::Keysyms{"F${i}"}) {
332 snom_key("F${i}");
333 return TRUE;
334 }
335 }
336 } else {
337 if ($event->state eq 'mod1-mask') {
338 for (my $i=1; $i<13; $i++) {
339 if ($keyval == $Gtk2::Gdk::Keysyms{"F${i}"}) {
340 snom_key("P${i}");
341 return TRUE;
342 }
343 }
344 }
345 }
346
347 print "Unhandled: Modifier: ".$event->state.", Key: ";
348 foreach my $key (keys(%Gtk2::Gdk::Keysyms)) {
349 if ($keyval == $Gtk2::Gdk::Keysyms{$key}) {
350 print "${key}\n";
351 return TRUE;
352 }
353 }
354 print "ERR\n";
355 return FALSE;
a3855c1d 356}
357
a3855c1d 358sub CloseAppWindow
359{
360 $window->destroy;
361 return TRUE;
362}
Impressum, Datenschutz