]> git.sur5r.net Git - minitube/blob - src/ListModel.h
2752aab196229dd4b1c4e20d8d2e4adc84322d67
[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     AuthorHoveredRole,
17     AuthorPressedRole
18 };
19
20 enum ItemTypes {
21     ItemTypeVideo = 1,
22     ItemTypeShowMore
23 };
24
25 class ListModel : public QAbstractListModel {
26
27     Q_OBJECT
28
29 public:
30
31     ListModel(QWidget *parent);
32     ~ListModel();
33
34     // inherited from QAbstractListModel
35     int rowCount(const QModelIndex &parent = QModelIndex()) const;
36     // int rowCount( const QModelIndex& parent = QModelIndex() ) const { Q_UNUSED( parent ); return videos.size(); }
37     int columnCount( const QModelIndex& parent = QModelIndex() ) const { Q_UNUSED( parent ); return 4; }
38     QVariant data(const QModelIndex &index, int role) const;
39     bool removeRows(int position, int rows, const QModelIndex &parent);
40
41     Qt::ItemFlags flags(const QModelIndex &index) const;
42     QStringList mimeTypes() const;
43     Qt::DropActions supportedDropActions() const;
44     QMimeData* mimeData( const QModelIndexList &indexes ) const;
45     bool dropMimeData(const QMimeData *data,
46                       Qt::DropAction action, int row, int column,
47                       const QModelIndex &parent);
48
49     // custom methods
50     void setActiveRow( int row );
51     bool rowExists( int row ) const { return (( row >= 0 ) && ( row < videos.size() ) ); }
52     int activeRow() const { return m_activeRow; } // returns -1 if there is no active row
53     int nextRow() const;
54     int previousRow() const;
55     void removeIndexes(QModelIndexList &indexes);
56     int rowForVideo(Video* video);
57     QModelIndex indexForVideo(Video* video);
58     void move(QModelIndexList &indexes, bool up);
59
60     Video* videoAt( int row ) const;
61     Video* activeVideo() const;
62
63     // video search methods
64     void search(SearchParams *searchParams);
65     void abortSearch();
66
67
68 public slots:
69     void searchMore();
70     void searchNeeded();
71     void addVideo(Video* video);
72     void searchFinished(int total);
73     void searchError(QString message);
74     void updateThumbnail();
75
76     void setHoveredRow(int row);
77     void clearHover();
78     void enterAuthorHover();
79     void exitAuthorHover();
80     void enterAuthorPressed();
81     void exitAuthorPressed();
82     void updateAuthor();
83
84 signals:
85     void activeRowChanged(int);
86     void needSelectionFor(QList<Video*>);
87
88 private:
89     void searchMore(int max);
90
91     YouTubeSearch *youtubeSearch;
92     SearchParams *searchParams;
93     bool searching;
94     bool canSearchMore;
95
96     QList<Video*> videos;
97     int skip;
98
99     // the row being played
100     int m_activeRow;
101     Video *m_activeVideo;
102
103     QString errorMessage;
104
105     int hoveredRow;
106     bool authorHovered;
107     bool authorPressed;
108 };
109
110 #endif