Exemple #1
0
    def get_tag_sort(self, tag, join=True, artist_compilations=True,
            extend_title=True):
        """
            Get a tag value in a form suitable for sorting.

            :param tag: The name of the tag to get
            :param join: If True, joins lists of values into a
                single value.
            :param artist_compilations: If True, automatically handle
                albumartist and other compilations detections when
                tag=="artist".
            :param extend_title: If the title tag is unknown, try to
                add some identifying information to it.
        """
        # The two magic values here are to ensure that compilations
        # and unknown values are always sorted below all normal
        # values.
        retval = None
        sorttag = self.__tags.get(tag + "sort")
        if sorttag and tag != "artist":
            retval = sorttag
        elif tag == "artist":
            if artist_compilations and self.__tags.get('__compilation'):
                retval = self.__tags.get('albumartist',
                        u"\uffff\uffff\uffff\ufffe")
            else:
                retval = self.__tags.get('artist',
                        u"\uffff\uffff\uffff\uffff")
            if sorttag and retval not in (u"\uffff\uffff\uffff\ufffe",
                    u"\uffff\uffff\uffff\uffff"):
                retval = sorttag
            else:
                sorttag = None
        elif tag in ('tracknumber', 'discnumber'):
            retval = self.split_numerical(self.__tags.get(tag))[0]
        elif tag in ('__length', '__playcount'):
            retval = self.__tags.get(tag, 0)
        else:
            retval = self.__tags.get(tag)

        if not retval:
            retval = u"\uffff\uffff\uffff\uffff" # unknown
            if tag == 'title':
                gloc = gio.File(self.__tags['__loc'])
                basename = glib.filename_display_name(gloc.get_basename())
                retval = u"%s (%s)" % (retval, basename)
        elif not tag.startswith("__") and \
                tag not in ('tracknumber', 'discnumber'):
            if not sorttag:
                retval = self.format_sort(retval)
            else:
                if isinstance(retval, list):
                    retval = [self.lower(v + u" " + v) for v in retval]
                else:
                    retval = self.lower(retval + u" " + v)
            if join:
                retval = self.join_values(retval)

        return retval
Exemple #2
0
 def get_fullname(self):
     """Get file full path, as UTF-8 if possible."""
     if self.path or self.uri:
         ret = self.gfile.get_parse_name()
     elif self.path:
         ret = glib.filename_display_name(self.path)
         ret = ret.encode('utf8')
     elif self.uri:
         ret = self.uri
     else:
         ret = self.get_name()
     return ret
Exemple #3
0
 def set_filename(self, f):
     try:
         disp = glib.filename_display_name(f)
         pb = gtk.gdk.pixbuf_new_from_file_at_size(f, 16, 16)
     except (glib.GError, TypeError):
         # TC: Text reads as /path/to/file.ext or this when no file is chosen.
         self._label.set_text(_("(None)"))
         self._image.clear()
         self._filename = None
     else:
         self._label.set_text(disp)
         self._image.set_from_pixbuf(pb)
         self._filename = f
         self._dialog.set_filename(f)
     self.emit("filename-changed", self._filename)
Exemple #4
0
 def get_items(self):
     strip_name_first_colon = not __kupfer_settings__[
         "page_name_starts_colon"]
     for notebook_name, notebook_path in _get_zim_notebooks():
         for root, dirs, files in os.walk(notebook_path):
             # find pages in notebook
             for filename in files:
                 file_path = os.path.join(root, filename)
                 page_name, ext = os.path.splitext(file_path)
                 if not ext.lower() == ".txt":
                     continue
                 page_name = page_name.replace(notebook_path, "", 1)
                 # Ask GLib for the correct unicode representation
                 # of the page's filename
                 page_name = glib.filename_display_name(page_name)
                 if strip_name_first_colon:
                     page_name = page_name.lstrip(os.path.sep)
                 page_name = (page_name.replace(os.path.sep,
                                                u":").replace(u"_", u" "))
                 yield ZimPage(file_path, page_name, notebook_path,
                               notebook_name)
Exemple #5
0
	def get_items(self):
		strip_name_first_colon = not __kupfer_settings__["page_name_starts_colon"]
		for notebook_name, notebook_path in _get_zim_notebooks():
			for root, dirs, files in os.walk(notebook_path):
				# find pages in notebook
				for filename in files:
					file_path = os.path.join(root, filename)
					page_name, ext = os.path.splitext(file_path)
					if not ext.lower() == ".txt":
						continue
					page_name = page_name.replace(notebook_path, "", 1)
					# Ask GLib for the correct unicode representation
					# of the page's filename
					page_name = glib.filename_display_name(page_name)
					if strip_name_first_colon:
						page_name = page_name.lstrip(os.path.sep)
					page_name = (page_name
							.replace(os.path.sep, u":")
							.replace(u"_", u" "))
					yield ZimPage(file_path, page_name, notebook_path,
							notebook_name)
Exemple #6
0
    def get_tag_display(self, tag, join=True, artist_compilations=False,
            extend_title=True):
        """
            Get a tag value in a form suitable for display.

            :param tag: The name of the tag to get
            :param join: If True, joins lists of values into a
                single value.
            :param artist_compilations: If True, automatically handle
                albumartist and other compilations detections when
                tag=="albumartist".
            :param extend_title: If the title tag is unknown, try to
                add some identifying information to it.
        """
        if tag == '__loc':
            uri = gio.File(self.__tags['__loc']).get_parse_name()
            return uri.decode('utf-8')

        value = None
        if tag == "albumartist":
            if artist_compilations and self.__tags.get('__compilation'):
                value = self.__tags.get('albumartist', _VARIOUSARTISTSSTR)
            else:
                value = self.__tags.get('artist', _UNKNOWNSTR)
        elif tag in ('tracknumber', 'discnumber'):
            value = self.split_numerical(self.__tags.get(tag))[0]
        elif tag in ('__length', '__startoffset', '__stopoffset'):
            value = self.__tags.get(tag, 0)
        elif tag == '__bitrate':
            try:
                value = int(self.__tags['__bitrate']) // 1000
                if value == -1:
                    value = " "
                else:
                    #TRANSLATORS: Bitrate (k here is short for kbps).
                    value = _("%dk") % value
            except (KeyError, ValueError):
                value = " "
        elif tag == '__basename':
            value = self.get_basename()
        elif tag == '__rating':
            value = unicode(self.get_rating())
        else:
            value = self.__tags.get(tag)

        if not value:
            if tag in ['tracknumber', 'discnumber']:
                return u""
            elif tag in ('__rating', '__playcount'):
                value = "0"
            else:
                value = _UNKNOWNSTR
                if tag == 'title':
                    gloc = gio.File(self.__tags['__loc'])
                    basename = glib.filename_display_name(gloc.get_basename())
                    value = u"%s (%s)" % (value, basename)

        if isinstance(value, list):
            value = [unicode(x) for x in value]
        else:
            value = unicode(value)

        if join:
            value = self.join_values(value, _JOINSTR)

        return value
Exemple #7
0
    def get_tag_display(self,
                        tag,
                        join=True,
                        artist_compilations=True,
                        extend_title=True):
        """
            Get a tag value in a form suitable for display.

            :param tag: The name of the tag to get
            :param join: If True, joins lists of values into a
                single value.
            :param artist_compilations: If True, automatically handle
                albumartist and other compilations detections when
                tag=="artist".
            :param extend_title: If the title tag is unknown, try to
                add some identifying information to it.
        """
        if tag == '__loc':
            uri = gio.File(self.__tags['__loc']).get_parse_name()
            return uri.decode('utf-8')

        retval = None
        if tag == "artist":
            if artist_compilations and self.__tags.get('__compilation'):
                retval = self.__tags.get('albumartist', _VARIOUSARTISTSSTR)
            else:
                retval = self.__tags.get('artist', _UNKNOWNSTR)
        elif tag in ('tracknumber', 'discnumber'):
            retval = self.split_numerical(self.__tags.get(tag))[0]
        elif tag == '__length':
            retval = self.__tags.get('__length', 0)
        elif tag == '__bitrate':
            try:
                retval = int(self.__tags['__bitrate']) / 1000
                if retval == -1:
                    retval = " "
                else:
                    retval = str(retval) + "k"
            except:
                retval = " "
        else:
            retval = self.__tags.get(tag)

        if not retval:
            if tag in ['tracknumber', 'discnumber']:
                return retval
            elif tag in ('__rating', '__playcount'):
                retval = "0"
            else:
                retval = _UNKNOWNSTR
                if tag == 'title':
                    gloc = gio.File(self.__tags['__loc'])
                    basename = glib.filename_display_name(gloc.get_basename())
                    retval = u"%s (%s)" % (retval, basename)

        if isinstance(retval, list):
            retval = [unicode(x) for x in retval]
        else:
            retval = unicode(retval)

        if join:
            retval = self.join_values(retval, _JOINSTR)

        return retval
Exemple #8
0
    def get_tag_sort(self,
                     tag,
                     join=True,
                     artist_compilations=True,
                     extend_title=True):
        """
            Get a tag value in a form suitable for sorting.

            :param tag: The name of the tag to get
            :param join: If True, joins lists of values into a
                single value.
            :param artist_compilations: If True, automatically handle
                albumartist and other compilations detections when
                tag=="artist".
            :param extend_title: If the title tag is unknown, try to
                add some identifying information to it.
        """
        # The two magic values here are to ensure that compilations
        # and unknown values are always sorted below all normal
        # values.
        retval = None
        sorttag = self.__tags.get(tag + "sort")
        if sorttag and tag != "artist":
            retval = sorttag
        elif tag == "artist":
            if artist_compilations and self.__tags.get('__compilation'):
                retval = self.__tags.get('albumartist',
                                         u"\uffff\uffff\uffff\ufffe")
            else:
                retval = self.__tags.get('artist', u"\uffff\uffff\uffff\uffff")
            if sorttag and retval not in (u"\uffff\uffff\uffff\ufffe",
                                          u"\uffff\uffff\uffff\uffff"):
                retval = sorttag
            else:
                sorttag = None
        elif tag in ('tracknumber', 'discnumber'):
            retval = self.split_numerical(self.__tags.get(tag))[0]
        elif tag in ('__length', '__playcount'):
            retval = self.__tags.get(tag, 0)
        else:
            retval = self.__tags.get(tag)

        if not retval:
            retval = u"\uffff\uffff\uffff\uffff"  # unknown
            if tag == 'title':
                gloc = gio.File(self.__tags['__loc'])
                basename = glib.filename_display_name(gloc.get_basename())
                retval = u"%s (%s)" % (retval, basename)
        elif not tag.startswith("__") and \
                tag not in ('tracknumber', 'discnumber'):
            if not sorttag:
                retval = self.format_sort(retval)
            else:
                if isinstance(retval, list):
                    retval = [self.lower(v + u" " + v) for v in retval]
                else:
                    retval = self.lower(retval + u" " + v)
            if join:
                retval = self.join_values(retval)

        return retval
Exemple #9
0
    def get_tag_display(self,
                        tag,
                        join=True,
                        artist_compilations=False,
                        extend_title=True):
        """
            Get a tag value in a form suitable for display.

            :param tag: The name of the tag to get
            :param join: If True, joins lists of values into a
                single value.
            :param artist_compilations: If True, automatically handle
                albumartist and other compilations detections when
                tag=="albumartist".
            :param extend_title: If the title tag is unknown, try to
                add some identifying information to it.
        """
        if tag == '__loc':
            uri = gio.File(self.__tags['__loc']).get_parse_name()
            return uri.decode('utf-8')

        value = None
        if tag == "albumartist":
            if artist_compilations and self.__tags.get('__compilation'):
                value = self.__tags.get('albumartist', _VARIOUSARTISTSSTR)
            else:
                value = self.__tags.get('artist', _UNKNOWNSTR)
        elif tag in ('tracknumber', 'discnumber'):
            value = self.split_numerical(self.__tags.get(tag))[0]
        elif tag in ('__length', '__startoffset', '__stopoffset'):
            value = self.__tags.get(tag, 0)
        elif tag == '__bitrate':
            try:
                value = int(self.__tags['__bitrate']) // 1000
                if value == -1:
                    value = " "
                else:
                    #TRANSLATORS: Bitrate (k here is short for kbps).
                    value = _("%dk") % value
            except (KeyError, ValueError):
                value = " "
        elif tag == '__basename':
            value = self.get_basename()
        elif tag == '__rating':
            value = unicode(self.get_rating())
        else:
            value = self.__tags.get(tag)

        if not value:
            if tag in ['tracknumber', 'discnumber']:
                return u""
            elif tag in ('__rating', '__playcount'):
                value = "0"
            else:
                value = _UNKNOWNSTR
                if tag == 'title':
                    gloc = gio.File(self.__tags['__loc'])
                    basename = glib.filename_display_name(gloc.get_basename())
                    value = u"%s (%s)" % (value, basename)

        if isinstance(value, list):
            value = [unicode(x) for x in value]
        else:
            value = unicode(value)

        if join:
            value = self.join_values(value, _JOINSTR)

        return value
Exemple #10
0
    def get_tag_display(self, tag, join=True, artist_compilations=True,
            extend_title=True):
        """
            Get a tag value in a form suitable for display.

            :param tag: The name of the tag to get
            :param join: If True, joins lists of values into a
                single value.
            :param artist_compilations: If True, automatically handle
                albumartist and other compilations detections when
                tag=="artist".
            :param extend_title: If the title tag is unknown, try to
                add some identifying information to it.
        """
        if tag == '__loc':
            uri = gio.File(self.__tags['__loc']).get_parse_name()
            return uri.decode('utf-8')

        retval = None
        if tag == "artist":
            if artist_compilations and self.__tags.get('__compilation'):
                retval = self.__tags.get('albumartist', _VARIOUSARTISTSSTR)
            else:
                retval = self.__tags.get('artist', _UNKNOWNSTR)
        elif tag in ('tracknumber', 'discnumber'):
            retval = self.split_numerical(self.__tags.get(tag))[0]
        elif tag == '__length':
            retval = self.__tags.get('__length', 0)
        elif tag == '__bitrate':
            try:
                retval = int(self.__tags['__bitrate']) / 1000
                if retval == -1:
                    retval = " "
                else:
                    retval = str(retval) + "k"
            except:
                retval = " "
        else:
            retval = self.__tags.get(tag)

        if not retval:
            if tag in ['tracknumber', 'discnumber']:
                return retval
            elif tag in ('__rating', '__playcount'):
                retval = "0"
            else:
                retval = _UNKNOWNSTR
                if tag == 'title':
                    gloc = gio.File(self.__tags['__loc'])
                    basename = glib.filename_display_name(gloc.get_basename())
                    retval = u"%s (%s)" % (retval, basename)

        if isinstance(retval, list):
            retval = [unicode(x) for x in retval]
        else:
            retval = unicode(retval)

        if join:
            retval = self.join_values(retval, _JOINSTR)

        return retval