40
44
"view-changed" : (gobject.SIGNAL_RUN_LAST,
47
def __init__(self, datadir, icons, store=None):
51
def __init__(self, datadir, db, icons, store=None):
48
52
super(ViewSwitcher, self).__init__()
49
53
self.datadir = datadir
52
store = ViewSwitcherList(datadir, icons)
56
store = ViewSwitcherList(datadir, db, icons)
53
57
# FIXME: this is just set here for app.py, make the
54
58
# transactions-changed signal part of the view api
55
59
# instead of the model
130
COL_ACTION) = range(3)
137
COL_CHANNEL_NAME) = range(4)
132
139
# items in the treeview
133
140
(ACTION_ITEM_AVAILABLE,
134
141
ACTION_ITEM_INSTALLED,
135
142
ACTION_ITEM_SEPARATOR_1,
136
ACTION_ITEM_PENDING) = range(4)
144
ACTION_ITEM_CHANNEL) = range(5)
140
148
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)
150
def __init__(self, datadir, db, icons):
151
gtk.TreeStore.__init__(self, AnimatedImage, str, int, str)
144
152
self.icons = icons
145
153
self.datadir = datadir
146
154
self.backend = get_install_backend()
147
155
self.backend.connect("transactions-changed", self.on_transactions_changed)
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.unknown_channel_icon = self._get_icon("unknown-channel")
169
# get list of channel sources of form:
170
# [icon, label, action, channel_name]
171
channel_sources = self._get_channel_sources()
173
# iterate the channel sources list and add as subnodes of the available node
174
for channel in channel_sources:
175
self.append(available_iter, channel)
164
177
icon = AnimatedImage(self.icons.load_icon("computer", self.ICON_SIZE, 0))
165
self.append(None, [icon, _("Installed Software"), self.ACTION_ITEM_INSTALLED])
178
installed_iter = self.append(None, [icon, _("Installed Software"), self.ACTION_ITEM_INSTALLED, ""])
166
179
icon = AnimatedImage(None)
167
self.append(None, [icon, "<span size='1'> </span>", self.ACTION_ITEM_SEPARATOR_1])
180
self.append(None, [icon, "<span size='1'> </span>", self.ACTION_ITEM_SEPARATOR_1, ""])
182
# iterate the channel sources list and add as subnodes of the installed node
183
# TODO: These lists must be filtered on installed only!
184
for channel in channel_sources:
185
self.append(installed_iter, channel)
169
187
def on_transactions_changed(self, backend, total_transactions):
170
188
logging.debug("on_transactions_changed '%s'" % total_transactions)
184
202
if row[self.COL_ACTION] == self.ACTION_ITEM_PENDING:
205
def _get_icon(self, icon_name):
206
if self.icons.lookup_icon(icon_name, self.ICON_SIZE, 0):
207
icon = AnimatedImage(self.icons.load_icon(icon_name, self.ICON_SIZE, 0))
209
# icon not present in theme, probably because running uninstalled
210
icon = AnimatedImage(self.icons.load_icon("gtk-missing-image",
214
def _get_channel_sources(self):
216
return a list of channel sources, with each entry in the list
218
[icon, label, action, channel_name]
221
for channel_iter in self.db.xapiandb.allterms("XOL"):
222
channel_name = channel_iter.term[3:]
223
print "channel_name: %s" % channel_name
225
# get origin information for this channel
226
m = self.db.xapiandb.postlist_begin(channel_iter.term)
227
doc = self.db.xapiandb.get_document(m.get_docid())
228
for term_iter in doc.termlist():
229
if term_iter.term.startswith("XOO"):
230
channel_origin = term_iter.term[3:]
231
print "channel_origin: %s" % channel_origin
233
channels.append((channel_name, channel_origin))
236
for (channel_name, channel_origin) in self._order_channels(channels):
237
channel_sources.append([self._get_icon_for_channel(channel_name, channel_origin),
238
self._get_display_name_for_channel(channel_name),
239
self.ACTION_ITEM_CHANNEL,
242
return channel_sources
244
def _order_channels(self, channels):
246
given a list of channels, order them according to:
247
Distribution, Partners, PPAs alphabetically, Other channels alphabetically,
255
ordered_channels = []
257
for (channel_name, channel_origin) in channels:
259
unknown_channel.append((channel_name, channel_origin))
260
elif channel_name == "Ubuntu":
261
dist_channel.append((channel_name, channel_origin))
262
elif channel_origin and channel_origin.startswith("LP-PPA"):
263
ppa_channels.append((channel_name, channel_origin))
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
282
# TODO: detect PPA using the origin string (see above)
283
if channel_name == "Ubuntu":
284
channel_icon = self.dist_icon
285
elif channel_origin.startswith("LP-PPA"):
286
channel_icon = self.ppa_icon
287
# TODO: Add check for partner_icon
288
elif channel_name == "Unknown":
289
channel_icon = self.unknown_channel_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 = "Unknown"
300
elif channel_name == "Ubuntu":
301
channel_display_name = _("Provided by Ubuntu")
303
channel_display_name = channel_name
304
return channel_display_name
187
306
if __name__ == "__main__":
188
307
logging.basicConfig(level=logging.DEBUG)