1 /* $Id$ */
2 /* Copyright (c) 2011-2016 Pierre Pronchery <khorben@defora.org> */
3 /* This file is part of DeforaOS Desktop Phone */
4 /* This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, version 3 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>. */
15
16
17
18 #include <stdlib.h>
19 #include <string.h>
20 #include <time.h>
21 #include <Phone/modem.h>
22 #include <gtk/gtk.h>
23 #include <System.h>
24 #include "../../config.h"
25
26
27 /* Debug */
28 /* private */
29 /* types */
30 typedef struct _ModemPlugin
31 {
32 ModemPluginHelper * helper;
33
34 guint source;
35
36 /* widgets */
37 GtkWidget * window;
38 GtkWidget * status;
39 GtkWidget * operator;
40 GtkWidget * roaming;
41 GtkWidget * ca_number;
42 GtkWidget * ca_direction;
43 GtkWidget * me_number;
44 GtkWidget * me_folder;
45 GtkWidget * me_message;
46 GtkWidget * no_type;
47 GtkWidget * no_title;
48 GtkWidget * no_message;
49
50 /* events */
51 ModemEvent event_call;
52 ModemEvent event_contact;
53 ModemEvent event_message;
54 } Debug;
55
56
57 /* prototypes */
58 /* modem */
59 static ModemPlugin * _debug_init(ModemPluginHelper * helper);
60 static void _debug_destroy(ModemPlugin * modem);
61 static int _debug_start(ModemPlugin * modem, unsigned int retry);
62 static int _debug_stop(ModemPlugin * modem);
63 static int _debug_request(ModemPlugin * modem, ModemRequest * request);
64 static int _debug_trigger(ModemPlugin * modem, ModemEventType event);
65
66 /* accessors */
67 static void _debug_set_status(ModemPlugin * modem, char const * status);
68
69 /* callbacks */
70 static gboolean _debug_on_closex(gpointer data);
71 static void _debug_on_call(gpointer data);
72 static void _debug_on_message_send(gpointer data);
73 static void _debug_on_notification(gpointer data);
74 static void _debug_on_operator_set(gpointer data);
75
76
77 /* public */
78 /* variables */
79 ModemPluginDefinition plugin =
80 {
81 "Debug",
82 "applications-development",
83 NULL,
84 _debug_init,
85 _debug_destroy,
86 _debug_start,
87 _debug_stop,
88 _debug_request,
89 _debug_trigger
90 };
91
92
93 /* private */
94 /* functions */
95 /* modem */
_debug_init(ModemPluginHelper * helper)96 static ModemPlugin * _debug_init(ModemPluginHelper * helper)
97 {
98 Debug * debug;
99 GtkSizeGroup * group;
100 GtkWidget * vbox;
101 GtkWidget * notebook;
102 GtkWidget * hbox;
103 GtkWidget * widget;
104
105 if((debug = object_new(sizeof(*debug))) == NULL)
106 return NULL;
107 debug->helper = helper;
108 debug->source = 0;
109 memset(&debug->event_call, 0, sizeof(debug->event_call));
110 memset(&debug->event_contact, 0, sizeof(debug->event_contact));
111 memset(&debug->event_message, 0, sizeof(debug->event_message));
112 /* window */
113 debug->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
114 gtk_container_set_border_width(GTK_CONTAINER(debug->window), 4);
115 gtk_window_set_title(GTK_WINDOW(debug->window), "Debug");
116 g_signal_connect_swapped(G_OBJECT(debug->window), "delete-event",
117 G_CALLBACK(_debug_on_closex), debug);
118 group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
119 notebook = gtk_notebook_new();
120 /* status */
121 #if GTK_CHECK_VERSION(3, 0, 0)
122 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
123 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
124 #else
125 vbox = gtk_vbox_new(FALSE, 4);
126 hbox = gtk_hbox_new(FALSE, 4);
127 #endif
128 widget = gtk_label_new("Status:");
129 #if GTK_CHECK_VERSION(3, 0, 0)
130 g_object_set(widget, "halign", GTK_ALIGN_START, NULL);
131 #else
132 gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.5);
133 #endif
134 gtk_size_group_add_widget(group, widget);
135 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
136 debug->status = gtk_label_new("initialized");
137 #if GTK_CHECK_VERSION(3, 0, 0)
138 g_object_set(debug->status, "halign", GTK_ALIGN_START, NULL);
139 #else
140 gtk_misc_set_alignment(GTK_MISC(debug->status), 0.0, 0.5);
141 #endif
142 gtk_box_pack_start(GTK_BOX(hbox), debug->status, TRUE, TRUE, 0);
143 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
144 /* operator */
145 #if GTK_CHECK_VERSION(3, 0, 0)
146 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
147 #else
148 hbox = gtk_hbox_new(FALSE, 4);
149 #endif
150 widget = gtk_label_new("Operator: ");
151 #if GTK_CHECK_VERSION(3, 0, 0)
152 g_object_set(widget, "halign", GTK_ALIGN_START, NULL);
153 #else
154 gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.5);
155 #endif
156 gtk_size_group_add_widget(group, widget);
157 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
158 debug->operator = gtk_entry_new();
159 g_signal_connect_swapped(debug->operator, "activate", G_CALLBACK(
160 _debug_on_operator_set), debug);
161 gtk_box_pack_start(GTK_BOX(hbox), debug->operator, TRUE, TRUE, 0);
162 widget = gtk_button_new_from_stock(GTK_STOCK_APPLY);
163 g_signal_connect_swapped(widget, "clicked", G_CALLBACK(
164 _debug_on_operator_set), debug);
165 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
166 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
167 #if GTK_CHECK_VERSION(3, 0, 0)
168 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
169 #else
170 hbox = gtk_hbox_new(FALSE, 4);
171 #endif
172 widget = gtk_label_new(NULL);
173 gtk_size_group_add_widget(group, widget);
174 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
175 debug->roaming = gtk_check_button_new_with_mnemonic("_Roaming");
176 gtk_box_pack_start(GTK_BOX(hbox), debug->roaming, TRUE, TRUE, 0);
177 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
178 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox,
179 gtk_label_new("Status"));
180 /* calls */
181 #if GTK_CHECK_VERSION(3, 0, 0)
182 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
183 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
184 #else
185 vbox = gtk_vbox_new(FALSE, 4);
186 hbox = gtk_hbox_new(FALSE, 4);
187 #endif
188 widget = gtk_label_new("Number: ");
189 #if GTK_CHECK_VERSION(3, 0, 0)
190 g_object_set(widget, "halign", GTK_ALIGN_START, NULL);
191 #else
192 gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.5);
193 #endif
194 gtk_size_group_add_widget(group, widget);
195 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
196 debug->ca_number = gtk_entry_new();
197 gtk_box_pack_start(GTK_BOX(hbox), debug->ca_number, TRUE, TRUE, 0);
198 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
199 #if GTK_CHECK_VERSION(3, 0, 0)
200 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
201 #else
202 hbox = gtk_hbox_new(FALSE, 4);
203 #endif
204 widget = gtk_label_new("Direction: ");
205 #if GTK_CHECK_VERSION(3, 0, 0)
206 g_object_set(widget, "halign", GTK_ALIGN_START, NULL);
207 #else
208 gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.5);
209 #endif
210 gtk_size_group_add_widget(group, widget);
211 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
212 #if GTK_CHECK_VERSION(3, 0, 0)
213 debug->ca_direction = gtk_combo_box_text_new();
214 gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(debug->ca_direction), NULL,
215 "Incoming");
216 gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(debug->ca_direction), NULL,
217 "Outgoing");
218 gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(debug->ca_direction), NULL,
219 "Established");
220 #else
221 debug->ca_direction = gtk_combo_box_new_text();
222 gtk_combo_box_append_text(GTK_COMBO_BOX(debug->ca_direction),
223 "Incoming");
224 gtk_combo_box_append_text(GTK_COMBO_BOX(debug->ca_direction),
225 "Outgoing");
226 gtk_combo_box_append_text(GTK_COMBO_BOX(debug->ca_direction),
227 "Established");
228 #endif
229 gtk_combo_box_set_active(GTK_COMBO_BOX(debug->ca_direction), 1);
230 gtk_box_pack_start(GTK_BOX(hbox), debug->ca_direction, TRUE, TRUE, 0);
231 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
232 #if GTK_CHECK_VERSION(3, 0, 0)
233 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
234 #else
235 hbox = gtk_hbox_new(FALSE, 4);
236 #endif
237 widget = gtk_button_new_with_label("Call");
238 gtk_button_set_image(GTK_BUTTON(widget), gtk_image_new_from_icon_name(
239 "call-start", GTK_ICON_SIZE_BUTTON));
240 g_signal_connect_swapped(G_OBJECT(widget), "clicked", G_CALLBACK(
241 _debug_on_call), debug);
242 gtk_box_pack_end(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
243 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
244 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox,
245 gtk_label_new("Calls"));
246 /* messages */
247 #if GTK_CHECK_VERSION(3, 0, 0)
248 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
249 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
250 #else
251 vbox = gtk_vbox_new(FALSE, 4);
252 hbox = gtk_hbox_new(FALSE, 4);
253 #endif
254 widget = gtk_label_new("Number: ");
255 #if GTK_CHECK_VERSION(3, 0, 0)
256 g_object_set(widget, "halign", GTK_ALIGN_START, NULL);
257 #else
258 gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.5);
259 #endif
260 gtk_size_group_add_widget(group, widget);
261 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
262 debug->me_number = gtk_entry_new();
263 gtk_box_pack_start(GTK_BOX(hbox), debug->me_number, TRUE, TRUE, 0);
264 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
265 #if GTK_CHECK_VERSION(3, 0, 0)
266 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
267 #else
268 hbox = gtk_hbox_new(FALSE, 4);
269 #endif
270 widget = gtk_label_new("Folder: ");
271 #if GTK_CHECK_VERSION(3, 0, 0)
272 g_object_set(widget, "halign", GTK_ALIGN_START, NULL);
273 #else
274 gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.5);
275 #endif
276 gtk_size_group_add_widget(group, widget);
277 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
278 #if GTK_CHECK_VERSION(3, 0, 0)
279 debug->me_folder = gtk_combo_box_text_new();
280 gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(debug->me_folder), NULL,
281 "Unknown");
282 gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(debug->me_folder), NULL,
283 "Inbox");
284 gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(debug->me_folder), NULL,
285 "Sent");
286 gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(debug->me_folder), NULL,
287 "Drafts");
288 gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(debug->me_folder), NULL,
289 "Trash");
290 #else
291 debug->me_folder = gtk_combo_box_new_text();
292 gtk_combo_box_append_text(GTK_COMBO_BOX(debug->me_folder), "Unknown");
293 gtk_combo_box_append_text(GTK_COMBO_BOX(debug->me_folder), "Inbox");
294 gtk_combo_box_append_text(GTK_COMBO_BOX(debug->me_folder), "Sent");
295 gtk_combo_box_append_text(GTK_COMBO_BOX(debug->me_folder), "Drafts");
296 gtk_combo_box_append_text(GTK_COMBO_BOX(debug->me_folder), "Trash");
297 #endif
298 gtk_combo_box_set_active(GTK_COMBO_BOX(debug->me_folder), 1);
299 gtk_box_pack_start(GTK_BOX(hbox), debug->me_folder, TRUE, TRUE, 0);
300 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
301 #if GTK_CHECK_VERSION(3, 0, 0)
302 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
303 #else
304 hbox = gtk_hbox_new(FALSE, 4);
305 #endif
306 widget = gtk_label_new("Message: ");
307 #if GTK_CHECK_VERSION(3, 0, 0)
308 g_object_set(widget, "halign", GTK_ALIGN_START,
309 "valign", GTK_ALIGN_START, NULL);
310 #else
311 gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.0);
312 #endif
313 gtk_size_group_add_widget(group, widget);
314 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
315 widget = gtk_scrolled_window_new(NULL, NULL);
316 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(widget),
317 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
318 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(widget),
319 GTK_SHADOW_ETCHED_IN);
320 debug->me_message = gtk_text_view_new();
321 gtk_container_add(GTK_CONTAINER(widget), debug->me_message);
322 gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0);
323 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
324 #if GTK_CHECK_VERSION(3, 0, 0)
325 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
326 #else
327 hbox = gtk_hbox_new(FALSE, 4);
328 #endif
329 widget = gtk_button_new_with_label("Send");
330 gtk_button_set_image(GTK_BUTTON(widget), gtk_image_new_from_icon_name(
331 "mail-send", GTK_ICON_SIZE_BUTTON));
332 g_signal_connect_swapped(G_OBJECT(widget), "clicked", G_CALLBACK(
333 _debug_on_message_send), debug);
334 gtk_box_pack_end(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
335 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
336 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox,
337 gtk_label_new("Messages"));
338 /* notification */
339 #if GTK_CHECK_VERSION(3, 0, 0)
340 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 4);
341 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
342 #else
343 vbox = gtk_vbox_new(FALSE, 4);
344 hbox = gtk_hbox_new(FALSE, 4);
345 #endif
346 widget = gtk_label_new("Type: ");
347 #if GTK_CHECK_VERSION(3, 0, 0)
348 g_object_set(widget, "halign", GTK_ALIGN_START, NULL);
349 #else
350 gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.5);
351 #endif
352 gtk_size_group_add_widget(group, widget);
353 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
354 #if GTK_CHECK_VERSION(3, 0, 0)
355 debug->no_type = gtk_combo_box_text_new();
356 gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(debug->no_type), NULL,
357 "Information");
358 gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(debug->no_type), NULL,
359 "Error");
360 gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(debug->no_type), NULL,
361 "Warning");
362 #else
363 debug->no_type = gtk_combo_box_new_text();
364 gtk_combo_box_append_text(GTK_COMBO_BOX(debug->no_type), "Information");
365 gtk_combo_box_append_text(GTK_COMBO_BOX(debug->no_type), "Error");
366 gtk_combo_box_append_text(GTK_COMBO_BOX(debug->no_type), "Warning");
367 #endif
368 gtk_combo_box_set_active(GTK_COMBO_BOX(debug->no_type), 0);
369 gtk_box_pack_start(GTK_BOX(hbox), debug->no_type, TRUE, TRUE, 0);
370 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
371 /* notification: title */
372 #if GTK_CHECK_VERSION(3, 0, 0)
373 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
374 #else
375 hbox = gtk_hbox_new(FALSE, 4);
376 #endif
377 widget = gtk_label_new("Title: ");
378 #if GTK_CHECK_VERSION(3, 0, 0)
379 g_object_set(widget, "halign", GTK_ALIGN_START, NULL);
380 #else
381 gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.5);
382 #endif
383 gtk_size_group_add_widget(group, widget);
384 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
385 debug->no_title = gtk_entry_new();
386 g_signal_connect_swapped(debug->no_title, "activate", G_CALLBACK(
387 _debug_on_notification), debug);
388 gtk_box_pack_start(GTK_BOX(hbox), debug->no_title, TRUE, TRUE, 0);
389 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
390 /* notification: message */
391 #if GTK_CHECK_VERSION(3, 0, 0)
392 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
393 #else
394 hbox = gtk_hbox_new(FALSE, 4);
395 #endif
396 widget = gtk_label_new("Message: ");
397 #if GTK_CHECK_VERSION(3, 0, 0)
398 g_object_set(widget, "halign", GTK_ALIGN_START,
399 "valign", GTK_ALIGN_START, NULL);
400 #else
401 gtk_misc_set_alignment(GTK_MISC(widget), 0.0, 0.0);
402 #endif
403 gtk_size_group_add_widget(group, widget);
404 gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
405 widget = gtk_scrolled_window_new(NULL, NULL);
406 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(widget),
407 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
408 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(widget),
409 GTK_SHADOW_ETCHED_IN);
410 debug->no_message = gtk_text_view_new();
411 gtk_container_add(GTK_CONTAINER(widget), debug->no_message);
412 gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0);
413 gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0);
414 /* notification: send */
415 #if GTK_CHECK_VERSION(3, 0, 0)
416 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 4);
417 #else
418 hbox = gtk_hbox_new(FALSE, 4);
419 #endif
420 widget = gtk_button_new_with_label("Send");
421 gtk_button_set_image(GTK_BUTTON(widget), gtk_image_new_from_icon_name(
422 "mail-send", GTK_ICON_SIZE_BUTTON));
423 g_signal_connect_swapped(widget, "clicked", G_CALLBACK(
424 _debug_on_notification), debug);
425 gtk_box_pack_end(GTK_BOX(hbox), widget, FALSE, TRUE, 0);
426 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
427 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox,
428 gtk_label_new("Notifications"));
429 gtk_container_add(GTK_CONTAINER(debug->window), notebook);
430 gtk_widget_show_all(debug->window);
431 return debug;
432 }
433
434
435 /* debug_destroy */
_debug_destroy(ModemPlugin * modem)436 static void _debug_destroy(ModemPlugin * modem)
437 {
438 Debug * debug = modem;
439
440 if(debug->source != 0)
441 g_source_remove(debug->source);
442 gtk_widget_destroy(debug->window);
443 object_delete(debug);
444 }
445
446
447 /* debug_start */
448 static gboolean _start_on_idle(gpointer data);
449
_debug_start(ModemPlugin * modem,unsigned int retry)450 static int _debug_start(ModemPlugin * modem, unsigned int retry)
451 {
452 Debug * debug = modem;
453
454 _debug_set_status(modem, "starting");
455 if(debug->source != 0)
456 g_source_remove(debug->source);
457 debug->source = g_idle_add(_start_on_idle, modem);
458 return 0;
459 }
460
_start_on_idle(gpointer data)461 static gboolean _start_on_idle(gpointer data)
462 {
463 ModemPlugin * modem = data;
464 Debug * debug = modem;
465
466 debug->source = 0;
467 _debug_set_status(modem, "started");
468 return FALSE;
469 }
470
471
472 /* debug_stop */
473 static gboolean _stop_on_idle(gpointer data);
474
_debug_stop(ModemPlugin * modem)475 static int _debug_stop(ModemPlugin * modem)
476 {
477 Debug * debug = modem;
478
479 _debug_set_status(modem, "stopping");
480 if(debug->source != 0)
481 g_source_remove(debug->source);
482 debug->source = g_idle_add(_stop_on_idle, modem);
483 return 0;
484 }
485
_stop_on_idle(gpointer data)486 static gboolean _stop_on_idle(gpointer data)
487 {
488 ModemPlugin * modem = data;
489 Debug * debug = modem;
490
491 debug->source = 0;
492 _debug_set_status(modem, "stopped");
493 return FALSE;
494 }
495
496
497 /* debug_request */
_debug_request(ModemPlugin * modem,ModemRequest * request)498 static int _debug_request(ModemPlugin * modem, ModemRequest * request)
499 {
500 Debug * debug = modem;
501 ModemPluginHelper * helper = debug->helper;
502 ModemEvent event;
503 unsigned int u;
504 char buf[32];
505
506 if(request == NULL)
507 return -1;
508 memset(&event, 0, sizeof(event));
509 switch(request->type)
510 {
511 case MODEM_REQUEST_CONTACT_DELETE:
512 event.type = MODEM_EVENT_TYPE_CONTACT_DELETED;
513 event.contact_deleted.id = request->contact_delete.id;
514 helper->event(helper->modem, &event);
515 break;
516 case MODEM_REQUEST_CONTACT_EDIT:
517 debug->event_contact.type = MODEM_EVENT_TYPE_CONTACT;
518 u = debug->event_contact.contact.id;
519 debug->event_contact.contact.id
520 = request->contact_edit.id;
521 debug->event_contact.contact.status
522 = rand() % MODEM_CONTACT_STATUS_COUNT;
523 debug->event_contact.contact.name
524 = request->contact_edit.name;
525 debug->event_contact.contact.number
526 = request->contact_edit.number;
527 helper->event(helper->modem, &debug->event_contact);
528 debug->event_contact.contact.id = u;
529 break;
530 case MODEM_REQUEST_CONTACT_NEW:
531 debug->event_contact.type = MODEM_EVENT_TYPE_CONTACT;
532 debug->event_contact.contact.id++;
533 debug->event_contact.contact.status
534 = rand() % MODEM_CONTACT_STATUS_COUNT;
535 debug->event_contact.contact.name
536 = request->contact_new.name;
537 debug->event_contact.contact.number
538 = request->contact_new.number;
539 helper->event(helper->modem, &debug->event_contact);
540 break;
541 case MODEM_REQUEST_DTMF_SEND:
542 u = request->dtmf_send.dtmf;
543 snprintf(buf, sizeof(buf), "Sending DTMF '%c'\n", u);
544 event.type = MODEM_EVENT_TYPE_NOTIFICATION;
545 event.notification.content = buf;
546 debug->helper->event(debug->helper->modem, &event);
547 break;
548 case MODEM_REQUEST_MESSAGE_DELETE:
549 event.type = MODEM_EVENT_TYPE_MESSAGE_DELETED;
550 event.message_deleted.id = request->message_delete.id;
551 helper->event(helper->modem, &event);
552 break;
553 default:
554 break;
555 }
556 return 0;
557 }
558
559
560 /* debug_trigger */
_debug_trigger(ModemPlugin * modem,ModemEventType event)561 static int _debug_trigger(ModemPlugin * modem, ModemEventType event)
562 {
563 Debug * debug = modem;
564 ModemEvent e;
565
566 memset(&e, 0, sizeof(e));
567 switch(event)
568 {
569 case MODEM_EVENT_TYPE_MODEL:
570 e.type = MODEM_EVENT_TYPE_MODEL;
571 e.model.vendor = "Phone";
572 e.model.name = PACKAGE;
573 e.model.version = VERSION;
574 e.model.serial = "SERIAL-NUMBER";
575 debug->helper->event(debug->helper->modem, &e);
576 return 0;
577 default:
578 return 1;
579 }
580 }
581
582
583 /* accessors */
584 /* debug_set_status */
_debug_set_status(ModemPlugin * modem,char const * status)585 static void _debug_set_status(ModemPlugin * modem, char const * status)
586 {
587 Debug * debug = modem;
588
589 gtk_label_set_text(GTK_LABEL(debug->status), status);
590 }
591
592
593 /* callbacks */
594 /* debug_on_closex */
_debug_on_closex(gpointer data)595 static gboolean _debug_on_closex(gpointer data)
596 {
597 ModemPlugin * modem = data;
598 Debug * debug = modem;
599
600 gtk_widget_hide(debug->window);
601 gtk_main_quit();
602 return TRUE;
603 }
604
605
606 /* debug_on_call */
_debug_on_call(gpointer data)607 static void _debug_on_call(gpointer data)
608 {
609 ModemPlugin * modem = data;
610 Debug * debug = modem;
611 int d;
612
613 debug->event_call.call.type = MODEM_EVENT_TYPE_CALL;
614 debug->event_call.call.call_type = MODEM_CALL_TYPE_VOICE;
615 d = gtk_combo_box_get_active(GTK_COMBO_BOX(debug->ca_direction));
616 switch(d)
617 {
618 case 0:
619 debug->event_call.call.direction
620 = MODEM_CALL_DIRECTION_INCOMING;
621 debug->event_call.call.status
622 = MODEM_CALL_STATUS_RINGING;
623 break;
624 case 1:
625 debug->event_call.call.direction
626 = MODEM_CALL_DIRECTION_OUTGOING;
627 debug->event_call.call.status
628 = MODEM_CALL_STATUS_RINGING;
629 break;
630 case 2:
631 debug->event_call.call.direction
632 = MODEM_CALL_DIRECTION_NONE;
633 debug->event_call.call.status
634 = MODEM_CALL_STATUS_ACTIVE;
635 break;
636 default:
637 return;
638 }
639 debug->event_call.call.number = gtk_entry_get_text(GTK_ENTRY(
640 debug->ca_number));
641 debug->helper->event(debug->helper->modem, &debug->event_call);
642 }
643
644
645 /* debug_on_message_send */
_debug_on_message_send(gpointer data)646 static void _debug_on_message_send(gpointer data)
647 {
648 ModemPlugin * modem = data;
649 Debug * debug = modem;
650 GtkTextBuffer * tbuf;
651 GtkTextIter start;
652 GtkTextIter end;
653 gchar * content;
654
655 debug->event_message.message.type = MODEM_EVENT_TYPE_MESSAGE;
656 debug->event_message.message.id++;
657 debug->event_message.message.date = time(NULL);
658 debug->event_message.message.number = gtk_entry_get_text(GTK_ENTRY(
659 debug->me_number));
660 debug->event_message.message.folder = gtk_combo_box_get_active(
661 GTK_COMBO_BOX(debug->me_folder));
662 debug->event_message.message.status = MODEM_MESSAGE_STATUS_NEW;
663 debug->event_message.message.encoding = MODEM_MESSAGE_ENCODING_UTF8;
664 tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(debug->me_message));
665 gtk_text_buffer_get_start_iter(tbuf, &start);
666 gtk_text_buffer_get_end_iter(tbuf, &end);
667 content = gtk_text_buffer_get_text(tbuf, &start, &end, FALSE);
668 debug->event_message.message.length = strlen(content);
669 debug->event_message.message.content = content;
670 debug->helper->event(debug->helper->modem, &debug->event_message);
671 g_free(content);
672 }
673
674
675 /* debug_on_notification */
_debug_on_notification(gpointer data)676 static void _debug_on_notification(gpointer data)
677 {
678 ModemPlugin * modem = data;
679 Debug * debug = modem;
680 ModemEvent event;
681 GtkTextBuffer * tbuf;
682 GtkTextIter start;
683 GtkTextIter end;
684 gchar * p;
685
686 memset(&event, 0, sizeof(event));
687 event.type = MODEM_EVENT_TYPE_NOTIFICATION;
688 event.notification.ntype = gtk_combo_box_get_active(
689 GTK_COMBO_BOX(debug->no_type));
690 event.notification.title = gtk_entry_get_text(GTK_ENTRY(
691 debug->no_title));
692 tbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(debug->no_message));
693 gtk_text_buffer_get_start_iter(tbuf, &start);
694 gtk_text_buffer_get_end_iter(tbuf, &end);
695 p = gtk_text_buffer_get_text(tbuf, &start, &end, FALSE);
696 event.notification.content = p;
697 debug->helper->event(debug->helper->modem, &event);
698 g_free(p);
699 }
700
701
702 /* debug_on_operator_set */
_debug_on_operator_set(gpointer data)703 static void _debug_on_operator_set(gpointer data)
704 {
705 ModemPlugin * modem = data;
706 Debug * debug = modem;
707 ModemEvent event;
708 char const * p;
709
710 memset(&event, 0, sizeof(event));
711 p = gtk_entry_get_text(GTK_ENTRY(debug->operator));
712 event.type = MODEM_EVENT_TYPE_REGISTRATION;
713 event.registration.status = MODEM_REGISTRATION_STATUS_REGISTERED;
714 event.registration._operator = p;
715 event.registration.roaming = gtk_toggle_button_get_active(
716 GTK_TOGGLE_BUTTON(debug->roaming));
717 debug->helper->event(debug->helper->modem, &event);
718 }
719