]> git.sur5r.net Git - minitube/blob - src/playlistmodel.h
d11ee56342ce977a10ec85ceaa29bb2c6c2304b1
[minitube] / src / playlistmodel.h
1 /* $BEGIN_LICENSE
2
3 This file is part of Minitube.
4 Copyright 2009, Flavio Tordini <flavio.tordini@gmail.com>
5
6 Minitube is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 Minitube is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with Minitube.  If not, see <http://www.gnu.org/licenses/>.
18
19 $END_LICENSE */
20
21 #ifndef PLAYLISTMODEL_H
22 #define PLAYLISTMODEL_H
23
24 #include <QtWidgets>
25
26 class Video;
27 class VideoSource;
28
29 enum DataRoles {
30     ItemTypeRole = Qt::UserRole,
31     VideoRole,
32     ActiveTrackRole,
33     DownloadItemRole,
34     HoveredItemRole,
35     DownloadButtonHoveredRole,
36     DownloadButtonPressedRole,
37     AuthorHoveredRole,
38     AuthorPressedRole
39 };
40
41 enum ItemTypes {
42     ItemTypeVideo = 1,
43     ItemTypeShowMore
44 };
45
46 class PlaylistModel : public QAbstractListModel {
47
48     Q_OBJECT
49
50 public:
51     PlaylistModel(QWidget *parent = 0);
52
53     int rowCount(const QModelIndex &parent = QModelIndex()) const;
54     int columnCount( const QModelIndex& parent = QModelIndex() ) const { Q_UNUSED( parent ); return 4; }
55     QVariant data(const QModelIndex &index, int role) const;
56     bool removeRows(int position, int rows, const QModelIndex &parent);
57
58     Qt::ItemFlags flags(const QModelIndex &index) const;
59     QStringList mimeTypes() const;
60     Qt::DropActions supportedDropActions() const;
61     Qt::DropActions supportedDragActions() const;
62     QMimeData* mimeData( const QModelIndexList &indexes ) const;
63     bool dropMimeData(const QMimeData *data,
64                       Qt::DropAction action, int row, int column,
65                       const QModelIndex &parent);
66
67     void setActiveRow(int row , bool notify = true);
68     bool rowExists( int row ) const { return (( row >= 0 ) && ( row < videos.size() ) ); }
69     int activeRow() const { return m_activeRow; } // returns -1 if there is no active row
70     int nextRow() const;
71     int previousRow() const;
72     void removeIndexes(QModelIndexList &indexes);
73     int rowForVideo(Video* video);
74     QModelIndex indexForVideo(Video* video);
75     void move(QModelIndexList &indexes, bool up);
76
77     Video* videoAt( int row ) const;
78     Video* activeVideo() const;
79     int rowForCloneVideo(const QString &videoId) const;
80
81     VideoSource* getVideoSource() { return videoSource; }
82     void setVideoSource(VideoSource *videoSource);
83     void abortSearch();
84
85 public slots:
86     void searchMore();
87     void searchNeeded();
88     void addVideos(const QVector<Video *> &newVideos);
89     void searchFinished(int total);
90     void searchError(const QString &message);
91     void updateVideoSender();
92     void emitDataChanged();
93
94     void setHoveredRow(int row);
95     void clearHover();
96     void updateHoveredRow();
97
98     void enterAuthorHover();
99     void exitAuthorHover();
100     void enterAuthorPressed();
101     void exitAuthorPressed();
102
103 signals:
104     void activeRowChanged(int);
105     void needSelectionFor(const QVector<Video*> &videos);
106     void haveSuggestions(const QStringList &suggestions);
107
108 private:
109     void handleFirstVideo(Video* video);
110     void searchMore(int max);
111
112     VideoSource *videoSource;
113     bool searching;
114     bool canSearchMore;
115     bool firstSearch;
116
117     QVector<Video*> videos;
118     int startIndex;
119     int max;
120
121     int m_activeRow;
122     Video *m_activeVideo;
123
124     QString errorMessage;
125
126     int hoveredRow;
127     bool authorHovered;
128     bool authorPressed;
129
130     QMutex mutex;
131 };
132
133 #endif