File indexing completed on 2024-05-19 04:48:39

0001 /****************************************************************************************
0002  * Copyright (c) 2010 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0003  * Copyright (c) 2010 Casey Link <unnamedrambler@gmail.com>                             *
0004  *                                                                                      *
0005  * This program is free software; you can redistribute it and/or modify it under        *
0006  * the terms of the GNU General Public License as published by the Free Software        *
0007  * Foundation; either version 2 of the License, or (at your option) any later           *
0008  * version.                                                                             *
0009  *                                                                                      *
0010  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0012  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0013  *                                                                                      *
0014  * You should have received a copy of the GNU General Public License along with         *
0015  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0016  ****************************************************************************************/
0017 
0018 #ifndef AMAROK_FILEVIEW_H
0019 #define AMAROK_FILEVIEW_H
0020 
0021 #include "core/collections/Collection.h"
0022 #include "core/meta/forward_declarations.h"
0023 #include "playlist/PlaylistController.h"
0024 #include "widgets/PrettyTreeView.h"
0025 
0026 #include <KFileItem>
0027 
0028 #include <QAction>
0029 #include <QList>
0030 #include <QTreeView>
0031 #include <QMutex>
0032 
0033 class PopupDropper;
0034 
0035 /**
0036 * Stores a collection associated with an action for move/copy to collection
0037 */
0038 class CollectionAction : public QAction
0039 {
0040     public:
0041         explicit CollectionAction( Collections::Collection *coll, QObject *parent = nullptr )
0042         : QAction( parent )
0043         , m_collection( coll )
0044         {
0045             setText( m_collection->prettyName() );
0046         }
0047 
0048         Collections::Collection *collection() const
0049         {
0050             return m_collection;
0051         }
0052 
0053     private:
0054         Collections::Collection *m_collection;
0055 };
0056 
0057 
0058 class FileView : public Amarok::PrettyTreeView
0059 {
0060     Q_OBJECT
0061 
0062 public:
0063     explicit FileView( QWidget *parent );
0064 
0065 Q_SIGNALS:
0066     void navigateToDirectory( const QModelIndex &index );
0067     void refreshBrowser();
0068 
0069 protected Q_SLOTS:
0070     void slotAppendToPlaylist();
0071     void slotReplacePlaylist();
0072     void slotEditTracks();
0073     void slotPrepareMoveTracks();
0074     void slotPrepareCopyTracks();
0075     void slotMoveTracks( const Meta::TrackList &tracks );
0076     void slotCopyTracks( const Meta::TrackList &tracks );
0077     void slotMoveToTrash( Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers );
0078     void slotMoveToTrashWithoutModifiers() { slotMoveToTrash( Qt::NoButton, Qt::NoModifier ); }
0079     void slotDelete();
0080 
0081 protected:
0082     enum ActionType {
0083         PlaylistAction = 1,
0084         OrganizeAction = 2,
0085         EditAction = 4,
0086         AllActions = PlaylistAction | OrganizeAction | EditAction
0087     };
0088     QList<QAction *> actionsForIndices( const QModelIndexList &indices, ActionType type = AllActions );
0089     void addSelectionToPlaylist( Playlist::AddOptions options );
0090 
0091     /**
0092      * Convenience.
0093      */
0094     void addIndexToPlaylist( const QModelIndex &idx, Playlist::AddOptions options );
0095     void addIndicesToPlaylist( QModelIndexList indices, Playlist::AddOptions options );
0096 
0097     void contextMenuEvent( QContextMenuEvent *e ) override;
0098     void mouseReleaseEvent( QMouseEvent *event ) override;
0099     void mouseDoubleClickEvent( QMouseEvent *event ) override;
0100 
0101     void keyPressEvent( QKeyEvent *event ) override;
0102 
0103     void startDrag( Qt::DropActions supportedActions ) override;
0104     KFileItemList selectedItems() const;
0105 
0106 private:
0107     Meta::TrackList tracksForEdit() const;
0108 
0109     QAction *m_appendAction;
0110     QAction *m_loadAction;
0111     QAction *m_editAction;
0112     QAction *m_moveToTrashAction;
0113     QAction *m_deleteAction;
0114 
0115     PopupDropper *m_pd;
0116     QMutex m_dragMutex;
0117     bool m_ongoingDrag;
0118     QPointer<Collections::Collection> m_moveDestinationCollection;
0119     QPointer<Collections::Collection> m_copyDestinationCollection;
0120 };
0121 
0122 #endif // end include guard