Debian Codegraph @

wifi/src/applet-init.c

raw
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
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"
28
29
30 CD_APPLET_DEFINE_BEGIN ("wifi",
31 3, 0, 2,
32 CAIRO_DOCK_CATEGORY_APPLET_INTERNET,
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)")
37 CD_APPLET_DEFINE_COMMON_APPLET_INTERFACE
38 CD_APPLET_ALLOW_EMPTY_TITLE
39 CD_APPLET_REDEFINE_TITLE (N_("Wifi"))
40 CD_APPLET_DEFINE_END
41
42
43 static void _set_data_renderer (GldiModuleInstance *myApplet, gboolean bReload)
44 {
45 CairoDataRendererAttribute *pRenderAttr = NULL; // attributes for the global data-renderer.
46 CairoGaugeAttribute aGaugeAttr; // gauge attributes.
47 CairoGraphAttribute aGraphAttr; // graph attributes.
48 CairoGraphAttribute aProgressBarAttr; // graph attributes.
49 switch (myConfig.iDisplayType)
50 {
51 case CD_WIFI_GAUGE:
52 {
53 memset (&aGaugeAttr, 0, sizeof (CairoGaugeAttribute));
54 pRenderAttr = CAIRO_DATA_RENDERER_ATTRIBUTE (&aGaugeAttr);
55 pRenderAttr->cModelName = "gauge";
56 aGaugeAttr.cThemePath = myConfig.cGThemePath;
57 }
58 break;
59 case CD_WIFI_GRAPH:
60 {
61 memset (&aGraphAttr, 0, sizeof (CairoGraphAttribute));
62 pRenderAttr = CAIRO_DATA_RENDERER_ATTRIBUTE (&aGraphAttr);
63 pRenderAttr->cModelName = "graph";
64 int w, h;
65 CD_APPLET_GET_MY_ICON_EXTENT (&w, &h);
66 pRenderAttr->iMemorySize = (w > 1 ? w : 32); // fWidth can be <= 1 in desklet mode when loading it
67 aGraphAttr.iType = myConfig.iGraphType;
68 aGraphAttr.fHighColor = myConfig.fHigholor;
69 aGraphAttr.fLowColor = myConfig.fLowColor;
70 memcpy (aGraphAttr.fBackGroundColor, myConfig.fBgColor, 4*sizeof (double));
71 }
72 break;
73 case CD_WIFI_BAR:
74 {
75 CD_APPLET_SET_USER_IMAGE_ON_MY_ICON (myConfig.cDefaultIcon, "default.svg");
76
77 memset (&aProgressBarAttr, 0, sizeof (CairoProgressBarAttribute));
78 pRenderAttr = CAIRO_DATA_RENDERER_ATTRIBUTE (&aProgressBarAttr);
79 pRenderAttr->cModelName = "progressbar";
80 }
81 break;
82 default:
83 break;
84 }
85 if (pRenderAttr != NULL)
86 {
87 pRenderAttr->iLatencyTime = myConfig.iCheckInterval * 1000 * myConfig.fSmoothFactor;
88 CD_APPLET_ADD_DATA_RENDERER_ON_MY_ICON (pRenderAttr);
89 }
90 }
91
92 static void _set_iwconfig_path (GldiModuleInstance *myApplet)
93 {
94 gchar *cResult = cairo_dock_launch_command_sync ("which iwconfig");
95 if (cResult != NULL && *cResult == '/')
96 myData.cIWConfigPath = cResult;
97 else
98 {
99 g_free (cResult);
100 // if '/sbin' is not in $PATH
101 myData.cIWConfigPath = g_strdup ("/sbin/iwconfig");
102 }
103 }
104
105 CD_APPLET_INIT_BEGIN
106 if (myDesklet != NULL)
107 {
108 CD_APPLET_SET_DESKLET_RENDERER ("Simple");
109 CD_APPLET_ALLOW_NO_CLICKABLE_DESKLET;
110 }
111
112 // Renderer Init
113 _set_data_renderer (myApplet, FALSE);
114
115 // check iwconfig path
116 _set_iwconfig_path (myApplet);
117
118 // Initialisation of the periodic task
119 myData.iPreviousQuality = -2; // force a redraw.
120 myData.pTask = gldi_task_new (myConfig.iCheckInterval,
121 (GldiGetDataAsyncFunc) cd_wifi_get_data,
122 (GldiUpdateSyncFunc) cd_wifi_update_from_data,
123 myApplet);
124 if (cairo_dock_is_loading ())
125 gldi_task_launch_delayed (myData.pTask, 2000);
126 else
127 gldi_task_launch (myData.pTask);
128
129 CD_APPLET_REGISTER_FOR_CLICK_EVENT;
130 CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
131 CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT;
132 CD_APPLET_INIT_END
133
134
135 CD_APPLET_STOP_BEGIN
136 //\_______________ On se desabonne de nos notifications.
137 CD_APPLET_UNREGISTER_FOR_CLICK_EVENT;
138 CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT;
139 CD_APPLET_UNREGISTER_FOR_MIDDLE_CLICK_EVENT;
140 CD_APPLET_STOP_END
141
142
143 CD_APPLET_RELOAD_BEGIN
144 //\_______________ On relance avec la nouvelle config ou on redessine.
145 if (CD_APPLET_MY_CONFIG_CHANGED)
146 {
147 if (myDesklet && CD_APPLET_MY_CONTAINER_TYPE_CHANGED) // we are now in a desklet, set a renderer.
148 {
149 CD_APPLET_SET_DESKLET_RENDERER ("Simple");
150 CD_APPLET_ALLOW_NO_CLICKABLE_DESKLET;
151 }
152
153 _set_data_renderer (myApplet, TRUE);
154
155 myData.iQuality = -2; // force le redessin.
156 myData.iPercent = -2;
157 myData.iSignalLevel = -2;
158
159 CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL);
160 gldi_task_change_frequency_and_relaunch (myData.pTask, myConfig.iCheckInterval);
161 }
162 else // on redessine juste l'icone.
163 {
164 ///CD_APPLET_RELOAD_MY_DATA_RENDERER (NULL);
165 if (myConfig.iDisplayType == CD_WIFI_GRAPH)
166 CD_APPLET_SET_MY_DATA_RENDERER_HISTORY_TO_MAX;
167
168 /**myData.iQuality = -2; // force le redessin.
169 if (! gldi_task_is_running (myData.pTask))
170 {
171 if (myData.bWirelessExt)
172 {
173 cd_wifi_draw_icon ();
174 }
175 else
176 {
177 cd_wifi_draw_no_wireless_extension ();
178 }
179 }*/
180 }
181 CD_APPLET_RELOAD_END