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

« back to all changes in this revision

Viewing changes to GMenu/src/applet-init.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
 
 
22
This file is a part of the cairo-dock program, 
 
23
released under the terms of the GNU General Public License.
 
24
 
 
25
Written by Fabrice Rey (for any bug report, please mail me to fabounet@users.berlios.de)
 
26
 
 
27
******************************************************************************/
 
28
 
 
29
#include "stdlib.h"
 
30
 
 
31
#include "applet-config.h"
 
32
#include "applet-notifications.h"
 
33
#include "applet-struct.h"
 
34
#include "applet-menu.h"
 
35
#include "applet-recent.h"
 
36
#include "applet-init.h"
 
37
 
 
38
 
 
39
CD_APPLET_DEFINITION ("GMenu",
 
40
        2, 0, 0,
 
41
        CAIRO_DOCK_CATEGORY_DESKTOP,
 
42
        N_("Displays the common Applications menu and the Recently used files.\n"
 
43
        "It is compatible with any XDG compliant menu (Gnome, XFCE, KDE, ...)\n"
 
44
        "Middle-click to open a dialog to quickly launch any command (you can set up a shortkey for it, like ALT+F2)\n"
 
45
        "You can also set up a shortkey to pop up the menu (like ALT+F1)"),
 
46
        "Fabounet (Fabrice Rey)")
 
47
 
 
48
 
 
49
//\___________ Here is where you initiate your applet. myConfig is already set at this point, and also myIcon, myContainer, myDock, myDesklet (and myDrawContext if you're in dock mode). The macro CD_APPLET_MY_CONF_FILE and CD_APPLET_MY_KEY_FILE can give you access to the applet's conf-file and its corresponding key-file (also available during reload). If you're in desklet mode, myDrawContext is still NULL, and myIcon's buffers has not been filled, because you may not need them then (idem when reloading).
 
50
CD_APPLET_INIT_BEGIN
 
51
        if (myDesklet)
 
52
        {
 
53
                CD_APPLET_SET_DESKLET_RENDERER ("Simple");  // set a desklet renderer.
 
54
        }
 
55
        
 
56
        CD_APPLET_SET_DEFAULT_IMAGE_ON_MY_ICON_IF_NONE;  // set the default icon if none is specified in conf.
 
57
        
 
58
        if (myConfig.bShowRecent)
 
59
        {
 
60
                cd_menu_init_recent (myApplet);
 
61
        }
 
62
        myData.pMenu = create_main_menu (myApplet);
 
63
        
 
64
        CD_APPLET_REGISTER_FOR_CLICK_EVENT;
 
65
        CD_APPLET_REGISTER_FOR_MIDDLE_CLICK_EVENT;
 
66
        CD_APPLET_REGISTER_FOR_BUILD_MENU_EVENT;
 
67
        
 
68
        cd_keybinder_bind (myConfig.cMenuShortkey, (CDBindkeyHandler) cd_menu_on_shortkey_menu, myApplet);
 
69
        cd_keybinder_bind (myConfig.cQuickLaunchShortkey, (CDBindkeyHandler) cd_menu_on_shortkey_quick_launch, myApplet);
 
70
CD_APPLET_INIT_END
 
71
 
 
72
 
 
73
//\___________ Here is where you stop your applet. myConfig and myData are still valid, but will be reseted to 0 at the end of the function. In the end, your applet will go back to its original state, as if it had never been activated.
 
74
CD_APPLET_STOP_BEGIN
 
75
        CD_APPLET_UNREGISTER_FOR_CLICK_EVENT;
 
76
        CD_APPLET_UNREGISTER_FOR_MIDDLE_CLICK_EVENT;
 
77
        CD_APPLET_UNREGISTER_FOR_BUILD_MENU_EVENT;
 
78
        
 
79
        if (myData.iSidFakeMenuIdle != 0)
 
80
                g_source_remove (myData.iSidFakeMenuIdle);
 
81
        if (myData.iSidCreateMenuIdle != 0)
 
82
                g_source_remove (myData.iSidCreateMenuIdle);
 
83
        if (myData.iSidTreeChangeIdle != 0)
 
84
                g_source_remove (myData.iSidTreeChangeIdle);
 
85
CD_APPLET_STOP_END
 
86
 
 
87
 
 
88
//\___________ The reload occurs in 2 occasions : when the user changes the applet's config, and when the user reload the cairo-dock's config or modify the desklet's size. The macro CD_APPLET_MY_CONFIG_CHANGED can tell you this. myConfig has already been reloaded at this point if you're in the first case, myData is untouched. You also have the macro CD_APPLET_MY_CONTAINER_TYPE_CHANGED that can tell you if you switched from dock/desklet to desklet/dock mode.
 
89
CD_APPLET_RELOAD_BEGIN
 
90
        if (myDesklet)
 
91
        {
 
92
                CD_APPLET_SET_DESKLET_RENDERER ("Simple");  // set a desklet renderer.
 
93
        }
 
94
        
 
95
        if (CD_APPLET_MY_CONFIG_CHANGED)
 
96
        {
 
97
                CD_APPLET_SET_DEFAULT_IMAGE_ON_MY_ICON_IF_NONE;  // set the default icon if none is specified in conf.
 
98
                
 
99
                cd_keybinder_bind (myConfig.cMenuShortkey, (CDBindkeyHandler) cd_menu_on_shortkey_menu, myApplet);  // shortkey were unbinded during reset_config.
 
100
                cd_keybinder_bind (myConfig.cQuickLaunchShortkey, (CDBindkeyHandler) cd_menu_on_shortkey_quick_launch, myApplet);
 
101
                
 
102
                // on reset ce qu'il faut.
 
103
                cd_menu_reset_recent (myApplet);  // le fitre peut avoir change.
 
104
                if (myData.pMenu != NULL &&
 
105
                        (myConfig.bHasIcons != myData.bIconsLoaded) || (myConfig.bShowRecent && myData.pRecentMenuItem == NULL))
 
106
                {
 
107
                        gtk_widget_destroy (myData.pMenu);  // detruit le sous-menu des recent items ?
 
108
                        myData.pMenu = NULL;
 
109
                        myData.pRecentMenuItem = NULL;
 
110
                }
 
111
                
 
112
                // on reconstruit ce qu'il faut.
 
113
                if (myData.pMenu == NULL)
 
114
                {
 
115
                        myData.pMenu = create_main_menu (myApplet);
 
116
                }
 
117
                else  // menu deja existant, on rajoute/enleve les recents a la main.
 
118
                {
 
119
                        if (! myConfig.bShowRecent)  // on ne veut plus des recent items.
 
120
                        {
 
121
                                if (myData.pRecentMenuItem != NULL)
 
122
                                {
 
123
                                        gtk_widget_destroy (myData.pRecentMenuItem);
 
124
                                        myData.pRecentMenuItem = NULL;
 
125
                                }
 
126
                        }
 
127
                        else  // on veut les recent items.
 
128
                        {
 
129
                                cd_menu_init_recent (myApplet);
 
130
                                if (myData.pRecentMenuItem != NULL)  // ils existent deja.
 
131
                                {
 
132
                                        if (myData.pRecentFilter != NULL)
 
133
                                                gtk_recent_chooser_add_filter (GTK_RECENT_CHOOSER (myData.pRecentMenuItem), myData.pRecentFilter);
 
134
                                }
 
135
                                else  // il faut les construire.
 
136
                                {
 
137
                                        // rien a faire, dans ce cas on a detruit le menu, car il faut placer les recent items a l'interieur.
 
138
                                }
 
139
                        }
 
140
                }
 
141
        }
 
142
CD_APPLET_RELOAD_END