]> git.sur5r.net Git - minitube/blob - src/channelsmodel.cpp
Upload 3.9.3-2 to unstable
[minitube] / src / channelsmodel.cpp
1 #include "channelsmodel.h"
2 #include "ytuser.h"
3 #include "mainwindow.h"
4
5 ChannelsModel::ChannelsModel(QObject *parent) : QSqlQueryModel(parent) {
6     hoveredRow = -1;
7 }
8
9 QVariant ChannelsModel::data(const QModelIndex &index, int role) const {
10
11     YTUser* user = 0;
12
13     switch (role) {
14
15     case ChannelsModel::ItemTypeRole:
16         return ChannelsModel::ItemChannel;
17         break;
18
19     case ChannelsModel::DataObjectRole:
20         user = userForIndex(index);
21         return QVariant::fromValue(QPointer<YTUser>(user));
22         break;
23
24     case ChannelsModel::HoveredItemRole:
25         return hoveredRow == index.row();
26         break;
27
28     case Qt::StatusTipRole:
29         user = userForIndex(index);
30         return user->getDescription();
31
32     }
33
34     return QVariant();
35 }
36
37 YTUser* ChannelsModel::userForIndex(const QModelIndex &index) const {
38     return YTUser::forId(QSqlQueryModel::data(QSqlQueryModel::index(index.row(), 0)).toString());
39 }
40
41 void ChannelsModel::setHoveredRow(int row) {
42     int oldRow = hoveredRow;
43     hoveredRow = row;
44     emit dataChanged( createIndex( oldRow, 0 ), createIndex( oldRow, columnCount() - 1 ) );
45     emit dataChanged( createIndex( hoveredRow, 0 ), createIndex( hoveredRow, columnCount() - 1 ) );
46 }
47
48 void ChannelsModel::clearHover() {
49     emit dataChanged( createIndex( hoveredRow, 0 ), createIndex( hoveredRow, columnCount() - 1 ) );
50     hoveredRow = -1;
51 }
52
53 // --- Sturm und drang ---
54
55
56 Qt::DropActions ChannelsModel::supportedDragActions() const {
57     return Qt::CopyAction;
58 }
59
60 Qt::DropActions ChannelsModel::supportedDropActions() const {
61     return Qt::CopyAction;
62 }
63
64 Qt::ItemFlags ChannelsModel::flags(const QModelIndex &index) const {
65     if (index.isValid())
66         return Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
67     else return 0;
68 }
69
70 QStringList ChannelsModel::mimeTypes() const {
71     QStringList types;
72     types << "x-minitube/channel";
73     return types;
74 }
75
76 QMimeData* ChannelsModel::mimeData( const QModelIndexList &indexes ) const {
77
78     /* TODO
79     UserMimeData* mime = new TrackMimeData();
80
81     foreach( const QModelIndex &index, indexes ) {
82         Item *item = userForIndex(index);
83         if (item) {
84             mime->addTracks(item->getTracks());
85         }
86     }
87
88     return mime;
89     */
90 }