| 1 |
/** |
| 2 |
* This file is a part of the Cairo-Dock project |
| 3 |
* |
| 4 |
* Copyright : (C) see the 'copyright' file. |
| 5 |
* E-mail : see the 'copyright' file. |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or |
| 8 |
* modify it under the terms of the GNU General Public License |
| 9 |
* as published by the Free Software Foundation; either version 3 |
| 10 |
* of the License, or (at your option) any later version. |
| 11 |
* |
| 12 |
* This program is distributed in the hope that it will be useful, |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
* GNU General Public License for more details. |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <stdlib.h> |
| 21 |
#include <string.h> |
| 22 |
#include <glib/gi18n.h> |
| 23 |
|
| 24 |
#include "applet-struct.h" |
| 25 |
#include "applet-notifications.h" |
| 26 |
#include "applet-wifi.h" |
| 27 |
#include "applet-draw.h" |
| 28 |
|
| 29 |
|
| 30 |
CD_APPLET_ON_CLICK_BEGIN |
| 31 |
gldi_dialogs_remove_on_icon (myIcon); |
| 32 |
cd_wifi_bubble(); |
| 33 |
CD_APPLET_ON_CLICK_END |
| 34 |
|
| 35 |
|
| 36 |
static void _wifi_recheck_wireless_extension (GtkMenuItem *menu_item, gpointer data) |
| 37 |
{ |
| 38 |
gldi_task_stop (myData.pTask); |
| 39 |
gldi_task_launch (myData.pTask); |
| 40 |
} |
| 41 |
|
| 42 |
static void _cd_wifi_show_config (GtkMenuItem *menu_item, gpointer data) |
| 43 |
{ |
| 44 |
if (myConfig.cUserCommand != NULL) |
| 45 |
{ |
| 46 |
cairo_dock_launch_command (myConfig.cUserCommand); |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
const gchar *cCommand = "nm-connection-editor"; // network-admin n'est plus present depuis Intrepid, et nm-connection-editor marche aussi sous KDE. |
| 51 |
cairo_dock_launch_command (cCommand); |
| 52 |
} |
| 53 |
|
| 54 |
static void toggle_wlan (void) |
| 55 |
{ |
| 56 |
DBusGProxy *dbus_proxy_nm = cairo_dock_create_new_system_proxy ( |
| 57 |
"org.freedesktop.NetworkManager", |
| 58 |
"/org/freedesktop/NetworkManager", |
| 59 |
"org.freedesktop.NetworkManager"); |
| 60 |
g_return_if_fail (dbus_proxy_nm != NULL); |
| 61 |
|
| 62 |
guint state = 0; |
| 63 |
dbus_g_proxy_call (dbus_proxy_nm, "state", NULL, |
| 64 |
G_TYPE_INVALID, |
| 65 |
G_TYPE_UINT, &state, |
| 66 |
G_TYPE_INVALID); |
| 67 |
cd_debug ("current network state : %d", state); |
| 68 |
if (state == 3) // actif |
| 69 |
{ |
| 70 |
dbus_g_proxy_call_no_reply (dbus_proxy_nm, "sleep", |
| 71 |
G_TYPE_INVALID, |
| 72 |
G_TYPE_INVALID); |
| 73 |
} |
| 74 |
else if (state == 1) // inactif |
| 75 |
{ |
| 76 |
dbus_g_proxy_call_no_reply (dbus_proxy_nm, "wake", |
| 77 |
G_TYPE_INVALID, |
| 78 |
G_TYPE_INVALID); |
| 79 |
} |
| 80 |
|
| 81 |
g_object_unref (dbus_proxy_nm); |
| 82 |
} |
| 83 |
CD_APPLET_ON_BUILD_MENU_BEGIN |
| 84 |
if (! myData.bWirelessExt) |
| 85 |
CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Check for Wireless Extension"), GLDI_ICON_NAME_REFRESH, _wifi_recheck_wireless_extension, CD_APPLET_MY_MENU); |
| 86 |
else |
| 87 |
{ |
| 88 |
gchar *cLabel = g_strdup_printf ("%s (%s)", D_("Toggle wifi ON/OFF"), D_("middle-click")); |
| 89 |
CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel, (myData.iQuality == WIFI_QUALITY_NO_SIGNAL ? GLDI_ICON_NAME_MEDIA_PLAY : GLDI_ICON_NAME_MEDIA_PAUSE), toggle_wlan, CD_APPLET_MY_MENU); |
| 90 |
g_free (cLabel); |
| 91 |
} |
| 92 |
CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Network Administration"), GLDI_ICON_NAME_PREFERENCES, _cd_wifi_show_config, CD_APPLET_MY_MENU); |
| 93 |
CD_APPLET_ON_BUILD_MENU_END |
| 94 |
|
| 95 |
|
| 96 |
CD_APPLET_ON_MIDDLE_CLICK_BEGIN |
| 97 |
toggle_wlan (); |
| 98 |
CD_APPLET_ON_MIDDLE_CLICK_END |