b6f3c9f75a854be13aaa55df7c6a2af6b8d7a68a
[debian/lxpanel.git] / plugins / netstatus / netstatus-dialog.c
1 /*
2 * Copyright (C) 2003 Sun Microsystems, Inc.
3 * Copyright (C) 2004 Red Hat Inc.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18 * 02111-1307, USA.
19 *
20 * Authors:
21 * Mark McLoughlin <mark@skynet.ie>
22 */
23
24 #ifdef HAVE_CONFIG_H
25 # include <config.h>
26 #endif
27
28 #include <gtk/gtk.h>
29
30 #include <glib/gi18n.h>
31 #include "netstatus-dialog.h"
32 #include <libfm/fm-gtk.h>
33
34 #include <string.h>
35 /* #include <gconf/gconf-client.h> */
36
37 #include "netstatus-icon.h"
38 #include "netstatus-util.h"
39
40 #define NETWORK_CONFIG_TOOL_DIR "/apps/netstatus_applet"
41 #define NETWORK_CONFIG_TOOL_KEY NETWORK_CONFIG_TOOL_DIR "/config_tool"
42
43 #if 0 /* stripped-down version does nothing to configurators. */
44 static const char *network_config_tools[] = {
45 "network-admin --configure %i",
46 "redhat-config-network",
47 "system-control-network"
48 };
49 #endif
50
51 #define UNKNOWN_STR(t,s) G_STMT_START { \
52 if (!((t) = (s))) (t) = _("Unknown"); \
53 } G_STMT_END
54
55 typedef struct
56 {
57 GtkBuilder* builder;
58 GtkWidget *dialog;
59
60 NetstatusIface *iface;
61 NetstatusIcon *icon;
62
63 /* GConfClient *client; */
64 char *config_tool;
65 /* guint listener; */
66
67 GtkWidget *name;
68 GtkWidget *name_entry; /* child GtkEntry of name (GtkComboBoxEntry) */
69 GtkWidget *status;
70 GtkWidget *received;
71 GtkWidget *sent;
72 GtkWidget *signal_strength_frame;
73 GtkWidget *signal_strength_bar;
74 GtkWidget *signal_strength_label;
75 GtkWidget *configure_button;
76
77 GtkWidget *inet4_frame;
78 GtkWidget *inet4_table;
79 GtkWidget *inet4_addr;
80 GtkWidget *inet4_addr_title;
81 GtkWidget *inet4_dest;
82 GtkWidget *inet4_dest_title;
83 GtkWidget *inet4_bcast;
84 GtkWidget *inet4_bcast_title;
85 GtkWidget *inet4_mask;
86 GtkWidget *inet4_mask_title;
87
88 GtkWidget *dev_frame;
89 GtkWidget *dev_type;
90 GtkWidget *dev_addr;
91
92 guint iface_list_monitor;
93 int n_ifaces;
94 } NetstatusDialogData;
95
96
97 static void
98 netstatus_dialog_update_state (NetstatusDialogData *data)
99 {
100 NetstatusState state;
101
102 state = netstatus_iface_get_state (data->iface);
103 gtk_label_set_text (GTK_LABEL (data->status),
104 netstatus_get_state_string (state));
105 }
106
107 static void
108 netstatus_dialog_update_name (NetstatusDialogData *data)
109 {
110 const char *iface_name;
111 const char *text;
112
113 iface_name = netstatus_iface_get_name (data->iface);
114 if (!iface_name)
115 {
116 gtk_window_set_title (GTK_WINDOW (data->dialog),
117 _("Connection Properties"));
118 }
119 else
120 {
121 char *p;
122
123 p = g_strdup_printf (_("Connection Properties: %s"), iface_name);
124 gtk_window_set_title (GTK_WINDOW (data->dialog), p);
125 g_free (p);
126 }
127
128 UNKNOWN_STR (text, iface_name);
129 gtk_entry_set_text (GTK_ENTRY (data->name_entry), text);
130 }
131
132 static inline void
133 print_packets_string (GString *str,
134 gulong packets)
135 {
136 g_string_printf (str, ngettext ("%lu packet", "%lu packets", packets), packets);
137 }
138
139 static inline void
140 print_bytes_string (GString *str,
141 guint64 bytes)
142 {
143 if (bytes > 1 << 30)
144 {
145 bytes = (bytes * 10) / (1 << 30);
146
147 g_string_append_printf (str, " (%"G_GUINT64_FORMAT".%"G_GUINT64_FORMAT" GiB)",
148 bytes / 10, bytes % 10);
149 }
150 else if (bytes > 1 << 20)
151 {
152 bytes = (bytes * 10) / (1 << 20);
153
154 g_string_append_printf (str, " (%"G_GUINT64_FORMAT".%"G_GUINT64_FORMAT" MiB)",
155 bytes / 10, bytes % 10);
156 }
157 else if (bytes > 1 << 10)
158 {
159 bytes = (bytes * 10) / (1 << 10);
160
161 g_string_append_printf (str, " (%"G_GUINT64_FORMAT".%"G_GUINT64_FORMAT" KiB)",
162 bytes / 10, bytes % 10);
163 }
164 else if (bytes > 0)
165 {
166 g_string_append_printf (str, " (%"G_GUINT64_FORMAT" B)", bytes);
167 }
168 }
169
170 static void
171 netstatus_dialog_update_activity (NetstatusDialogData *data)
172 {
173 NetstatusStats stats = { 0, };
174 GString *str;
175
176 netstatus_iface_get_statistics (data->iface, &stats);
177
178 str = g_string_new (NULL);
179
180 print_packets_string (str, stats.out_packets);
181 print_bytes_string (str, stats.out_bytes);
182 gtk_label_set_text (GTK_LABEL (data->sent), str->str);
183
184 print_packets_string (str, stats.in_packets);
185 print_bytes_string (str, stats.in_bytes);
186 gtk_label_set_text (GTK_LABEL (data->received), str->str);
187
188 g_string_free (str, TRUE);
189 }
190
191 static void
192 netstatus_dialog_update_signal_strength (NetstatusDialogData *data)
193 {
194 if (netstatus_iface_get_is_wireless (data->iface))
195 {
196 int signal_strength;
197 char *str;
198
199 gtk_widget_show (data->signal_strength_frame);
200
201 signal_strength = netstatus_iface_get_signal_strength (data->iface);
202
203 gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (data->signal_strength_bar),
204 signal_strength == 0 ? 0.0 : signal_strength / 100.0);
205
206 str = g_strdup_printf ("%d%%\n", signal_strength);
207 gtk_label_set_text (GTK_LABEL (data->signal_strength_label), str);
208 g_free (str);
209 }
210 else
211 {
212 gtk_widget_hide (data->signal_strength_frame);
213 }
214 }
215
216 static void
217 netstatus_dialog_update_inet4_support (NetstatusDialogData *data)
218 {
219 char *addr = NULL;
220 char *dest = NULL;
221 char *bcast = NULL;
222 char *mask = NULL;
223
224 if (netstatus_iface_get_inet4_details (data->iface, &addr, &dest, &bcast, &mask))
225 {
226 gtk_widget_show (data->inet4_frame);
227
228 /* Address */
229 if (addr)
230 {
231 gtk_table_set_row_spacing (GTK_TABLE (data->inet4_table), 0, 6);
232 gtk_label_set_text (GTK_LABEL (data->inet4_addr), addr);
233 gtk_widget_show (data->inet4_addr);
234 gtk_widget_show (data->inet4_addr_title);
235 }
236 else
237 {
238 gtk_table_set_row_spacing (GTK_TABLE (data->inet4_table), 0, 0);
239 gtk_widget_hide (data->inet4_addr);
240 gtk_widget_hide (data->inet4_addr_title);
241 }
242
243 /* Destination */
244 if (dest)
245 {
246 gtk_table_set_row_spacing (GTK_TABLE (data->inet4_table), 1, 6);
247 gtk_label_set_text (GTK_LABEL (data->inet4_dest), dest);
248 gtk_widget_show (data->inet4_dest);
249 gtk_widget_show (data->inet4_dest_title);
250 }
251 else
252 {
253 gtk_table_set_row_spacing (GTK_TABLE (data->inet4_table), 1, 0);
254 gtk_widget_hide (data->inet4_dest);
255 gtk_widget_hide (data->inet4_dest_title);
256 }
257
258 /* Broadcast */
259 if (bcast)
260 {
261 gtk_table_set_row_spacing (GTK_TABLE (data->inet4_table), 2, 6);
262 gtk_label_set_text (GTK_LABEL (data->inet4_bcast), bcast);
263 gtk_widget_show (data->inet4_bcast);
264 gtk_widget_show (data->inet4_bcast_title);
265 }
266 else
267 {
268 gtk_table_set_row_spacing (GTK_TABLE (data->inet4_table), 2, 0);
269 gtk_widget_hide (data->inet4_bcast);
270 gtk_widget_hide (data->inet4_bcast_title);
271 }
272
273 /* Subnet Mask */
274 if (mask)
275 {
276 gtk_label_set_text (GTK_LABEL (data->inet4_mask), mask);
277 gtk_widget_show (data->inet4_mask);
278 gtk_widget_show (data->inet4_mask_title);
279 }
280 else
281 {
282 gtk_widget_hide (data->inet4_mask);
283 gtk_widget_hide (data->inet4_mask_title);
284 }
285
286 g_free (addr);
287 g_free (dest);
288 g_free (bcast);
289 g_free (mask);
290 }
291 else
292 {
293 gtk_widget_hide (data->inet4_frame);
294 }
295 }
296
297 static void
298 netstatus_dialog_update_device_support (NetstatusDialogData *data)
299 {
300 const char *type = NULL;
301 char *addr = NULL;
302
303 if (netstatus_iface_get_device_details (data->iface, &type, &addr))
304 {
305 g_assert (type != NULL);
306
307 gtk_widget_show (data->dev_frame);
308
309 /* Device type */
310 gtk_label_set_text (GTK_LABEL (data->dev_type), type);
311
312 /* Address */
313 if (addr)
314 gtk_label_set_text (GTK_LABEL (data->dev_addr), addr);
315 else
316 gtk_label_set_text (GTK_LABEL (data->dev_addr), _("Unknown"));
317
318 g_free (addr);
319 }
320 else
321 {
322 gtk_widget_hide (data->dev_frame);
323 }
324 }
325
326 static void
327 netstatus_dialog_iface_state_changed (NetstatusIface *iface,
328 GParamSpec *pspec,
329 NetstatusDialogData *data)
330 {
331 netstatus_dialog_update_state (data);
332 netstatus_dialog_update_inet4_support (data);
333 netstatus_dialog_update_device_support (data);
334 }
335
336 static void
337 netstatus_dialog_iface_stats_changed (NetstatusIface *iface,
338 GParamSpec *pspec,
339 NetstatusDialogData *data)
340 {
341 netstatus_dialog_update_activity (data);
342 }
343
344 static void
345 netstatus_dialog_iface_signal_strength_changed (NetstatusIface *iface,
346 GParamSpec *pspec,
347 NetstatusDialogData *data)
348 {
349 netstatus_dialog_update_signal_strength (data);
350 }
351
352 static void
353 netstatus_dialog_iface_name_changed (NetstatusIface *iface,
354 GParamSpec *pspec,
355 NetstatusDialogData *data)
356 {
357 netstatus_dialog_update_name (data);
358 netstatus_dialog_update_signal_strength (data);
359 }
360
361 static void
362 netstatus_dialog_set_iface_name (NetstatusDialogData *data,
363 GtkEntry *entry)
364 {
365 const char *iface_name;
366
367 iface_name = gtk_entry_get_text (entry);
368 if (iface_name && iface_name [0])
369 {
370 netstatus_iface_set_name (data->iface, iface_name);
371
372 gtk_widget_set_sensitive (data->configure_button,
373 !netstatus_iface_get_is_loopback (data->iface));
374 }
375 }
376
377 static void
378 netstatus_dialog_response (GtkWidget *dialog,
379 int response)
380 {
381 switch (response)
382 {
383 case GTK_RESPONSE_HELP:
384 {
385 GError *error = NULL;
386 GdkScreen *screen;
387
388 screen = gtk_window_get_screen (GTK_WINDOW (dialog));
389
390 // gnome_help_display_on_screen ("gnome-netstatus", "gnome-netstatus-props", screen, &error);
391
392 if (error)
393 {
394 GtkWidget *message_dialog;
395
396 message_dialog = gtk_message_dialog_new (GTK_WINDOW (dialog),
397 GTK_DIALOG_DESTROY_WITH_PARENT,
398 GTK_MESSAGE_ERROR,
399 GTK_BUTTONS_CLOSE,
400 _("There was an error displaying help:\n%s"),
401 error->message);
402
403 gtk_window_set_resizable (GTK_WINDOW (message_dialog), FALSE);
404 gtk_window_set_screen (GTK_WINDOW (message_dialog), screen);
405
406 g_signal_connect (message_dialog, "response",
407 G_CALLBACK (gtk_widget_destroy),
408 NULL);
409
410 gtk_widget_show (message_dialog);
411
412 g_error_free (error);
413 }
414 }
415 break;
416 default:
417 gtk_widget_hide (dialog);
418 break;
419 }
420 }
421
422 static void
423 netstatus_dialog_destroy (GtkWidget *dialog)
424 {
425 NetstatusDialogData *data;
426
427 data = g_object_get_data (G_OBJECT (dialog), "netstatus-dialog-data");
428 if (!data)
429 return;
430
431 if (data->config_tool)
432 g_free (data->config_tool);
433 data->config_tool = NULL;
434
435 /*
436 if (data->listener)
437 {
438 g_assert (data->client != NULL);
439
440 gconf_client_notify_remove (data->client, data->listener);
441 data->listener = 0;
442
443 gconf_client_remove_dir (data->client, NETWORK_CONFIG_TOOL_DIR, NULL);
444 }
445
446 if (data->client)
447 g_object_unref (data->client);
448 data->client = NULL;
449 */
450
451 if (data->iface_list_monitor)
452 g_source_remove (data->iface_list_monitor);
453 data->iface_list_monitor = 0;
454
455 if (data->iface)
456 g_object_unref (data->iface);
457 data->iface = NULL;
458
459 g_free (data);
460 }
461
462 static gboolean
463 netstatus_dialog_check_config_tool (NetstatusDialogData *dialog_data,
464 const char *config_tool)
465 {
466 char **argv = NULL;
467 gboolean found = FALSE;
468
469 if (config_tool && g_shell_parse_argv (config_tool, NULL, &argv, NULL))
470 {
471 char *path;
472
473 g_assert (argv != NULL);
474
475 if ((path = g_find_program_in_path (argv [0])))
476 {
477 if (dialog_data->config_tool)
478 g_free (dialog_data->config_tool);
479 dialog_data->config_tool = g_strdup (config_tool);
480 found = TRUE;
481 }
482
483 g_free (path);
484 g_strfreev (argv);
485 }
486
487 return found;
488 }
489
490 /*
491 static void
492 netstatus_dialog_config_tool_notify (GConfClient *client,
493 guint cnx_id,
494 GConfEntry *entry,
495 NetstatusDialogData *dialog_data)
496 {
497 if (!entry->value || !entry->value->type == GCONF_VALUE_STRING)
498 return;
499
500 netstatus_dialog_check_config_tool (dialog_data,
501 gconf_value_get_string (entry->value));
502 }
503 */
504
505 static void
506 netstatus_dialog_detect_configuration_tool (NetstatusDialogData *dialog_data)
507 {
508 /*
509 char *config_tool;
510 int i;
511
512 dialog_data->client = gconf_client_get_default ();
513
514 gconf_client_add_dir (dialog_data->client,
515 NETWORK_CONFIG_TOOL_DIR,
516 GCONF_CLIENT_PRELOAD_NONE,
517 NULL);
518
519 dialog_data->listener =
520 gconf_client_notify_add (dialog_data->client,
521 NETWORK_CONFIG_TOOL_KEY,
522 (GConfClientNotifyFunc) netstatus_dialog_config_tool_notify,
523 dialog_data, NULL, NULL);
524
525 config_tool = gconf_client_get_string (dialog_data->client,
526 NETWORK_CONFIG_TOOL_KEY,
527 NULL);
528 if (netstatus_dialog_check_config_tool (dialog_data, config_tool))
529 {
530 g_free (config_tool);
531 return;
532 }
533
534 for (i = 0; i < G_N_ELEMENTS (network_config_tools); i++)
535 {
536 if (netstatus_dialog_check_config_tool (dialog_data, network_config_tools [i]))
537 break;
538 }
539 */
540 }
541
542 static void
543 netstatus_iface_configure (GtkWidget *configure_button,
544 NetstatusDialogData *dialog_data)
545 {
546 GString *command;
547 char **argv = NULL;
548 int i;
549
550 g_return_if_fail (dialog_data != NULL);
551 g_return_if_fail (dialog_data->config_tool != NULL);
552
553 g_shell_parse_argv (dialog_data->config_tool, NULL, &argv, NULL);
554
555 /* We've already verified config_tool as valid */
556 g_assert (argv != NULL);
557
558 command = g_string_new (argv [0]);
559
560 for (i = 1; argv [i]; i++)
561 {
562 command = g_string_append_c (command, ' ');
563
564 if (!strcmp (argv [i], "%i"))
565 command = g_string_append (command,
566 netstatus_iface_get_name (dialog_data->iface));
567 else
568 command = g_string_append (command, argv [i]);
569 }
570
571 fm_launch_command_simple(GTK_WINDOW (dialog_data->dialog), NULL,
572 G_APP_INFO_CREATE_NONE, command->str, NULL);
573
574 g_string_free (command, TRUE);
575 g_strfreev (argv);
576 }
577
578 static void
579 netstatus_dialog_setup_configure_button (NetstatusDialogData *data)
580 {
581 data->configure_button = (GtkWidget*)gtk_builder_get_object(data->builder, "configure_button");
582
583 g_signal_connect (data->configure_button, "clicked",
584 G_CALLBACK (netstatus_iface_configure), data);
585
586 netstatus_dialog_detect_configuration_tool (data);
587
588 if (!data->config_tool)
589 gtk_widget_hide (data->configure_button);
590
591 gtk_widget_set_sensitive (data->configure_button,
592 !netstatus_iface_get_is_loopback (data->iface));
593 }
594
595 static void
596 netstatus_dialog_setup_connection (NetstatusDialogData *data)
597 {
598 GtkWidget *hbox;
599 GtkWidget *icon;
600 GtkListStore* model;
601
602 hbox = (GtkWidget*)gtk_builder_get_object(data->builder, "connection_hbox");
603
604 icon = netstatus_icon_new (data->iface);
605 netstatus_icon_set_tooltips_enabled (NETSTATUS_ICON (icon), FALSE);
606 netstatus_icon_set_show_signal (NETSTATUS_ICON (icon), FALSE);
607 gtk_box_pack_end (GTK_BOX (hbox), icon, FALSE, TRUE, 4);
608 gtk_widget_show (icon);
609
610 data->icon = NETSTATUS_ICON (icon);
611
612 data->name = (GtkWidget*)gtk_builder_get_object(data->builder, "name_combo");
613 data->name_entry = gtk_bin_get_child((GtkBin*)data->name);
614 model = gtk_list_store_new(1, G_TYPE_STRING);
615 gtk_combo_box_set_model(GTK_COMBO_BOX(data->name), GTK_TREE_MODEL(model));
616 #if GTK_CHECK_VERSION(2, 24, 0)
617 gtk_combo_box_set_entry_text_column(GTK_COMBO_BOX(data->name), 0);
618 #else
619 gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(data->name), 0);
620 #endif
621 g_object_unref(model);
622
623 data->status = (GtkWidget*)gtk_builder_get_object(data->builder, "status_label");
624
625 netstatus_dialog_update_name (data);
626 netstatus_dialog_update_state (data);
627 }
628
629 static void
630 netstatus_dialog_setup_activity (NetstatusDialogData *data)
631 {
632 data->sent = (GtkWidget*)gtk_builder_get_object(data->builder, "sent_label");
633 data->received = (GtkWidget*)gtk_builder_get_object(data->builder, "received_label");
634
635 netstatus_dialog_update_activity (data);
636 }
637
638 static void
639 netstatus_dialog_setup_signal_strength_details (NetstatusDialogData *data)
640 {
641 data->signal_strength_frame = (GtkWidget*)gtk_builder_get_object(data->builder, "signal_strength_frame");
642 data->signal_strength_bar = (GtkWidget*)gtk_builder_get_object(data->builder, "signal_strength_bar");
643 data->signal_strength_label = (GtkWidget*)gtk_builder_get_object(data->builder, "signal_strength_label");
644
645 netstatus_dialog_update_signal_strength (data);
646 }
647
648 static void
649 netstatus_dialog_setup_inet4_support (NetstatusDialogData *data)
650 {
651 data->inet4_frame = (GtkWidget*)gtk_builder_get_object(data->builder, "inet4_frame");
652 data->inet4_table = (GtkWidget*)gtk_builder_get_object(data->builder, "inet4_table");
653 data->inet4_addr = (GtkWidget*)gtk_builder_get_object(data->builder, "inet4_addr_label");
654 data->inet4_addr_title = (GtkWidget*)gtk_builder_get_object(data->builder, "inet4_addr_title");
655 data->inet4_dest = (GtkWidget*)gtk_builder_get_object(data->builder, "inet4_dest_label");
656 data->inet4_dest_title = (GtkWidget*)gtk_builder_get_object(data->builder, "inet4_dest_title");
657 data->inet4_bcast = (GtkWidget*)gtk_builder_get_object(data->builder, "inet4_bcast_label");
658 data->inet4_bcast_title = (GtkWidget*)gtk_builder_get_object(data->builder, "inet4_bcast_title");
659 data->inet4_mask = (GtkWidget*)gtk_builder_get_object(data->builder, "inet4_mask_label");
660 data->inet4_mask_title = (GtkWidget*)gtk_builder_get_object(data->builder, "inet4_mask_title");
661
662 netstatus_dialog_update_inet4_support (data);
663 }
664 static void
665 netstatus_dialog_setup_device_support (NetstatusDialogData *data)
666 {
667 data->dev_frame = (GtkWidget*)gtk_builder_get_object(data->builder, "dev_frame");
668 data->dev_type = (GtkWidget*)gtk_builder_get_object(data->builder, "dev_type_label");
669 data->dev_addr = (GtkWidget*)gtk_builder_get_object(data->builder, "dev_addr_label");
670
671 netstatus_dialog_update_device_support (data);
672 }
673
674 static void
675 netstatus_dialog_set_icon (GtkWidget *dialog)
676 {
677 GtkIconTheme *icon_theme;
678 GtkIconInfo *icon_info;
679
680 icon_theme = gtk_icon_theme_get_for_screen (gtk_window_get_screen (GTK_WINDOW (dialog)));
681
682 if ((icon_info = gtk_icon_theme_lookup_icon (icon_theme, "gnome-netstatus-tx", 48, 0)))
683 {
684 gtk_window_set_icon_from_file (GTK_WINDOW (dialog),
685 gtk_icon_info_get_filename (icon_info),
686 NULL);
687 gtk_icon_info_free (icon_info);
688 }
689 }
690
691 static gboolean
692 _netstatus_dialog_iface_list_monitor (NetstatusDialogData *data)
693 {
694 GList *iface_names, *l;
695 int n_ifaces;
696 GtkListStore* model;
697
698 iface_names = netstatus_list_interface_names (NULL);
699
700 n_ifaces = g_list_length (iface_names);
701
702 if (data->n_ifaces != n_ifaces)
703 {
704 model = (GtkListStore*)gtk_combo_box_get_model(GTK_COMBO_BOX(data->name));
705 gtk_list_store_clear(model);
706 g_signal_handlers_block_by_func (data->name_entry,
707 G_CALLBACK (netstatus_dialog_set_iface_name), data);
708
709 for (l = iface_names; l; l = l->next)
710 {
711 GtkTreeIter it;
712 gtk_list_store_append(model, &it);
713 gtk_list_store_set(model, &it, 0, (char*)l->data, -1);
714 }
715 /* GtkCombo is deprecated. */
716 /* gtk_combo_set_popdown_strings (GTK_COMBO (data->name), iface_names); */
717 netstatus_dialog_update_name (data);
718
719 g_signal_handlers_unblock_by_func (data->name_entry,
720 G_CALLBACK (netstatus_dialog_set_iface_name), data);
721 }
722
723 data->n_ifaces = n_ifaces;
724
725 for (l = iface_names; l; l = l->next)
726 g_free (l->data);
727 g_list_free (iface_names);
728
729 return TRUE;
730 }
731
732 static gboolean
733 netstatus_dialog_iface_list_monitor (gpointer data)
734 {
735 if (g_source_is_destroyed(g_main_current_source()))
736 return FALSE;
737 return _netstatus_dialog_iface_list_monitor (data);
738 }
739
740 GtkWidget *
741 netstatus_dialog_new (NetstatusIface *iface)
742 {
743 NetstatusDialogData *data;
744 data = g_new0 (NetstatusDialogData, 1);
745
746 data->builder = gtk_builder_new();
747 gtk_builder_add_from_file(data->builder, PACKAGE_UI_DIR "/netstatus.ui", NULL);
748 data->dialog = (GtkWidget*)gtk_builder_get_object(data->builder, "network_status_dialog");
749
750 g_object_set_data (G_OBJECT (data->dialog), "netstatus-dialog-data", data);
751
752 netstatus_dialog_set_icon (data->dialog);
753
754 data->iface = g_object_ref (iface);
755 netstatus_connect_signal_while_alive (data->iface,
756 "notify::state",
757 G_CALLBACK (netstatus_dialog_iface_state_changed),
758 data,
759 data->dialog);
760
761 netstatus_connect_signal_while_alive (data->iface,
762 "notify::stats",
763 G_CALLBACK (netstatus_dialog_iface_stats_changed),
764 data,
765 data->dialog);
766
767 netstatus_connect_signal_while_alive (data->iface,
768 "notify::name",
769 G_CALLBACK (netstatus_dialog_iface_name_changed),
770 data,
771 data->dialog);
772
773 netstatus_connect_signal_while_alive (data->iface,
774 "notify::wireless",
775 G_CALLBACK (netstatus_dialog_iface_signal_strength_changed),
776 data,
777 data->dialog);
778
779 netstatus_connect_signal_while_alive (data->iface,
780 "notify::signal-strength",
781 G_CALLBACK (netstatus_dialog_iface_signal_strength_changed),
782 data,
783 data->dialog);
784
785 g_signal_connect (data->dialog, "response",
786 G_CALLBACK (netstatus_dialog_response), NULL);
787
788 g_signal_connect (data->dialog, "destroy",
789 G_CALLBACK (netstatus_dialog_destroy), NULL);
790
791 netstatus_dialog_setup_connection (data);
792 netstatus_dialog_setup_activity (data);
793 netstatus_dialog_setup_signal_strength_details (data);
794 netstatus_dialog_setup_inet4_support (data);
795 netstatus_dialog_setup_device_support (data);
796 netstatus_dialog_setup_configure_button (data);
797
798 data->iface_list_monitor = g_timeout_add (2 * 1000,
799 netstatus_dialog_iface_list_monitor,
800 data);
801 _netstatus_dialog_iface_list_monitor (data);
802
803 g_signal_connect_swapped (data->name_entry, "changed",
804 G_CALLBACK (netstatus_dialog_set_iface_name),
805 data);
806
807 g_object_unref(data->builder);
808 data->builder = NULL;
809
810 return data->dialog;
811 }
812
813 /* 2006.10.08 Add by Hong Jen Yee (PCMan) to be used in lxpanel plugin */
814 void netstatus_dialog_set_configuration_tool( GtkWidget* dialog, const char* tool )
815 {
816 NetstatusDialogData *data;
817 data = g_object_get_data (G_OBJECT (dialog), "netstatus-dialog-data");
818
819 netstatus_dialog_check_config_tool( data, tool );
820
821 if (data->config_tool)
822 gtk_widget_show (data->configure_button);
823 else
824 gtk_widget_hide (data->configure_button);
825 }
826
827 const char* netstatus_dialog_get_configuration_tool( GtkWidget* dialog )
828 {
829 NetstatusDialogData *data;
830 data = g_object_get_data (G_OBJECT (dialog), "netstatus-dialog-data");
831 return data->config_tool;
832 }
833
834 /* 2009.05.10 Add by Hong Jen Yee (PCMan) to be used in lxpanel plugin */
835 const char* netstatus_dialog_get_iface_name( GtkWidget* dialog )
836 {
837 NetstatusDialogData *data;
838 data = g_object_get_data (G_OBJECT (dialog), "netstatus-dialog-data");
839 return netstatus_iface_get_name (data->iface);
840 }