1 /*
2  * Strawberry Music Player
3  * Copyright 2018-2021, Jonas Kvinge <jonas@jkvinge.net>
4  *
5  * Strawberry is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * Strawberry is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with Strawberry.  If not, see <http://www.gnu.org/licenses/>.
17  *
18  */
19 
20 #ifndef INTERNETSERVICE_H
21 #define INTERNETSERVICE_H
22 
23 #include <QtGlobal>
24 #include <QObject>
25 #include <QMetaType>
26 #include <QMap>
27 #include <QString>
28 #include <QUrl>
29 #include <QIcon>
30 
31 #include "core/song.h"
32 #include "settings/settingsdialog.h"
33 #include "internetsearchview.h"
34 
35 class QSortFilterProxyModel;
36 class Application;
37 class CollectionBackend;
38 class CollectionModel;
39 
40 class InternetService : public QObject {
41   Q_OBJECT
42 
43  public:
44   explicit InternetService(Song::Source source, const QString &name, const QString &url_scheme, const QString &settings_group, SettingsDialog::Page settings_page, Application *app, QObject *parent = nullptr);
45 
46   ~InternetService() override {}
47   virtual void Exit() {}
48 
49   virtual Song::Source source() const { return source_; }
50   virtual QString name() const { return name_; }
51   virtual QString url_scheme() const { return url_scheme_; }
52   virtual QString settings_group() const { return settings_group_; }
53   virtual SettingsDialog::Page settings_page() const { return settings_page_; }
54   virtual bool has_initial_load_settings() const { return false; }
55   virtual void InitialLoadSettings() {}
56   virtual void ReloadSettings() {}
57   virtual QIcon Icon() { return Song::IconForSource(source_); }
58   virtual bool oauth() { return false; }
59   virtual bool authenticated() { return false; }
60   virtual int Search(const QString &query, InternetSearchView::SearchType type) { Q_UNUSED(query); Q_UNUSED(type); return 0; }
61   virtual void CancelSearch() {}
62 
63   virtual CollectionBackend *artists_collection_backend() { return nullptr; }
64   virtual CollectionBackend *albums_collection_backend() { return nullptr; }
65   virtual CollectionBackend *songs_collection_backend() { return nullptr; }
66 
67   virtual CollectionModel *artists_collection_model() { return nullptr; }
68   virtual CollectionModel *albums_collection_model() { return nullptr; }
69   virtual CollectionModel *songs_collection_model() { return nullptr; }
70 
71   virtual QSortFilterProxyModel *artists_collection_sort_model() { return nullptr; }
72   virtual QSortFilterProxyModel *albums_collection_sort_model() { return nullptr; }
73   virtual QSortFilterProxyModel *songs_collection_sort_model() { return nullptr; }
74 
75  public slots:
76   virtual void ShowConfig() {}
77   virtual void GetArtists() {}
78   virtual void GetAlbums() {}
79   virtual void GetSongs() {}
80   virtual void ResetArtistsRequest() {}
81   virtual void ResetAlbumsRequest() {}
82   virtual void ResetSongsRequest() {}
83 
84  signals:
85   void ExitFinished();
86   void RequestLogin();
87   void RequestLogout();
88   void LoginWithCredentials(QString api_token, QString username, QString password);
89   void LoginWithHostname(QString hostname, int, QString username, QString password);
90   void LoginSuccess();
91   void LoginFailure(QString failure_reason);
92   void LoginComplete(bool success, QString error = QString());
93 
94   void TestSuccess();
95   void TestFailure(QString failure_reason);
96   void TestComplete(bool success, QString error = QString());
97 
98   void Error(QString error);
99   void Results(SongMap songs, QString error);
100   void UpdateStatus(QString text);
101   void ProgressSetMaximum(int max);
102   void UpdateProgress(int max);
103 
104   void ArtistsResults(SongMap songs, QString error);
105   void ArtistsUpdateStatus(QString text);
106   void ArtistsProgressSetMaximum(int max);
107   void ArtistsUpdateProgress(int max);
108 
109   void AlbumsResults(SongMap songs, QString error);
110   void AlbumsUpdateStatus(QString text);
111   void AlbumsProgressSetMaximum(int max);
112   void AlbumsUpdateProgress(int max);
113 
114   void SongsResults(SongMap songs, QString error);
115   void SongsUpdateStatus(QString text);
116   void SongsProgressSetMaximum(int max);
117   void SongsUpdateProgress(int max);
118 
119   void SearchResults(int id, SongMap songs, QString error);
120   void SearchUpdateStatus(int id, QString text);
121   void SearchProgressSetMaximum(int id, int max);
122   void SearchUpdateProgress(int id, int max);
123 
124   void AddArtists(SongList songs);
125   void AddAlbums(SongList songs);
126   void AddSongs(SongMap songs);
127 
128   void RemoveArtists(SongList songs);
129   void RemoveAlbums(SongList songs);
130   void RemoveSongs(SongList songs);
131   void RemoveSongs(SongMap songs);
132 
133   void StreamURLFinished(QUrl original_url, QUrl stream_url, Song::FileType filetype, int samplerate, int bit_depth, qint64 duration, QString error = QString());
134 
135  protected:
136   Application *app_;
137 
138  private:
139   Song::Source source_;
140   QString name_;
141   QString url_scheme_;
142   QString settings_group_;
143   SettingsDialog::Page settings_page_;
144 
145 };
146 Q_DECLARE_METATYPE(InternetService*)
147 
148 #endif  // INTERNETSERVICE_H
149