CuteLogger
Fast and simple logging solution for Qt based applications
filesdock.h
1 /*
2  * Copyright (c) 2024-2025 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 <QFileSystemModel>
23 #include <QHash>
24 #include <QMutex>
25 #include <QTimer>
26 #include <QUndoCommand>
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 class LineEditClear;
40 class QLabel;
41 
42 class FilesDock : public QDockWidget
43 {
44  Q_OBJECT
45 
46 public:
47  explicit FilesDock(QWidget *parent = 0);
48  ~FilesDock();
49 
50  struct CacheItem
51  {
52  int mediaType{-1}; // -1 = unknown
53  };
54 
55  int getCacheMediaType(const QString &key);
56  void setCacheMediaType(const QString &key, int mediaType);
57 
58 signals:
59  void selectionChanged();
60 
61 public slots:
62  void onOpenActionTriggered();
63  void changeDirectory(const QString &path, bool updateLocation = true);
64  void changeFilesDirectory(const QModelIndex &index);
65 
66 private slots:
67  void viewCustomContextMenuRequested(const QPoint &pos);
68  void onMediaTypeClicked();
69  void onOpenOtherAdd();
70  void onOpenOtherRemove();
71  void clearStatus();
72  void updateStatus();
73  void onLocationsEditingFinished();
74 
75  void on_locationsCombo_activated(int index);
76 
77  void on_addLocationButton_clicked();
78 
79  void on_removeLocationButton_clicked();
80 
81 protected:
82  void keyPressEvent(QKeyEvent *event);
83  void keyReleaseEvent(QKeyEvent *event);
84 
85 private:
86  void setupActions();
87  void emitDataChanged(const QVector<int> &roles);
88  void updateViewMode();
89  void onUpdateThumbnailsActionTriggered();
90  void onSelectAllActionTriggered();
91  void incrementIndex(int step);
92  void addOpenWithMenu(QMenu *menu);
93  QString firstSelectedFilePath();
94  QString firstSelectedMediaType();
95  void openClip(const QString &filePath);
96 
97  Ui::FilesDock *ui;
98  QAbstractItemView *m_view;
99  PlaylistIconView *m_iconsView;
100  std::unique_ptr<QFileSystemModel> m_dirsModel;
101  FilesModel *m_filesModel;
102  QItemSelectionModel *m_selectionModel;
103  QMenu *m_mainMenu;
104  FilesProxyModel *m_filesProxyModel;
105  QHash<QString, CacheItem> m_cache;
106  QMutex m_cacheMutex;
107  LineEditClear *m_searchField;
108  QLabel *m_label;
109 };
110 
111 #endif // FILESDOCK_H