~cairo-dock-team/ubuntu/oneiric/cairo-dock-plug-ins/2.4.0-0beta2

« back to all changes in this revision

Viewing changes to logout/src/applet-notifications.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthieu Baerts (matttbe)
  • Date: 2011-04-20 20:46:51 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20110420204651-ftnpzesj6uc7qeul
Tags: 2.3.0~1-0ubuntu1
* New Upstream Version (LP: #723995)
* Upstream short ChangeLog (since 2.3.0~0rc1):
 - Updated translations
 - Updated the integration of the new versions of kwin and compiz
    (Switcher, ShowDesktop, etc.)
 - Removed a lot of useless g_print
 - Updated a few plug-ins to fit with the new version of the API (gldit)
 - Fixed a few bugs
 - Updated MeMenu, MessagingMenu and Status-Notifier to works
    with the latest version of dbusmenu, etc.
* Switch to dpkg-source 3.0 (quilt) format
* debian/cairo-dock-plug-ins.install:
 - Added new files (interfaces for python, ruby, vala and mono)
* debian/control:
 - Added new dependences for new applets (sensors and zeitgeist)
    and new interfaces (python, valac, ruby and mono)
 - Updated the version of cairo-dock build-dependences
* debian/rules:
 - Added a new CMake flag to install python interface in debian/tmp
* Updated debian/watch

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "applet-struct.h"
27
27
#include "applet-notifications.h"
28
28
 
 
29
#define GUEST_SESSION_LAUNCHER "/usr/share/gdm/guest-session/guest-session-launch"
 
30
 
29
31
 
30
32
static void _logout (void)
31
33
{
57
59
                }
58
60
        }
59
61
}
 
62
static inline void _execute_action (gint iAction)
 
63
{
 
64
        switch (iAction)
 
65
        {
 
66
                case CD_LOGOUT:
 
67
                default:
 
68
                        _logout ();
 
69
                break;
 
70
                case CD_SHUTDOWN:
 
71
                        _shutdown ();
 
72
                break;
 
73
                case CD_LOCK_SCREEN:
 
74
                        cairo_dock_fm_lock_screen ();
 
75
                break;
 
76
        }
 
77
}
 
78
 
60
79
CD_APPLET_ON_CLICK_BEGIN
61
80
{
62
 
        if (myIcon->Xid != 0)
 
81
        /**if (myIcon->Xid != 0)
63
82
        {
64
83
                if (cairo_dock_get_current_active_window () == myIcon->Xid && myTaskBar.bMinimizeOnClick)
65
84
                        cairo_dock_minimize_xwindow (myIcon->Xid);
66
85
                else
67
86
                        cairo_dock_show_xwindow (myIcon->Xid);
68
87
        }
69
 
        else
 
88
        else*/
70
89
        {
71
 
                if (myConfig.bInvertButtons)
72
 
                        _shutdown ();
73
 
                else
74
 
                        _logout ();
 
90
                // on execute l'action meme si la fenetre est deja ouverte (ca lui redonne le focus), car si on avait deja execute l'autre action, ca empeche de faire celle-ci.
 
91
                _execute_action (myConfig.iActionOnClick);
75
92
        }
76
93
}
77
94
CD_APPLET_ON_CLICK_END
79
96
 
80
97
CD_APPLET_ON_MIDDLE_CLICK_BEGIN
81
98
{
82
 
        if (myConfig.bInvertButtons)
83
 
                _logout ();
84
 
        else
85
 
                _shutdown ();
 
99
        _execute_action (myConfig.iActionOnMiddleClick);
86
100
}
87
101
CD_APPLET_ON_MIDDLE_CLICK_END
88
102
 
89
103
 
90
 
static void _cd_logout_lock_screen (GtkMenuItem *menu_item, gpointer data)
 
104
static void _cd_logout (GtkMenuItem *menu_item, gpointer data)
 
105
{
 
106
        CD_APPLET_ENTER;
 
107
        _logout ();
 
108
        CD_APPLET_LEAVE ();
 
109
}
 
110
static void _cd_shutdown (GtkMenuItem *menu_item, gpointer data)
 
111
{
 
112
        CD_APPLET_ENTER;
 
113
        _shutdown ();
 
114
        CD_APPLET_LEAVE ();
 
115
}
 
116
static void _cd_lock_screen (GtkMenuItem *menu_item, gpointer data)
91
117
{
92
118
        CD_APPLET_ENTER;
93
119
        cairo_dock_fm_lock_screen ();
94
120
        CD_APPLET_LEAVE ();
95
121
}
96
122
 
 
123
static void _cd_logout_guest_session (GtkMenuItem *menu_item, gpointer data)
 
124
{
 
125
        CD_APPLET_ENTER;
 
126
        gchar *cResult = cairo_dock_launch_command_sync ("which guest-session");
 
127
        if (cResult != NULL && *cResult == '/')
 
128
                cairo_dock_launch_command ("guest-session");
 
129
        else if (g_file_test (GUEST_SESSION_LAUNCHER, G_FILE_TEST_EXISTS))
 
130
                cairo_dock_launch_command (GUEST_SESSION_LAUNCHER);
 
131
        g_free (cResult);
 
132
        CD_APPLET_LEAVE ();
 
133
}
 
134
 
97
135
static void _cd_logout_program_shutdown (GtkMenuItem *menu_item, gpointer data)
98
136
{
99
137
        CD_APPLET_ENTER;
121
159
CD_APPLET_ON_BUILD_MENU_BEGIN
122
160
{
123
161
        GtkWidget *pSubMenu = CD_APPLET_CREATE_MY_SUB_MENU ();
124
 
        if (g_iDesktopEnv == CAIRO_DOCK_GNOME)
125
 
                CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Lock screen"), MY_APPLET_SHARE_DATA_DIR"/icon-lock.png", _cd_logout_lock_screen, CD_APPLET_MY_MENU);
 
162
        
 
163
        gchar *cLabel;
 
164
        if (myConfig.iActionOnClick != CD_LOGOUT)  // logout action not on click => put it in the menu
 
165
        {
 
166
                if (myConfig.iActionOnMiddleClick == CD_LOGOUT)  // logout action on middle-click
 
167
                        cLabel = g_strdup_printf ("%s (%s)", D_("Log out"), D_("middle-click"));
 
168
                else
 
169
                        cLabel = g_strdup (D_("Log out"));
 
170
                CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel, MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE, _cd_logout, CD_APPLET_MY_MENU);
 
171
                g_free (cLabel);
 
172
        }
 
173
        if (myConfig.iActionOnClick != CD_SHUTDOWN)  // shutdown action not on click => put it in the menu
 
174
        {
 
175
                if (myConfig.iActionOnMiddleClick == CD_SHUTDOWN)  // logout action on middle-click
 
176
                        cLabel = g_strdup_printf ("%s (%s)", D_("Shut down"), D_("middle-click"));
 
177
                else
 
178
                        cLabel = g_strdup (D_("Shut down"));
 
179
                CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel, MY_APPLET_SHARE_DATA_DIR"/"MY_APPLET_ICON_FILE, _cd_shutdown, CD_APPLET_MY_MENU);
 
180
                g_free (cLabel);
 
181
        }
 
182
        if (myConfig.iActionOnClick != CD_LOCK_SCREEN)  // lockscreen action not on click => put it in the menu
 
183
        {
 
184
                if (myConfig.iActionOnMiddleClick == CD_LOCK_SCREEN)  // lockscreen action on middle-click
 
185
                        cLabel = g_strdup_printf ("%s (%s)", D_("Lock screen"), D_("middle-click"));
 
186
                else
 
187
                        cLabel = g_strdup (D_("Lock screen"));
 
188
                CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel, MY_APPLET_SHARE_DATA_DIR"/icon-lock.png", _cd_lock_screen, CD_APPLET_MY_MENU);
 
189
                g_free (cLabel);
 
190
        }
 
191
        if (g_file_test (GUEST_SESSION_LAUNCHER, G_FILE_TEST_EXISTS)) // Guest Session
 
192
        {
 
193
                CD_APPLET_ADD_IN_MENU (D_("Guest session"), _cd_logout_guest_session, CD_APPLET_MY_MENU);
 
194
        }
 
195
        else
 
196
        {
 
197
                gchar *cResult = cairo_dock_launch_command_sync ("which guest-session");
 
198
                if (cResult != NULL && *cResult == '/')
 
199
                        CD_APPLET_ADD_IN_MENU (D_("Guest session"), _cd_logout_guest_session, CD_APPLET_MY_MENU);
 
200
                g_free (cResult);
 
201
        }
126
202
        
127
203
        CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Program an automatic shut-down"), MY_APPLET_SHARE_DATA_DIR"/icon-scheduling.png", _cd_logout_program_shutdown, CD_APPLET_MY_MENU);  // pas beaucoup d'entrees => on le met dans le menu global.
128
204
        
139
215
        if (t_cur >= myConfig.iShutdownTime)
140
216
        {
141
217
                cd_debug ("shutdown !\n");
142
 
                
143
218
                if (g_iDesktopEnv == CAIRO_DOCK_KDE)
144
219
                        cairo_dock_launch_command ("dbus-send --session --type=method_call --dest=org.kde.ksmserver /KSMServer org.kde.KSMServerInterface.logout int32:0 int32:2 int32:2");
145
220
                else
148
223
                
149
224
                myData.iSidTimer = 0;
150
225
                CD_APPLET_LEAVE (FALSE);  // inutile de faire quoique ce soit d'autre, puisque l'ordi s'eteint.
151
 
                //return FALSE;  // inutile de faire quoique ce soit d'autre, puisque l'ordi s'eteint.
152
226
        }
153
227
        else
154
228
        {
159
233
                        cairo_dock_show_temporary_dialog_with_icon (D_("Your computer will shut-down in 1 minute."), myIcon, myContainer, 8000, "same icon");
160
234
        }
161
235
        CD_APPLET_LEAVE (TRUE);
162
 
        //return TRUE;
163
236
        
164
237
}
165
238
void cd_logout_set_timer (void)
178
251
                CD_APPLET_SET_QUICK_INFO_ON_MY_ICON (NULL);
179
252
        }
180
253
}
 
254
 
 
255
static void _set_reboot_message (void)
 
256
{
 
257
        gchar *cMessage = NULL;
 
258
        gsize length = 0;
 
259
        g_file_get_contents (CD_REBOOT_NEEDED_FILE,
 
260
                &cMessage,
 
261
                &length,
 
262
                NULL);
 
263
        if (cMessage != NULL)
 
264
        {
 
265
                int len = strlen (cMessage);
 
266
                if (cMessage[len-1] == '\n')
 
267
                        cMessage[len-1] = '\0';
 
268
                CD_APPLET_SET_NAME_FOR_MY_ICON (cMessage);
 
269
        }
 
270
        else
 
271
                CD_APPLET_SET_NAME_FOR_MY_ICON (myConfig.cDefaultLabel);
 
272
        g_free (cMessage);
 
273
}
 
274
void cd_logout_check_reboot_required (CairoDockFMEventType iEventType, const gchar *cURI, gpointer data)
 
275
{
 
276
        switch (iEventType)
 
277
        {
 
278
                case CAIRO_DOCK_FILE_MODIFIED:  // new message
 
279
                        _set_reboot_message ();
 
280
                break;
 
281
                
 
282
                case CAIRO_DOCK_FILE_DELETED:  // reboot no more required (shouldn't happen)
 
283
                        myData.bRebootNeeded = FALSE;
 
284
                        CD_APPLET_SET_NAME_FOR_MY_ICON (myConfig.cDefaultLabel);
 
285
                        CD_APPLET_STOP_DEMANDING_ATTENTION;
 
286
                break;
 
287
                
 
288
                case CAIRO_DOCK_FILE_CREATED:  // reboot required
 
289
                        myData.bRebootNeeded = TRUE;
 
290
                        _set_reboot_message ();
 
291
                        CD_APPLET_DEMANDS_ATTENTION ("pulse", 20);
 
292
                        cairo_dock_show_temporary_dialog_with_icon (myIcon->cName, myIcon, myContainer, 5e3, "same icon");
 
293
                        if (myConfig.cEmblemPath != NULL && *myConfig.cEmblemPath != '\0' && g_file_test (myConfig.cEmblemPath, G_FILE_TEST_EXISTS))
 
294
                                CD_APPLET_SET_EMBLEM_ON_MY_ICON (myConfig.cEmblemPath, CAIRO_DOCK_EMBLEM_UPPER_RIGHT);
 
295
                        else
 
296
                                CD_APPLET_SET_EMBLEM_ON_MY_ICON (MY_APPLET_SHARE_DATA_DIR"/emblem-reboot.png", CAIRO_DOCK_EMBLEM_UPPER_RIGHT);
 
297
                break;
 
298
                default:
 
299
                break;
 
300
        }
 
301
}
 
302
 
 
303
void cd_logout_check_reboot_required_init (void)
 
304
{
 
305
        if (g_file_test (CD_REBOOT_NEEDED_FILE, G_FILE_TEST_EXISTS))
 
306
        {
 
307
                cd_logout_check_reboot_required (CAIRO_DOCK_FILE_CREATED, CD_REBOOT_NEEDED_FILE, NULL);
 
308
        }
 
309
}