diff --git a/ChangeLog b/ChangeLog index 39d886129f..3451b234f0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,69 @@ +2005-06-09 Dan Williams + + * NetworkManager.h + - Add NMWirelessScanMethod enum for scan methods + + * gnome/applet/applet-dbus-devices.c + - (nmwa_dbus_update_scanning_enabled_cb): remove + - (nmwa_dbus_update_scanning_enabled): remove + - (nmwa_dbus_update_devices): don't call nmwa_dbus_update_scanning_enabled() anymore + since it got removed + - (nmwa_dbus_enable_scanning): remove + + * gnome/applet/applet-dbus-info.c + - (nmi_dbus_signal_update_scan_method): new function, signal NetworkManager to + update the wireless scanning method from NMI + - (nmi_dbus_get_wireless_scan_method): new function, return wireless scanning + method value to NetworkManager + - (nmi_dbus_info_message_handler): respond to the "getWirelessScanMethod" method call + + * gnome/applet/applet-dbus-info.h + - Add prototype for nmi_dbus_signal_update_scan_method + + * gnome/applet/applet.c + - (scanning_menu_update): new function, update one GtkCheckMenuItem from the + Wireless Scanning menu based on current wireless scan method + - (nmwa_menu_scanning_item_activate): new function, callback for GTK "activate" + signal for Wireless Scanning menu items, tell NetworkManager the new method + and update our menu items to make sure the right one is checked + - (nmwa_set_scanning_enabled_cb): remove + - (nmwa_context_menu_update): remove references to pause_scanning_item + - (nmwa_context_menu_create): remove pause_scanning_item, and add new Wireless + Scanning menu item + - (nmwa_gconf_get_wireless_scan_method): new method, pull wireless scanning method + from GConf + - nmwa_gconf_networks_notify_callback -> nmwa_gconf_info_notify_callback: generalize + so we get notified of preference values too + - (nmwa_get_instance): monitor GCONF_PATH_WIRELESS rather than GCONF_PATH_WIRELESS_NETWORKS + + * gnome/applet/applet.h + - GCONF_PATH_WIRELESS added, one level below GCONF_PATH_WIRELESS_NETWORKS + - Add wireless scan method member to applet data + - Remove pause_scanning_item, add Wireless Scanning submenu + + * src/NetworkManager.c + - (nm_data_new): default to NM_SCAN_METHOD_ON + - (main): grab scanning method from NMI if we can + + * src/NetworkManagerDbus.c + - (nm_dbus_update_wireless_scan_method_cb): new function, callback from + nm_dbus_update_wireless_scan_method() + - (nm_dbus_update_wireless_scan_method): new function to grab scanning method + from NMI + - (nm_dbus_nmi_is_running): redundant function, removed + - (nm_dbus_signal_filter): trap "WirelessScanMethodUpdate" signal, grab scanning method + when NMI comes back + + * src/NetworkManagerDevice.c + - (nm_device_is_activated): return TRUE if the device is activated + - (nm_device_wireless_scan): don't scan if the scan method is OFF, or if its AUTO + and we are activated + + * src/nm-dbus-nm.c + - (nm_dbus_nm_set_scanning_enabled): removed + - nm_dbus_nm_get_scanning_enabled -> nm_dbus_nm_get_wireless_scan_method + - (nm_dbus_nm_methods_setup): remove [get | set] ScanningEnabled and add "getWirelessScanMethod" + 2005-06-09 Dan Williams * NetworkManager.h diff --git a/NetworkManager.h b/NetworkManager.h index 75640b4b6c..907a6f3516 100644 --- a/NetworkManager.h +++ b/NetworkManager.h @@ -209,4 +209,16 @@ typedef enum NMActStage } NMActStage; +/* + * Wireless scanning methods + * + */ +typedef enum NMWirelessScanMethod +{ + NM_SCAN_METHOD_UNKNOWN = 0, + NM_SCAN_METHOD_ON, + NM_SCAN_METHOD_OFF, + NM_SCAN_METHOD_AUTO +} NMWirelessScanMethod; + #endif diff --git a/gnome/applet/applet-dbus-devices.c b/gnome/applet/applet-dbus-devices.c index c05f74de9d..91129c2d2b 100644 --- a/gnome/applet/applet-dbus-devices.c +++ b/gnome/applet/applet-dbus-devices.c @@ -108,67 +108,6 @@ void nmwa_dbus_update_nm_state (NMWirelessApplet *applet) } -/* - * nmwa_dbus_update_scanning_enabled_cb - * - * Callback from nmwa_dbus_update_scanning_enabled - * - */ -void nmwa_dbus_update_scanning_enabled_cb (DBusPendingCall *pcall, void *user_data) -{ - DBusMessage * reply; - NMWirelessApplet * applet = (NMWirelessApplet *) user_data; - gboolean scanning_enabled; - - g_return_if_fail (pcall != NULL); - g_return_if_fail (applet != NULL); - - dbus_pending_call_ref (pcall); - - if (!dbus_pending_call_get_completed (pcall)) - goto out; - - if (!(reply = dbus_pending_call_steal_reply (pcall))) - goto out; - - if (message_is_error (reply)) - { - dbus_message_unref (reply); - goto out; - } - - if (dbus_message_get_args (reply, NULL, DBUS_TYPE_BOOLEAN, &scanning_enabled, DBUS_TYPE_INVALID)) - applet->scanning_enabled = scanning_enabled; - dbus_message_unref (reply); - -out: - dbus_pending_call_unref (pcall); -} - - -/* - * nmwa_dbus_update_scanning_enabled - * - * Get the scanning_enabled value from NetworkManager - * - */ -void nmwa_dbus_update_scanning_enabled (NMWirelessApplet *applet) -{ - DBusMessage * message; - DBusPendingCall * pcall = NULL; - - g_return_if_fail (applet != NULL); - - if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "getScanningEnabled"))) - { - dbus_connection_send_with_reply (applet->connection, message, &pcall, -1); - dbus_message_unref (message); - if (pcall) - dbus_pending_call_set_notify (pcall, nmwa_dbus_update_scanning_enabled_cb, applet, NULL); - } -} - - /* * nmwa_dbus_update_wireless_enabled_cb * @@ -1016,7 +955,6 @@ void nmwa_dbus_update_devices (NMWirelessApplet *applet) dbus_pending_call_set_notify (pcall, nmwa_dbus_update_devices_cb, applet, NULL); } - nmwa_dbus_update_scanning_enabled (applet); nmwa_dbus_update_wireless_enabled (applet); } @@ -1124,28 +1062,6 @@ void nmwa_dbus_create_network (DBusConnection *connection, NetworkDevice *dev, c } -/* - * nmwa_dbus_enable_scanning - * - * Tell NetworkManager to start/stop scanning. - * - */ -void nmwa_dbus_enable_scanning (NMWirelessApplet *applet, gboolean enabled) -{ - DBusMessage *message; - - g_return_if_fail (applet != NULL); - g_return_if_fail (applet->connection != NULL); - - if ((message = dbus_message_new_method_call (NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE, "setScanningEnabled"))) - { - dbus_message_append_args (message, DBUS_TYPE_BOOLEAN, &enabled, DBUS_TYPE_INVALID); - dbus_connection_send (applet->connection, message, NULL); - nmwa_dbus_update_scanning_enabled (applet); - } -} - - /* * nmwa_dbus_enable_wireless * diff --git a/gnome/applet/applet-dbus-info.c b/gnome/applet/applet-dbus-info.c index 41a6e2ea30..42c834e180 100644 --- a/gnome/applet/applet-dbus-info.c +++ b/gnome/applet/applet-dbus-info.c @@ -114,6 +114,55 @@ void nmi_dbus_return_user_key (DBusConnection *connection, DBusMessage *message, } +/* + * nmi_dbus_signal_update_scan_method + * + * Signal NetworkManager that it needs to update its wireless scanning method + * + */ +void nmi_dbus_signal_update_scan_method (DBusConnection *connection) +{ + DBusMessage *message; + + g_return_if_fail (connection != NULL); + + message = dbus_message_new_signal (NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "WirelessScanMethodUpdate"); + if (!message) + { + nm_warning ("nmi_dbus_signal_update_scan_method(): Not enough memory for new dbus message!"); + return; + } + + if (!dbus_connection_send (connection, message, NULL)) + nm_warning ("nmi_dbus_signal_update_scan_method(): Could not raise the 'WirelessScanMethodUpdate' signal!"); + + dbus_message_unref (message); +} + + +/* + * nmi_dbus_get_wireless_scan_method + * + * Tell NetworkManager what wireless scanning method it should use + * + */ +static DBusMessage *nmi_dbus_get_wireless_scan_method (NMWirelessApplet *applet, DBusMessage *message) +{ + DBusMessage * reply = NULL; + NMWirelessScanMethod method = NM_SCAN_METHOD_ON; + GConfEntry * entry; + + g_return_val_if_fail (applet != NULL, NULL); + g_return_val_if_fail (message != NULL, NULL); + + method = nmwa_gconf_get_wireless_scan_method (applet); + reply = dbus_message_new_method_return (message); + dbus_message_append_args (reply, DBUS_TYPE_UINT32, &method, DBUS_TYPE_INVALID); + + return (reply); +} + + /* * nmi_dbus_signal_update_network * @@ -913,6 +962,7 @@ DBusHandlerResult nmi_dbus_info_message_handler (DBusConnection *connection, DBu reply = nmi_dbus_get_key_for_network (applet, message); else if (strcmp ("cancelGetKeyForNetwork", method) == 0) nmi_passphrase_dialog_schedule_cancel (applet); +#if 0 /* Not used at this time */ else if (strcmp ("networkNotFound", method) == 0) { const char * network; @@ -933,6 +983,9 @@ DBusHandlerResult nmi_dbus_info_message_handler (DBusConnection *connection, DBu gtk_widget_destroy (GTK_WIDGET (dialog)); } } +#endif + else if (strcmp ("getWirelessScanMethod", method) == 0) + reply = nmi_dbus_get_wireless_scan_method (applet, message); else if (strcmp ("getNetworks", method) == 0) reply = nmi_dbus_get_networks (applet, message); else if (strcmp ("getNetworkProperties", method) == 0) diff --git a/gnome/applet/applet-dbus-info.h b/gnome/applet/applet-dbus-info.h index 0445d44829..a550ae4bbc 100644 --- a/gnome/applet/applet-dbus-info.h +++ b/gnome/applet/applet-dbus-info.h @@ -31,6 +31,8 @@ DBusHandlerResult nmi_dbus_info_message_handler (DBusConnection *connection, void nmi_dbus_return_user_key (DBusConnection *connection, DBusMessage *message, const char *passphrase, const int key_type); +void nmi_dbus_signal_update_scan_method (DBusConnection *connection); + void nmi_dbus_signal_update_network (DBusConnection *connection, const char *network, NMNetworkType type); void nmi_dbus_signal_update_vpn_connection (DBusConnection *connection, const char *name); diff --git a/gnome/applet/applet.c b/gnome/applet/applet.c index f072f39d3a..c6de48ee2a 100644 --- a/gnome/applet/applet.c +++ b/gnome/applet/applet.c @@ -1137,6 +1137,50 @@ static void nmwa_menu_disconnect_vpn_item_activate (GtkMenuItem *item, gpointer } +static void scanning_menu_update (GtkWidget *menu_item, GtkCheckMenuItem *active_item) +{ + g_return_if_fail (active_item != NULL); + + g_object_set_data (G_OBJECT (menu_item), "block-activate", GINT_TO_POINTER(1)); + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (menu_item), (GTK_CHECK_MENU_ITEM (menu_item) == active_item) ? TRUE : FALSE); + g_object_set_data (G_OBJECT (menu_item), "block-activate", GINT_TO_POINTER(0)); +} + + +/* + * nmwa_menu_scanning_item_activate + * + * Handle a request to change scanning behavior + * + */ +static void nmwa_menu_scanning_item_activate (GtkMenuItem *item, gpointer user_data) +{ + NMWirelessApplet * applet = (NMWirelessApplet *)user_data; + char * tag; + + g_return_if_fail (item != NULL); + g_return_if_fail (applet != NULL); + + if ((tag = g_object_get_data (G_OBJECT (item), "block-activate"))) + if (GPOINTER_TO_INT(tag) == 1) + return; + + if ((tag = g_object_get_data (G_OBJECT (item), "scan_method"))) + { + NMWirelessScanMethod method = GPOINTER_TO_UINT (tag); + + if ((method == NM_SCAN_METHOD_ON) || (method == NM_SCAN_METHOD_OFF) || (method == NM_SCAN_METHOD_AUTO)) + gconf_client_set_int (applet->gconf_client, GCONF_PATH_WIRELESS "/scan_method", method, NULL); + } + + /* Check only this menu item */ + if (!applet->scanning_menu) + return; + + gtk_container_foreach (GTK_CONTAINER (applet->scanning_menu), (GtkCallback) scanning_menu_update, (gpointer) item); +} + + /* * nmwa_menu_add_separator_item * @@ -1492,13 +1536,6 @@ static void nmwa_menu_add_devices (GtkWidget *menu, NMWirelessApplet *applet) } -static void nmwa_set_scanning_enabled_cb (GtkWidget *widget, NMWirelessApplet *applet) -{ - g_return_if_fail (applet != NULL); - - nmwa_dbus_enable_scanning (applet, !applet->scanning_enabled); -} - static void nmwa_set_wireless_enabled_cb (GtkWidget *widget, NMWirelessApplet *applet) { g_return_if_fail (applet != NULL); @@ -1645,29 +1682,12 @@ static void nmwa_context_menu_update (NMWirelessApplet *applet) GtkWidget *image; g_return_if_fail (applet != NULL); - g_return_if_fail (applet->pause_scanning_item != NULL); g_return_if_fail (applet->stop_wireless_item != NULL); g_mutex_lock (applet->data_mutex); - gtk_widget_destroy (applet->pause_scanning_item); gtk_widget_destroy (applet->stop_wireless_item); - if (applet->scanning_enabled) - { - applet->pause_scanning_item = gtk_image_menu_item_new_with_label (_("Pause Wireless Scanning")); - image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_PAUSE, GTK_ICON_SIZE_MENU); - } - else - { - applet->pause_scanning_item = gtk_image_menu_item_new_with_label (_("Resume Wireless Scanning")); - image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_PLAY, GTK_ICON_SIZE_MENU); - } - g_signal_connect (G_OBJECT (applet->pause_scanning_item), "activate", G_CALLBACK (nmwa_set_scanning_enabled_cb), applet); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (applet->pause_scanning_item), image); - gtk_menu_shell_insert (GTK_MENU_SHELL (applet->context_menu), applet->pause_scanning_item, 0); - gtk_widget_show_all (applet->pause_scanning_item); - if (applet->wireless_enabled) { applet->stop_wireless_item = gtk_image_menu_item_new_with_label (_("Stop All Wireless Devices")); @@ -1698,25 +1718,49 @@ static GtkWidget *nmwa_context_menu_create (NMWirelessApplet *applet) GtkWidget *menu; GtkWidget *menu_item; GtkWidget *image; + GtkWidget *scanning_subitem; g_return_val_if_fail (applet != NULL, NULL); menu = gtk_menu_new (); - applet->pause_scanning_item = gtk_image_menu_item_new_with_label (_("Pause Wireless Scanning")); - g_signal_connect (G_OBJECT (applet->pause_scanning_item), "activate", G_CALLBACK (nmwa_set_scanning_enabled_cb), applet); - image = gtk_image_new_from_stock (GTK_STOCK_MEDIA_PAUSE, GTK_ICON_SIZE_MENU); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (applet->pause_scanning_item), image); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), applet->pause_scanning_item); + /* Construct the wireless scanning submenu */ + applet->scan_method = nmwa_gconf_get_wireless_scan_method (applet); + applet->scanning_item = gtk_menu_item_new_with_label (_("Wireless Scanning")); + applet->scanning_menu = gtk_menu_new (); + scanning_subitem = GTK_WIDGET (gtk_check_menu_item_new_with_label (_("On"))); + g_object_set_data (G_OBJECT (scanning_subitem), "scan_method", GUINT_TO_POINTER (NM_SCAN_METHOD_ON)); + if (applet->scan_method == NM_SCAN_METHOD_ON) + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (scanning_subitem), TRUE); + g_signal_connect (G_OBJECT (scanning_subitem), "activate", G_CALLBACK (nmwa_menu_scanning_item_activate), applet); + gtk_menu_shell_append (GTK_MENU_SHELL (applet->scanning_menu), GTK_WIDGET (scanning_subitem)); + + scanning_subitem = GTK_WIDGET (gtk_check_menu_item_new_with_label (_("Off"))); + g_object_set_data (G_OBJECT (scanning_subitem), "scan_method", GINT_TO_POINTER (NM_SCAN_METHOD_OFF)); + if (applet->scan_method == NM_SCAN_METHOD_OFF) + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (scanning_subitem), TRUE); + g_signal_connect (G_OBJECT (scanning_subitem), "activate", G_CALLBACK (nmwa_menu_scanning_item_activate), applet); + gtk_menu_shell_append (GTK_MENU_SHELL (applet->scanning_menu), GTK_WIDGET (scanning_subitem)); + + scanning_subitem = GTK_WIDGET (gtk_check_menu_item_new_with_label (_("Automatic"))); + g_object_set_data (G_OBJECT (scanning_subitem), "scan_method", GINT_TO_POINTER (NM_SCAN_METHOD_AUTO)); + if (applet->scan_method == NM_SCAN_METHOD_AUTO) + gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (scanning_subitem), TRUE); + g_signal_connect (G_OBJECT (scanning_subitem), "activate", G_CALLBACK (nmwa_menu_scanning_item_activate), applet); + gtk_menu_shell_append (GTK_MENU_SHELL (applet->scanning_menu), GTK_WIDGET (scanning_subitem)); + + gtk_menu_item_set_submenu (GTK_MENU_ITEM (applet->scanning_item), applet->scanning_menu); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), applet->scanning_item); + + /* Stop All Wireless Devices item */ applet->stop_wireless_item = gtk_image_menu_item_new_with_label (_("Stop All Wireless Devices")); g_signal_connect (G_OBJECT (applet->stop_wireless_item), "activate", G_CALLBACK (nmwa_set_wireless_enabled_cb), applet); image = gtk_image_new_from_stock (GTK_STOCK_STOP, GTK_ICON_SIZE_MENU); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (applet->stop_wireless_item), image); gtk_menu_shell_append (GTK_MENU_SHELL (menu), applet->stop_wireless_item); - menu_item = gtk_separator_menu_item_new (); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); + nmwa_menu_add_separator_item (menu); menu_item = gtk_image_menu_item_new_with_label (_("Help")); /* g_signal_connect (G_OBJECT (menu_item), "activate", G_CALLBACK (nmwa_help_cb), applet); */ @@ -1827,13 +1871,45 @@ static void nmwa_setup_widgets (NMWirelessApplet *applet) applet->encryption_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); } + /* - * nmwa_gconf_networks_notify_callback + * nmwa_gconf_get_wireless_scan_method * - * Callback from gconf when wireless networking key/values have changed. + * Grab the wireless scan method from GConf * */ -static void nmwa_gconf_networks_notify_callback (GConfClient *client, guint connection_id, GConfEntry *entry, gpointer user_data) +NMWirelessScanMethod nmwa_gconf_get_wireless_scan_method (NMWirelessApplet *applet) +{ + NMWirelessScanMethod method = NM_SCAN_METHOD_ON; + GConfEntry * entry; + + g_return_val_if_fail (applet, NM_SCAN_METHOD_ON); + g_return_val_if_fail (applet->gconf_client, NM_SCAN_METHOD_ON); + + if ((entry = gconf_client_get_entry (applet->gconf_client, GCONF_PATH_WIRELESS "/scan_method", NULL, TRUE, NULL))) + { + GConfValue * value = gconf_entry_get_value (entry); + + if (value && (value->type == GCONF_VALUE_INT)) + { + NMWirelessScanMethod temp_method = gconf_value_get_int (value); + + if ((method == NM_SCAN_METHOD_ON) || (method == NM_SCAN_METHOD_OFF) || (method == NM_SCAN_METHOD_AUTO)) + method = temp_method; + } + } + + return method; +} + + +/* + * nmwa_gconf_info_notify_callback + * + * Callback from gconf when wireless key/values have changed. + * + */ +static void nmwa_gconf_info_notify_callback (GConfClient *client, guint connection_id, GConfEntry *entry, gpointer user_data) { NMWirelessApplet * applet = (NMWirelessApplet *)user_data; const char * key = NULL; @@ -1844,11 +1920,23 @@ static void nmwa_gconf_networks_notify_callback (GConfClient *client, guint conn if ((key = gconf_entry_get_key (entry))) { - int path_len = strlen (GCONF_PATH_WIRELESS_NETWORKS) + 1; + int net_path_len = strlen (GCONF_PATH_WIRELESS_NETWORKS) + 1; - if (strncmp (GCONF_PATH_WIRELESS_NETWORKS"/", key, path_len) == 0) + if (strcmp (GCONF_PATH_WIRELESS "/scan_method", key) == 0) { - char *network = g_strdup ((key + path_len)); + GConfValue * value = gconf_entry_get_value (entry); + + if (value && (value->type == GCONF_VALUE_INT)) + { + NMWirelessScanMethod method = gconf_value_get_int (value); + + if ((method == NM_SCAN_METHOD_ON) || (method == NM_SCAN_METHOD_OFF) || (method == NM_SCAN_METHOD_AUTO)) + nmi_dbus_signal_update_scan_method (applet->connection); + } + } + if (strncmp (GCONF_PATH_WIRELESS_NETWORKS"/", key, net_path_len) == 0) + { + char *network = g_strdup ((key + net_path_len)); char *slash_pos; char *unescaped_network; @@ -1941,7 +2029,7 @@ static void nmwa_destroy (NMWirelessApplet *applet, gpointer user_data) g_free (applet->glade_file); - gconf_client_notify_remove (applet->gconf_client, applet->gconf_net_notify_id); + gconf_client_notify_remove (applet->gconf_client, applet->gconf_prefs_notify_id); gconf_client_notify_remove (applet->gconf_client, applet->gconf_vpn_notify_id); g_object_unref (G_OBJECT (applet->gconf_client)); } @@ -1974,6 +2062,8 @@ static GtkWidget * nmwa_get_instance (NMWirelessApplet *applet) applet->thread_context = NULL; applet->thread_loop = NULL; applet->thread_done = FALSE; + applet->scanning_menu = NULL; + applet->scanning_item = NULL; applet->glade_file = g_build_filename (GLADEDIR, "wireless-applet.glade", NULL); if (!applet->glade_file || !g_file_test (applet->glade_file, G_FILE_TEST_IS_REGULAR)) @@ -1990,9 +2080,9 @@ static GtkWidget * nmwa_get_instance (NMWirelessApplet *applet) if (!applet->gconf_client) return NULL; - gconf_client_add_dir (applet->gconf_client, GCONF_PATH_WIRELESS_NETWORKS, GCONF_CLIENT_PRELOAD_NONE, NULL); - applet->gconf_net_notify_id = gconf_client_notify_add (applet->gconf_client, GCONF_PATH_WIRELESS_NETWORKS, - nmwa_gconf_networks_notify_callback, applet, NULL, NULL); + gconf_client_add_dir (applet->gconf_client, GCONF_PATH_WIRELESS, GCONF_CLIENT_PRELOAD_NONE, NULL); + applet->gconf_prefs_notify_id = gconf_client_notify_add (applet->gconf_client, GCONF_PATH_WIRELESS, + nmwa_gconf_info_notify_callback, applet, NULL, NULL); gconf_client_add_dir (applet->gconf_client, GCONF_PATH_VPN_CONNECTIONS, GCONF_CLIENT_PRELOAD_NONE, NULL); applet->gconf_vpn_notify_id = gconf_client_notify_add (applet->gconf_client, GCONF_PATH_VPN_CONNECTIONS, diff --git a/gnome/applet/applet.h b/gnome/applet/applet.h index bea119f017..a0894c4284 100644 --- a/gnome/applet/applet.h +++ b/gnome/applet/applet.h @@ -37,6 +37,7 @@ * Preference locations */ #define GCONF_PATH_WIRELESS_NETWORKS "/system/networking/wireless/networks" +#define GCONF_PATH_WIRELESS "/system/networking/wireless" #define GCONF_PATH_VPN_CONNECTIONS "/system/networking/vpn_connections" #define GCONF_PATH_PREFS "/apps/NetworkManagerApplet" @@ -66,7 +67,7 @@ typedef struct DBusConnection * connection; GConfClient * gconf_client; - guint gconf_net_notify_id; + guint gconf_prefs_notify_id; guint gconf_vpn_notify_id; char * glade_file; guint redraw_timeout_id; @@ -80,7 +81,7 @@ typedef struct /* Data model elements */ GMutex * data_mutex; gboolean is_adhoc; - gboolean scanning_enabled; + NMWirelessScanMethod scan_method; gboolean wireless_enabled; gboolean nm_running; @@ -130,7 +131,8 @@ typedef struct GtkTooltips * tooltips; GtkWidget * context_menu; - GtkWidget * pause_scanning_item; + GtkWidget * scanning_item; + GtkWidget * scanning_menu; GtkWidget * stop_wireless_item; GtkWidget * passphrase_dialog; @@ -152,6 +154,8 @@ void nmwa_schedule_vpn_login_banner_dialog (NMWirelessApplet *applet, const c NetworkDevice * nmwa_get_first_active_device (GSList *dev_list); +NMWirelessScanMethod nmwa_gconf_get_wireless_scan_method (NMWirelessApplet *applet); + int nm_null_safe_strcmp (const char *s1, const char *s2); #endif diff --git a/src/NetworkManager.c b/src/NetworkManager.c index 5f059aa0b3..d366b3f3d9 100644 --- a/src/NetworkManager.c +++ b/src/NetworkManager.c @@ -437,7 +437,7 @@ static NMData *nm_data_new (gboolean enable_test_devices) data->enable_test_devices = enable_test_devices; - data->scanning_enabled = TRUE; + data->scanning_method = NM_SCAN_METHOD_ON; data->wireless_enabled = TRUE; nm_policy_schedule_device_change_check (data); @@ -862,6 +862,7 @@ int main( int argc, char *argv[] ) { nm_policy_schedule_allowed_ap_list_update (nm_data); nm_dbus_vpn_schedule_vpn_connections_update (nm_data); + nm_dbus_update_wireless_scan_method (nm_data->dbus_connection, nm_data); } /* Right before we init hal, we have to make sure our mainloop diff --git a/src/NetworkManagerDbus.c b/src/NetworkManagerDbus.c index bbab5a4619..5be05e380c 100644 --- a/src/NetworkManagerDbus.c +++ b/src/NetworkManagerDbus.c @@ -557,6 +557,73 @@ void nm_dbus_cancel_get_user_key_for_network (DBusConnection *connection, NMActR } +/* + * nm_dbus_update_wireless_scan_method_cb + * + * Callback from nm_dbus_update_wireless_scan_method + * + */ +static void nm_dbus_update_wireless_scan_method_cb (DBusPendingCall *pcall, NMData *data) +{ + DBusMessage * reply; + NMWirelessScanMethod method = NM_SCAN_METHOD_UNKNOWN; + + g_return_if_fail (pcall != NULL); + g_return_if_fail (data != NULL); + + if (!dbus_pending_call_get_completed (pcall)) + goto out; + + if (!(reply = dbus_pending_call_steal_reply (pcall))) + goto out; + + if (dbus_message_get_type (reply) == DBUS_MESSAGE_TYPE_ERROR) + { + dbus_message_unref (reply); + goto out; + } + + if (dbus_message_get_args (reply, NULL, DBUS_TYPE_UINT32, &method, DBUS_TYPE_INVALID)) + { + if ((method == NM_SCAN_METHOD_ON) || (method == NM_SCAN_METHOD_OFF) || (method == NM_SCAN_METHOD_AUTO)) + data->scanning_method = method; + } + dbus_message_unref (reply); + +out: + dbus_pending_call_unref (pcall); +} + + +/* + * nm_dbus_update_wireless_scan_method + * + * Get the wireless scan method from NetworkManagerInfo + * + */ +void nm_dbus_update_wireless_scan_method (DBusConnection *connection, NMData *data) +{ + DBusMessage * message = NULL; + DBusPendingCall * pcall = NULL; + + g_return_if_fail (connection != NULL); + g_return_if_fail (data != NULL); + + if (!(message = dbus_message_new_method_call (NMI_DBUS_SERVICE, NMI_DBUS_PATH, NMI_DBUS_INTERFACE, "getWirelessScanMethod"))) + { + nm_warning ("nm_dbus_update_wireless_scan_method(): Couldn't allocate the dbus message"); + return; + } + + if (dbus_connection_send_with_reply (connection, message, &pcall, INT_MAX) && pcall) + dbus_pending_call_set_notify (pcall, (DBusPendingCallNotifyFunction) nm_dbus_update_wireless_scan_method_cb, data, NULL); + else + nm_warning ("nm_dbus_update_wireless_scan_method(): could not send dbus message"); + + dbus_message_unref (message); +} + + /* * nm_dbus_update_network_auth_method * @@ -921,27 +988,6 @@ static void nm_dbus_update_one_allowed_network (DBusConnection *connection, cons } -/* - * nm_dbus_nmi_is_running - * - * Ask dbus whether or not NetworkManagerInfo is running - * - */ -gboolean nm_dbus_nmi_is_running (DBusConnection *connection) -{ - DBusError error; - gboolean exists; - - g_return_val_if_fail (connection != NULL, FALSE); - - dbus_error_init (&error); - exists = dbus_bus_name_has_owner (connection, NMI_DBUS_SERVICE, &error); - if (dbus_error_is_set (&error)) - dbus_error_free (&error); - return (exists); -} - - /* * nm_dbus_signal_filter * @@ -971,30 +1017,33 @@ static DBusHandlerResult nm_dbus_signal_filter (DBusConnection *connection, DBus dbus_error_init (&error); - if ( (strcmp (object_path, NMI_DBUS_PATH) == 0) - && dbus_message_is_signal (message, NMI_DBUS_INTERFACE, "WirelessNetworkUpdate")) + if (strcmp (object_path, NMI_DBUS_PATH) == 0) { - char *network = NULL; - - if (dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &network, DBUS_TYPE_INVALID)) + if (dbus_message_is_signal (message, NMI_DBUS_INTERFACE, "WirelessNetworkUpdate")) { - /* Update a single wireless network's data */ - nm_debug ("NetworkManagerInfo triggered update of wireless network '%s'", network); - nm_dbus_update_one_allowed_network (connection, network, data); - handled = TRUE; - } - } - else if ( (strcmp (object_path, NMI_DBUS_PATH) == 0) - && dbus_message_is_signal (message, NMI_DBUS_INTERFACE, "VPNConnectionUpdate")) - { - char *name = NULL; + char *network = NULL; - if (dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) - { - nm_debug ("NetworkManagerInfo triggered update of VPN connection '%s'", name); - nm_dbus_vpn_update_one_vpn_connection (data->dbus_connection, name, data); - handled = TRUE; + if (dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &network, DBUS_TYPE_INVALID)) + { + /* Update a single wireless network's data */ + nm_debug ("NetworkManagerInfo triggered update of wireless network '%s'", network); + nm_dbus_update_one_allowed_network (connection, network, data); + handled = TRUE; + } } + else if (dbus_message_is_signal (message, NMI_DBUS_INTERFACE, "VPNConnectionUpdate")) + { + char *name = NULL; + + if (dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID)) + { + nm_debug ("NetworkManagerInfo triggered update of VPN connection '%s'", name); + nm_dbus_vpn_update_one_vpn_connection (data->dbus_connection, name, data); + handled = TRUE; + } + } + else if (dbus_message_is_signal (message, NMI_DBUS_INTERFACE, "WirelessScanMethodUpdate")) + nm_dbus_update_wireless_scan_method (data->dbus_connection, data); } else if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "Disconnected")) { @@ -1022,6 +1071,7 @@ static DBusHandlerResult nm_dbus_signal_filter (DBusConnection *connection, DBus dbus_bus_add_match (connection, match, NULL); nm_policy_schedule_allowed_ap_list_update (data); nm_dbus_vpn_schedule_vpn_connections_update (data); + nm_dbus_update_wireless_scan_method (data->dbus_connection, data); g_free (match); handled = TRUE; } diff --git a/src/NetworkManagerDbus.h b/src/NetworkManagerDbus.h index 1b2edbdf7c..98ce80eee9 100644 --- a/src/NetworkManagerDbus.h +++ b/src/NetworkManagerDbus.h @@ -70,14 +70,14 @@ void nm_dbus_get_user_key_for_network (DBusConnection *connection, NMActReque void nm_dbus_cancel_get_user_key_for_network (DBusConnection *connection, NMActRequest *req); +void nm_dbus_update_wireless_scan_method (DBusConnection *connection, NMData *data); + NMAccessPoint *nm_dbus_get_network_object (DBusConnection *connection, NMNetworkType type, const char *network); gboolean nm_dbus_add_network_address (DBusConnection *connection, NMNetworkType type, const char *network, struct ether_addr *addr); gboolean nm_dbus_update_network_auth_method (DBusConnection *connection, const char *network, const NMDeviceAuthMethod auth_method); -gboolean nm_dbus_nmi_is_running (DBusConnection *connection); - void nm_dbus_update_allowed_networks (DBusConnection *connection, NMAccessPointList *list, NMData *data); DBusMessage * nm_dbus_create_error_message (DBusMessage *message, const char *exception_namespace, diff --git a/src/NetworkManagerDevice.c b/src/NetworkManagerDevice.c index f36c5a9b87..1d147ee8f1 100644 --- a/src/NetworkManagerDevice.c +++ b/src/NetworkManagerDevice.c @@ -3028,6 +3028,47 @@ gboolean nm_device_is_activating (NMDevice *dev) } +/* + * nm_device_is_activated + * + * Return whether or not the device is successfully activated. + * + */ +gboolean nm_device_is_activated (NMDevice *dev) +{ + NMActRequest * req; + NMActStage stage; + gboolean activated = FALSE; + + g_return_val_if_fail (dev != NULL, FALSE); + + if (!(req = nm_device_get_act_request (dev))) + return FALSE; + + stage = nm_act_request_get_stage (req); + switch (stage) + { + case NM_ACT_STAGE_ACTIVATED: + activated = TRUE; + break; + + case NM_ACT_STAGE_DEVICE_PREPARE: + case NM_ACT_STAGE_DEVICE_CONFIG: + case NM_ACT_STAGE_NEED_USER_KEY: + case NM_ACT_STAGE_IP_CONFIG_START: + case NM_ACT_STAGE_IP_CONFIG_GET: + case NM_ACT_STAGE_IP_CONFIG_COMMIT: + case NM_ACT_STAGE_FAILED: + case NM_ACT_STAGE_CANCELLED: + case NM_ACT_STAGE_UNKNOWN: + default: + break; + } + + return activated; +} + + /* * nm_device_activation_should_cancel * @@ -3899,9 +3940,21 @@ static gboolean nm_device_wireless_scan (gpointer user_data) return FALSE; } - /* Just reschedule ourselves if scanning or all wireless is disabled */ - if ( (dev->app_data->scanning_enabled == FALSE) - || (dev->app_data->wireless_enabled == FALSE) + /* Reschedule if scanning is off, or if scanning is AUTO and we are + * associated to an access point. + */ + if ( (dev->app_data->scanning_method == NM_SCAN_METHOD_OFF) + || ( (dev->app_data->scanning_method == NM_SCAN_METHOD_AUTO) + && nm_device_is_activated (dev))) + { + dev->options.wireless.scan_interval = 10; + goto reschedule; + } + + /* Reschedule ourselves if all wireless is disabled, we're asleep, + * or we are currently activating. + */ + if ( (dev->app_data->wireless_enabled == FALSE) || (dev->app_data->asleep == TRUE) || (nm_device_is_activating (dev) == TRUE)) { diff --git a/src/NetworkManagerMain.h b/src/NetworkManagerMain.h index 7d2fb5d5e6..d5e14196d8 100644 --- a/src/NetworkManagerMain.h +++ b/src/NetworkManagerMain.h @@ -80,7 +80,7 @@ typedef struct NMData GSList * dev_list; GMutex * dev_list_mutex; - gboolean scanning_enabled; + NMWirelessScanMethod scanning_method; gboolean wireless_enabled; gboolean asleep; diff --git a/src/nm-dbus-nm.c b/src/nm-dbus-nm.c index 8ac68bcfa7..3e35f2b083 100644 --- a/src/nm-dbus-nm.c +++ b/src/nm-dbus-nm.c @@ -329,28 +329,14 @@ static DBusMessage *nm_dbus_nm_remove_test_device (DBusConnection *connection, D } -static DBusMessage *nm_dbus_nm_set_scanning_enabled (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data) -{ - gboolean enabled = FALSE; - DBusError err; - - g_return_val_if_fail (data && data->data && connection && message, NULL); - - dbus_error_init (&err); - if (dbus_message_get_args (message, &err, DBUS_TYPE_BOOLEAN, &enabled, DBUS_TYPE_INVALID)) - data->data->scanning_enabled = enabled; - - return NULL; -} - -static DBusMessage *nm_dbus_nm_get_scanning_enabled (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data) +static DBusMessage *nm_dbus_nm_get_wireless_scan_method (DBusConnection *connection, DBusMessage *message, NMDbusCBData *data) { DBusMessage *reply = NULL; g_return_val_if_fail (data && data->data && connection && message, NULL); if ((reply = dbus_message_new_method_return (message))) - dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &data->data->scanning_enabled, DBUS_TYPE_INVALID); + dbus_message_append_args (reply, DBUS_TYPE_UINT32, &data->data->scanning_method, DBUS_TYPE_INVALID); return reply; } @@ -478,8 +464,7 @@ NMDbusMethodList *nm_dbus_nm_methods_setup (void) nm_dbus_method_list_add_method (list, "getDevices", nm_dbus_nm_get_devices); nm_dbus_method_list_add_method (list, "setActiveDevice", nm_dbus_nm_set_active_device); nm_dbus_method_list_add_method (list, "createWirelessNetwork", nm_dbus_nm_create_wireless_network); - nm_dbus_method_list_add_method (list, "setScanningEnabled", nm_dbus_nm_set_scanning_enabled); - nm_dbus_method_list_add_method (list, "getScanningEnabled", nm_dbus_nm_get_scanning_enabled); + nm_dbus_method_list_add_method (list, "getWirelessScanMethod", nm_dbus_nm_get_wireless_scan_method); nm_dbus_method_list_add_method (list, "setWirelessEnabled", nm_dbus_nm_set_wireless_enabled); nm_dbus_method_list_add_method (list, "getWirelessEnabled", nm_dbus_nm_get_wireless_enabled); nm_dbus_method_list_add_method (list, "sleep", nm_dbus_nm_sleep);