Fix up add from database dialog

This commit is contained in:
Keith Edmunds 2021-04-10 12:25:21 +01:00
parent 301bee4ba5
commit 9ee5730b14
2 changed files with 72 additions and 57 deletions

View File

@ -781,6 +781,9 @@ class DbDialog(QDialog):
self.ui.setupUi(self)
self.ui.searchString.textEdited.connect(self.chars_typed)
self.ui.matchList.itemDoubleClicked.connect(self.double_click)
self.ui.btnAdd.clicked.connect(self.add_selected)
self.ui.btnAddClose.clicked.connect(self.add_selected_and_close)
self.ui.btnClose.clicked.connect(self.close)
record = Settings.get_int("dbdialog_width")
width = record.f_int or 800
@ -797,6 +800,18 @@ class DbDialog(QDialog):
if record.f_int != self.width():
record.update({'f_int': self.width()})
def add_selected(self):
if not self.ui.matchList.selectedItems():
return
item = self.ui.matchList.currentItem()
track_id = item.data(Qt.UserRole)
self.add_track(track_id)
def add_selected_and_close(self):
self.add_selected()
self.close()
def chars_typed(self, s):
if len(s) >= 3:
matches = Tracks.search_titles(s)
@ -813,8 +828,10 @@ class DbDialog(QDialog):
def double_click(self, entry):
track_id = entry.data(Qt.UserRole)
track = Tracks.track_from_id(track_id)
self.add_track(track_id)
def add_track(self, track_id):
track = Tracks.track_from_id(track_id)
# Store in current playlist in database
db_playlist = Playlists.get_playlist_by_id(self.parent().playlist_id)
db_playlist.add_track(track)

View File

@ -15,8 +15,6 @@
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label">
@ -30,56 +28,56 @@
</item>
</layout>
</item>
<item row="1" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="matchList"/>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<property name="sizeHint" stdset="0">
<size>
<width>88</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="btnAdd">
<property name="text">
<string>&amp;Add</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnAddClose">
<property name="text">
<string>A&amp;dd and close</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnClose">
<property name="text">
<string>&amp;Close</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
<connections/>
</ui>