/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. #ifndef SOURCESMODEL_H
  21. #define SOURCESMODEL_H
  22. #include "Typedefs.h"
  23. #include "Source.h"
  24. #include <QModelIndex>
  25. #include <QStringList>
  26. #include <QList>
  27. #include <QAction>
  28. class QMimeData;
  29. class SourceTreeItem;
  30. class GroupItem;
  31. namespace Tomahawk {
  32. class Source;
  33. class Playlist;
  34. class ViewPage;
  35. }
  36. class SourcesModel : public QAbstractItemModel
  37. {
  38. Q_OBJECT
  39. public:
  40. enum RowType {
  41. Invalid = -1,
  42. Divider = 9,
  43. Collection = 0,
  44. Group = 8,
  45. Category = 1,
  46. CategoryAdd = 2,
  47. StaticPlaylist = 3,
  48. AutomaticPlaylist = 4,
  49. Station = 5,
  50. GenericPage = 6,
  51. TemporaryPage = 7,
  52. LovedTracksPage = 10
  53. };
  54. enum CategoryType {
  55. PlaylistsCategory = 0,
  56. StationsCategory = 1
  57. };
  58. enum Roles {
  59. SourceTreeItemRole = Qt::UserRole + 10,
  60. SourceTreeItemTypeRole = Qt::UserRole + 11,
  61. SortRole = Qt::UserRole + 12,
  62. IDRole = Qt::UserRole + 13,
  63. LatchedOnRole = Qt::UserRole + 14,
  64. LatchedRealtimeRole = Qt::UserRole + 15,
  65. CustomActionRole = Qt::UserRole + 16 // QList< QAction* >
  66. };
  67. SourcesModel( QObject* parent = 0 );
  68. virtual ~SourcesModel();
  69. static QString rowTypeToString( RowType type );
  70. // reimplemented from QAIM
  71. virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
  72. virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
  73. virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
  74. virtual QModelIndex parent(const QModelIndex& child) const;
  75. virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const;
  76. virtual bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole);
  77. virtual QStringList mimeTypes() const;
  78. virtual QMimeData* mimeData(const QModelIndexList& indexes) const;
  79. virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent);
  80. virtual Qt::DropActions supportedDropActions() const;
  81. virtual Qt::ItemFlags flags(const QModelIndex& index) const;
  82. void appendGroups();
  83. void appendItem( const Tomahawk::source_ptr& source );
  84. bool removeItem( const Tomahawk::source_ptr& source );
  85. void linkSourceItemToPage( SourceTreeItem* item, Tomahawk::ViewPage* p );
  86. void removeSourceItemLink( SourceTreeItem* item );
  87. QModelIndex indexFromItem( SourceTreeItem* item ) const;
  88. QList< Tomahawk::source_ptr > sourcesWithViewPage() const;
  89. public slots:
  90. void loadSources();
  91. void itemUpdated();
  92. void onItemRowsAddedBegin( int first, int last );
  93. void onItemRowsAddedDone();
  94. void onItemRowsRemovedBegin( int first, int last );
  95. void onItemRowsRemovedDone();
  96. void viewPageActivated( Tomahawk::ViewPage* );
  97. void itemSelectRequest( SourceTreeItem* item );
  98. void itemExpandRequest( SourceTreeItem* item );
  99. void itemToggleExpandRequest( SourceTreeItem* item );
  100. signals:
  101. void selectRequest( const QPersistentModelIndex& idx );
  102. void expandRequest( const QPersistentModelIndex& idx );
  103. void toggleExpandRequest( const QPersistentModelIndex& idx );
  104. private slots:
  105. void onSourcesAdded( const QList<Tomahawk::source_ptr>& sources );
  106. void onSourceAdded( const Tomahawk::source_ptr& source );
  107. void onSourceRemoved( const Tomahawk::source_ptr& source );
  108. void onWidgetDestroyed( QWidget* w );
  109. private:
  110. SourceTreeItem* itemFromIndex( const QModelIndex& idx ) const;
  111. int rowForItem( SourceTreeItem* item ) const;
  112. SourceTreeItem* activatePlaylistPage( Tomahawk::ViewPage* p, SourceTreeItem* i );
  113. SourceTreeItem* m_rootItem;
  114. GroupItem* m_collectionsGroup;
  115. GroupItem* m_myMusicGroup;
  116. QList< Tomahawk::source_ptr > m_sourcesWithViewPage;
  117. QHash< Tomahawk::source_ptr, SourceTreeItem* > m_sourcesWithViewPageItems;
  118. QHash< Tomahawk::ViewPage*, SourceTreeItem* > m_sourceTreeLinks;
  119. Tomahawk::ViewPage* m_viewPageDelayedCacheItem;
  120. };
  121. Q_DECLARE_METATYPE( QList< QAction* > )
  122. #endif // SOURCESMODEL_H