52
def __init__(self, datadir, db, icons, store=None):
52
def __init__(self, datadir, db, cache, icons, store=None):
53
53
super(ViewSwitcher, self).__init__()
54
54
self.datadir = datadir
57
store = ViewSwitcherList(datadir, db, icons)
57
store = ViewSwitcherList(datadir, db, cache, icons)
58
58
# FIXME: this is just set here for app.py, make the
59
59
# transactions-changed signal part of the view api
60
60
# instead of the model
83
83
self.set_enable_search(False)
85
85
self.selected_channel_name = None
86
self.selected_channel_installed_only = False
87
88
self.connect("row-expanded", self.on_treeview_row_expanded)
88
89
self.connect("row-collapsed", self.on_treeview_row_collapsed)
106
107
def on_cursor_changed(self, widget):
107
108
(path, column) = self.get_cursor()
108
109
model = self.get_model()
109
self.selected_channel_name = model[path][ViewSwitcherList.COL_NAME]
110
110
action = model[path][ViewSwitcherList.COL_ACTION]
111
111
channel = model[path][ViewSwitcherList.COL_CHANNEL]
112
self.selected_channel_name = model[path][ViewSwitcherList.COL_NAME]
114
self.selected_channel_installed_only = channel.installed_only
112
115
self.emit("view-changed", action, channel)
114
117
def get_view(self):
140
143
def expand_available_node(self):
141
144
""" expand the available pane node in the viewswitcher pane """
142
145
model = self.get_model()
143
available_path = model.get_path(model.available_iter)
144
self.expand_row(available_path, False)
147
self.expand_row(model.get_path(model.available_iter), False)
146
149
def is_available_node_expanded(self):
147
150
""" return True if the available pane node in the viewswitcher pane is expanded """
149
model = self.get_model()
151
available_path = model.get_path(model.available_iter)
152
expanded = self.row_expanded(available_path)
151
model = self.get_model()
154
expanded = self.row_expanded(model.get_path(model.available_iter))
157
def expand_installed_node(self):
158
""" expand the installed pane node in the viewswitcher pane """
159
model = self.get_model()
161
self.expand_row(model.get_path(model.installed_iter), False)
163
def is_installed_node_expanded(self):
164
""" return True if the installed pane node in the viewswitcher pane is expanded """
165
model = self.get_model()
168
expanded = self.row_expanded(model.get_path(model.installed_iter))
155
171
def _on_channels_refreshed(self, model):
160
176
model = self.get_model()
162
channel_iter_to_select = model.get_channel_iter_for_name(self.selected_channel_name)
178
channel_iter_to_select = model.get_channel_iter_for_name(self.selected_channel_name,
179
self.selected_channel_installed_only)
163
180
if channel_iter_to_select:
164
181
self.set_cursor(model.get_path(channel_iter_to_select))
184
201
ANIMATION_PATH = "/usr/share/icons/hicolor/24x24/status/softwarecenter-progress.png"
186
203
__gsignals__ = {'channels-refreshed':(gobject.SIGNAL_RUN_FIRST,
190
def __init__(self, datadir, db, icons):
208
def __init__(self, datadir, db, cache, icons):
191
209
gtk.TreeStore.__init__(self, AnimatedImage, str, int, gobject.TYPE_PYOBJECT)
192
210
self.icons = icons
193
211
self.datadir = datadir
194
212
self.backend = get_install_backend()
195
213
self.backend.connect("transactions-changed", self.on_transactions_changed)
214
self.backend.connect("transaction-finished", self.on_transaction_finished)
196
215
self.backend.connect("channels-changed", self.on_channels_changed)
198
218
self.distro = get_distro()
199
219
# pending transactions
200
220
self._pending = 0
201
221
# setup the normal stuff
222
# first, the availablepane items
202
223
available_icon = self._get_icon("softwarecenter")
203
224
self.available_iter = self.append(None, [available_icon, _("Get Software"), self.ACTION_ITEM_AVAILABLE, None])
225
# the installedpane items
226
icon = AnimatedImage(self.icons.load_icon("computer", self.ICON_SIZE, 0))
227
self.installed_iter = self.append(None, [icon, _("Installed Software"), self.ACTION_ITEM_INSTALLED, None])
205
229
# do initial channel list update
206
230
self.channel_manager = ChannelsManager(db, icons)
207
231
self._update_channel_list()
209
icon = AnimatedImage(self.icons.load_icon("computer", self.ICON_SIZE, 0))
210
installed_iter = self.append(None, [icon, _("Installed Software"), self.ACTION_ITEM_INSTALLED, None])
233
# the historypane item
211
234
icon = self._get_icon("clock")
212
235
history_iter = self.append(None, [icon, _("History"), self.ACTION_ITEM_HISTORY, None])
213
236
icon = AnimatedImage(None)
237
260
for (i, row) in enumerate(self):
238
261
if row[self.COL_ACTION] == self.ACTION_ITEM_PENDING:
264
def on_transaction_finished(self, backend, success):
266
self._update_channel_list_installed_view()
267
self.emit("channels-refreshed")
241
def get_channel_iter_for_name(self, channel_name):
269
def get_channel_iter_for_name(self, channel_name, installed_only):
242
270
channel_iter_for_name = None
243
child = self.iter_children(self.available_iter)
272
parent_iter = self.installed_iter
274
parent_iter = self.available_iter
275
child = self.iter_children(parent_iter)
245
277
if self.get_value(child, self.COL_NAME) == channel_name:
246
278
channel_iter_for_name = child
248
280
child = self.iter_next(child)
281
if not channel_iter_for_name:
249
283
return channel_iter_for_name
251
285
def _get_icon(self, icon_name):
260
294
def _update_channel_list(self):
295
self._update_channel_list_available_view()
296
self._update_channel_list_installed_view()
297
self.emit("channels-refreshed")
299
def _update_channel_list_available_view(self):
261
300
# check what needs to be cleared. we need to append first, kill
262
301
# afterward because otherwise a row without children is collapsed
273
312
# iterate the channels and add as subnodes of the available node
274
313
for channel in self.channel_manager.channels:
275
314
self.append(self.available_iter, [
276
channel.get_channel_icon(),
277
channel.get_channel_display_name(),
278
self.ACTION_ITEM_CHANNEL,
280
# delete the old ones
281
for child in iters_to_kill:
283
self.emit("channels-refreshed")
315
channel.get_channel_icon(),
316
channel.get_channel_display_name(),
317
self.ACTION_ITEM_CHANNEL,
319
# delete the old ones
320
for child in iters_to_kill:
323
def _update_channel_list_installed_view(self):
324
# see comments for _update_channel_list_available_view() method above
325
child = self.iter_children(self.installed_iter)
326
iters_to_kill = set()
328
iters_to_kill.add(child)
329
child = self.iter_next(child)
330
# iterate the channels and add as subnodes of the installed node
331
for channel in self.channel_manager.channels_installed_only:
332
# check for no installed items for each channel and do not
333
# append the channel item in this case
334
enquire = xapian.Enquire(self.db.xapiandb)
335
enquire.set_query(channel.get_channel_query())
336
matches = enquire.get_mset(0, len(self.db))
337
# only check channels that have a small number of items
338
add_channel_item = True
339
if len(matches) < 200:
340
add_channel_item = False
342
doc = m[xapian.MSET_DOCUMENT]
343
pkgname = self.db.get_pkgname(doc)
344
if (pkgname in self.cache and
345
self.cache[pkgname].is_installed):
346
add_channel_item = True
349
self.append(self.installed_iter, [
350
channel.get_channel_icon(),
351
channel.get_channel_display_name(),
352
self.ACTION_ITEM_CHANNEL,
354
# delete the old ones
355
for child in iters_to_kill:
286
358
if __name__ == "__main__":
287
359
logging.basicConfig(level=logging.DEBUG)