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