From 87b310fbe25eb5088cbecb9a4e8fe2bb71d4f0b0 Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Mon, 27 Feb 2012 16:27:34 +0000 Subject: stream browser: added favorites list support git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@2644 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/General/streambrowser/streamwindow.cpp | 149 ++++++++++++++++++--- src/plugins/General/streambrowser/streamwindow.h | 14 +- src/plugins/General/streambrowser/streamwindow.ui | 6 +- .../translations/streambrowser_plugin_cs.ts | 35 +++-- .../translations/streambrowser_plugin_de.ts | 35 +++-- .../translations/streambrowser_plugin_es.ts | 35 +++-- .../translations/streambrowser_plugin_it.ts | 35 +++-- .../translations/streambrowser_plugin_ja.ts | 35 +++-- .../translations/streambrowser_plugin_lt.ts | 35 +++-- .../translations/streambrowser_plugin_nl.ts | 35 +++-- .../translations/streambrowser_plugin_pl.ts | 35 +++-- .../translations/streambrowser_plugin_ru.ts | 35 +++-- .../translations/streambrowser_plugin_tr.ts | 35 +++-- .../translations/streambrowser_plugin_uk_UA.ts | 35 +++-- .../translations/streambrowser_plugin_zh_CN.ts | 35 +++-- .../translations/streambrowser_plugin_zh_TW.ts | 35 +++-- 16 files changed, 497 insertions(+), 127 deletions(-) (limited to 'src') diff --git a/src/plugins/General/streambrowser/streamwindow.cpp b/src/plugins/General/streambrowser/streamwindow.cpp index e7e625cf0..35c1816cf 100644 --- a/src/plugins/General/streambrowser/streamwindow.cpp +++ b/src/plugins/General/streambrowser/streamwindow.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -42,10 +43,10 @@ StreamWindow::StreamWindow(QWidget *parent) : QWidget(parent) setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_QuitOnClose, false); m_requestReply = 0; - + //buttons ui.addPushButton->setIcon(QIcon::fromTheme("list-add")); ui.updatePushButton->setIcon(QIcon::fromTheme("view-refresh")); - + //icecast model m_iceCastModel = new QStandardItemModel(this); m_iceCastModel->setHorizontalHeaderLabels(QStringList() << tr("Name") << tr("Genre") @@ -55,16 +56,35 @@ StreamWindow::StreamWindow(QWidget *parent) : QWidget(parent) m_iceCastFilterModel->setSourceModel(m_iceCastModel); m_iceCastFilterModel->setDynamicSortFilter(true); m_iceCastFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); - - + //icecast table ui.icecastTableView->setModel(m_iceCastFilterModel); ui.icecastTableView->verticalHeader()->setDefaultSectionSize(fontMetrics().height()); ui.icecastTableView->verticalHeader()->setResizeMode(QHeaderView::Fixed); ui.icecastTableView->setEditTriggers(QAbstractItemView::NoEditTriggers); + ui.icecastTableView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui.icecastTableView, SIGNAL(customContextMenuRequested(QPoint)), + SLOT(execIceCastMenu(QPoint))); + //favorites model + m_favoritesModel = new QStandardItemModel(this); + m_favoritesModel->setHorizontalHeaderLabels(QStringList() << tr("Name") + << tr("Genre") + << tr("Bitrate") + << tr("Format")); + m_favoritesFilterModel = new QSortFilterProxyModel(this); + m_favoritesFilterModel->setSourceModel(m_favoritesModel); + m_favoritesFilterModel->setDynamicSortFilter(true); + m_favoritesFilterModel->setFilterCaseSensitivity(Qt::CaseInsensitive); + //favorites table + ui.favoritesTableView->setModel(m_favoritesFilterModel); + ui.favoritesTableView->verticalHeader()->setDefaultSectionSize(fontMetrics().height()); + ui.favoritesTableView->verticalHeader()->setResizeMode(QHeaderView::Fixed); + ui.favoritesTableView->setEditTriggers(QAbstractItemView::NoEditTriggers); + ui.favoritesTableView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui.favoritesTableView, SIGNAL(customContextMenuRequested(QPoint)), + SLOT(execFavoritesMenu(QPoint))); ui.statusLabel->hide(); - m_http = new QNetworkAccessManager(this); //load global proxy settings QmmpSettings *gs = QmmpSettings::instance(); @@ -93,9 +113,22 @@ StreamWindow::StreamWindow(QWidget *parent) : QWidget(parent) //read cache QFile file(path + "/streambrowser/icecast.xml"); if(file.open(QIODevice::ReadOnly)) - readIceCast(&file); + readXml(&file, m_iceCastModel); else on_updatePushButton_clicked(); + QFile file2(path + "/streambrowser/favorites.xml"); + if(file2.open(QIODevice::ReadOnly)) + 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_favoritesMenu = new QMenu(this); + m_favoritesMenu->addAction(addAction); + m_favoritesMenu->addSeparator(); + m_favoritesMenu->addAction(tr("&Remove"), this, SLOT(removeFromFavorites()), QKeySequence::Delete); + addActions(m_favoritesMenu->actions()); } StreamWindow::~StreamWindow() @@ -116,7 +149,7 @@ void StreamWindow::showText(QNetworkReply *reply) if(m_requestReply == reply) { m_requestReply = 0; - readIceCast(reply); + readXml(reply, m_iceCastModel); } reply->deleteLater(); } @@ -133,12 +166,24 @@ void StreamWindow::on_updatePushButton_clicked() void StreamWindow::on_addPushButton_clicked() { - QModelIndexList indexes = ui.icecastTableView->selectionModel()->selectedRows(0); QStringList urls; - foreach(QModelIndex index, indexes) + if(ui.tabWidget->currentIndex() == 0) { - QModelIndex source_index = m_iceCastFilterModel->mapToSource(index); - urls.append(m_iceCastModel->item(source_index.row(),0)->data().toString()); + QModelIndexList indexes = ui.favoritesTableView->selectionModel()->selectedRows(0); + foreach(QModelIndex index, indexes) + { + QModelIndex source_index = m_favoritesFilterModel->mapToSource(index); + urls.append(m_favoritesModel->item(source_index.row(),0)->data().toString()); + } + } + else + { + QModelIndexList indexes = ui.icecastTableView->selectionModel()->selectedRows(0); + foreach(QModelIndex index, indexes) + { + QModelIndex source_index = m_iceCastFilterModel->mapToSource(index); + urls.append(m_iceCastModel->item(source_index.row(),0)->data().toString()); + } } urls.removeDuplicates(); PlayListManager::instance()->add(urls); @@ -147,6 +192,55 @@ void StreamWindow::on_addPushButton_clicked() void StreamWindow::on_filterLineEdit_textChanged(const QString &text) { m_iceCastFilterModel->setFilterFixedString(text); + m_favoritesFilterModel->setFilterFixedString(text); +} + +void StreamWindow::execIceCastMenu(const QPoint &pos) +{ + m_iceCastMenu->exec(ui.icecastTableView->viewport()->mapToGlobal(pos)); +} + +void StreamWindow::execFavoritesMenu(const QPoint &pos) +{ + m_favoritesMenu->exec(ui.favoritesTableView->viewport()->mapToGlobal(pos)); +} + +void StreamWindow::addToFavorites() +{ + QModelIndexList indexes = ui.icecastTableView->selectionModel()->selectedRows(0); + foreach(QModelIndex index, indexes) + { + QModelIndex source_index = m_iceCastFilterModel->mapToSource(index); + int row = source_index.row(); + m_favoritesModel->appendRow(QList () + << m_iceCastModel->item(row, 0)->clone() + << m_iceCastModel->item(row, 1)->clone() + << m_iceCastModel->item(row, 2)->clone() + << m_iceCastModel->item(row, 3)->clone()); + } +} + +void StreamWindow::removeFromFavorites() +{ + if(ui.tabWidget->currentIndex() != 0) + return; + QModelIndexList indexes = ui.favoritesTableView->selectionModel()->selectedRows(0); + QList rows_to_remove; + foreach(QModelIndex index, indexes) + { + rows_to_remove.append(m_favoritesFilterModel->mapToSource(index).row()); + } + qStableSort(rows_to_remove); + int prev_row = -1; + for(int i = rows_to_remove.count() - 1; i >= 0; i -= 1 ) + { + int current = rows_to_remove[i]; + if(current != prev_row) + { + m_favoritesFilterModel->removeRows(current, 1); + prev_row = current; + } + } } void StreamWindow::closeEvent(QCloseEvent *) @@ -158,9 +252,9 @@ void StreamWindow::closeEvent(QCloseEvent *) settings.endGroup(); QString path = QFileInfo(Qmmp::configFile()).absoluteDir().path(); + //save icecast directory QFile file(path + "/streambrowser/icecast.xml"); file.open(QIODevice::WriteOnly); - QXmlStreamWriter writer(&file); writer.setCodec("UTF-8"); writer.setAutoFormatting(true); @@ -178,11 +272,33 @@ void StreamWindow::closeEvent(QCloseEvent *) } writer.writeEndElement(); writer.writeEndDocument(); + file.close(); + //save favorites + QFile file2(path + "/streambrowser/favorites.xml"); + file2.open(QIODevice::WriteOnly); + QXmlStreamWriter writer2(&file2); + writer2.setCodec("UTF-8"); + writer2.setAutoFormatting(true); + writer2.writeStartDocument(); + writer2.writeStartElement("directory"); + for(int i = 0; i < m_favoritesModel->rowCount(); ++i) + { + writer2.writeStartElement("entry"); + writer2.writeTextElement("server_name", m_favoritesModel->item(i,0)->text()); + writer2.writeTextElement("listen_url", m_favoritesModel->item(i,0)->data().toString()); + writer2.writeTextElement("genre", m_favoritesModel->item(i,1)->text()); + writer2.writeTextElement("bitrate", m_favoritesModel->item(i,2)->text()); + writer2.writeTextElement("server_type", m_favoritesModel->item(i,3)->text()); + writer2.writeEndElement(); + } + writer2.writeEndElement(); + writer2.writeEndDocument(); + file2.close(); } -void StreamWindow::readIceCast(QIODevice *input) +void StreamWindow::readXml(QIODevice *input, QStandardItemModel *model) { - m_iceCastModel->removeRows(0, m_iceCastModel->rowCount()); + model->removeRows(0, model->rowCount()); QXmlStreamReader xml(input); QString currentTag, server_name, listen_url, genre, bitrate, server_type; while (!xml.atEnd()) @@ -196,13 +312,13 @@ void StreamWindow::readIceCast(QIODevice *input) { if (xml.name() == "entry") { - m_iceCastModel->appendRow(QList () + model->appendRow(QList () << new QStandardItem(server_name) << new QStandardItem(genre) << new QStandardItem(bitrate) << new QStandardItem(server_type)); - QStandardItem *item = m_iceCastModel->item(m_iceCastModel->rowCount()-1, 0); + QStandardItem *item = model->item(model->rowCount()-1, 0); item->setToolTip(server_name + "\n" + listen_url); item->setData(listen_url); @@ -212,7 +328,6 @@ void StreamWindow::readIceCast(QIODevice *input) bitrate.clear(); server_type.clear(); } - } else if (xml.isCharacters() && !xml.isWhitespace()) { diff --git a/src/plugins/General/streambrowser/streamwindow.h b/src/plugins/General/streambrowser/streamwindow.h index 12c734e7b..35844702d 100644 --- a/src/plugins/General/streambrowser/streamwindow.h +++ b/src/plugins/General/streambrowser/streamwindow.h @@ -27,6 +27,7 @@ class QNetworkAccessManager; class QNetworkReply; class QStandardItemModel; class QSortFilterProxyModel; +class QMenu; /** @author Ilya Kotov @@ -44,16 +45,23 @@ private slots: void on_updatePushButton_clicked(); void on_addPushButton_clicked(); void on_filterLineEdit_textChanged(const QString &text); + void execIceCastMenu(const QPoint &pos); + void execFavoritesMenu(const QPoint &pos); + void addToFavorites(); + void removeFromFavorites(); private: void closeEvent(QCloseEvent *); - void readIceCast(QIODevice *input); + void readXml(QIODevice *input, QStandardItemModel *model); + Ui::StreamWindow ui; QNetworkAccessManager *m_http; QNetworkReply *m_requestReply; QString m_artist, m_title; - QStandardItemModel *m_iceCastModel; - QSortFilterProxyModel *m_iceCastFilterModel; + QStandardItemModel *m_iceCastModel, *m_favoritesModel; + QSortFilterProxyModel *m_iceCastFilterModel, *m_favoritesFilterModel; + QMenu *m_iceCastMenu; + QMenu *m_favoritesMenu; }; #endif diff --git a/src/plugins/General/streambrowser/streamwindow.ui b/src/plugins/General/streambrowser/streamwindow.ui index e86e0f1e7..57f67af64 100644 --- a/src/plugins/General/streambrowser/streamwindow.ui +++ b/src/plugins/General/streambrowser/streamwindow.ui @@ -40,7 +40,7 @@ - 1 + 0 @@ -48,12 +48,12 @@ - + true - QAbstractItemView::SingleSelection + QAbstractItemView::ExtendedSelection QAbstractItemView::SelectRows diff --git a/src/plugins/General/streambrowser/translations/streambrowser_plugin_cs.ts b/src/plugins/General/streambrowser/translations/streambrowser_plugin_cs.ts index 178f0a122..27cb861d5 100644 --- a/src/plugins/General/streambrowser/translations/streambrowser_plugin_cs.ts +++ b/src/plugins/General/streambrowser/translations/streambrowser_plugin_cs.ts @@ -75,38 +75,57 @@ - + + Name - + + Genre - + + Bitrate - + + Format - + + &Add to favorites + + + + + &Add to playlist + + + + + &Remove + + + + Done Hotovo - - + + Error Chyba - + Receiving Příjímám diff --git a/src/plugins/General/streambrowser/translations/streambrowser_plugin_de.ts b/src/plugins/General/streambrowser/translations/streambrowser_plugin_de.ts index 7f612d5ea..b394b1f11 100644 --- a/src/plugins/General/streambrowser/translations/streambrowser_plugin_de.ts +++ b/src/plugins/General/streambrowser/translations/streambrowser_plugin_de.ts @@ -75,38 +75,57 @@ - + + Name - + + Genre - + + Bitrate - + + Format - + + &Add to favorites + + + + + &Add to playlist + + + + + &Remove + + + + Done Fertig - - + + Error Fehler - + Receiving Daten werden empfangen diff --git a/src/plugins/General/streambrowser/translations/streambrowser_plugin_es.ts b/src/plugins/General/streambrowser/translations/streambrowser_plugin_es.ts index 483b595cb..6df80abfc 100644 --- a/src/plugins/General/streambrowser/translations/streambrowser_plugin_es.ts +++ b/src/plugins/General/streambrowser/translations/streambrowser_plugin_es.ts @@ -75,38 +75,57 @@ - + + Name - + + Genre - + + Bitrate - + + Format - + + &Add to favorites + + + + + &Add to playlist + + + + + &Remove + + + + Done Hecho - - + + Error Error - + Receiving Recibiendo diff --git a/src/plugins/General/streambrowser/translations/streambrowser_plugin_it.ts b/src/plugins/General/streambrowser/translations/streambrowser_plugin_it.ts index e933bb385..f057f76d4 100644 --- a/src/plugins/General/streambrowser/translations/streambrowser_plugin_it.ts +++ b/src/plugins/General/streambrowser/translations/streambrowser_plugin_it.ts @@ -75,38 +75,57 @@ - + + Name - + + Genre - + + Bitrate - + + Format - + + &Add to favorites + + + + + &Add to playlist + + + + + &Remove + + + + Done - - + + Error - + Receiving Ricezione diff --git a/src/plugins/General/streambrowser/translations/streambrowser_plugin_ja.ts b/src/plugins/General/streambrowser/translations/streambrowser_plugin_ja.ts index d0ccde68e..597d34457 100644 --- a/src/plugins/General/streambrowser/translations/streambrowser_plugin_ja.ts +++ b/src/plugins/General/streambrowser/translations/streambrowser_plugin_ja.ts @@ -75,38 +75,57 @@ - + + Name - + + Genre - + + Bitrate - + + Format - + + &Add to favorites + + + + + &Add to playlist + + + + + &Remove + + + + Done 完了 - - + + Error 事故 - + Receiving 取得中 diff --git a/src/plugins/General/streambrowser/translations/streambrowser_plugin_lt.ts b/src/plugins/General/streambrowser/translations/streambrowser_plugin_lt.ts index bd2feb375..7054fb21a 100644 --- a/src/plugins/General/streambrowser/translations/streambrowser_plugin_lt.ts +++ b/src/plugins/General/streambrowser/translations/streambrowser_plugin_lt.ts @@ -75,38 +75,57 @@ - + + Name - + + Genre - + + Bitrate - + + Format - + + &Add to favorites + + + + + &Add to playlist + + + + + &Remove + + + + Done Atlikta - - + + Error Klaida - + Receiving Gaunu diff --git a/src/plugins/General/streambrowser/translations/streambrowser_plugin_nl.ts b/src/plugins/General/streambrowser/translations/streambrowser_plugin_nl.ts index 13b3f6a1f..ed59e9983 100644 --- a/src/plugins/General/streambrowser/translations/streambrowser_plugin_nl.ts +++ b/src/plugins/General/streambrowser/translations/streambrowser_plugin_nl.ts @@ -75,38 +75,57 @@ - + + Name - + + Genre - + + Bitrate - + + Format - + + &Add to favorites + + + + + &Add to playlist + + + + + &Remove + + + + Done Klaar - - + + Error Fout - + Receiving Bezig met ontvangen diff --git a/src/plugins/General/streambrowser/translations/streambrowser_plugin_pl.ts b/src/plugins/General/streambrowser/translations/streambrowser_plugin_pl.ts index bff4226d6..09fafca78 100644 --- a/src/plugins/General/streambrowser/translations/streambrowser_plugin_pl.ts +++ b/src/plugins/General/streambrowser/translations/streambrowser_plugin_pl.ts @@ -75,38 +75,57 @@ - + + Name - + + Genre - + + Bitrate - + + Format - + + &Add to favorites + + + + + &Add to playlist + + + + + &Remove + + + + Done Gotowe - - + + Error Błąd - + Receiving Pobieranie diff --git a/src/plugins/General/streambrowser/translations/streambrowser_plugin_ru.ts b/src/plugins/General/streambrowser/translations/streambrowser_plugin_ru.ts index 3dd38ad19..e8b8d2b1b 100644 --- a/src/plugins/General/streambrowser/translations/streambrowser_plugin_ru.ts +++ b/src/plugins/General/streambrowser/translations/streambrowser_plugin_ru.ts @@ -75,38 +75,57 @@ Обновить - + + Name Имя - + + Genre Жанр - + + Bitrate Битовая частота - + + Format Формат - + + &Add to favorites + &Добавить в избранное + + + + &Add to playlist + &Добавить в список воспроизведения + + + + &Remove + &Удалить + + + Done Готово - - + + Error Ошибка - + Receiving Получение diff --git a/src/plugins/General/streambrowser/translations/streambrowser_plugin_tr.ts b/src/plugins/General/streambrowser/translations/streambrowser_plugin_tr.ts index 9dff74a6b..74c3fc26c 100644 --- a/src/plugins/General/streambrowser/translations/streambrowser_plugin_tr.ts +++ b/src/plugins/General/streambrowser/translations/streambrowser_plugin_tr.ts @@ -75,38 +75,57 @@ - + + Name - + + Genre - + + Bitrate - + + Format - + + &Add to favorites + + + + + &Add to playlist + + + + + &Remove + + + + Done - - + + Error - + Receiving Alınıyor diff --git a/src/plugins/General/streambrowser/translations/streambrowser_plugin_uk_UA.ts b/src/plugins/General/streambrowser/translations/streambrowser_plugin_uk_UA.ts index b65aa9548..8b4b6120c 100644 --- a/src/plugins/General/streambrowser/translations/streambrowser_plugin_uk_UA.ts +++ b/src/plugins/General/streambrowser/translations/streambrowser_plugin_uk_UA.ts @@ -75,38 +75,57 @@ - + + Name - + + Genre - + + Bitrate - + + Format - + + &Add to favorites + + + + + &Add to playlist + + + + + &Remove + + + + Done Готово - - + + Error Помилка - + Receiving Отримання diff --git a/src/plugins/General/streambrowser/translations/streambrowser_plugin_zh_CN.ts b/src/plugins/General/streambrowser/translations/streambrowser_plugin_zh_CN.ts index 81c682e7d..2dbf491af 100644 --- a/src/plugins/General/streambrowser/translations/streambrowser_plugin_zh_CN.ts +++ b/src/plugins/General/streambrowser/translations/streambrowser_plugin_zh_CN.ts @@ -75,38 +75,57 @@ - + + Name - + + Genre - + + Bitrate - + + Format - + + &Add to favorites + + + + + &Add to playlist + + + + + &Remove + + + + Done 完成 - - + + Error 错误 - + Receiving 接受 diff --git a/src/plugins/General/streambrowser/translations/streambrowser_plugin_zh_TW.ts b/src/plugins/General/streambrowser/translations/streambrowser_plugin_zh_TW.ts index 3cc29186d..eb70a262e 100644 --- a/src/plugins/General/streambrowser/translations/streambrowser_plugin_zh_TW.ts +++ b/src/plugins/General/streambrowser/translations/streambrowser_plugin_zh_TW.ts @@ -75,38 +75,57 @@ - + + Name - + + Genre - + + Bitrate - + + Format - + + &Add to favorites + + + + + &Add to playlist + + + + + &Remove + + + + Done 完成 - - + + Error 錯誤 - + Receiving 接受 -- cgit v1.2.3-13-gbd6f