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

« back to all changes in this revision

Viewing changes to .pc/bzr3031-3032_GMenu_remove_empty_submenus.patch/GMenu/src/applet-menu.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 "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"
 
26
 
 
27
static void cd_menu_append_poweroff_to_menu (GtkWidget *menu, GldiModuleInstance *myApplet);
 
28
 
 
29
 
 
30
static gboolean _make_menu_from_trees (CDSharedMemory *pSharedMemory)
 
31
{
 
32
        CD_APPLET_ENTER;
 
33
        
 
34
        myData.pTrees = pSharedMemory->pTrees;
 
35
        pSharedMemory->pTrees = NULL;
 
36
        
 
37
        // create the menu
 
38
        myData.pMenu = gldi_menu_new (myIcon);
 
39
        
 
40
        cd_menu_append_entry ();
 
41
        
 
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
 
46
         */
 
47
        GMenuTree *tree;
 
48
        GList *t;
 
49
        for (t = myData.pTrees; t != NULL; t = t->next)
 
50
        {
 
51
                tree = t->data;
 
52
                cd_append_tree_in_menu (tree, myData.pMenu);
 
53
        }
 
54
        
 
55
        // append recent events
 
56
        if (myConfig.bShowRecent)
 
57
                cd_menu_append_recent_to_menu (myData.pMenu, myApplet);
 
58
        
 
59
        // append logout item
 
60
        if (myConfig.iShowQuit != CD_GMENU_SHOW_QUIT_NONE)
 
61
                cd_menu_append_poweroff_to_menu (myData.pMenu, myApplet);
 
62
        
 
63
        cd_menu_check_for_new_apps ();
 
64
        
 
65
        if (myData.bShowMenuPending)
 
66
        {
 
67
                cd_menu_show_menu ();
 
68
                myData.bShowMenuPending = FALSE;
 
69
        }
 
70
        
 
71
        cairo_dock_discard_task (myData.pTask);
 
72
        myData.pTask = NULL;
 
73
        
 
74
        CD_APPLET_LEAVE (FALSE);
 
75
}
 
76
 
 
77
static void _load_trees_async (CDSharedMemory *pSharedMemory)
 
78
{
 
79
        GMenuTree *tree = cd_load_tree_from_file ("applications.menu");
 
80
        if (tree)
 
81
                pSharedMemory->pTrees = g_list_append (pSharedMemory->pTrees, tree);
 
82
 
 
83
        if (myConfig.bLoadSettingsMenu)
 
84
        {
 
85
                tree = cd_load_tree_from_file ("settings.menu");
 
86
                if (tree)
 
87
                        pSharedMemory->pTrees = g_list_append (pSharedMemory->pTrees, tree);
 
88
        }
 
89
}
 
90
 
 
91
static void _free_shared_memory (CDSharedMemory *pSharedMemory)
 
92
{
 
93
        g_list_foreach (pSharedMemory->pTrees, (GFunc)g_object_unref, NULL);
 
94
        g_list_free (pSharedMemory->pTrees);
 
95
        g_free (pSharedMemory);
 
96
}
 
97
 
 
98
void cd_menu_start (void)
 
99
{
 
100
        cd_menu_init_apps ();
 
101
        
 
102
        CDSharedMemory *pSharedMemory = g_new0 (CDSharedMemory, 1);
 
103
        
 
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,
 
108
                pSharedMemory);
 
109
        
 
110
        if (cairo_dock_is_loading ())
 
111
                cairo_dock_launch_task_delayed (myData.pTask, 0);  // 0 <=> g_idle
 
112
        else
 
113
                cairo_dock_launch_task (myData.pTask);
 
114
}
 
115
 
 
116
void cd_menu_stop (void)
 
117
{
 
118
        cairo_dock_discard_task (myData.pTask);
 
119
        myData.pTask = NULL;
 
120
        
 
121
        g_list_foreach (myData.pTrees, (GFunc)g_object_unref, NULL);
 
122
        g_list_free (myData.pTrees);
 
123
        myData.pTrees = NULL;
 
124
        
 
125
        if (myData.pMenu != NULL)
 
126
        {
 
127
                gtk_widget_destroy (myData.pMenu);
 
128
                myData.pMenu = NULL;
 
129
                myData.pRecentMenuItem = NULL;
 
130
        }
 
131
}
 
132
 
 
133
 
 
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)
 
136
{
 
137
        GtkWidget *pMenuItem = gldi_menu_item_new_full (cLabel, gtkStock, FALSE, GTK_ICON_SIZE_LARGE_TOOLBAR);
 
138
        
 
139
        gtk_menu_shell_append  (GTK_MENU_SHELL (pMenu), pMenuItem);
 
140
        if (pFunction)
 
141
                g_signal_connect (G_OBJECT (pMenuItem), "activate", G_CALLBACK (pFunction), pData);
 
142
        return pMenuItem;
 
143
}
 
144
 
 
145
static void cd_menu_append_poweroff_to_menu (GtkWidget *menu, GldiModuleInstance *myApplet)
 
146
{
 
147
        GtkWidget *menuitem = gtk_separator_menu_item_new ();
 
148
        gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
 
149
        gtk_widget_show (menuitem);
 
150
 
 
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);
 
153
 
 
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);
 
156
}
 
157
 
 
158
void cd_menu_show_menu (void)
 
159
{
 
160
        if (myData.pMenu != NULL)
 
161
        {
 
162
                CD_APPLET_POPUP_MENU_ON_MY_ICON (myData.pMenu);
 
163
                gtk_widget_grab_focus (myData.pEntry);
 
164
        }
 
165
        else
 
166
        {
 
167
                myData.bShowMenuPending = TRUE;
 
168
        }
 
169
}