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