Sayonara Player
DirectoryTreeView.h
1 /* DirectoryTreeView.h */
2 
3 /* Copyright (C) 2011-2020 Michael Lugmair (Lucio Carreras)
4  *
5  * This file is part of sayonara player
6  *
7  * This program 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  * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef DIRECTORYTREEVIEW_H
22 #define DIRECTORYTREEVIEW_H
23 
24 #include "DirectoryModel.h"
25 #include "Gui/InfoDialog/InfoDialogContainer.h"
26 
27 #include "Gui/Utils/SearchableWidget/SearchableView.h"
28 #include "Gui/Utils/Widgets/WidgetTemplate.h"
29 #include "Gui/Utils/Widgets/Dragable.h"
30 #include "Utils/Pimpl.h"
31 
32 #include <QTreeView>
33 #include <QModelIndexList>
34 #include <QTreeView>
35 
36 class Model;
37 class IconProvider;
38 
39 namespace Gui
40 {
41  class LibraryContextMenu;
42  class CustomMimeData;
43 }
44 
45 namespace Library
46 {
47  class Info;
48 }
49 
50 
51 namespace Directory
52 {
57  class TreeView :
58  public Gui::WidgetTemplate<QTreeView>,
59  public InfoDialogContainer,
60  protected Gui::Dragable
61  {
62  Q_OBJECT
63  PIMPL(TreeView)
64 
66 
67  signals:
68  void sigDeleteClicked();
69  void sigPlayClicked();
70  void sigPlayNewTabClicked();
71  void sigPlayNextClicked();
72  void sigAppendClicked();
73  void sigDirectoryLoaded(const QModelIndex& index);
74  void sigCurrentIndexChanged(const QModelIndex& index);
75 
76  void sigEnterPressed();
77  void sigImportRequested(LibraryId lib_id, const QStringList& v_md, const QString& targetDirectory);
78 
79  void sigCopyRequested(const QStringList& paths, const QString& target);
80  void sigMoveRequested(const QStringList& paths, const QString& target);
81  void sigRenameRequested(const QString& path, const QString& target);
82 
83  void sigCopyToLibraryRequested(LibraryId libraryId);
84  void sigMoveToLibraryRequested(LibraryId libraryId);
85 
86  public:
87  explicit TreeView(QWidget* parent=nullptr);
88  ~TreeView() override;
89 
90  QString directoryName(const QModelIndex& index);
91 
92  QModelIndexList selctedRows() const;
93  QStringList selectedPaths() const;
94 
95  void setLibraryInfo(const Library::Info& info);
96  void setFilterTerm(const QString& filter);
97 
98  public slots:
99  void setBusy(bool b);
100 
101  private:
102  enum class DropAction
103  {
104  Copy,
105  Move,
106  Cancel
107  };
108 
109  void initContextMenu();
110  DropAction showDropMenu(const QPoint& pos);
111  void handleSayonaraDrop(const Gui::CustomMimeData* mimedata, const QString& targetDirectory);
112 
113  private slots:
114  void createDirectoryClicked();
115  void renameDirectoryClicked();
116  void viewInFileManagerClicked();
117  void dragTimerTimeout();
118 
119  protected:
120  // Dragable
121  QMimeData* dragableMimedata() const override;
122 
123  void skinChanged() override;
124 
125  void keyPressEvent(QKeyEvent* event) override;
126  void contextMenuEvent(QContextMenuEvent* event) override;
127 
128  void dragEnterEvent(QDragEnterEvent* event) override;
129  void dragLeaveEvent(QDragLeaveEvent* event) override;
130  void dragMoveEvent(QDragMoveEvent* event) override;
131  void dropEvent(QDropEvent* event) override;
132 
133  void selectionChanged(const QItemSelection& selected, const QItemSelection& deselected) override;
134 
135  // InfoDialogContainer interface
136  MD::Interpretation metadataInterpretation() const override;
137  MetaDataList infoDialogData() const override;
138  bool hasMetadata() const override;
139  QStringList pathlist() const override;
140  };
141 }
142 
143 #endif // DIRECTORYTREEVIEW_H
Mimedata class for drag and dropping metadata.
Definition: CustomMimeData.h:36
bool hasMetadata() const override
returns, if the widget can provide metadata instantly If false, the info dialog will the pathlist
The DirectoryTreeView class.
Definition: DirectoryTreeView.h:57
An interface used to abstract the usage of the info dialog. An implementing class has to return the i...
Definition: InfoDialogContainer.h:61
Template for Sayonara Widgets. This template is responsible for holding a reference to the settings.
Definition: WidgetTemplate.h:84
The MetaDataList class.
Definition: MetaDataList.h:35
QStringList pathlist() const override
Returns a list of paths. This is only used if has_metadata() returns false.
MD::Interpretation metadataInterpretation() const override
get the interpretation for the metadata. Maybe a list of metadata should be intrepeted as albums whil...
The Info class.
Definition: LibraryInfo.h:35
The Dragable class.
Definition: Dragable.h:60
MetaDataList infoDialogData() const override
get the metadata that should be used for the info dialog So for lists, the selected tracks are used h...
An interface class needed when implementing a library plugin.
Definition: LocalLibraryWatcher.h:30