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

« back to all changes in this revision

Viewing changes to logout/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
 
 
21
#include <stdlib.h>
 
22
#include <string.h>
 
23
#include <signal.h>
 
24
#include <glib/gi18n.h>
 
25
 
 
26
#include "applet-struct.h"
 
27
#include "applet-notifications.h"
 
28
 
 
29
 
 
30
static _logout (void)
 
31
{
 
32
        if (myConfig.cUserAction != NULL)
 
33
        {
 
34
                cairo_dock_launch_command (myConfig.cUserAction);
 
35
        }
 
36
        else
 
37
        {
 
38
                gboolean bLoggedOut = cairo_dock_fm_logout ();
 
39
                if (! bLoggedOut)
 
40
                {
 
41
                        if (g_iDesktopEnv == CAIRO_DOCK_KDE)
 
42
                        {
 
43
                                int answer = cairo_dock_ask_question_and_wait ("Log out ?", myIcon, myContainer);
 
44
                                if (answer == GTK_RESPONSE_YES)
 
45
                                {
 
46
                                        system ("dcop ksmserver default logout 0 0 0");  // kdmctl shutdown reboot forcenow  // kdeinit_shutdown
 
47
                                        system ("qdbus org.kde.ksmserver /KSMServer logout 0 2 0");
 
48
                                }
 
49
                        }
 
50
                        else
 
51
                        {
 
52
                                cd_warning ("couldn't guess what to do to log out.");
 
53
                        }
 
54
                }
 
55
        }
 
56
}
 
57
static _shutdown (void)
 
58
{
 
59
        if (myConfig.cUserAction2 != NULL)
 
60
        {
 
61
                cairo_dock_launch_command (myConfig.cUserAction2);
 
62
        }
 
63
        else
 
64
        {
 
65
                gboolean bShutdowned = cairo_dock_fm_shutdown ();
 
66
                if (! bShutdowned)
 
67
                {
 
68
                        if (g_iDesktopEnv == CAIRO_DOCK_KDE)
 
69
                        {
 
70
                                int answer = cairo_dock_ask_question_and_wait ("Shutdown ?", myIcon, myContainer);
 
71
                                if (answer == GTK_RESPONSE_YES)
 
72
                                {
 
73
                                        system ("dcop ksmserver default logout 0 0 0");  // kdmctl shutdown reboot forcenow  // kdeinit_shutdown
 
74
                                }
 
75
                        }
 
76
                        else
 
77
                        {
 
78
                                cd_warning ("couldn't guess what to do to shutdown.");
 
79
                        }
 
80
                }
 
81
        }
 
82
}
 
83
CD_APPLET_ON_CLICK_BEGIN
 
84
{
 
85
        if (myIcon->Xid != 0)
 
86
        {
 
87
                if (cairo_dock_get_current_active_window () == myIcon->Xid && myTaskBar.bMinimizeOnClick)
 
88
                        cairo_dock_minimize_xwindow (myIcon->Xid);
 
89
                else
 
90
                        cairo_dock_show_xwindow (myIcon->Xid);
 
91
        }
 
92
        else
 
93
        {
 
94
                if (myConfig.bInvertButtons)
 
95
                        _shutdown ();
 
96
                else
 
97
                        _logout ();
 
98
        }
 
99
}
 
100
CD_APPLET_ON_CLICK_END
 
101
 
 
102
 
 
103
CD_APPLET_ON_MIDDLE_CLICK_BEGIN
 
104
{
 
105
        if (myConfig.bInvertButtons)
 
106
                _logout ();
 
107
        else
 
108
                _shutdown ();
 
109
}
 
110
CD_APPLET_ON_MIDDLE_CLICK_END
 
111
 
 
112
 
 
113
CD_APPLET_ON_BUILD_MENU_BEGIN
 
114
{
 
115
       GtkWidget *pSubMenu = CD_APPLET_CREATE_MY_SUB_MENU ();
 
116
        CD_APPLET_ADD_ABOUT_IN_MENU (pSubMenu);
 
117
}
 
118
CD_APPLET_ON_BUILD_MENU_END