]> git.sur5r.net Git - minitube/blob - src/ListModel.h
Imported Upstream version 1.2
[minitube] / src / ListModel.h
1 #ifndef LISTMODEL_H
2 #define LISTMODEL_H
3
4 #include "video.h"
5 #include "youtubesearch.h"
6 #include "searchparams.h"
7
8 enum DataRoles {
9     ItemTypeRole = Qt::UserRole,
10     VideoRole,
11     ActiveTrackRole,
12     DownloadItemRole,
13     HoveredItemRole,
14     DownloadButtonHoveredRole,
15     DownloadButtonPressedRole
16 };
17
18 enum ItemTypes {
19     ItemTypeVideo = 1,
20     ItemTypeShowMore
21 };
22
23 class ListModel : public QAbstractListModel {
24
25     Q_OBJECT
26
27 public:
28
29     ListModel(QWidget *parent);
30     ~ListModel();
31
32     // inherited from QAbstractListModel
33     int rowCount(const QModelIndex &parent = QModelIndex()) const;
34     // int rowCount( const QModelIndex& parent = QModelIndex() ) const { Q_UNUSED( parent ); return videos.size(); }
35     int columnCount( const QModelIndex& parent = QModelIndex() ) const { Q_UNUSED( parent ); return 4; }
36     QVariant data(const QModelIndex &index, int role) const;
37     bool removeRows(int position, int rows, const QModelIndex &parent);
38
39     Qt::ItemFlags flags(const QModelIndex &index) const;
40     QStringList mimeTypes() const;
41     Qt::DropActions supportedDropActions() const;
42     QMimeData* mimeData( const QModelIndexList &indexes ) const;
43     bool dropMimeData(const QMimeData *data,
44                       Qt::DropAction action, int row, int column,
45                       const QModelIndex &parent);
46
47     // custom methods
48     void setActiveRow( int row );
49     bool rowExists( int row ) const { return (( row >= 0 ) && ( row < videos.size() ) ); }
50     int activeRow() const { return m_activeRow; } // returns -1 if there is no active row
51     int nextRow() const;
52     void removeIndexes(QModelIndexList &indexes);
53     int rowForVideo(Video* video);
54     QModelIndex indexForVideo(Video* video);
55     void move(QModelIndexList &indexes, bool up);
56
57     Video* videoAt( int row ) const;
58     Video* activeVideo() const;
59
60     // video search methods
61     void search(SearchParams *searchParams);
62     void abortSearch();
63
64
65 public slots:
66     void searchMore();
67     void searchNeeded();
68     void addVideo(Video* video);
69     void searchFinished(int total);
70     void searchError(QString message);
71     void updateThumbnail();
72
73 signals:
74     void activeRowChanged(int);
75     void needSelectionFor(QList<Video*>);
76
77 private:
78     void searchMore(int max);
79
80     YouTubeSearch *youtubeSearch;
81     SearchParams *searchParams;
82     bool searching;
83     bool canSearchMore;
84
85     QList<Video*> videos;
86     int skip;
87
88     // the row being played
89     int m_activeRow;
90     Video *m_activeVideo;
91
92     QString errorMessage;
93 };
94
95 #endif