]> git.sur5r.net Git - minitube/blob - src/playlistmodel.h
88d6dcfea7601e24bfa3bb6a17449e9774485f21
[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 <QtGui>
25 #if QT_VERSION >= 0x050000
26 #include <QtWidgets>
27 #endif
28
29 class Video;
30 class VideoSource;
31
32 enum DataRoles {
33     ItemTypeRole = Qt::UserRole,
34     VideoRole,
35     ActiveTrackRole,
36     DownloadItemRole,
37     HoveredItemRole,
38     DownloadButtonHoveredRole,
39     DownloadButtonPressedRole,
40     AuthorHoveredRole,
41     AuthorPressedRole
42 };
43
44 enum ItemTypes {
45     ItemTypeVideo = 1,
46     ItemTypeShowMore
47 };
48
49 class PlaylistModel : public QAbstractListModel {
50
51     Q_OBJECT
52
53 public:
54     PlaylistModel(QWidget *parent = 0);
55
56     int rowCount(const QModelIndex &parent = QModelIndex()) const;
57     int columnCount( const QModelIndex& parent = QModelIndex() ) const { Q_UNUSED( parent ); return 4; }
58     QVariant data(const QModelIndex &index, int role) const;
59     bool removeRows(int position, int rows, const QModelIndex &parent);
60
61     Qt::ItemFlags flags(const QModelIndex &index) const;
62     QStringList mimeTypes() const;
63     Qt::DropActions supportedDropActions() const;
64     Qt::DropActions supportedDragActions() const;
65     QMimeData* mimeData( const QModelIndexList &indexes ) const;
66     bool dropMimeData(const QMimeData *data,
67                       Qt::DropAction action, int row, int column,
68                       const QModelIndex &parent);
69
70     void setActiveRow(int row , bool notify = true);
71     bool rowExists( int row ) const { return (( row >= 0 ) && ( row < videos.size() ) ); }
72     int activeRow() const { return m_activeRow; } // returns -1 if there is no active row
73     int nextRow() const;
74     int previousRow() const;
75     void removeIndexes(QModelIndexList &indexes);
76     int rowForVideo(Video* video);
77     QModelIndex indexForVideo(Video* video);
78     void move(QModelIndexList &indexes, bool up);
79
80     Video* videoAt( int row ) const;
81     Video* activeVideo() const;
82     int rowForCloneVideo(const QString &videoId) const;
83
84     VideoSource* getVideoSource() { return videoSource; }
85     void setVideoSource(VideoSource *videoSource);
86     void abortSearch();
87
88 public slots:
89     void searchMore();
90     void searchNeeded();
91     void addVideos(QList<Video*> newVideos);
92     void searchFinished(int total);
93     void searchError(QString message);
94     void updateThumbnail();
95
96     void setHoveredRow(int row);
97     void clearHover();
98     void enterAuthorHover();
99     void exitAuthorHover();
100     void enterAuthorPressed();
101     void exitAuthorPressed();
102     void updateAuthor();
103
104 signals:
105     void activeRowChanged(int);
106     void needSelectionFor(QList<Video*>);
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     QList<Video*> videos;
119     int skip;
120     int max;
121
122     int m_activeRow;
123     Video *m_activeVideo;
124
125     QString errorMessage;
126
127     int hoveredRow;
128     bool authorHovered;
129     bool authorPressed;
130 };
131
132 #endif