~jgonzalezdr/cairo-dock-plug-ins/suspend-workaround-applet_3.3

« back to all changes in this revision

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

  • Committer: Matthieu Baerts
  • Date: 2013-03-16 16:20:08 UTC
  • Revision ID: matttbe@gmail.com-20130316162008-chjlmzgnkn6i2bmi
GMenu: fixed a bzr typo: keep the history of all modifications

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
 
 
23
#include "applet-struct.h"
 
24
#include "applet-recent.h"
 
25
#include "applet-run-dialog.h"
 
26
#include "applet-notifications.h"
 
27
 
 
28
static const gchar *s_cEditMenuCmd = NULL; // we need to check with 'which' only one time if alacarte or kmenuedit is available
 
29
 
 
30
static void cd_menu_show_menu (void)
 
31
{
 
32
        if (myData.pMenu != NULL)
 
33
        {
 
34
                CD_APPLET_POPUP_MENU_ON_MY_ICON (myData.pMenu);
 
35
        }
 
36
}
 
37
 
 
38
static void cd_menu_show_hide_quick_launch (void)
 
39
{
 
40
        cd_run_dialog_show_hide (myApplet);
 
41
}
 
42
 
 
43
//\___________ Define here the action to be taken when the user left-clicks on your icon or on its subdock or your desklet. The icon and the container that were clicked are available through the macros CD_APPLET_CLICKED_ICON and CD_APPLET_CLICKED_CONTAINER. CD_APPLET_CLICKED_ICON may be NULL if the user clicked in the container but out of icons.
 
44
CD_APPLET_ON_CLICK_BEGIN
 
45
        cd_menu_show_menu ();
 
46
CD_APPLET_ON_CLICK_END
 
47
 
 
48
 
 
49
//\___________ Define here the entries you want to add to the menu when the user right-clicks on your icon or on its subdock or your desklet. The icon and the container that were clicked are available through the macros CD_APPLET_CLICKED_ICON and CD_APPLET_CLICKED_CONTAINER. CD_APPLET_CLICKED_ICON may be NULL if the user clicked in the container but out of icons. The menu where you can add your entries is available throught the macro CD_APPLET_MY_MENU; you can add sub-menu to it if you want.
 
50
static void _cd_menu_configure_menu (GtkMenuItem *menu_item, gpointer data)
 
51
{
 
52
        CD_APPLET_ENTER;
 
53
        GError *error = NULL;
 
54
        if (myConfig.cConfigureMenuCommand != NULL)
 
55
        {
 
56
                g_spawn_command_line_async (myConfig.cConfigureMenuCommand, &error);
 
57
        }
 
58
        else if (s_cEditMenuCmd != NULL)
 
59
        {
 
60
                g_spawn_command_line_async (s_cEditMenuCmd, &error);
 
61
        }
 
62
        
 
63
        if (error != NULL)
 
64
        {
 
65
                cd_warning ("Attention : when trying to execute '%s' : %s",
 
66
                        myConfig.cConfigureMenuCommand ? myConfig.cConfigureMenuCommand : s_cEditMenuCmd,
 
67
                        error->message);
 
68
                g_error_free (error);
 
69
        }
 
70
        CD_APPLET_LEAVE();
 
71
}
 
72
 
 
73
static gboolean _cd_check_edit_menu_cmd (const gchar *cWhich)
 
74
{
 
75
        gchar *cResult = cairo_dock_launch_command_sync (cWhich);  // Gnome (2 + 3(?)) + XFCE(?)
 
76
        gboolean bResult = (cResult != NULL && *cResult == '/');
 
77
        g_free (cResult);
 
78
        return bResult;
 
79
}
 
80
 
 
81
CD_APPLET_ON_BUILD_MENU_BEGIN
 
82
        gchar *cLabel = g_strdup_printf ("%s (%s)", D_("Quick launch"), D_("middle-click"));
 
83
        CD_APPLET_ADD_IN_MENU_WITH_STOCK (cLabel, GTK_STOCK_EXECUTE, cd_menu_show_hide_quick_launch, CD_APPLET_MY_MENU);
 
84
        g_free (cLabel);
 
85
        CD_APPLET_ADD_SEPARATOR_IN_MENU (CD_APPLET_MY_MENU);
 
86
 
 
87
        static gboolean bEditMenuCmdChecked = FALSE;
 
88
        if (!myConfig.cConfigureMenuCommand && !bEditMenuCmdChecked)
 
89
        {
 
90
                bEditMenuCmdChecked = TRUE;
 
91
                if (_cd_check_edit_menu_cmd ("which alacarte"))
 
92
                        s_cEditMenuCmd = "alacarte";
 
93
                else if (_cd_check_edit_menu_cmd ("which kmenuedit"))
 
94
                        s_cEditMenuCmd = "kmenuedit";
 
95
                else if (_cd_check_edit_menu_cmd ("which menulibre"))
 
96
                        s_cEditMenuCmd = "menulibre";
 
97
        }
 
98
        if (myConfig.cConfigureMenuCommand || s_cEditMenuCmd)
 
99
                CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Configure menu"), GTK_STOCK_PREFERENCES, _cd_menu_configure_menu, CD_APPLET_MY_MENU);
 
100
        
 
101
        CD_APPLET_ADD_SEPARATOR_IN_MENU (CD_APPLET_MY_MENU);
 
102
        CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Clear recent"), GTK_STOCK_CLEAR, cd_menu_clear_recent, CD_APPLET_MY_MENU);
 
103
CD_APPLET_ON_BUILD_MENU_END
 
104
 
 
105
 
 
106
CD_APPLET_ON_MIDDLE_CLICK_BEGIN
 
107
        cd_menu_show_hide_quick_launch ();
 
108
CD_APPLET_ON_MIDDLE_CLICK_END
 
109
 
 
110
 
 
111
void cd_menu_on_shortkey_menu (const char *keystring, gpointer data)
 
112
{
 
113
        cd_menu_show_menu ();
 
114
}
 
115
 
 
116
void cd_menu_on_shortkey_quick_launch (const char *keystring, gpointer data)
 
117
{
 
118
        cd_menu_show_hide_quick_launch ();
 
119
}