Example #1
0
    def test_navhistory_cat_search_then_clear(self):
        (back_forward_btn, options, navhistory, view_manager,
         pane) = self._get_boring_stuff()

        # first we must initialize the NavHistory with the equivalent of the initial category view
        # NnavigationItem(view_manager, pane, page, view_state, callback)
        item = NavigationItem(view_manager, pane, AvailablePane.Pages.LOBBY,
                              DisplayState())
        navhistory.append(item)

        # simulate Accessories category LIST
        dstate = DisplayState()
        dstate.category = Category('accessories', 'Accessories', 'iconname',
                                   'query')
        item = NavigationItem(view_manager, pane, AvailablePane.Pages.LIST,
                              dstate)
        navhistory.append(item)
        # displaying the Accessories LIST
        self.assertTrue(len(navhistory.stack) == 2)
        self.assertTrue(back_forward_btn.left.sensitive)
        self.assertFalse(back_forward_btn.right.sensitive)

        # simulate a user search
        dstate = DisplayState()
        dstate.category = Category('accessories', 'Accessories', 'iconname',
                                   'query')
        dstate.search_term = "chess"
        item = NavigationItem(view_manager, pane, AvailablePane.Pages.LIST,
                              dstate)
        navhistory.append(item)
        # should be displaying the search results for Accessories
        self.assertTrue(back_forward_btn.left.sensitive)
        self.assertFalse(back_forward_btn.right.sensitive)
        self.assertTrue(len(navhistory.stack) == 3)

        # simulate a user clearing the search
        dstate = DisplayState()
        dstate.category = Category('accessories', 'Accessories', 'iconname',
                                   'query')
        dstate.search_term = ""
        item = NavigationItem(view_manager, pane, AvailablePane.Pages.LIST,
                              dstate)
        navhistory.append(item)
        self.assertTrue(back_forward_btn.left.sensitive)
        self.assertFalse(back_forward_btn.right.sensitive)
        # should be returned to the Accessories list view
        self.assertTrue(len(navhistory.stack) == 2)
Example #2
0
 def _on_show_exhibits(self, exhibit_banner, exhibit):
     pkgs = exhibit.package_names.split(",")
     if len(pkgs) == 1:
         app = Application("", pkgs[0])
         self.emit("application-activated", app)
     else:
         query = get_query_for_pkgnames(pkgs)
         title = exhibit.title_translated
         untranslated_name = exhibit.package_names
         # create a temp query
         cat = Category(untranslated_name,
                        title,
                        None,
                        query,
                        flags=['nonapps-visible'])
         self.emit("category-selected", cat)
Example #3
0
    def _update_subcat_departments(self, category, num_items):
        self.departments.remove_all()

        # set the subcat header
        m = "<b><big>%s</big></b>"
        self.subcat_label.set_markup(m % GLib.markup_escape_text(self.header))

        # sort Category.name's alphabetically
        sorted_cats = categories_sorted_by_name(self.categories)
        enquire = xapian.Enquire(self.db.xapiandb)
        app_filter = AppFilter(self.db, self.cache)
        distro = get_distro()
        supported_only = get_global_filter().supported_only
        for cat in sorted_cats:
            # add the subcategory if and only if it is non-empty
            if supported_only:
                enquire.set_query(
                    xapian.Query(xapian.Query.OP_AND, cat.query,
                                 distro.get_supported_query()))
            else:
                enquire.set_query(cat.query)
            if len(enquire.get_mset(0, 1)):
                tile = CategoryTile(cat.name, cat.iconname)
                tile.connect('clicked', self.on_category_clicked, cat)
                self.departments.add_child(tile)

        # partially work around a (quite rare) corner case
        if num_items == 0:
            enquire.set_query(
                xapian.Query(xapian.Query.OP_AND, category.query,
                             xapian.Query("ATapplication")))
            # assuming that we only want apps is not always correct ^^^
            tmp_matches = enquire.get_mset(0, len(self.db), None, app_filter)
            num_items = tmp_matches.get_matches_estimated()

        # append an additional button to show all of the items in the category
        all_cat = Category("All", _("All"), "category-show-all",
                           category.query)
        name = GLib.markup_escape_text('%s %s' % (_("All"), num_items))
        tile = CategoryTile(name, "category-show-all")
        tile.connect('clicked', self.on_category_clicked, all_cat)
        self.departments.add_child(tile)
        self.departments.queue_draw()
        return num_items
Example #4
0
    def test_navhistory_subcat_search_then_clear(self):
        (back_forward_btn, options, navhistory, view_manager,
         pane) = self._get_boring_stuff()

        # first we must initialize the NavHistory with the equivalent of the initial category view
        # NnavigationItem(view_manager, pane, page, view_state, callback)
        item = NavigationItem(view_manager, pane, AvailablePane.Pages.LOBBY,
                              DisplayState())
        navhistory.append(item)

        board_games = Category('board-games', 'Board Games', 'iconname',
                               'query')
        games = Category('games',
                         'Games',
                         'iconname',
                         'query',
                         subcategories=[
                             board_games,
                         ])

        # simulate Games category (with subcats)
        dstate = DisplayState()

        dstate.category = games
        item = NavigationItem(view_manager, pane,
                              AvailablePane.Pages.SUBCATEGORY, dstate)
        navhistory.append(item)

        # displaying the Games SUBCATEGORY
        self.assertTrue(len(navhistory.stack) == 2)
        self.assertTrue(back_forward_btn.left.sensitive)
        self.assertFalse(back_forward_btn.right.sensitive)

        # simulate Board Games subcategory LIST
        dstate = DisplayState()
        dstate.category = games
        dstate.subcategory = board_games
        item = NavigationItem(view_manager, pane, AvailablePane.Pages.LIST,
                              dstate)
        navhistory.append(item)

        # displaying the Accessories LIST
        self.assertTrue(len(navhistory.stack) == 3)
        self.assertTrue(back_forward_btn.left.sensitive)
        self.assertFalse(back_forward_btn.right.sensitive)

        # simulate a user search within subcat
        dstate = DisplayState()
        dstate.category = games
        dstate.subcategory = board_games
        dstate.search_term = "chess"
        item = NavigationItem(view_manager, pane, AvailablePane.Pages.LIST,
                              dstate)
        navhistory.append(item)

        # should be displaying the search results for Accessories
        self.assertTrue(back_forward_btn.left.sensitive)
        self.assertFalse(back_forward_btn.right.sensitive)
        self.assertTrue(len(navhistory.stack) == 4)

        # simulate a user clearing the search
        dstate = DisplayState()
        dstate.category = games
        dstate.subcategory = board_games
        dstate.search_term = ""
        item = NavigationItem(view_manager, pane, AvailablePane.Pages.LIST,
                              dstate)
        navhistory.append(item)

        # should be returned to the Board Games LIST view
        self.assertTrue(back_forward_btn.left.sensitive)
        self.assertFalse(back_forward_btn.right.sensitive)
        self.assertTrue(len(navhistory.stack) == 3)

        # verify that navhistory item 2 is LIST page
        self.assertTrue(navhistory.stack[2].page == AvailablePane.Pages.LIST)
        # verify that navhistory item 1 is SUBCATEGORY page
        self.assertTrue(
            navhistory.stack[1].page == AvailablePane.Pages.SUBCATEGORY)
        # verify that navhistory item 0 is LOBBY page
        self.assertTrue(navhistory.stack[0].page == AvailablePane.Pages.LOBBY)