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/>.
23
#include <glib/gi18n.h>
25
#include "applet-struct.h"
26
#include "applet-wifi.h"
27
#include "applet-draw.h"
30
static gchar *s_cIconName[WIFI_NB_QUALITY] = {"link-0.svg", "link-1.svg", "link-2.svg", "link-3.svg", "link-4.svg", "link-5.svg"};
31
static gchar *s_cLevelQualityName[WIFI_NB_QUALITY] = {N_("None"), N_("Very Low"), N_("Low"), N_("Middle"), N_("Good"), N_("Excellent")};
34
void cd_wifi_draw_no_wireless_extension (void) {
35
if (myData.iPreviousQuality != myData.iQuality) {
36
if (myDesklet != NULL)
37
CD_APPLET_SET_DESKLET_RENDERER ("Simple");
39
myData.iPreviousQuality = myData.iQuality;
40
CD_APPLET_SET_NAME_FOR_MY_ICON (myConfig.defaultTitle);
41
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON ("N/A");
42
cd_wifi_draw_icon_with_effect (WIFI_QUALITY_NO_SIGNAL);
44
CD_APPLET_REDRAW_MY_ICON;
48
void cd_wifi_draw_icon (void) {
49
gboolean bNeedRedraw = FALSE;
50
switch (myConfig.quickInfoType) {
52
if (myIcon->cQuickInfo != NULL) {
53
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL);
57
case WIFI_INFO_SIGNAL_STRENGTH_LEVEL :
58
if (myData.iQuality != myData.iPreviousQuality) {
59
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (D_(s_cLevelQualityName[myData.iQuality]));
63
case WIFI_INFO_SIGNAL_STRENGTH_PERCENT :
64
if (myData.iPrevPercent != myData.iPercent) {
65
myData.iPrevPercent = myData.iPercent;
66
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON_PRINTF ("%d%%", myData.iPercent);
70
case WIFI_INFO_SIGNAL_STRENGTH_DB :
71
if (myData.iPrevSignalLevel != myData.iSignalLevel || myData.iPrevNoiseLevel != myData.iNoiseLevel) {
72
myData.iPrevSignalLevel = myData.iSignalLevel;
73
myData.iPrevNoiseLevel = myData.iNoiseLevel;
74
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON_PRINTF ("%d/%d", myData.iSignalLevel, myData.iNoiseLevel);
80
if (myData.iQuality != myData.iPreviousQuality || myConfig.iDisplayType == CD_WIFI_GRAPH) {
81
myData.iPreviousQuality = myData.iQuality;
82
//cd_debug ("Wifi - Value have changed, redraw. (Use Gauge: %d)", myConfig.bUseGauge);
83
if (myConfig.iDisplayType == CD_WIFI_BAR) {
84
cd_wifi_draw_icon_with_effect (myData.iQuality);
88
double fValue = (double) myData.iPercent / 100.;
89
CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (&fValue);
93
if (myConfig.bESSID && myData.cESSID != NULL && cairo_dock_strings_differ (myData.cESSID, myIcon->acName))
94
CD_APPLET_SET_NAME_FOR_MY_ICON (myData.cESSID);
97
CD_APPLET_REDRAW_MY_ICON;
100
void cd_wifi_draw_icon_with_effect (CDWifiQuality iQuality) {
101
cairo_surface_t *pSurface = myData.pSurfaces[iQuality];
102
if (pSurface == NULL) {
103
if (myConfig.cUserImage[iQuality] != NULL) {
104
gchar *cUserImagePath = cairo_dock_generate_file_path (myConfig.cUserImage[iQuality]);
105
myData.pSurfaces[iQuality] = CD_APPLET_LOAD_SURFACE_FOR_MY_APPLET (cUserImagePath);
106
g_free (cUserImagePath);
109
gchar *cImagePath = g_strdup_printf ("%s/%s", MY_APPLET_SHARE_DATA_DIR, s_cIconName[iQuality]);
110
myData.pSurfaces[iQuality] = CD_APPLET_LOAD_SURFACE_FOR_MY_APPLET (cImagePath);
113
pSurface = myData.pSurfaces[iQuality];
116
switch (myConfig.iEffect) {
117
double fAlpha, fScale;
118
case WIFI_EFFECT_NONE:
119
CD_APPLET_SET_SURFACE_ON_MY_ICON (pSurface);
121
case WIFI_EFFECT_ZOOM:
122
fScale = .2 + .8 * myData.iPercent / 100.;
123
CD_APPLET_SET_SURFACE_ON_MY_ICON_WITH_ZOOM (pSurface, fScale);
125
case WIFI_EFFECT_TRANSPARENCY:
126
fAlpha = .2 + .8 * myData.iPercent / 100.;
127
CD_APPLET_SET_SURFACE_ON_MY_ICON_WITH_ALPHA (pSurface, fAlpha);
129
case WIFI_EFFECT_BAR:
130
CD_APPLET_SET_SURFACE_ON_MY_ICON_WITH_BAR (pSurface, myData.iPercent / 100.);
137
void cd_wifi_bubble (void) {
138
if (cairo_dock_task_is_running (myData.pTask))
140
cairo_dock_show_temporary_dialog (D_("Checking connection...\nPlease retry in a few seconds"), myIcon, myContainer, 3000);
143
GString *sInfo = g_string_new ("");
145
if (! myData.bWirelessExt)
147
cIconPath = MY_APPLET_SHARE_DATA_DIR"/link-0.svg";
148
g_string_assign (sInfo, D_("Wifi disabled."));
152
cIconPath = MY_APPLET_SHARE_DATA_DIR"/link-5.svg";
153
g_string_assign (sInfo, D_("Wifi enabled."));
154
g_string_printf (sInfo, "%s : %s\n%s : %s\n%s : %s\n%s : %d/%d",
155
D_ ("Network ID"), myData.cESSID ? myData.cESSID : D_("unknown"),
156
D_ ("Access point"), myData.cAccessPoint,
157
D_ ("Interface"), myData.cInterface,
158
D_ ("Signal Quality"), myData.iQuality, WIFI_NB_QUALITY-1);
161
//cd_debug ("%s (%s)", sInfo->str, cIconPath);
162
cairo_dock_show_temporary_dialog_with_icon (sInfo->str, myIcon, myContainer, 6000, cIconPath);
163
g_string_free (sInfo, TRUE);}