def find_keyring_items(self):
     def got_items(result, items):
         def created_item(result, id):
             if result is None: # Item successfully created
                 self.__keyring_data['id'] = id
                 keyring.item_get_info(None, id, got_item)
             else:
                 print "Couldn't create keyring item: " + str(result)
                 
         def got_item(result, item):
             if result is None: # Item retrieved successfully
                 self.__keyring_data['item'] = item
                 self.fill_account_details()
             else:
                 print "Couldn't retrieve keyring item: " + str(result) 
             
         if result is None and len(items) != 0: # Got list of search results
             self.__keyring_data['id'] = items[0].item_id
             keyring.item_get_info(None, self.__keyring_data['id'], got_item)
         elif result == keyring.NoMatchError or len(items) == 0: # No items were found, so we'll create one
             keyring.item_create(None,
                                 keyring.ITEM_GENERIC_SECRET,
                                 "Rhythmbox: Pandora account information",
                                 {'rhythmbox-plugin': 'pandora'},
                                 "", # Empty secret for now
                                 True,
                                 created_item)
         else: # Some other error occurred
             print "Couldn't access keyring: " + str(result)
     # Make asynchronous calls
     keyring.find_items(keyring.ITEM_GENERIC_SECRET, {'rhythmbox-plugin': 'pandora'}, got_items)
Пример #2
0
					except xml.sax.SAXParseException, e:
						print "error parsing catalogue: %s" % e

					load_size['size'] += len(result)
					self.__load_progress = (load_size['size'], total)

				self.__notify_status_changed()


			self.__has_loaded = True
			self.__updating = True
			self.__load_progress = (0, 0) # (complete, total)
			self.__notify_status_changed()

			load_size = {'size': 0}
			keyring.find_items(keyring.ITEM_GENERIC_SECRET, {'rhythmbox-plugin': 'magnatune'}, got_items)


		self.__catalogue_check = rb.UpdateCheck()
		self.__catalogue_check.check_for_update(magnatune_song_info, magnatune_song_info_uri.get_uri(), update_cb)


	def __show_loading_screen(self, show):
		if self.__info_screen is None:
			# load the builder stuff
			builder = gtk.Builder()
			builder.add_from_file(self.__plugin.find_file("magnatune-loading.ui"))
			self.__info_screen = builder.get_object("magnatune_loading_scrolledwindow")
			self.pack_start(self.__info_screen)
			self.get_entry_view().set_no_show_all(True)
			self.__info_screen.set_no_show_all(True)
Пример #3
0
class Magnatune(rb.Plugin):
    client = gconf.client_get_default()

    format_list = ['ogg', 'flac', 'wav', 'mp3-vbr', 'mp3-cbr']

    gconf_keys = {
        'format': "/apps/rhythmbox/plugins/magnatune/format",
        'pay': "/apps/rhythmbox/plugins/magnatune/pay",
        'ccauthtoken': "/apps/rhythmbox/plugins/magnatune/ccauthtoken",
        'continue': "/apps/rhythmbox/plugins/magnatune/continue",
        'account_type': "/apps/rhythmbox/plugins/magnatune/account_type"
    }

    #
    # Core methods
    #

    def __init__(self):
        rb.Plugin.__init__(self)

    def activate(self, shell):
        self.shell = shell  # so the source can update the progress bar
        self.db = shell.get_property("db")

        self.entry_type = self.db.entry_register_type("MagnatuneEntryType")
        # allow changes which don't do anything
        self.entry_type.can_sync_metadata = True
        self.entry_type.sync_metadata = None

        theme = gtk.icon_theme_get_default()
        rb.append_plugin_source_path(theme, "/icons")

        width, height = gtk.icon_size_lookup(gtk.ICON_SIZE_LARGE_TOOLBAR)
        icon = rb.try_load_icon(theme, "magnatune", width, 0)

        group = rb.rb_source_group_get_by_name("stores")
        self.source = gobject.new(MagnatuneSource,
                                  shell=shell,
                                  entry_type=self.entry_type,
                                  source_group=group,
                                  icon=icon,
                                  plugin=self)

        shell.register_entry_type_for_source(self.source, self.entry_type)
        shell.append_source(self.source, None)  # Add the source to the list

        manager = shell.get_player().get_property('ui-manager')
        # Add the popup menu actions
        self.action_group = gtk.ActionGroup('MagnatunePluginActions')

        action = gtk.Action('MagnatuneDownloadAlbum', _('Download Album'),
                            _("Download this album from Magnatune"),
                            'gtk-save')
        action.connect(
            'activate', lambda a: self.shell.get_property("selected-source").
            download_album())
        self.action_group.add_action(action)
        action = gtk.Action('MagnatuneArtistInfo', _('Artist Information'),
                            _("Get information about this artist"), 'gtk-info')
        action.connect(
            'activate', lambda a: self.shell.get_property("selected-source").
            display_artist_info())
        self.action_group.add_action(action)
        action = gtk.Action('MagnatuneCancelDownload', _('Cancel Downloads'),
                            _("Stop downloading purchased albums"), 'gtk-stop')
        action.connect(
            'activate', lambda a: self.shell.get_property("selected-source").
            cancel_downloads())
        action.set_sensitive(False)
        self.action_group.add_action(action)

        manager.insert_action_group(self.action_group, 0)
        self.ui_id = manager.add_ui_from_string(popup_ui)

        self.pec_id = shell.get_player().connect('playing-song-changed',
                                                 self.playing_entry_changed)
        manager.ensure_update()

    def deactivate(self, shell):
        manager = shell.get_player().get_property('ui-manager')
        manager.remove_ui(self.ui_id)
        manager.remove_action_group(self.action_group)
        self.action_group = None

        shell.get_player().disconnect(self.pec_id)

        self.db.entry_delete_by_type(self.entry_type)
        self.db.commit()
        self.db = None
        self.entry_type = None
        self.source.delete_thyself()
        self.source = None
        self.shell = None

    def playing_entry_changed(self, sp, entry):
        self.source.playing_entry_changed(entry)

    def create_configure_dialog(self, dialog=None):
        # We use a dictionary so we can modify these values from within inner functions
        keyring_data = {'id': 0, 'item': None}

        def got_items(result, items):
            def created_item(result, id):
                if result is None:  # Item successfully created
                    keyring_data['id'] = id
                    keyring.item_get_info(None, id, got_item)
                else:
                    print "Couldn't create keyring item: " + str(result)
                    fill_account_details()
                    dialog.present()

            def got_item(result, item):
                if result is None:  # Item retrieved successfully
                    keyring_data['item'] = item
                else:
                    print "Couldn't retrieve keyring item: " + str(result)
                fill_account_details()
                dialog.present()

            if result is None and len(
                    items) != 0:  # Got list of search results
                keyring_data['id'] = items[0].item_id
                keyring.item_get_info(None, keyring_data['id'], got_item)
            elif result == keyring.NoMatchError or len(
                    items) == 0:  # No items were found, so we'll create one
                keyring.item_create(
                    None,
                    keyring.ITEM_GENERIC_SECRET,
                    "Rhythmbox: Magnatune account information",
                    {'rhythmbox-plugin': 'magnatune'},
                    "",  # Empty secret for now
                    True,
                    created_item)
            else:  # Some other error occurred
                print "Couldn't access keyring: " + str(result)
                fill_account_details()
                dialog.present()

        if dialog == None:

            def fill_account_details():
                account_type = self.client.get_string(
                    self.gconf_keys['account_type'])
                builder.get_object("no_account_radio").set_active(
                    account_type == "none")
                builder.get_object("stream_account_radio").set_active(
                    account_type == "stream")
                builder.get_object("download_account_radio").set_active(
                    account_type == "download")

                username = ""
                password = ""
                try:
                    if keyring_data['item']:
                        username, password = keyring_data['item'].get_secret(
                        ).split('\n')
                except ValueError:  # Couldn't parse the secret, probably because it's empty
                    pass
                builder.get_object("username_entry").set_text(username)
                builder.get_object("password_entry").set_text(password)

                has_account = account_type != "none"
                builder.get_object("username_entry").set_sensitive(has_account)
                builder.get_object("password_entry").set_sensitive(has_account)
                builder.get_object("username_label").set_sensitive(has_account)
                builder.get_object("password_label").set_sensitive(has_account)

                builder.get_object("account_changed_label").hide()

            def account_type_toggled(button):
                print "account type radiobutton toggled: " + button.get_name()
                account_type = {
                    "no_account_radio": "none",
                    "stream_account_radio": "stream",
                    "download_account_radio": "download"
                }
                if button.get_active():
                    self.client.set_string(self.gconf_keys['account_type'],
                                           account_type[button.get_name()])
                    if account_type[button.get_name()] == 'none':
                        builder.get_object("username_label").set_sensitive(
                            False)
                        builder.get_object("username_entry").set_sensitive(
                            False)
                        builder.get_object("password_label").set_sensitive(
                            False)
                        builder.get_object("password_entry").set_sensitive(
                            False)
                    else:
                        builder.get_object("username_label").set_sensitive(
                            True)
                        builder.get_object("username_entry").set_sensitive(
                            True)
                        builder.get_object("password_label").set_sensitive(
                            True)
                        builder.get_object("password_entry").set_sensitive(
                            True)
                    builder.get_object("account_changed_label").show()

            def account_details_changed(entry):
                username = builder.get_object("username_entry").get_text()
                password = builder.get_object("password_entry").get_text()
                if keyring_data['item']:
                    keyring_data['item'].set_secret('\n'.join(
                        (username, password)))

                builder.get_object("account_changed_label").show()

            def close_button_pressed(x, y):
                try:
                    if keyring_data['id'] and keyring_data['item']:
                        # The async version is not in the python bindings, grr...
                        keyring.item_set_info_sync(None, keyring_data['id'],
                                                   keyring_data['item'])
                    else:
                        rb.error_dialog(
                            title=_("Couldn't store account information"),
                            message=
                            _("There was a problem accessing the keyring. Check the debug output for more information."
                              ))
                except Exception, e:
                    rb.error_dialog(
                        title=_("Couldn't store account information"),
                        message=str(e))
                dialog.hide()

            self.configure_callback_dic = {
                "rb_magnatune_audio_combobox_changed_cb":
                lambda w: self.client.set_string(
                    self.gconf_keys['format'], self.format_list[w.get_active()]
                ),
                "rb_magnatune_radio_account_toggled_cb":
                account_type_toggled,
                "rb_magnatune_username_changed_cb":
                account_details_changed,
                "rb_magnatune_password_changed_cb":
                account_details_changed
            }

            builder = gtk.Builder()
            builder.add_from_file(self.find_file("magnatune-prefs.ui"))

            # FIXME this bit should be in builder too  (what?)
            dialog = builder.get_object('preferences_dialog')

            # Set the names of the radio buttons so we can tell which one has been clicked
            for name in ("no_account_radio", "stream_account_radio",
                         "download_account_radio"):
                builder.get_object(name).set_name(name)

            builder.get_object("audio_combobox").set_active(
                self.format_list.index(
                    self.client.get_string(self.gconf_keys['format'])))

            builder.connect_signals(self.configure_callback_dic)
            dialog.connect("response", close_button_pressed)

        keyring.find_items(keyring.ITEM_GENERIC_SECRET,
                           {'rhythmbox-plugin': 'magnatune'}, got_items)
        return dialog
                        parser.feed(result)
                    except xml.sax.SAXParseException, e:
                        print "error parsing catalogue: %s" % e

                    load_size['size'] += len(result)
                    self.__load_progress = (load_size['size'], total)

                self.__notify_status_changed()

            self.__has_loaded = True
            self.__updating = True
            self.__load_progress = (0, 0)  # (complete, total)
            self.__notify_status_changed()

            load_size = {'size': 0}
            keyring.find_items(keyring.ITEM_GENERIC_SECRET,
                               {'rhythmbox-plugin': 'magnatune'}, got_items)

        self.__catalogue_check = rb.UpdateCheck()
        self.__catalogue_check.check_for_update(
            magnatune_song_info, magnatune_song_info_uri.get_uri(), update_cb)

    def __show_loading_screen(self, show):
        if self.__info_screen is None:
            # load the builder stuff
            builder = gtk.Builder()
            builder.add_from_file(
                self.__plugin.find_file("magnatune-loading.ui"))
            self.__info_screen = builder.get_object(
                "magnatune_loading_scrolledwindow")
            self.pack_start(self.__info_screen)
            self.get_entry_view().set_no_show_all(True)
Пример #5
0
class MagnatuneConfig(gobject.GObject, PeasGtk.Configurable):
    __gtype_name__ = 'MagnatuneConfig'
    object = gobject.property(type=gobject.GObject)

    def __init__(self):
        gobject.GObject.__init__(self)

    def do_create_configure_widget(self):
        # We use a dictionary so we can modify these values from within inner functions
        keyring_data = {'id': 0, 'item': None}

        def got_items(result, items):
            def created_item(result, id):
                if result is None:  # Item successfully created
                    keyring_data['id'] = id
                    keyring.item_get_info(None, id, got_item)
                else:
                    print "Couldn't create keyring item: " + str(result)
                    fill_account_details()
                    dialog.present()

            def got_item(result, item):
                if result is None:  # Item retrieved successfully
                    keyring_data['item'] = item
                else:
                    print "Couldn't retrieve keyring item: " + str(result)
                fill_account_details()
                dialog.present()

            if result is None and len(
                    items) != 0:  # Got list of search results
                keyring_data['id'] = items[0].item_id
                keyring.item_get_info(None, keyring_data['id'], got_item)
            elif result == keyring.NoMatchError or len(
                    items) == 0:  # No items were found, so we'll create one
                keyring.item_create(
                    None,
                    keyring.ITEM_GENERIC_SECRET,
                    "Rhythmbox: Magnatune account information",
                    {'rhythmbox-plugin': 'magnatune'},
                    "",  # Empty secret for now
                    True,
                    created_item)
            else:  # Some other error occurred
                print "Couldn't access keyring: " + str(result)
                fill_account_details()
                dialog.present()

        def fill_account_details():
            account_type = self.settings['account_type']
            builder.get_object("no_account_radio").set_active(
                account_type == "none")
            builder.get_object("stream_account_radio").set_active(
                account_type == "stream")
            builder.get_object("download_account_radio").set_active(
                account_type == "download")

            username = ""
            password = ""
            try:
                if keyring_data['item']:
                    username, password = keyring_data['item'].get_secret(
                    ).split('\n')
            except ValueError:  # Couldn't parse the secret, probably because it's empty
                pass
            builder.get_object("username_entry").set_text(username)
            builder.get_object("password_entry").set_text(password)

            has_account = account_type != "none"
            builder.get_object("username_entry").set_sensitive(has_account)
            builder.get_object("password_entry").set_sensitive(has_account)
            builder.get_object("username_label").set_sensitive(has_account)
            builder.get_object("password_label").set_sensitive(has_account)

            builder.get_object("account_changed_label").hide()

        def account_type_toggled(button):
            print "account type radiobutton toggled: " + button.get_name()
            account_type = {
                "no_account_radio": "none",
                "stream_account_radio": "stream",
                "download_account_radio": "download"
            }
            if button.get_active():
                self.settings['account_type'] = account_type[button.get_name()]
                if account_type[button.get_name()] == 'none':
                    builder.get_object("username_label").set_sensitive(False)
                    builder.get_object("username_entry").set_sensitive(False)
                    builder.get_object("password_label").set_sensitive(False)
                    builder.get_object("password_entry").set_sensitive(False)
                else:
                    builder.get_object("username_label").set_sensitive(True)
                    builder.get_object("username_entry").set_sensitive(True)
                    builder.get_object("password_label").set_sensitive(True)
                    builder.get_object("password_entry").set_sensitive(True)
                builder.get_object("account_changed_label").show()

        def account_details_changed(entry):
            username = builder.get_object("username_entry").get_text()
            password = builder.get_object("password_entry").get_text()
            if keyring_data['item']:
                keyring_data['item'].set_secret('\n'.join(
                    (username, password)))

            builder.get_object("account_changed_label").show()

        def close_button_pressed(x, y):
            try:
                if keyring_data['id'] and keyring_data['item']:
                    # The async version is not in the python bindings, grr...
                    keyring.item_set_info_sync(None, keyring_data['id'],
                                               keyring_data['item'])
                else:
                    RB.error_dialog(
                        title=_("Couldn't store account information"),
                        message=
                        _("There was a problem accessing the keyring. Check the debug output for more information."
                          ))
            except Exception, e:
                RB.error_dialog(title=_("Couldn't store account information"),
                                message=str(e))
            dialog.hide()

        def format_selection_changed(self, button):
            self.settings['format'] = self.format_list[button.get_active()]

        self.configure_callback_dic = {
            "rb_magnatune_audio_combobox_changed_cb":
            self.format_selection_changed,
            "rb_magnatune_radio_account_toggled_cb": account_type_toggled,
            "rb_magnatune_username_changed_cb": account_details_changed,
            "rb_magnatune_password_changed_cb": account_details_changed
        }

        builder = Gtk.Builder()
        builder.add_from_file(rb.find_plugin_file(self, "magnatune-prefs.ui"))

        dialog = builder.get_object('preferences_dialog')

        # Set the names of the radio buttons so we can tell which one has been clicked
        for name in ("no_account_radio", "stream_account_radio",
                     "download_account_radio"):
            builder.get_object(name).set_name(name)

        builder.get_object("audio_combobox").set_active(
            self.format_list.index(self.settings['format']))

        builder.connect_signals(self.configure_callback_dic)
        dialog.connect("response", close_button_pressed)

        keyring.find_items(keyring.ITEM_GENERIC_SECRET,
                           {'rhythmbox-plugin': 'magnatune'}, got_items)
        return dialog