]> git.sur5r.net Git - minitube/blob - src/playlistmodel.h
Upload 3.9.3-2 to unstable
[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 { ItemTypeVideo = 1, ItemTypeShowMore };
42
43 class PlaylistModel : public QAbstractListModel {
44     Q_OBJECT
45
46 public:
47     PlaylistModel(QWidget *parent = 0);
48
49     int rowCount(const QModelIndex &parent = QModelIndex()) const;
50     int columnCount(const QModelIndex &parent = QModelIndex()) const {
51         Q_UNUSED(parent);
52         return 4;
53     }
54     QVariant data(const QModelIndex &index, int role) const;
55     bool removeRows(int position, int rows, const QModelIndex &parent);
56
57     Qt::ItemFlags flags(const QModelIndex &index) const;
58     QStringList mimeTypes() const;
59     Qt::DropActions supportedDropActions() const;
60     Qt::DropActions supportedDragActions() const;
61     QMimeData *mimeData(const QModelIndexList &indexes) const;
62     bool dropMimeData(const QMimeData *data,
63                       Qt::DropAction action,
64                       int row,
65                       int column,
66                       const QModelIndex &parent);
67
68     void setActiveRow(int row, bool notify = true);
69     bool rowExists(int row) const { return ((row >= 0) && (row < videos.size())); }
70     int activeRow() const { return m_activeRow; } // returns -1 if there is no active row
71     int nextRow() const;
72     int previousRow() const;
73     void removeIndexes(QModelIndexList &indexes);
74     int rowForVideo(Video *video);
75     QModelIndex indexForVideo(Video *video);
76     void move(QModelIndexList &indexes, bool up);
77
78     Video *videoAt(int row) const;
79     Video *activeVideo() const;
80     int rowForCloneVideo(const QString &videoId) const;
81
82     VideoSource *getVideoSource() { return videoSource; }
83     void setVideoSource(VideoSource *videoSource);
84     void abortSearch();
85
86 public slots:
87     void searchMore();
88     void searchNeeded();
89     void addVideos(const QVector<Video *> &newVideos);
90     void searchFinished(int total);
91     void searchError(const QString &message);
92     void updateVideoSender();
93     void emitDataChanged();
94
95     void setHoveredRow(int row);
96     void clearHover();
97     void updateHoveredRow();
98
99     void enterAuthorHover();
100     void exitAuthorHover();
101     void enterAuthorPressed();
102     void exitAuthorPressed();
103
104 signals:
105     void activeVideoChanged(Video *video, Video *previousVideo);
106     void needSelectionFor(const QVector<Video *> &videos);
107     void haveSuggestions(const QStringList &suggestions);
108
109 private:
110     void handleFirstVideo(Video *video);
111     void searchMore(int max);
112
113     VideoSource *videoSource;
114     bool searching;
115     bool canSearchMore;
116     bool firstSearch;
117
118     QVector<Video *> videos;
119     QVector<Video *> deletedVideos;
120     int startIndex;
121     int max;
122
123     int m_activeRow;
124     Video *m_activeVideo;
125
126     QString errorMessage;
127
128     int hoveredRow;
129     bool authorHovered;
130     bool authorPressed;
131
132     QMutex mutex;
133 };
134
135 #endif