From 20eb62db4b2ee132777fe7fda809d0b7163c15cd Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 29 Aug 2010 13:52:59 +0200 Subject: Library: move folding patter selection to the widget itself with this the settings widget for library can go --- nephilim/plugins/Library.py | 103 +++++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 50 deletions(-) diff --git a/nephilim/plugins/Library.py b/nephilim/plugins/Library.py index 0e2b153..3ff6242 100644 --- a/nephilim/plugins/Library.py +++ b/nephilim/plugins/Library.py @@ -29,7 +29,7 @@ class Library(Plugin): o = None # private - DEFAULTS = {'grouping' : ['albumartist', 'album']} + DEFAULTS = {'foldings' : ['albumartist/album'], 'cur_folding' : 0} def _load(self): self.o = LibraryWidget(self) @@ -44,53 +44,10 @@ class Library(Plugin): return self.o.fill_library() - class SettingsWidgetLibrary(Plugin.SettingsWidget): - taglist = None - def __init__(self, plugin): - Plugin.SettingsWidget.__init__(self, plugin) - self.settings.beginGroup(self.plugin.name) - - tags_enabled = self.settings.value('grouping') - tags = self.plugin.mpclient.tagtypes - self.taglist = QtGui.QListWidget(self) - self.taglist.setDragDropMode(QtGui.QAbstractItemView.InternalMove) - for tag in [tag for tag in tags_enabled if tag in tags]: - it = QtGui.QListWidgetItem(tag) - it.setCheckState(QtCore.Qt.Checked) - self.taglist.addItem(it) - for tag in [tag for tag in tags if tag not in tags_enabled]: - it = QtGui.QListWidgetItem(tag) - it.setCheckState(QtCore.Qt.Unchecked) - self.taglist.addItem(it) - - self.setLayout(QtGui.QVBoxLayout()) - self._add_widget(self.taglist, label = 'Group', tooltip = 'Checked items and their order determines,\n' - 'by what tags will songs be grouped in Library. Use drag and drop to change the\n' - 'order of tags.') - - self.settings.endGroup() - - def save_settings(self): - self.settings.beginGroup(self.plugin.name) - - tags = [] - for i in range(self.taglist.count()): - it = self.taglist.item(i) - if it.checkState() == QtCore.Qt.Checked: - tags.append(it.text()) - self.settings.setValue('grouping', tags) - - self.settings.endGroup() - self.plugin.fill_library() - - def get_settings_widget(self): - return self.SettingsWidgetLibrary(self) - class LibraryWidget(QtGui.QWidget): library_view = None library_model = None search_txt = None - grouping = None settings = None plugin = None logger = None @@ -108,7 +65,15 @@ class LibraryWidget(QtGui.QWidget): self.filtered_items = [] self.settings.beginGroup(self.plugin.name) - self.grouping = QtGui.QLabel() + # folding widgets + self.foldings = LibraryFolding(self.plugin, self) + self.foldings.activated.connect(self.fill_library) + del_folding = QtGui.QPushButton(QtGui.QIcon(':icons/delete.png'), '') + del_folding.setToolTip('Delete current folding pattern.') + del_folding.clicked.connect(lambda :self.foldings.removeItem(self.foldings.currentIndex())) + folding_layout = QtGui.QHBoxLayout() + folding_layout.addWidget(self.foldings, stretch = 1) + folding_layout.addWidget(del_folding) self.search_txt = QtGui.QLineEdit() self.search_txt.setToolTip('Filter library') @@ -126,7 +91,7 @@ class LibraryWidget(QtGui.QWidget): self.setLayout(QtGui.QVBoxLayout()) self.layout().setSpacing(2) self.layout().setMargin(0) - self.layout().addWidget(self.grouping) + self.layout().addLayout(folding_layout) self.layout().addWidget(self.search_txt) self.layout().addWidget(self.library_view) @@ -134,8 +99,7 @@ class LibraryWidget(QtGui.QWidget): def fill_library(self): self.logger.info('Refreshing library.') - self.grouping.setText('/'.join(self.settings.value('grouping'))) - self.plugin.mpclient.database(lambda songs: self.library_model.fill(songs, self.settings.value('grouping'))) + self.plugin.mpclient.database(lambda songs: self.library_model.fill(songs, self.foldings.currentText().split('/'))) @Slot(unicode) def filter_library(self, text): @@ -199,13 +163,13 @@ class LibrarySongItem(QtGui.QStandardItem): path = None class LibraryModel(QtGui.QStandardItemModel): - def fill(self, songs, grouping): + def fill(self, songs, folding): self.clear() tree = [{},self.invisibleRootItem()] for song in songs: cur_item = tree - for part in grouping: + for part in folding: try: tag = song[part] except KeyError: @@ -261,3 +225,42 @@ class LibraryView(QtGui.QTreeView): self.setUniformRowHeights(True) self.setHeaderHidden(True) self.setDragEnabled(True) + +class LibraryFolding(QtGui.QComboBox): + + #### PRIVATE #### + _plugin = None + _settings = None + + #### PUBLIC #### + + def __init__(self, plugin, parent): + QtGui.QComboBox.__init__(self, parent) + self.setEditable(True) + self.setToolTip('Current folding pattern.') + + self._plugin = plugin + + # fill with stored folding patterns, ensure at least an empty string + self._settings = QtCore.QSettings() + self._settings.beginGroup(self._plugin.name) + for item in self._settings.value('foldings'): + self.addItem(item) + if not self.count(): + self.addItem('') + self.setCurrentIndex(int(self._settings.value('cur_folding'))) + + # connect signals to slots + self.currentIndexChanged.connect( self._update_foldings) + self.model().rowsInserted.connect(self._update_foldings) + self.model().rowsRemoved.connect( self._update_foldings) + self.model().rowsMoved.connect( self._update_foldings) + + #### PRIVATE #### + @Slot() + def _update_foldings(self): + foldings = [] + for i in xrange(self.count()): + foldings.append(self.itemText(i)) + self._settings.setValue('foldings', foldings) + self._settings.setValue('cur_folding', self.currentIndex()) -- cgit v1.2.3