def test_get_appmanager(self): app_manager = get_appmanager() self.assertNotEqual(app_manager, None) # test singleton app_manager2 = get_appmanager() self.assertEqual(app_manager, app_manager2) # test creating it twice raises a error self.assertRaises( ValueError, ApplicationManager, self.db, self.backend, self.icons)
def test_get_appmanager(self): app_manager = get_appmanager() self.assertNotEqual(app_manager, None) # test singleton app_manager2 = get_appmanager() self.assertEqual(app_manager, app_manager2) # test creating it twice raises a error self.assertRaises(ValueError, ApplicationManager, self.db, self.backend, self.icons)
def test_appmanager(self): app_manager = get_appmanager() self.assertNotEqual(app_manager, None) # test interface app_manager.reload() app = Application("", "2vcard") # call and ensure the stuff is passed to the backend app_manager.install(app, [], []) self.assertTrue(self.backend.install.called) app_manager.remove(app, [], []) self.assertTrue(self.backend.remove.called) app_manager.upgrade(app, [], []) self.assertTrue(self.backend.upgrade.called) app_manager.apply_changes(app, [], []) self.assertTrue(self.backend.apply_changes.called) app_manager.enable_software_source(app) self.assertTrue(self.backend.enable_component.called) app_manager.reinstall_purchased(app) self.assertTrue(self.backend.add_repo_add_key_and_install_app.called) # buy is special as it needs help from the purchase view app_manager.connect("purchase-requested", self._on_purchase_requested) app_manager.buy_app(app) self.assertTrue(self._purchase_requested_signal) do_events()
def get_test_window_availablepane(): # needed because available pane will try to get it vm = get_test_gtk3_viewmanager() assert vm is not None db = get_test_db() cache = get_test_pkg_info() icons = get_test_gtk3_icon_cache() backend = get_test_install_backend() distro = softwarecenter.distro.get_distro() manager = appmanager.get_appmanager() if manager is None: # create global AppManager instance manager = appmanager.ApplicationManager(db, backend, icons) navhistory_back_action = Gtk.Action.new("navhistory_back_action", "Back", "Back", None) navhistory_forward_action = Gtk.Action.new("navhistory_forward_action", "Forward", "Forward", None) zl = "softwarecenter.backend.zeitgeist_logger.ZeitgeistLogger"; patch(zl + ".log_install_event").start().return_value = False patch(zl + ".log_uninstall_event").start().return_value = False patch("softwarecenter.utils.is_unity_running").start().return_value = False w = availablepane.AvailablePane(cache, db, distro, icons, navhistory_back_action, navhistory_forward_action) w.init_view() w.show() win = get_test_window(child=w, width=800, height=600) # this is used later in tests win.set_data("pane", w) win.set_data("vm", vm) return win
def setUp(self): # get required test stuff self.db = get_test_db() self.backend = Mock() self.distro = get_distro() self.datadir = softwarecenter.paths.datadir self.icons = get_test_gtk3_icon_cache() # create it once, it becomes global instance if get_appmanager() is None: ApplicationManager(self.db, self.backend, self.icons)
def setUp(self): # get required test stuff self.db = get_test_db() self.backend = Mock() self.distro = get_distro() self.datadir = softwarecenter.paths.datadir self.icons = get_test_gtk3_icon_cache() # create it once, it becomes global instance if get_appmanager() is None: ApplicationManager( self.db, self.backend, self.icons)
def _app_activated_cb(self, btn, btn_id, app, store, path): if self.rowref_is_category(app): return # FIXME: would be nice if that would be more elegant # because we use a treefilter we need to get the "real" # model first if type(store) is Gtk.TreeModelFilter: store = store.get_model() pkgname = self.appmodel.get_pkgname(app) if btn_id == CellButtonIDs.INFO: self.app_view.emit("application-activated", self.appmodel.get_application(app)) elif btn_id == CellButtonIDs.ACTION: btn.set_sensitive(False) store.row_changed(path, store.get_iter(path)) app_manager = get_appmanager() # be sure we dont request an action for a pkg with # pre-existing actions if pkgname in self._action_block_list: logging.debug("Action already in progress for package:" " '%s'" % pkgname) return False self._action_block_list.append(pkgname) if self.appmodel.is_installed(app): action = AppActions.REMOVE elif self.appmodel.is_purchasable(app): app_manager.buy_app(self.appmodel.get_application(app)) store.notify_action_request(app, path) return else: action = AppActions.INSTALL store.notify_action_request(app, path) app_manager.request_action( self.appmodel.get_application(app), [], [], action) return False
def _app_activated_cb(self, btn, btn_id, app, store, path): if self.rowref_is_category(app): return # FIXME: would be nice if that would be more elegant # because we use a treefilter we need to get the "real" # model first if type(store) is Gtk.TreeModelFilter: store = store.get_model() pkgname = self.appmodel.get_pkgname(app) if btn_id == CellButtonIDs.INFO: self.app_view.emit("application-activated", self.appmodel.get_application(app)) elif btn_id == CellButtonIDs.ACTION: btn.set_sensitive(False) store.row_changed(path, store.get_iter(path)) app_manager = get_appmanager() # be sure we dont request an action for a pkg with # pre-existing actions if pkgname in self._action_block_list: logging.debug("Action already in progress for package:" " '%s'" % pkgname) return False self._action_block_list.append(pkgname) if self.appmodel.is_installed(app): action = AppActions.REMOVE elif self.appmodel.is_purchasable(app): app_manager.buy_app(self.appmodel.get_application(app)) store.notify_action_request(app, path) return else: action = AppActions.INSTALL store.notify_action_request(app, path) app_manager.request_action(self.appmodel.get_application(app), [], [], action) return False
def _app_activated_cb(self, btn, btn_id, app, path): if self.rowref_is_category(app): return model = self.appmodel # don't continue if we don't have a valid model (LP: #969907) if not model: return pkgname = model.get_pkgname(app) if btn_id == CellButtonIDs.INFO: self.app_view.emit("application-activated", model.get_application(app)) elif btn_id == CellButtonIDs.ACTION: btn.set_sensitive(False) model.row_changed(path, model.get_iter(path)) app_manager = get_appmanager() # be sure we don't request an action for a pkg with # pre-existing actions if pkgname in self._action_block_list: logging.debug("Action already in progress for package:" " '%s'" % pkgname) return False self._action_block_list.append(pkgname) if model.is_installed(app): action = AppActions.REMOVE elif model.is_purchasable(app): app_manager.buy_app(model.get_application(app)) model.notify_action_request(app, path) return else: action = AppActions.INSTALL model.notify_action_request(app, path) app_manager.request_action( model.get_application(app), [], [], action) return False
def _app_activated_cb(self, btn, btn_id, app, path): if self.rowref_is_category(app): return model = self.appmodel # don't continue if we don't have a valid model (LP: #969907) if not model: return pkgname = model.get_pkgname(app) if btn_id == CellButtonIDs.INFO: self.app_view.emit("application-activated", model.get_application(app)) elif btn_id == CellButtonIDs.ACTION: btn.set_sensitive(False) model.row_changed(path, model.get_iter(path)) app_manager = get_appmanager() # be sure we dont request an action for a pkg with # pre-existing actions if pkgname in self._action_block_list: logging.debug("Action already in progress for package:" " '%s'" % pkgname) return False self._action_block_list.append(pkgname) if model.is_installed(app): action = AppActions.REMOVE elif model.is_purchasable(app): app_manager.buy_app(model.get_application(app)) model.notify_action_request(app, path) return else: action = AppActions.INSTALL model.notify_action_request(app, path) app_manager.request_action(model.get_application(app), [], [], action) return False
def init_view(self): if self.view_initialized: return self.show_appview_spinner() window = self.get_window() if window is not None: window.set_cursor(self.busy_cursor) while Gtk.events_pending(): Gtk.main_iteration() SoftwarePane.init_view(self) # set the AppTreeView model, available pane uses list models liststore = AppListStore(self.db, self.cache, self.icons) #~ def on_appcount_changed(widget, appcount): #~ self.subcategories_view._append_appcount(appcount) #~ self.app_view._append_appcount(appcount) #~ liststore.connect('appcount-changed', on_appcount_changed) self.app_view.set_model(liststore) liststore.connect("needs-refresh", lambda helper, pkgname: self.app_view.queue_draw()) # purchase view self.purchase_view = PurchaseView() app_manager = get_appmanager() app_manager.connect("purchase-requested", self.on_purchase_requested) self.purchase_view.connect("purchase-succeeded", self.on_purchase_succeeded) self.purchase_view.connect("purchase-failed", self.on_purchase_failed) self.purchase_view.connect("purchase-cancelled-by-user", self.on_purchase_cancelled_by_user) self.purchase_view.connect("terms-of-service-declined", self.on_terms_of_service_declined) self.purchase_view.connect("purchase-needs-spinner", self.on_purchase_needs_spinner) # categories, appview and details into the notebook in the bottom self.scroll_categories = Gtk.ScrolledWindow() self.scroll_categories.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.cat_view = LobbyViewGtk(self.datadir, APP_INSTALL_PATH, self.cache, self.db, self.icons, self.apps_filter) self.scroll_categories.add(self.cat_view) self.notebook.append_page(self.scroll_categories, Gtk.Label(label="categories")) # sub-categories view self.subcategories_view = SubCategoryViewGtk( self.datadir, APP_INSTALL_PATH, self.cache, self.db, self.icons, self.apps_filter, root_category=self.cat_view.categories[0]) self.subcategories_view.connect("category-selected", self.on_subcategory_activated) self.subcategories_view.connect("application-activated", self.on_application_activated) self.subcategories_view.connect("show-category-applist", self.on_show_category_applist) # FIXME: why do we have two application-{selected,activated] ?!? self.subcategories_view.connect("application-selected", self.on_application_selected) self.subcategories_view.connect("application-activated", self.on_application_activated) self.scroll_subcategories = Gtk.ScrolledWindow() self.scroll_subcategories.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.scroll_subcategories.add(self.subcategories_view) self.notebook.append_page(self.scroll_subcategories, Gtk.Label(label=NavButtons.SUBCAT)) # app list self.notebook.append_page(self.box_app_list, Gtk.Label(label=NavButtons.LIST)) self.cat_view.connect("category-selected", self.on_category_activated) self.cat_view.connect("application-selected", self.on_application_selected) self.cat_view.connect("application-activated", self.on_application_activated) # details self.notebook.append_page(self.scroll_details, Gtk.Label(label=NavButtons.DETAILS)) # purchase view self.notebook.append_page(self.purchase_view, Gtk.Label(label=NavButtons.PURCHASE)) # install backend self.backend.connect("transaction-started", self.on_transaction_started) self.backend.connect("transactions-changed", self.on_transactions_changed) self.backend.connect("transaction-finished", self.on_transaction_complete) self.backend.connect("transaction-cancelled", self.on_transaction_cancelled) # a transaction error is treated the same as a cancellation self.backend.connect("transaction-stopped", self.on_transaction_cancelled) # now we are initialized self.searchentry.set_sensitive(True) self.emit("available-pane-created") self.show_all() self.hide_appview_spinner() # consider the view initialized here already as display_page() # may run into a endless recurison otherwise (it will call init_view()) # again (LP: #851671) self.view_initialized = True # important to "seed" the initial history stack (LP: #1005104) vm = get_viewmanager() vm.display_page(self, AvailablePane.Pages.LOBBY, self.state, self.display_lobby_page) if window is not None: window.set_cursor(None)
def init_view(self): if self.view_initialized: return self.show_appview_spinner() window = self.get_window() if window is not None: window.set_cursor(self.busy_cursor) while Gtk.events_pending(): Gtk.main_iteration() SoftwarePane.init_view(self) # set the AppTreeView model, available pane uses list models liststore = AppListStore(self.db, self.cache, self.icons) #~ def on_appcount_changed(widget, appcount): #~ self.subcategories_view._append_appcount(appcount) #~ self.app_view._append_appcount(appcount) #~ liststore.connect('appcount-changed', on_appcount_changed) self.app_view.set_model(liststore) liststore.connect("needs-refresh", lambda helper, pkgname: self.app_view.queue_draw()) # purchase view self.purchase_view = PurchaseView() app_manager = get_appmanager() app_manager.connect("purchase-requested", self.on_purchase_requested) self.purchase_view.connect("purchase-succeeded", self.on_purchase_succeeded) self.purchase_view.connect("purchase-failed", self.on_purchase_failed) self.purchase_view.connect("purchase-cancelled-by-user", self.on_purchase_cancelled_by_user) self.purchase_view.connect("terms-of-service-declined", self.on_terms_of_service_declined) self.purchase_view.connect("purchase-needs-spinner", self.on_purchase_needs_spinner) # categories, appview and details into the notebook in the bottom self.scroll_categories = Gtk.ScrolledWindow() self.scroll_categories.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.cat_view = LobbyViewGtk(self.datadir, APP_INSTALL_PATH, self.cache, self.db, self.icons, self.apps_filter) self.scroll_categories.add(self.cat_view) self.notebook.append_page(self.scroll_categories, Gtk.Label(label="categories")) # sub-categories view self.subcategories_view = SubCategoryViewGtk(self.datadir, APP_INSTALL_PATH, self.cache, self.db, self.icons, self.apps_filter, root_category=self.cat_view.categories[0]) self.subcategories_view.connect( "category-selected", self.on_subcategory_activated) self.subcategories_view.connect( "application-activated", self.on_application_activated) self.subcategories_view.connect( "show-category-applist", self.on_show_category_applist) # FIXME: why do we have two application-{selected,activated] ?!? self.subcategories_view.connect( "application-selected", self.on_application_selected) self.subcategories_view.connect( "application-activated", self.on_application_activated) self.scroll_subcategories = Gtk.ScrolledWindow() self.scroll_subcategories.set_policy( Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC) self.scroll_subcategories.add(self.subcategories_view) self.notebook.append_page(self.scroll_subcategories, Gtk.Label(label=NavButtons.SUBCAT)) # app list self.notebook.append_page(self.box_app_list, Gtk.Label(label=NavButtons.LIST)) self.cat_view.connect( "category-selected", self.on_category_activated) self.cat_view.connect( "application-selected", self.on_application_selected) self.cat_view.connect( "application-activated", self.on_application_activated) # details self.notebook.append_page(self.scroll_details, Gtk.Label(label=NavButtons.DETAILS)) # purchase view self.notebook.append_page(self.purchase_view, Gtk.Label(label=NavButtons.PURCHASE)) # install backend self.backend.connect("transaction-started", self.on_transaction_started) self.backend.connect("transactions-changed", self.on_transactions_changed) self.backend.connect("transaction-finished", self.on_transaction_complete) self.backend.connect("transaction-stopped", self.on_transaction_complete) # now we are initialized self.searchentry.set_sensitive(True) self.emit("available-pane-created") self.show_all() self.hide_appview_spinner() # consider the view initialized here already as display_page() # may run into a endless recurison otherwise (it will call init_view()) # again (LP: #851671) self.view_initialized = True if window is not None: window.set_cursor(None)