示例#1
0
    def update_format(self):
        for track in self.current_songs:
            items = [
                formatting.parse(part, track, True)
                for part in self.columnformat
            ]

            self.currentdata.append([mpdh.get(track, 'id', 0, True)] + items)
示例#2
0
	def library_populate_filesystem_data(self, path):
		# List all dirs/files at path
		bd = []
		if path == '/' and self.lib_view_filesystem_cache is not None:
			# Use cache if possible...
			bd = self.lib_view_filesystem_cache
		else:
			for item in mpdh.call(self.client, 'lsinfo', path):
				if 'directory' in item:
					name = mpdh.get(item, 'directory').split('/')[-1]
					data = self.library_set_data(path=mpdh.get(item, 'directory'))
					bd += [('d' + unicode(name).lower(), [self.openpb, data, misc.escape_html(name)])]
				elif 'file' in item:
					data = self.library_set_data(path=mpdh.get(item, 'file'))
					bd += [('f' + unicode(mpdh.get(item, 'file')).lower(), [self.sonatapb, data, formatting.parse(self.config.libraryformat, item, True)])]
			bd.sort(key=operator.itemgetter(0))
			if path != '/' and len(bd) > 0:
				bd = self.library_populate_add_parent_rows() + bd
			if path == '/': 
				self.lib_view_filesystem_cache = bd
		return bd
示例#3
0
    def current_update(self, prevstatus_playlist, new_playlist_length):
        if self.connected():

            if self.sonata_loaded():
                playlistposition = self.current.get_visible_rect()[1]

            self.current.freeze_child_notify()

            if not self.current_update_skip:

                if not self.filterbox_visible:
                    self.current.set_model(None)

                if prevstatus_playlist:
                    changed_songs = mpdh.call(self.client, 'plchanges',
                                              prevstatus_playlist)
                else:
                    changed_songs = mpdh.call(self.client, 'plchanges', 0)
                    self.current_songs = []

                newlen = int(new_playlist_length)
                currlen = len(self.currentdata)

                for track in changed_songs:
                    pos = mpdh.get(track, 'pos', 0, True)

                    items = [
                        formatting.parse(part, track, True)
                        for part in self.columnformat
                    ]

                    if pos < currlen:
                        # Update attributes for item:
                        i = self.currentdata.get_iter((pos, ))
                        trackid = mpdh.get(track, 'id', 0, True)
                        if trackid != self.currentdata.get_value(i, 0):
                            self.currentdata.set_value(i, 0, trackid)
                        for index in range(len(items)):
                            if items[index] != self.currentdata.get_value(
                                    i, index + 1):
                                self.currentdata.set_value(
                                    i, index + 1, items[index])
                        self.current_songs[pos] = track
                    else:
                        # Add new item:
                        self.currentdata.append(
                            [mpdh.get(track, 'id', 0, True)] + items)
                        self.current_songs.append(track)

                if newlen == 0:
                    self.currentdata.clear()
                    self.current_songs = []
                else:
                    # Remove excess songs:
                    for i in range(currlen - newlen):
                        it = self.currentdata.get_iter((currlen - 1 - i, ))
                        self.currentdata.remove(it)
                    self.current_songs = self.current_songs[:newlen]

                if not self.filterbox_visible:
                    self.current.set_model(self.currentdata)

            self.current_update_skip = False

            # Update statusbar time:
            self.total_time = 0
            for track in self.current_songs:
                try:
                    self.total_time = self.total_time + mpdh.get(
                        track, 'time', 0, True)
                except:
                    pass

            if 'pos' in self.songinfo():
                currsong = mpdh.get(self.songinfo(), 'pos', 0, True)
                self.boldrow(currsong)
                self.prev_boldrow = currsong

            if self.filterbox_visible:
                # Refresh filtered results:
                self.prevtodo = "RETAIN_POS_AND_SEL"  # Hacky, but this ensures we retain the self.current position/selection
                self.plpos = playlistposition
                self.searchfilter_feed_loop(self.filterpattern)
            elif self.sonata_loaded():
                self.playlist_retain_view(self.current, playlistposition)
                self.current.thaw_child_notify()

            self.header_update_column_indicators()
            self.update_statusbar()
            ui.change_cursor(None)
示例#4
0
	def library_populate_data_songs(self, genre, artist, album, year):
		bd = []
		if genre is not None:
			songs, _playtime, _num_songs = self.library_return_search_items(genre=genre, artist=artist, album=album, year=year)
		else:
			songs, _playtime, _num_songs = self.library_return_search_items(artist=artist, album=album, year=year)
		for song in songs:
			data = self.library_set_data(path=mpdh.get(song, 'file'))
			track = mpdh.get(song, 'track', '99', False, 2)
			disc = mpdh.get(song, 'disc', '99', False, 2)
			try:
				bd += [('f' + disc + track + misc.lower_no_the(mpdh.get(song, 'title')), [self.sonatapb, data, formatting.parse(self.config.libraryformat, song, True)])]
			except:
				bd += [('f' + disc + track + unicode(mpdh.get(song, 'file')).lower(), [self.sonatapb, data, formatting.parse(self.config.libraryformat, song, True)])]
		return bd
示例#5
0
	def libsearchfilter_do_search(self, searchby, todo):
		if not self.prevlibtodo_base in todo:
			# Do library search based on first two letters:
			self.prevlibtodo_base = todo[:2]
			self.prevlibtodo_base_results = mpdh.call(self.client, 'search', searchby, self.prevlibtodo_base)
			subsearch = False
		else:
			subsearch = True

		# Now, use filtering similar to playlist filtering:
		# this make take some seconds... and we'll escape the search text because
		# we'll be searching for a match in items that are also escaped.
		#
		# Note that the searching is not order specific. That is, "foo bar"
		# will match on "fools bar" and "barstool foo".

		todos = todo.split(" ")
		regexps = []
		for i in range(len(todos)):
			todos[i] = misc.escape_html(todos[i])
			todos[i] = re.escape(todos[i])
			todos[i] = '.*' + todos[i].lower()
			regexps.append(re.compile(todos[i]))
		matches = []
		if searchby != 'any':
			for row in self.prevlibtodo_base_results:
				is_match = True
				for regexp in regexps:
					if not regexp.match(unicode(mpdh.get(row, searchby)).lower()):
						is_match = False
						break
				if is_match:
					matches.append(row)
		else:
			for row in self.prevlibtodo_base_results:
				allstr = " ".join(mpdh.get(row, meta) for meta in row)
				is_match = True
				for regexp in regexps:
					if not regexp.match(unicode(allstr).lower()):
						is_match = False
						break
				if is_match:
					matches.append(row)
		if subsearch and len(matches) == len(self.librarydata):
			# nothing changed..
			return
		self.library.freeze_child_notify()
		currlen = len(self.librarydata)
		bd = [[self.sonatapb,
		       self.library_set_data(path=mpdh.get(item, 'file')),
		       formatting.parse(self.config.libraryformat, item, True)]
		      for item in matches if 'file' in item]
		bd.sort(locale.strcoll, key=operator.itemgetter(2))
		for i, item in enumerate(bd):
			if i < currlen:
				j = self.librarydata.get_iter((i, ))
				for index in range(len(item)):
					if item[index] != self.librarydata.get_value(j, index):
						self.librarydata.set_value(j, index, item[index])
			else:
				self.librarydata.append(item)
		# Remove excess items...
		newlen = len(bd)
		if newlen == 0:
			self.librarydata.clear()
		else:
			for i in range(currlen-newlen):
				j = self.librarydata.get_iter((currlen-1-i,))
				self.librarydata.remove(j)
		self.library.thaw_child_notify()
		if len(matches) == 0:
			gobject.idle_add(self.filtering_entry_make_red, self.searchtext)
		else:
			gobject.idle_add(self.library.set_cursor,'0')
			gobject.idle_add(self.filtering_entry_revert_color, self.searchtext)
示例#6
0
    def current_update(self, prevstatus_playlist, new_playlist_length):
        if self.connected():

            if self.sonata_loaded():
                playlistposition = self.current.get_visible_rect()[1]

            self.current.freeze_child_notify()

            if not self.current_update_skip:

                if not self.filterbox_visible:
                    self.current.set_model(None)

                if prevstatus_playlist:
                    changed_songs = mpdh.call(self.client, 'plchanges', prevstatus_playlist)
                else:
                    changed_songs = mpdh.call(self.client, 'plchanges', 0)
                    self.current_songs = []

                newlen = int(new_playlist_length)
                currlen = len(self.currentdata)

                for track in changed_songs:
                    pos = mpdh.get(track, 'pos', 0, True)

                    items = [formatting.parse(part, track,
                                  True)
                         for part in self.columnformat]
                    if self.aimp_headers:
                        items += [""]

                    if pos < currlen:
                        # Update attributes for item:
                        i = self.currentdata.get_iter((pos, ))
                        trackid = mpdh.get(track, 'id',
                                    0, True)
                        if trackid != self.currentdata.get_value(i, 0):
                            self.currentdata.set_value(i, 0, trackid)
                        for index in range(len(items)):
                            if items[index] != self.currentdata.get_value(i, index + 1):
                                self.currentdata.set_value(i, index + 1, items[index])
                        if pos < len(self.current_songs):
                            self.current_songs[pos] = track
                        elif pos == len(self.current_songs):
                            self.current_songs.append(track)
                        else:
                            raise Exception
                    else:
                        # Add new item:
                        self.currentdata.append([mpdh.get(track, 'id', 0, True)] + items)
                        self.current_songs.append(track)

                if newlen == 0:
                    self.currentdata.clear()
                    self.current_songs = []
                else:
                    # Remove excess songs:
                    for i in range(currlen-newlen):
                        it = self.currentdata.get_iter((currlen-1-i,))
                        self.currentdata.remove(it)
                    self.current_songs = self.current_songs[:newlen]

                if not self.filterbox_visible:
                    self.current.set_model(self.currentdata)

            self.current_update_skip = False

            # Update AIMP headers
            if len(self.current_songs) > 0:
                self.currentdata.set_value(self.currentdata.get_iter(0), len(self.columnformat)+1, aimpheaders.by_filename(mpdh.get(self.current_songs[0], 'file')))
                for i in range(1, len(self.current_songs)):
                    this_header = aimpheaders.by_filename(mpdh.get(self.current_songs[i], 'file'))
                    prev_header = aimpheaders.by_filename(mpdh.get(self.current_songs[i-1], 'file'))
                    if this_header != prev_header:
                        self.currentdata.set_value(self.currentdata.get_iter(i), len(self.columnformat)+1, this_header)
                    else:
                        self.currentdata.set_value(self.currentdata.get_iter(i), len(self.columnformat)+1, '')

            # Update statusbar time:
            self.total_time = 0
            for track in self.current_songs:
                try:
                    self.total_time = self.total_time + mpdh.get(track, 'time', 0, True)
                except:
                    pass

            if 'pos' in self.songinfo():
                currsong = mpdh.get(self.songinfo(), 'pos', 0,
                            True)
                self.boldrow(currsong)
                self.prev_boldrow = currsong

            if self.filterbox_visible:
                # Refresh filtered results:
                self.prevtodo = "RETAIN_POS_AND_SEL" # Hacky, but this ensures we retain the self.current position/selection
                self.plpos = playlistposition
                self.searchfilter_feed_loop(self.filterpattern)
            elif self.sonata_loaded():
                self.playlist_retain_view(self.current, playlistposition)
                self.current.thaw_child_notify()

            self.header_update_column_indicators()
            self.update_statusbar()
            ui.change_cursor(None)
示例#7
0
    def update_format(self):
        for track in self.current_songs:
            items = [formatting.parse(part, track, True)
                 for part in self.columnformat]

            self.currentdata.append([mpdh.get(track, 'id', 0, True)] + items)