~ubuntu-branches/ubuntu/wily/gnome-menus/wily-proposed

« back to all changes in this revision

Viewing changes to simple-editor/GMenuSimpleEditor/menutreemodel.py

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-06-08 16:16:43 UTC
  • mfrom: (1.1.73) (2.2.5 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130608161643-eemx2dcsvjyw3wz1
Tags: 3.8.0-1ubuntu1
* Merge with Debian, remaining changes:
  - debian/gnome-menus.postinst:
    + Disable blacklist to not break old applications
  - debian/gnome-menus.triggers: Drop "gmenucache".
  - debian/patches/series: Disable 01_default_prefix.patch
  - debian/patches/09_app_install_entry.patch:
    + Include Software Center in menus
  - debian/patches/70_ubuntu-directories.patch
    + Add Ubuntu-specific directories back to POTFILES.in
* Dropped changes:
  - debian/patches/22_directory-suffix-for-icons.patch
  - debian/gnome-menus.maintscript:
    + ensure conffile is removed on upgrade (not needed after 12.04 LTS)
* Refreshed patches
* debian/patches/50_add-gcc-apps.patch
  - Unhide Settings panels in GNOME Shell since we're sticking with Settings
    3.6 for now. Settings 3.8 includes a GNOME Shell 3.8 search provider.
* debian/patches/git_restore_calculator.patch:
  - Git patch to not hide Calculator from the menus

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# Copyright (C) 2005 Red Hat, Inc.
3
 
#
4
 
# This program is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; either version 2 of the License, or
7
 
# (at your option) any later version.
8
 
#
9
 
# This program is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
 
#
18
 
 
19
 
import os
20
 
import os.path
21
 
from gi.repository import GObject
22
 
from gi.repository import Gio
23
 
from gi.repository import Gtk
24
 
from gi.repository import GdkPixbuf
25
 
from gi.repository import GMenu
26
 
 
27
 
def lookup_system_menu_file (menu_file):
28
 
    conf_dirs = None
29
 
    if os.environ.has_key ("XDG_CONFIG_DIRS"):
30
 
        conf_dirs = os.environ["XDG_CONFIG_DIRS"]
31
 
    if not conf_dirs:
32
 
        conf_dirs = "/etc/xdg"
33
 
 
34
 
    for conf_dir in conf_dirs.split (":"):
35
 
        menu_file_path = os.path.join (conf_dir, "menus", menu_file)
36
 
        if os.path.isfile (menu_file_path):
37
 
            return menu_file_path
38
 
    
39
 
    return None
40
 
 
41
 
class MenuTreeModel (Gtk.TreeStore):
42
 
    (
43
 
        COLUMN_IS_ENTRY,
44
 
        COLUMN_ID,
45
 
        COLUMN_NAME,
46
 
        COLUMN_ICON,
47
 
        COLUMN_MENU_FILE,
48
 
        COLUMN_SYSTEM_VISIBLE,
49
 
        COLUMN_USER_VISIBLE
50
 
    ) = range (7)
51
 
 
52
 
    def __init__ (self, menu_files):
53
 
        Gtk.TreeStore.__init__ (self, bool, str, str, Gio.Icon, str, bool, bool)
54
 
 
55
 
        self.entries_list_iter = None
56
 
        
57
 
        if (len (menu_files) < 1):
58
 
            menu_files = ["applications.menu"]
59
 
 
60
 
        for menu_file in menu_files:
61
 
            if menu_file == "applications.menu" and os.environ.has_key ("XDG_MENU_PREFIX"):
62
 
                menu_file = os.environ["XDG_MENU_PREFIX"] + menu_file
63
 
 
64
 
            tree = GObject.new (GMenu.Tree, menu_basename = menu_file, flags = GMenu.TreeFlags.INCLUDE_EXCLUDED|GMenu.TreeFlags.SORT_DISPLAY_NAME)
65
 
            tree.load_sync ()
66
 
 
67
 
            self.__append_directory (tree.get_root_directory (), None, False, menu_file)
68
 
 
69
 
            system_file = lookup_system_menu_file (menu_file)
70
 
            if system_file:
71
 
                system_tree = GObject.new (GMenu.Tree, menu_path = system_file, flags = GMenu.TreeFlags.INCLUDE_EXCLUDED|GMenu.TreeFlags.SORT_DISPLAY_NAME)
72
 
                system_tree.load_sync ()
73
 
 
74
 
                self.__append_directory (system_tree.get_root_directory (), None, True, menu_file)
75
 
 
76
 
    def __append_directory (self, directory, parent_iter, system, menu_file):
77
 
        if not directory:
78
 
            return
79
 
        
80
 
        iter = self.iter_children (parent_iter)
81
 
        while iter is not None:
82
 
            if self.get_value(iter, self.COLUMN_ID) == directory.get_menu_id ():
83
 
                break
84
 
            iter = self.iter_next (iter)
85
 
 
86
 
        if iter is None:
87
 
            row = (False, directory.get_menu_id (), directory.get_name (), directory.get_icon (), menu_file, False, False)
88
 
            iter = self.append (parent_iter, row)
89
 
 
90
 
        if system:
91
 
            self.set_value (iter, self.COLUMN_SYSTEM_VISIBLE, True)
92
 
        else:
93
 
            self.set_value (iter, self.COLUMN_USER_VISIBLE, True)
94
 
 
95
 
        dir_iter = directory.iter ()
96
 
        next_type = dir_iter.next ()
97
 
        while next_type != GMenu.TreeItemType.INVALID:
98
 
            current_type = next_type
99
 
            next_type = dir_iter.next ()
100
 
 
101
 
            if current_type == GMenu.TreeItemType.DIRECTORY:
102
 
                child_item = dir_iter.get_directory ()
103
 
                self.__append_directory (child_item, iter, system, None)
104
 
                
105
 
            if current_type != GMenu.TreeItemType.ENTRY:
106
 
                continue
107
 
            
108
 
            child_item = dir_iter.get_entry ()
109
 
 
110
 
            child_iter = self.iter_children (iter)
111
 
            while child_iter is not None:
112
 
                if self.get_value(child_iter, self.COLUMN_IS_ENTRY) and \
113
 
                   self.get_value(child_iter, self.COLUMN_ID) == child_item.get_desktop_file_id ():
114
 
                        break
115
 
                child_iter = self.iter_next (child_iter)
116
 
 
117
 
            if child_iter is None:
118
 
                app_info = child_item.get_app_info ()
119
 
                row = (True, child_item.get_desktop_file_id (), app_info.get_display_name (), app_info.get_icon (), None, False, False)
120
 
                child_iter = self.append (iter, row)
121
 
 
122
 
            if system:
123
 
                self.set_value (child_iter, self.COLUMN_SYSTEM_VISIBLE, not child_item.get_is_excluded (),)
124
 
            else:
125
 
                self.set_value (child_iter, self.COLUMN_USER_VISIBLE, not child_item.get_is_excluded (),)