File indexing completed on 2024-05-05 04:47:30

0001 /****************************************************************************************
0002  * Copyright (c) 2007 Alexandre Pereira de Oliveira <aleprj@gmail.com>                  *
0003  *                                                                                      *
0004  * This program is free software; you can redistribute it and/or modify it under        *
0005  * the terms of the GNU General Public License as published by the Free Software        *
0006  * Foundation; either version 2 of the License, or (at your option) any later           *
0007  * version.                                                                             *
0008  *                                                                                      *
0009  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0011  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0012  *                                                                                      *
0013  * You should have received a copy of the GNU General Public License along with         *
0014  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0015  ****************************************************************************************/
0016 
0017 #ifndef COLLECTIONTREEVIEW_H
0018 #define COLLECTIONTREEVIEW_H
0019 
0020 #include "amarok_export.h"
0021 #include "BrowserDefines.h"
0022 #include "widgets/PrettyTreeView.h"
0023 #include "browsers/CollectionTreeItem.h"
0024 #include "core/meta/forward_declarations.h"
0025 #include "playlist/PlaylistController.h"
0026 
0027 #include <QModelIndex>
0028 #include <QMutex>
0029 #include <QSet>
0030 #include <QApplication>
0031 
0032 class AmarokMimeData;
0033 class CollectionSortFilterProxyModel;
0034 class CollectionTreeItemModelBase;
0035 class PopupDropper;
0036 namespace Collections {
0037     class Collection;
0038     class QueryMaker;
0039 }
0040 class QAction;
0041 class QSortFilterProxyModel;
0042 
0043 typedef QList<QAction *> QActionList;
0044 
0045 class AMAROK_EXPORT CollectionTreeView : public Amarok::PrettyTreeView
0046 {
0047         Q_OBJECT
0048 
0049     public:
0050         explicit CollectionTreeView( QWidget *parent = nullptr );
0051         ~CollectionTreeView() override;
0052 
0053         QSortFilterProxyModel* filterModel() const;
0054 
0055         void setLevels( const QList<CategoryId::CatMenuId> &levels );
0056         QList<CategoryId::CatMenuId> levels() const;
0057 
0058         void setLevel( int level, CategoryId::CatMenuId type );
0059 
0060         void setModel( QAbstractItemModel *model ) override;
0061 
0062         //Helper function to remove children if their parent is already present
0063         static QSet<CollectionTreeItem*> cleanItemSet( const QSet<CollectionTreeItem*> &items );
0064         static bool onlyOneCollection( const QModelIndexList &indices );
0065         static Collections::Collection *getCollection( const QModelIndex &index );
0066         Collections::QueryMaker* createMetaQueryFromItems( const QSet<CollectionTreeItem*> &items, bool cleanItems=true ) const;
0067 
0068         /**
0069          * Copies all selected tracks to the local collection. The user can also
0070          * choose to do on-the-fly transcoding.
0071          */
0072         void copySelectedToLocalCollection();
0073 
0074     public Q_SLOTS:
0075         void slotSetFilter( const QString &filter );
0076 
0077         /**
0078          * This should append all currently visible tracks to the playlist. Takes
0079          * care to ensure that the tracks are added only after any pending searches
0080          * are finished.
0081          */
0082         void slotAddFilteredTracksToPlaylist();
0083 
0084         void playChildTracksSlot( Meta::TrackList list );
0085 
0086     Q_SIGNALS:
0087         /**
0088          * This signal is emitted when slotAddFilteredTracksToPlaylist() has done its
0089          * work.
0090          */
0091         void addingFilteredTracksDone();
0092 
0093     protected:
0094         void contextMenuEvent( QContextMenuEvent *event ) override;
0095         void mouseDoubleClickEvent( QMouseEvent *event ) override;
0096         void mouseReleaseEvent( QMouseEvent *event ) override;
0097         void keyPressEvent( QKeyEvent *event ) override;
0098         void dragEnterEvent( QDragEnterEvent *event ) override;
0099         void dragMoveEvent( QDragMoveEvent *event ) override;
0100         void startDrag( Qt::DropActions supportedActions ) override;
0101 
0102     protected Q_SLOTS:
0103         void selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected ) override;
0104         void slotCollapsed( const QModelIndex &index );
0105         void slotExpanded( const QModelIndex &index );
0106         void slotExpandIndex( const QModelIndex &index );
0107 
0108         void slotCheckAutoExpand( bool reallyExpand = true );
0109         void slotCheckAutoExpandReally() { slotCheckAutoExpand( true ); }
0110 
0111         void slotReplacePlaylistWithChildTracks();
0112         void slotAppendChildTracks();
0113         void slotQueueChildTracks();
0114         void slotEditTracks();
0115         void slotCopyTracks();
0116         void slotMoveTracks();
0117         void slotTrashTracks();
0118         void slotDeleteTracks();
0119         void slotOrganize();
0120 
0121     private:
0122         // Utility function to play all items
0123         // that have this as a parent..
0124         void playChildTracks( CollectionTreeItem *item, Playlist::AddOptions insertMode );
0125         void playChildTracks( const QSet<CollectionTreeItem*> &items, Playlist::AddOptions insertMode );
0126         void editTracks( const QSet<CollectionTreeItem*> &items ) const;
0127         void organizeTracks( const QSet<CollectionTreeItem*> &items ) const;
0128         void copyTracks( const QSet<CollectionTreeItem*> &items, Collections::Collection *destination,
0129                          bool removeSources) const;
0130         void removeTracks( const QSet<CollectionTreeItem*> &items, bool useTrash ) const;
0131 
0132         // creates different actions from the different objects.
0133         // note: you should not delete the created actions.
0134         QActionList createBasicActions( const QModelIndexList &indices );
0135         QActionList createExtendedActions( const QModelIndexList &indices );
0136         QActionList createCollectionActions( const QModelIndexList &indices );
0137         QActionList createCustomActions( const QModelIndexList &indices );
0138 
0139         QHash<QAction*, Collections::Collection*> getCopyActions( const QModelIndexList &indices );
0140         QHash<QAction*, Collections::Collection*> getMoveActions( const QModelIndexList &indices );
0141 
0142         CollectionTreeItem* getItemFromIndex( QModelIndex &index );
0143 
0144         CollectionSortFilterProxyModel *m_filterModel;
0145         CollectionTreeItemModelBase *m_treeModel;
0146         PopupDropper* m_pd;
0147         QAction* m_appendAction;
0148         QAction* m_loadAction;
0149         QAction* m_editAction;
0150         QAction* m_organizeAction;
0151 
0152         QHash<QAction*, Collections::Collection*> m_currentCopyDestination;
0153         QHash<QAction*, Collections::Collection*> m_currentMoveDestination;
0154 
0155         QMap<AmarokMimeData*, Playlist::AddOptions> m_playChildTracksMode;
0156 
0157         QSet<CollectionTreeItem*> m_currentItems;
0158 
0159         bool m_ongoingDrag;
0160 
0161     Q_SIGNALS:
0162         void itemSelected( CollectionTreeItem * item );
0163         void leavingTree();
0164 };
0165 
0166 #endif