~mvo/software-center/new-apps-test1

« back to all changes in this revision

Viewing changes to softwarecenter/view/viewswitcher.py

  • Committer: Gary Lasker
  • Date: 2010-06-21 00:27:54 UTC
  • mfrom: (848.1.7 software-center)
  • Revision ID: gary.lasker@canonical.com-20100621002754-vvkcbimcff1dcqdh
* softwarecenter/app.py,
  softwarecenter/backend/channel.py,
  softwarecenter/view/channelpane.py,
  softwarecenter/view/viewswitcher.py:
  - implement channel views for installed items

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
    }
50
50
 
51
51
 
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
55
55
        self.icons = icons
56
56
        if not store:
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)
84
84
 
85
85
        self.selected_channel_name = None
 
86
        self.selected_channel_installed_only = False
86
87
        
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]
 
113
        if channel:
 
114
            self.selected_channel_installed_only = channel.installed_only
112
115
        self.emit("view-changed", action, channel)
113
116
        
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)
 
146
        if model:
 
147
            self.expand_row(model.get_path(model.available_iter), False)
145
148
            
146
149
    def is_available_node_expanded(self):
147
150
        """ return True if the available pane node in the viewswitcher pane is expanded """
148
 
        expanded = False
149
 
        model = self.get_model()
150
 
        if model:
151
 
            available_path = model.get_path(model.available_iter)
152
 
            expanded = self.row_expanded(available_path)
 
151
        model = self.get_model()
 
152
        expanded = False
 
153
        if model:
 
154
            expanded = self.row_expanded(model.get_path(model.available_iter))
 
155
        return expanded
 
156
        
 
157
    def expand_installed_node(self):
 
158
        """ expand the installed pane node in the viewswitcher pane """
 
159
        model = self.get_model()
 
160
        if model:
 
161
            self.expand_row(model.get_path(model.installed_iter), False)
 
162
            
 
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()
 
166
        expanded = False
 
167
        if model:
 
168
            expanded = self.row_expanded(model.get_path(model.installed_iter))
153
169
        return expanded
154
170
 
155
171
    def _on_channels_refreshed(self, model):
159
175
        """
160
176
        model = self.get_model()
161
177
        if 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))
165
182
 
184
201
    ANIMATION_PATH = "/usr/share/icons/hicolor/24x24/status/softwarecenter-progress.png"
185
202
 
186
203
    __gsignals__ = {'channels-refreshed':(gobject.SIGNAL_RUN_FIRST,
187
 
                                     gobject.TYPE_NONE,
188
 
                                     ())}
189
 
 
190
 
    def __init__(self, datadir, db, icons):
 
204
                                          gobject.TYPE_NONE,
 
205
                                          ())}
 
206
 
 
207
 
 
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)
197
216
        self.db = db
 
217
        self.cache = cache
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])
204
 
 
 
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])
 
228
        
205
229
        # do initial channel list update
206
230
        self.channel_manager = ChannelsManager(db, icons)
207
231
        self._update_channel_list()
208
232
        
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:
239
262
                    del self[(i,)]
 
263
                    
 
264
    def on_transaction_finished(self, backend, success):
 
265
        if success:
 
266
            self._update_channel_list_installed_view()
 
267
            self.emit("channels-refreshed")
240
268
 
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)
 
271
        if installed_only:
 
272
            parent_iter = self.installed_iter
 
273
        else:
 
274
            parent_iter = self.available_iter
 
275
        child = self.iter_children(parent_iter)
244
276
        while child:
245
277
            if self.get_value(child, self.COL_NAME) == channel_name:
246
278
                channel_iter_for_name = child
247
279
                break
248
280
            child = self.iter_next(child)
 
281
        if not channel_iter_for_name:
 
282
            return parent_iter
249
283
        return channel_iter_for_name
250
284
                    
251
285
    def _get_icon(self, icon_name):
258
292
        return icon
259
293
 
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")
 
298
        
 
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
263
302
        # by the view.
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,
279
 
                    channel])
280
 
        # delete the old ones
281
 
        for child in iters_to_kill:
282
 
            self.remove(child)
283
 
        self.emit("channels-refreshed")
284
 
        
 
315
                        channel.get_channel_icon(),
 
316
                        channel.get_channel_display_name(),
 
317
                        self.ACTION_ITEM_CHANNEL,
 
318
                        channel])
 
319
        # delete the old ones
 
320
        for child in iters_to_kill:
 
321
            self.remove(child)
 
322
    
 
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()
 
327
        while child:
 
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
 
341
                for m in matches:
 
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
 
347
                        break
 
348
            if add_channel_item:
 
349
                self.append(self.installed_iter, [
 
350
                            channel.get_channel_icon(),
 
351
                            channel.get_channel_display_name(),
 
352
                            self.ACTION_ITEM_CHANNEL,
 
353
                            channel])
 
354
        # delete the old ones
 
355
        for child in iters_to_kill:
 
356
            self.remove(child)
285
357
 
286
358
if __name__ == "__main__":
287
359
    logging.basicConfig(level=logging.DEBUG)