~ubuntu-branches/ubuntu/utopic/cairo-dock-plug-ins/utopic-201408192140

« back to all changes in this revision

Viewing changes to logout/src/applet-reboot-required.c

  • Committer: Matthieu Baerts
  • Date: 2014-04-06 23:04:40 UTC
  • mfrom: (1.1.37)
  • Revision ID: matttbe@gmail.com-20140406230440-ho7ktfc4a7vndigu
Tags: 3.3.99.beta1.2.really.3.3.2-0ubuntu1
* Revert back to the 3.3.2 version: (LP: #1302246)
  Unfortunately, due to the lack of time, we have to revert back to the
  latest stable version. Sorry for that but feel free to help us ;-)
* debian/patches: cherry-pick patches from upstream BZR repo, all 'bug-fix'
  and changes that were already in the 3.3.99.beta1 version except all
  changes linked to the new style, the menu and the configuration.
  - bzr3008_GMenu_new_apps_in_the_list.patch: GMenu: New Apps: if there are
    new apps when the 'new apps' dialogue is opened, add these new apps in
    the list
  - bzr3010_GMenu_option_hide_new_apps_dialogue.patch: GMenu: Config: Added
    the possibility to not display notification to quickly launch new apps
  - bzr3021_Terminal_launch_default_terminal_middle_click.patch: Terminal:
    middle click: launch the default terminal
  - bzr3031-3032_GMenu_remove_empty_submenus.patch: GMenu: do not add empty
    submenus when creating them and remove empty submenus
  - bzr3035_DND2Share_History_was_empty.patch: DnD2Share: history menu was
    empty
  - bzr3036-3040_Shortcuts_removed_disk_usage_on_bookmarks_and_support_
    x-nautilus_URI.patch: Shortcuts: correctly removed an old bookmark ;
    added support for x-nautilus-(...) URI ; avoid duplicated code +
    bookmarks doesn't have a disk usage ; translated a few sentences from
    French to English
  - bzr3043_Fixed_typo_with_some_sentences.patch: Fixed typo with some
    sentences which were not correctly translated
  - bzr3045-3046_GVFS_support_x-nautilus-desktop_and_fixed_typos_and_memory_
    leaks.patch: gvfs: fixed typo and tiny memory leak ; GTK3: 'x-nautilus-
    desktop' is just an URI where the root is the path to the desktop
  - bzr3047-3048_Status-Notifier_Added_support_of_middle_click_and_scroll:
    Status-Notifier: IAS (ubuntu): added the support of the middle click ;
    Scroll signals were not catched
  - bzr3051_Logout_Added_support_of_Cinnamon.patch: logout: added support of
    Cinnamon
  - bzr3057_GMenu_new_apps_show_dialog_after_installation.patch: GMenu: new
    apps: show the dialog only after the end of the installation
  - bzr3065_Impulse_do_not_redraw_icon_when_not_needed.patch: Impulse: stop
    animations: do not redraw the icon if it's not needed (e.g. when
    disabling the applet)
  - bzr3067_AlsaMixer_support_cinnamon_settings.patch: AlsaMixer: added the
    support of cinnamon-settings
  - bzr3068_Clock_fixed_a_crash_when_configuring_when_not_enabled.patch:
    Clock: fixed a crash when configuring the applet if it's not activated
  - bzr3069_Indicator_Generic_no_need_to_hide_the_icon_before_removing_it:
    Indicator Generic: stop: no need to hide the icon before removing it
* debian/control: bumped Core versions

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 <string.h>
21
 
 
22
 
#include "applet-struct.h"
23
 
#include "applet-logout.h"
24
 
#include "applet-reboot-required.h"
25
 
 
26
 
static gboolean s_bRebootRequired = FALSE;
27
 
static gboolean s_bMonitored = FALSE;
28
 
 
29
 
static const gchar * _get_default_message (void)
30
 
{
31
 
        if (myConfig.cDefaultLabel) // has another default name
32
 
                return myConfig.cDefaultLabel;
33
 
        else
34
 
                return myApplet->pModule->pVisitCard->cTitle;
35
 
}
36
 
 
37
 
static gchar * _get_reboot_message (void)
38
 
{
39
 
        gchar *cMessage = NULL;
40
 
        gsize length = 0;
41
 
        g_file_get_contents (CD_REBOOT_NEEDED_FILE,
42
 
                &cMessage,
43
 
                &length,
44
 
                NULL);
45
 
        if (cMessage != NULL)
46
 
        {
47
 
                int len = strlen (cMessage);
48
 
                if (cMessage[len-1] == '\n')
49
 
                        cMessage[len-1] = '\0';
50
 
        }
51
 
 
52
 
        return (cMessage);
53
 
}
54
 
 
55
 
static void _notify_action_required (void)
56
 
{
57
 
        CD_APPLET_DEMANDS_ATTENTION ("pulse", 20);
58
 
        gldi_dialogs_remove_on_icon (myIcon);
59
 
 
60
 
        // it's not a good idea to reboot the computer before the end of the update ;)
61
 
        gchar *cName = g_strdup_printf ("%s\n%s", myIcon->cName,
62
 
                D_("Please do that at the end of the update."));
63
 
 
64
 
        gldi_dialog_show_temporary_with_icon (cName, myIcon, myContainer, 15e3, "same icon");
65
 
 
66
 
        g_free (cName);
67
 
 
68
 
        gint iIconSize = MAX (myIcon->image.iWidth, myIcon->image.iHeight);
69
 
        gchar *cImagePath = cd_logout_check_icon (myConfig.cEmblemPath,
70
 
                (myConfig.iRebootNeededImage == CD_DISPLAY_EMBLEM ?
71
 
                                iIconSize / 2 :
72
 
                                iIconSize));
73
 
        if (! cImagePath)
74
 
        {
75
 
                cImagePath = cd_logout_check_icon (GTK_STOCK_REFRESH,
76
 
                        (myConfig.iRebootNeededImage == CD_DISPLAY_EMBLEM ?
77
 
                                iIconSize / 2 :
78
 
                                iIconSize));
79
 
                if (! cImagePath)
80
 
                        cImagePath = g_strdup (MY_APPLET_SHARE_DATA_DIR"/system-restart.svg");
81
 
        }
82
 
 
83
 
        if (myConfig.iRebootNeededImage == CD_DISPLAY_EMBLEM)
84
 
                CD_APPLET_PRINT_OVERLAY_ON_MY_ICON (cImagePath, CAIRO_OVERLAY_UPPER_RIGHT);
85
 
        else
86
 
                CD_APPLET_SET_IMAGE_ON_MY_ICON (cImagePath);
87
 
        g_free (cImagePath);
88
 
}
89
 
 
90
 
static void _stop_notify_action_required (void)
91
 
{
92
 
         // should not happen... mainly for the tests.
93
 
        gldi_dialogs_remove_on_icon (myIcon);
94
 
        if (myConfig.iRebootNeededImage == CD_DISPLAY_EMBLEM)
95
 
                CD_APPLET_PRINT_OVERLAY_ON_MY_ICON (NULL, CAIRO_OVERLAY_UPPER_RIGHT);
96
 
        else
97
 
                CD_APPLET_SET_IMAGE_ON_MY_ICON (myConfig.cDefaultIcon);
98
 
        CD_APPLET_STOP_DEMANDING_ATTENTION;
99
 
}
100
 
 
101
 
static gboolean _notify_reboot_requiered (gpointer pData)
102
 
{
103
 
        if (! myApplet || ! s_bRebootRequired)
104
 
        {
105
 
                s_bMonitored = FALSE;
106
 
                return FALSE;
107
 
        }
108
 
 
109
 
        CairoDockFMEventType iEventType = GPOINTER_TO_INT (pData);
110
 
 
111
 
        gchar *cMessage = _get_reboot_message ();
112
 
        if (cMessage && *cMessage != '\0')
113
 
                CD_APPLET_SET_NAME_FOR_MY_ICON (cMessage);
114
 
        else
115
 
                CD_APPLET_SET_NAME_FOR_MY_ICON (_get_default_message ());
116
 
        if (iEventType == CAIRO_DOCK_FILE_CREATED)
117
 
                _notify_action_required ();
118
 
 
119
 
        g_free (cMessage);
120
 
        s_bMonitored = FALSE;
121
 
 
122
 
        return FALSE;
123
 
}
124
 
 
125
 
void cd_logout_check_reboot_required (CairoDockFMEventType iEventType, const gchar *cURI)
126
 
{
127
 
        switch (iEventType)
128
 
        {
129
 
                case CAIRO_DOCK_FILE_MODIFIED: // new message
130
 
                case CAIRO_DOCK_FILE_CREATED:  // reboot required
131
 
                        s_bRebootRequired = TRUE;
132
 
                        if (! s_bMonitored)
133
 
                        {
134
 
                                s_bMonitored = TRUE;
135
 
                                gpointer pEventType = GINT_TO_POINTER (iEventType);
136
 
                                #ifdef END_INSTALLATION_PID
137
 
                                cairo_dock_fm_monitor_pid (END_INSTALLATION_PID, FALSE,
138
 
                                        _notify_reboot_requiered, TRUE, pEventType);
139
 
                                #else
140
 
                                _notify_reboot_requiered (pEventType);
141
 
                                #endif
142
 
                        }
143
 
                break;
144
 
                
145
 
                case CAIRO_DOCK_FILE_DELETED:  // reboot/logout no more required (shouldn't happen)
146
 
                        s_bRebootRequired = FALSE;
147
 
                        _stop_notify_action_required (); // default icon
148
 
                        CD_APPLET_SET_NAME_FOR_MY_ICON (_get_default_message ());
149
 
                break;
150
 
                default:
151
 
                break;
152
 
        }
153
 
}
154
 
 
155
 
void cd_logout_check_reboot_required_init (void)
156
 
{
157
 
        if (g_file_test (CD_REBOOT_NEEDED_FILE, G_FILE_TEST_EXISTS))
158
 
        {
159
 
                cd_logout_check_reboot_required (CAIRO_DOCK_FILE_CREATED, CD_REBOOT_NEEDED_FILE);
160
 
        }
161
 
}
162
 
 
163
 
gboolean cd_logout_can_safety_shutdown (void)
164
 
{
165
 
        gboolean bResult = ! s_bMonitored || ! s_bRebootRequired;
166
 
        #ifdef END_INSTALLATION_PID
167
 
        bResult &= cairo_dock_fm_get_pid (END_INSTALLATION_PID) == -1;
168
 
        #endif
169
 
        return bResult;
170
 
}
 
 
b'\\ No newline at end of file'