]> git.sur5r.net Git - minitube/blob - src/ListModel.h
Initial import
[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     StreamUrlRole,
12     ActiveTrackRole
13 };
14
15 enum ItemTypes {
16     ItemTypeVideo = 1,
17     ItemTypeShowMore
18 };
19
20 class ListModel : public QAbstractListModel {
21
22     Q_OBJECT
23
24 public:
25
26     ListModel(QWidget *parent);
27     ~ListModel();
28
29     // inherited from QAbstractListModel
30     int rowCount(const QModelIndex &parent = QModelIndex()) const;
31     // int rowCount( const QModelIndex& parent = QModelIndex() ) const { Q_UNUSED( parent ); return videos.size(); }
32     int columnCount( const QModelIndex& parent = QModelIndex() ) const { Q_UNUSED( parent ); return 4; }
33     QVariant data(const QModelIndex &index, int role) const;
34     bool removeRows(int position, int rows, const QModelIndex &parent);
35
36     Qt::ItemFlags flags(const QModelIndex &index) const;
37     QStringList mimeTypes() const;
38     Qt::DropActions supportedDropActions() const;
39     QMimeData* mimeData( const QModelIndexList &indexes ) const;
40     bool dropMimeData(const QMimeData *data,
41                       Qt::DropAction action, int row, int column,
42                       const QModelIndex &parent);
43
44     // custom methods
45     void setActiveRow( int row );
46     bool rowExists( int row ) const { return (( row >= 0 ) && ( row < videos.size() ) ); }
47     // int activeRow() const { return m_activeRow; } // returns -1 if there is no active row
48     int nextRow() const;
49     void removeIndexes(QModelIndexList &indexes);
50     int rowForVideo(Video* video);
51     QModelIndex indexForVideo(Video* video);
52     void move(QModelIndexList &indexes, bool up);
53
54     Video* videoAt( int row ) const;
55     Video* activeVideo() const;
56
57     // video search methods
58     void search(SearchParams *searchParams);
59     void abortSearch();
60
61
62 public slots:
63     void searchMore();
64     void searchNeeded();
65     void addVideo(Video* video);
66     void searchFinished(int total);
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 };
89
90 #endif