]> git.zerfleddert.de Git - snom-frontend/blob - snom.pl
283b3988f06e35cec60ae5cea8489f763abadd12
[snom-frontend] / snom.pl
1 #!/bin/sh
2 #$Id: snom.pl,v 1.1 2006-05-21 11:53:53 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
16 #set_locale Gtk2;
17
18 sub snom_key(@) {
19 (my $key) = @_;
20 $key='%23' if ($key eq '#');
21 my $req = HTTP::Request->new(GET => "http://${ARGV[0]}/command.htm?key=${key}");
22 $ua->request($req);
23 }
24
25 sub snom_number(@) {
26 (my $number) = @_;
27 my $req = HTTP::Request->new(GET => "http://${ARGV[0]}/command.htm?number=${number}");
28 $ua->request($req);
29 }
30
31 if (!defined($ARGV[0])) {
32 print STDERR "Usage: ${0} snom.phone.address\n";
33 exit 1
34 }
35
36 my $window = Gtk2::Window->new('toplevel');
37 $window->set_title("snom");
38 $window->signal_connect(delete_event => \&CloseAppWindow);
39 $window->signal_connect(destroy => sub { Gtk2->main_quit; });
40 my $kphandler = $window->signal_connect(key_press_event => \&KBDInput);
41 $window->set_border_width(15);
42 $window->set_resizable(FALSE);
43
44 my $keypad = Gtk2::Table->new(4, 3, 1);
45 $keypad->set_row_spacings(2);
46 $keypad->set_col_spacings(2);
47 my %key = ();
48 my $n = 0;
49 foreach my $i (1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#') {
50 $key{$i} = Gtk2::Button->new(" ${i} ");
51 $key{$i}->signal_connect(clicked => \&KeyPressed, $i);
52 $keypad->attach_defaults($key{$i}, (($n)%3), (($n)%3)+1, int(($n)/3), int((($n)/3)+1));
53 $key{$i}->show();
54 $n++;
55 }
56 $keypad->show();
57
58 my $fkeys = Gtk2::Table->new(6, 2, 1);
59 $fkeys->set_row_spacings(2);
60 $fkeys->set_col_spacings(2);
61 $n = 0;
62 foreach my $i qw(Redial Settings Directory Help Menu snom _ _ Conference Transfer Hold DND) {
63 if ($i ne '_') {
64 $key{$i} = Gtk2::Button->new("${i}");
65 $key{$i}->signal_connect(clicked => \&KeyPressed, $i);
66 $fkeys->attach_defaults($key{$i}, (($n)%2), (($n)%2)+1, int(($n)/2), int((($n)/2)+1));
67 $key{$i}->show();
68 }
69 $n++;
70 }
71 $fkeys->show();
72
73 my $pkeys = Gtk2::Table->new(6, 2, 1);
74 $pkeys->set_row_spacings(2);
75 $pkeys->set_col_spacings(2);
76 $n = 0;
77 foreach my $i qw(P7 P1 P8 P2 P9 P3 P10 P4 P11 P5 P12 P6) {
78 $key{$i} = Gtk2::Button->new("${i}");
79 $key{$i}->signal_connect(clicked => \&KeyPressed, $i);
80 $pkeys->attach_defaults($key{$i}, (($n+1)%2), (($n+1)%2)+1, int($n/2), int($n/2)+1);
81 $key{$i}->show();
82 $n++;
83 }
84 $pkeys->show();
85
86 my $softkeys = Gtk2::Table->new(1, 4);
87 $softkeys->set_col_spacings(6);
88 $n = 0;
89 foreach my $i qw(F1 F2 F3 F4) {
90 $key{$i} = Gtk2::Button->new("${i}");
91 $key{$i}->signal_connect(clicked => \&KeyPressed, $i);
92 $softkeys->attach_defaults($key{$i}, $n, $n+1, 0, 1);
93 $key{$i}->show();
94 $n++;
95 }
96 $softkeys->show();
97
98 my $navi = Gtk2::Table->new(3, 5);
99 $n = 0;
100 foreach my $i qw(_ _ ^ _ _ X < _ > OK _ _ V _ _) {
101 if ( $i ne '_' ) {
102 $key{$i} = Gtk2::Button->new("${i}");
103 $key{$i}->signal_connect(clicked => \&KeyPressed, $i);
104 $navi->attach_defaults($key{$i}, (($n)%5), (($n)%5)+1, int(($n)/5), int((($n)/5)+1));
105 $key{$i}->show();
106 }
107 $n++;
108 }
109 $navi->show();
110
111 my $output = Gtk2::Table->new(2, 3);
112 $output->set_row_spacings(2);
113 $output->set_col_spacings(2);
114 $n = 0;
115 foreach my $i qw(- + _ Mute Speaker Headset) {
116 if ( $i ne '_' ) {
117 $key{$i} = Gtk2::Button->new("${i}");
118 $key{$i}->signal_connect(clicked => \&KeyPressed, $i);
119 $output->attach_defaults($key{$i}, (($n)%3), (($n)%3)+1, int(($n)/3), int((($n)/3)+1));
120 $key{$i}->show();
121 }
122 $n++;
123 }
124 $output->show();
125
126 my $special= Gtk2::Table->new(1, 2);
127 $special->set_col_spacings(2);
128 $n = 0;
129 foreach my $i qw(Record Retrieve) {
130 $key{$i} = Gtk2::Button->new("${i}");
131 $key{$i}->signal_connect(clicked => \&KeyPressed, $i);
132 $special->attach_defaults($key{$i}, $n, $n+1, 0, 1);
133 $key{$i}->show();
134 $n++;
135 }
136 $special->show();
137
138 my $display = Gtk2::Entry->new();
139 $display->signal_connect(activate => \&DialNumber);
140 my $kph_blocked = FALSE;
141 #$display->signal_connect(focus_in_event => \&DisplayMouseOver, TRUE);
142 $display->signal_connect(enter_notify_event => \&DisplayMouseOver, TRUE);
143 #$display->signal_connect(focus_out_event => \&DisplayMouseOver, FALSE);
144 $display->signal_connect(leave_notify_event => \&DisplayMouseOver, FALSE);
145 $display->show();
146
147 my $dispbox = Gtk2::VBox->new(0, 5);
148 $dispbox->pack_start($display, 0, 0, 0);
149 $dispbox->pack_start($softkeys, 0, 0, 0);
150 $dispbox->pack_start($navi, 0, 0, 0);
151 $dispbox->show();
152
153 my $outbox = Gtk2::VBox->new(0, 0);
154 $outbox->pack_end($output, 0, 0, 0);
155 $outbox->show();
156
157 my $specialbox = Gtk2::VBox->new(0, 0);
158 $specialbox->pack_end($special, 0, 0, 0);
159 $specialbox->show();
160
161 my $ubox = Gtk2::HBox->new(0, 30);
162 $ubox->pack_start($outbox, 0, 0, 0);
163 $ubox->pack_start($dispbox, 0, 0, 0);
164 $ubox->pack_start($specialbox, 0, 0, 0);
165 $ubox->show();
166
167
168 my $kbbox = Gtk2::HBox->new(0, 30);
169 $kbbox->pack_start($keypad, 1, 1, 0);
170 $kbbox->pack_start($fkeys, 0, 0, 0);
171 $kbbox->show();
172
173 my $kvbox = Gtk2::VBox->new(0, 5);
174 $kvbox->pack_end($kbbox, 0, 0, 0);
175 $kvbox->show();
176
177 my $lbox = Gtk2::HBox->new(0, 30);
178 $lbox->pack_start($kvbox, 1, 1, 0);
179 $lbox->pack_start($pkeys, 0, 0, 0);
180 $lbox->show();
181
182 my $mainbox = Gtk2::VBox->new(0,5);
183 $mainbox->pack_start($ubox, 0, 0, 0);
184 $mainbox->pack_start($lbox, 0, 0, 0);
185 $mainbox->show();
186
187 $window->add($mainbox);
188 $window->show();
189
190 # Gtk2 event loop
191 Gtk2->main;
192
193 # Should never get here
194 exit( 0 );
195
196
197 sub KeyPressed
198 {
199 my ($button, $text) = @_;
200 foreach my $i (1, 2, 3, 4, 5, 6, 7, 8, 9, '*', 0, '#',
201 'F1', 'F2', 'F3', 'F4',
202 'P1', 'P2', 'P3', 'P4', 'P5', 'P6',
203 'P7', 'P8', 'P9', 'P10', 'P11', 'P12') {
204 if ($i eq $text) {
205 snom_key($i);
206 return;
207 }
208 }
209
210 snom_key("REDIAL") if ( $text eq "Redial" );
211 snom_key("SETTINGS") if ( $text eq "Settings" );
212 snom_key("F_ADR_BOOK") if ( $text eq "Directory" );
213 snom_key("HELP") if ( $text eq "Help" );
214 snom_key("MENU") if ( $text eq "Menu" );
215 snom_key("SNOM") if ( $text eq "snom" );
216 snom_key("CONFERENCE") if ( $text eq "Conference" );
217 snom_key("TRANSFER") if ( $text eq "Transfer" );
218 snom_key("F_R") if ( $text eq "Hold" );
219 snom_key("DND") if ( $text eq "DND" );
220
221 snom_key("MUTE") if ( $text eq "Mute" );
222 snom_key("SPEAKER") if ( $text eq "Speaker" );
223 snom_key("HEADSET") if ( $text eq "Headset" );
224
225 snom_key("CANCEL") if ( $text eq "X" );
226 snom_key("ENTER") if ( $text eq "OK" );
227 snom_key("UP") if ( $text eq "^" );
228 snom_key("DOWN") if ( $text eq "V" );
229 snom_key("LEFT") if ( $text eq "<" );
230 snom_key("RIGHT") if ( $text eq ">" );
231
232 snom_key("F_REC") if ( $text eq "Record" );
233 snom_key("F_RETRIEVE") if ( $text eq "Retrieve" );
234
235 snom_key("VOLUME_UP") if ( $text eq "+" );
236 snom_key("VOLUME_DOWN") if ( $text eq "-" );
237 }
238
239 sub DialNumber
240 {
241 my ($entry) = @_;
242 snom_number($entry->get_text());
243 }
244
245 sub DisplayMouseOver
246 {
247 my ($widget, $event, $active) = @_;
248
249 if ($active) {
250 $widget->grab_focus();
251 if (!$kph_blocked) {
252 $window->signal_handler_block($kphandler);
253 $kph_blocked=TRUE;
254 }
255 } else {
256 $key{OK}->grab_focus();
257 if ($kph_blocked) {
258 $window->signal_handler_unblock($kphandler);
259 $kph_blocked=FALSE;
260 }
261 }
262
263 return TRUE;
264 }
265
266 sub KBDInput
267 {
268 my ($widget, $event) = @_;
269
270 my $keyval = $event->keyval;
271 foreach my $i (1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 'F1', 'F2', 'F3', 'F4') {
272 if ($keyval == $Gtk2::Gdk::Keysyms{$i}) {
273 snom_key($i);
274 return TRUE;
275 }
276 }
277
278 if ($keyval == $Gtk2::Gdk::Keysyms{Return}) {snom_key("ENTER"); return TRUE;}
279 if ($keyval == $Gtk2::Gdk::Keysyms{KP_Enter}) {snom_key("ENTER"); return TRUE;}
280 if ($keyval == $Gtk2::Gdk::Keysyms{Escape}) {snom_key("CANCEL"); return TRUE;}
281 if ($keyval == $Gtk2::Gdk::Keysyms{Left}) {snom_key("LEFT"); return TRUE;}
282 if ($keyval == $Gtk2::Gdk::Keysyms{KP_Left}) {snom_key("LEFT"); return TRUE;}
283 if ($keyval == $Gtk2::Gdk::Keysyms{Right}) {snom_key("RIGHT"); return TRUE;}
284 if ($keyval == $Gtk2::Gdk::Keysyms{KP_Right}) {snom_key("RIGHT"); return TRUE;}
285 if ($keyval == $Gtk2::Gdk::Keysyms{Up}) {snom_key("UP"); return TRUE;}
286 if ($keyval == $Gtk2::Gdk::Keysyms{KP_Up}) {snom_key("UP"); return TRUE;}
287 if ($keyval == $Gtk2::Gdk::Keysyms{Down}) {snom_key("DOWN"); return TRUE;}
288 if ($keyval == $Gtk2::Gdk::Keysyms{KP_Down}) {snom_key("DOWN"); return TRUE;}
289 return TRUE;
290 }
291
292 ### Callback function to close the window
293 sub CloseAppWindow
294 {
295 $window->destroy;
296 return TRUE;
297 }
298
299
300 # END EXAMPLE PROGRAM
Impressum, Datenschutz