| 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 speed and space</i></b>.\n" |
| 33 |
"\n" |
| 34 |
"This applet show your disks informations. You can activate both options at once, but they're better separated in 2 or more instances of the applet.\n" |
| 35 |
"Using both in the same applet can cause problems with the speed display not scaling down.\n" |
| 36 |
"\n" |
| 37 |
"<b>Disk space</b> : Show disk transfer rates. Up to 10 partitions\n" |
| 38 |
" You need to configure the mount point of each monitored partition like / or /home\n" |
| 39 |
" Better seen in a gauge, with 30 or 60s refresh rate and really short or no transition delay.\n" |
| 40 |
"\n" |
| 41 |
"<b>Disk speed</b> : Show disk transfer rates. Up to 5 disks\n" |
| 42 |
" You need to configure the name of each monitored disk with his device name like sda or sdb\n" |
| 43 |
" Better seen in a graph, with 2 or 3s refresh rate and no delay between transitions.\n" |
| 44 |
"\n" |
| 45 |
"Second release, a lot more need to be done :\n" |
| 46 |
" <u>Free space :</u>\n" |
| 47 |
" - Popup with detailed informations.\n" |
| 48 |
" - Editable labels ?\n" |
| 49 |
" <u>Speed :</u>\n" |
| 50 |
" - All disks option.\n" |
| 51 |
" - Pop up showing disks info to know what to add in the list.\n" |
| 52 |
" - Editable labels ?\n" |
| 53 |
" - Get real block size for disks\n" |
| 54 |
" <u>Global</u>\n" |
| 55 |
" - Find actions : left, middle click, drop and wheel.\n" |
| 56 |
" - Fill menu with actions.\n" |
| 57 |
), |
| 58 |
"SQP"); |
| 59 |
|
| 60 |
|
| 61 |
static void _set_data_renderer (GldiModuleInstance *myApplet) |
| 62 |
{ |
| 63 |
CairoDataRendererAttribute *pRenderAttr = NULL; // attributes for the global data-renderer. |
| 64 |
CairoGaugeAttribute aGaugeAttr; // gauge attributes. |
| 65 |
CairoGraphAttribute aGraphAttr; // graph attributes. |
| 66 |
double fHighColor[CD_DISKS_NB_MAX_VALUES*3]; // attributes for the graph |
| 67 |
double fLowColor[CD_DISKS_NB_MAX_VALUES*3]; // (but have to be declared here to force GCC to keep data) |
| 68 |
if (myConfig.iDisplayType == CD_DISKS_GAUGE) |
| 69 |
{ |
| 70 |
memset (&aGaugeAttr, 0, sizeof (CairoGaugeAttribute)); |
| 71 |
pRenderAttr = CAIRO_DATA_RENDERER_ATTRIBUTE (&aGaugeAttr); |
| 72 |
pRenderAttr->cModelName = "gauge"; |
| 73 |
pRenderAttr->iRotateTheme = myConfig.iRotateTheme; |
| 74 |
aGaugeAttr.cThemePath = myConfig.cGThemePath; |
| 75 |
} |
| 76 |
else if (myConfig.iDisplayType == CD_DISKS_GRAPH) |
| 77 |
{ |
| 78 |
memset (&aGraphAttr, 0, sizeof (CairoGraphAttribute)); |
| 79 |
pRenderAttr = CAIRO_DATA_RENDERER_ATTRIBUTE (&aGraphAttr); |
| 80 |
pRenderAttr->cModelName = "graph"; |
| 81 |
pRenderAttr->iMemorySize = (myIcon->fWidth > 1 ? myIcon->fWidth : 32); // fWidth peut etre <= 1 en mode desklet au chargement. |
| 82 |
aGraphAttr.iType = myConfig.iGraphType; |
| 83 |
aGraphAttr.bMixGraphs = myConfig.bMixGraph; |
| 84 |
gsize i; |
| 85 |
for (i = 0; i < myData.iNumberDisks * 2; i+=2) |
| 86 |
{ |
| 87 |
memcpy (&fHighColor[3*i], myConfig.fHigholor, 3*sizeof (double)); |
| 88 |
memcpy (&fLowColor[3*i], myConfig.fLowColor, 3*sizeof (double)); |
| 89 |
memcpy (&fHighColor[3*i+3], myConfig.fHigholor, 3*sizeof (double)); |
| 90 |
memcpy (&fLowColor[3*i+3], myConfig.fLowColor, 3*sizeof (double)); |
| 91 |
} |
| 92 |
aGraphAttr.fHighColor = fHighColor; |
| 93 |
aGraphAttr.fLowColor = fLowColor; |
| 94 |
memcpy (aGraphAttr.fBackGroundColor, myConfig.fBgColor, 4*sizeof (double)); |
| 95 |
} |
| 96 |
|
| 97 |
const gchar *labels[CD_DISKS_NB_MAX_VALUES] = {}; |
| 98 |
|
| 99 |
if (myConfig.iNumberParts > 0) |
| 100 |
{ |
| 101 |
gsize i; |
| 102 |
for (i = 0; i < myConfig.iNumberParts; i++) |
| 103 |
{ |
| 104 |
/// Ca non plus je suppose :) |
| 105 |
double *pSize; |
| 106 |
pSize = g_new0 (double, 1); |
| 107 |
myData.lParts = g_list_append (myData.lParts, pSize); |
| 108 |
labels[i] = myConfig.cParts[i]; |
| 109 |
} |
| 110 |
} |
| 111 |
|
| 112 |
if (myData.iNumberDisks > 0) |
| 113 |
{ |
| 114 |
gsize i; |
| 115 |
for (i = 0; i < myData.iNumberDisks; i++) |
| 116 |
{ |
| 117 |
/// Ne pas faire ca ici !... |
| 118 |
CDDiskSpeedData *pSpeed; |
| 119 |
pSpeed = g_new0 (CDDiskSpeedData, 1); |
| 120 |
myData.lDisks = g_list_append (myData.lDisks, pSpeed); |
| 121 |
pSpeed->cName = g_strdup (myConfig.cDisks[i]); |
| 122 |
//~ pSpeed->uID = i; |
| 123 |
labels[2 * i] = pSpeed->cName; |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
pRenderAttr->cLabels = (gchar **)labels; |
| 128 |
pRenderAttr->iLatencyTime = myConfig.iCheckInterval * 1000 * myConfig.fSmoothFactor; |
| 129 |
pRenderAttr->iNbValues = myConfig.iNumberParts + 2 * myData.iNumberDisks; |
| 130 |
|
| 131 |
/// Problem here : should be FALSE for size and TRUE for speed. |
| 132 |
/// This version force FALSE when size is monitored, so applets using both monitors |
| 133 |
/// could have some display problems on speed display. |
| 134 |
pRenderAttr->bUpdateMinMax = !(myConfig.iNumberParts > 0); |
| 135 |
|
| 136 |
if (myConfig.iInfoDisplay == CAIRO_DOCK_INFO_ON_ICON) |
| 137 |
{ |
| 138 |
pRenderAttr->bWriteValues = TRUE; |
| 139 |
pRenderAttr->format_value = (CairoDataRendererFormatValueFunc)cd_disks_format_value_on_icon; |
| 140 |
pRenderAttr->pFormatData = myApplet; |
| 141 |
} |
| 142 |
|
| 143 |
CD_APPLET_ADD_DATA_RENDERER_ON_MY_ICON (pRenderAttr); |
| 144 |
} |
| 145 |
|
| 146 |
CD_APPLET_INIT_BEGIN |
| 147 |
if (myDesklet != NULL) { |
| 148 |
CD_APPLET_SET_DESKLET_RENDERER ("Simple"); |
| 149 |
CD_APPLET_ALLOW_NO_CLICKABLE_DESKLET; |
| 150 |
} |
| 151 |
|
| 152 |
// Initialisation du rendu. |
| 153 |
myData.iNumberDisks = myConfig.iNumberDisks; |
| 154 |
_set_data_renderer (myApplet); |
| 155 |
|
| 156 |
// Initialisation de la tache periodique de mesure. |
| 157 |
myData.pClock = g_timer_new (); |
| 158 |
myData.pPeriodicTask = gldi_task_new (myConfig.iCheckInterval, |
| 159 |
(GldiGetDataAsyncFunc) cd_disks_get_data, |
| 160 |
(GldiUpdateSyncFunc) cd_disks_update_from_data, |
| 161 |
myApplet); |
| 162 |
//~ myData.bAcquisitionOK = TRUE; |
| 163 |
gldi_task_launch (myData.pPeriodicTask); |
| 164 |
|
| 165 |
CD_APPLET_REGISTER_FOR_CLICK_EVENT; |
| 166 |
CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT; |
| 167 |
// CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT; |
| 168 |
CD_APPLET_INIT_END |
| 169 |
|
| 170 |
|
| 171 |
CD_APPLET_STOP_BEGIN |
| 172 |
//\_______________ On se desabonne de nos notifications. |
| 173 |
CD_APPLET_UNREGISTER_FOR_CLICK_EVENT; |
| 174 |
CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT; |
| 175 |
// CD_APPLET_UNREGISTER_FOR_MIDDLE_CLICK_EVENT; |
| 176 |
CD_APPLET_STOP_END |
| 177 |
|
| 178 |
|
| 179 |
CD_APPLET_RELOAD_BEGIN |
| 180 |
//\_______________ On recharge les donnees qui ont pu changer. |
| 181 |
if (CD_APPLET_MY_CONFIG_CHANGED) { |
| 182 |
if (myDesklet && CD_APPLET_MY_CONTAINER_TYPE_CHANGED) // we are now in a desklet, set a renderer. |
| 183 |
{ |
| 184 |
CD_APPLET_SET_DESKLET_RENDERER ("Simple"); |
| 185 |
CD_APPLET_ALLOW_NO_CLICKABLE_DESKLET; |
| 186 |
} |
| 187 |
|
| 188 |
cd_disks_reset_parts_list (myApplet); |
| 189 |
cd_disks_reset_disks_list (myApplet); |
| 190 |
|
| 191 |
_set_data_renderer (myApplet); |
| 192 |
|
| 193 |
if (myConfig.iInfoDisplay != CAIRO_DOCK_INFO_ON_ICON) |
| 194 |
{ |
| 195 |
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL); |
| 196 |
} |
| 197 |
if (myConfig.iInfoDisplay != CAIRO_DOCK_INFO_ON_LABEL) |
| 198 |
{ |
| 199 |
if (myConfig.defaultTitle) // has another default name |
| 200 |
CD_APPLET_SET_NAME_FOR_MY_ICON (myConfig.defaultTitle); |
| 201 |
else |
| 202 |
CD_APPLET_SET_NAME_FOR_MY_ICON (myApplet->pModule->pVisitCard->cTitle); |
| 203 |
} |
| 204 |
|
| 205 |
gldi_task_change_frequency_and_relaunch (myData.pPeriodicTask, myConfig.iCheckInterval); |
| 206 |
} |
| 207 |
else { // on redessine juste l'icone. |
| 208 |
//CD_APPLET_RELOAD_MY_DATA_RENDERER (NULL); |
| 209 |
if (myConfig.iDisplayType == CD_DISKS_GRAPH) |
| 210 |
CD_APPLET_SET_MY_DATA_RENDERER_HISTORY_TO_MAX; |
| 211 |
|
| 212 |
/**if (! gldi_task_is_running (myData.pPeriodicTask)) |
| 213 |
cd_disks_update_from_data (myApplet);*/ |
| 214 |
} |
| 215 |
CD_APPLET_RELOAD_END |