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

« back to all changes in this revision

Viewing changes to cpusage/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-init.h"
 
26
#include "applet-cpusage.h"
 
27
 
 
28
 
 
29
CD_APPLET_DEFINITION (N_("cpusage"),
 
30
        1, 6, 3,
 
31
        CAIRO_DOCK_CATEGORY_ACCESSORY,
 
32
        N_("The cpusage applet show you the amount of CPU currently used.\n"
 
33
        "Middle click on the icon to get some valuable info.\n"
 
34
        "Left click on the icon to get a list of the most cpu using programs."),
 
35
        "parAdOxxx_ZeRo")
 
36
 
 
37
static gboolean _unthreaded_task (CairoDockModuleInstance *myApplet)
 
38
{
 
39
        cd_cpusage_read_data (myApplet);
 
40
        cd_cpusage_update_from_data (myApplet);
 
41
        return TRUE;
 
42
}
 
43
 
 
44
CD_APPLET_INIT_BEGIN
 
45
        if (myDesklet != NULL) {
 
46
                CD_APPLET_SET_DESKLET_RENDERER ("Simple");
 
47
        }
 
48
        
 
49
        //Initialisation du rendu jauge/graphique.
 
50
        double fMaxScale = cairo_dock_get_max_scale (myContainer);
 
51
        if (myConfig.bUseGraphic)
 
52
        {
 
53
                myData.pGraph = cairo_dock_create_graph (myDrawContext,
 
54
                        20, myConfig.iGraphType,
 
55
                        myIcon->fWidth * fMaxScale, myIcon->fHeight * fMaxScale,
 
56
                        myConfig.fLowColor, myConfig.fHigholor, myConfig.fBgColor, NULL, NULL);
 
57
                if (myConfig.cWatermarkImagePath != NULL)
 
58
                        cairo_dock_add_watermark_on_graph (myDrawContext, myData.pGraph, myConfig.cWatermarkImagePath, myConfig.fAlpha);
 
59
                CD_APPLET_RENDER_GRAPH (myData.pGraph);
 
60
        }
 
61
        else
 
62
        {
 
63
                myData.pGauge = cairo_dock_load_gauge(myDrawContext,myConfig.cGThemePath,myIcon->fWidth * fMaxScale, myIcon->fHeight * fMaxScale);
 
64
                if (myConfig.cWatermarkImagePath != NULL)
 
65
                        cairo_dock_add_watermark_on_gauge (myDrawContext, myData.pGauge, myConfig.cWatermarkImagePath, myConfig.fAlpha);
 
66
                CD_APPLET_RENDER_GAUGE (myData.pGauge, 0.);
 
67
        }
 
68
        
 
69
        //Initialisation du timer de mesure.
 
70
        myData.pClock = g_timer_new ();
 
71
        myData.pTask = cairo_dock_new_task (myConfig.iCheckInterval,
 
72
                (CairoDockGetDataAsyncFunc)NULL,  // cd_cpusage_read_data
 
73
                (CairoDockUpdateSyncFunc) _unthreaded_task,  // cd_cpusage_update_from_data
 
74
                myApplet);
 
75
        myData.bAcquisitionOK = TRUE;
 
76
        cairo_dock_launch_task (myData.pTask);
 
77
        
 
78
        CD_APPLET_REGISTER_FOR_CLICK_EVENT;
 
79
        CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT;
 
80
        CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
 
81
CD_APPLET_INIT_END
 
82
 
 
83
 
 
84
CD_APPLET_STOP_BEGIN
 
85
        //\_______________ On se desabonne de nos notifications.
 
86
        CD_APPLET_UNREGISTER_FOR_CLICK_EVENT;
 
87
        CD_APPLET_UNREGISTER_FOR_MIDDLE_CLICK_EVENT;
 
88
        CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT;
 
89
CD_APPLET_STOP_END
 
90
 
 
91
 
 
92
CD_APPLET_RELOAD_BEGIN
 
93
        //\_______________ On recharge les donnees qui ont pu changer.
 
94
        if (myDesklet != NULL) {
 
95
                CD_APPLET_SET_DESKLET_RENDERER ("Simple");
 
96
        }
 
97
        
 
98
        double fMaxScale = cairo_dock_get_max_scale (myContainer);
 
99
        if (CD_APPLET_MY_CONFIG_CHANGED) {
 
100
                
 
101
                cairo_dock_free_gauge (myData.pGauge);
 
102
                cairo_dock_free_graph (myData.pGraph);
 
103
                if (myConfig.bUseGraphic)
 
104
                {
 
105
                        myData.pGauge = NULL;
 
106
                        myData.pGraph = cairo_dock_create_graph (myDrawContext,
 
107
                                20, myConfig.iGraphType,
 
108
                                myIcon->fWidth * fMaxScale, myIcon->fHeight * fMaxScale,
 
109
                                myConfig.fLowColor, myConfig.fHigholor, myConfig.fBgColor, NULL, NULL);
 
110
                        if (myConfig.cWatermarkImagePath != NULL)
 
111
                                cairo_dock_add_watermark_on_graph (myDrawContext, myData.pGraph, myConfig.cWatermarkImagePath, myConfig.fAlpha);
 
112
                }
 
113
                else
 
114
                {
 
115
                        myData.pGraph = NULL;
 
116
                        myData.pGauge = cairo_dock_load_gauge(myDrawContext,
 
117
                                myConfig.cGThemePath,
 
118
                                myIcon->fWidth * fMaxScale,myIcon->fHeight * fMaxScale);
 
119
                        if (myConfig.cWatermarkImagePath != NULL)
 
120
                                cairo_dock_add_watermark_on_gauge (myDrawContext, myData.pGauge, myConfig.cWatermarkImagePath, myConfig.fAlpha);
 
121
                }
 
122
                
 
123
                if (myConfig.iInfoDisplay != CAIRO_DOCK_INFO_ON_ICON)
 
124
                {
 
125
                        CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL);
 
126
                }
 
127
                if (myConfig.iInfoDisplay != CAIRO_DOCK_INFO_ON_LABEL)
 
128
                {
 
129
                        CD_APPLET_SET_NAME_FOR_MY_ICON (myConfig.defaultTitle);
 
130
                }
 
131
                
 
132
                cairo_dock_relaunch_task_immediately (myData.pTask, myConfig.iCheckInterval);
 
133
                
 
134
                g_free (myData.pTopList);
 
135
                myData.pTopList = NULL;
 
136
                if (myData.pTopTask != NULL)
 
137
                        cairo_dock_change_task_frequency (myData.pTopTask, myConfig.iProcessCheckInterval);
 
138
        }
 
139
        else {  // on redessine juste l'icone.
 
140
                if (myData.pGauge != NULL)
 
141
                        cairo_dock_reload_gauge (myDrawContext, myData.pGauge, myIcon->fWidth * fMaxScale, myIcon->fHeight * fMaxScale);
 
142
                else if (myData.pGraph != NULL)
 
143
                        cairo_dock_reload_graph (myDrawContext, myData.pGraph, myIcon->fWidth * fMaxScale, myIcon->fHeight * fMaxScale);
 
144
                else if (myConfig.bUseGraphic)
 
145
                        myData.pGraph = cairo_dock_create_graph (myDrawContext,
 
146
                                20, myConfig.iGraphType,
 
147
                                myIcon->fWidth * fMaxScale, myIcon->fHeight * fMaxScale,
 
148
                                myConfig.fLowColor, myConfig.fHigholor, myConfig.fBgColor, NULL, NULL);
 
149
                else
 
150
                        myData.pGauge = cairo_dock_load_gauge(myDrawContext,
 
151
                                myConfig.cGThemePath,
 
152
                                myIcon->fWidth * fMaxScale, myIcon->fHeight * fMaxScale);
 
153
                if (myConfig.cWatermarkImagePath != NULL)
 
154
                {
 
155
                        if (myData.pGauge != NULL)
 
156
                                cairo_dock_add_watermark_on_gauge (myDrawContext, myData.pGauge, myConfig.cWatermarkImagePath, myConfig.fAlpha);
 
157
                        else
 
158
                                cairo_dock_add_watermark_on_graph (myDrawContext, myData.pGraph, myConfig.cWatermarkImagePath, myConfig.fAlpha);
 
159
                }
 
160
                
 
161
                CairoDockLabelDescription *pOldLabelDescription = myConfig.pTopTextDescription;
 
162
                myConfig.pTopTextDescription = cairo_dock_duplicate_label_description (&myDialogs.dialogTextDescription);
 
163
                memcpy (myConfig.pTopTextDescription->fColorStart, pOldLabelDescription->fColorStart, 3*sizeof (double));
 
164
                memcpy (myConfig.pTopTextDescription->fColorStop, pOldLabelDescription->fColorStop, 3*sizeof (double));
 
165
                myConfig.pTopTextDescription->bVerticalPattern = TRUE;
 
166
                cairo_dock_free_label_description (pOldLabelDescription);
 
167
                
 
168
                cd_cpusage_update_from_data (myApplet);
 
169
        }
 
170
CD_APPLET_RELOAD_END