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