diff options
7 files changed, 374 insertions, 11 deletions
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 <QPushButton> +#include <QUrl> +#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<EditStreamDialog::Key, QString> &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::Key, QString> &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 <QDialog> +#include <QMap> + +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<Key, QString> &values); + const QMap<Key, QString> &values() const; + +private slots: + void validate(); + +private: + Ui::EditStreamDialog *m_ui; + QMap<Key, QString> 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 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>EditStreamDialog</class> + <widget class="QDialog" name="EditStreamDialog"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>396</width> + <height>214</height> + </rect> + </property> + <property name="windowTitle"> + <string>Edit Stream</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="leftMargin"> + <number>6</number> + </property> + <property name="rightMargin"> + <number>6</number> + </property> + <property name="bottomMargin"> + <number>6</number> + </property> + <item> + <layout class="QFormLayout" name="formLayout"> + <property name="labelAlignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + <item row="0" column="0"> + <widget class="QLabel" name="label"> + <property name="text"> + <string>URL:</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QLineEdit" name="urlLineEdit"/> + </item> + <item row="1" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Name:</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QLineEdit" name="nameLineEdit"/> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> + <string>Genre:</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLineEdit" name="genreLineEdit"/> + </item> + <item row="3" column="0"> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>Bitrate:</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QLineEdit" name="bitrateLineEdit"/> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="label_5"> + <property name="text"> + <string>Type:</string> + </property> + </widget> + </item> + <item row="4" column="1"> + <widget class="QComboBox" name="typeComboBox"> + <property name="editable"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </item> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>0</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>EditStreamDialog</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>EditStreamDialog</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> +</ui> 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 <QMenu> #include <QXmlStreamReader> #include <QXmlStreamWriter> +#include <QIcon> #include <algorithm> #include <qmmp/qmmpsettings.h> #include <qmmp/qmmp.h> #include <qmmpui/playlistmanager.h> +#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<EditStreamDialog::Key, QString> values = dialog.values(); + + if(values[EditStreamDialog::NAME].isEmpty()) + values[EditStreamDialog::NAME] = values[EditStreamDialog::URL].section("/", -1); + + m_favoritesModel->appendRow(QList<QStandardItem *> () + << 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<EditStreamDialog::Key, QString> 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<EditStreamDialog::Key, QString> 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; }; /** |
