]> git.zerfleddert.de Git - snom-frontend/blob - snom.pl
b2d4a21db7c81ef76cd5537bae69966a1e74e537
[snom-frontend] / snom.pl
1 #!/bin/sh
2 #$Id: snom.pl,v 1.4 2006-05-21 12:29:13 simigern Exp $
3
4 PATH=/opt/csw/bin:/opt/local/bin:/usr/bin:/bin exec perl -w -x "$0" "$@"
5
6 #!perl
7
8 use Glib qw/TRUE FALSE/;
9 use Gtk2 '-init';
10 use Gtk2::Gdk::Keysyms;
11 use strict;
12
13 use LWP::UserAgent;
14 my $ua = LWP::UserAgent->new;
15 #$ua->credentials("${ARGV[0]}:80","snom","root","geheim");
16
17 set_locale Gtk2;
18
19 sub 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
26 sub 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
32 if (!defined($ARGV[0])) {
33 print STDERR "Usage: ${0} snom.phone.address\n";
34 exit 1
35 }
36
37 my $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; });
41 my $kphandler = $window->signal_connect(key_press_event => \&KBDInput);
42 $window->set_border_width(15);
43 $window->set_resizable(FALSE);
44
45 my $keypad = Gtk2::Table->new(4, 3, 1);
46 $keypad->set_row_spacings(2);
47 $keypad->set_col_spacings(2);
48 my %key = ();
49 my $n = 0;
50 foreach 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
59 my $fkeys = Gtk2::Table->new(6, 2, 1);
60 $fkeys->set_row_spacings(2);
61 $fkeys->set_col_spacings(2);
62 $n = 0;
63 foreach my $i qw(Redial Settings Directory Help Menu snom _ _ Conference Transfer Hold DND) {
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
74 my $pkeys = Gtk2::Table->new(6, 2, 1);
75 $pkeys->set_row_spacings(2);
76 $pkeys->set_col_spacings(2);
77 $n = 0;
78 foreach 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
87 my $softkeys = Gtk2::Table->new(1, 4);
88 $softkeys->set_col_spacings(6);
89 $n = 0;
90 foreach 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
99 my $navi = Gtk2::Table->new(3, 5);
100 $n = 0;
101 foreach 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
112 my $output = Gtk2::Table->new(2, 3);
113 $output->set_row_spacings(2);
114 $output->set_col_spacings(2);
115 $n = 0;
116 foreach my $i qw(- + _ Mute Speaker Headset) {
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
127 my $special= Gtk2::Table->new(1, 2);
128 $special->set_col_spacings(2);
129 $n = 0;
130 foreach 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
139 my $display = Gtk2::Entry->new();
140 $display->signal_connect(activate => \&DialNumber);
141 my $kph_blocked = FALSE;
142 $display->signal_connect(enter_notify_event => \&DisplayMouseOver, TRUE);
143 $display->signal_connect(leave_notify_event => \&DisplayMouseOver, FALSE);
144 $display->show();
145
146 my $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
152 my $outbox = Gtk2::VBox->new(0, 0);
153 $outbox->pack_end($output, 0, 0, 0);
154 $outbox->show();
155
156 my $specialbox = Gtk2::VBox->new(0, 0);
157 $specialbox->pack_end($special, 0, 0, 0);
158 $specialbox->show();
159
160 my $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
167 my $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
172 my $kvbox = Gtk2::VBox->new(0, 5);
173 $kvbox->pack_end($kbbox, 0, 0, 0);
174 $kvbox->show();
175
176 my $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
181 my $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
189 $key{OK}->grab_focus();
190
191 # Gtk2 event loop
192 Gtk2->main;
193
194 # Should never get here
195 exit( 0 );
196
197
198 sub KeyPressed
199 {
200 my ($button, $text) = @_;
201 foreach my $i (1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#',
202 'F1', 'F2', 'F3', 'F4',
203 'P1', 'P2', 'P3', 'P4', 'P5', 'P6',
204 'P7', 'P8', 'P9', 'P10', 'P11', 'P12') {
205 if ($i eq $text) {
206 snom_key($i);
207 return TRUE;
208 }
209 }
210
211 snom_key("REDIAL") if ( $text eq "Redial" );
212 snom_key("SETTINGS") if ( $text eq "Settings" );
213 snom_key("F_ADR_BOOK") if ( $text eq "Directory" );
214 snom_key("HELP") if ( $text eq "Help" );
215 snom_key("MENU") if ( $text eq "Menu" );
216 snom_key("SNOM") if ( $text eq "snom" );
217 snom_key("CONFERENCE") if ( $text eq "Conference" );
218 snom_key("TRANSFER") if ( $text eq "Transfer" );
219 snom_key("F_R") if ( $text eq "Hold" );
220 snom_key("DND") if ( $text eq "DND" );
221
222 snom_key("MUTE") if ( $text eq "Mute" );
223 snom_key("SPEAKER") if ( $text eq "Speaker" );
224 snom_key("HEADSET") if ( $text eq "Headset" );
225
226 snom_key("CANCEL") if ( $text eq "X" );
227 snom_key("ENTER") if ( $text eq "OK" );
228 snom_key("UP") if ( $text eq "^" );
229 snom_key("DOWN") if ( $text eq "V" );
230 snom_key("LEFT") if ( $text eq "<" );
231 snom_key("RIGHT") if ( $text eq ">" );
232
233 snom_key("F_REC") if ( $text eq "Record" );
234 snom_key("F_RETRIEVE") if ( $text eq "Retrieve" );
235
236 snom_key("VOLUME_UP") if ( $text eq "+" );
237 snom_key("VOLUME_DOWN") if ( $text eq "-" );
238 return TRUE;
239 }
240
241 sub DialNumber
242 {
243 my ($entry) = @_;
244
245 snom_number($entry->get_text());
246 return TRUE;
247 }
248
249 sub DisplayMouseOver
250 {
251 my ($widget, $event, $active) = @_;
252
253 if ($active) {
254 $widget->grab_focus();
255 if (!$kph_blocked) {
256 $window->signal_handler_block($kphandler);
257 $kph_blocked=TRUE;
258 }
259 } else {
260 $key{OK}->grab_focus();
261 if ($kph_blocked) {
262 $window->signal_handler_unblock($kphandler);
263 $kph_blocked=FALSE;
264 }
265 }
266
267 return TRUE;
268 }
269
270 sub KBDInput
271 {
272 my ($widget, $event) = @_;
273
274 my $keyval = $event->keyval;
275 foreach my $i (1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 'F1', 'F2', 'F3', 'F4') {
276 if ($keyval == $Gtk2::Gdk::Keysyms{$i}) {
277 snom_key($i);
278 return TRUE;
279 }
280 }
281
282 if ($keyval == $Gtk2::Gdk::Keysyms{Return}) {snom_key("ENTER"); return TRUE;}
283 if ($keyval == $Gtk2::Gdk::Keysyms{KP_Enter}) {snom_key("ENTER"); return TRUE;}
284 if ($keyval == $Gtk2::Gdk::Keysyms{Escape}) {snom_key("CANCEL"); return TRUE;}
285 if ($keyval == $Gtk2::Gdk::Keysyms{Left}) {snom_key("LEFT"); return TRUE;}
286 if ($keyval == $Gtk2::Gdk::Keysyms{KP_Left}) {snom_key("LEFT"); return TRUE;}
287 if ($keyval == $Gtk2::Gdk::Keysyms{Right}) {snom_key("RIGHT"); return TRUE;}
288 if ($keyval == $Gtk2::Gdk::Keysyms{KP_Right}) {snom_key("RIGHT"); return TRUE;}
289 if ($keyval == $Gtk2::Gdk::Keysyms{Up}) {snom_key("UP"); return TRUE;}
290 if ($keyval == $Gtk2::Gdk::Keysyms{KP_Up}) {snom_key("UP"); return TRUE;}
291 if ($keyval == $Gtk2::Gdk::Keysyms{Down}) {snom_key("DOWN"); return TRUE;}
292 if ($keyval == $Gtk2::Gdk::Keysyms{KP_Down}) {snom_key("DOWN"); return TRUE;}
293 return TRUE;
294 }
295
296 ### Callback function to close the window
297 sub CloseAppWindow
298 {
299 $window->destroy;
300 return TRUE;
301 }
302
303
304 # END EXAMPLE PROGRAM
Impressum, Datenschutz