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