def __init__(self, activity_info): ActivityPalette.__init__(self, activity_info) self._bundle_id = activity_info.get_bundle_id() self._version = activity_info.get_activity_version() registry = bundleregistry.get_registry() self._favorites = [] self._favorite_items = [] self._favorite_icons = [] for i in range(desktop.get_number_of_views()): self._favorites.append(registry.is_bundle_favorite(self._bundle_id, self._version, i)) self._favorite_items.append(PaletteMenuItem()) self._favorite_icons.append(Icon(icon_name=desktop.get_favorite_icons()[i], icon_size=Gtk.IconSize.MENU)) self._favorite_items[i].set_image(self._favorite_icons[i]) self._favorite_icons[i].show() self._favorite_items[i].connect("activate", self.__change_favorite_activate_cb, i) self.menu_box.append_item(self._favorite_items[i]) self._favorite_items[i].show() if activity_info.is_user_activity(): self._add_erase_option(registry, activity_info) registry = bundleregistry.get_registry() self._activity_changed_sid = [] for i in range(desktop.get_number_of_views()): self._activity_changed_sid.append(registry.connect("bundle_changed", self.__activity_changed_cb, i)) self._update_favorite_item(i) self.menu_box.connect("destroy", self.__destroy_cb)
def __init__(self, activity_info): ActivityPalette.__init__(self, activity_info) self._bundle_id = activity_info.get_bundle_id() self._version = activity_info.get_activity_version() registry = bundleregistry.get_registry() self._favorite = registry.is_bundle_favorite(self._bundle_id, self._version) self._favorite_item = MenuItem('') self._favorite_icon = Icon(icon_name='emblem-favorite', icon_size=Gtk.IconSize.MENU) self._favorite_item.set_image(self._favorite_icon) self._favorite_item.connect('activate', self.__change_favorite_activate_cb) self.menu.append(self._favorite_item) self._favorite_item.show() if activity_info.is_user_activity(): self._add_erase_option(registry, activity_info) registry = bundleregistry.get_registry() self._activity_changed_sid = registry.connect( 'bundle_changed', self.__activity_changed_cb) self._update_favorite_item() self.menu.connect('destroy', self.__destroy_cb)
def __init__(self, activity_info): ActivityPalette.__init__(self, activity_info) self._bundle_id = activity_info.get_bundle_id() self._version = activity_info.get_activity_version() registry = bundleregistry.get_registry() self._favorite = registry.is_bundle_favorite(self._bundle_id, self._version) self._favorite_item = MenuItem('') self._favorite_icon = Icon(icon_name='emblem-favorite', icon_size=Gtk.IconSize.MENU) self._favorite_item.set_image(self._favorite_icon) self._favorite_item.connect('activate', self.__change_favorite_activate_cb) self.menu.append(self._favorite_item) self._favorite_item.show() if activity_info.is_user_activity(): self._add_erase_option(registry, activity_info) registry = bundleregistry.get_registry() self._activity_changed_sid = registry.connect('bundle_changed', self.__activity_changed_cb) self._update_favorite_item() self.menu.connect('destroy', self.__destroy_cb)
def __init__(self, modelwrapper, alerts): SectionView.__init__(self) get_control_panel()._section_toolbar.cancel_button.hide() bundleregistry.get_registry().disable_directory_monitoring() self._in_sugar = (modelwrapper is not None) self.set_spacing(style.DEFAULT_SPACING) self.set_border_width(style.DEFAULT_SPACING * 2) # top labels. self.top_label = Gtk.Label() self.top_label.set_line_wrap(True) self.top_label.set_justify(Gtk.Justification.LEFT) self.top_label.set_property('xalign', 0) self.top_label.set_markup('<big>%s</big>' % _('Checking for updates...')) bottom_label = Gtk.Label() bottom_label.set_line_wrap(True) # doesn't really work right =( bottom_label.set_justify(Gtk.Justification.LEFT) bottom_label.set_property('xalign', 0) bottom_label.set_markup( _('Software updates correct errors, eliminate security vulnerabilities, and provide new features.' )) vbox2 = Gtk.VBox() vbox2.pack_start(self.top_label, False, True, 0) vbox2.pack_start(Gtk.HSeparator(), False, False, 0) vbox2.pack_start(bottom_label, True, True, 0) self.pack_start(vbox2, False, True, 0) # activity/group pane #### self.activity_list = model.UpdateList() self.activity_pane = ActivityPane(self) self.pack_start(self.activity_pane, True, True, 0) # progress pane ########### self.progress_pane = ProgressPane(self) self.pack_start(self.progress_pane, True, False, 0) # special little extension to progress pane. self.expander = Gtk.Expander(label=_('Modify activity groups')) def expander_cb(expander, param_): if expander.get_expanded(): self.activity_pane.switch() self.activity_pane.expander.set_expanded(True) expander.set_expanded(False) self.expander.connect("notify::expanded", expander_cb) self.pack_end(self.expander, False, True, 0) # show our work! self.show_all() # and start refreshing. self.refresh_cb(None, None)
def __init__(self, modelwrapper, alerts): SectionView.__init__(self) get_control_panel()._section_toolbar.cancel_button.hide() bundleregistry.get_registry().disable_directory_monitoring() self._in_sugar = (modelwrapper is not None) self.set_spacing(style.DEFAULT_SPACING) self.set_border_width(style.DEFAULT_SPACING * 2) # top labels. self.top_label = Gtk.Label() self.top_label.set_line_wrap(True) self.top_label.set_justify(Gtk.Justification.LEFT) self.top_label.set_property('xalign',0) self.top_label.set_markup('<big>%s</big>'%_('Checking for updates...')) bottom_label = Gtk.Label() bottom_label.set_line_wrap(True) # doesn't really work right =( bottom_label.set_justify(Gtk.Justification.LEFT) bottom_label.set_property('xalign', 0) bottom_label.set_markup(_('Software updates correct errors, eliminate security vulnerabilities, and provide new features.')) vbox2 = Gtk.VBox() vbox2.pack_start(self.top_label, False, True, 0) vbox2.pack_start(Gtk.HSeparator(), False, False, 0) vbox2.pack_start(bottom_label, True, True, 0) self.pack_start(vbox2, False, True, 0) # activity/group pane #### self.activity_list = model.UpdateList() self.activity_pane = ActivityPane(self) self.pack_start(self.activity_pane, True, True, 0) # progress pane ########### self.progress_pane = ProgressPane(self) self.pack_start(self.progress_pane, True, False, 0) # special little extension to progress pane. self.expander = Gtk.Expander(label=_('Modify activity groups')) def expander_cb(expander, param_): if expander.get_expanded(): self.activity_pane.switch() self.activity_pane.expander.set_expanded(True) expander.set_expanded(False) self.expander.connect("notify::expanded", expander_cb) self.pack_end(self.expander, False, True, 0) # show our work! self.show_all() # and start refreshing. self.refresh_cb(None, None)
def __icon_clicked_cb(self, cell, path): row = self.get_model()[path] registry = bundleregistry.get_registry() bundle = registry.get_bundle(row[ListModel.COLUMN_BUNDLE_ID]) misc.launch(bundle)
def __run_actvity_cb(self, run_button): if self.save_unchanged: self.editor.save_all() registry = bundleregistry.get_registry() bundle = registry.get_bundle(self.bundle.get_bundle_id()) activityfactory.create(bundle)
def _update_open_submenu(self): activities = self._get_activities() logging.debug('_update_open_submenu: %r', activities) child = self._open_item.get_child() if activities is None or len(activities) <= 1: child.set_text(_('Open')) if self._open_item.get_submenu() is not None: self._open_item.remove_submenu() return child.set_text(_('Open with')) submenu = self._open_item.get_submenu() if submenu is None: submenu = gtk.Menu() self._open_item.set_submenu(submenu) submenu.show() else: for item in submenu.get_children(): submenu.remove(item) for service_name in activities: registry = bundleregistry.get_registry() activity_info = registry.get_bundle(service_name) if not activity_info: logging.warning('Activity %s is unknown.', service_name) item = gtk.MenuItem(activity_info.get_name()) item.connect('activate', self._open_submenu_item_activate_cb, service_name) submenu.append(item) item.show()
def __activity_changed_cb(self, activity_registry, activity_info): if activity_info.get_bundle_id() == self._bundle_id and \ activity_info.get_activity_version() == self._version: registry = bundleregistry.get_registry() self._favorite = registry.is_bundle_favorite( self._bundle_id, self._version) self._update_favorite_item()
def _erase_button_clicked_cb(self, button): registry = bundleregistry.get_registry() bundle = misc.get_bundle(self._metadata) if bundle is not None and registry.is_installed(bundle): registry.uninstall(bundle) model.delete(self._metadata['uid'])
def __init__(self, invite): Palette.__init__(self, "") self._invite = invite menu_item = MenuItem(_("Join"), icon_name="dialog-ok") menu_item.connect("activate", self.__join_activate_cb) self.menu.append(menu_item) menu_item.show() menu_item = MenuItem(_("Decline"), icon_name="dialog-cancel") menu_item.connect("activate", self.__decline_activate_cb) self.menu.append(menu_item) menu_item.show() bundle_id = invite.get_bundle_id() registry = bundleregistry.get_registry() self._bundle = registry.get_bundle(bundle_id) if self._bundle: name = self._bundle.get_name() else: name = bundle_id self.set_primary_text(GLib.markup_escape_text(name))
def _start_activity(self, path): row = self.get_model()[path] registry = bundleregistry.get_registry() bundle = registry.get_bundle(row[ListModel.COLUMN_BUNDLE_ID]) misc.launch(bundle)
def __activity_changed_cb(self, activity_registry, activity_info): if activity_info.get_bundle_id() == self._bundle_id and \ activity_info.get_activity_version() == self._version: registry = bundleregistry.get_registry() self._favorite = registry.is_bundle_favorite(self._bundle_id, self._version) self._update_favorite_item()
def _window_opened_cb(self, screen, window): """Handle the callback for the 'window opened' event. Most activities will register 2 windows during their lifetime: the launcher window, and the 'main' app window. When the main window appears, we send a signal to the launcher window to close. Some activities (notably non-native apps) open several windows during their lifetime, switching from one to the next as the 'main' window. We use a stack to track them. """ if window.get_window_type() == Wnck.WindowType.NORMAL or \ window.get_window_type() == Wnck.WindowType.SPLASHSCREEN: home_activity = None xid = window.get_xid() activity_id = SugarExt.wm_get_activity_id(xid) service_name = SugarExt.wm_get_bundle_id(xid) if service_name: registry = get_registry() activity_info = registry.get_bundle(service_name) else: activity_info = None if activity_id: home_activity = self.get_activity_by_id(activity_id) display = Gdk.Display.get_default() gdk_window = GdkX11.X11Window.foreign_new_for_display(display, xid) gdk_window.set_decorations(0) window.maximize() if not home_activity: logging.debug('first window registered for %s', activity_id) color = self._shared_activities.get(activity_id, None) home_activity = Activity(activity_info, activity_id, color, window) self._add_activity(home_activity) else: logging.debug('window registered for %s', activity_id) home_activity.add_window(window) if window.get_window_type() != Wnck.WindowType.SPLASHSCREEN \ and \ home_activity.get_launch_status() == Activity.LAUNCHING: self.emit('launch-completed', home_activity) startup_time = time.time() - home_activity.get_launch_time() logging.debug('%s launched in %f seconds.', activity_id, startup_time) if self._active_activity is None: self._set_active_activity(home_activity)
def get_bundle(bundle_id=None, object_id=None): if bundle_id is None and object_id is None: logging.error('At least one parameter has to be passed') return None if bundle_id is None: obj = datastore.get(object_id) if obj.metadata['mime_type'] is None: return None mime_type = str(obj.metadata['mime_type']) activities = get_activities_for_mime(mime_type) if not activities: logging.warning('No activity can start object with type, %s.', mime_type) return None return activities[0] else: bundle = bundleregistry.get_registry().get_bundle(bundle_id) if bundle is None: logging.warning('Activity with the bundle_id %s was not found', mime_type) return None return bundle
def _add_activity(self, activity_info): if activity_info.get_bundle_id() == 'org.laptop.JournalActivity': return timestamp = activity_info.get_installation_time() version = activity_info.get_activity_version() registry = bundleregistry.get_registry() favorites = [] for i in range(desktop.get_number_of_views()): favorites.append( registry.is_bundle_favorite(activity_info.get_bundle_id(), version, i)) tag_list = activity_info.get_tags() if tag_list is None or not tag_list: title = '<b>%s</b>' % activity_info.get_name() else: tags = ', '.join(tag_list) title = '<b>%s</b>\n' \ '<span style="italic" weight="light">%s</span>' % \ (activity_info.get_name(), tags) model_list = [activity_info.get_bundle_id()] for i in range(desktop.get_number_of_views()): model_list.append(favorites[i]) model_list.append(activity_info.get_icon()) model_list.append(title) model_list.append(version) model_list.append(_('Version %s') % version) model_list.append(int(timestamp)) model_list.append(util.timestamp_to_elapsed_string(timestamp)) self._model.append(model_list)
def _add_activity(self, activity_info): if activity_info.get_bundle_id() == 'org.laptop.JournalActivity': return timestamp = activity_info.get_installation_time() version = activity_info.get_activity_version() registry = bundleregistry.get_registry() favorite = registry.is_bundle_favorite(activity_info.get_bundle_id(), version) tag_list = activity_info.get_tags() if tag_list is None or not tag_list: title = '<b>%s</b>' % activity_info.get_name() else: tags = ', '.join(tag_list) title = '<b>%s</b>\n' \ '<span style="italic" weight="light">%s</span>' % \ (activity_info.get_name(), tags) self._model.append([activity_info.get_bundle_id(), favorite, activity_info.get_icon(), title, version, _('Version %s') % version, int(timestamp), util.timestamp_to_elapsed_string(timestamp)])
def __init__(self, invite): Palette.__init__(self, '') self._invite = invite self.menu_box = PaletteMenuBox() self.set_content(self.menu_box) self.menu_box.show() menu_item = PaletteMenuItem(_('Join'), icon_name='dialog-ok') menu_item.connect('activate', self.__join_activate_cb) self.menu_box.append_item(menu_item) menu_item.show() menu_item = PaletteMenuItem(_('Decline'), icon_name='dialog-cancel') menu_item.connect('activate', self.__decline_activate_cb) self.menu_box.append_item(menu_item) menu_item.show() bundle_id = invite.get_bundle_id() registry = bundleregistry.get_registry() self._bundle = registry.get_bundle(bundle_id) if self._bundle: activity_name = self._bundle.get_name() else: activity_name = bundle_id self.set_primary_text(activity_name) title = self._invite.get_activity_title() if title is not None: self.set_secondary_text(title)
def __gen_turtle_path(self, turtle_id, plugin_folder): #genero el path al plugin #turtle_path ="algo" print "turtle id:", turtle_id turtle_path = bundleregistry.get_registry().get_bundle( turtle_id).get_path() self.__plugin_folder = turtle_path + "/plugins/" + plugin_folder
def _check_for_bundle(self, object_id): registry = bundleregistry.get_registry() metadata = model.get(object_id) if metadata.get('progress', '').isdigit(): if int(metadata['progress']) < 100: return bundle = misc.get_bundle(metadata) if bundle is None: return if registry.is_installed(bundle): logging.debug('_check_for_bundle bundle already installed') return if metadata['mime_type'] == JournalEntryBundle.MIME_TYPE: # JournalEntryBundle code takes over the datastore entry and # transforms it into the journal entry from the bundle -- we have # nothing more to do. try: registry.install(bundle, metadata['uid']) except (ZipExtractException, RegistrationException): logging.exception('Could not install bundle %s', bundle.get_path()) return try: registry.install(bundle) except (ZipExtractException, RegistrationException): logging.exception('Could not install bundle %s', bundle.get_path()) return metadata['bundle_id'] = bundle.get_bundle_id() model.write(metadata)
def get_icon_name(metadata): file_name = None bundle_id = metadata.get('activity', '') if not bundle_id: bundle_id = metadata.get('bundle_id', '') if bundle_id: if bundle_id == PROJECT_BUNDLE_ID: file_name = \ '/home/broot/sugar-build/build' + \ '/out/install/share/icons/sugar/' + \ 'scalable/mimetypes/project-box.svg' return file_name activity_info = bundleregistry.get_registry().get_bundle(bundle_id) if activity_info: file_name = activity_info.get_icon() if file_name is None and is_activity_bundle(metadata): file_path = model.get_file(metadata['uid']) if file_path is not None and os.path.exists(file_path): try: bundle = get_bundle_instance(file_path) file_name = bundle.get_icon() except Exception: logging.exception('Could not read bundle') if file_name is None: file_name = _get_icon_for_mime(metadata.get('mime_type', '')) if file_name is None: file_name = get_icon_file_name('application-octet-stream') return file_name
def do_download(): # get activity registry from jarabe.model.bundleregistry import get_registry registry = get_registry() # requires a dbus-registered main loop install_event = Event() # progress bar bookkeeping. counts = [0, self.activity_list.updates_selected(), 0] def p(n, extra, icon): if n is None: progress_cb(n, extra, icon) else: progress_cb((n+(counts[0]/counts[1]))/2, extra, icon) counts[2] = n # last fraction. def q(n, row): p(n, _('Downloading %s...') % row[model.DESCRIPTION_BIG], row[model.ACTIVITY_ICON]) for row, f in self.activity_list.download_selected_updates(q): if f is None: continue # cancelled or network error. try: p(counts[2], _('Examining %s...')%row[model.DESCRIPTION_BIG], row[model.ACTIVITY_ICON]) b = actutils.BundleHelper(f) p(counts[2], _('Installing %s...') % b.get_name(), _svg2pixbuf(b.get_icon_data())) install_event.clear() GLib.idle_add(self.install_cb, registry, b, install_event) install_event.wait() except: logging.exception("Failed to install bundle") pass # XXX: use alert to indicate install failure. if os.path.exists(f): os.unlink(f) counts[0]+=1 # refresh when we're done. GObject.idle_add(self.refresh_cb, None, None, False)
def __init__(self, updates): Gtk.ListStore.__init__(self, str, bool, str, str, int) registry = bundleregistry.get_registry() for bundle_update in updates: installed = registry.get_bundle(bundle_update.bundle_id) row = [None] * 5 row[self.BUNDLE_ID] = bundle_update.bundle_id row[self.SELECTED] = not bundle_update.optional if installed: row[self.ICON_FILE_NAME] = installed.get_icon() else: if bundle_update.icon_file_name is not None: row[self.ICON_FILE_NAME] = bundle_update.icon_file_name if installed: details = _('From version %(current)s to %(new)s (Size: ' '%(size)s)') details = details % \ {'current': installed.get_activity_version(), 'new': bundle_update.version, 'size': _format_size(bundle_update.size)} else: details = _('Version %(version)s (Size: %(size)s)') details = details % \ {'version': bundle_update.version, 'size': _format_size(bundle_update.size)} row[self.DESCRIPTION] = '<b>%s</b>\n%s' % \ (bundle_update.name, details) row[self.SIZE] = bundle_update.size self.append(row)
def get_bundle(bundle_id=None, object_id=None): if bundle_id is None and object_id is None: logging.error('At least one parameter has to be passed') return None if bundle_id is None: obj = datastore.get(object_id) if obj.metadata['mime_type'] is None: return None mime_type = str(obj.metadata['mime_type']) activities = get_activities_for_mime(mime_type) if not activities: logging.warning('No activity can start object with type, %s.', mime_type) return None return activities[0] bundle = bundleregistry.get_registry().get_bundle(bundle_id) if bundle is None: logging.warning('Activity with the bundle_id %s was not found', mime_type) return None return bundle
def _add_activity(self, activity_info): if activity_info.get_bundle_id() == 'org.laptop.JournalActivity': return timestamp = activity_info.get_installation_time() version = activity_info.get_activity_version() registry = bundleregistry.get_registry() favorite = registry.is_bundle_favorite(activity_info.get_bundle_id(), version) tag_list = activity_info.get_tags() if tag_list is None or not tag_list: title = '<b>%s</b>' % activity_info.get_name() else: tags = ', '.join(tag_list) title = '<b>%s</b>\n' \ '<span style="italic" weight="light">%s</span>' % \ (activity_info.get_name(), tags) self._model.append([ activity_info.get_bundle_id(), favorite, activity_info.get_icon(), title, version, _('Version %s') % version, timestamp, util.timestamp_to_elapsed_string(timestamp) ])
def __erase_confirmation_dialog_response_cb(self, alert, response_id, bundle_id): self.remove_alert() if response_id == Gtk.ResponseType.OK: registry = bundleregistry.get_registry() bundle = registry.get_bundle(bundle_id) registry.uninstall(bundle, delete_profile=True)
def _filter_results(self): # Remove updates for which we already have an equivalent or newer # version installed. Queue the remaining ones to be checked. registry = bundleregistry.get_registry() self._bundles_to_check = [] for bundle_id, data in list(self._parser.results.items()): # filter optional activities for automatic updates if self._auto and data[2] is True: logging.debug('filtered optional activity %s', bundle_id) continue bundle = registry.get_bundle(bundle_id) if bundle: if data[0] <= NormalizedVersion(bundle.get_activity_version()): continue name = bundle.get_name() if bundle else None bundle_update = BundleUpdate(bundle_id, name, data[0], data[1], 0, optional=data[2]) self._bundles_to_check.append(bundle_update) self._total_bundles_to_check = len(self._bundles_to_check) _logger.debug("%d results after filter", self._total_bundles_to_check)
def _update_open_submenu(self): activities = self._get_activities() logging.debug('_update_open_submenu: %r', activities) child = self._open_item.get_child() if activities is None or len(activities) <= 1: child.set_text(_('Open')) if self._open_item.get_submenu() is not None: self._open_item.set_submenu(None) return child.set_text(_('Open with')) submenu = self._open_item.get_submenu() if submenu is None: submenu = Gtk.Menu() self._open_item.set_submenu(submenu) submenu.show() else: for item in submenu.get_children(): submenu.remove(item) for service_name in activities: registry = bundleregistry.get_registry() activity_info = registry.get_bundle(service_name) if not activity_info: logging.warning('Activity %s is unknown.', service_name) item = Gtk.MenuItem(activity_info.get_name()) item.connect('activate', self._open_submenu_item_activate_cb, service_name) submenu.append(item) item.show()
def get_icon_name(metadata): file_name = None bundle_id = metadata.get("activity", "") if not bundle_id: bundle_id = metadata.get("bundle_id", "") if bundle_id: activity_info = bundleregistry.get_registry().get_bundle(bundle_id) if activity_info: file_name = activity_info.get_icon() if file_name is None and is_activity_bundle(metadata): file_path = model.get_file(metadata["uid"]) if file_path is not None and os.path.exists(file_path): try: bundle = ActivityBundle(file_path) file_name = bundle.get_icon() except Exception: logging.exception("Could not read bundle") if file_name is None: file_name = _get_icon_for_mime(metadata.get("mime_type", "")) if file_name is None: file_name = get_icon_file_name("application-octet-stream") return file_name
def __init__(self, invite): Palette.__init__(self, '') self._invite = invite menu_item = MenuItem(_('Join'), icon_name='dialog-ok') menu_item.connect('activate', self.__join_activate_cb) self.menu.append(menu_item) menu_item.show() menu_item = MenuItem(_('Decline'), icon_name='dialog-cancel') menu_item.connect('activate', self.__decline_activate_cb) self.menu.append(menu_item) menu_item.show() bundle_id = invite.get_bundle_id() registry = bundleregistry.get_registry() self._bundle = registry.get_bundle(bundle_id) if self._bundle: name = self._bundle.get_name() else: name = bundle_id self.set_primary_text(glib.markup_escape_text(name))
def get_icon_name(metadata): file_name = None bundle_id = metadata.get('activity', '') if not bundle_id: bundle_id = metadata.get('bundle_id', '') if bundle_id: activity_info = bundleregistry.get_registry().get_bundle(bundle_id) if activity_info: file_name = activity_info.get_icon() if file_name is None and is_activity_bundle(metadata): file_path = model.get_file(metadata['uid']) if file_path is not None and os.path.exists(file_path): try: bundle = ActivityBundle(file_path) file_name = bundle.get_icon() except Exception: logging.exception('Could not read bundle') if file_name is None: file_name = _get_icon_for_mime(metadata.get('mime_type', '')) if file_name is None: file_name = get_icon_file_name('application-octet-stream') return file_name
def __activity_updated_cb(self, account, activity_id, properties): logging.debug('__activity_updated_cb %r %r', activity_id, properties) if activity_id not in self._activities: logging.debug( '__activity_updated_cb Unknown activity with ' 'activity_id %r', activity_id) return registry = bundleregistry.get_registry() bundle = registry.get_bundle(properties['type']) if not bundle: logging.warning('Ignoring shared activity we don' 't have') return activity = self._activities[activity_id] is_new = activity.props.bundle is None activity.props.color = XoColor(properties['color']) activity.props.bundle = bundle activity.props.name = properties['name'] activity.props.private = properties['private'] if is_new: self._shell_model.add_shared_activity(activity_id, activity.props.color) self.emit('activity-added', activity)
def _add_activity(self, activity_info): if activity_info.get_bundle_id() == "org.laptop.JournalActivity": return timestamp = activity_info.get_installation_time() version = activity_info.get_activity_version() registry = bundleregistry.get_registry() favorites = [] for i in range(desktop.get_number_of_views()): favorites.append(registry.is_bundle_favorite(activity_info.get_bundle_id(), version, i)) tag_list = activity_info.get_tags() if tag_list is None or not tag_list: title = "<b>%s</b>" % activity_info.get_name() else: tags = ", ".join(tag_list) title = "<b>%s</b>\n" '<span style="italic" weight="light">%s</span>' % (activity_info.get_name(), tags) model_list = [activity_info.get_bundle_id()] for i in range(desktop.get_number_of_views()): model_list.append(favorites[i]) model_list.append(activity_info.get_icon()) model_list.append(title) model_list.append(version) model_list.append(_("Version %s") % version) model_list.append(int(timestamp)) model_list.append(util.timestamp_to_elapsed_string(timestamp)) self._model.append(model_list)
def __favorite_clicked_cb(self, cell, path): row = self.get_model()[path] registry = bundleregistry.get_registry() registry.set_bundle_favorite( row[self._model.column_bundle_id], row[self._model.column_version], not row[self._model.column_favorites[cell.favorite_view]], cell.favorite_view)
def __connect_to_bundle_registry_cb(self): registry = bundleregistry.get_registry() for info in registry: self._add_activity(info) registry.connect('bundle-added', self.__activity_added_cb) registry.connect('bundle-changed', self.__activity_changed_cb) registry.connect('bundle-removed', self.__activity_removed_cb)
def __get_last_activity_reply_handler_cb(self, entries, total_count): registry = bundleregistry.get_registry() if entries: misc.resume(entries[0], entries[0]['activity']) else: bundle = registry.get_bundle(self._activity_selected) misc.launch(bundle)
def resume(metadata, bundle_id=None): registry = bundleregistry.get_registry() if is_activity_bundle(metadata) and bundle_id is None: logging.debug("Creating activity bundle") file_path = model.get_file(metadata["uid"]) bundle = ActivityBundle(file_path) if not registry.is_installed(bundle): logging.debug("Installing activity bundle") try: registry.install(bundle) except AlreadyInstalledException: _downgrade_option_alert(bundle) return else: logging.debug("Upgrading activity bundle") registry.upgrade(bundle) _launch_bundle(bundle) elif is_content_bundle(metadata) and bundle_id is None: logging.debug("Creating content bundle") file_path = model.get_file(metadata["uid"]) bundle = ContentBundle(file_path) if not bundle.is_installed(): logging.debug("Installing content bundle") bundle.install() activities = _get_activities_for_mime("text/html") if len(activities) == 0: logging.warning("No activity can open HTML content bundles") return uri = bundle.get_start_uri() logging.debug("activityfactory.creating with uri %s", uri) activity_bundle = registry.get_bundle(activities[0].get_bundle_id()) launch(activity_bundle, uri=uri) else: activity_id = metadata.get("activity_id", "") if bundle_id is None: activities = get_activities(metadata) if not activities: logging.warning("No activity can open this object, %s.", metadata.get("mime_type", None)) return bundle_id = activities[0].get_bundle_id() bundle = registry.get_bundle(bundle_id) if metadata.get("mountpoint", "/") == "/": object_id = metadata["uid"] else: object_id = model.copy(metadata, "/") launch(bundle, activity_id=activity_id, object_id=object_id, color=get_icon_color(metadata))
def __activity_updated_cb(self, account, activity_id, properties): logging.debug('__activity_updated_cb %r %r', activity_id, properties) if activity_id not in self._activities: logging.debug('__activity_updated_cb Unknown activity with ' 'activity_id %r', activity_id) return registry = bundleregistry.get_registry() bundle = registry.get_bundle(properties['type']) if not bundle: logging.warning('Ignoring shared activity we don''t have') return activity = self._activities[activity_id] is_new = activity.props.bundle is None # arrives unicode but we connect with byte_arrays=True - SL #4157 activity.props.color = XoColor(str(properties['color'])) activity.props.bundle = bundle activity.props.name = properties['name'] activity.props.private = properties['private'] if is_new: self._shell_model.add_shared_activity(activity_id, activity.props.color) self.emit('activity-added', activity)
def get_icon_name(metadata): file_name = None bundle_id = metadata.get('activity', '') if not bundle_id: bundle_id = metadata.get('bundle_id', '') if bundle_id: activity_info = bundleregistry.get_registry().get_bundle(bundle_id) if activity_info: file_name = activity_info.get_icon() if file_name is None and is_activity_bundle(metadata): file_path = model.get_file(metadata['uid']) if file_path is not None and os.path.exists(file_path): try: bundle = get_bundle_instance(file_path) file_name = bundle.get_icon() except Exception: logging.exception('Could not read bundle') if file_name is None: file_name = _get_icon_for_mime(metadata.get('mime_type', '')) if file_name is None: file_name = get_icon_file_name('application-octet-stream') return file_name
def _start_activity(self, path): model = self.get_model() row = model[path] registry = bundleregistry.get_registry() bundle = registry.get_bundle(row[self._model.column_bundle_id]) misc.launch(bundle)
def __is_turtle_installed(self, turtle_id): #reviso que exista el torutga para ese id bunlde = None bunlde = bundleregistry.get_registry().get_bundle(turtle_id) if (bunlde is None): return False else: return True
def _downgrade_alert_response_cb(alert, response_id, bundle): if response_id is Gtk.ResponseType.OK: journalwindow.get_journal_window().remove_alert(alert) registry = bundleregistry.get_registry() registry.install(bundle, force_downgrade=True) _launch_bundle(bundle) elif response_id is Gtk.ResponseType.CANCEL: journalwindow.get_journal_window().remove_alert(alert)
def __erase_alert_response_cb(self, alert, response_id): journalwindow.get_journal_window().remove_alert(alert) if response_id is Gtk.ResponseType.OK: registry = bundleregistry.get_registry() bundle = misc.get_bundle(self._metadata) if bundle is not None and registry.is_installed(bundle): registry.uninstall(bundle) model.delete(self._metadata['uid'])
def _cancel_checking(self): logging.debug('UpdateModel._cancel_checking') total = len(bundleregistry.get_registry()) current = total - len(self._bundles_to_check) self.emit('progress', UpdateModel.ACTION_CHECKING, '', current, current) self._bundles_to_check = None self._cancelling = False
def _unset_favorites(self, favorites_data): favorites = favorites_data['favorites'] keys = favorites.keys() registry = bundleregistry.get_registry() for bundle in keys: bundle = bundle.encode('ascii', 'replace') bundle_id, version = bundle.split(' ') logging.debug('removing %s' % (bundle_id)) registry.set_bundle_favorite(bundle_id, version, False)