CuteLogger
Fast and simple logging solution for Qt based applications
filesdock.h
1 /*
2  * Copyright (c) 2024 Meltytech, LLC
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef FILESDOCK_H
19 #define FILESDOCK_H
20 
21 #include <QDockWidget>
22 #include <QUndoCommand>
23 #include <QTimer>
24 #include <QFileSystemModel>
25 #include <QHash>
26 #include <QMutex>
27 
28 namespace Ui {
29 class FilesDock;
30 }
31 
32 class QAbstractItemView;
33 class QItemSelectionModel;
34 class QMenu;
35 class PlaylistIconView;
36 class FilesModel;
37 class FilesProxyModel;
38 class QSortFilterProxyModel;
39 
40 class FilesDock : public QDockWidget
41 {
42  Q_OBJECT
43 
44 public:
45  explicit FilesDock(QWidget *parent = 0);
46  ~FilesDock();
47 
48  struct CacheItem {
49  int mediaType {-1}; // -1 = unknown
50  };
51 
52  int getCacheMediaType(const QString &key);
53  void setCacheMediaType(const QString &key, int mediaType);
54 
55 signals:
56  void selectionChanged();
57 
58 public slots:
59  void onOpenActionTriggered();
60  void changeDirectory(const QString &path, bool resetLocations = true);
61  void changeFilesDirectory(const QModelIndex &index);
62 
63 private slots:
64  void viewCustomContextMenuRequested(const QPoint &pos);
65  void onMediaTypeClicked();
66  void onOpenOtherAdd();
67  void onOpenOtherRemove();
68 
69  void on_locationsCombo_activated(int index);
70 
71  void on_addLocationButton_clicked();
72 
73  void on_removeLocationButton_clicked();
74 
75 protected:
76  void keyPressEvent(QKeyEvent *event);
77  void keyReleaseEvent(QKeyEvent *event);
78 
79 private:
80  void setupActions();
81  void emitDataChanged(const QVector<int> &roles);
82  void updateViewMode();
83  void onUpdateThumbnailsActionTriggered();
84  void onSelectAllActionTriggered();
85  void incrementIndex(int step);
86  void addOpenWithMenu(QMenu *menu);
87  QString firstSelectedFilePath();
88  QString firstSelectedMediaType();
89  void openClip(const QString &filePath);
90 
91  Ui::FilesDock *ui;
92  QAbstractItemView *m_view;
93  PlaylistIconView *m_iconsView;
94  std::unique_ptr<QFileSystemModel> m_dirsModel;
95  FilesModel *m_filesModel;
96  QItemSelectionModel *m_selectionModel;
97  QMenu *m_mainMenu;
98  FilesProxyModel *m_filesProxyModel;
99  QHash<QString, CacheItem> m_cache;
100  QMutex m_cacheMutex;
101 };
102 
103 #endif // FILESDOCK_H