~ubuntu-branches/ubuntu/quantal/cairo-dock-plug-ins/quantal-201208191523

« back to all changes in this revision

Viewing changes to Disks/src/applet-init.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2011-04-20 20:46:51 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20110420204651-ftnpzesj6uc7qeul
Tags: 2.3.0~1-0ubuntu1
* New Upstream Version (LP: #723995)
* Upstream short ChangeLog (since 2.3.0~0rc1):
 - Updated translations
 - Updated the integration of the new versions of kwin and compiz
    (Switcher, ShowDesktop, etc.)
 - Removed a lot of useless g_print
 - Updated a few plug-ins to fit with the new version of the API (gldit)
 - Fixed a few bugs
 - Updated MeMenu, MessagingMenu and Status-Notifier to works
    with the latest version of dbusmenu, etc.
* Switch to dpkg-source 3.0 (quilt) format
* debian/cairo-dock-plug-ins.install:
 - Added new files (interfaces for python, ruby, vala and mono)
* debian/control:
 - Added new dependences for new applets (sensors and zeitgeist)
    and new interfaces (python, valac, ruby and mono)
 - Updated the version of cairo-dock build-dependences
* debian/rules:
 - Added a new CMake flag to install python interface in debian/tmp
* Updated debian/watch

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-init.h"
 
26
#include "applet-disks.h"
 
27
 
 
28
 
 
29
CD_APPLET_DEFINITION (N_("Disks"),
 
30
        2, 0, 5,
 
31
        CAIRO_DOCK_CATEGORY_APPLET_SYSTEM,
 
32
        N_("<b><i>monitors disks activity</i></b>.\n\n"
 
33
        "Initial release, a lot more need to be done :\n"
 
34
        " - All disks option\n"
 
35
        " - Pop up showing disks info to know what to add in the list\n"
 
36
        " - Free space\n"
 
37
        " - Find actions : left, middle click, drop and wheel\n"
 
38
        " - Fill menu with actions\n"
 
39
        " - Editable labels ?\n"
 
40
        ),
 
41
        "SQP");
 
42
 
 
43
 
 
44
static void _set_data_renderer (CairoDockModuleInstance *myApplet, gboolean bReload)
 
45
{
 
46
        CairoDataRendererAttribute *pRenderAttr = NULL;  // les attributs generiques du data-renderer.
 
47
        if (myConfig.iDisplayType == CD_DISKS_GAUGE)
 
48
        {
 
49
                CairoGaugeAttribute attr;  // les attributs de la jauge.
 
50
                memset (&attr, 0, sizeof (CairoGaugeAttribute));
 
51
                pRenderAttr = CAIRO_DATA_RENDERER_ATTRIBUTE (&attr);
 
52
                pRenderAttr->cModelName = "gauge";
 
53
                attr.cThemePath = myConfig.cGThemePath;
 
54
        }
 
55
        else if (myConfig.iDisplayType == CD_DISKS_GRAPH)
 
56
        {
 
57
                CairoGraphAttribute attr;  // les attributs du graphe.
 
58
                memset (&attr, 0, sizeof (CairoGraphAttribute));
 
59
                pRenderAttr = CAIRO_DATA_RENDERER_ATTRIBUTE (&attr);
 
60
                pRenderAttr->cModelName = "graph";
 
61
                pRenderAttr->iMemorySize = (myIcon->fWidth > 1 ? myIcon->fWidth : 32);  // fWidht peut etre <= 1 en mode desklet au chargement.
 
62
                attr.iType = myConfig.iGraphType;
 
63
                attr.iRadius = 10;
 
64
                attr.bMixGraphs = myConfig.bMixGraph;
 
65
                double fHighColor[CD_DISKS_NB_MAX_VALUES*3];
 
66
                double fLowColor[CD_DISKS_NB_MAX_VALUES*3];
 
67
                gsize i;
 
68
                for (i = 0; i < myData.iNumberDisks * 2; i+=2)
 
69
                {
 
70
                        memcpy (&fHighColor[3*i], myConfig.fHigholor, 3*sizeof (double));
 
71
                        memcpy (&fLowColor[3*i], myConfig.fLowColor, 3*sizeof (double));
 
72
                        memcpy (&fHighColor[3*i+3], myConfig.fHigholor, 3*sizeof (double));
 
73
                        memcpy (&fLowColor[3*i+3], myConfig.fLowColor, 3*sizeof (double));
 
74
                }
 
75
                attr.fHighColor = fHighColor;
 
76
                attr.fLowColor = fLowColor;
 
77
                memcpy (attr.fBackGroundColor, myConfig.fBgColor, 4*sizeof (double));
 
78
        }
 
79
 
 
80
        if (pRenderAttr != NULL)  // attributs generiques.
 
81
        {
 
82
                const gchar *labels[CD_DISKS_NB_MAX_VALUES] = {};
 
83
                if (myData.iNumberDisks > 0)
 
84
                {
 
85
                        gsize i;
 
86
                        for (i = 0; i < myData.iNumberDisks; i++)
 
87
                        {
 
88
                                /// Ne pas faire ca ici !...
 
89
                                CDDiskSpeedData *pSpeed;
 
90
                                pSpeed = g_new0 (CDDiskSpeedData, 1);
 
91
                                myData.lDisks = g_list_append (myData.lDisks, pSpeed);
 
92
                                pSpeed->cName = g_strdup (myConfig.cDisks[i]);
 
93
                                //~ pSpeed->uID = i;
 
94
                                labels[2 * i] = pSpeed->cName;
 
95
                        }
 
96
                }
 
97
 
 
98
                pRenderAttr->cLabels = (gchar **)labels;
 
99
                pRenderAttr->iLatencyTime = myConfig.iCheckInterval * 1000 * myConfig.fSmoothFactor;
 
100
                pRenderAttr->iNbValues = 2 * myData.iNumberDisks;
 
101
                pRenderAttr->bUpdateMinMax = TRUE;
 
102
                if (myConfig.iInfoDisplay == CAIRO_DOCK_INFO_ON_ICON)
 
103
                {
 
104
                        pRenderAttr->bWriteValues = TRUE;
 
105
                        pRenderAttr->format_value = (CairoDataRendererFormatValueFunc)cd_disks_format_value_on_icon;
 
106
                        pRenderAttr->pFormatData = myApplet;
 
107
                }
 
108
 
 
109
                if (! bReload)
 
110
                        CD_APPLET_ADD_DATA_RENDERER_ON_MY_ICON (pRenderAttr);
 
111
                else
 
112
                        CD_APPLET_RELOAD_MY_DATA_RENDERER (pRenderAttr);
 
113
        }
 
114
}
 
115
 
 
116
CD_APPLET_INIT_BEGIN
 
117
        if (myDesklet != NULL) {
 
118
                CD_APPLET_SET_DESKLET_RENDERER ("Simple");
 
119
                CD_APPLET_ALLOW_NO_CLICKABLE_DESKLET;
 
120
        }
 
121
        
 
122
        // Initialisation du rendu.
 
123
        myData.iNumberDisks = myConfig.iNumberDisks;
 
124
        _set_data_renderer (myApplet, FALSE);
 
125
        
 
126
        // Initialisation de la tache periodique de mesure.
 
127
        myData.pClock = g_timer_new ();
 
128
        myData.pPeriodicTask = cairo_dock_new_task (myConfig.iCheckInterval,
 
129
                (CairoDockGetDataAsyncFunc) cd_disks_get_data,
 
130
                (CairoDockUpdateSyncFunc) cd_disks_update_from_data,
 
131
                myApplet);
 
132
        //~ myData.bAcquisitionOK = TRUE;
 
133
        cairo_dock_launch_task (myData.pPeriodicTask);
 
134
        
 
135
        CD_APPLET_REGISTER_FOR_CLICK_EVENT;
 
136
        CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
 
137
        CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT;
 
138
CD_APPLET_INIT_END
 
139
 
 
140
 
 
141
CD_APPLET_STOP_BEGIN
 
142
        //\_______________ On se desabonne de nos notifications.
 
143
        CD_APPLET_UNREGISTER_FOR_CLICK_EVENT;
 
144
        CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT;
 
145
        CD_APPLET_UNREGISTER_FOR_MIDDLE_CLICK_EVENT;
 
146
CD_APPLET_STOP_END
 
147
 
 
148
 
 
149
CD_APPLET_RELOAD_BEGIN
 
150
        //\_______________ On recharge les donnees qui ont pu changer.
 
151
        if (CD_APPLET_MY_CONFIG_CHANGED) {
 
152
                if (myDesklet && CD_APPLET_MY_CONTAINER_TYPE_CHANGED)  // we are now in a desklet, set a renderer.
 
153
                {
 
154
                        CD_APPLET_SET_DESKLET_RENDERER ("Simple");
 
155
                        CD_APPLET_ALLOW_NO_CLICKABLE_DESKLET;
 
156
                }
 
157
                
 
158
                reset_disks_list (myApplet);
 
159
                
 
160
                _set_data_renderer (myApplet, TRUE);
 
161
                
 
162
                if (myConfig.iInfoDisplay != CAIRO_DOCK_INFO_ON_ICON)
 
163
                {
 
164
                        CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL);
 
165
                }
 
166
                if (myConfig.iInfoDisplay != CAIRO_DOCK_INFO_ON_LABEL)
 
167
                {
 
168
                        CD_APPLET_SET_NAME_FOR_MY_ICON (myConfig.defaultTitle);
 
169
                }
 
170
                
 
171
                cairo_dock_relaunch_task_immediately (myData.pPeriodicTask, myConfig.iCheckInterval);
 
172
        }
 
173
        else {  // on redessine juste l'icone.
 
174
                CD_APPLET_RELOAD_MY_DATA_RENDERER (NULL);
 
175
                if (myConfig.iDisplayType == CD_DISKS_GRAPH)
 
176
                        CD_APPLET_SET_MY_DATA_RENDERER_HISTORY_TO_MAX;
 
177
                
 
178
                if (! cairo_dock_task_is_running (myData.pPeriodicTask))
 
179
                        cd_disks_update_from_data (myApplet);
 
180
        }
 
181
CD_APPLET_RELOAD_END