~ubuntu-branches/ubuntu/saucy/cairo-dock-plug-ins/saucy

« back to all changes in this revision

Viewing changes to wifi/src/applet-draw.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-08-26 21:07:39 UTC
  • Revision ID: james.westby@ubuntu.com-20090826210739-gyjuuqezrzuluao4
Tags: upstream-2.0.8.1
ImportĀ upstreamĀ versionĀ 2.0.8.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <stdio.h>
 
22
#include <string.h>
 
23
#include <glib/gi18n.h>
 
24
 
 
25
#include "applet-struct.h"
 
26
#include "applet-wifi.h"
 
27
#include "applet-draw.h"
 
28
 
 
29
 
 
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")};
 
32
 
 
33
 
 
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");
 
38
                
 
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);
 
43
                
 
44
                CD_APPLET_REDRAW_MY_ICON;
 
45
        }
 
46
}
 
47
 
 
48
void cd_wifi_draw_icon (void) {
 
49
        gboolean bNeedRedraw = FALSE;
 
50
        switch (myConfig.quickInfoType) {
 
51
                case WIFI_INFO_NONE :
 
52
                        if (myIcon->cQuickInfo != NULL) {
 
53
                                CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL);
 
54
                                bNeedRedraw = TRUE;
 
55
                        }
 
56
                break;
 
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]));
 
60
                                bNeedRedraw = TRUE;
 
61
                        }
 
62
                break;
 
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);
 
67
                                bNeedRedraw = TRUE;
 
68
                        }
 
69
                break;
 
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);
 
75
                                bNeedRedraw = TRUE;
 
76
                        }
 
77
                break;
 
78
        }
 
79
        
 
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);
 
85
                }
 
86
                else
 
87
                {
 
88
                        double fValue = (double) myData.iPercent / 100.;
 
89
                        CD_APPLET_RENDER_NEW_DATA_ON_MY_ICON (&fValue);
 
90
                }
 
91
        }
 
92
        
 
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);
 
95
        
 
96
        if (bNeedRedraw)
 
97
                CD_APPLET_REDRAW_MY_ICON;
 
98
}
 
99
 
 
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);
 
107
                }
 
108
                else {
 
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);
 
111
                        g_free (cImagePath);
 
112
                }
 
113
                pSurface = myData.pSurfaces[iQuality];
 
114
        }
 
115
        
 
116
        switch (myConfig.iEffect) {
 
117
                double fAlpha, fScale;
 
118
          case WIFI_EFFECT_NONE:
 
119
                CD_APPLET_SET_SURFACE_ON_MY_ICON (pSurface);
 
120
          break;
 
121
          case WIFI_EFFECT_ZOOM:
 
122
                fScale = .2 + .8 * myData.iPercent / 100.;
 
123
                CD_APPLET_SET_SURFACE_ON_MY_ICON_WITH_ZOOM (pSurface, fScale);
 
124
          break;
 
125
          case WIFI_EFFECT_TRANSPARENCY:
 
126
                fAlpha = .2 + .8 * myData.iPercent / 100.;
 
127
                CD_APPLET_SET_SURFACE_ON_MY_ICON_WITH_ALPHA (pSurface, fAlpha);
 
128
          break;
 
129
          case WIFI_EFFECT_BAR:
 
130
                CD_APPLET_SET_SURFACE_ON_MY_ICON_WITH_BAR (pSurface, myData.iPercent / 100.);
 
131
          break;
 
132
          default :
 
133
          break;
 
134
        }
 
135
}
 
136
 
 
137
void cd_wifi_bubble (void) {
 
138
        if (cairo_dock_task_is_running (myData.pTask))
 
139
        {
 
140
                cairo_dock_show_temporary_dialog  (D_("Checking connection...\nPlease retry in a few seconds"), myIcon, myContainer, 3000);
 
141
                return ;
 
142
        }
 
143
        GString *sInfo = g_string_new ("");
 
144
        gchar *cIconPath;
 
145
        if (! myData.bWirelessExt)
 
146
        {
 
147
                cIconPath = MY_APPLET_SHARE_DATA_DIR"/link-0.svg";
 
148
                g_string_assign (sInfo, D_("Wifi disabled."));
 
149
        }
 
150
        else
 
151
        {
 
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);
 
159
        }
 
160
                
 
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);}