Filer
FileManagerMainWindow.h
1 /*-
2  * Copyright (c) 2022-23 Simon Peter <probono@puredarwin.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 #ifndef FILEMANAGERMAINWINDOW_H
28 #define FILEMANAGERMAINWINDOW_H
29 
30 #include <QMainWindow>
31 #include <QMenuBar>
32 #include <QTreeView>
33 #include "CustomTreeView.h"
34 #include <QStatusBar>
35 #include <QList>
36 #include <QStackedWidget>
37 #include <QAbstractItemView>
38 #include "CustomFileSystemModel.h"
39 #include "CustomListView.h"
40 #include "ExtendedAttributes.h"
41 #include "CustomProxyModel.h"
42 #include <QRect>
43 
44 class FileManagerMainWindow : public QMainWindow
45 {
46  Q_OBJECT
47 
48 public:
49  static QList<FileManagerMainWindow *> & instances();
50  QString getPath() const;
51 
52 
53  bool instanceExists(const QString &directory);
54 
55  FileManagerMainWindow(QWidget *parent = nullptr, const QString &initialDirectory = "/");
56 
58 
59  QItemSelectionModel *m_selectionModel;
60 
61  QString directory() const;
62  void setDirectory(const QString &directory);
63 
64  void showAboutBox();
65 
66  void showTreeView();
67  void showIconView();
68  void showHideStatusBar();
69 
70  void refresh();
71 
72  CustomFileSystemModel *m_fileSystemModel;
73  CustomProxyModel *m_proxyModel;
74 
75  bool isFirstInstance() const;
76 
77  QAbstractItemView* getCurrentView() const;
78 
79  FileManagerMainWindow* getInstanceForDirectory(const QString &directory);
80 
81  void selectItems(const QStringList &paths);
82  void bringToFront();
83 
84  void getInfo();
85 
86 public slots:
87  void open(const QString &filePath);
88  void openWith(const QString &filePath);
89  void openFolderInNewWindow(const QString &rootPath);
90  void renameSelectedItem();
91  void resizeEvent(QResizeEvent *event);
92 
93  void moveEvent(QMoveEvent *event);
94 
95  void updateMenus();
96  void updateEmptyTrashMenu();
97 
98  static void displayPicturesOnAllScreens();
99 
100 private:
101  QStackedWidget *m_stackedWidget;
102 
103  bool m_isFirstInstance = false;
104 
105  QString m_currentDir;
106 
107  CustomTreeView *m_treeView;
108  CustomListView *m_iconView;
109 
110  QMenuBar *m_menuBar;
111 
112  QStatusBar *m_statusBar;
113  QAction *m_treeViewAction;
114  QAction *m_iconViewAction;
115 
116  QAction *m_newAction;
117  QAction *m_openAction;
118  QAction *m_openWithAction;
119  QAction *m_showContentsAction;
120  QAction *m_getInfoAction;
121  QAction *m_renameAction;
122 
123  QAction *m_moveToTrashAction;
124  QAction *m_emptyTrashAction;
125 
126  QAction *m_showHiddenFilesAction;
127  QAction *m_showStatusBarAction;
128 
129  QStringList readFilenamesFromHiddenFile(const QString &filePath);
130 
131  void createMenus();
132 
133  void selectAll();
134  void updateStatusBar();
135  void copySelectedItems(const QString &destinationPath);
136  void moveSelectedItems(const QString &destinationPath);
137 
138  void saveWindowGeometry();
139 
140  void setFilterRegExpForHiddenFiles(QSortFilterProxyModel *proxyModel, const QString &hiddenFilePath);
141 
142  ExtendedAttributes *m_extendedAttributes;
143 
144  void handleSelectionChange();
145 
146  void showPreferencesDialog();
147 
148  void showHideHiddenFiles();
149 
150  void setGridSize();
151 
152  void handleScreenChange(const QRect &geometry);
153 
154  void alignIcons();
155 };
156 
157 #endif // FILEMANAGERMAINWINDOW_H
Definition: CustomFileSystemModel.h:41
Definition: CustomListView.h:38
A custom proxy model for sorting items in views.
Definition: CustomProxyModel.h:45
Definition: CustomTreeView.h:43
The ExtendedAttributes class provides functionality to read and write extended attributes of a file.
Definition: ExtendedAttributes.h:42
Definition: FileManagerMainWindow.h:45