1 /*
2 
3     Copyright (C) 2013  Hong Jen Yee (PCMan) <pcman.tw@gmail.com>
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License along
16     with this program; if not, write to the Free Software Foundation, Inc.,
17     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19 
20 #ifndef FM_MAIN_WINDOW_H
21 #define FM_MAIN_WINDOW_H
22 
23 #include "ui_main-win.h"
24 #include <QPointer>
25 #include <QMainWindow>
26 #include <QListView>
27 #include <QSortFilterProxyModel>
28 #include <QLineEdit>
29 #include <QTabWidget>
30 #include <QMessageBox>
31 #include <QTabBar>
32 #include <QStackedWidget>
33 #include <QSplitter>
34 #include "launcher.h"
35 #include "tabbar.h"
36 #include <libfm-qt/core/filepath.h>
37 #include <libfm-qt/core/bookmarks.h>
38 
39 namespace Fm {
40 class PathEdit;
41 class PathBar;
42 }
43 
44 namespace PCManFM {
45 
46 class ViewFrame : public QFrame {
47     Q_OBJECT
48 public:
49     ViewFrame(QWidget* parent = nullptr);
~ViewFrame()50     ~ViewFrame() {};
51 
52     void createTopBar(bool usePathButtons);
53     void removeTopBar();
54 
getTopBar()55     QWidget* getTopBar() const {
56         return topBar_;
57     }
getTabBar()58     TabBar* getTabBar() const {
59         return tabBar_;
60     }
getStackedWidget()61     QStackedWidget* getStackedWidget() const {
62         return stackedWidget_;
63     }
64 
65 private:
66     QWidget* topBar_;
67     TabBar* tabBar_;
68     QStackedWidget* stackedWidget_;
69 };
70 
71 //======================================================================
72 
73 class TabPage;
74 class Settings;
75 
76 class MainWindow : public QMainWindow {
77     Q_OBJECT
78 public:
79     MainWindow(Fm::FilePath path = Fm::FilePath());
80     virtual ~MainWindow();
81 
82     void chdir(Fm::FilePath path, ViewFrame* viewFrame);
chdir(Fm::FilePath path)83     void chdir(Fm::FilePath path) {
84         chdir(path, activeViewFrame_);
85     }
86 
87     void addTab(Fm::FilePath path, ViewFrame* viewFrame);
addTab(Fm::FilePath path)88     void addTab(Fm::FilePath path) {
89         addTab(path, activeViewFrame_);
90     }
91 
currentPage(ViewFrame * viewFrame)92     TabPage* currentPage(ViewFrame* viewFrame) {
93         return reinterpret_cast<TabPage*>(viewFrame->getStackedWidget()->currentWidget());
94     }
currentPage()95     TabPage* currentPage() {
96         return currentPage(activeViewFrame_);
97     }
98 
99     void updateFromSettings(Settings& settings);
100 
lastActive()101     static MainWindow* lastActive() {
102         return lastActive_;
103     }
104 
105 protected Q_SLOTS:
106 
107     void onPathEntryReturnPressed();
108     void onPathBarChdir(const Fm::FilePath& dirPath);
109     void onPathBarMiddleClickChdir(const Fm::FilePath &dirPath);
110 
111     void on_actionNewTab_triggered();
112     void on_actionNewWin_triggered();
113     void on_actionNewFolder_triggered();
114     void on_actionNewBlankFile_triggered();
115     void on_actionCloseTab_triggered();
116     void on_actionCloseWindow_triggered();
117     void on_actionFileProperties_triggered();
118     void on_actionFolderProperties_triggered();
119 
120     void on_actionCut_triggered();
121     void on_actionCopy_triggered();
122     void on_actionPaste_triggered();
123     void on_actionDelete_triggered();
124     void on_actionRename_triggered();
125     void on_actionBulkRename_triggered();
126     void on_actionSelectAll_triggered();
127     void on_actionInvertSelection_triggered();
128     void on_actionPreferences_triggered();
129 
130     void on_actionGoBack_triggered();
131     void on_actionGoForward_triggered();
132     void on_actionGoUp_triggered();
133     void on_actionHome_triggered();
134     void on_actionReload_triggered();
135     void on_actionConnectToServer_triggered();
136 
137     void on_actionIconView_triggered();
138     void on_actionCompactView_triggered();
139     void on_actionDetailedList_triggered();
140     void on_actionThumbnailView_triggered();
141 
142     void on_actionGo_triggered();
143     void on_actionShowHidden_triggered(bool check);
144     void on_actionShowThumbnails_triggered(bool check);
145     void on_actionSplitView_triggered(bool check);
146     void on_actionPreserveView_triggered(bool checked);
147     void on_actionPreserveViewRecursive_triggered(bool checked);
148     void on_actionGoToCustomizedViewSource_triggered();
149 
150     void on_actionByFileName_triggered(bool checked);
151     void on_actionByMTime_triggered(bool checked);
152     void on_actionByCrTime_triggered(bool checked);
153     void on_actionByDTime_triggered(bool checked);
154     void on_actionByOwner_triggered(bool checked);
155     void on_actionByGroup_triggered(bool checked);
156     void on_actionByFileType_triggered(bool checked);
157     void on_actionByFileSize_triggered(bool checked);
158     void on_actionAscending_triggered(bool checked);
159     void on_actionDescending_triggered(bool checked);
160     void on_actionFolderFirst_triggered(bool checked);
161     void on_actionHiddenLast_triggered(bool checked);
162     void on_actionCaseSensitive_triggered(bool checked);
163     void on_actionFilter_triggered(bool checked);
164     void on_actionUnfilter_triggered();
165     void on_actionShowFilter_triggered();
166 
167     void on_actionLocationBar_triggered(bool checked);
168     void on_actionPathButtons_triggered(bool checked);
169 
170     void on_actionApplications_triggered();
171     void on_actionComputer_triggered();
172     void on_actionTrash_triggered();
173     void on_actionNetwork_triggered();
174     void on_actionDesktop_triggered();
175     void on_actionAddToBookmarks_triggered();
176     void on_actionEditBookmarks_triggered();
177 
178     void on_actionOpenTerminal_triggered();
179     void on_actionCreateLauncher_triggered();
180     void on_actionOpenAsAdmin_triggered();
181     void on_actionOpenAsRoot_triggered();
182     void on_actionCopyFullPath_triggered();
183     void on_actionFindFiles_triggered();
184 
185     void on_actionAbout_triggered();
186     void on_actionHiddenShortcuts_triggered();
187 
188     void onBookmarkActionTriggered();
189 
190     void onTabBarCloseRequested(int index);
191     void onTabBarCurrentChanged(int index);
192     void onTabBarTabMoved(int from, int to);
193 
194     void onShortcutPrevTab();
195     void onShortcutNextTab();
196     void onShortcutJumpToTab();
197 
198     void onStackedWidgetWidgetRemoved(int index);
199 
200     void onTabPageTitleChanged();
201     void onTabPageStatusChanged(int type, QString statusText);
202     void onTabPageSortFilterChanged();
203 
204     void onSidePaneChdirRequested(int type, const Fm::FilePath &path);
205     void onSidePaneOpenFolderInNewWindowRequested(const Fm::FilePath &path);
206     void onSidePaneOpenFolderInNewTabRequested(const Fm::FilePath &path);
207     void onSidePaneOpenFolderInTerminalRequested(const Fm::FilePath &path);
208     void onSidePaneCreateNewFolderRequested(const Fm::FilePath &path);
209     void onSidePaneModeChanged(Fm::SidePane::Mode mode);
210     void on_actionSidePane_triggered(bool check);
211     void onSplitterMoved(int pos, int index);
212     void onResetFocus();
213 
214     void onBackForwardContextMenu(QPoint pos);
215 
216     void onFolderUnmounted();
217 
218     void tabContextMenu(const QPoint& pos);
219     void onTabBarClicked(int index);
220     void closeLeftTabs();
221     void closeRightTabs();
closeOtherTabs()222     void closeOtherTabs() {
223         closeLeftTabs();
224         closeRightTabs();
225     }
226     void focusPathEntry();
227     void toggleMenuBar(bool checked);
228     void detachTab();
229 
230     void onBookmarksChanged();
231 
232     void onSettingHiddenPlace(const QString& str, bool hide);
233 
234     void on_actionCleanPerFolderConfig_triggered();
235 
236 protected:
237     bool event(QEvent* event) override;
238     void changeEvent(QEvent* event) override;
239     void closeTab(int index, ViewFrame* viewFrame);
closeTab(int index)240     void closeTab(int index) {
241         closeTab(index, activeViewFrame_);
242     }
243     virtual void resizeEvent(QResizeEvent* event) override;
244     virtual void closeEvent(QCloseEvent* event) override;
245     virtual void dragEnterEvent(QDragEnterEvent* event) override;
246     virtual void dropEvent(QDropEvent* event) override;
247     virtual bool eventFilter(QObject* watched, QEvent* event) override;
248 
249 private:
250     void loadBookmarksMenu();
251     void updateUIForCurrentPage(bool setFocus = true);
252     void updateViewMenuForCurrentPage();
253     void updateEditSelectedActions();
254     void updateStatusBarForCurrentPage();
255     void setRTLIcons(bool isRTL);
256     void createPathBar(bool usePathButtons);
257     void addViewFrame(const Fm::FilePath& path);
258     ViewFrame* viewFrameForTabPage(TabPage* page);
259     int addTabWithPage(TabPage* page, ViewFrame* viewFrame, Fm::FilePath path = Fm::FilePath());
260     void dropTab(QObject* source);
261     void setTabIcon(TabPage* tabPage);
262 
263 private:
264     Ui::MainWindow ui;
265     Fm::PathEdit* pathEntry_;
266     Fm::PathBar* pathBar_;
267     QLabel* fsInfoLabel_;
268     std::shared_ptr<Fm::Bookmarks> bookmarks_;
269     Launcher fileLauncher_;
270     int rightClickIndex_;
271     bool updatingViewMenu_;
272     QAction* menuSep_;
273     QAction* menuSpacer_;
274 
275     ViewFrame* activeViewFrame_;
276     // The split mode of this window is changed only from its settings,
277     // not from another window. So, we get the mode at the start and keep it.
278     bool splitView_;
279 
280     static QPointer<MainWindow> lastActive_;
281 };
282 
283 }
284 
285 #endif // FM_MAIN_WINDOW_H
286