2
* This file is a part of the Cairo-Dock project
4
* Copyright : (C) see the 'copyright' file.
5
* E-mail : see the 'copyright' file.
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.
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/>.
20
#include "applet-struct.h"
21
#include "applet-menu.h"
22
#include "applet-recent.h"
23
#include "applet-entry.h"
24
#include "applet-apps.h"
25
#include "applet-tree.h"
27
static void cd_menu_append_poweroff_to_menu (GtkWidget *menu, GldiModuleInstance *myApplet);
30
static gboolean _make_menu_from_trees (CDSharedMemory *pSharedMemory)
34
myData.pTrees = pSharedMemory->pTrees;
35
pSharedMemory->pTrees = NULL;
38
myData.pMenu = gldi_menu_new (myIcon);
40
cd_menu_append_entry ();
42
/* append the trees we got
43
* + it will populate menu and create all things
44
* (it will have a look at new images and maybe preload them)
45
* => do that in the separated thread
49
for (t = myData.pTrees; t != NULL; t = t->next)
52
cd_append_tree_in_menu (tree, myData.pMenu);
55
// append recent events
56
if (myConfig.bShowRecent)
57
cd_menu_append_recent_to_menu (myData.pMenu, myApplet);
60
if (myConfig.iShowQuit != CD_GMENU_SHOW_QUIT_NONE)
61
cd_menu_append_poweroff_to_menu (myData.pMenu, myApplet);
63
cd_menu_check_for_new_apps ();
65
if (myData.bShowMenuPending)
68
myData.bShowMenuPending = FALSE;
71
cairo_dock_discard_task (myData.pTask);
74
CD_APPLET_LEAVE (FALSE);
77
static void _load_trees_async (CDSharedMemory *pSharedMemory)
79
GMenuTree *tree = cd_load_tree_from_file ("applications.menu");
81
pSharedMemory->pTrees = g_list_append (pSharedMemory->pTrees, tree);
83
if (myConfig.bLoadSettingsMenu)
85
tree = cd_load_tree_from_file ("settings.menu");
87
pSharedMemory->pTrees = g_list_append (pSharedMemory->pTrees, tree);
91
static void _free_shared_memory (CDSharedMemory *pSharedMemory)
93
g_list_foreach (pSharedMemory->pTrees, (GFunc)g_object_unref, NULL);
94
g_list_free (pSharedMemory->pTrees);
95
g_free (pSharedMemory);
98
void cd_menu_start (void)
100
cd_menu_init_apps ();
102
CDSharedMemory *pSharedMemory = g_new0 (CDSharedMemory, 1);
104
myData.pTask = cairo_dock_new_task_full (0, // 1 shot task.
105
(CairoDockGetDataAsyncFunc) _load_trees_async,
106
(CairoDockUpdateSyncFunc) _make_menu_from_trees,
107
(GFreeFunc) _free_shared_memory,
110
if (cairo_dock_is_loading ())
111
cairo_dock_launch_task_delayed (myData.pTask, 0); // 0 <=> g_idle
113
cairo_dock_launch_task (myData.pTask);
116
void cd_menu_stop (void)
118
cairo_dock_discard_task (myData.pTask);
121
g_list_foreach (myData.pTrees, (GFunc)g_object_unref, NULL);
122
g_list_free (myData.pTrees);
123
myData.pTrees = NULL;
125
if (myData.pMenu != NULL)
127
gtk_widget_destroy (myData.pMenu);
129
myData.pRecentMenuItem = NULL;
134
// == cairo_dock_add_in_menu_with_stock_and_data with icon size 24
135
static GtkWidget *_append_one_item_to_menu (const gchar *cLabel, const gchar *gtkStock, GFunc pFunction, GtkWidget *pMenu, gpointer pData)
137
GtkWidget *pMenuItem = gldi_menu_item_new_full (cLabel, gtkStock, FALSE, GTK_ICON_SIZE_LARGE_TOOLBAR);
139
gtk_menu_shell_append (GTK_MENU_SHELL (pMenu), pMenuItem);
141
g_signal_connect (G_OBJECT (pMenuItem), "activate", G_CALLBACK (pFunction), pData);
145
static void cd_menu_append_poweroff_to_menu (GtkWidget *menu, GldiModuleInstance *myApplet)
147
GtkWidget *menuitem = gtk_separator_menu_item_new ();
148
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
149
gtk_widget_show (menuitem);
151
if (myConfig.iShowQuit == CD_GMENU_SHOW_QUIT_LOGOUT || myConfig.iShowQuit == CD_GMENU_SHOW_QUIT_BOTH)
152
_append_one_item_to_menu (D_("Logout"), "system-log-out", (GFunc) cairo_dock_fm_logout, menu, NULL);
154
if (myConfig.iShowQuit == CD_GMENU_SHOW_QUIT_SHUTDOWN || myConfig.iShowQuit == CD_GMENU_SHOW_QUIT_BOTH)
155
_append_one_item_to_menu (D_("Shutdown"), "system-shutdown", (GFunc) cairo_dock_fm_shutdown, menu, NULL);
158
void cd_menu_show_menu (void)
160
if (myData.pMenu != NULL)
162
CD_APPLET_POPUP_MENU_ON_MY_ICON (myData.pMenu);
163
gtk_widget_grab_focus (myData.pEntry);
167
myData.bShowMenuPending = TRUE;