Beispiel #1
0
 def _profile_chosen(self, profile_combo, nameentry, hostentry, portentry, passwordentry, direntry):
     profile_num = profile_combo.get_active()
     self.updating_nameentry = True
     nameentry.set_text(str(self.config.profile_names[profile_num]))
     self.updating_nameentry = False
     hostentry.set_text(str(self.config.host[profile_num]))
     portentry.set_value(self.config.port[profile_num])
     passwordentry.set_text(str(self.config.password[profile_num]))
     direntry.set_current_folder(misc.sanitize_musicdir(self.config.musicdir[profile_num]))
Beispiel #2
0
 def _profile_chosen(self, profile_combo, nameentry, hostentry, portentry, passwordentry, direntry):
     profile_num = profile_combo.get_active()
     self.updating_nameentry = True
     nameentry.set_text(str(self.config.profile_names[profile_num]))
     self.updating_nameentry = False
     hostentry.set_text(str(self.config.host[profile_num]))
     portentry.set_value(self.config.port[profile_num])
     passwordentry.set_text(str(self.config.password[profile_num]))
     direntry.set_current_folder(misc.sanitize_musicdir(self.config.musicdir[profile_num]))
Beispiel #3
0
 def _direntry_changed(self, entry, profile_combo):
     profile_num = profile_combo.get_active()
     self.config.musicdir[profile_num] = misc.sanitize_musicdir(entry.get_filename())
Beispiel #4
0
 def _direntry_changed(self, entry, profile_combo):
     profile_num = profile_combo.get_active()
     self.config.musicdir[profile_num] = misc.sanitize_musicdir(
         entry.get_filename())
Beispiel #5
0
    def settings_load_real(self):
        """Load configuration from file"""

        conf = ConfigParser()
        misc.create_dir(os.path.dirname(self.CONFIG_PATH))
        conf.read(self.CONFIG_PATH)

        # Load all the "simple" options, as described in self._options, and set
        # them as instance attribute.
        for section, attributes in self._options.items():
            for attribute, (opt_key, type, default) in attributes.items():
                if conf.has_option(section, opt_key):
                    try:
                        value = getattr(conf, 'get' + type)(section, opt_key)
                    except Exception as e:
                        # BBB: we need to expect some errors since Sonata uses
                        # to write None values for "int"-type settings, which
                        # fail to be loaded when using getint(). The new code
                        # should write better values each time. Consider
                        # removing this try/except clause when configuration
                        # files are "clean".
                        value = default
                        # This should be safe in all cases
                        faulty_value = conf.get(section, opt_key)
                        logger.warning(
                            "Can't load %r from section %r (as %s). Value is %r",
                            opt_key, section, type if type else "str",
                            faulty_value)
                else:
                    value = default
                setattr(self, attribute, value)

        # Load all the attributes which have several values and are indexed.
        for section, (index_name, attributes) in self._indexed_options.items():
            if not conf.has_option(section, index_name):
                num = 0
            else:
                num = conf.getint(section, index_name)

            for attribute, (key, type, default) in attributes.items():
                if num == 0:
                    setattr(self, attribute, default)
                else:
                    setattr(self, attribute, [])

                for i in range(num):
                    opt_key = "%s[%d]" % (key, i)
                    value = getattr(conf, 'get' + type)(section, opt_key)
                    getattr(self, attribute).append(value)

        # Finally, load attributes related to the library. This is a bit weird
        # so we use an helper function to make it easier:
        def lib_get(name):
            # Helper function to load attributes related to the library.
            value = None
            if conf.has_option('library', name):
                value = conf.get('library', name)
            if value == LIB_NODATA:
                value = None
            return value

        if conf.has_section('library'):
            album  = lib_get('lib_album')
            artist = lib_get('lib_artist')
            genre  = lib_get('lib_genre')
            year   = lib_get('lib_year')
            path   = lib_get('lib_path')
            self.wd = SongRecord(album, artist, genre, year, path)

        # Finally, patch some values:
        self.musicdir = [misc.sanitize_musicdir(v) for v in self.musicdir]
        # Ensure we have a valid profile number:
        self.profile_num = max(0, min(self.profile_num,
                                      len(self.profile_names) - 1))

        # Specifying remote artwork first is too confusing and probably
        # rarely used, so we're removing this option and defaulting users
        # back to the default 'local, then remote' option.
        # Backward compatibility
        if self.covers_pref > consts.ART_LOCAL_REMOTE:
            self.covers_pref = consts.ART_LOCAL_REMOTE
Beispiel #6
0
    def settings_load_real(self):
        """Load configuration from file"""

        conf = ConfigParser()
        misc.create_dir(os.path.dirname(self.CONFIG_PATH))
        conf.read(self.CONFIG_PATH)

        # Load all the "simple" options, as described in self._options, and set
        # them as instance attribute.
        for section, attributes in self._options.items():
            for attribute, (opt_key, type, default) in attributes.items():
                if conf.has_option(section, opt_key):
                    try:
                        value = getattr(conf, 'get' + type)(section, opt_key)
                    except Exception as e:
                        # BBB: we need to expect some errors since Sonata uses
                        # to write None values for "int"-type settings, which
                        # fail to be loaded when using getint(). The new code
                        # should write better values each time. Consider
                        # removing this try/except clause when configuration
                        # files are "clean".
                        value = default
                        # This should be safe in all cases
                        faulty_value = conf.get(section, opt_key)
                        logger.warning(
                            "Can't load %r from section %r (as %s). Value is %r",
                            opt_key, section, type if type else "str",
                            faulty_value)
                else:
                    value = default
                setattr(self, attribute, value)

        # Load all the attributes which have several values and are indexed.
        for section, (index_name, attributes) in self._indexed_options.items():
            if not conf.has_option(section, index_name):
                num = 0
            else:
                num = conf.getint(section, index_name)

            for attribute, (key, type, default) in attributes.items():
                if num == 0:
                    setattr(self, attribute, default)
                else:
                    setattr(self, attribute, [])

                for i in range(num):
                    opt_key = "%s[%d]" % (key, i)
                    value = getattr(conf, 'get' + type)(section, opt_key)
                    getattr(self, attribute).append(value)

        # Finally, load attributes related to the library. This is a bit weird
        # so we use an helper function to make it easier:
        def lib_get(name):
            # Helper function to load attributes related to the library.
            value = None
            if conf.has_option('library', name):
                value = conf.get('library', name)
            if value == LIB_NODATA:
                value = None
            return value

        if conf.has_section('library'):
            album = lib_get('lib_album')
            artist = lib_get('lib_artist')
            genre = lib_get('lib_genre')
            year = lib_get('lib_year')
            path = lib_get('lib_path')
            self.wd = SongRecord(album, artist, genre, year, path)

        # Finally, patch some values:
        self.musicdir = [misc.sanitize_musicdir(v) for v in self.musicdir]
        # Ensure we have a valid profile number:
        self.profile_num = max(
            0, min(self.profile_num,
                   len(self.profile_names) - 1))

        # Specifying remote artwork first is too confusing and probably
        # rarely used, so we're removing this option and defaulting users
        # back to the default 'local, then remote' option.
        # Backward compatibility
        if self.covers_pref > consts.ART_LOCAL_REMOTE:
            self.covers_pref = consts.ART_LOCAL_REMOTE