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/>.
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"
29
CD_APPLET_DEFINITION (N_("Disks"),
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"
37
" - Find actions : left, middle click, drop and wheel\n"
38
" - Fill menu with actions\n"
39
" - Editable labels ?\n"
44
static void _set_data_renderer (CairoDockModuleInstance *myApplet, gboolean bReload)
46
CairoDataRendererAttribute *pRenderAttr = NULL; // les attributs generiques du data-renderer.
47
if (myConfig.iDisplayType == CD_DISKS_GAUGE)
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;
55
else if (myConfig.iDisplayType == CD_DISKS_GRAPH)
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;
64
attr.bMixGraphs = myConfig.bMixGraph;
65
double fHighColor[CD_DISKS_NB_MAX_VALUES*3];
66
double fLowColor[CD_DISKS_NB_MAX_VALUES*3];
68
for (i = 0; i < myData.iNumberDisks * 2; i+=2)
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));
75
attr.fHighColor = fHighColor;
76
attr.fLowColor = fLowColor;
77
memcpy (attr.fBackGroundColor, myConfig.fBgColor, 4*sizeof (double));
80
if (pRenderAttr != NULL) // attributs generiques.
82
const gchar *labels[CD_DISKS_NB_MAX_VALUES] = {};
83
if (myData.iNumberDisks > 0)
86
for (i = 0; i < myData.iNumberDisks; i++)
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]);
94
labels[2 * i] = pSpeed->cName;
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)
104
pRenderAttr->bWriteValues = TRUE;
105
pRenderAttr->format_value = (CairoDataRendererFormatValueFunc)cd_disks_format_value_on_icon;
106
pRenderAttr->pFormatData = myApplet;
110
CD_APPLET_ADD_DATA_RENDERER_ON_MY_ICON (pRenderAttr);
112
CD_APPLET_RELOAD_MY_DATA_RENDERER (pRenderAttr);
117
if (myDesklet != NULL) {
118
CD_APPLET_SET_DESKLET_RENDERER ("Simple");
119
CD_APPLET_ALLOW_NO_CLICKABLE_DESKLET;
122
// Initialisation du rendu.
123
myData.iNumberDisks = myConfig.iNumberDisks;
124
_set_data_renderer (myApplet, FALSE);
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,
132
//~ myData.bAcquisitionOK = TRUE;
133
cairo_dock_launch_task (myData.pPeriodicTask);
135
CD_APPLET_REGISTER_FOR_CLICK_EVENT;
136
CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
137
CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT;
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;
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.
154
CD_APPLET_SET_DESKLET_RENDERER ("Simple");
155
CD_APPLET_ALLOW_NO_CLICKABLE_DESKLET;
158
reset_disks_list (myApplet);
160
_set_data_renderer (myApplet, TRUE);
162
if (myConfig.iInfoDisplay != CAIRO_DOCK_INFO_ON_ICON)
164
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL);
166
if (myConfig.iInfoDisplay != CAIRO_DOCK_INFO_ON_LABEL)
168
CD_APPLET_SET_NAME_FOR_MY_ICON (myConfig.defaultTitle);
171
cairo_dock_relaunch_task_immediately (myData.pPeriodicTask, myConfig.iCheckInterval);
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;
178
if (! cairo_dock_task_is_running (myData.pPeriodicTask))
179
cd_disks_update_from_data (myApplet);