40
45
"view-changed" : (gobject.SIGNAL_RUN_LAST,
47
def __init__(self, datadir, icons, store=None):
52
def __init__(self, datadir, db, icons, store=None):
48
53
super(ViewSwitcher, self).__init__()
49
54
self.datadir = datadir
52
store = ViewSwitcherList(datadir, icons)
57
store = ViewSwitcherList(datadir, db, icons)
53
58
# FIXME: this is just set here for app.py, make the
54
59
# transactions-changed signal part of the view api
55
60
# instead of the model
130
COL_ACTION) = range(3)
136
COL_CHANNEL_NAME) = range(4)
132
138
# items in the treeview
133
139
(ACTION_ITEM_AVAILABLE,
134
140
ACTION_ITEM_INSTALLED,
135
141
ACTION_ITEM_SEPARATOR_1,
136
ACTION_ITEM_PENDING) = range(4)
143
ACTION_ITEM_CHANNEL) = range(5)
140
147
ANIMATION_PATH = "/usr/share/icons/hicolor/24x24/status/softwarecenter-progress.png"
142
def __init__(self, datadir, icons):
143
gtk.TreeStore.__init__(self, AnimatedImage, str, int)
149
def __init__(self, datadir, db, icons):
150
gtk.TreeStore.__init__(self, AnimatedImage, str, int, str)
144
151
self.icons = icons
145
152
self.datadir = datadir
146
153
self.backend = get_install_backend()
147
154
self.backend.connect("transactions-changed", self.on_transactions_changed)
156
self.distro = get_distro()
157
# pending transactions
148
159
# setup the normal stuff
149
if self.icons.lookup_icon("softwarecenter", self.ICON_SIZE, 0):
150
icon = AnimatedImage(self.icons.load_icon("softwarecenter", self.ICON_SIZE, 0))
152
icon = AnimatedImage(self.icons.load_icon("gtk-missing-image",
154
piter = self.append(None, [icon, _("Get Software"), self.ACTION_ITEM_AVAILABLE])
156
if self.icons.lookup_icon("distributor-logo", self.ICON_SIZE, 0):
157
icon = AnimatedImage(self.icons.load_icon("distributor-logo", self.ICON_SIZE, 0))
159
# icon not present in theme, probably because running uninstalled
160
icon = AnimatedImage(self.icons.load_icon("gtk-missing-image",
162
self.append(piter, [icon, _("Free Software"), self.ACTION_ITEM_AVAILABLE])
160
available_icon = self._get_icon("softwarecenter")
161
available_iter = self.append(None, [available_icon, _("Get Software"), self.ACTION_ITEM_AVAILABLE, None])
163
# gather icons for use with channel sources
164
self.dist_icon = self._get_icon("distributor-logo")
165
self.partner_icon = self._get_icon("partner")
166
self.ppa_icon = self._get_icon("ppa")
167
self.generic_repo_icon = self._get_icon("generic-repository")
168
self.unknown_channel_icon = self._get_icon("unknown-channel")
170
# get list of channel sources of form:
171
# [icon, label, action, channel_name]
172
channel_sources = self._get_channel_sources()
174
# iterate the channel sources list and add as subnodes of the available node
175
for channel in channel_sources:
176
self.append(available_iter, channel)
164
178
icon = AnimatedImage(self.icons.load_icon("computer", self.ICON_SIZE, 0))
165
self.append(None, [icon, _("Installed Software"), self.ACTION_ITEM_INSTALLED])
179
installed_iter = self.append(None, [icon, _("Installed Software"), self.ACTION_ITEM_INSTALLED, ""])
166
180
icon = AnimatedImage(None)
167
self.append(None, [icon, "<span size='1'> </span>", self.ACTION_ITEM_SEPARATOR_1])
181
self.append(None, [icon, "<span size='1'> </span>", self.ACTION_ITEM_SEPARATOR_1, ""])
169
183
def on_transactions_changed(self, backend, total_transactions):
170
184
logging.debug("on_transactions_changed '%s'" % total_transactions)
184
198
if row[self.COL_ACTION] == self.ACTION_ITEM_PENDING:
201
def _get_icon(self, icon_name):
202
if self.icons.lookup_icon(icon_name, self.ICON_SIZE, 0):
203
icon = AnimatedImage(self.icons.load_icon(icon_name, self.ICON_SIZE, 0))
205
# icon not present in theme, probably because running uninstalled
206
icon = AnimatedImage(self.icons.load_icon("gtk-missing-image",
210
def _get_channel_sources(self):
212
return a list of channel sources, with each entry in the list
214
[icon, label, action, channel_name]
217
for channel_iter in self.db.xapiandb.allterms("XOL"):
218
if len(channel_iter.term) == 3:
220
channel_name = channel_iter.term[3:]
222
# get origin information for this channel
223
m = self.db.xapiandb.postlist_begin(channel_iter.term)
224
doc = self.db.xapiandb.get_document(m.get_docid())
225
for term_iter in doc.termlist():
226
if term_iter.term.startswith("XOO") and len(term_iter.term) > 3:
227
channel_origin = term_iter.term[3:]
229
logging.debug("channel_name: %s" % channel_name)
230
logging.debug("channel_origin: %s" % channel_origin)
231
channels.append((channel_name, channel_origin))
234
for (channel_name, channel_origin) in self._order_channels(channels):
235
channel_sources.append(
236
[self._get_icon_for_channel(channel_name, channel_origin),
237
self._get_display_name_for_channel(channel_name),
238
self.ACTION_ITEM_CHANNEL,
241
return channel_sources
243
def _order_channels(self, channels):
245
given a list of channels, order them according to:
246
Distribution, Partners, PPAs alphabetically, Other channels alphabetically,
254
ordered_channels = []
256
for (channel_name, channel_origin) in channels:
258
unknown_channel.append((channel_name, channel_origin))
259
elif channel_name == self.distro.get_distro_channel_name():
260
dist_channel.append((channel_name, channel_origin))
261
elif channel_origin and channel_origin.startswith("LP-PPA"):
262
ppa_channels.append((channel_name, channel_origin))
263
# TODO: detect generic repository source (e.g., Google, Inc.)
264
# TODO: detect partner channel
266
other_channels.append((channel_name, channel_origin))
269
ordered_channels.extend(dist_channel)
270
ordered_channels.extend(partner_channel)
271
ordered_channels.extend(ppa_channels)
272
ordered_channels.extend(other_channels)
273
ordered_channels.extend(unknown_channel)
275
return ordered_channels
277
def _get_icon_for_channel(self, channel_name, channel_origin):
279
return the icon that corresponds to each channel node based
280
on the channel name and its origin string
283
channel_icon = self.unknown_channel_icon
284
elif channel_name == self.distro.get_distro_channel_name():
285
channel_icon = self.dist_icon
286
elif channel_origin and channel_origin.startswith("LP-PPA"):
287
channel_icon = self.ppa_icon
288
# TODO: add check for generic repository source (e.g., Google, Inc.)
289
# TODO: add check for partner_icon
291
channel_icon = self.unknown_channel_icon
294
def _get_display_name_for_channel(self, channel_name):
296
return the display name for the corresponding channel node
299
channel_display_name = _("Other")
300
elif channel_name == self.distro.get_distro_channel_name():
301
channel_display_name = self.distro.get_distro_channel_description()
303
channel_display_name = channel_name
304
return channel_display_name
187
306
if __name__ == "__main__":
188
307
logging.basicConfig(level=logging.DEBUG)