1
# Copyright (C) 2008 Valmantas Paliksa <walmis at balticum-tv dot lt>
2
# Copyright (C) 2008 Tadas Dailyda <tadas at dailyda dot com>
4
# Licensed under the GNU General Public License Version 3
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# 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/>.
1
from blueman.main.PluginManager import StopException
19
2
from blueman.Functions import *
20
3
from blueman.plugins.AppletPlugin import AppletPlugin
24
8
class StatusIcon(AppletPlugin, gtk.StatusIcon):
25
__unloadable__ = False
28
def on_entry_changed(self, entry, ic, image):
30
if ic.has_icon(self.get_option("icon")):
31
icon = gtk.STOCK_APPLY
33
icon = gtk.STOCK_CANCEL
35
image.set_from_stock(icon, gtk.ICON_SIZE_LARGE_TOOLBAR)
38
gobject.source_remove(self.timeout)
40
self.timeout = gobject.timeout_add(1000, lambda: self.IconShouldChange())
42
def widget_decorator(self, widget, name, options):
43
entry = widget.get_children()[1]
46
completion = gtk.EntryCompletion()
47
entry.set_completion(completion)
49
liststore = gtk.ListStore(gobject.TYPE_STRING)
51
completion.set_model(liststore)
53
completion.set_text_column(0)
55
ic = gtk.icon_theme_get_default()
56
icons = ic.list_icons("Applications")
60
if ic.has_icon(self.get_option("icon")):
61
icon = gtk.STOCK_APPLY
63
icon = gtk.STOCK_CANCEL
65
image.set_from_stock(icon, gtk.ICON_SIZE_LARGE_TOOLBAR)
67
widget.pack_start(image, 0, 0)
68
entry.connect("changed", self.on_entry_changed, ic, image)
70
__options__ = {"icon": {"type": str,
71
"default": "blueman-tray",
72
"name": _("Icon Name"),
73
"desc": _("Custom icon to use for the notification area"),
74
"decorator": widget_decorator
82
def on_load(self, applet):
83
gtk.StatusIcon.__init__(self)
88
#self.connect("size-changed", self.on_status_icon_resized)
90
self.SetTextLine(0, _("Bluetooth Enabled"))
92
AppletPlugin.add_method(self.on_query_status_icon_visibility)
93
AppletPlugin.add_method(self.on_status_icon_query_icon)
95
ic = gtk.icon_theme_get_default()
96
ic.connect("changed", self.on_icon_theme_changed)
98
self.on_status_icon_resized()
100
def on_icon_theme_changed(self, icon_theme):
101
self.IconShouldChange()
103
def on_power_state_changed(self, manager, state):
105
self.SetTextLine(0, _("Bluetooth Enabled"))
107
self.SetTextLine(0, _("Bluetooth Disabled"))
109
self.QueryVisibility()
111
def QueryVisibility(self):
113
rets = self.Applet.Plugins.Run("on_query_status_icon_visibility")
114
if not StatusIcon.FORCE_HIDE in rets:
115
if StatusIcon.FORCE_SHOW in rets:
116
self.set_visible(True)
118
if not self.Applet.Manager:
119
self.set_visible(False)
123
if self.Applet.Manager.ListAdapters() == []:
124
self.set_visible(False)
126
self.set_visible(True)
128
self.set_visible(False)
130
self.set_visible(False)
132
def set_visible(self, visible):
133
self.props.visible = visible
135
def SetTextLine(self, id, text):
137
self.lines[id] = text
144
self.update_tooltip()
147
def update_tooltip(self):
149
keys = self.lines.keys()
152
s += self.lines[k] + "\n"
154
self.props.tooltip_markup = s[:-1]
156
def IconShouldChange(self):
157
self.on_status_icon_resized()
159
def on_adapter_added(self, path):
160
self.QueryVisibility()
162
def on_adapter_removed(self, path):
163
self.QueryVisibility()
165
def on_manager_state_changed(self, state):
166
self.QueryVisibility()
168
def on_status_icon_resized(self):
169
self.icon = "blueman-tray"
171
#p = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, 22, 22)
175
#self.pixbuf.copy_area(0, 0, self.pixbuf.props.width, self.pixbuf.props.height, p, 5, 0)
178
ic = gtk.icon_theme_get_default()
180
def callback(inst, ret):
187
self.Applet.Plugins.RunEx("on_status_icon_query_icon", callback)
188
self.props.icon_name = self.icon
192
def on_query_status_icon_visibility(self):
193
return StatusIcon.SHOW
195
def on_status_icon_query_icon(self):
12
def on_entry_changed(self, entry, ic, image):
14
if ic.has_icon(self.get_option("icon")):
15
icon = gtk.STOCK_APPLY
17
icon = gtk.STOCK_CANCEL
19
image.set_from_stock(icon, gtk.ICON_SIZE_LARGE_TOOLBAR)
22
gobject.source_remove(self.timeout)
24
self.timeout = gobject.timeout_add(1000, lambda: self.IconShouldChange())
26
def widget_decorator(self, widget, name, options):
27
entry = widget.get_children()[1]
30
completion = gtk.EntryCompletion()
31
entry.set_completion(completion)
33
liststore = gtk.ListStore(gobject.TYPE_STRING)
35
completion.set_model(liststore)
37
completion.set_text_column(0)
39
ic = gtk.icon_theme_get_default()
40
icons = ic.list_icons("Applications")
44
if ic.has_icon(self.get_option("icon")):
45
icon = gtk.STOCK_APPLY
47
icon = gtk.STOCK_CANCEL
49
image.set_from_stock(icon, gtk.ICON_SIZE_LARGE_TOOLBAR)
51
widget.pack_start(image, 0, 0)
52
entry.connect("changed", self.on_entry_changed, ic, image)
54
__options__ = {"icon": {"type": str,
55
"default": "blueman-tray",
56
"name": _("Icon Name"),
57
"desc": _("Custom icon to use for the notification area"),
58
"decorator": widget_decorator
66
def on_load(self, applet):
67
gtk.StatusIcon.__init__(self)
72
#self.connect("size-changed", self.on_status_icon_resized)
74
self.SetTextLine(0, _("Bluetooth Enabled"))
76
AppletPlugin.add_method(self.on_query_status_icon_visibility)
77
AppletPlugin.add_method(self.on_status_icon_query_icon)
79
ic = gtk.icon_theme_get_default()
80
ic.connect("changed", self.on_icon_theme_changed)
82
self.on_status_icon_resized()
84
def on_icon_theme_changed(self, icon_theme):
85
self.IconShouldChange()
87
def on_power_state_changed(self, manager, state):
89
self.SetTextLine(0, _("Bluetooth Enabled"))
91
self.SetTextLine(0, _("Bluetooth Disabled"))
93
self.QueryVisibility()
95
def QueryVisibility(self):
97
rets = self.Applet.Plugins.Run("on_query_status_icon_visibility")
98
if not StatusIcon.FORCE_HIDE in rets:
99
if StatusIcon.FORCE_SHOW in rets:
100
self.set_visible(True)
102
if not self.Applet.Manager:
103
self.set_visible(False)
107
if self.Applet.Manager.ListAdapters() == []:
108
self.set_visible(False)
110
self.set_visible(True)
112
self.set_visible(False)
114
self.set_visible(False)
116
def set_visible(self, visible):
117
self.props.visible = visible
119
def SetTextLine(self, id, text):
121
self.lines[id] = text
128
self.update_tooltip()
131
def update_tooltip(self):
133
keys = self.lines.keys()
136
s += self.lines[k] + "\n"
138
self.props.tooltip_markup = s[:-1]
140
def IconShouldChange(self):
141
self.on_status_icon_resized()
143
def on_adapter_added(self, path):
144
self.QueryVisibility()
146
def on_adapter_removed(self, path):
147
self.QueryVisibility()
149
def on_manager_state_changed(self, state):
150
self.QueryVisibility()
152
def on_status_icon_resized(self):
153
self.icon = "blueman-tray"
155
#p = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, 22, 22)
159
#self.pixbuf.copy_area(0, 0, self.pixbuf.props.width, self.pixbuf.props.height, p, 5, 0)
162
ic = gtk.icon_theme_get_default()
164
def callback(inst, ret):
171
self.Applet.Plugins.RunEx("on_status_icon_query_icon", callback)
172
self.props.icon_name = self.icon
176
def on_query_status_icon_visibility(self):
177
return StatusIcon.SHOW
179
def on_status_icon_query_icon(self):