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

0001 /****************************************************************************************
0002  * Copyright (c) 2008 Nikolaj Hald Nielsen <nhn@kde.org>                                *
0003  * Copyright (c) 2010 Bart Cerneels <bart.cerneels@kde.org>                             *
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 PLAYLISTBROWSERVIEW_H
0019 #define PLAYLISTBROWSERVIEW_H
0020 
0021 #include "core/playlists/Playlist.h"
0022 #include "playlist/PlaylistController.h"
0023 #include "widgets/PrettyTreeView.h"
0024 
0025 #include <QMutex>
0026 #include <QDialogButtonBox>
0027 #include <QVBoxLayout>
0028 #include <QPushButton>
0029 
0030 class PopupDropper;
0031 class QKeyEvent;
0032 class QMouseEvent;
0033 class QContextMenuEvent;
0034 
0035 namespace PlaylistBrowserNS {
0036 
0037 class PlaylistBrowserView : public Amarok::PrettyTreeView
0038 {
0039 Q_OBJECT
0040 public:
0041     explicit PlaylistBrowserView( QAbstractItemModel *model, QWidget *parent = nullptr );
0042 
0043     void setModel( QAbstractItemModel *model ) override;
0044 
0045 Q_SIGNALS:
0046     void currentItemChanged( const QModelIndex &current );
0047 
0048 protected:
0049     // TODO: re-implement QWidget::dragEnterEvent() to show drop-not-allowed indicator
0050 
0051     void keyPressEvent( QKeyEvent *event ) override;
0052     void mouseDoubleClickEvent( QMouseEvent *event ) override;
0053     void mouseReleaseEvent( QMouseEvent *event ) override;
0054     void startDrag( Qt::DropActions supportedActions ) override;
0055 
0056     void contextMenuEvent( QContextMenuEvent *event ) override;
0057 
0058 protected Q_SLOTS:
0059     /** reimplemented to Q_EMIT a signal */
0060     void currentChanged( const QModelIndex &current, const QModelIndex &previous ) override;
0061 
0062 private Q_SLOTS:
0063     // these are connected to m_*Actions:
0064     void slotCreateEmptyPlaylist();
0065     void slotAppend();
0066     void slotLoad();
0067     void slotSetNew( bool newState );
0068     void slotRename();
0069     void slotDelete();
0070     void slotRemoveTracks();
0071     void slotExport();
0072 
0073 private:
0074     void insertIntoPlaylist( const QModelIndex &index, Playlist::AddOptions options );
0075     void insertIntoPlaylist( const QModelIndexList &list, Playlist::AddOptions options );
0076     void insertIntoPlaylist( Playlist::AddOptions options );
0077 
0078     /**
0079      * Gets action for a list of indices and sets internal action targets to these.
0080      *
0081      * After you have processed/triggered the actions, you should call
0082      * resetActionTargets() to prevent stale targets laying around.
0083      */
0084     QList<QAction *> actionsFor( const QModelIndexList &indexes );
0085     void resetActionTargets();
0086 
0087     PopupDropper* m_pd;
0088 
0089     QAction *m_createEmptyPlaylistAction;
0090     QAction *m_appendAction;
0091     QAction *m_loadAction;
0092     QAction *m_setNewAction; // for podcasts
0093     QAction *m_renamePlaylistAction;
0094     QAction *m_deletePlaylistAction;
0095     QAction *m_removeTracksAction;
0096     QAction *m_exportAction;
0097     QAction *m_separatorAction;
0098     bool m_ongoingDrag;
0099 
0100     Playlists::PlaylistProvider *m_writableActionProvider;
0101     Playlists::PlaylistList m_actionPlaylists;
0102     Playlists::PlaylistList m_writableActionPlaylists;
0103     QMultiHash<Playlists::PlaylistPtr, int> m_actionTracks; // maps playlists to track positions
0104     QMultiHash<Playlists::PlaylistPtr, int> m_writableActionTracks;
0105 };
0106 
0107 } // namespace PlaylistBrowserNS
0108 
0109 #endif // PLAYLISTBROWSERVIEW_H