From fc03804ef77762ef3f6e3dd9f9190f7390ffed1f Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Sat, 29 Sep 2018 14:40:09 +0000 Subject: improved streambrowser plugin git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@8383 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/General/streambrowser/CMakeLists.txt | 4 +- .../General/streambrowser/editstreamdialog.cpp | 76 +++++++++++ .../General/streambrowser/editstreamdialog.h | 62 +++++++++ .../General/streambrowser/editstreamdialog.ui | 147 +++++++++++++++++++++ .../General/streambrowser/streambrowser.pro | 9 +- src/plugins/General/streambrowser/streamwindow.cpp | 83 +++++++++++- src/plugins/General/streambrowser/streamwindow.h | 4 + 7 files changed, 374 insertions(+), 11 deletions(-) create mode 100644 src/plugins/General/streambrowser/editstreamdialog.cpp create mode 100644 src/plugins/General/streambrowser/editstreamdialog.h create mode 100644 src/plugins/General/streambrowser/editstreamdialog.ui diff --git a/src/plugins/General/streambrowser/CMakeLists.txt b/src/plugins/General/streambrowser/CMakeLists.txt index 380880d2f..392b47a6c 100644 --- a/src/plugins/General/streambrowser/CMakeLists.txt +++ b/src/plugins/General/streambrowser/CMakeLists.txt @@ -11,9 +11,10 @@ SET(libstreambrowser_SRCS streambrowser.cpp streambrowserfactory.cpp streamwindow.cpp + editstreamdialog.cpp ) -SET(libstreambrowser_RCCS +SET(libstreambrowser_RCCS translations/translations.qrc) QT5_ADD_RESOURCES(libstreambrowser_RCC_SRCS ${libstreambrowser_RCCS}) @@ -22,6 +23,7 @@ QT5_ADD_RESOURCES(libstreambrowser_RCC_SRCS ${libstreambrowser_RCCS}) SET(libstreambrowser_UIS streamwindow.ui + editstreamdialog.ui ) QT5_WRAP_UI(libstreambrowser_UIS_H ${libstreambrowser_UIS}) diff --git a/src/plugins/General/streambrowser/editstreamdialog.cpp b/src/plugins/General/streambrowser/editstreamdialog.cpp new file mode 100644 index 000000000..132738111 --- /dev/null +++ b/src/plugins/General/streambrowser/editstreamdialog.cpp @@ -0,0 +1,76 @@ +/*************************************************************************** + * Copyright (C) 2018 by Ilya Kotov * + * forkotov02@ya.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include +#include +#include "editstreamdialog.h" +#include "ui_editstreamdialog.h" + +EditStreamDialog::EditStreamDialog(QWidget *parent) : + QDialog(parent), + m_ui(new Ui::EditStreamDialog) +{ + m_ui->setupUi(this); + connect(m_ui->nameLineEdit, SIGNAL(textChanged(QString)), SLOT(validate())); + connect(m_ui->urlLineEdit, SIGNAL(textChanged(QString)), SLOT(validate())); + m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + m_ui->typeComboBox->addItems(QStringList() + << "application/ogg" + << "audio/aac" + << "audio/aacp" + << "audio/mpeg"); +} + +EditStreamDialog::~EditStreamDialog() +{ + delete m_ui; +} + +void EditStreamDialog::accept() +{ + m_values[URL] = m_ui->urlLineEdit->text(); + m_values[NAME] = m_ui->nameLineEdit->text(); + m_values[GENRE] = m_ui->genreLineEdit->text(); + m_values[BITRATE] = m_ui->bitrateLineEdit->text(); + m_values[TYPE] = m_ui->typeComboBox->currentText(); + QDialog::accept(); +} + +void EditStreamDialog::setValues(const QMap &values) +{ + m_values = values; + m_ui->urlLineEdit->setText(values.value(URL)); + m_ui->nameLineEdit->setText(values.value(NAME)); + m_ui->genreLineEdit->setText(values.value(GENRE)); + m_ui->bitrateLineEdit->setText(values.value(BITRATE)); + m_ui->typeComboBox->setEditText(values.value(TYPE)); +} + +const QMap &EditStreamDialog::values() const +{ + return m_values; +} + +void EditStreamDialog::validate() +{ + bool ok = !m_ui->nameLineEdit->text().isEmpty(); + ok &= QUrl(m_ui->urlLineEdit->text()).isValid(); + m_ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ok); +} diff --git a/src/plugins/General/streambrowser/editstreamdialog.h b/src/plugins/General/streambrowser/editstreamdialog.h new file mode 100644 index 000000000..a0e24ce3a --- /dev/null +++ b/src/plugins/General/streambrowser/editstreamdialog.h @@ -0,0 +1,62 @@ +/*************************************************************************** + * Copyright (C) 2018 by Ilya Kotov * + * forkotov02@ya.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef EDITSTREAMDIALOG_H +#define EDITSTREAMDIALOG_H + +#include +#include + +namespace Ui { +class EditStreamDialog; +} + +class EditStreamDialog : public QDialog +{ + Q_OBJECT + +public: + explicit EditStreamDialog(QWidget *parent = 0); + ~EditStreamDialog(); + + enum Key + { + URL = 0, + NAME, + GENRE, + BITRATE, + TYPE + }; + +public slots: + void accept(); + + void setValues(const QMap &values); + const QMap &values() const; + +private slots: + void validate(); + +private: + Ui::EditStreamDialog *m_ui; + QMap m_values; +}; + +#endif // EDITSTREAMDIALOG_H diff --git a/src/plugins/General/streambrowser/editstreamdialog.ui b/src/plugins/General/streambrowser/editstreamdialog.ui new file mode 100644 index 000000000..02dd40811 --- /dev/null +++ b/src/plugins/General/streambrowser/editstreamdialog.ui @@ -0,0 +1,147 @@ + + + EditStreamDialog + + + + 0 + 0 + 396 + 214 + + + + Edit Stream + + + + 6 + + + 6 + + + 6 + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + URL: + + + + + + + + + + Name: + + + + + + + + + + Genre: + + + + + + + + + + Bitrate: + + + + + + + + + + Type: + + + + + + + true + + + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + EditStreamDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + EditStreamDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/src/plugins/General/streambrowser/streambrowser.pro b/src/plugins/General/streambrowser/streambrowser.pro index 77d550055..9861ea1f1 100644 --- a/src/plugins/General/streambrowser/streambrowser.pro +++ b/src/plugins/General/streambrowser/streambrowser.pro @@ -6,13 +6,16 @@ QT += network HEADERS += streambrowserfactory.h \ streambrowser.h \ - streamwindow.h + streamwindow.h \ + editstreamdialog.h SOURCES += streambrowserfactory.cpp \ streambrowser.cpp \ - streamwindow.cpp + streamwindow.cpp \ + editstreamdialog.cpp -FORMS += streamwindow.ui +FORMS += streamwindow.ui \ + editstreamdialog.ui RESOURCES = translations/translations.qrc diff --git a/src/plugins/General/streambrowser/streamwindow.cpp b/src/plugins/General/streambrowser/streamwindow.cpp index a367fa9a9..6bf73f6d4 100644 --- a/src/plugins/General/streambrowser/streamwindow.cpp +++ b/src/plugins/General/streambrowser/streamwindow.cpp @@ -31,10 +31,12 @@ #include #include #include +#include #include #include #include #include +#include "editstreamdialog.h" #include "ui_streamwindow.h" #include "streamwindow.h" @@ -125,19 +127,24 @@ StreamWindow::StreamWindow(QWidget *parent) readXml(&file2, m_favoritesModel); //create menus m_iceCastMenu = new QMenu(this); - m_iceCastMenu->addAction(tr("&Add to favorites"), this, SLOT(addToFavorites())); - QAction *addAction = m_iceCastMenu->addAction(tr("&Add to playlist"), this, - SLOT(on_addPushButton_clicked())); + m_addToFavoritesAction = m_iceCastMenu->addAction(QIcon::fromTheme("user-bookmarks"), tr("&Add to favorites"), + this, SLOT(addToFavorites())); + m_addAction = m_iceCastMenu->addAction(QIcon::fromTheme("list-add"), + tr("&Add to playlist"), this, SLOT(on_addPushButton_clicked())); m_favoritesMenu = new QMenu(this); - m_favoritesMenu->addAction(addAction); + m_favoritesMenu->addAction(m_addAction); + m_favoritesMenu->addAction(QIcon::fromTheme("document-new"), tr("&Create"), + this, SLOT(createStream())); + m_editAction = m_favoritesMenu->addAction(QIcon::fromTheme("document-properties"), tr("&Edit"), + this, SLOT(editStream())); m_favoritesMenu->addSeparator(); - m_favoritesMenu->addAction(tr("&Remove"), this, SLOT(removeFromFavorites()), QKeySequence::Delete); + m_removeAction = m_favoritesMenu->addAction(QIcon::fromTheme("edit-delete"), tr("&Remove"), + this, SLOT(removeFromFavorites()), QKeySequence::Delete); addActions(m_favoritesMenu->actions()); } StreamWindow::~StreamWindow() -{ -} +{} void StreamWindow::showText(QNetworkReply *reply) { @@ -201,11 +208,17 @@ void StreamWindow::on_filterLineEdit_textChanged(const QString &text) void StreamWindow::execIceCastMenu(const QPoint &pos) { + QModelIndex index = m_ui->icecastTableView->selectionModel()->currentIndex(); + m_addToFavoritesAction->setEnabled(index.isValid()); m_iceCastMenu->exec(m_ui->icecastTableView->viewport()->mapToGlobal(pos)); } void StreamWindow::execFavoritesMenu(const QPoint &pos) { + QModelIndex index = m_ui->favoritesTableView->selectionModel()->currentIndex(); + m_addAction->setEnabled(index.isValid()); + m_editAction->setEnabled(index.isValid()); + m_removeAction->setEnabled(index.isValid()); m_favoritesMenu->exec(m_ui->favoritesTableView->viewport()->mapToGlobal(pos)); } @@ -224,6 +237,62 @@ void StreamWindow::addToFavorites() } } +void StreamWindow::createStream() +{ + EditStreamDialog dialog(this); + if(dialog.exec() == QDialog::Accepted) + { + QMap values = dialog.values(); + + if(values[EditStreamDialog::NAME].isEmpty()) + values[EditStreamDialog::NAME] = values[EditStreamDialog::URL].section("/", -1); + + m_favoritesModel->appendRow(QList () + << new QStandardItem(values[EditStreamDialog::NAME]) + << new QStandardItem(values[EditStreamDialog::GENRE]) + << new QStandardItem(values[EditStreamDialog::BITRATE]) + << new QStandardItem(values[EditStreamDialog::TYPE])); + + QStandardItem *item = m_favoritesModel->item(m_favoritesModel->rowCount()-1, 0); + item->setToolTip(values[EditStreamDialog::NAME] + "\n" + values[EditStreamDialog::URL]); + item->setData(values[EditStreamDialog::URL]); + } +} + +void StreamWindow::editStream() +{ + QModelIndex index = m_ui->favoritesTableView->selectionModel()->currentIndex(); + if(!index.isValid()) + return; + + int row = m_favoritesFilterModel->mapToSource(index).row(); + + EditStreamDialog dialog(this); + dialog.setWindowTitle(tr("Edit Stream")); + QMap values; + values[EditStreamDialog::URL] = m_favoritesModel->item(row, 0)->data().toString(); + values[EditStreamDialog::NAME] = m_favoritesModel->item(row, 0)->text(); + values[EditStreamDialog::GENRE] = m_favoritesModel->item(row, 1)->text(); + values[EditStreamDialog::BITRATE] = m_favoritesModel->item(row, 2)->text(); + values[EditStreamDialog::TYPE] = m_favoritesModel->item(row, 3)->text(); + dialog.setValues(values); + + if(dialog.exec() == QDialog::Accepted) + { + QMap values = dialog.values(); + + if(values[EditStreamDialog::NAME].isEmpty()) + values[EditStreamDialog::NAME] = values[EditStreamDialog::URL].section("/", -1); + + m_favoritesModel->item(row, 0)->setData(values[EditStreamDialog::URL]); + m_favoritesModel->item(row, 0)->setText(values[EditStreamDialog::NAME]); + m_favoritesModel->item(row, 1)->setText(values[EditStreamDialog::GENRE]); + m_favoritesModel->item(row, 2)->setText(values[EditStreamDialog::BITRATE]); + m_favoritesModel->item(row, 3)->setText(values[EditStreamDialog::TYPE]); + m_favoritesModel->item(row, 0)->setToolTip(values[EditStreamDialog::NAME] + "\n" + values[EditStreamDialog::URL]); + } +} + void StreamWindow::removeFromFavorites() { if(m_ui->tabWidget->currentIndex() != 0) diff --git a/src/plugins/General/streambrowser/streamwindow.h b/src/plugins/General/streambrowser/streamwindow.h index 742dfb416..c36c54b69 100644 --- a/src/plugins/General/streambrowser/streamwindow.h +++ b/src/plugins/General/streambrowser/streamwindow.h @@ -28,6 +28,7 @@ class QNetworkReply; class QStandardItemModel; class QSortFilterProxyModel; class QMenu; +class QAction; class StreamsProxyModel; namespace Ui { @@ -53,6 +54,8 @@ private slots: void execIceCastMenu(const QPoint &pos); void execFavoritesMenu(const QPoint &pos); void addToFavorites(); + void createStream(); + void editStream(); void removeFromFavorites(); private: @@ -67,6 +70,7 @@ private: QSortFilterProxyModel *m_iceCastFilterModel, *m_favoritesFilterModel; QMenu *m_iceCastMenu; QMenu *m_favoritesMenu; + QAction *m_addAction, *m_editAction, *m_removeAction, *m_addToFavoritesAction; }; /** -- cgit v1.2.3-13-gbd6f