2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
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.
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/>.
20
/******************************************************************************
22
This file is a part of the cairo-dock program,
23
released under the terms of the GNU General Public License.
25
Written by Rémy Robertson (for any bug report, please mail me to changfu@cairo-dock.org)
26
Fabrice Rey <fabounet@users.berlios.de>
28
******************************************************************************/
34
#include <glib/gi18n.h>
35
#include <glib/gstdio.h>
37
#include "applet-struct.h"
38
#include "applet-notifications.h"
39
#include "applet-draw.h"
40
#include "applet-wifi.h"
43
#define _pick_string(cValueName, cValue) \
44
str = g_strstr_len (cOneInfopipe, -1, cValueName);\
46
str += strlen (cValueName) + 1;\
51
str2 = strchr (str, '"'); }\
53
str2 = strchr (str, ' '); }\
55
cValue = g_strndup (str, str2 - str);\
56
cd_debug ("%s : %s", cValueName, cValue); } }
57
#define _pick_value(cValueName, iValue, iMaxValue)\
58
str = g_strstr_len (cOneInfopipe, -1, cValueName);\
60
str += strlen (cValueName) + 1;\
62
str2 = strchr (str, '/');\
64
iMaxValue = atoi (str2+1);\
65
cd_debug ("%s : %d (/%d)", cValueName, iValue, iMaxValue); }
67
void cd_wifi_get_data (gpointer data)
69
myData.iPreviousQuality = myData.iQuality;
71
myData.iPrevPercent = myData.iPercent;
73
myData.iPrevSignalLevel = myData.iSignalLevel;
74
myData.iSignalLevel = -1;
75
myData.iPrevNoiseLevel = myData.iNoiseLevel;
76
myData.iNoiseLevel = -1;
77
g_free (myData.cESSID);
79
g_free (myData.cInterface);
80
myData.cInterface = NULL;
81
g_free (myData.cAccessPoint);
82
myData.cAccessPoint = NULL;
84
gchar *cResult = cairo_dock_launch_command_sync (MY_APPLET_SHARE_DATA_DIR"/wifi");
85
if (cResult == NULL || *cResult == '\0') // // erreur a l'execution d'iwconfig (probleme de droit d'execution ou iwconfig pas installe) ou aucune interface wifi presente
91
gchar **cInfopipesList = g_strsplit (cResult, "\n", -1);
93
gchar *cOneInfopipe, *str, *str2;
95
for (i = 0; cInfopipesList[i] != NULL; i ++)
97
cOneInfopipe = cInfopipesList[i];
98
if (*cOneInfopipe == '\0' || *cOneInfopipe == '\n' )
101
if (myData.cInterface != NULL && *cOneInfopipe != ' ') // nouvelle interface, on n'en veut qu'une.
104
if (myData.cInterface == NULL && *cOneInfopipe != ' ')
106
str = cOneInfopipe; // le nom de l'interface est en debut de ligne.
107
str2 = strchr (str, ' ');
110
myData.cInterface = g_strndup (cOneInfopipe, str2 - str);
111
cd_debug ("interface : %s", myData.cInterface);
115
if (myData.cESSID == NULL)
117
_pick_string ("ESSID", myData.cESSID); // eth1 IEEE 802.11g ESSID:"bla bla bla"
119
/*if (myData.cNickName == NULL)
121
_pick_string ("Nickname", myData.cNickName);
123
if (myData.cAccessPoint == NULL)
125
_pick_string ("Access Point", myData.cAccessPoint);
128
if (myData.iQuality == -1) // Link Quality=54/100 Signal level=-76 dBm Noise level=-78 dBm OU Link Quality:5 Signal level:219 Noise level:177
131
_pick_value ("Link Quality", myData.iQuality, iMaxValue);
132
if (iMaxValue != 0) // vieille version, qualite indiquee en %
134
myData.iPercent = 100. * myData.iQuality / iMaxValue;
135
if (myData.iPercent <= 0)
136
myData.iQuality = WIFI_QUALITY_NO_SIGNAL;
137
else if (myData.iPercent < 20)
138
myData.iQuality = WIFI_QUALITY_VERY_LOW;
139
else if (myData.iPercent < 40)
140
myData.iQuality = WIFI_QUALITY_LOW;
141
else if (myData.iPercent < 60)
142
myData.iQuality = WIFI_QUALITY_MIDDLE;
143
else if (myData.iPercent < 80)
144
myData.iQuality = WIFI_QUALITY_GOOD;
146
myData.iQuality = WIFI_QUALITY_EXCELLENT;
150
myData.iPercent = 100. * myData.iQuality / (WIFI_NB_QUALITY-1);
153
if (myData.iSignalLevel == -1)
155
_pick_value ("Signal level", myData.iSignalLevel, iMaxValue);
157
if (myData.iNoiseLevel == -1)
159
_pick_value ("Noise level", myData.iNoiseLevel, iMaxValue);
162
g_strfreev (cInfopipesList);
166
gboolean cd_wifi_update_from_data (gpointer data)
168
if (myData.cInterface != NULL)
170
myData.bWirelessExt = TRUE;
171
cd_wifi_draw_icon ();
172
cairo_dock_set_normal_task_frequency (myData.pTask);
176
myData.bWirelessExt = FALSE;
177
cd_wifi_draw_no_wireless_extension ();
178
cairo_dock_downgrade_task_frequency (myData.pTask);