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/>.
22
#include "applet-config.h"
23
#include "applet-notifications.h"
24
#include "applet-struct.h"
25
#include "applet-wifi.h"
26
#include "applet-draw.h"
27
#include "applet-init.h"
30
CD_APPLET_DEFINITION ("wifi",
32
CAIRO_DOCK_CATEGORY_ACCESSORY,
33
N_("This applet shows you the signal strength of the first active wifi connection\n"
34
"Left-click to pop-up some info,"
35
"Middle-click to re-check immediately."),
36
"ChAnGFu (Rémy Robertson)");
39
static void _set_data_renderer (CairoDockModuleInstance *myApplet, gboolean bReload)
41
CairoDataRendererAttribute *pRenderAttr = NULL; // les attributs du data-renderer global.
42
if (myConfig.iDisplayType == CD_WIFI_GAUGE)
44
CairoGaugeAttribute attr; // les attributs de la jauge.
45
memset (&attr, 0, sizeof (CairoGaugeAttribute));
46
pRenderAttr = CAIRO_DATA_RENDERER_ATTRIBUTE (&attr);
47
pRenderAttr->cModelName = "gauge";
48
attr.cThemePath = myConfig.cGThemePath;
50
else if (myConfig.iDisplayType == CD_WIFI_GRAPH)
52
CairoGraph2Attribute attr; // les attributs du graphe.
53
memset (&attr, 0, sizeof (CairoGraph2Attribute));
54
pRenderAttr = CAIRO_DATA_RENDERER_ATTRIBUTE (&attr);
55
pRenderAttr->cModelName = "graph";
56
pRenderAttr->iMemorySize = 32; // bon compromis sur la lisibilite.
57
attr.iType = myConfig.iGraphType;
59
attr.fHighColor = myConfig.fHigholor;
60
attr.fLowColor = myConfig.fLowColor;
61
memcpy (attr.fBackGroundColor, myConfig.fBgColor, 4*sizeof (double));
63
else if (myConfig.iDisplayType == CD_WIFI_BAR)
67
if (pRenderAttr != NULL)
69
pRenderAttr->iLatencyTime = myConfig.iCheckInterval * 1000 * myConfig.fSmoothFactor;
70
//pRenderAttr->bWriteValues = TRUE;
72
CD_APPLET_ADD_DATA_RENDERER_ON_MY_ICON (pRenderAttr);
74
CD_APPLET_RELOAD_MY_DATA_RENDERER (pRenderAttr);
79
if (myDesklet != NULL)
80
CD_APPLET_SET_DESKLET_RENDERER ("Simple");
82
// Initialisation du rendu.
83
_set_data_renderer (myApplet, FALSE);
85
// Initialisation de la tache periodique de mesure.
86
myData.iPreviousQuality = -2; // force le dessin.
87
myData.pTask = cairo_dock_new_task (myConfig.iCheckInterval,
88
(CairoDockGetDataAsyncFunc) cd_wifi_get_data,
89
(CairoDockUpdateSyncFunc) cd_wifi_update_from_data,
91
if (cairo_dock_is_loading ())
92
cairo_dock_launch_task_delayed (myData.pTask, 5000);
94
cairo_dock_launch_task (myData.pTask);
96
CD_APPLET_REGISTER_FOR_CLICK_EVENT;
97
CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
98
CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT;
103
//\_______________ On se desabonne de nos notifications.
104
CD_APPLET_UNREGISTER_FOR_CLICK_EVENT;
105
CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT;
106
CD_APPLET_UNREGISTER_FOR_MIDDLE_CLICK_EVENT;
110
CD_APPLET_RELOAD_BEGIN
111
//\_______________ On recharge les donnees qui ont pu changer.
112
if (myDesklet != NULL)
113
CD_APPLET_SET_DESKLET_RENDERER ("Simple");
115
int i; // reset surfaces utilisateurs.
116
for (i = 0; i < WIFI_NB_QUALITY; i ++) {
117
if (myData.pSurfaces[i] != NULL) {
118
cairo_surface_destroy (myData.pSurfaces[i]);
119
myData.pSurfaces[i] = NULL;
123
//\_______________ On relance avec la nouvelle config ou on redessine.
124
if (CD_APPLET_MY_CONFIG_CHANGED)
126
_set_data_renderer (myApplet, TRUE);
128
myData.iQuality = -2; // force le redessin.
129
myData.iPercent = -2;
130
myData.iSignalLevel = -2;
132
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL);
133
cairo_dock_stop_task (myData.pTask); // on stoppe avant car on ne veut pas attendre la prochaine iteration.
134
cairo_dock_change_task_frequency (myData.pTask, myConfig.iCheckInterval);
135
cairo_dock_launch_task (myData.pTask); // mesure immediate.
137
else // on redessine juste l'icone.
139
myData.iQuality = -2; // force le redessin.
140
if (! cairo_dock_task_is_running (myData.pTask))
142
if (myData.bWirelessExt)
144
cd_wifi_draw_icon ();
148
cd_wifi_draw_no_wireless_extension ();