3
# Copyright (c) 2011 Canonical
5
# Author: Michael Vogt <mvo@ubuntu.com>
7
# This program is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU General Public License as
9
# published by the Free Software Foundation; either version 2 of the
10
# 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.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
24
HAVE_UNITY_SUPPORT=False
26
from gi.repository import Dbusmenu, Unity
27
HAVE_UNITY_SUPPORT=True
28
except ImportError as e:
29
logging.warn("can not import unity GI %s" % e)
31
class IUnitySupport(object):
32
""" interface for unity support """
33
def __init__(self, parent): pass
34
def set_updates_count(self, num_updates): pass
35
def set_install_menuitem_visible(self, visible): pass
37
class UnitySupportImpl(IUnitySupport):
38
""" implementation of unity support (if unity is available) """
40
def __init__(self, parent):
41
# create launcher and quicklist
42
um_launcher_entry = Unity.LauncherEntry.get_for_desktop_id(
43
"update-manager.desktop")
44
self._unity = um_launcher_entry
45
quicklist = Dbusmenu.Menuitem.new()
47
update_dbusmenuitem = Dbusmenu.Menuitem.new()
48
update_dbusmenuitem.property_set(
49
Dbusmenu.MENUITEM_PROP_LABEL, _("Check for Updates"))
50
update_dbusmenuitem.property_set_bool(
51
Dbusmenu.MENUITEM_PROP_VISIBLE, True)
52
update_dbusmenuitem.connect (
53
"item-activated", parent.on_button_reload_clicked, None)
54
quicklist.child_append(update_dbusmenuitem)
56
self.install_dbusmenuitem = Dbusmenu.Menuitem.new()
57
self.install_dbusmenuitem.property_set (Dbusmenu.MENUITEM_PROP_LABEL,
58
_("Install All Available Updates"))
59
self.install_dbusmenuitem.property_set_bool (Dbusmenu.MENUITEM_PROP_VISIBLE, True)
60
self.install_dbusmenuitem.connect (
61
"item-activated", parent.install_all_updates, None)
62
quicklist.child_append (self.install_dbusmenuitem)
64
um_launcher_entry.set_property ("quicklist", quicklist)
66
def set_updates_count(self, num_updates):
67
self._unity.set_property("count", num_updates)
68
self._unity.set_property("count-visible", True)
69
# FIXME: setup emblem as well(?) and add urgency only for security
71
self._unity.set_property("urgent", True)
73
self._unity.set_property("urgent", False)
75
def set_install_menuitem_visible(self, visible):
76
self.install_dbusmenuitem.property_set_bool(Dbusmenu.MENUITEM_PROP_VISIBLE, visible)
79
# check what to export to the clients
80
if HAVE_UNITY_SUPPORT:
81
UnitySupport = UnitySupportImpl
83
# we just provide the empty interface
84
UnitySupport = IUnitySupport