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

« back to all changes in this revision

Viewing changes to rame/src/applet-notifications.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
#include <string.h>
 
22
#include <glib/gi18n.h>
 
23
 
 
24
#include "applet-struct.h"
 
25
#include "applet-notifications.h"
 
26
#include "applet-rame.h"
 
27
 
 
28
 
 
29
 
 
30
 
 
31
static void _cd_rame_get_top_list (CairoDockModuleInstance *myApplet)
 
32
{
 
33
        cd_rame_get_process_memory ();
 
34
}
 
35
 
 
36
static gboolean _cd_rame_update_top_list (CairoDockModuleInstance *myApplet)
 
37
{
 
38
        CDProcess *pProcess;
 
39
        int i;
 
40
        
 
41
        for (i = 0; i < myConfig.iNbDisplayedProcesses; i ++)
 
42
        {
 
43
                if (myData.pTopList[i] == NULL || myData.pPreviousTopList[i] == NULL || myData.pTopList[i]->iPid != myData.pPreviousTopList[i]->iPid || myData.pTopList[i]->iMemAmount != myData.pPreviousTopList[i]->iMemAmount)
 
44
                        break ;
 
45
        }
 
46
        if (i == myConfig.iNbDisplayedProcesses)  // aucun changement.
 
47
        {
 
48
                return TRUE;
 
49
        }
 
50
        
 
51
        GString *sTopInfo = g_string_new ("");
 
52
        for (i = 0; i < myConfig.iNbDisplayedProcesses; i ++)
 
53
        {
 
54
                pProcess = myData.pTopList[i];
 
55
                if (pProcess == NULL)
 
56
                        break;
 
57
                g_string_append_printf (sTopInfo, "  %s (%d) : %.1f%s\n", pProcess->cName, pProcess->iPid, (double) pProcess->iMemAmount / (myConfig.bTopInPercent && myData.ramTotal ? 10.24 * myData.ramTotal : 1024 * 1024), (myConfig.bTopInPercent && myData.ramTotal ? "%" : D_("Mb")));
 
58
        }
 
59
        sTopInfo->str[sTopInfo->len-1] = '\0';
 
60
        
 
61
        cairo_dock_render_dialog_with_new_data (myData.pTopDialog, (CairoDialogRendererDataPtr) sTopInfo->str);
 
62
        g_string_free (sTopInfo, TRUE);
 
63
        return TRUE;
 
64
}
 
65
 
 
66
CD_APPLET_ON_CLICK_BEGIN
 
67
        if (myData.bAcquisitionOK)
 
68
        {
 
69
                if (myData.pTopDialog != NULL)
 
70
                {
 
71
                        cairo_dock_stop_task (myData.pTopTask);
 
72
                        cairo_dock_dialog_unreference (myData.pTopDialog);
 
73
                        myData.pTopDialog = NULL;
 
74
                        cairo_surface_destroy (myData.pTopSurface);
 
75
                        myData.pTopSurface = NULL;
 
76
                        cd_rame_clean_all_processes ();
 
77
                        return CAIRO_DOCK_INTERCEPT_NOTIFICATION;
 
78
                }
 
79
                
 
80
                gchar *cTitle = g_strdup_printf ("  [ Top %d ] :", myConfig.iNbDisplayedProcesses);
 
81
                gchar *cIconPath = g_strdup_printf ("%s/%s", MY_APPLET_SHARE_DATA_DIR, MY_APPLET_ICON_FILE);
 
82
                GtkWidget *pInteractiveWidget = gtk_vbox_new (FALSE, 0);
 
83
                gtk_widget_set_size_request (pInteractiveWidget,
 
84
                        myConfig.pTopTextDescription->iSize * 15,
 
85
                        myConfig.pTopTextDescription->iSize * myConfig.iNbDisplayedProcesses);  // approximatif au depart.
 
86
                myData.pTopDialog = cairo_dock_show_dialog_full (cTitle,
 
87
                        myIcon,
 
88
                        myContainer,
 
89
                        0,
 
90
                        cIconPath,
 
91
                        pInteractiveWidget,
 
92
                        NULL,
 
93
                        NULL,
 
94
                        NULL);
 
95
                g_free (cTitle);
 
96
                g_free (cIconPath);
 
97
                g_return_val_if_fail (myData.pTopDialog != NULL, CAIRO_DOCK_INTERCEPT_NOTIFICATION);
 
98
                
 
99
                gpointer pConfig[2] = {myConfig.pTopTextDescription, "Loading ..."};
 
100
                cairo_dock_set_dialog_renderer_by_name (myData.pTopDialog, "Text", myDrawContext, (CairoDialogRendererConfigPtr) pConfig);
 
101
                
 
102
                if (myData.pTopTask == NULL)
 
103
                        myData.pTopTask = cairo_dock_new_task (5,
 
104
                                (CairoDockGetDataAsyncFunc) _cd_rame_get_top_list,
 
105
                                (CairoDockUpdateSyncFunc) _cd_rame_update_top_list,
 
106
                                myApplet);
 
107
                cairo_dock_launch_task (myData.pTopTask);
 
108
        }
 
109
        else
 
110
                cairo_dock_show_temporary_dialog(D_("Data acquisition has failed"), myIcon, myContainer, 3e3);
 
111
CD_APPLET_ON_CLICK_END
 
112
 
 
113
 
 
114
static void _show_monitor_system (GtkMenuItem *menu_item, CairoDockModuleInstance *myApplet)
 
115
{
 
116
        if (myConfig.cSystemMonitorCommand != NULL)
 
117
        {
 
118
                cairo_dock_launch_command (myConfig.cSystemMonitorCommand);
 
119
        }
 
120
        else if (g_iDesktopEnv == CAIRO_DOCK_KDE)
 
121
        {
 
122
                system ("kde-system-monitor");
 
123
        }
 
124
        else
 
125
        {
 
126
                cairo_dock_fm_show_system_monitor ();
 
127
        }
 
128
}
 
129
CD_APPLET_ON_BUILD_MENU_BEGIN
 
130
        GtkWidget *pSubMenu = CD_APPLET_CREATE_MY_SUB_MENU ();
 
131
                CD_APPLET_ADD_IN_MENU (D_("Monitor System"), _show_monitor_system, pSubMenu);
 
132
                CD_APPLET_ADD_ABOUT_IN_MENU (pSubMenu);
 
133
CD_APPLET_ON_BUILD_MENU_END