PageRenderTime 31ms CodeModel.GetById 13ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/src/sourcetree/sourcesmodel.h

http://github.com/tomahawk-player/tomahawk
C++ Header | 158 lines | 102 code | 36 blank | 20 comment | 0 complexity | d2e361697017226624b69f6a540baed2 MD5 | raw file
  1/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> ===
  2 *
  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>
  6 *
  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.
 11 *
 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.
 16 *
 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/>.
 19 */
 20
 21
 22#ifndef SOURCESMODEL_H
 23#define SOURCESMODEL_H
 24
 25#include "Typedefs.h"
 26#include "Source.h"
 27
 28#include <QModelIndex>
 29#include <QStringList>
 30#include <QList>
 31#include <QAction>
 32
 33class QMimeData;
 34
 35class SourceTreeItem;
 36class GroupItem;
 37
 38namespace Tomahawk {
 39    class Source;
 40    class Playlist;
 41    class ViewPage;
 42}
 43
 44class SourcesModel : public QAbstractItemModel
 45{
 46    Q_OBJECT
 47public:
 48    enum RowType {
 49        Invalid = -1,
 50        Divider = 9,
 51
 52        Collection = 0,
 53        Group = 8,
 54
 55        Category = 1,
 56        CategoryAdd = 2,
 57
 58        StaticPlaylist = 3,
 59        AutomaticPlaylist = 4,
 60        Station = 5,
 61
 62        GenericPage = 6,
 63        TemporaryPage = 7,
 64        LovedTracksPage = 10
 65    };
 66
 67    enum CategoryType {
 68        PlaylistsCategory = 0,
 69        StationsCategory = 1
 70    };
 71
 72    enum Roles {
 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* >
 80    };
 81
 82    SourcesModel( QObject* parent = 0 );
 83    virtual ~SourcesModel();
 84
 85    static QString rowTypeToString( RowType type );
 86
 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);
 94
 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;
100
101    void appendGroups();
102
103    void appendItem( const Tomahawk::source_ptr& source );
104    bool removeItem( const Tomahawk::source_ptr& source );
105
106    void linkSourceItemToPage( SourceTreeItem* item, Tomahawk::ViewPage* p );
107    void removeSourceItemLink( SourceTreeItem* item );
108
109    QModelIndex indexFromItem( SourceTreeItem* item ) const;
110
111    QList< Tomahawk::source_ptr > sourcesWithViewPage() const;
112
113public slots:
114    void loadSources();
115
116    void itemUpdated();
117    void onItemRowsAddedBegin( int first, int last );
118    void onItemRowsAddedDone();
119    void onItemRowsRemovedBegin( int first, int last );
120    void onItemRowsRemovedDone();
121
122    void viewPageActivated( Tomahawk::ViewPage* );
123
124    void itemSelectRequest( SourceTreeItem* item );
125    void itemExpandRequest( SourceTreeItem* item );
126    void itemToggleExpandRequest( SourceTreeItem* item );
127
128signals:
129    void selectRequest( const QPersistentModelIndex& idx );
130    void expandRequest( const QPersistentModelIndex& idx );
131    void toggleExpandRequest( const QPersistentModelIndex& idx );
132
133private slots:
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 );
137
138    void onWidgetDestroyed( QWidget* w );
139
140private:
141    SourceTreeItem* itemFromIndex( const QModelIndex& idx ) const;
142    int rowForItem( SourceTreeItem* item ) const;
143    SourceTreeItem* activatePlaylistPage( Tomahawk::ViewPage* p, SourceTreeItem* i );
144
145    SourceTreeItem* m_rootItem;
146    GroupItem* m_collectionsGroup;
147    GroupItem* m_myMusicGroup;
148
149    QList< Tomahawk::source_ptr > m_sourcesWithViewPage;
150    QHash< Tomahawk::source_ptr, SourceTreeItem* > m_sourcesWithViewPageItems;
151
152    QHash< Tomahawk::ViewPage*, SourceTreeItem* > m_sourceTreeLinks;
153    Tomahawk::ViewPage* m_viewPageDelayedCacheItem;
154};
155
156Q_DECLARE_METATYPE( QList< QAction* > )
157
158#endif // SOURCESMODEL_H