1
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
3
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
4
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
5
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
7
* Tomahawk is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
12
* Tomahawk is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with Tomahawk. If not, see <http://www.gnu.org/licenses/>.
22
#ifndef SOURCESMODEL_H
23
#define SOURCESMODEL_H
28
#include <QModelIndex>
29
#include <QStringList>
44
class SourcesModel : public QAbstractItemModel
59
AutomaticPlaylist = 4,
68
PlaylistsCategory = 0,
73
SourceTreeItemRole = Qt::UserRole + 10,
74
SourceTreeItemTypeRole = Qt::UserRole + 11,
75
SortRole = Qt::UserRole + 12,
76
IDRole = Qt::UserRole + 13,
77
LatchedOnRole = Qt::UserRole + 14,
78
LatchedRealtimeRole = Qt::UserRole + 15,
79
CustomActionRole = Qt::UserRole + 16 // QList< QAction* >
82
SourcesModel( QObject* parent = 0 );
83
virtual ~SourcesModel();
85
static QString rowTypeToString( RowType type );
87
// reimplemented from QAIM
88
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
89
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
90
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
91
virtual QModelIndex parent(const QModelIndex& child) const;
92
virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
93
virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
95
virtual QStringList mimeTypes() const;
96
virtual QMimeData* mimeData(const QModelIndexList& indexes) const;
97
virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent);
98
virtual Qt::DropActions supportedDropActions() const;
99
virtual Qt::ItemFlags flags(const QModelIndex& index) const;
103
void appendItem( const Tomahawk::source_ptr& source );
104
bool removeItem( const Tomahawk::source_ptr& source );
106
void linkSourceItemToPage( SourceTreeItem* item, Tomahawk::ViewPage* p );
107
void removeSourceItemLink( SourceTreeItem* item );
109
QModelIndex indexFromItem( SourceTreeItem* item ) const;
111
QList< Tomahawk::source_ptr > sourcesWithViewPage() const;
117
void onItemRowsAddedBegin( int first, int last );
118
void onItemRowsAddedDone();
119
void onItemRowsRemovedBegin( int first, int last );
120
void onItemRowsRemovedDone();
122
void viewPageActivated( Tomahawk::ViewPage* );
124
void itemSelectRequest( SourceTreeItem* item );
125
void itemExpandRequest( SourceTreeItem* item );
126
void itemToggleExpandRequest( SourceTreeItem* item );
129
void selectRequest( const QPersistentModelIndex& idx );
130
void expandRequest( const QPersistentModelIndex& idx );
131
void toggleExpandRequest( const QPersistentModelIndex& idx );
134
void onSourcesAdded( const QList<Tomahawk::source_ptr>& sources );
135
void onSourceAdded( const Tomahawk::source_ptr& source );
136
void onSourceRemoved( const Tomahawk::source_ptr& source );
138
void onWidgetDestroyed( QWidget* w );
141
SourceTreeItem* itemFromIndex( const QModelIndex& idx ) const;
142
int rowForItem( SourceTreeItem* item ) const;
143
SourceTreeItem* activatePlaylistPage( Tomahawk::ViewPage* p, SourceTreeItem* i );
145
SourceTreeItem* m_rootItem;
146
GroupItem* m_collectionsGroup;
147
GroupItem* m_myMusicGroup;
149
QList< Tomahawk::source_ptr > m_sourcesWithViewPage;
150
QHash< Tomahawk::source_ptr, SourceTreeItem* > m_sourcesWithViewPageItems;
152
QHash< Tomahawk::ViewPage*, SourceTreeItem* > m_sourceTreeLinks;
153
Tomahawk::ViewPage* m_viewPageDelayedCacheItem;
156
Q_DECLARE_METATYPE( QList< QAction* > )
158
#endif // SOURCESMODEL_H