~mmcg069/software-center/star-tweaks

« back to all changes in this revision

Viewing changes to softwarecenter/view/catview_gtk.py

  • Committer: Matthew McGowan
  • Date: 2011-04-02 00:09:53 UTC
  • mfrom: (1556.1.65 trunk)
  • Revision ID: matthew.joseph.mcgowan@gmail.com-20110402000953-uxeempz22lurkmms
merge w trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
175
175
        self.whatsnew_carousel = None
176
176
        self.departments = None
177
177
 
 
178
        # this means that the departments don't jump down once the cache loads
 
179
        # it doesn't look odd if the recommends are never loaded
 
180
        self.recommended = gtk.Label()
 
181
        self.vbox.pack_start(self.recommended, False, False)
 
182
 
178
183
        self.build(desktopdir)
179
184
        return
180
185
 
275
280
    @wait_for_apt_cache_ready
276
281
    def _append_recommendations(self):
277
282
        """ get recommendations from zeitgeist and add to the view """
278
 
 
279
 
        def _show_recommended_apps_widget(query, r_apps):
280
 
            recommended = gtk.Label()
281
 
            recommended_text = gettext.ngettext(
 
283
        # FIXME: the whole process of finding mimetypes, querying db etc seems
 
284
        #        to be a bit duplicated
 
285
 
 
286
        def _show_recommended_apps_widget(query):
 
287
            # determine correctly how many apps will be shown
 
288
            enquire = xapian.Enquire(self.db.xapiandb)
 
289
            enquire.set_query(query)
 
290
            tmp_matches = enquire.get_mset(0, len(self.db), None, self.apps_filter)
 
291
            nr_apps = tmp_matches.get_matches_estimated()
 
292
 
 
293
            # update the widget
 
294
            text = gettext.ngettext(
282
295
             "Welcome back! There is <a href=\"\">%i new recommendation</a>"
283
 
                                                   " for you." % len(r_apps),
 
296
                                                   " for you." % nr_apps,
284
297
             "Welcome back! There are <a href=\"\">%i new recommendations</a>"
285
 
                                                     " for you." % len(r_apps),
286
 
             len(r_apps))
287
 
            recommended.set_markup(recommended_text)
288
 
            recommended.set_visible(True)
289
 
            recommended.get_accessible().set_role(atk.ROLE_PUSH_BUTTON)
290
 
            recommended.set_alignment(0,-1)
291
 
            self.vbox.pack_start(recommended, False, False)
292
 
            self.vbox.reorder_child(recommended, 0)
 
298
                                                     " for you." % nr_apps,
 
299
             nr_apps)
 
300
            self.recommended.set_markup(text)
 
301
            self.recommended.get_accessible().set_role(atk.ROLE_PUSH_BUTTON)
 
302
            self.recommended.set_alignment(0,-1)
293
303
 
294
304
            # build category
295
305
            rec_cat = Category("Recommendations",
297
307
                               "category-recommendations",
298
308
                               query,
299
309
                               sortmode=SORT_BY_SEARCH_RANKING)
300
 
            recommended.connect('activate-link',
301
 
                                self._on_recommended_clicked,
302
 
                                rec_cat)
 
310
            self.recommended.connect('activate-link',
 
311
                                     self._on_recommended_clicked,
 
312
                                     rec_cat)
303
313
              
304
314
        def _popular_mimetypes_callback(mimetypes):
305
315
            def _find_applications(mimetypes):
319
329
                    results.append("AP"+app.pkgname)
320
330
                return results
321
331
 
322
 
            def _make_query(r_apps):
323
 
                if len(r_apps) > 0:
324
 
                    return xapian.Query(xapian.Query.OP_OR, r_apps)
325
 
                return None
326
332
            # get the recommended apps     
327
333
            r_apps =_find_applications(mimetypes) 
328
334
            if r_apps:
329
 
                # build the widget
330
 
                _show_recommended_apps_widget(_make_query(r_apps), r_apps)
 
335
                _show_recommended_apps_widget(xapian.Query(xapian.Query.OP_OR, r_apps))
331
336
        
332
337
        zeitgeist_singleton.get_popular_mimetypes(_popular_mimetypes_callback)
333
338
 
358
363
                                     self.icons,
359
364
                                     featured_cat.query,
360
365
                                     self.apps_limit,
361
 
                                     exact=True,
362
366
                                     filter=self.apps_filter,
363
367
                                     icon_size=best_stock_size,
364
368
                                     global_icon_cache=False,
493
497
        self.root_category = root_category
494
498
 
495
499
        # sections
 
500
        self.current_category = None
496
501
        self.departments = None
497
502
        return
498
503
 
534
539
 
535
540
        buttons = []
536
541
        for cat in sorted_cats:
537
 
            cat_btn = SubcategoryButton(cat.name, cat.iconname)
538
 
            cat_btn.connect('clicked', self._on_category_clicked, cat)
539
 
            buttons.append(cat_btn)
 
542
            # add the subcategory if and only if it is non-empty
 
543
            enquire = xapian.Enquire(self.db.xapiandb)
 
544
            enquire.set_query(cat.query)
 
545
            if len(enquire.get_mset(0, 1, None, self.apps_filter)):
 
546
                cat_btn = SubcategoryButton(cat.name, cat.iconname)
 
547
                cat_btn.connect('clicked', self._on_category_clicked, cat)
 
548
                buttons.append(cat_btn)
 
549
 
 
550
        # partialy work around a (quite rare) corner case
 
551
        if num_items == 0:
 
552
            enquire = xapian.Enquire(self.db.xapiandb)
 
553
            enquire.set_query(xapian.Query(xapian.Query.OP_AND, 
 
554
                                           root_category.query,
 
555
                                           xapian.Query("ATapplication")))
 
556
            # assuming that we only want apps is not always correct ^^^
 
557
            tmp_matches = enquire.get_mset(0, len(self.db), None, self.apps_filter)
 
558
            num_items = tmp_matches.get_matches_estimated()
540
559
 
541
560
        # append an additional button to show all of the items in the category
542
561
        name = gobject.markup_escape_text('%s %s' % (_("All"), num_items))
558
577
        return
559
578
 
560
579
    def set_subcategory(self, root_category, num_items=0, block=False):
 
580
        self.current_category = root_category
561
581
        # nothing to do
562
582
        if self.categories == root_category.subcategories:
563
583
            return