~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/internet/internetservice.h

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of Clementine.
 
2
   Copyright 2010, David Sansome <me@davidsansome.com>
 
3
 
 
4
   Clementine is free software: you can redistribute it and/or modify
 
5
   it under the terms of the GNU General Public License as published by
 
6
   the Free Software Foundation, either version 3 of the License, or
 
7
   (at your option) any later version.
 
8
 
 
9
   Clementine is distributed in the hope that it will be useful,
 
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
   GNU General Public License for more details.
 
13
 
 
14
   You should have received a copy of the GNU General Public License
 
15
   along with Clementine.  If not, see <http://www.gnu.org/licenses/>.
 
16
*/
 
17
 
 
18
#ifndef INTERNETSERVICE_H
 
19
#define INTERNETSERVICE_H
 
20
 
 
21
#include <QObject>
 
22
#include <QList>
 
23
#include <QUrl>
 
24
 
 
25
#include "core/song.h"
 
26
#include "playlist/playlistitem.h"
 
27
#include "smartplaylists/generator.h"
 
28
#include "ui/settingsdialog.h"
 
29
#include "widgets/multiloadingindicator.h"
 
30
 
 
31
class InternetModel;
 
32
class LibraryFilterWidget;
 
33
 
 
34
class InternetService : public QObject {
 
35
  Q_OBJECT
 
36
 
 
37
public:
 
38
  // Constructs a new internet service with the given name and model. The name
 
39
  // should be user-friendly (like 'DigitallyImported' or 'Last.fm').
 
40
  InternetService(const QString& name, InternetModel* model, QObject* parent = NULL);
 
41
  virtual ~InternetService() {}
 
42
 
 
43
  QString name() const { return name_; }
 
44
  InternetModel* model() const { return model_; }
 
45
 
 
46
  virtual QStandardItem* CreateRootItem() = 0;
 
47
  virtual void LazyPopulate(QStandardItem* parent) = 0;
 
48
 
 
49
  virtual void ShowContextMenu(const QModelIndex& index, const QPoint& global_pos) {}
 
50
  virtual void ItemDoubleClicked(QStandardItem* item) {}
 
51
  // Create a generator for smart playlists
 
52
  virtual smart_playlists::GeneratorPtr CreateGenerator(QStandardItem* item) { return smart_playlists::GeneratorPtr(); }
 
53
  // Give the service a chance to do a custom action when data is dropped on it
 
54
  virtual void DropMimeData(const QMimeData* data, const QModelIndex& index) {}
 
55
 
 
56
  virtual PlaylistItem::Options playlistitem_options() const { return PlaylistItem::Default; }
 
57
  // Redefine this function to add service' specific actions to the playlist item
 
58
  virtual QList<QAction*> playlistitem_actions(const Song& song) { return QList<QAction*>(); }
 
59
 
 
60
  virtual QWidget* HeaderWidget() const { return NULL; }
 
61
 
 
62
  virtual void ReloadSettings() {}
 
63
 
 
64
  virtual QString Icon() { return QString(); }
 
65
 
 
66
signals:
 
67
  void StreamError(const QString& message);
 
68
  void StreamMetadataFound(const QUrl& original_url, const Song& song);
 
69
  void OpenSettingsAtPage(SettingsDialog::Page page);
 
70
 
 
71
  void AddToPlaylistSignal(QMimeData* data);
 
72
 
 
73
private slots:
 
74
  void AppendToPlaylist();
 
75
  void ReplacePlaylist();
 
76
  void OpenInNewPlaylist();
 
77
 
 
78
protected:
 
79
  // Subclass provides the currently selected QModelIndex on InternetService's
 
80
  // request.
 
81
  virtual QModelIndex GetCurrentIndex() = 0;
 
82
 
 
83
  // Returns all the playlist insertion related QActions (see below).
 
84
  QList<QAction*> GetPlaylistActions();
 
85
 
 
86
  // Returns the 'append to playlist' QAction.
 
87
  QAction* GetAppendToPlaylistAction();
 
88
  // Returns the 'replace playlist' QAction.
 
89
  QAction* GetReplacePlaylistAction();
 
90
  // Returns the 'open in new playlist' QAction.
 
91
  QAction* GetOpenInNewPlaylistAction();
 
92
 
 
93
  // Describes how songs should be added to playlist.
 
94
  enum AddMode {
 
95
    // appends songs to the current playlist
 
96
    AddMode_Append,
 
97
    // clears the current playlist and then appends all songs to it
 
98
    AddMode_Replace,
 
99
    // creates a new, empty playlist and then adds all songs to it
 
100
    AddMode_OpenInNew
 
101
  };
 
102
 
 
103
  // Adds the 'index' element to playlist using the 'add_mode' mode.
 
104
  void AddItemToPlaylist(const QModelIndex& index, AddMode add_mode);
 
105
  // Adds the 'indexes' elements to playlist using the 'add_mode' mode.
 
106
  void AddItemsToPlaylist(const QModelIndexList& indexes, AddMode add_mode);
 
107
 
 
108
private:
 
109
  InternetModel* model_;
 
110
  QString name_;
 
111
 
 
112
  QAction* append_to_playlist_;
 
113
  QAction* replace_playlist_;
 
114
  QAction* open_in_new_playlist_;
 
115
  QAction* separator_;
 
116
};
 
117
 
 
118
Q_DECLARE_METATYPE(InternetService*);
 
119
 
 
120
#endif // INTERNETSERVICE_H