diff options
author | Arno <arno@disconnect.de> | 2017-10-15 09:17:50 +0200 |
---|---|---|
committer | Arno <arno@disconnect.de> | 2017-10-15 09:17:50 +0200 |
commit | 1bcbd9e93eadcffec21d32100b70310abec9a58f (patch) | |
tree | 674920d3f07992fcf0e77a5bdbf43c98aaa6f58c | |
parent | 7e1ebd90789ae1d9d9fdfc54988aad722667df4c (diff) | |
download | BeetPlayer-1bcbd9e93eadcffec21d32100b70310abec9a58f.tar.gz BeetPlayer-1bcbd9e93eadcffec21d32100b70310abec9a58f.tar.bz2 BeetPlayer-1bcbd9e93eadcffec21d32100b70310abec9a58f.zip |
Fix WebRadioDialog
Revamp the WebRadio Dialog: Make it possible to delete WebRadios.
-rw-r--r-- | playerwidget.cpp | 15 | ||||
-rw-r--r-- | playerwidget.h | 2 | ||||
-rw-r--r-- | webradiodialog.cpp | 110 | ||||
-rw-r--r-- | webradiodialog.h | 11 |
4 files changed, 111 insertions, 27 deletions
diff --git a/playerwidget.cpp b/playerwidget.cpp index 3637560..a633fbd 100644 --- a/playerwidget.cpp +++ b/playerwidget.cpp @@ -382,8 +382,8 @@ void PlayerWidget::createActions(){ connect(miscMusicBrainzLeftA, &QAction::triggered, this, &PlayerWidget::searchMusicbrainzLeft); QAction *miscFilterFromPlaylistA = new QAction(QIcon(":/chastity_belt.png"), tr("Filter artist"), this); connect(miscFilterFromPlaylistA, &QAction::triggered, this, &PlayerWidget::filterFromPlaylist); - QAction *addToWebRadioA = new QAction(QIcon(":/dog_hood.png"), tr("Add Webradio"), this); - connect(addToWebRadioA, &QAction::triggered, this, &PlayerWidget::addWebRadio); + QAction *addToWebRadioA = new QAction(QIcon(":/dog_hood.png"), tr("Edit Webradio..."), this); + connect(addToWebRadioA, &QAction::triggered, this, &PlayerWidget::editWebradio); QAction *addToFavoritesA = new QAction(QIcon(":/male_chastity_belt.png"), tr("Add to Favorites"), this); connect(addToFavoritesA, &QAction::triggered, this, &PlayerWidget::addToFavorites); mView->addAction(addToPlayListA); @@ -1517,17 +1517,10 @@ void PlayerWidget::filterFromPlaylist(){ doFilter(); } -void PlayerWidget::addWebRadio(){ +void PlayerWidget::editWebradio(){ WebRadioDialog dlg(this); dlg.exec(); - QString desc = dlg.description(); - QString url = dlg.url(); - QSqlDatabase db = QSqlDatabase::database("beetplayerdb"); - QSqlQuery wrQ(db); - wrQ.prepare("INSERT INTO webradio (tdescription, turl) VALUES(:d, :u)"); - wrQ.bindValue(":d", desc); - wrQ.bindValue(":u", url); - wrQ.exec(); + doPopulateByWebradio(); } void PlayerWidget::doMetadataChange(const QString &key, const QVariant &value){ diff --git a/playerwidget.h b/playerwidget.h index 4fa8490..93efc2c 100644 --- a/playerwidget.h +++ b/playerwidget.h @@ -78,7 +78,7 @@ class PlayerWidget : public QWidget { void searchMusicbrainzLeft(); void webDlDone(); void filterFromPlaylist(); - void addWebRadio(); + void editWebradio(); void doMetadataChange(const QString &key, const QVariant &value); void updateStreamData(); diff --git a/webradiodialog.cpp b/webradiodialog.cpp index 4e08627..25578cc 100644 --- a/webradiodialog.cpp +++ b/webradiodialog.cpp @@ -2,28 +2,110 @@ #include <QHBoxLayout> #include <QFormLayout> #include <QPushButton> +#include <QSqlQuery> +#include <QGroupBox> #include <QApplication> #include "webradiodialog.h" WebRadioDialog::WebRadioDialog(QWidget *parent, Qt::WindowFlags f) : QDialog(parent, f){ + //available + mModel = new QStandardItemModel; + mView = new QTreeView; + mView->setModel(mModel); + mView->setSelectionBehavior(QAbstractItemView::SelectRows); + mView->setSelectionMode(QAbstractItemView::SingleSelection); + QGroupBox *availGB = new QGroupBox(tr("Available")); + QVBoxLayout *availL = new QVBoxLayout; + availL->addWidget(mView); + QHBoxLayout *availBL = new QHBoxLayout; + QPushButton *deleteBtn = new QPushButton(tr("Delete selected...")); + connect(deleteBtn, &QPushButton::clicked, this, &WebRadioDialog::deleteSelected); + availBL->addStretch(); + availBL->addWidget(deleteBtn); + availL->addLayout(availBL); + availGB->setLayout(availL); + + //add + QGroupBox *addGB = new QGroupBox(tr("Add")); mDescription = new QLineEdit; mUrl = new QLineEdit; - QFormLayout *topL = new QFormLayout; - topL->addRow(tr("&Description:"), mDescription); - topL->addRow(tr("&Url:"), mUrl); - QPushButton *okB = new QPushButton(tr("OK")); - connect(okB, &QPushButton::clicked, this, &QDialog::accept); - QPushButton *cancelB = new QPushButton(tr("Cancel")); - connect(cancelB, &QPushButton::clicked, this, &QDialog::reject); - QHBoxLayout *buttonL = new QHBoxLayout; - buttonL->addStretch(); - buttonL->addWidget(okB); - buttonL->addWidget(cancelB); + QFormLayout *addFormL = new QFormLayout; + addFormL->addRow(tr("&Description:"), mDescription); + addFormL->addRow(tr("&Url:"), mUrl); + QPushButton *addBtn = new QPushButton(tr("Add")); + QPushButton *doneBtn = new QPushButton(tr("Done")); + connect(addBtn, &QPushButton::clicked, this, &WebRadioDialog::add); + connect(doneBtn, &QPushButton::clicked, this, &QDialog::accept); + QHBoxLayout *addBtnL = new QHBoxLayout; + addBtnL->addWidget(doneBtn); + addBtnL->addStretch(); + addBtnL->addWidget(addBtn); + QVBoxLayout *addL = new QVBoxLayout; + addL->addLayout(addFormL); + addL->addLayout(addBtnL); + addGB->setLayout(addL); + QVBoxLayout *mainL = new QVBoxLayout; - mainL->addLayout(topL); - mainL->addLayout(buttonL); + mainL->addWidget(availGB); + mainL->addWidget(addGB); setLayout(mainL); - setWindowTitle(QString(tr("%1 - Add WebRadio")).arg(qApp->applicationName())); + setWindowTitle(QString(tr("%1 - Edit WebRadio")).arg(qApp->applicationName())); setMinimumWidth(768); + populate(); +} + +void WebRadioDialog::populate(){ + QSqlDatabase db = QSqlDatabase::database("beetplayerdb"); + mModel->clear(); + mModel->setHorizontalHeaderLabels(QStringList() << tr("Description") << tr("URL")); + QStandardItem *root = mModel->invisibleRootItem(); + QIcon wrIcon(":/dog_hood.png"); + QSqlQuery wrQ = QSqlQuery(db); + wrQ.prepare("SELECT tdescription, turl FROM webradio ORDER BY tdescription DESC"); + wrQ.exec(); + while(wrQ.next()){ + QStandardItem *curDescr = new QStandardItem; + curDescr->setIcon(wrIcon); + curDescr->setText(wrQ.value(0).toString()); + curDescr->setData(wrQ.value(0), DescriptionRole); + curDescr->setData(wrQ.value(1), UrlRole); + curDescr->setFont(QFont("courier")); + QStandardItem *curUrl = new QStandardItem; + curUrl->setText(wrQ.value(1).toString()); + curUrl->setFont(QFont("courier")); + root->appendRow(QList<QStandardItem*>() << curDescr << curUrl); + } + mView->resizeColumnToContents(1); + mView->resizeColumnToContents(0); +} + +void WebRadioDialog::deleteSelected(){ + QModelIndexList sel = mView->selectionModel()->selectedRows(); + if(sel.isEmpty()){ + return; + } + QVariant descr = sel.at(0).data(DescriptionRole); + QVariant url = sel.at(0).data(UrlRole); + QSqlDatabase db = QSqlDatabase::database("beetplayerdb"); + QSqlQuery delQ(db); + delQ.prepare("DELETE FROM webradio WHERE tdescription = :descr AND turl = :url"); + delQ.bindValue(":descr", descr); + delQ.bindValue(":url", url); + delQ.exec(); + populate(); +} + +void WebRadioDialog::add(){ + QString descr = mDescription->text(); + QString url = mUrl->text(); + if(!descr.isEmpty() && !url.isEmpty()){ + QSqlDatabase db = QSqlDatabase::database("beetplayerdb"); + QSqlQuery addQ(db); + addQ.prepare("INSERT INTO webradio (tdescription, turl) VALUES(:d, :u)"); + addQ.bindValue(":d", descr); + addQ.bindValue(":u", url); + addQ.exec(); + } + populate(); } diff --git a/webradiodialog.h b/webradiodialog.h index 96262dd..906edcb 100644 --- a/webradiodialog.h +++ b/webradiodialog.h @@ -3,18 +3,27 @@ #include <QDialog> #include <QLineEdit> +#include <QTreeView> +#include <QStandardItemModel> class WebRadioDialog : public QDialog { Q_OBJECT public: + enum WrRole { DescriptionRole, UrlRole }; explicit WebRadioDialog(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); const QString description() { return mDescription->text(); } const QString url() { return mUrl->text(); } + private slots: + void populate(); + void deleteSelected(); + void add(); + private: QLineEdit *mDescription; QLineEdit *mUrl; - + QStandardItemModel *mModel; + QTreeView *mView; }; #endif // WEBRADIODIALOG_H |