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

« back to all changes in this revision

Viewing changes to wifi/src/applet-init.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
 
 
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_DEFINITION ("wifi",
 
31
        2, 0, 7,
 
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)");
 
37
 
 
38
 
 
39
static void _set_data_renderer (CairoDockModuleInstance *myApplet, gboolean bReload)
 
40
{
 
41
        CairoDataRendererAttribute *pRenderAttr = NULL;  // les attributs du data-renderer global.
 
42
        if (myConfig.iDisplayType == CD_WIFI_GAUGE)
 
43
        {
 
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;
 
49
        }
 
50
        else if (myConfig.iDisplayType == CD_WIFI_GRAPH)
 
51
        {
 
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;
 
58
                attr.iRadius = 10;
 
59
                attr.fHighColor = myConfig.fHigholor;
 
60
                attr.fLowColor = myConfig.fLowColor;
 
61
                memcpy (attr.fBackGroundColor, myConfig.fBgColor, 4*sizeof (double));
 
62
        }
 
63
        else if (myConfig.iDisplayType == CD_WIFI_BAR)
 
64
        {
 
65
                /// A FAIRE...
 
66
        }
 
67
        if (pRenderAttr != NULL)
 
68
        {
 
69
                pRenderAttr->iLatencyTime = myConfig.iCheckInterval * 1000 * myConfig.fSmoothFactor;
 
70
                //pRenderAttr->bWriteValues = TRUE;
 
71
                if (! bReload)
 
72
                        CD_APPLET_ADD_DATA_RENDERER_ON_MY_ICON (pRenderAttr);
 
73
                else
 
74
                        CD_APPLET_RELOAD_MY_DATA_RENDERER (pRenderAttr);
 
75
        }
 
76
}
 
77
 
 
78
CD_APPLET_INIT_BEGIN
 
79
        if (myDesklet != NULL)
 
80
                CD_APPLET_SET_DESKLET_RENDERER ("Simple");
 
81
        
 
82
        // Initialisation du rendu.
 
83
        _set_data_renderer (myApplet, FALSE);
 
84
        
 
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,
 
90
                myApplet);
 
91
        if (cairo_dock_is_loading ())
 
92
                cairo_dock_launch_task_delayed (myData.pTask, 5000);
 
93
        else
 
94
                cairo_dock_launch_task (myData.pTask);
 
95
        
 
96
        CD_APPLET_REGISTER_FOR_CLICK_EVENT;
 
97
        CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
 
98
        CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT;
 
99
CD_APPLET_INIT_END
 
100
 
 
101
 
 
102
CD_APPLET_STOP_BEGIN
 
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;
 
107
CD_APPLET_STOP_END
 
108
 
 
109
 
 
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");
 
114
        
 
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;
 
120
                }
 
121
        }
 
122
        
 
123
        //\_______________ On relance avec la nouvelle config ou on redessine.
 
124
        if (CD_APPLET_MY_CONFIG_CHANGED)
 
125
        {
 
126
                _set_data_renderer (myApplet, TRUE);
 
127
                
 
128
                myData.iQuality = -2;  // force le redessin.
 
129
                myData.iPercent = -2;
 
130
                myData.iSignalLevel = -2;
 
131
                
 
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.
 
136
        }
 
137
        else  // on redessine juste l'icone.
 
138
        {
 
139
                myData.iQuality = -2;  // force le redessin.
 
140
                if (! cairo_dock_task_is_running (myData.pTask))
 
141
                {
 
142
                        if (myData.bWirelessExt)
 
143
                        {
 
144
                                cd_wifi_draw_icon ();
 
145
                        }
 
146
                        else
 
147
                        {
 
148
                                cd_wifi_draw_no_wireless_extension ();
 
149
                        }
 
150
                }
 
151
        }
 
152
CD_APPLET_RELOAD_END