예제 #1
0
def get_test_window():
    import softwarecenter.log
    softwarecenter.log.root.setLevel(level=logging.DEBUG)
    softwarecenter.log.add_filters_from_string("performance")
    fmt = logging.Formatter("%(name)s - %(message)s", None)
    softwarecenter.log.handler.setFormatter(fmt)

    from softwarecenter.paths import XAPIAN_BASE_PATH
    xapian_base_path = XAPIAN_BASE_PATH
    pathname = os.path.join(xapian_base_path, "xapian")

    # the store
    from softwarecenter.db.pkginfo import get_pkg_info
    cache = get_pkg_info()
    cache.open()

    # the db
    from softwarecenter.db.database import StoreDatabase
    db = StoreDatabase(pathname, cache)
    db.open()

    # additional icons come from app-install-data
    icons = Gtk.IconTheme.get_default()
    icons.prepend_search_path("/usr/share/app-install/icons/")
    icons.prepend_search_path("/usr/share/software-center/icons/")

    # create a filter
    from softwarecenter.db.appfilter import AppFilter
    filter = AppFilter(db, cache)
    filter.set_supported_only(False)
    filter.set_installed_only(True)

    # appview
    from softwarecenter.ui.gtk3.models.appstore2 import AppListStore
    from softwarecenter.db.enquire import AppEnquire
    enquirer = AppEnquire(cache, db)
    store = AppListStore(db, cache, icons)

    from softwarecenter.ui.gtk3.views.appview import AppView
    view = AppView(db, cache, icons, show_ratings=True)
    view.set_model(store)

    entry = Gtk.Entry()
    entry.stamp = 0
    entry.connect("changed", on_entry_changed, (view, enquirer))
    entry.set_text("gtk3")

    scroll = Gtk.ScrolledWindow()
    box = Gtk.VBox()
    box.pack_start(entry, False, True, 0)
    box.pack_start(scroll, True, True, 0)

    win = Gtk.Window()
    win.connect("destroy", lambda x: Gtk.main_quit())
    scroll.add(view)
    win.add(box)
    win.set_size_request(600, 400)
    win.show_all()

    return win
예제 #2
0
 def _run_channel_enquirer(self, persistent_duplicate_filter=True):
     xfilter = AppFilter(self.db, self.cache)
     xfilter.set_installed_only(True)
     if self.state.channel:
         self.enquirer.set_query(
             self.state.channel.query,
             sortmode=SortMethods.BY_ALPHABET,
             nonapps_visible=NonAppVisibility.MAYBE_VISIBLE,
             filter=xfilter,
             nonblocking_load=False,
             persistent_duplicate_filter=persistent_duplicate_filter)
예제 #3
0
 def _run_channel_enquirer(self, persistent_duplicate_filter=True):
     xfilter = AppFilter(self.db, self.cache)
     xfilter.set_installed_only(True)
     if self.state.channel:
         self.enquirer.set_query(
             self.state.channel.query,
             sortmode=SortMethods.BY_ALPHABET,
             nonapps_visible=NonAppVisibility.MAYBE_VISIBLE,
             filter=xfilter,
             nonblocking_load=False,
             persistent_duplicate_filter=persistent_duplicate_filter)
예제 #4
0
    def _do_search(self, terms):
        self.state.search_term = terms
        xfilter = AppFilter(self.db, self.cache)
        xfilter.set_installed_only(True)
        self.enquirer.set_query(
            self.get_query(), nonapps_visible=self.nonapps_visible, filter=xfilter, nonblocking_load=True
        )

        self.visible_docids = self.enquirer.get_docids()
        self.visible_cats = self._get_vis_cats(self.visible_docids)
        self.treefilter.refilter()
        self.app_view.tree_view.expand_all()
예제 #5
0
    def _do_search(self, terms):
        self.state.search_term = terms
        xfilter = AppFilter(self.db, self.cache)
        xfilter.set_installed_only(True)
        self.enquirer.set_query(self.get_query(),
                                nonapps_visible=self.nonapps_visible,
                                filter=xfilter,
                                nonblocking_load=True)

        self.visible_docids = self.enquirer.get_docids()
        self.visible_cats = self._get_vis_cats(self.visible_docids)
        self.treefilter.refilter()
        self.app_view.tree_view.expand_all()
예제 #6
0
 def get_documents(self, db):
     """ return the database docids for the given category """
     enq = AppEnquire(db._aptcache, db)
     app_filter = AppFilter(db, db._aptcache)
     if "available-only" in self.flags:
         app_filter.set_available_only(True)
     if "not-installed-only" in self.flags:
         app_filter.set_not_installed_only(True)
     enq.set_query(self.query,
                   limit=self.item_limit,
                   filter=app_filter,
                   sortmode=self.sortmode,
                   nonapps_visible=NonAppVisibility.ALWAYS_VISIBLE,
                   nonblocking_load=False)
     return enq.get_documents()
예제 #7
0
def get_test_window():
    import softwarecenter.log
    softwarecenter.log.root.setLevel(level=logging.DEBUG)
    softwarecenter.log.add_filters_from_string("performance")
    fmt = logging.Formatter("%(name)s - %(message)s", None)
    softwarecenter.log.handler.setFormatter(fmt)

    from softwarecenter.testutils import (
        get_test_db, get_test_pkg_info, get_test_gtk3_icon_cache,
        get_test_categories)

    cache = get_test_pkg_info()
    db = get_test_db()
    icons = get_test_gtk3_icon_cache()

    # create a filter
    from softwarecenter.db.appfilter import AppFilter
    filter = AppFilter(db, cache)
    filter.set_supported_only(False)
    filter.set_installed_only(True)

    # get the TREEstore
    from softwarecenter.ui.gtk3.models.appstore2 import AppTreeStore
    store = AppTreeStore(db, cache, icons)

    # populate from data
    cats = get_test_categories(db)
    for cat in cats[:3]:
        with ExecutionTime("query cat '%s'" % cat.name):
            docs = db.get_docs_from_query(cat.query)
            store.set_category_documents(cat, docs)

    # ok, this is confusing - the AppView contains the AppTreeView that
    #                         is a tree or list depending on the model
    from softwarecenter.ui.gtk3.views.appview import AppView
    app_view = AppView(db, cache, icons, show_ratings=True)
    app_view.set_model(store)

    box = Gtk.VBox()
    box.pack_start(app_view, True, True, 0)

    win = Gtk.Window()
    win.add(box)
    win.connect("destroy", lambda x: Gtk.main_quit())
    win.set_size_request(600, 400)
    win.show_all()

    return win
예제 #8
0
    def test_new_no_sort_info_yet(self):
        # ensure that we don't show a empty "whats new" category
        # see LP: #865985
        from softwarecenter.testutils import get_test_db
        db = get_test_db()
        cache = db._aptcache
        # simulate a fresh install with no catalogedtime info
        del db._axi_values["catalogedtime"]

        from softwarecenter.testutils import get_test_gtk3_icon_cache
        icons = get_test_gtk3_icon_cache()

        from softwarecenter.db.appfilter import AppFilter
        apps_filter = AppFilter(db, cache)

        from softwarecenter.distro import get_distro
        from softwarecenter.ui.gtk3.views.catview_gtk import LobbyViewGtk
        view = LobbyViewGtk(softwarecenter.paths.datadir,
                            softwarecenter.paths.APP_INSTALL_PATH, cache, db,
                            icons, get_distro(), apps_filter)
        view.show()

        # gui
        win = Gtk.Window()
        self.addCleanup(win.destroy)
        win.set_size_request(800, 400)

        scroll = Gtk.ScrolledWindow()
        scroll.add(view)
        scroll.show()
        win.add(scroll)
        win.show()
        # test visibility
        do_events()
        self.assertFalse(view.whats_new_frame.get_property("visible"))
예제 #9
0
def get_test_window_catview():
    def on_category_selected(view, cat):
        print("on_category_selected %s %s" % view, cat)

    from softwarecenter.db.pkginfo import get_pkg_info
    cache = get_pkg_info()
    cache.open()

    from softwarecenter.db.database import StoreDatabase
    xapian_base_path = "/var/cache/software-center"
    pathname = os.path.join(xapian_base_path, "xapian")
    db = StoreDatabase(pathname, cache)
    db.open()

    import softwarecenter.paths
    datadir = softwarecenter.paths.datadir

    from softwarecenter.ui.gtk3.utils import get_sc_icon_theme
    icons = get_sc_icon_theme(datadir)

    import softwarecenter.distro
    distro = softwarecenter.distro.get_distro()

    apps_filter = AppFilter(db, cache)

    # gui
    win = Gtk.Window()
    n = Gtk.Notebook()

    from softwarecenter.paths import APP_INSTALL_PATH
    view = LobbyViewGtk(datadir, APP_INSTALL_PATH, cache, db, icons, distro,
                        apps_filter)
    win.set_data("lobby", view)

    scroll = Gtk.ScrolledWindow()
    scroll.add(view)
    n.append_page(scroll, Gtk.Label(label="Lobby"))

    # find a cat in the LobbyView that has subcategories
    subcat_cat = None
    for cat in reversed(view.categories):
        if cat.subcategories:
            subcat_cat = cat
            break

    view = SubCategoryViewGtk(datadir, APP_INSTALL_PATH, cache, db, icons,
                              apps_filter)
    view.connect("category-selected", on_category_selected)
    view.set_subcategory(subcat_cat)
    win.set_data("subcat", view)

    scroll = Gtk.ScrolledWindow()
    scroll.add(view)
    n.append_page(scroll, Gtk.Label(label="Subcats"))

    win.add(n)
    win.set_size_request(800, 600)
    win.show_all()
    win.connect('destroy', Gtk.main_quit)
    return win
    def set_category(self, category):
        LOG.debug('set_category: %s' % category)
        self.state.category = category

        # apply flags
        if category:
            if 'nonapps-visible' in category.flags:
                self.nonapps_visible = NonAppVisibility.ALWAYS_VISIBLE
            else:
                self.nonapps_visible = NonAppVisibility.MAYBE_VISIBLE

        # apply any category based filters
        if not self.state.filter:
            self.state.filter = AppFilter(self.db, self.cache)

        if (category and category.flags
                and 'available-only' in category.flags):
            self.state.filter.set_available_only(True)
        else:
            self.state.filter.set_available_only(False)

        if (category and category.flags
                and 'not-installed-only' in category.flags):
            self.state.filter.set_not_installed_only(True)
        else:
            self.state.filter.set_not_installed_only(False)
예제 #11
0
def get_test_catview():
    def on_category_selected(view, cat):
        print("on_category_selected %s %s" % view, cat)

    from softwarecenter.db.pkginfo import get_pkg_info
    cache = get_pkg_info()
    cache.open()

    from softwarecenter.db.database import StoreDatabase
    xapian_base_path = "/var/cache/software-center"
    pathname = os.path.join(xapian_base_path, "xapian")
    db = StoreDatabase(pathname, cache)
    db.open()

    import softwarecenter.paths
    datadir = softwarecenter.paths.datadir

    from softwarecenter.ui.gtk3.utils import get_sc_icon_theme
    icons = get_sc_icon_theme(datadir)

    import softwarecenter.distro
    distro = softwarecenter.distro.get_distro()

    apps_filter = AppFilter(db, cache)

    from softwarecenter.paths import APP_INSTALL_PATH
    cat_view = LobbyViewGtk(datadir, APP_INSTALL_PATH, cache, db, icons,
                            distro, apps_filter)
    return cat_view
    def __init__(self, cache, db, distro, icons, datadir,
                 navhistory_back_action, navhistory_forward_action):
        # parent
        SoftwarePane.__init__(self, cache, db, distro, icons, datadir)
        self.searchentry.set_sensitive(False)
        # navigation history actions
        self.navhistory_back_action = navhistory_back_action
        self.navhistory_forward_action = navhistory_forward_action
        # configure any initial state attrs
        self.state.filter = AppFilter(db, cache)
        # the spec says we mix installed/not installed
        #self.apps_filter.set_not_installed_only(True)
        self.current_app_by_category = {}
        self.current_app_by_subcategory = {}
        self.pane_name = _("Get Software")

        # views to be created in init_view
        self.cat_view = None
        self.subcategories_view = None

        # integrate with the Unity launcher
        self.unity_launcher = UnityLauncher()
        # keep track of applications that are queued to be added
        # to the Unity launcher
        self.unity_launcher_transaction_queue = {}
        # flag to indicate whether applications should be added to the
        # unity launcher when installed (this value is initialized by
        # the config load in app.py)
        self.add_to_launcher_enabled = True
예제 #13
0
def get_test_window():
    import softwarecenter.log
    softwarecenter.log.root.setLevel(level=logging.DEBUG)
    softwarecenter.log.add_filters_from_string("performance")
    fmt = logging.Formatter("%(name)s - %(message)s", None)
    softwarecenter.log.handler.setFormatter(fmt)

    from softwarecenter.testutils import (
        get_test_db, get_test_pkg_info, get_test_gtk3_icon_cache)
    from softwarecenter.ui.gtk3.models.appstore2 import AppListStore

    db = get_test_db()
    cache = get_test_pkg_info()
    icons = get_test_gtk3_icon_cache()

    # create a filter
    from softwarecenter.db.appfilter import AppFilter
    filter = AppFilter(db, cache)
    filter.set_supported_only(False)
    filter.set_installed_only(True)

    # appview
    from softwarecenter.db.enquire import AppEnquire
    enquirer = AppEnquire(cache, db)
    store = AppListStore(db, cache, icons)

    from softwarecenter.ui.gtk3.views.appview import AppView
    view = AppView(db, cache, icons, show_ratings=True)
    view.set_model(store)

    entry = Gtk.Entry()
    entry.stamp = 0
    entry.connect("changed", on_entry_changed, (view, enquirer))

    box = Gtk.VBox()
    box.pack_start(entry, False, True, 0)
    box.pack_start(view, True, True, 0)

    win = Gtk.Window()
    win.set_data("appview", view)
    win.set_data("entry", entry)
    win.connect("destroy", lambda x: Gtk.main_quit())
    win.add(box)
    win.set_size_request(600, 400)
    win.show_all()

    return win
예제 #14
0
 def _ceibal_get_docs(self):
     """ return the database docids for the given category """
     enq = AppEnquire(self.db._aptcache, self.db)
     app_filter = AppFilter(self.db, self.db._aptcache)
     
     app_filter.set_available_only(True)
     #app_filter.set_not_installed_only(True)
     p = "http://apt.ceibal.edu.uy/recommendations/list.json"
     data = json.load(urllib2.urlopen(p))
     query = get_query_for_pkgnames(data['packages']) 
     enq.set_query(query,
                   limit=20,
                   filter=app_filter,
                   sortmode=0,
                   nonapps_visible=NonAppVisibility.ALWAYS_VISIBLE,
                   nonblocking_load=False)
     return enq.get_documents()
예제 #15
0
파일: catview.py 프로젝트: sti-lyneos/shop
 def _get_sub_top_rated_content(self, category):
     app_filter = AppFilter(self.db, self.cache)
     self.enquire.set_query(category.query,
                            limit=TOP_RATED_CAROUSEL_LIMIT,
                            sortmode=SortMethods.BY_TOP_RATED,
                            filter=app_filter,
                            nonapps_visible=NonAppVisibility.ALWAYS_VISIBLE,
                            nonblocking_load=False)
     return self.enquire.get_documents()
예제 #16
0
def get_test_window():
    import softwarecenter.log
    softwarecenter.log.root.setLevel(level=logging.DEBUG)
    softwarecenter.log.add_filters_from_string("performance")
    fmt = logging.Formatter("%(name)s - %(message)s", None)
    softwarecenter.log.handler.setFormatter(fmt)

    from softwarecenter.paths import XAPIAN_BASE_PATH
    xapian_base_path = XAPIAN_BASE_PATH
    pathname = os.path.join(xapian_base_path, "xapian")

    # the store
    from softwarecenter.db.pkginfo import get_pkg_info
    cache = get_pkg_info()
    cache.open()

    # the db
    from softwarecenter.db.database import StoreDatabase
    db = StoreDatabase(pathname, cache)
    db.open()

    # additional icons come from app-install-data
    icons = Gtk.IconTheme.get_default()
    icons.prepend_search_path("/usr/share/app-install/icons/")
    icons.prepend_search_path("/usr/share/software-center/icons/")

    # create a filter
    from softwarecenter.db.appfilter import AppFilter
    filter = AppFilter(db, cache)
    filter.set_supported_only(False)
    filter.set_installed_only(True)

    # appview
    from softwarecenter.ui.gtk3.models.appstore2 import AppListStore
    from softwarecenter.db.enquire import AppEnquire
    enquirer = AppEnquire(cache, db)
    store = AppListStore(db, cache, icons)

    from softwarecenter.ui.gtk3.views.appview import AppView
    view = AppView(db, cache, icons, show_ratings=True)
    view.set_model(store)

    entry = Gtk.Entry()
    entry.stamp = 0
    entry.connect("changed", on_entry_changed, (view, enquirer))
    entry.set_text("gtk3")

    scroll = Gtk.ScrolledWindow()
    box = Gtk.VBox()
    box.pack_start(entry, False, True, 0)
    box.pack_start(scroll, True, True, 0)

    win = Gtk.Window()
    win.connect("destroy", lambda x: Gtk.main_quit())
    scroll.add(view)
    win.add(box)
    win.set_size_request(600, 400)
    win.show_all()

    return win
예제 #17
0
    def _get_new_category_content(self):
        whatsnew_cat = get_category_by_name(self.categories, 
                                            u"What\u2019s New") # unstranslated name
        if whatsnew_cat is None:
            LOG.warn("No 'new' category found!!")
            return None, []

        enq = AppEnquire(self.cache, self.db)
        app_filter = AppFilter(self.db, self.cache)
        app_filter.set_available_only(True)
        app_filter.set_not_installed_only(True)
        enq.set_query(whatsnew_cat.query,
                      limit=8,
                      filter=app_filter,
                      sortmode=SortMethods.BY_CATALOGED_TIME,
                      nonapps_visible=NonAppVisibility.ALWAYS_VISIBLE,
                      nonblocking_load=False)

        if not hasattr(self, "helper"):
            self.helper = AppPropertiesHelper(self.db,
                                              self.cache,
                                              self.icons)

        return whatsnew_cat, enq.get_documents()
예제 #18
0
파일: catview.py 프로젝트: sti-lyneos/shop
    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
예제 #19
0
    def __init__(self, cache, db, distro, icons, datadir,
                 navhistory_back_action, navhistory_forward_action):
        # parent
        SoftwarePane.__init__(self, cache, db, distro, icons, datadir)
        self.searchentry.set_sensitive(False)
        # navigation history actions
        self.navhistory_back_action = navhistory_back_action
        self.navhistory_forward_action = navhistory_forward_action
        # configure any initial state attrs
        self.state.filter = AppFilter(db, cache)
        # the spec says we mix installed/not installed
        #self.apps_filter.set_not_installed_only(True)
        self.current_app_by_category = {}
        self.current_app_by_subcategory = {}
        self.pane_name = _("Get Software")

        # views to be created in init_view
        self.cat_view = None
        self.subcategories_view = None
예제 #20
0
    def _get_toprated_category_content(self):
        toprated_cat = get_category_by_name(self.categories,
                                            u"Top Rated")  # unstranslated name
        if toprated_cat is None:
            LOG.warn("No 'toprated' category found!!")
            return None, []

        enq = AppEnquire(self.cache, self.db)
        app_filter = AppFilter(self.db, self.cache)
        enq.set_query(toprated_cat.query,
                      limit=TOP_RATED_CAROUSEL_LIMIT,
                      sortmode=toprated_cat.sortmode,
                      filter=app_filter,
                      nonapps_visible=NonAppVisibility.ALWAYS_VISIBLE,
                      nonblocking_load=False)

        if not hasattr(self, "helper"):
            self.helper = AppPropertiesHelper(self.db, self.cache, self.icons)

        return toprated_cat, enq.get_documents()
예제 #21
0
 def get_documents(self, db):
     """ return the database docids for the given category """
     enq = AppEnquire(db._aptcache, db)
     app_filter = AppFilter(db, db._aptcache)
     if "available-only" in self.flags:
         app_filter.set_available_only(True)
     if "not-installed-only" in self.flags:
         app_filter.set_not_installed_only(True)
     enq.set_query(self.query,
                   limit=self.item_limit,
                   filter=app_filter,
                   sortmode=self.sortmode,
                   nonapps_visible=NonAppVisibility.ALWAYS_VISIBLE,
                   nonblocking_load=False)
     return enq.get_documents()
    def test_app_enquire(self):
        db = get_test_db()
        cache = get_test_pkg_info()

        xfilter = AppFilter(cache, db)
        enquirer = AppEnquire(cache, db)
        terms = [
            "app", "this", "the", "that", "foo", "tool", "game", "graphic",
            "ubuntu", "debian", "gtk", "this", "bar", "baz"
        ]

        # run a bunch of the querries in parallel
        for nonblocking in [False, True]:
            for i in range(10):
                for term in terms:
                    enquirer.set_query(search_query=xapian.Query(term),
                                       limit=0,
                                       filter=xfilter,
                                       nonblocking_load=nonblocking)
        # give the threads a bit of time
        time.sleep(5)
예제 #23
0
def get_test_window():
    import softwarecenter.log
    softwarecenter.log.root.setLevel(level=logging.DEBUG)
    softwarecenter.log.add_filters_from_string("performance")
    fmt = logging.Formatter("%(name)s - %(message)s", None)
    softwarecenter.log.handler.setFormatter(fmt)

    from softwarecenter.testutils import (get_test_db, get_test_pkg_info,
                                          get_test_gtk3_icon_cache,
                                          get_test_categories)

    cache = get_test_pkg_info()
    db = get_test_db()
    icons = get_test_gtk3_icon_cache()

    # create a filter
    from softwarecenter.db.appfilter import AppFilter
    filter = AppFilter(db, cache)
    filter.set_supported_only(False)
    filter.set_installed_only(True)

    # get the TREEstore
    from softwarecenter.ui.gtk3.models.appstore2 import AppTreeStore
    store = AppTreeStore(db, cache, icons)

    # populate from data
    cats = get_test_categories(db)
    for cat in cats[:3]:
        with ExecutionTime("query cat '%s'" % cat.name):
            docs = db.get_docs_from_query(cat.query)
            store.set_category_documents(cat, docs)

    # ok, this is confusing - the AppView contains the AppTreeView that
    #                         is a tree or list depending on the model
    from softwarecenter.ui.gtk3.views.appview import AppView
    app_view = AppView(db, cache, icons, show_ratings=True)
    app_view.set_model(store)

    box = Gtk.VBox()
    box.pack_start(app_view, True, True, 0)

    win = Gtk.Window()
    win.add(box)
    win.connect("destroy", lambda x: Gtk.main_quit())
    win.set_size_request(600, 400)
    win.show_all()

    return win
def get_test_window():
    import softwarecenter.log
    softwarecenter.log.root.setLevel(level=logging.DEBUG)
    softwarecenter.log.add_filters_from_string("performance")
    fmt = logging.Formatter("%(name)s - %(message)s", None)
    softwarecenter.log.handler.setFormatter(fmt)

    from softwarecenter.testutils import (get_test_db, get_test_pkg_info,
                                          get_test_gtk3_icon_cache)
    from softwarecenter.ui.gtk3.models.appstore2 import AppListStore

    db = get_test_db()
    cache = get_test_pkg_info()
    icons = get_test_gtk3_icon_cache()

    # create a filter
    from softwarecenter.db.appfilter import AppFilter
    filter = AppFilter(db, cache)
    filter.set_supported_only(False)
    filter.set_installed_only(True)

    # appview
    from softwarecenter.db.enquire import AppEnquire
    enquirer = AppEnquire(cache, db)
    store = AppListStore(db, cache, icons)

    from softwarecenter.ui.gtk3.views.appview import AppView
    view = AppView(db, cache, icons, show_ratings=True)
    view.set_model(store)

    entry = Gtk.Entry()
    entry.stamp = 0
    entry.connect("changed", on_entry_changed, (view, enquirer))

    box = Gtk.VBox()
    box.pack_start(entry, False, True, 0)
    box.pack_start(view, True, True, 0)

    win = Gtk.Window()
    win.set_data("appview", view)
    win.set_data("entry", entry)
    win.connect("destroy", lambda x: Gtk.main_quit())
    win.add(box)
    win.set_size_request(600, 400)
    win.show_all()

    return win
예제 #25
0
    def _get_new_category_content(self):
        whatsnew_cat = get_category_by_name(
            self.categories, u"What\u2019s New")  # unstranslated name
        if whatsnew_cat is None:
            LOG.warn("No 'new' category found!!")
            return None, []

        enq = AppEnquire(self.cache, self.db)
        app_filter = AppFilter(self.db, self.cache)
        app_filter.set_available_only(True)
        app_filter.set_not_installed_only(True)
        enq.set_query(whatsnew_cat.query,
                      limit=8,
                      filter=app_filter,
                      sortmode=SortMethods.BY_CATALOGED_TIME,
                      nonapps_visible=NonAppVisibility.ALWAYS_VISIBLE,
                      nonblocking_load=False)

        if not hasattr(self, "helper"):
            self.helper = AppPropertiesHelper(self.db, self.cache, self.icons)

        return whatsnew_cat, enq.get_documents()
예제 #26
0
        def rebuild_oneconfview():

            # FIXME for P: hide the search entry
            self.searchentry.hide()

            self.cat_docid_map = {}
            enq = self.enquirer
            query = xapian.Query("")
            if self.state.channel and self.state.channel.query:
                query = xapian.Query(xapian.Query.OP_AND, query,
                                     self.state.channel.query)

            i = 0

            # First search: missing apps only
            xfilter = AppFilter(self.db, self.cache)
            xfilter.set_restricted_list(self.oneconf_additional_pkg)
            xfilter.set_not_installed_only(True)

            enq.set_query(
                query,
                sortmode=SortMethods.BY_ALPHABET,
                nonapps_visible=self.nonapps_visible,
                filter=xfilter,
                nonblocking_load=True,  # we don't block this one for
                # better oneconf responsiveness
                persistent_duplicate_filter=(i > 0))

            L = len(enq.matches)

            if L:
                cat_title = utf8(
                    ngettext(
                        u'%(amount)s item on “%(machine)s” not on this computer',
                        u'%(amount)s items on “%(machine)s” not on this computer',
                        L)) % {
                            'amount': L,
                            'machine': utf8(self.current_hostname)
                        }
                i += L
                docs = enq.get_documents()
                self.cat_docid_map["missingpkg"] = set(
                    [doc.get_docid() for doc in docs])
                model.set_nocategory_documents(
                    docs,
                    untranslated_name="additionalpkg",
                    display_name=cat_title)

            # Second search: additional apps
            xfilter.set_restricted_list(self.oneconf_missing_pkg)
            xfilter.set_not_installed_only(False)
            xfilter.set_installed_only(True)
            enq.set_query(query,
                          sortmode=SortMethods.BY_ALPHABET,
                          nonapps_visible=self.nonapps_visible,
                          filter=xfilter,
                          nonblocking_load=False,
                          persistent_duplicate_filter=(i > 0))

            L = len(enq.matches)
            if L:
                cat_title = utf8(
                    ngettext(
                        u'%(amount)s item on this computer not on “%(machine)s”',
                        '%(amount)s items on this computer not on “%(machine)s”',
                        L)) % {
                            'amount': L,
                            'machine': utf8(self.current_hostname)
                        }
                i += L
                docs = enq.get_documents()
                self.cat_docid_map["additionalpkg"] = set(
                    [doc.get_docid() for doc in docs])
                model.set_nocategory_documents(
                    docs,
                    untranslated_name="additionalpkg",
                    display_name=cat_title)

            if i:
                self.app_view.tree_view.set_cursor(Gtk.TreePath(), None, False)
                if i <= 10:
                    self.app_view.tree_view.expand_all()

            # cache the installed app count
            self.installed_count = i
            self.app_view._append_appcount(self.installed_count,
                                           mode=AppView.DIFF_MODE)

            self.app_view.set_model(self.treefilter)
            if keep_state:
                self._restore_treeview_state(treeview_state)

            # hide the local spinner
            self.hide_installed_view_spinner()

            if window:
                window.set_cursor(None)

            self.emit("app-list-changed", i)
            return
예제 #27
0
        def rebuild_oneconfview():

            # FIXME for P: hide the search entry
            self.searchentry.hide()

            self.cat_docid_map = {}
            enq = self.enquirer
            query = xapian.Query("")
            if self.state.channel and self.state.channel.query:
                query = xapian.Query(xapian.Query.OP_AND, query, self.state.channel.query)

            i = 0

            # First search: missing apps only
            xfilter = AppFilter(self.db, self.cache)
            xfilter.set_restricted_list(self.oneconf_additional_pkg)
            xfilter.set_not_installed_only(True)

            enq.set_query(
                query,
                sortmode=SortMethods.BY_ALPHABET,
                nonapps_visible=self.nonapps_visible,
                filter=xfilter,
                nonblocking_load=True,  # we don't block this one for
                # better oneconf responsiveness
                persistent_duplicate_filter=(i > 0),
            )

            L = len(enq.matches)

            if L:
                cat_title = utf8(
                    ngettext(
                        u"%(amount)s item on “%(machine)s” not on this computer",
                        u"%(amount)s items on “%(machine)s” not on this computer",
                        L,
                    )
                ) % {"amount": L, "machine": utf8(self.current_hostname)}
                i += L
                docs = enq.get_documents()
                self.cat_docid_map["missingpkg"] = set([doc.get_docid() for doc in docs])
                model.set_nocategory_documents(docs, untranslated_name="additionalpkg", display_name=cat_title)

            # Second search: additional apps
            xfilter.set_restricted_list(self.oneconf_missing_pkg)
            xfilter.set_not_installed_only(False)
            xfilter.set_installed_only(True)
            enq.set_query(
                query,
                sortmode=SortMethods.BY_ALPHABET,
                nonapps_visible=self.nonapps_visible,
                filter=xfilter,
                nonblocking_load=False,
                persistent_duplicate_filter=(i > 0),
            )

            L = len(enq.matches)
            if L:
                cat_title = utf8(
                    ngettext(
                        u"%(amount)s item on this computer not on “%(machine)s”",
                        "%(amount)s items on this computer not on “%(machine)s”",
                        L,
                    )
                ) % {"amount": L, "machine": utf8(self.current_hostname)}
                i += L
                docs = enq.get_documents()
                self.cat_docid_map["additionalpkg"] = set([doc.get_docid() for doc in docs])
                model.set_nocategory_documents(docs, untranslated_name="additionalpkg", display_name=cat_title)

            if i:
                self.app_view.tree_view.set_cursor(Gtk.TreePath(), None, False)
                if i <= 10:
                    self.app_view.tree_view.expand_all()

            # cache the installed app count
            self.installed_count = i
            self.app_view._append_appcount(self.installed_count, mode=AppView.DIFF_MODE)

            self.app_view.set_model(self.treefilter)
            if keep_state:
                self._restore_treeview_state(treeview_state)

            # hide the local spinner
            self.hide_installed_view_spinner()

            if window:
                window.set_cursor(None)

            self.emit("app-list-changed", i)
            return
예제 #28
0
        def rebuild_categorised_view():
            self.cat_docid_map = {}
            enq = self.enquirer

            i = 0

            while Gtk.events_pending():
                Gtk.main_iteration()

            xfilter = AppFilter(self.db, self.cache)
            xfilter.set_installed_only(True)

            for cat in self._all_cats:
                # for each category do category query and append as a new
                # node to tree_view
                if not self._use_category(cat):
                    continue
                query = self.get_query_for_cat(cat)
                LOG.debug("xfilter.installed_only: %s" % xfilter.installed_only)
                enq.set_query(
                    query,
                    sortmode=SortMethods.BY_ALPHABET,
                    nonapps_visible=self.nonapps_visible,
                    filter=xfilter,
                    nonblocking_load=False,
                    persistent_duplicate_filter=(i > 0),
                )

                L = len(enq.matches)
                if L:
                    i += L
                    docs = enq.get_documents()
                    self.cat_docid_map[cat.untranslated_name] = set([doc.get_docid() for doc in docs])
                    model.set_category_documents(cat, docs)

            while Gtk.events_pending():
                Gtk.main_iteration()

            # check for uncategorised pkgs
            if self.state.channel:
                self._run_channel_enquirer(persistent_duplicate_filter=(i > 0))
                L = len(enq.matches)
                if L:
                    # some foo for channels
                    # if no categorised results but in channel, then use
                    # the channel name for the category
                    channel_name = None
                    if not i and self.state.channel:
                        channel_name = self.state.channel.display_name
                    docs = enq.get_documents()
                    tag = channel_name or "Uncategorized"
                    self.cat_docid_map[tag] = set([doc.get_docid() for doc in docs])
                    model.set_nocategory_documents(docs, untranslated_name=tag, display_name=channel_name)
                    i += L

            if i:
                self.app_view.tree_view.set_cursor(Gtk.TreePath(), None, False)
                if i <= 10:
                    self.app_view.tree_view.expand_all()

            # cache the installed app count
            self.installed_count = i
            self.app_view._append_appcount(self.installed_count, mode=AppView.INSTALLED_MODE)

            self.app_view.set_model(self.treefilter)
            if keep_state:
                self._restore_treeview_state(treeview_state)

            # hide the local spinner
            self.hide_installed_view_spinner()

            if window:
                window.set_cursor(None)

            # reapply search if needed
            if self.state.search_term:
                self._do_search(self.state.search_term)

            self.emit("app-list-changed", i)
            return
예제 #29
0
        def rebuild_categorised_view():
            self.cat_docid_map = {}
            enq = self.enquirer

            i = 0

            while Gtk.events_pending():
                Gtk.main_iteration()

            xfilter = AppFilter(self.db, self.cache)
            xfilter.set_installed_only(True)

            for cat in self._all_cats:
                # for each category do category query and append as a new
                # node to tree_view
                if not self._use_category(cat):
                    continue
                query = self.get_query_for_cat(cat)
                LOG.debug("xfilter.installed_only: %s" %
                          xfilter.installed_only)
                enq.set_query(query,
                              sortmode=SortMethods.BY_ALPHABET,
                              nonapps_visible=self.nonapps_visible,
                              filter=xfilter,
                              nonblocking_load=False,
                              persistent_duplicate_filter=(i > 0))

                L = len(enq.matches)
                if L:
                    i += L
                    docs = enq.get_documents()
                    self.cat_docid_map[cat.untranslated_name] = \
                                        set([doc.get_docid() for doc in docs])
                    model.set_category_documents(cat, docs)

            while Gtk.events_pending():
                Gtk.main_iteration()

            # check for uncategorised pkgs
            if self.state.channel:
                self._run_channel_enquirer(persistent_duplicate_filter=(i > 0))
                L = len(enq.matches)
                if L:
                    # some foo for channels
                    # if no categorised results but in channel, then use
                    # the channel name for the category
                    channel_name = None
                    if not i and self.state.channel:
                        channel_name = self.state.channel.display_name
                    docs = enq.get_documents()
                    tag = channel_name or 'Uncategorized'
                    self.cat_docid_map[tag] = set(
                        [doc.get_docid() for doc in docs])
                    model.set_nocategory_documents(docs,
                                                   untranslated_name=tag,
                                                   display_name=channel_name)
                    i += L

            if i:
                self.app_view.tree_view.set_cursor(Gtk.TreePath(), None, False)
                if i <= 10:
                    self.app_view.tree_view.expand_all()

            # cache the installed app count
            self.installed_count = i
            self.app_view._append_appcount(self.installed_count,
                                           mode=AppView.INSTALLED_MODE)

            self.app_view.set_model(self.treefilter)
            if keep_state:
                self._restore_treeview_state(treeview_state)

            # hide the local spinner
            self.hide_installed_view_spinner()

            if window:
                window.set_cursor(None)

            # reapply search if needed
            if self.state.search_term:
                self._do_search(self.state.search_term)

            self.emit("app-list-changed", i)
            return