Add internet tabs view and tidal favorites (#167)

This commit is contained in:
Jonas Kvinge
2019-05-27 21:10:37 +02:00
committed by GitHub
parent c4b732ff93
commit 890fba0f61
45 changed files with 3844 additions and 1081 deletions

View File

@@ -0,0 +1,441 @@
/*
* Strawberry Music Player
* This code was part of Clementine
* Copyright 2010, David Sansome <me@davidsansome.com>
* Copyright 2018, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry 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 3 of the License, or
* (at your option) any later version.
*
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <QtGlobal>
#include <QTreeView>
#include <QSortFilterProxyModel>
#include <QAbstractItemView>
#include <QVariant>
#include <QString>
#include <QPainter>
#include <QRect>
#include <QFont>
#include <QFontMetrics>
#include <QMimeData>
#include <QMenu>
#include <QtEvents>
#include "core/application.h"
#include "core/iconloader.h"
#include "core/mimedata.h"
#include "collection/collectionbackend.h"
#include "collection/collectionmodel.h"
#include "collection/collectionfilterwidget.h"
#include "collection/collectionitem.h"
#include "collection/collectionitemdelegate.h"
#include "internetcollectionview.h"
InternetCollectionView::InternetCollectionView(QWidget *parent)
: AutoExpandingTreeView(parent),
app_(nullptr),
collection_backend_(nullptr),
collection_model_(nullptr),
filter_(nullptr),
total_song_count_(0),
total_artist_count_(0),
total_album_count_(0),
nomusic_(":/pictures/nomusic.png"),
context_menu_(nullptr),
is_in_keyboard_search_(false)
{
setItemDelegate(new CollectionItemDelegate(this));
setAttribute(Qt::WA_MacShowFocusRect, false);
setHeaderHidden(true);
setAllColumnsShowFocus(true);
setDragEnabled(true);
setDragDropMode(QAbstractItemView::DragOnly);
setSelectionMode(QAbstractItemView::ExtendedSelection);
SetAutoOpen(false);
setStyleSheet("QTreeView::item{padding-top:1px;}");
}
InternetCollectionView::~InternetCollectionView() {}
void InternetCollectionView::Init(Application *app, CollectionBackend *backend, CollectionModel *model) {
app_ = app;
collection_backend_ = backend;
collection_model_ = model;
collection_model_->set_pretty_covers(true);
collection_model_->set_show_dividers(true);
ReloadSettings();
}
void InternetCollectionView::SetFilter(CollectionFilterWidget *filter) { filter_ = filter; }
void InternetCollectionView::ReloadSettings() {}
void InternetCollectionView::SaveFocus() {
QModelIndex current = currentIndex();
QVariant type = model()->data(current, CollectionModel::Role_Type);
if (!type.isValid() || !(type.toInt() == CollectionItem::Type_Song || type.toInt() == CollectionItem::Type_Container || type.toInt() == CollectionItem::Type_Divider)) {
return;
}
last_selected_path_.clear();
last_selected_song_ = Song();
last_selected_container_ = QString();
switch (type.toInt()) {
case CollectionItem::Type_Song: {
QModelIndex index = qobject_cast<QSortFilterProxyModel*>(model())->mapToSource(current);
SongList songs = collection_model_->GetChildSongs(index);
if (!songs.isEmpty()) {
last_selected_song_ = songs.last();
}
break;
}
case CollectionItem::Type_Container:
case CollectionItem::Type_Divider: {
QString text = model()->data(current, CollectionModel::Role_SortText).toString();
last_selected_container_ = text;
break;
}
default:
return;
}
SaveContainerPath(current);
}
void InternetCollectionView::SaveContainerPath(const QModelIndex &child) {
QModelIndex current = model()->parent(child);
QVariant type = model()->data(current, CollectionModel::Role_Type);
if (!type.isValid() || !(type.toInt() == CollectionItem::Type_Container || type.toInt() == CollectionItem::Type_Divider)) {
return;
}
QString text = model()->data(current, CollectionModel::Role_SortText).toString();
last_selected_path_ << text;
SaveContainerPath(current);
}
void InternetCollectionView::RestoreFocus() {
if (last_selected_container_.isEmpty() && last_selected_song_.url().isEmpty()) {
return;
}
RestoreLevelFocus();
}
bool InternetCollectionView::RestoreLevelFocus(const QModelIndex &parent) {
if (model()->canFetchMore(parent)) {
model()->fetchMore(parent);
}
int rows = model()->rowCount(parent);
for (int i = 0; i < rows; i++) {
QModelIndex current = model()->index(i, 0, parent);
QVariant type = model()->data(current, CollectionModel::Role_Type);
switch (type.toInt()) {
case CollectionItem::Type_Song:
if (!last_selected_song_.url().isEmpty()) {
QModelIndex index = qobject_cast<QSortFilterProxyModel*>(model())->mapToSource(current);
SongList songs = collection_model_->GetChildSongs(index);
for (const Song &song : songs) {
if (song == last_selected_song_) {
setCurrentIndex(current);
return true;
}
}
}
break;
case CollectionItem::Type_Container:
case CollectionItem::Type_Divider: {
QString text = model()->data(current, CollectionModel::Role_SortText).toString();
if (!last_selected_container_.isEmpty() && last_selected_container_ == text) {
emit expand(current);
setCurrentIndex(current);
return true;
}
else if (last_selected_path_.contains(text)) {
emit expand(current);
// If a selected container or song were not found, we've got into a wrong subtree (happens with "unknown" all the time)
if (!RestoreLevelFocus(current)) {
emit collapse(current);
}
else {
return true;
}
}
break;
}
}
}
return false;
}
void InternetCollectionView::TotalSongCountUpdated(int count) {
int old = total_song_count_;
total_song_count_ = count;
if (old != total_song_count_) update();
if (total_song_count_ == 0)
setCursor(Qt::PointingHandCursor);
else
unsetCursor();
emit TotalSongCountUpdated_();
}
void InternetCollectionView::TotalArtistCountUpdated(int count) {
int old = total_artist_count_;
total_artist_count_ = count;
if (old != total_artist_count_) update();
if (total_artist_count_ == 0)
setCursor(Qt::PointingHandCursor);
else
unsetCursor();
emit TotalArtistCountUpdated_();
}
void InternetCollectionView::TotalAlbumCountUpdated(int count) {
int old = total_album_count_;
total_album_count_ = count;
if (old != total_album_count_) update();
if (total_album_count_ == 0)
setCursor(Qt::PointingHandCursor);
else
unsetCursor();
emit TotalAlbumCountUpdated_();
}
void InternetCollectionView::paintEvent(QPaintEvent *event) {
if (total_song_count_ == 0) {
QPainter p(viewport());
QRect rect(viewport()->rect());
// Draw the confused strawberry
QRect image_rect((rect.width() - nomusic_.width()) / 2, 50, nomusic_.width(), nomusic_.height());
p.drawPixmap(image_rect, nomusic_);
// Draw the title text
QFont bold_font;
bold_font.setBold(true);
p.setFont(bold_font);
QFontMetrics metrics(bold_font);
QRect title_rect(0, image_rect.bottom() + 20, rect.width(), metrics.height());
p.drawText(title_rect, Qt::AlignHCenter, tr("The internet collection is empty!"));
// Draw the other text
p.setFont(QFont());
QRect text_rect(0, title_rect.bottom() + 5, rect.width(), metrics.height());
p.drawText(text_rect, Qt::AlignHCenter, tr("Click here to retrieve music"));
}
else {
QTreeView::paintEvent(event);
}
}
void InternetCollectionView::mouseReleaseEvent(QMouseEvent *e) {
QTreeView::mouseReleaseEvent(e);
if (total_song_count_ == 0) {
emit GetSongs();
}
}
void InternetCollectionView::contextMenuEvent(QContextMenuEvent *e) {
if (!context_menu_) {
context_menu_ = new QMenu(this);
add_to_playlist_ = context_menu_->addAction(IconLoader::Load("media-play"), tr("Append to current playlist"), this, SLOT(AddToPlaylist()));
load_ = context_menu_->addAction(IconLoader::Load("media-play"), tr("Replace current playlist"), this, SLOT(Load()));
open_in_new_playlist_ = context_menu_->addAction(IconLoader::Load("document-new"), tr("Open in new playlist"), this, SLOT(OpenInNewPlaylist()));
context_menu_->addSeparator();
add_to_playlist_enqueue_ = context_menu_->addAction(IconLoader::Load("go-next"), tr("Queue track"), this, SLOT(AddToPlaylistEnqueue()));
add_to_playlist_enqueue_next_ = context_menu_->addAction(IconLoader::Load("go-next"), tr("Queue to play next"), this, SLOT(AddToPlaylistEnqueueNext()));
context_menu_->addSeparator();
//add_songs_ = context_menu_->addAction(IconLoader::Load("document-new"), tr("Add songs"), this, SLOT(AddSongs()));
//remove_songs_ = context_menu_->addAction(IconLoader::Load("document-new"), tr("Remove songs"), this, SLOT(RemoveSongs()));
//context_menu_->addSeparator();
if (filter_) context_menu_->addMenu(filter_->menu());
}
context_menu_index_ = indexAt(e->pos());
if (!context_menu_index_.isValid()) return;
context_menu_index_ = qobject_cast<QSortFilterProxyModel*>(model())->mapToSource(context_menu_index_);
QModelIndexList selected_indexes = qobject_cast<QSortFilterProxyModel*>(model())->mapSelectionToSource(selectionModel()->selection()).indexes();
int songs_selected = selected_indexes.count();;
// In all modes
load_->setEnabled(songs_selected);
add_to_playlist_->setEnabled(songs_selected);
open_in_new_playlist_->setEnabled(songs_selected);
add_to_playlist_enqueue_->setEnabled(songs_selected);
//add_songs_->setEnabled(songs_selected);
//remove_songs_->setEnabled(songs_selected);
context_menu_->popup(e->globalPos());
}
void InternetCollectionView::Load() {
QMimeData *data = model()->mimeData(selectedIndexes());
if (MimeData *mime_data = qobject_cast<MimeData*>(data)) {
mime_data->clear_first_ = true;
}
emit AddToPlaylistSignal(data);
}
void InternetCollectionView::AddToPlaylist() {
emit AddToPlaylistSignal(model()->mimeData(selectedIndexes()));
}
void InternetCollectionView::AddToPlaylistEnqueue() {
QMimeData *data = model()->mimeData(selectedIndexes());
if (MimeData* mime_data = qobject_cast<MimeData*>(data)) {
mime_data->enqueue_now_ = true;
}
emit AddToPlaylistSignal(data);
}
void InternetCollectionView::AddToPlaylistEnqueueNext() {
QMimeData *data = model()->mimeData(selectedIndexes());
if (MimeData *mime_data = qobject_cast<MimeData*>(data)) {
mime_data->enqueue_next_now_ = true;
}
emit AddToPlaylistSignal(data);
}
void InternetCollectionView::OpenInNewPlaylist() {
QMimeData *data = model()->mimeData(selectedIndexes());
if (MimeData* mime_data = qobject_cast<MimeData*>(data)) {
mime_data->open_in_new_playlist_ = true;
}
emit AddToPlaylistSignal(data);
}
void InternetCollectionView::AddSongs() {
emit AddSongs(GetSelectedSongs());
}
void InternetCollectionView::RemoveSongs() {
emit RemoveSongs(GetSelectedSongs());
}
void InternetCollectionView::keyboardSearch(const QString &search) {
is_in_keyboard_search_ = true;
QTreeView::keyboardSearch(search);
is_in_keyboard_search_ = false;
}
void InternetCollectionView::scrollTo(const QModelIndex &index, ScrollHint hint) {
if (is_in_keyboard_search_)
QTreeView::scrollTo(index, QAbstractItemView::PositionAtTop);
else
QTreeView::scrollTo(index, hint);
}
SongList InternetCollectionView::GetSelectedSongs() const {
QModelIndexList selected_indexes = qobject_cast<QSortFilterProxyModel*>(model())->mapSelectionToSource(selectionModel()->selection()).indexes();
return collection_model_->GetChildSongs(selected_indexes);
}
void InternetCollectionView::FilterReturnPressed() {
if (!currentIndex().isValid()) {
// Pick the first thing that isn't a divider
for (int row = 0; row < model()->rowCount(); ++row) {
QModelIndex idx(model()->index(row, 0));
if (idx.data(CollectionModel::Role_Type) != CollectionItem::Type_Divider) {
setCurrentIndex(idx);
break;
}
}
}
if (!currentIndex().isValid()) return;
emit doubleClicked(currentIndex());
}
int InternetCollectionView::TotalSongs() {
return total_song_count_;
}
int InternetCollectionView::TotalArtists() {
return total_artist_count_;
}
int InternetCollectionView::TotalAlbums() {
return total_album_count_;
}

View File

@@ -0,0 +1,146 @@
/*
* Strawberry Music Player
* This code was part of Clementine
* Copyright 2010, David Sansome <me@davidsansome.com>
* Copyright 2018, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry 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 3 of the License, or
* (at your option) any later version.
*
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef INTERNETCOLLECTIONVIEW_H
#define INTERNETCOLLECTIONVIEW_H
#include "config.h"
#include <stdbool.h>
#include <QObject>
#include <QWidget>
#include <QSet>
#include <QString>
#include <QPixmap>
#include <QAction>
#include <QMenu>
#include <QtEvents>
#include "widgets/autoexpandingtreeview.h"
#include "core/song.h"
class QContextMenuEvent;
class QHelpEvent;
class QMouseEvent;
class QPaintEvent;
class Application;
class CollectionBackend;
class CollectionModel;
class CollectionFilterWidget;
class InternetCollectionView : public AutoExpandingTreeView {
Q_OBJECT
public:
InternetCollectionView(QWidget *parent = nullptr);
~InternetCollectionView();
void Init(Application *app, CollectionBackend *backend, CollectionModel *model);
// Returns Songs currently selected in the collection view.
// Please note that the selection is recursive meaning that if for example an album is selected this will return all of it's songs.
SongList GetSelectedSongs() const;
void SetApplication(Application *app);
void SetFilter(CollectionFilterWidget *filter);
// QTreeView
void keyboardSearch(const QString &search);
void scrollTo(const QModelIndex &index, ScrollHint hint = EnsureVisible);
int TotalSongs();
int TotalArtists();
int TotalAlbums();
public slots:
void TotalSongCountUpdated(int count);
void TotalArtistCountUpdated(int count);
void TotalAlbumCountUpdated(int count);
void ReloadSettings();
void FilterReturnPressed();
void SaveFocus();
void RestoreFocus();
signals:
void GetSongs();
void TotalSongCountUpdated_();
void TotalArtistCountUpdated_();
void TotalAlbumCountUpdated_();
void Error(const QString &message);
void AddSongs(const SongList songs);
void RemoveSongs(const SongList songs);
protected:
// QWidget
void paintEvent(QPaintEvent *event);
void mouseReleaseEvent(QMouseEvent *e);
void contextMenuEvent(QContextMenuEvent *e);
private slots:
void Load();
void AddToPlaylist();
void AddToPlaylistEnqueue();
void AddToPlaylistEnqueueNext();
void OpenInNewPlaylist();
void AddSongs();
void RemoveSongs();
private:
void RecheckIsEmpty();
bool RestoreLevelFocus(const QModelIndex &parent = QModelIndex());
void SaveContainerPath(const QModelIndex &child);
private:
Application *app_;
CollectionBackend *collection_backend_;
CollectionModel*collection_model_;
CollectionFilterWidget *filter_;
int total_song_count_;
int total_artist_count_;
int total_album_count_;
QPixmap nomusic_;
QMenu *context_menu_;
QModelIndex context_menu_index_;
QAction *load_;
QAction *add_to_playlist_;
QAction *add_to_playlist_enqueue_;
QAction *add_to_playlist_enqueue_next_;
QAction *open_in_new_playlist_;
//QAction *add_songs_;
//QAction *remove_songs_;
bool is_in_keyboard_search_;
// Save focus
Song last_selected_song_;
QString last_selected_container_;
QSet<QString> last_selected_path_;
};
#endif // INTERNETCOLLECTIONVIEW_H

View File

@@ -0,0 +1,58 @@
/*
* Strawberry Music Player
* Copyright 2018, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry 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 3 of the License, or
* (at your option) any later version.
*
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <QWidget>
#include <QPushButton>
#include <QLabel>
#include <QProgressBar>
#include <QKeyEvent>
#include <QContextMenuEvent>
#include "core/application.h"
#include "internetcollectionview.h"
#include "internetcollectionviewcontainer.h"
#include "ui_internetcollectionviewcontainer.h"
#include "collection/collectionfilterwidget.h"
#include "internetservice.h"
InternetCollectionViewContainer::InternetCollectionViewContainer(QWidget *parent) :
QWidget(parent),
ui_(new Ui_InternetCollectionViewContainer)
{
ui_->setupUi(this);
view()->SetFilter(filter());
connect(filter(), SIGNAL(UpPressed()), view(), SLOT(UpAndFocus()));
connect(filter(), SIGNAL(DownPressed()), view(), SLOT(DownAndFocus()));
connect(filter(), SIGNAL(ReturnPressed()), view(), SLOT(FilterReturnPressed()));
connect(view(), SIGNAL(FocusOnFilterSignal(QKeyEvent*)), filter(), SLOT(FocusOnFilter(QKeyEvent*)));
ui_->progressbar->hide();
ReloadSettings();
}
InternetCollectionViewContainer::~InternetCollectionViewContainer() { delete ui_; }
void InternetCollectionViewContainer::contextMenuEvent(QContextMenuEvent *e) {
}

View File

@@ -0,0 +1,66 @@
/*
* Strawberry Music Player
* Copyright 2018, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry 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 3 of the License, or
* (at your option) any later version.
*
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef INTERNETCOLLECTIONVIEWCONTAINER_H
#define INTERNETCOLLECTIONVIEWCONTAINER_H
#include "config.h"
#include <QWidget>
#include "ui_internetcollectionviewcontainer.h"
class QStackedWidget;
class QPushButton;
class QLabel;
class QProgressBar;
class Application;
class InternetCollectionView;
class CollectionFilterWidget;
class InternetService;
class Ui_InternetCollectionViewContainer;
class InternetCollectionViewContainer : public QWidget {
Q_OBJECT
public:
InternetCollectionViewContainer(QWidget *parent = nullptr);
~InternetCollectionViewContainer();
QStackedWidget *stacked() const { return ui_->stacked; }
QWidget *help_page() const { return ui_->help_page; }
QWidget *internetcollection_page() const { return ui_->internetcollection_page; }
InternetCollectionView *view() const { return ui_->view; }
CollectionFilterWidget *filter() const { return ui_->filter; }
QPushButton *refresh() const { return ui_->refresh; }
QLabel *status() const { return ui_->status; }
QProgressBar *progressbar() const { return ui_->progressbar; }
void ReloadSettings() { view()->ReloadSettings(); }
private slots:
void contextMenuEvent(QContextMenuEvent *e);
private:
Ui_InternetCollectionViewContainer *ui_;
Application *app_;
InternetService *service_;
};
#endif // INTERNETCOLLECTIONVIEWCONTAINER_H

View File

@@ -0,0 +1,131 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>InternetCollectionViewContainer</class>
<widget class="QWidget" name="InternetCollectionViewContainer">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="refresh">
<property name="text">
<string>Refresh catalogue</string>
</property>
</widget>
</item>
<item>
<widget class="QStackedWidget" name="stacked">
<widget class="QWidget" name="help_page">
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QLabel" name="status">
<property name="enabled">
<bool>true</bool>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>40</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="progressbar">
<property name="enabled">
<bool>true</bool>
</property>
<property name="value">
<number>0</number>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<widget class="QWidget" name="internetcollection_page">
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="CollectionFilterWidget" name="filter" native="true"/>
</item>
<item>
<widget class="InternetCollectionView" name="view"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>CollectionFilterWidget</class>
<extends>QWidget</extends>
<header>collection/collectionfilterwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>InternetCollectionView</class>
<extends>QTreeView</extends>
<header location="global">internet/internetcollectionview.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -21,8 +21,6 @@
#include "config.h"
#include <algorithm>
#include <QtGlobal>
#include <QObject>
#include <QList>
@@ -40,20 +38,15 @@
#include "core/application.h"
#include "core/logging.h"
#include "core/closure.h"
#include "core/iconloader.h"
#include "core/song.h"
#include "playlist/songmimedata.h"
#include "covermanager/albumcoverloader.h"
#include "internet/internetsongmimedata.h"
#include "playlist/songmimedata.h"
#include "internetsearch.h"
#include "internetservice.h"
#include "internetservices.h"
using std::advance;
const int InternetSearch::kDelayedSearchTimeoutMs = 200;
const int InternetSearch::kMaxResultsPerEmission = 2000;
const int InternetSearch::kArtHeight = 32;
InternetSearch::InternetSearch(Application *app, Song::Source source, QObject *parent)
@@ -70,11 +63,10 @@ InternetSearch::InternetSearch(Application *app, Song::Source source, QObject *p
connect(app_->album_cover_loader(), SIGNAL(ImageLoaded(quint64, QImage)), SLOT(AlbumArtLoaded(quint64, QImage)));
connect(this, SIGNAL(SearchAsyncSig(int, QString, SearchType)), this, SLOT(DoSearchAsync(int, QString, SearchType)));
connect(this, SIGNAL(ResultsAvailable(int, InternetSearch::ResultList)), SLOT(ResultsAvailableSlot(int, InternetSearch::ResultList)));
connect(this, SIGNAL(ArtLoaded(int, QImage)), SLOT(ArtLoadedSlot(int, QImage)));
connect(service_, SIGNAL(UpdateStatus(QString)), SLOT(UpdateStatusSlot(QString)));
connect(service_, SIGNAL(ProgressSetMaximum(int)), SLOT(ProgressSetMaximumSlot(int)));
connect(service_, SIGNAL(UpdateProgress(int)), SLOT(UpdateProgressSlot(int)));
connect(service_, SIGNAL(SearchUpdateStatus(QString)), SLOT(UpdateStatusSlot(QString)));
connect(service_, SIGNAL(SearchProgressSetMaximum(int)), SLOT(ProgressSetMaximumSlot(int)));
connect(service_, SIGNAL(SearchUpdateProgress(int)), SLOT(UpdateProgressSlot(int)));
connect(service_, SIGNAL(SearchResults(int, SongList)), SLOT(SearchDone(int, SongList)));
connect(service_, SIGNAL(SearchError(int, QString)), SLOT(HandleError(int, QString)));
@@ -145,14 +137,22 @@ void InternetSearch::SearchDone(int service_id, const SongList &songs) {
const PendingState state = pending_searches_.take(service_id);
const int search_id = state.orig_id_;
ResultList ret;
ResultList results;
for (const Song &song : songs) {
Result result;
result.metadata_ = song;
ret << result;
results << result;
}
emit ResultsAvailable(search_id, ret);
if (results.isEmpty()) return;
// Load cached pixmaps into the results
for (InternetSearch::ResultList::iterator it = results.begin(); it != results.end(); ++it) {
it->pixmap_cache_key_ = PixmapCacheKey(*it);
}
emit AddResults(search_id, results);
MaybeSearchFinished(search_id);
}
@@ -172,6 +172,7 @@ void InternetSearch::MaybeSearchFinished(int id) {
}
void InternetSearch::CancelSearch(int id) {
QMap<int, DelayedSearch>::iterator it;
for (it = delayed_searches_.begin(); it != delayed_searches_.end(); ++it) {
if (it.value().id_ == id) {
@@ -181,9 +182,11 @@ void InternetSearch::CancelSearch(int id) {
}
}
service_->CancelSearch();
}
void InternetSearch::timerEvent(QTimerEvent *e) {
QMap<int, DelayedSearch>::iterator it = delayed_searches_.find(e->timerId());
if (it != delayed_searches_.end()) {
SearchAsync(it.value().id_, it.value().query_, it.value().type_);
@@ -192,25 +195,6 @@ void InternetSearch::timerEvent(QTimerEvent *e) {
}
QObject::timerEvent(e);
}
void InternetSearch::ResultsAvailableSlot(int id, InternetSearch::ResultList results) {
if (results.isEmpty()) return;
// Limit the number of results that are used from each emission.
if (results.count() > kMaxResultsPerEmission) {
InternetSearch::ResultList::iterator begin = results.begin();
std::advance(begin, kMaxResultsPerEmission);
results.erase(begin, results.end());
}
// Load cached pixmaps into the results
for (InternetSearch::ResultList::iterator it = results.begin(); it != results.end(); ++it) {
it->pixmap_cache_key_ = PixmapCacheKey(*it);
}
emit AddResults(id, results);
}
@@ -235,27 +219,17 @@ int InternetSearch::LoadArtAsync(const InternetSearch::Result &result) {
}
void InternetSearch::ArtLoadedSlot(int id, const QImage &image) {
HandleLoadedArt(id, image);
}
void InternetSearch::AlbumArtLoaded(quint64 id, const QImage &image) {
if (!cover_loader_tasks_.contains(id)) return;
int orig_id = cover_loader_tasks_.take(id);
HandleLoadedArt(orig_id, image);
}
void InternetSearch::HandleLoadedArt(int id, const QImage &image) {
const QString key = pending_art_searches_.take(id);
const QString key = pending_art_searches_.take(orig_id);
QPixmap pixmap = QPixmap::fromImage(image);
pixmap_cache_.insert(key, pixmap);
emit ArtLoaded(id, pixmap);
emit ArtLoaded(orig_id, pixmap);
}

View File

@@ -24,10 +24,13 @@
#include "config.h"
#include <QtGlobal>
#include <QObject>
#include <QFuture>
#include <QIcon>
#include <QMetaType>
#include <QMap>
#include <QString>
#include <QStringList>
#include <QImage>
#include <QPixmap>
#include <QPixmapCache>
#include "core/song.h"
@@ -58,7 +61,6 @@ class InternetSearch : public QObject {
typedef QList<Result> ResultList;
static const int kDelayedSearchTimeoutMs;
static const int kMaxResultsPerEmission;
Application *application() const { return app_; }
Song::Source source() const { return source_; }
@@ -85,7 +87,6 @@ class InternetSearch : public QObject {
void UpdateProgress(int max);
void ArtLoaded(int id, const QPixmap &pixmap);
void ArtLoaded(int id, const QImage &image);
protected:
@@ -107,7 +108,7 @@ class InternetSearch : public QObject {
void timerEvent(QTimerEvent *e);
// These functions treat queries in the same way as LibraryQuery.
// These functions treat queries in the same way as CollectionQuery.
// They're useful for figuring out whether you got a result because it matched in the song title or the artist/album name.
static QStringList TokenizeQuery(const QString &query);
static bool Matches(const QStringList &tokens, const QString &string);
@@ -116,9 +117,7 @@ class InternetSearch : public QObject {
void DoSearchAsync(int id, const QString &query, SearchType type);
void SearchDone(int id, const SongList &songs);
void HandleError(const int id, const QString error);
void ResultsAvailableSlot(int id, InternetSearch::ResultList results);
void ArtLoadedSlot(int id, const QImage &image);
void AlbumArtLoaded(quint64 id, const QImage &image);
void UpdateStatusSlot(QString text);

View File

@@ -18,18 +18,20 @@
*
*/
#include <QPainter>
#include <QStyleOptionViewItem>
#include <QPainter>
#include "internetsearchitemdelegate.h"
#include "internetsearchview.h"
InternetSearchItemDelegate::InternetSearchItemDelegate(InternetSearchView* view)
InternetSearchItemDelegate::InternetSearchItemDelegate(InternetSearchView *view)
: CollectionItemDelegate(view), view_(view) {}
void InternetSearchItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const {
// Tell the view we painted this item so it can lazy load some art.
const_cast<InternetSearchView*>(view_)->LazyLoadArt(index);
CollectionItemDelegate::paint(painter, option, index);
}

View File

@@ -21,11 +21,11 @@
#ifndef INTERNETSEARCHITEMDELEGATE_H
#define INTERNETSEARCHITEMDELEGATE_H
#include <QPainter>
#include <QStyleOptionViewItem>
#include "collection/collectionview.h"
#include "collection/collectionitemdelegate.h"
class QPainter;
class InternetSearchView;
class InternetSearchItemDelegate : public CollectionItemDelegate {
@@ -35,7 +35,8 @@ class InternetSearchItemDelegate : public CollectionItemDelegate {
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
private:
InternetSearchView* view_;
InternetSearchView *view_;
};
#endif // INTERNETSEARCHITEMDELEGATE_H

View File

@@ -20,15 +20,13 @@
#include "config.h"
#include <QObject>
#include <QStandardItem>
#include <QStandardItemModel>
#include <QMimeData>
#include <QList>
#include <QSet>
#include <QVariant>
#include <QString>
#include <QPixmap>
#include <QMimeData>
#include "core/mimedata.h"
#include "core/iconloader.h"

View File

@@ -21,30 +21,24 @@
#include "config.h"
#include <functional>
#include <algorithm>
#include <QtGlobal>
#include <QWidget>
#include <QTimer>
#include <QList>
#include <QString>
#include <QStringList>
#include <QPixmap>
#include <QPalette>
#include <QColor>
#include <QFont>
#include <QMenu>
#include <QSortFilterProxyModel>
#include <QStandardItem>
#include <QSettings>
#include <QMenu>
#include <QAction>
#include <QSettings>
#include <QtEvents>
#include "core/application.h"
#include "core/logging.h"
#include "core/mimedata.h"
#include "core/timeconstants.h"
#include "core/iconloader.h"
#include "internet/internetsongmimedata.h"
#include "collection/collectionfilterwidget.h"
@@ -64,18 +58,16 @@ using std::swap;
const int InternetSearchView::kSwapModelsTimeoutMsec = 250;
InternetSearchView::InternetSearchView(Application *app, InternetSearch *engine, QString settings_group, SettingsDialog::Page settings_page, QWidget *parent)
InternetSearchView::InternetSearchView(QWidget *parent)
: QWidget(parent),
app_(app),
engine_(engine),
settings_group_(settings_group),
settings_page_(settings_page),
app_(nullptr),
engine_(nullptr),
ui_(new Ui_InternetSearchView),
context_menu_(nullptr),
last_search_id_(0),
front_model_(new InternetSearchModel(engine_, this)),
back_model_(new InternetSearchModel(engine_, this)),
current_model_(front_model_),
front_model_(nullptr),
back_model_(nullptr),
current_model_(nullptr),
front_proxy_(new InternetSearchSortModel(this)),
back_proxy_(new InternetSearchSortModel(this)),
current_proxy_(front_proxy_),
@@ -84,24 +76,15 @@ InternetSearchView::InternetSearchView(Application *app, InternetSearch *engine,
{
ui_->setupUi(this);
ui_->progressbar->hide();
ui_->progressbar->reset();
front_model_->set_proxy(front_proxy_);
back_model_->set_proxy(back_proxy_);
ui_->search->installEventFilter(this);
ui_->results_stack->installEventFilter(this);
ui_->settings->setIcon(IconLoader::Load("configure"));
// Must be a queued connection to ensure the InternetSearch handles it first.
connect(app_, SIGNAL(SettingsChanged()), SLOT(ReloadSettings()), Qt::QueuedConnection);
connect(ui_->search, SIGNAL(textChanged(QString)), SLOT(TextEdited(QString)));
connect(ui_->results, SIGNAL(AddToPlaylistSignal(QMimeData*)), SIGNAL(AddToPlaylist(QMimeData*)));
connect(ui_->results, SIGNAL(FocusOnFilterSignal(QKeyEvent*)), SLOT(FocusOnFilter(QKeyEvent*)));
// Set the appearance of the results list
ui_->results->setItemDelegate(new InternetSearchItemDelegate(this));
ui_->results->setAttribute(Qt::WA_MacShowFocusRect, false);
@@ -123,6 +106,32 @@ InternetSearchView::InternetSearchView(Application *app, InternetSearch *engine,
help_font.setBold(true);
ui_->label_helptext->setFont(help_font);
}
InternetSearchView::~InternetSearchView() { delete ui_; }
void InternetSearchView::Init(Application *app, InternetSearch *engine, QString settings_group, SettingsDialog::Page settings_page) {
app_ = app;
engine_ = engine;
settings_group_ = settings_group;
settings_page_ = settings_page;
front_model_ = new InternetSearchModel(engine_, this);
back_model_ = new InternetSearchModel(engine_, this);
front_proxy_ = new InternetSearchSortModel(this);
back_proxy_ = new InternetSearchSortModel(this);
front_model_->set_proxy(front_proxy_);
back_model_->set_proxy(back_proxy_);
current_model_ = front_model_;
current_proxy_ = front_proxy_;
// Must be a queued connection to ensure the InternetSearch handles it first.
connect(app_, SIGNAL(SettingsChanged()), SLOT(ReloadSettings()), Qt::QueuedConnection);
// Set up the sorting proxy model
front_proxy_->setSourceModel(front_model_);
front_proxy_->setDynamicSortFilter(true);
@@ -132,10 +141,6 @@ InternetSearchView::InternetSearchView(Application *app, InternetSearch *engine,
back_proxy_->setDynamicSortFilter(true);
back_proxy_->sort(0);
swap_models_timer_->setSingleShot(true);
swap_models_timer_->setInterval(kSwapModelsTimeoutMsec);
connect(swap_models_timer_, SIGNAL(timeout()), SLOT(SwapModels()));
// Add actions to the settings menu
group_by_actions_ = CollectionFilterWidget::CreateGroupByActions(this);
QMenu *settings_menu = new QMenu(this);
@@ -144,12 +149,19 @@ InternetSearchView::InternetSearchView(Application *app, InternetSearch *engine,
settings_menu->addAction(IconLoader::Load("configure"), tr("Configure %1...").arg(Song::TextForSource(engine->source())), this, SLOT(OpenSettingsDialog()));
ui_->settings->setMenu(settings_menu);
swap_models_timer_->setSingleShot(true);
swap_models_timer_->setInterval(kSwapModelsTimeoutMsec);
connect(swap_models_timer_, SIGNAL(timeout()), SLOT(SwapModels()));
connect(ui_->radiobutton_search_artists, SIGNAL(clicked(bool)), SLOT(SearchArtistsClicked(bool)));
connect(ui_->radiobutton_search_albums, SIGNAL(clicked(bool)), SLOT(SearchAlbumsClicked(bool)));
connect(ui_->radiobutton_search_songs, SIGNAL(clicked(bool)), SLOT(SearchSongsClicked(bool)));
connect(group_by_actions_, SIGNAL(triggered(QAction*)), SLOT(GroupByClicked(QAction*)));
connect(ui_->search, SIGNAL(textChanged(QString)), SLOT(TextEdited(QString)));
connect(ui_->results, SIGNAL(AddToPlaylistSignal(QMimeData*)), SIGNAL(AddToPlaylist(QMimeData*)));
connect(ui_->results, SIGNAL(FocusOnFilterSignal(QKeyEvent*)), SLOT(FocusOnFilter(QKeyEvent*)));
// These have to be queued connections because they may get emitted before our call to Search() (or whatever) returns and we add the ID to the map.
connect(engine_, SIGNAL(UpdateStatus(QString)), SLOT(UpdateStatus(QString)));
@@ -164,8 +176,6 @@ InternetSearchView::InternetSearchView(Application *app, InternetSearch *engine,
}
InternetSearchView::~InternetSearchView() { delete ui_; }
void InternetSearchView::ReloadSettings() {
QSettings s;
@@ -176,11 +186,9 @@ void InternetSearchView::ReloadSettings() {
const bool pretty = s.value("pretty_covers", true).toBool();
front_model_->set_use_pretty_covers(pretty);
back_model_->set_use_pretty_covers(pretty);
s.endGroup();
// Internet search settings
s.beginGroup(settings_group_);
search_type_ = InternetSearch::SearchType(s.value("type", int(InternetSearch::SearchType_Artists)).toInt());
switch (search_type_) {
case InternetSearch::SearchType_Artists:
@@ -243,21 +251,25 @@ void InternetSearchView::TextEdited(const QString &text) {
}
void InternetSearchView::AddResults(int id, const InternetSearch::ResultList &results) {
if (id != last_search_id_) return;
if (results.isEmpty()) return;
ui_->label_status->clear();
ui_->progressbar->reset();
ui_->progressbar->hide();
current_model_->AddResults(results);
}
void InternetSearchView::SearchError(const int id, const QString error) {
error_ = true;
ui_->label_helptext->setText(error);
ui_->label_status->clear();
ui_->progressbar->reset();
ui_->progressbar->hide();
ui_->results_stack->setCurrentWidget(ui_->help_page);
}
void InternetSearchView::SwapModels() {

View File

@@ -25,25 +25,28 @@
#include "config.h"
#include <QWidget>
#include <QObject>
#include <QTimer>
#include <QMap>
#include <QList>
#include <QString>
#include <QIcon>
#include <QPixmap>
#include <QMimeData>
#include <QMenu>
#include <QSortFilterProxyModel>
#include <QAction>
#include <QActionGroup>
#include <QtEvents>
#include "collection/collectionmodel.h"
#include "settings/settingsdialog.h"
#include "playlist/playlistmanager.h"
#include "internetsearch.h"
class QSortFilterProxyModel;
class QMimeData;
class QTimer;
class QMenu;
class QAction;
class QActionGroup;
class QEvent;
class QKeyEvent;
class QShowEvent;
class QHideEvent;
class QContextMenuEvent;
class Application;
class GroupByDialog;
class InternetSearchModel;
@@ -53,9 +56,11 @@ class InternetSearchView : public QWidget {
Q_OBJECT
public:
InternetSearchView(Application *app, InternetSearch *engine, QString settings_group, SettingsDialog::Page settings_page, QWidget *parent = nullptr);
InternetSearchView(QWidget *parent = nullptr);
~InternetSearchView();
void Init(Application *app, InternetSearch *engine, QString settings_group, SettingsDialog::Page settings_page);
static const int kSwapModelsTimeoutMsec;
void LazyLoadArt(const QModelIndex &index);

View File

@@ -72,7 +72,7 @@
<bool>true</bool>
</property>
<property name="text">
<string>Search for</string>
<string>Search type</string>
</property>
<property name="margin">
<number>10</number>
@@ -215,7 +215,7 @@
<x>0</x>
<y>0</y>
<width>398</width>
<height>521</height>
<height>511</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">

View File

@@ -18,14 +18,12 @@
*/
#include <QObject>
#include <QStandardItem>
#include <QVariant>
#include <QString>
#include "core/logging.h"
#include "core/mimedata.h"
#include "internetservices.h"
#include "internetservice.h"
#include "core/song.h"
class Application;
InternetService::InternetService(Song::Source source, const QString &name, const QString &url_scheme, Application *app, QObject *parent)
: QObject(parent), app_(app), source_(source), name_(name), url_scheme_(url_scheme) {

View File

@@ -21,23 +21,17 @@
#define INTERNETSERVICE_H
#include <QObject>
#include <QStandardItem>
#include <QAction>
#include <QObject>
#include <QList>
#include <QString>
#include <QUrl>
#include <QIcon>
#include "core/song.h"
#include "core/iconloader.h"
#include "playlist/playlistitem.h"
#include "settings/settingsdialog.h"
#include "internetsearch.h"
class QSortFilterProxyModel;
class Application;
class InternetServices;
class CollectionFilterWidget;
class CollectionBackend;
class CollectionModel;
class InternetService : public QObject {
Q_OBJECT
@@ -45,6 +39,7 @@ class InternetService : public QObject {
public:
InternetService(Song::Source source, const QString &name, const QString &url_scheme, Application *app, QObject *parent = nullptr);
virtual ~InternetService() {}
virtual Song::Source source() const { return source_; }
virtual QString name() const { return name_; }
virtual QString url_scheme() const { return url_scheme_; }
@@ -55,8 +50,63 @@ class InternetService : public QObject {
virtual int Search(const QString &query, InternetSearch::SearchType type) = 0;
virtual void CancelSearch() = 0;
virtual CollectionBackend *artists_collection_backend() = 0;
virtual CollectionBackend *albums_collection_backend() = 0;
virtual CollectionBackend *songs_collection_backend() = 0;
virtual CollectionModel *artists_collection_model() = 0;
virtual CollectionModel *albums_collection_model() = 0;
virtual CollectionModel *songs_collection_model() = 0;
virtual QSortFilterProxyModel *artists_collection_sort_model() = 0;
virtual QSortFilterProxyModel *albums_collection_sort_model() = 0;
virtual QSortFilterProxyModel *songs_collection_sort_model() = 0;
public slots:
virtual void ShowConfig() {}
virtual void GetArtists() = 0;
virtual void GetAlbums() = 0;
virtual void GetSongs() = 0;
signals:
void Login();
void Logout();
void Login(const QString &username, const QString &password, const QString &token);
void LoginSuccess();
void LoginFailure(QString failure_reason);
void LoginComplete(bool success, QString error = QString());
void Error(QString message);
void Results(SongList songs);
void UpdateStatus(QString text);
void ProgressSetMaximum(int max);
void UpdateProgress(int max);
void ArtistsError(QString message);
void ArtistsResults(SongList songs);
void ArtistsUpdateStatus(QString text);
void ArtistsProgressSetMaximum(int max);
void ArtistsUpdateProgress(int max);
void AlbumsError(QString message);
void AlbumsResults(SongList songs);
void AlbumsUpdateStatus(QString text);
void AlbumsProgressSetMaximum(int max);
void AlbumsUpdateProgress(int max);
void SongsError(QString message);
void SongsResults(SongList songs);
void SongsUpdateStatus(QString text);
void SongsProgressSetMaximum(int max);
void SongsUpdateProgress(int max);
void SearchResults(int id, SongList songs);
void SearchError(int id, QString message);
void SearchUpdateStatus(QString text);
void SearchProgressSetMaximum(int max);
void SearchUpdateProgress(int max);
void StreamURLFinished(const QUrl original_url, const QUrl stream_url, const Song::FileType, QString error = QString());
protected:
Application *app_;

View File

@@ -24,19 +24,11 @@
#include "config.h"
#include <QtGlobal>
#include <QObject>
#include <QStandardItemModel>
#include <QMap>
#include <QString>
#include "core/song.h"
#include "collection/collectionmodel.h"
#include "playlist/playlistitem.h"
#include "settings/settingsdialog.h"
#include "widgets/multiloadingindicator.h"
class Application;
class InternetService;
class InternetServices : public QObject {

View File

@@ -0,0 +1,213 @@
/*
* Strawberry Music Player
* Copyright 2018, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry 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 3 of the License, or
* (at your option) any later version.
*
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "config.h"
#include <QtGlobal>
#include <QWidget>
#include <QString>
#include <QStackedWidget>
#include <QContextMenuEvent>
#include <QSettings>
#include "core/application.h"
#include "collection/collectionbackend.h"
#include "collection/collectionfilterwidget.h"
#include "internetservice.h"
#include "internettabsview.h"
#include "ui_internettabsview.h"
InternetTabsView::InternetTabsView(Application *app, InternetService *service, InternetSearch *engine, QString settings_group, SettingsDialog::Page settings_page, QWidget *parent)
: QWidget(parent),
app_(app),
service_(service),
engine_(engine),
settings_group_(settings_group),
settings_page_(settings_page),
ui_(new Ui_InternetTabsView)
{
ui_->setupUi(this);
ui_->search_view->Init(app, engine, settings_group, settings_page);
if (service_->artists_collection_model()) {
ui_->artists_collection->stacked()->setCurrentWidget(ui_->artists_collection->internetcollection_page());
ui_->artists_collection->view()->Init(app_, service_->artists_collection_backend(), service_->artists_collection_model());
ui_->artists_collection->view()->setModel(service_->artists_collection_sort_model());
ui_->artists_collection->view()->SetFilter(ui_->artists_collection->filter());
ui_->artists_collection->filter()->SetCollectionModel(service_->artists_collection_model());
connect(ui_->artists_collection->view(), SIGNAL(GetSongs()), SLOT(GetArtists()));
connect(ui_->artists_collection->refresh(), SIGNAL(clicked()), SLOT(GetArtists()));
connect(service_, SIGNAL(ArtistsResults(SongList)), SLOT(ArtistsFinished(SongList)));
connect(service_, SIGNAL(ArtistsError(QString)), ui_->artists_collection->status(), SLOT(setText(QString)));
connect(service_, SIGNAL(ArtistsUpdateStatus(QString)), ui_->artists_collection->status(), SLOT(setText(QString)));
connect(service_, SIGNAL(ArtistsProgressSetMaximum(int)), ui_->artists_collection->progressbar(), SLOT(setMaximum(int)));
connect(service_, SIGNAL(ArtistsUpdateProgress(int)), ui_->artists_collection->progressbar(), SLOT(setValue(int)));
connect(service_->artists_collection_model(), SIGNAL(TotalArtistCountUpdated(int)), ui_->artists_collection->view(), SLOT(TotalArtistCountUpdated(int)));
connect(service_->artists_collection_model(), SIGNAL(TotalAlbumCountUpdated(int)), ui_->artists_collection->view(), SLOT(TotalAlbumCountUpdated(int)));
connect(service_->artists_collection_model(), SIGNAL(TotalSongCountUpdated(int)), ui_->artists_collection->view(), SLOT(TotalSongCountUpdated(int)));
connect(service_->artists_collection_model(), SIGNAL(modelAboutToBeReset()), ui_->artists_collection->view(), SLOT(SaveFocus()));
connect(service_->artists_collection_model(), SIGNAL(modelReset()), ui_->artists_collection->view(), SLOT(RestoreFocus()));
}
else {
ui_->tabs->removeTab(ui_->tabs->indexOf(ui_->artists));
}
if (service_->albums_collection_model()) {
ui_->albums_collection->stacked()->setCurrentWidget(ui_->albums_collection->internetcollection_page());
ui_->albums_collection->view()->Init(app_, service_->albums_collection_backend(), service_->albums_collection_model());
ui_->albums_collection->view()->setModel(service_->albums_collection_sort_model());
ui_->albums_collection->view()->SetFilter(ui_->albums_collection->filter());
ui_->albums_collection->filter()->SetCollectionModel(service_->albums_collection_model());
connect(ui_->albums_collection->view(), SIGNAL(GetSongs()), SLOT(GetAlbums()));
connect(ui_->albums_collection->refresh(), SIGNAL(clicked()), SLOT(GetAlbums()));
connect(service_, SIGNAL(AlbumsResults(SongList)), SLOT(AlbumsFinished(SongList)));
connect(service_, SIGNAL(AlbumsError(QString)), ui_->albums_collection->status(), SLOT(setText(QString)));
connect(service_, SIGNAL(AlbumsUpdateStatus(QString)), ui_->albums_collection->status(), SLOT(setText(QString)));
connect(service_, SIGNAL(AlbumsProgressSetMaximum(int)), ui_->albums_collection->progressbar(), SLOT(setMaximum(int)));
connect(service_, SIGNAL(AlbumsUpdateProgress(int)), ui_->albums_collection->progressbar(), SLOT(setValue(int)));
connect(service_->albums_collection_model(), SIGNAL(TotalArtistCountUpdated(int)), ui_->albums_collection->view(), SLOT(TotalArtistCountUpdated(int)));
connect(service_->albums_collection_model(), SIGNAL(TotalAlbumCountUpdated(int)), ui_->albums_collection->view(), SLOT(TotalAlbumCountUpdated(int)));
connect(service_->albums_collection_model(), SIGNAL(TotalSongCountUpdated(int)), ui_->albums_collection->view(), SLOT(TotalSongCountUpdated(int)));
connect(service_->albums_collection_model(), SIGNAL(modelAboutToBeReset()), ui_->albums_collection->view(), SLOT(SaveFocus()));
connect(service_->albums_collection_model(), SIGNAL(modelReset()), ui_->albums_collection->view(), SLOT(RestoreFocus()));
}
else {
ui_->tabs->removeTab(ui_->tabs->indexOf(ui_->albums));
}
if (service_->songs_collection_model()) {
ui_->songs_collection->stacked()->setCurrentWidget(ui_->songs_collection->internetcollection_page());
ui_->songs_collection->view()->Init(app_, service_->songs_collection_backend(), service_->songs_collection_model());
ui_->songs_collection->view()->setModel(service_->songs_collection_sort_model());
ui_->songs_collection->view()->SetFilter(ui_->songs_collection->filter());
ui_->songs_collection->filter()->SetCollectionModel(service_->songs_collection_model());
connect(ui_->songs_collection->view(), SIGNAL(GetSongs()), SLOT(GetSongs()));
connect(ui_->songs_collection->refresh(), SIGNAL(clicked()), SLOT(GetSongs()));
connect(service_, SIGNAL(SongsResults(SongList)), SLOT(SongsFinished(SongList)));
connect(service_, SIGNAL(SongsError(QString)), ui_->songs_collection->status(), SLOT(setText(QString)));
connect(service_, SIGNAL(SongsUpdateStatus(QString)), ui_->songs_collection->status(), SLOT(setText(QString)));
connect(service_, SIGNAL(SongsProgressSetMaximum(int)), ui_->songs_collection->progressbar(), SLOT(setMaximum(int)));
connect(service_, SIGNAL(SongsUpdateProgress(int)), ui_->songs_collection->progressbar(), SLOT(setValue(int)));
connect(service_->songs_collection_model(), SIGNAL(TotalArtistCountUpdated(int)), ui_->songs_collection->view(), SLOT(TotalArtistCountUpdated(int)));
connect(service_->songs_collection_model(), SIGNAL(TotalAlbumCountUpdated(int)), ui_->songs_collection->view(), SLOT(TotalAlbumCountUpdated(int)));
connect(service_->songs_collection_model(), SIGNAL(TotalSongCountUpdated(int)), ui_->songs_collection->view(), SLOT(TotalSongCountUpdated(int)));
connect(service_->songs_collection_model(), SIGNAL(modelAboutToBeReset()), ui_->songs_collection->view(), SLOT(SaveFocus()));
connect(service_->songs_collection_model(), SIGNAL(modelReset()), ui_->songs_collection->view(), SLOT(RestoreFocus()));
}
else {
ui_->tabs->removeTab(ui_->tabs->indexOf(ui_->songs));
}
QSettings s;
s.beginGroup(settings_group_);
QString tab = s.value("tab", "artists").toString().toLower();
s.endGroup();
qLog(Debug) << tab;
if (tab == "artists") {
ui_->tabs->setCurrentWidget(ui_->artists);
}
else if (tab == "albums") {
ui_->tabs->setCurrentWidget(ui_->albums);
}
else if (tab == "songs") {
ui_->tabs->setCurrentWidget(ui_->songs);
}
else if (tab == "search") {
ui_->tabs->setCurrentWidget(ui_->search);
}
ReloadSettings();
}
InternetTabsView::~InternetTabsView() {
QSettings s;
s.beginGroup(settings_group_);
s.setValue("tab", ui_->tabs->currentWidget()->objectName().toLower());
s.endGroup();
delete ui_;
}
void InternetTabsView::ReloadSettings() { ui_->search_view->ReloadSettings(); }
void InternetTabsView::contextMenuEvent(QContextMenuEvent *e) {
}
void InternetTabsView::GetArtists() {
ui_->artists_collection->stacked()->setCurrentWidget(ui_->artists_collection->help_page());
ui_->artists_collection->progressbar()->show();
service_->GetArtists();
}
void InternetTabsView::ArtistsFinished(SongList songs) {
service_->artists_collection_backend()->DeleteAll();
ui_->artists_collection->stacked()->setCurrentWidget(ui_->artists_collection->internetcollection_page());
ui_->artists_collection->status()->clear();
service_->artists_collection_backend()->AddOrUpdateSongs(songs);
}
void InternetTabsView::GetAlbums() {
ui_->albums_collection->stacked()->setCurrentWidget(ui_->albums_collection->help_page());
service_->GetAlbums();
}
void InternetTabsView::AlbumsFinished(SongList songs) {
service_->albums_collection_backend()->DeleteAll();
ui_->albums_collection->stacked()->setCurrentWidget(ui_->albums_collection->internetcollection_page());
ui_->albums_collection->status()->clear();
service_->albums_collection_backend()->AddOrUpdateSongs(songs);
}
void InternetTabsView::GetSongs() {
ui_->songs_collection->stacked()->setCurrentWidget(ui_->songs_collection->help_page());
service_->GetSongs();
}
void InternetTabsView::SongsFinished(SongList songs) {
service_->songs_collection_backend()->DeleteAll();
ui_->songs_collection->stacked()->setCurrentWidget(ui_->songs_collection->internetcollection_page());
ui_->songs_collection->status()->clear();
service_->songs_collection_backend()->AddOrUpdateSongs(songs);
}

View File

@@ -0,0 +1,76 @@
/*
* Strawberry Music Player
* Copyright 2018, Jonas Kvinge <jonas@jkvinge.net>
*
* Strawberry 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 3 of the License, or
* (at your option) any later version.
*
* Strawberry 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 Strawberry. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef INTERNETTABSVIEW_H
#define INTERNETTABSVIEW_H
#include "config.h"
#include <QWidget>
#include <QString>
#include "settings/settingsdialog.h"
#include "internetcollectionviewcontainer.h"
#include "internetcollectionview.h"
#include "ui_internettabsview.h"
#include "core/song.h"
class QContextMenuEvent;
class Application;
class InternetService;
class InternetSearch;
class Ui_InternetTabsView;
class InternetCollectionView;
class InternetSearchView;
class InternetTabsView : public QWidget {
Q_OBJECT
public:
InternetTabsView(Application *app, InternetService *service, InternetSearch *engine, QString settings_group, SettingsDialog::Page settings_page, QWidget *parent = nullptr);
~InternetTabsView();
void ReloadSettings();
InternetCollectionView *artists_collection_view() const { return ui_->artists_collection->view(); }
InternetCollectionView *albums_collection_view() const { return ui_->albums_collection->view(); }
InternetCollectionView *songs_collection_view() const { return ui_->songs_collection->view(); }
InternetSearchView *search_view() const { return ui_->search_view; }
private slots:
void contextMenuEvent(QContextMenuEvent *e);
void GetArtists();
void GetAlbums();
void GetSongs();
void ArtistsFinished(SongList songs);
void AlbumsFinished(SongList songs);
void SongsFinished(SongList songs);
private:
Application *app_;
InternetService *service_;
InternetSearch *engine_;
QString settings_group_;
SettingsDialog::Page settings_page_;
Ui_InternetTabsView *ui_;
};
#endif // INTERNETTABSVIEW_H

View File

@@ -0,0 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>InternetTabsView</class>
<widget class="QWidget" name="InternetTabsView">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>660</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QTabWidget" name="tabs">
<property name="currentIndex">
<number>3</number>
</property>
<widget class="QWidget" name="artists">
<attribute name="title">
<string>Artists</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_7">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="InternetCollectionViewContainer" name="artists_collection" native="true"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="albums">
<attribute name="title">
<string>Albums</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_8">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="InternetCollectionViewContainer" name="albums_collection" native="true"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="songs">
<attribute name="title">
<string>Songs</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_9">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="InternetCollectionViewContainer" name="songs_collection" native="true"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="search">
<attribute name="title">
<string>Search</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="InternetSearchView" name="search_view" native="true"/>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>InternetSearchView</class>
<extends>QWidget</extends>
<header>internet/internetsearchview.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>InternetCollectionViewContainer</class>
<extends>QWidget</extends>
<header>internet/internetcollectionviewcontainer.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>