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-rame.h"
28
CD_APPLET_DEFINITION ("ram-meter",
30
CAIRO_DOCK_CATEGORY_ACCESSORY,
31
N_("This applet shows you the amount of RAM and SWAP that is curently used\n"
32
"Left-click to show a list of the most memory using programs"),
36
if (myDesklet != NULL) {
37
CD_APPLET_SET_DESKLET_RENDERER ("Simple");
40
//Initialisation du rendu jauge/graphique.
41
double fMaxScale = cairo_dock_get_max_scale (myContainer);
42
if (myConfig.bUseGraphic)
44
myData.pGraph = cairo_dock_create_graph (myDrawContext,
45
20, myConfig.iGraphType | CAIRO_DOCK_DOUBLE_GRAPH | (myConfig.bMixGraph ? CAIRO_DOCK_MIX_DOUBLE_GRAPH : 0),
46
myIcon->fWidth * fMaxScale, myIcon->fHeight * fMaxScale,
47
myConfig.fLowColor, myConfig.fHigholor, myConfig.fBgColor, myConfig.fLowColor2, myConfig.fHigholor2);
48
if (myConfig.cWatermarkImagePath != NULL)
49
cairo_dock_add_watermark_on_graph (myDrawContext, myData.pGraph, myConfig.cWatermarkImagePath, myConfig.fAlpha);
50
CD_APPLET_RENDER_GRAPH (myData.pGraph);
54
myData.pGauge = cairo_dock_load_gauge(myDrawContext,myConfig.cGThemePath,myIcon->fWidth * fMaxScale, myIcon->fHeight * fMaxScale);
55
if (myConfig.cWatermarkImagePath != NULL)
56
cairo_dock_add_watermark_on_gauge (myDrawContext, myData.pGauge, myConfig.cWatermarkImagePath, myConfig.fAlpha);
57
CD_APPLET_RENDER_GAUGE (myData.pGauge, 0.);
60
//Initialisation du timer de mesure.
61
myData.pTask = cairo_dock_new_task (myConfig.iCheckInterval,
62
(CairoDockGetDataAsyncFunc) cd_rame_read_data,
63
(CairoDockUpdateSyncFunc) cd_rame_update_from_data,
65
myData.bAcquisitionOK = TRUE;
66
cairo_dock_launch_task (myData.pTask);
68
CD_APPLET_REGISTER_FOR_CLICK_EVENT;
69
CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
74
//\_______________ On se desabonne de nos notifications.
75
CD_APPLET_UNREGISTER_FOR_CLICK_EVENT;
76
CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT;
80
CD_APPLET_RELOAD_BEGIN
81
//\_______________ On recharge les donnees qui ont pu changer.
82
if (myDesklet != NULL) {
83
CD_APPLET_SET_DESKLET_RENDERER ("Simple");
86
double fMaxScale = cairo_dock_get_max_scale (myContainer);
88
if (CD_APPLET_MY_CONFIG_CHANGED) {
89
cairo_dock_free_gauge(myData.pGauge);
90
cairo_dock_free_graph (myData.pGraph);
91
if (myConfig.bUseGraphic)
94
myData.pGraph = cairo_dock_create_graph (myDrawContext,
95
20, myConfig.iGraphType | CAIRO_DOCK_DOUBLE_GRAPH | (myConfig.bMixGraph ? CAIRO_DOCK_MIX_DOUBLE_GRAPH : 0),
96
myIcon->fWidth * fMaxScale, myIcon->fHeight * fMaxScale,
97
myConfig.fLowColor, myConfig.fHigholor, myConfig.fBgColor, myConfig.fLowColor2, myConfig.fHigholor2);
98
if (myConfig.cWatermarkImagePath != NULL)
99
cairo_dock_add_watermark_on_graph (myDrawContext, myData.pGraph, myConfig.cWatermarkImagePath, myConfig.fAlpha);
103
myData.pGraph = NULL;
104
myData.pGauge = cairo_dock_load_gauge(myDrawContext,
105
myConfig.cGThemePath,
106
myIcon->fWidth * fMaxScale,myIcon->fHeight * fMaxScale);
107
if (myConfig.cWatermarkImagePath != NULL)
108
cairo_dock_add_watermark_on_gauge (myDrawContext, myData.pGauge, myConfig.cWatermarkImagePath, myConfig.fAlpha);
111
if (myConfig.iInfoDisplay != CAIRO_DOCK_INFO_ON_ICON)
113
CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL);
115
if (myConfig.iInfoDisplay != CAIRO_DOCK_INFO_ON_LABEL)
117
CD_APPLET_SET_NAME_FOR_MY_ICON (myConfig.defaultTitle);
120
myData.fPrevRamPercent = 0; // on force le redessin.
121
cairo_dock_relaunch_task_immediately (myData.pTask, myConfig.iCheckInterval);
123
if (cairo_dock_task_is_active (myData.pTopTask))
125
cd_rame_clean_all_processes ();
126
cairo_dock_stop_task (myData.pTopTask);
127
g_free (myData.pTopList);
128
myData.pTopList = NULL;
129
g_free (myData.pPreviousTopList);
130
myData.pPreviousTopList = NULL;
131
cairo_dock_launch_task (myData.pTopTask);
134
else { // on redessine juste l'icone.
135
if (myData.pGauge != NULL)
136
cairo_dock_reload_gauge (myDrawContext, myData.pGauge, myIcon->fWidth * fMaxScale, myIcon->fHeight * fMaxScale);
137
else if (myData.pGraph != NULL)
138
cairo_dock_reload_graph (myDrawContext, myData.pGraph, myIcon->fWidth * fMaxScale, myIcon->fHeight * fMaxScale);
139
else if (myConfig.bUseGraphic)
140
myData.pGraph = cairo_dock_create_graph (myDrawContext,
141
20, myConfig.iGraphType | CAIRO_DOCK_DOUBLE_GRAPH | (myConfig.bMixGraph ? CAIRO_DOCK_MIX_DOUBLE_GRAPH : 0),
142
myIcon->fWidth * fMaxScale, myIcon->fHeight * fMaxScale,
143
myConfig.fLowColor, myConfig.fHigholor, myConfig.fBgColor, myConfig.fLowColor2, myConfig.fHigholor2);
145
myData.pGauge = cairo_dock_load_gauge(myDrawContext,
146
myConfig.cGThemePath,
147
myIcon->fWidth * fMaxScale, myIcon->fHeight * fMaxScale);
148
if (myConfig.cWatermarkImagePath != NULL)
150
if (myData.pGauge != NULL)
151
cairo_dock_add_watermark_on_gauge (myDrawContext, myData.pGauge, myConfig.cWatermarkImagePath, myConfig.fAlpha);
153
cairo_dock_add_watermark_on_graph (myDrawContext, myData.pGraph, myConfig.cWatermarkImagePath, myConfig.fAlpha);
156
CairoDockLabelDescription *pOldLabelDescription = myConfig.pTopTextDescription; // on recupere le nouveau style des etiquettes en cas de changement de la config du dock.
157
myConfig.pTopTextDescription = cairo_dock_duplicate_label_description (&myDialogs.dialogTextDescription);
158
memcpy (myConfig.pTopTextDescription->fColorStart, pOldLabelDescription->fColorStart, 3*sizeof (double));
159
memcpy (myConfig.pTopTextDescription->fColorStop, pOldLabelDescription->fColorStop, 3*sizeof (double));
160
myConfig.pTopTextDescription->bVerticalPattern = TRUE;
161
cairo_dock_free_label_description (pOldLabelDescription);
163
myData.fPrevRamPercent = 0; // on force le redessin.
164
cd_rame_update_from_data (myApplet);