PCManFM-Qt
 All Classes
mainwindow.h
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 <QMainWindow>
25 #include <QListView>
26 #include <QSortFilterProxyModel>
27 #include <QLineEdit>
28 #include <QTabWidget>
29 #include <QMessageBox>
30 #include <QTabBar>
31 #include <QStackedWidget>
32 #include <QSplitter>
33 #include "launcher.h"
34 #include "tabbar.h"
35 #include <libfm-qt/core/filepath.h>
36 #include <libfm-qt/core/bookmarks.h>
37 
38 namespace Fm {
39 class PathEdit;
40 class PathBar;
41 }
42 
43 namespace PCManFM {
44 
45 class ViewFrame : public QFrame {
46  Q_OBJECT
47 public:
48  ViewFrame(QWidget* parent = nullptr);
49  ~ViewFrame() {};
50 
51  void createTopBar(bool usePathButtons);
52  void removeTopBar();
53 
54  QWidget* getTopBar() const {
55  return topBar_;
56  }
57  TabBar* getTabBar() const {
58  return tabBar_;
59  }
60  QStackedWidget* getStackedWidget() const {
61  return stackedWidget_;
62  }
63 
64 private:
65  QWidget* topBar_;
66  TabBar* tabBar_;
67  QStackedWidget* stackedWidget_;
68 };
69 
70 //======================================================================
71 
72 class TabPage;
73 class Settings;
74 
75 class MainWindow : public QMainWindow {
76  Q_OBJECT
77 public:
78  MainWindow(Fm::FilePath path = Fm::FilePath());
79  virtual ~MainWindow();
80 
81  void chdir(Fm::FilePath path, ViewFrame* viewFrame);
82  void chdir(Fm::FilePath path) {
83  chdir(path, activeViewFrame_);
84  }
85 
86  int addTab(Fm::FilePath path, ViewFrame* viewFrame);
87  int addTab(Fm::FilePath path) {
88  return addTab(path, activeViewFrame_);
89  }
90 
91  TabPage* currentPage(ViewFrame* viewFrame) {
92  return reinterpret_cast<TabPage*>(viewFrame->getStackedWidget()->currentWidget());
93  }
94  TabPage* currentPage() {
95  return currentPage(activeViewFrame_);
96  }
97 
98  void updateFromSettings(Settings& settings);
99 
100  static MainWindow* lastActive() {
101  return lastActive_;
102  }
103 
104 protected Q_SLOTS:
105 
106  void onPathEntryReturnPressed();
107  void onPathBarChdir(const Fm::FilePath& dirPath);
108  void onPathBarMiddleClickChdir(const Fm::FilePath &dirPath);
109 
110  void on_actionNewTab_triggered();
111  void on_actionNewWin_triggered();
112  void on_actionNewFolder_triggered();
113  void on_actionNewBlankFile_triggered();
114  void on_actionCloseTab_triggered();
115  void on_actionCloseWindow_triggered();
116  void on_actionFileProperties_triggered();
117  void on_actionFolderProperties_triggered();
118 
119  void on_actionCut_triggered();
120  void on_actionCopy_triggered();
121  void on_actionPaste_triggered();
122  void on_actionDelete_triggered();
123  void on_actionRename_triggered();
124  void on_actionBulkRename_triggered();
125  void on_actionSelectAll_triggered();
126  void on_actionInvertSelection_triggered();
127  void on_actionPreferences_triggered();
128 
129  void on_actionGoBack_triggered();
130  void on_actionGoForward_triggered();
131  void on_actionGoUp_triggered();
132  void on_actionHome_triggered();
133  void on_actionReload_triggered();
134  void on_actionConnectToServer_triggered();
135 
136  void on_actionIconView_triggered();
137  void on_actionCompactView_triggered();
138  void on_actionDetailedList_triggered();
139  void on_actionThumbnailView_triggered();
140 
141  void on_actionGo_triggered();
142  void on_actionShowHidden_triggered(bool check);
143  void on_actionSplitView_triggered(bool check);
144  void on_actionPreserveView_triggered(bool checked);
145 
146  void on_actionByFileName_triggered(bool checked);
147  void on_actionByMTime_triggered(bool checked);
148  void on_actionByOwner_triggered(bool checked);
149  void on_actionByGroup_triggered(bool checked);
150  void on_actionByFileType_triggered(bool checked);
151  void on_actionByFileSize_triggered(bool checked);
152  void on_actionAscending_triggered(bool checked);
153  void on_actionDescending_triggered(bool checked);
154  void on_actionFolderFirst_triggered(bool checked);
155  void on_actionCaseSensitive_triggered(bool checked);
156  void on_actionFilter_triggered(bool checked);
157  void on_actionUnfilter_triggered();
158  void on_actionShowFilter_triggered();
159 
160  void on_actionLocationBar_triggered(bool checked);
161  void on_actionPathButtons_triggered(bool checked);
162 
163  void on_actionApplications_triggered();
164  void on_actionComputer_triggered();
165  void on_actionTrash_triggered();
166  void on_actionNetwork_triggered();
167  void on_actionDesktop_triggered();
168  void on_actionAddToBookmarks_triggered();
169  void on_actionEditBookmarks_triggered();
170 
171  void on_actionOpenTerminal_triggered();
172  void on_actionOpenAsRoot_triggered();
173  void on_actionCopyFullPath_triggered();
174  void on_actionFindFiles_triggered();
175 
176  void on_actionAbout_triggered();
177 
178  void onBookmarkActionTriggered();
179 
180  void onTabBarCloseRequested(int index);
181  void onTabBarCurrentChanged(int index);
182  void onTabBarTabMoved(int from, int to);
183 
184  void onShortcutPrevTab();
185  void onShortcutNextTab();
186  void onShortcutJumpToTab();
187 
188  void onStackedWidgetWidgetRemoved(int index);
189 
190  void onTabPageTitleChanged(QString title);
191  void onTabPageStatusChanged(int type, QString statusText);
192  void onTabPageOpenDirRequested(const Fm::FilePath &path, int target);
193  void onTabPageSortFilterChanged();
194 
195  void onSidePaneChdirRequested(int type, const Fm::FilePath &path);
196  void onSidePaneOpenFolderInNewWindowRequested(const Fm::FilePath &path);
197  void onSidePaneOpenFolderInNewTabRequested(const Fm::FilePath &path);
198  void onSidePaneOpenFolderInTerminalRequested(const Fm::FilePath &path);
199  void onSidePaneCreateNewFolderRequested(const Fm::FilePath &path);
200  void onSidePaneModeChanged(Fm::SidePane::Mode mode);
201  void onSplitterMoved(int pos, int index);
202  void onResetFocus();
203 
204  void onBackForwardContextMenu(QPoint pos);
205 
206  void onFolderUnmounted();
207 
208  void tabContextMenu(const QPoint& pos);
209  void onTabBarClicked(int index);
210  void closeLeftTabs();
211  void closeRightTabs();
212  void closeOtherTabs() {
213  closeLeftTabs();
214  closeRightTabs();
215  }
216  void focusPathEntry();
217  void toggleMenuBar(bool checked);
218  void detachTab();
219 
220  void onBookmarksChanged();
221 
222  void onSettingHiddenPlace(const QString& str, bool hide);
223 
224 protected:
225  bool event(QEvent* event) override;
226  void changeEvent(QEvent* event) override;
227  void closeTab(int index, ViewFrame* viewFrame);
228  void closeTab(int index) {
229  closeTab(index, activeViewFrame_);
230  }
231  virtual void resizeEvent(QResizeEvent* event) override;
232  virtual void closeEvent(QCloseEvent* event) override;
233  virtual void dragEnterEvent(QDragEnterEvent* event) override;
234  virtual void dropEvent(QDropEvent* event) override;
235  virtual bool eventFilter(QObject* watched, QEvent* event);
236 
237 private:
238  void loadBookmarksMenu();
239  void updateUIForCurrentPage(bool setFocus = true);
240  void updateViewMenuForCurrentPage();
241  void updateEditSelectedActions();
242  void updateStatusBarForCurrentPage();
243  void setRTLIcons(bool isRTL);
244  void createPathBar(bool usePathButtons);
245  void addViewFrame(const Fm::FilePath& path);
246  ViewFrame* viewFrameForTabPage(TabPage* page);
247  int addTabWithPage(TabPage* page, ViewFrame* viewFrame, Fm::FilePath path = Fm::FilePath());
248  void dropTab();
249 
250 private:
251  Ui::MainWindow ui;
252  Fm::PathEdit* pathEntry_;
253  Fm::PathBar* pathBar_;
254  QLabel* fsInfoLabel_;
255  std::shared_ptr<Fm::Bookmarks> bookmarks_;
256  Launcher fileLauncher_;
257  int rightClickIndex_;
258  bool updatingViewMenu_;
259  QAction* menuSep_;
260  QAction* menuSpacer_;
261 
262  ViewFrame* activeViewFrame_;
263  // The split mode of this window is changed only from its settings,
264  // not from another window. So, we get the mode at the start and keep it.
265  bool splitView_;
266 
267  static MainWindow* lastActive_;
268 };
269 
270 }
271 
272 #endif // FM_MAIN_WINDOW_H
Definition: settings.h:122
Definition: mainwindow.h:45
Definition: tabpage.h:107
Definition: tabbar.h:30
Definition: launcher.h:30
Definition: mainwindow.h:75