mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-06 05:00:15 +01:00
2004-08-11 Dan Williams <dcbw@redhat.com>
* panel-applet/NMWirelessApplet.[ch] - Fix up copyright and credits to include Bastien and Eskil, who created the gnome-applets wireless applet, from whose skeleton this one was created - Rework nmwa_update_state()/nmwa_draw() so that state and which pixmap to draw is computed during nmwa_update_state() - Applet now shows itself all the time due to panel packing issues which caused the applet to previously never come back after hiding. When a wired device is the active device, the applet shows "not connected" * panel-applet/NMWirelessAppletDbus.[ch] - Clean up error messages and show what function they are from - nmwa_dbus_get_active_wireless_device()->nmwa_dbus_get_active_device() - Add new device type getters, and a status getter * src/NetworkManagerDbus.c - (nm_dbus_devices_handle_request): Don't return an active network unless that network is actually in the device's ap list - (nm_dbus_nm_message_handler): Fix silly mistake returning status * src/NetworkManagerDevice.c - (nm_device_update_best_ap): If the best AP is NULL, clear out the ESSID of the card * test/nmclienttest.c - Report status of NetworkManager too git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@47 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:
parent
d06aa3e6ff
commit
f9b8cb84d1
8 changed files with 243 additions and 103 deletions
29
ChangeLog
29
ChangeLog
|
|
@ -1,3 +1,32 @@
|
|||
2004-08-11 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* panel-applet/NMWirelessApplet.[ch]
|
||||
- Fix up copyright and credits to include Bastien and Eskil,
|
||||
who created the gnome-applets wireless applet, from whose
|
||||
skeleton this one was created
|
||||
- Rework nmwa_update_state()/nmwa_draw() so that state and which
|
||||
pixmap to draw is computed during nmwa_update_state()
|
||||
- Applet now shows itself all the time due to panel packing issues
|
||||
which caused the applet to previously never come back after hiding.
|
||||
When a wired device is the active device, the applet shows "not connected"
|
||||
|
||||
* panel-applet/NMWirelessAppletDbus.[ch]
|
||||
- Clean up error messages and show what function they are from
|
||||
- nmwa_dbus_get_active_wireless_device()->nmwa_dbus_get_active_device()
|
||||
- Add new device type getters, and a status getter
|
||||
|
||||
* src/NetworkManagerDbus.c
|
||||
- (nm_dbus_devices_handle_request): Don't return an active network unless that
|
||||
network is actually in the device's ap list
|
||||
- (nm_dbus_nm_message_handler): Fix silly mistake returning status
|
||||
|
||||
* src/NetworkManagerDevice.c
|
||||
- (nm_device_update_best_ap): If the best AP is NULL, clear out the ESSID of the
|
||||
card
|
||||
|
||||
* test/nmclienttest.c
|
||||
- Report status of NetworkManager too
|
||||
|
||||
2004-08-11 Dan Williams <dcbw@redhat.com>
|
||||
|
||||
* info-daemon/NetworkManagerInfo.c:
|
||||
|
|
|
|||
|
|
@ -16,7 +16,14 @@
|
|||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* This applet used the GNOME Wireless Applet as a skeleton to build from.
|
||||
*
|
||||
* GNOME Wireless Applet Authors:
|
||||
* Eskil Heyn Olsen <eskil@eskil.dk>
|
||||
* Bastien Nocera <hadess@hadess.net> (Gnome2 port)
|
||||
*
|
||||
* (C) Copyright 2004 Red Hat, Inc.
|
||||
* (C) Copyright 2001, 2002 Free Software Foundation
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
|
@ -102,20 +109,63 @@ static void nmwa_draw (NMWirelessApplet *applet)
|
|||
{
|
||||
const char *label_text;
|
||||
char *tmp;
|
||||
PixmapState state = PIX_BROKEN;
|
||||
|
||||
if (applet->have_active_device)
|
||||
state = PIX_SIGNAL_4;
|
||||
|
||||
if (applet->pixmaps[state] != applet->current_pixbuf)
|
||||
if (applet->pixmaps[applet->pix_state] != applet->current_pixbuf)
|
||||
{
|
||||
applet->current_pixbuf = (GdkPixbuf *)applet->pixmaps[state];
|
||||
applet->current_pixbuf = (GdkPixbuf *)applet->pixmaps[applet->pix_state];
|
||||
gtk_image_set_from_pixbuf (GTK_IMAGE (applet->pixmap), applet->current_pixbuf);
|
||||
}
|
||||
}
|
||||
|
||||
static void nmwa_update_state (NMWirelessApplet *applet)
|
||||
{
|
||||
if (applet->nm_active)
|
||||
{
|
||||
char *status = nmwa_dbus_get_nm_status (applet->connection);
|
||||
char *active_device = nmwa_dbus_get_active_device (applet->connection);
|
||||
|
||||
if (active_device && status)
|
||||
{
|
||||
int type = nmwa_dbus_get_device_type (applet->connection, active_device);
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case (DEVICE_TYPE_WIRELESS_ETHERNET):
|
||||
applet->have_active_device = TRUE;
|
||||
if (strcmp (status, "connected") == 0)
|
||||
applet->pix_state = PIX_SIGNAL_4;
|
||||
else if (strcmp (status, "connecting") == 0)
|
||||
{
|
||||
if ( (applet->pix_state < PIX_CONNECT_0)
|
||||
|| (applet->pix_state > PIX_CONNECT_2))
|
||||
applet->pix_state = PIX_CONNECT_0;
|
||||
else
|
||||
applet->pix_state++;
|
||||
}
|
||||
break;
|
||||
|
||||
case (DEVICE_TYPE_WIRED_ETHERNET):
|
||||
default:
|
||||
applet->have_active_device = FALSE;
|
||||
applet->pix_state = PIX_BROKEN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
applet->have_active_device = FALSE;
|
||||
applet->pix_state = PIX_BROKEN;
|
||||
}
|
||||
|
||||
if (active_device) dbus_free (active_device);
|
||||
if (status) dbus_free (status);
|
||||
}
|
||||
else
|
||||
{
|
||||
applet->have_active_device = FALSE;
|
||||
applet->pix_state = PIX_BROKEN;
|
||||
}
|
||||
|
||||
nmwa_draw (applet);
|
||||
}
|
||||
|
||||
|
|
@ -156,35 +206,11 @@ static void nmwa_load_theme (NMWirelessApplet *applet)
|
|||
|
||||
static int nmwa_timeout_handler (NMWirelessApplet *applet)
|
||||
{
|
||||
char *active_device;
|
||||
|
||||
/* Try to get a connection to dbus if we don't already have one */
|
||||
if (!applet->connection)
|
||||
applet->connection = nmwa_dbus_init (applet);
|
||||
|
||||
if (applet->nm_active)
|
||||
{
|
||||
fprintf( stderr, "NM is present {\n");
|
||||
if ((active_device = nmwa_dbus_get_active_wireless_device (applet->connection)))
|
||||
{
|
||||
applet->have_active_device = TRUE;
|
||||
nmwa_update_state (applet);
|
||||
fprintf( stderr, " A wireless device was active, showing applet\n");
|
||||
gtk_widget_show (GTK_WIDGET (applet));
|
||||
dbus_free (active_device);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf( stderr, " A wireless device was not active, hiding applet\n");
|
||||
gtk_widget_hide (GTK_WIDGET (applet));
|
||||
}
|
||||
fprintf( stderr, "}\n\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf( stderr, "NM is *not* present\n");
|
||||
gtk_widget_hide (GTK_WIDGET (applet));
|
||||
}
|
||||
nmwa_update_state (applet);
|
||||
|
||||
return (TRUE);
|
||||
}
|
||||
|
|
@ -228,6 +254,8 @@ static void nmwa_about_cb (BonoboUIComponent *uic, NMWirelessApplet *applet)
|
|||
const gchar *authors[] =
|
||||
{
|
||||
"Dan Williams <dcbw@redhat.com>",
|
||||
"Eskil Heyn Olsen <eskil@eskil.org> (GNOME Wireless Applet)",
|
||||
"Bastien Nocera <hadess@hadess.net> (GNOME Wireless Applet)",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
|
@ -245,8 +273,8 @@ static void nmwa_about_cb (BonoboUIComponent *uic, NMWirelessApplet *applet)
|
|||
applet->about_dialog = gnome_about_new (
|
||||
"Wireless Network Applet",
|
||||
VERSION,
|
||||
"(C) 2004 Red Hat, Inc.",
|
||||
"This utility shows the status of a wireless link.",
|
||||
"(C) 2004 Red Hat, Inc.\n(C) Copyright 2001, 2002 Free Software Foundation",
|
||||
"This utility shows the status of a wireless networking link.",
|
||||
authors,
|
||||
NULL,
|
||||
NULL,
|
||||
|
|
@ -495,6 +523,7 @@ static GtkWidget * nmwa_new (NMWirelessApplet *applet)
|
|||
|
||||
gtk_widget_hide(GTK_WIDGET(applet));
|
||||
|
||||
applet->pix_state = PIX_BROKEN;
|
||||
applet->connection = nmwa_dbus_init(applet);
|
||||
applet->have_active_device = FALSE;
|
||||
applet->nm_active = nmwa_dbus_nm_is_running(applet->connection);
|
||||
|
|
@ -507,7 +536,7 @@ static GtkWidget * nmwa_new (NMWirelessApplet *applet)
|
|||
|
||||
nmwa_timeout_handler (applet);
|
||||
nmwa_start_timeout (applet);
|
||||
|
||||
|
||||
panel_applet_setup_menu_from_file (PANEL_APPLET (applet), NULL, "NMWirelessApplet.xml", NULL,
|
||||
nmwa_context_menu_verbs, applet);
|
||||
|
||||
|
|
@ -534,7 +563,7 @@ static gboolean nmwa_fill (NMWirelessApplet *applet)
|
|||
glade_file = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_DATADIR,
|
||||
"NMWirelessApplet/wireless-applet.glade", FALSE, NULL);
|
||||
|
||||
nmwa_new (applet);
|
||||
gtk_widget_show (nmwa_new (applet));
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ typedef struct
|
|||
gboolean nm_active;
|
||||
gboolean have_active_device;
|
||||
|
||||
PixmapState pix_state;
|
||||
/* contains pointers into the images GList.
|
||||
* 0-100 are for link */
|
||||
GdkPixbuf *pixmaps[PIX_NUMBER];
|
||||
|
|
|
|||
|
|
@ -53,11 +53,9 @@ char * nmwa_dbus_get_string (DBusConnection *connection, const char *path, const
|
|||
g_return_val_if_fail (path != NULL, NULL);
|
||||
g_return_val_if_fail (method != NULL, NULL);
|
||||
|
||||
fprintf( stderr, "path = '%s', method = '%s' interface = '%s'\n", path, method, NM_DBUS_INTERFACE);
|
||||
|
||||
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE, method)))
|
||||
{
|
||||
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
||||
fprintf (stderr, "nmwa_dbus_get_string(): Couldn't allocate the dbus message\n");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
|
@ -65,14 +63,14 @@ fprintf( stderr, "path = '%s', method = '%s' interface = '%s'\n", path, method,
|
|||
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
||||
if (dbus_error_is_set (&error))
|
||||
{
|
||||
fprintf (stderr, "aaa %s raised:\n %s\n\n", error.name, error.message);
|
||||
fprintf (stderr, "nmwa_dbus_get_string(): %s raised:\n %s\n\n", error.name, error.message);
|
||||
dbus_message_unref (message);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (reply == NULL)
|
||||
{
|
||||
fprintf (stderr, "dbus reply message was NULL\n" );
|
||||
fprintf (stderr, "nmwa_dbus_get_string(): dbus reply message was NULL\n" );
|
||||
dbus_message_unref (message);
|
||||
return (NULL);
|
||||
}
|
||||
|
|
@ -80,14 +78,13 @@ fprintf( stderr, "path = '%s', method = '%s' interface = '%s'\n", path, method,
|
|||
dbus_error_init (&error);
|
||||
if (!dbus_message_get_args (reply, &error, DBUS_TYPE_STRING, &string, DBUS_TYPE_INVALID))
|
||||
{
|
||||
fprintf (stderr, "bbb %s raised:\n %s\n\n", error.name, error.message);
|
||||
fprintf (stderr, "nmwa_dbus_get_string(): error while getting args: name='%s' message='%s'\n", error.name, error.message);
|
||||
string = NULL;
|
||||
}
|
||||
|
||||
dbus_message_unref (reply);
|
||||
dbus_message_unref (message);
|
||||
|
||||
fprintf (stderr, "getstring done\n");
|
||||
return (string);
|
||||
}
|
||||
|
||||
|
|
@ -107,11 +104,9 @@ gint32 nmwa_dbus_get_int (DBusConnection *connection, const char *path, const ch
|
|||
g_return_val_if_fail (path != NULL, 0);
|
||||
g_return_val_if_fail (method != NULL, 0);
|
||||
|
||||
fprintf( stderr, "getint() path = '%s', method = '%s' interface = '%s'\n", path, method, NM_DBUS_INTERFACE);
|
||||
|
||||
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE, method)))
|
||||
{
|
||||
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
||||
fprintf (stderr, "nmwa_dbus_get_int(): Couldn't allocate the dbus message\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
@ -119,14 +114,14 @@ fprintf( stderr, "getint() path = '%s', method = '%s' interface = '%s'\n", path,
|
|||
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
||||
if (dbus_error_is_set (&error))
|
||||
{
|
||||
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
|
||||
fprintf (stderr, "nmwa_dbus_get_int(): %s raised:\n %s\n\n", error.name, error.message);
|
||||
dbus_message_unref (message);
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (reply == NULL)
|
||||
{
|
||||
fprintf( stderr, "dbus reply message was NULL\n" );
|
||||
fprintf( stderr, "nmwa_dbus_get_int(): dbus reply message was NULL\n" );
|
||||
dbus_message_unref (message);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -138,7 +133,6 @@ fprintf( stderr, "getint() path = '%s', method = '%s' interface = '%s'\n", path,
|
|||
dbus_message_unref (reply);
|
||||
dbus_message_unref (message);
|
||||
|
||||
fprintf( stderr, "end getint\n");
|
||||
return (num);
|
||||
}
|
||||
|
||||
|
|
@ -158,11 +152,9 @@ double nmwa_dbus_get_double (DBusConnection *connection, const char *path, const
|
|||
g_return_val_if_fail (path != NULL, 0);
|
||||
g_return_val_if_fail (method != NULL, 0);
|
||||
|
||||
fprintf( stderr, "getdouble(): path = '%s', method = '%s' interface = '%s'\n", path, method, NM_DBUS_INTERFACE);
|
||||
|
||||
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE, method)))
|
||||
{
|
||||
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
||||
fprintf (stderr, "nmwa_dbus_get_double(): Couldn't allocate the dbus message\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
@ -170,14 +162,14 @@ fprintf( stderr, "getdouble(): path = '%s', method = '%s' interface = '%s'\n", p
|
|||
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
||||
if (dbus_error_is_set (&error))
|
||||
{
|
||||
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
|
||||
fprintf (stderr, "nmwa_dbus_get_double(): %s raised:\n %s\n\n", error.name, error.message);
|
||||
dbus_message_unref (message);
|
||||
return (0);
|
||||
}
|
||||
|
||||
if (reply == NULL)
|
||||
{
|
||||
fprintf( stderr, "dbus reply message was NULL\n" );
|
||||
fprintf( stderr, "nmwa_dbus_get_double(): dbus reply message was NULL\n" );
|
||||
dbus_message_unref (message);
|
||||
return (0);
|
||||
}
|
||||
|
|
@ -212,11 +204,9 @@ char **nmwa_dbus_get_string_array (DBusConnection *connection, const char *path,
|
|||
g_return_val_if_fail (method != NULL, NULL);
|
||||
g_return_val_if_fail (num_items != NULL, NULL);
|
||||
|
||||
fprintf( stderr, "getstringarray() path = '%s', method = '%s' interface = '%s'\n", path, method, NM_DBUS_INTERFACE);
|
||||
|
||||
if (!(message = dbus_message_new_method_call (NM_DBUS_SERVICE, path, NM_DBUS_INTERFACE, method)))
|
||||
{
|
||||
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
||||
fprintf (stderr, "nmwa_dbus_get_string_array(): Couldn't allocate the dbus message\n");
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
|
|
@ -224,14 +214,14 @@ fprintf( stderr, "getstringarray() path = '%s', method = '%s' interface = '%s'\n
|
|||
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
||||
if (dbus_error_is_set (&error))
|
||||
{
|
||||
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
|
||||
fprintf (stderr, "nmwa_dbus_get_string_array(): %s raised:\n %s\n\n", error.name, error.message);
|
||||
dbus_message_unref (message);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
if (reply == NULL)
|
||||
{
|
||||
fprintf( stderr, "dbus reply message was NULL\n" );
|
||||
fprintf( stderr, "nmwa_dbus_get_string_array(): dbus reply message was NULL\n" );
|
||||
dbus_message_unref (message);
|
||||
return (NULL);
|
||||
}
|
||||
|
|
@ -244,49 +234,77 @@ fprintf( stderr, "getstringarray() path = '%s', method = '%s' interface = '%s'\n
|
|||
dbus_message_unref (reply);
|
||||
dbus_message_unref (message);
|
||||
|
||||
fprintf( stderr, "getstringarray() done\n");
|
||||
return (array);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmwa_dbus_get_active_wireless_device
|
||||
* nmwa_dbus_get_active_device
|
||||
*
|
||||
* Returns the object_path of the currently active wireless device, if any.
|
||||
* Returns the object_path of the currently active device, if any.
|
||||
*
|
||||
*/
|
||||
char * nmwa_dbus_get_active_wireless_device (DBusConnection *connection)
|
||||
char * nmwa_dbus_get_active_device (DBusConnection *connection)
|
||||
{
|
||||
char *active_device;
|
||||
|
||||
if (!connection)
|
||||
return (NULL);
|
||||
|
||||
if ((active_device = active_device = nmwa_dbus_get_string (connection, NM_DBUS_PATH, "getActiveDevice")))
|
||||
if ((active_device = nmwa_dbus_get_string (connection, NM_DBUS_PATH, "getActiveDevice")))
|
||||
{
|
||||
if (strlen (active_device) > 0)
|
||||
{
|
||||
int type;
|
||||
|
||||
type = nmwa_dbus_get_int (connection, active_device, "getType");
|
||||
if (type != 2) /* wireless */
|
||||
{
|
||||
dbus_free (active_device);
|
||||
active_device = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
if (strlen (active_device) < 1)
|
||||
{
|
||||
dbus_free (active_device);
|
||||
active_device = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
fprintf( stderr, "get_active_device() returning '%s'\n", active_device);
|
||||
return (active_device);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmwa_dbus_get_device_type
|
||||
*
|
||||
* Returns the object_path of the currently active device, if any.
|
||||
*
|
||||
*/
|
||||
int nmwa_dbus_get_device_type (DBusConnection *connection, char *path)
|
||||
{
|
||||
if (!connection || !path)
|
||||
return (0);
|
||||
|
||||
return (nmwa_dbus_get_int (connection, path, "getType"));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmwa_dbus_get_nm_status
|
||||
*
|
||||
* Returns NetworkManager's status
|
||||
*
|
||||
*/
|
||||
char * nmwa_dbus_get_nm_status (DBusConnection *connection)
|
||||
{
|
||||
char *status;
|
||||
|
||||
if (!connection)
|
||||
return (NULL);
|
||||
|
||||
if ((status = nmwa_dbus_get_string (connection, NM_DBUS_PATH, "status")))
|
||||
{
|
||||
if (strlen (status) < 1)
|
||||
{
|
||||
dbus_free (status);
|
||||
status = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return (status);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* nmwa_dbus_add_networks_to_menu
|
||||
*
|
||||
|
|
@ -303,40 +321,39 @@ void nmwa_dbus_add_networks_to_menu (DBusConnection *connection, gpointer user_d
|
|||
if (!connection)
|
||||
{
|
||||
nmwa_add_menu_item ("No wireless networks found...", FALSE, user_data);
|
||||
fprintf( stderr, "!connection\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(active_device = nmwa_dbus_get_active_wireless_device (connection)))
|
||||
if (!(active_device = nmwa_dbus_get_active_device (connection)))
|
||||
{
|
||||
nmwa_add_menu_item ("No wireless networks found...", FALSE, user_data);
|
||||
fprintf( stderr, "!active_device\n");
|
||||
nmwa_add_menu_item ("No network connection is present.", FALSE, user_data);
|
||||
return;
|
||||
}
|
||||
fprintf( stderr, "active_device = '%s'\n", active_device);
|
||||
if (!(active_network = nmwa_dbus_get_string (connection, active_device, "getActiveNetwork")))
|
||||
|
||||
switch (nmwa_dbus_get_device_type (connection, active_device))
|
||||
{
|
||||
nmwa_add_menu_item ("No wireless networks found...", FALSE, user_data);
|
||||
fprintf( stderr, "!active_network\n");
|
||||
return;
|
||||
case (DEVICE_TYPE_WIRED_ETHERNET):
|
||||
nmwa_add_menu_item ("A wired ethernet card is currently active.", FALSE, user_data);
|
||||
return;
|
||||
|
||||
case (DEVICE_TYPE_WIRELESS_ETHERNET):
|
||||
break;
|
||||
|
||||
default:
|
||||
nmwa_add_menu_item ("Some other network device is currently active.", FALSE, user_data);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Get each of the networks in turn and add them to the menu */
|
||||
if ((networks = nmwa_dbus_get_string_array (connection, active_device, "getNetworks", &num_items)))
|
||||
{
|
||||
fprintf ( stderr, "foobar\n");
|
||||
if (strlen (networks[0]) == 0)
|
||||
{
|
||||
fprintf ( stderr, "foobar2\n");
|
||||
nmwa_add_menu_item ("No wireless networks found...", FALSE, user_data);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf ( stderr, "foobar3\n");
|
||||
int i;
|
||||
for (i = 0; i < num_items; i++)
|
||||
{
|
||||
fprintf ( stderr, "foobar %d\n", i + 10);
|
||||
char *name = nmwa_dbus_get_string (connection, networks[i], "getName");
|
||||
nmwa_add_menu_item (name, (strcmp (networks[i], active_network) == 0), user_data);
|
||||
dbus_free (name);
|
||||
|
|
@ -344,10 +361,7 @@ fprintf ( stderr, "foobar %d\n", i + 10);
|
|||
}
|
||||
dbus_free_string_array (networks);
|
||||
}
|
||||
else
|
||||
fprintf( stderr, "!networks\n");
|
||||
|
||||
fprintf( stderr, "done iwth menu population\n");
|
||||
dbus_free (active_device);
|
||||
}
|
||||
|
||||
|
|
@ -436,7 +450,7 @@ DBusConnection * nmwa_dbus_init (gpointer user_data)
|
|||
if (!dbus_connection_add_filter (connection, nmwa_dbus_filter, user_data, NULL))
|
||||
return (NULL);
|
||||
|
||||
// dbus_connection_set_exit_on_disconnect (connection, FALSE);
|
||||
dbus_connection_set_exit_on_disconnect (connection, FALSE);
|
||||
dbus_connection_setup_with_g_main (connection, NULL);
|
||||
|
||||
dbus_bus_add_match(connection,
|
||||
|
|
|
|||
|
|
@ -25,12 +25,24 @@
|
|||
#include <dbus/dbus.h>
|
||||
#include <dbus/dbus-glib.h>
|
||||
|
||||
/* Must match NetworkManager device types */
|
||||
enum
|
||||
{
|
||||
DEVICE_TYPE_DONT_KNOW = 0,
|
||||
DEVICE_TYPE_WIRED_ETHERNET,
|
||||
DEVICE_TYPE_WIRELESS_ETHERNET
|
||||
};
|
||||
|
||||
DBusConnection * nmwa_dbus_init (gpointer user_data);
|
||||
|
||||
gboolean nmwa_dbus_nm_is_running (DBusConnection *connection);
|
||||
|
||||
void nmwa_dbus_add_networks_to_menu (DBusConnection *connection, gpointer user_data);
|
||||
|
||||
char * nmwa_dbus_get_active_wireless_device (DBusConnection *connection);
|
||||
char * nmwa_dbus_get_active_device (DBusConnection *connection);
|
||||
|
||||
int nmwa_dbus_get_device_type (DBusConnection *connection, char *path);
|
||||
|
||||
char * nmwa_dbus_get_nm_status (DBusConnection *connection);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -873,7 +873,7 @@ static DBusHandlerResult nm_dbus_nmi_filter (DBusConnection *connection, DBusMes
|
|||
if (!(object_path = dbus_message_get_path (message)))
|
||||
return (DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
|
||||
|
||||
NM_DEBUG_PRINT_2 ("nm_dbus_nmi_filter() got method %s for path %s\n", method, object_path);
|
||||
/* NM_DEBUG_PRINT_2 ("nm_dbus_nmi_filter() got method %s for path %s\n", method, object_path); /**/
|
||||
|
||||
if ( (strcmp (object_path, NMI_DBUS_PATH) == 0)
|
||||
&& dbus_message_is_signal (message, NMI_DBUS_INTERFACE, "TrustedNetworkUpdate"))
|
||||
|
|
@ -1069,7 +1069,7 @@ static DBusMessage *nm_dbus_devices_handle_request (DBusConnection *connection,
|
|||
|
||||
if ((ap = nm_device_ap_list_get_ap_by_essid (dev, nm_device_get_essid (dev))))
|
||||
{
|
||||
if ((object_path = nm_device_get_path_for_ap (dev, ap)))
|
||||
if ((ap == nm_device_get_best_ap (dev)) && (object_path = nm_device_get_path_for_ap (dev, ap)))
|
||||
{
|
||||
dbus_message_append_args (reply_message, DBUS_TYPE_STRING, object_path, DBUS_TYPE_INVALID);
|
||||
g_free (object_path);
|
||||
|
|
@ -1160,7 +1160,7 @@ static DBusHandlerResult nm_dbus_nm_message_handler (DBusConnection *connection,
|
|||
method = dbus_message_get_member (message);
|
||||
path = dbus_message_get_path (message);
|
||||
|
||||
NM_DEBUG_PRINT_2 ("nm_dbus_nm_message_handler() got method %s for path %s\n", method, path);
|
||||
/* NM_DEBUG_PRINT_2 ("nm_dbus_nm_message_handler() got method %s for path %s\n", method, path); /**/
|
||||
|
||||
if (strcmp ("getActiveDevice", method) == 0)
|
||||
reply_message = nm_dbus_nm_get_active_device (connection, message, data);
|
||||
|
|
@ -1173,10 +1173,10 @@ static DBusHandlerResult nm_dbus_nm_message_handler (DBusConnection *connection,
|
|||
reply_message = dbus_message_new_method_return (message);
|
||||
if (reply_message)
|
||||
{
|
||||
if (data->active_device)
|
||||
dbus_message_append_args (reply_message, DBUS_TYPE_STRING, "connected", DBUS_TYPE_INVALID);
|
||||
if (data->active_device && nm_device_activating (data->active_device))
|
||||
dbus_message_append_args (reply_message, DBUS_TYPE_STRING, "connecting", DBUS_TYPE_INVALID);
|
||||
else if (data->active_device)
|
||||
dbus_message_append_args (reply_message, DBUS_TYPE_STRING, "connected", DBUS_TYPE_INVALID);
|
||||
else
|
||||
dbus_message_append_args (reply_message, DBUS_TYPE_STRING, "disconnected", DBUS_TYPE_INVALID);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1413,7 +1413,6 @@ void nm_device_update_best_ap (NMDevice *dev)
|
|||
char *ap_essid = nm_ap_get_essid (ap);
|
||||
|
||||
/* Access points in the "invalid" list cannot be used */
|
||||
fprintf( stderr, "PREF: Looking at ap '%s'\n", nm_ap_get_essid (ap));
|
||||
if (!nm_ap_list_get_ap_by_essid (dev->app_data->invalid_ap_list, ap_essid))
|
||||
{
|
||||
NMAccessPoint *tmp_ap = nm_ap_list_get_ap_by_essid (dev->app_data->preferred_ap_list, ap_essid);
|
||||
|
|
@ -1423,7 +1422,6 @@ fprintf( stderr, "PREF: Looking at ap '%s'\n", nm_ap_get_essid (ap));
|
|||
*/
|
||||
if ( tmp_ap && (nm_ap_get_priority (tmp_ap) < highest_priority))
|
||||
{
|
||||
fprintf( stderr, "PREF: setting ap '%s' as best\n", nm_ap_get_essid (ap));
|
||||
best_ap = ap;
|
||||
highest_priority = nm_ap_get_priority (ap);
|
||||
}
|
||||
|
|
@ -1432,7 +1430,14 @@ fprintf( stderr, "PREF: setting ap '%s' as best\n", nm_ap_get_essid (ap));
|
|||
nm_ap_list_iter_free (iter);
|
||||
}
|
||||
|
||||
/* If the best ap is NULL, bring device down and clear out its essid and AP */
|
||||
nm_device_set_best_ap (dev, best_ap);
|
||||
if (!best_ap)
|
||||
{
|
||||
nm_device_bring_down (dev);
|
||||
nm_device_set_essid (dev, "");
|
||||
nm_device_bring_up (dev);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -128,6 +128,55 @@ void get_device_name (DBusConnection *connection, char *path)
|
|||
dbus_message_unref (message);
|
||||
}
|
||||
|
||||
void get_nm_status (DBusConnection *connection)
|
||||
{
|
||||
DBusMessage *message;
|
||||
DBusMessage *reply;
|
||||
DBusMessageIter iter;
|
||||
DBusError error;
|
||||
|
||||
message = dbus_message_new_method_call ("org.freedesktop.NetworkManager",
|
||||
"/org/freedesktop/NetworkManager",
|
||||
"org.freedesktop.NetworkManager",
|
||||
"status");
|
||||
if (message == NULL)
|
||||
{
|
||||
fprintf (stderr, "Couldn't allocate the dbus message\n");
|
||||
return;
|
||||
}
|
||||
|
||||
dbus_error_init (&error);
|
||||
reply = dbus_connection_send_with_reply_and_block (connection, message, -1, &error);
|
||||
if (dbus_error_is_set (&error))
|
||||
{
|
||||
fprintf (stderr, "%s raised:\n %s\n\n", error.name, error.message);
|
||||
dbus_message_unref (message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (reply == NULL)
|
||||
{
|
||||
fprintf( stderr, "dbus reply message was NULL\n" );
|
||||
dbus_message_unref (message);
|
||||
return;
|
||||
}
|
||||
|
||||
/* now analyze reply */
|
||||
dbus_message_iter_init (reply, &iter);
|
||||
char *string;
|
||||
string = dbus_message_iter_get_string (&iter);
|
||||
if (!string)
|
||||
{
|
||||
fprintf (stderr, "NetworkManager returned a NULL status" );
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf (stderr, "NM Status: '%s'\n", string );
|
||||
|
||||
dbus_message_unref (reply);
|
||||
dbus_message_unref (message);
|
||||
}
|
||||
|
||||
void get_device_active_network (DBusConnection *connection, char *path)
|
||||
{
|
||||
DBusMessage *message;
|
||||
|
|
@ -441,6 +490,7 @@ int main( int argc, char *argv[] )
|
|||
char *path;
|
||||
int type;
|
||||
|
||||
get_nm_status (connection);
|
||||
path = get_active_device (connection);
|
||||
get_device_name (connection, path);
|
||||
type = get_device_type (connection, path);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue