PCManFM-Qt
tabpage.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 
21 #ifndef FM_TABPAGE_H
22 #define FM_TABPAGE_H
23 
24 #include <QWidget>
25 #include <QVBoxLayout>
26 #include <libfm/fm.h>
27 #include <libfm-qt/browsehistory.h>
28 #include "view.h"
29 #include <libfm-qt/path.h>
30 #include <libfm-qt/folder.h>
31 #include <libfm-qt/fileinfo.h>
32 #include "settings.h"
33 
34 namespace Fm {
35  class FileLauncher;
36  class FolderModel;
37  class ProxyFolderModel;
38  class CachedFolderModel;
39 };
40 
41 namespace PCManFM {
42 
43 class Launcher;
44 
45 class ProxyFilter : public Fm::ProxyFolderModelFilter {
46 public:
47  bool filterAcceptsRow(const Fm::ProxyFolderModel* model, FmFileInfo* info) const;
48  virtual ~ProxyFilter() {}
49  void setVirtHidden(Fm::Folder folder);
50  QString getFilterStr() {
51  return filterStr_;
52  }
53  void setFilterStr(QString str) {
54  filterStr_ = str;
55  }
56 
57 private:
58  QString filterStr_;
59  QStringList virtHiddenList_;
60 };
61 
62 class TabPage : public QWidget {
63 Q_OBJECT
64 
65 public:
66  enum StatusTextType {
67  StatusTextNormal,
68  StatusTextSelectedFiles,
69  StatusTextFSInfo,
70  StatusTextNum
71  };
72 
73 public:
74  explicit TabPage(Fm::Path path, QWidget* parent = nullptr);
75  virtual ~TabPage();
76 
77  void chdir(Fm::Path newPath, bool addHistory = true);
78 
79  Fm::FolderView::ViewMode viewMode() {
80  return folderSettings_.viewMode();
81  }
82 
83  void setViewMode(Fm::FolderView::ViewMode mode);
84 
85  void sort(int col, Qt::SortOrder order = Qt::AscendingOrder);
86 
87  int sortColumn() {
88  return folderSettings_.sortColumn();
89  }
90 
91  Qt::SortOrder sortOrder() {
92  return folderSettings_.sortOrder();
93  }
94 
95  bool sortFolderFirst() {
96  return folderSettings_.sortFolderFirst();
97  }
98  void setSortFolderFirst(bool value);
99 
100  bool sortCaseSensitive() {
101  return folderSettings_.sortCaseSensitive();
102  }
103 
104  void setSortCaseSensitive(bool value);
105 
106  bool showHidden() {
107  return folderSettings_.showHidden();
108  }
109 
110  void setShowHidden(bool showHidden);
111 
112  Fm::Path path() {
113  return Fm::Path(!folder_.isNull() ? folder_.getPath() : nullptr);
114  }
115 
116  QString pathName();
117 
118  Fm::Folder& folder() {
119  return folder_;
120  }
121 
122  Fm::FolderModel* folderModel() {
123  return reinterpret_cast<Fm::FolderModel*>(folderModel_);
124  }
125 
126  View* folderView() {
127  return folderView_;
128  }
129 
130  Fm::BrowseHistory& browseHistory() {
131  return history_;
132  }
133 
134  Fm::FileInfoList selectedFiles() {
135  return folderView_->selectedFiles();
136  }
137 
138  Fm::PathList selectedFilePaths() {
139  return folderView_->selectedFilePaths();
140  }
141 
142  void selectAll();
143 
144  void invertSelection();
145 
146  void reload() {
147  if(!folder_.isNull()) {
148  proxyFilter_->setVirtHidden(folder_); // reread ".hidden"
149  folder_.reload();
150  }
151  }
152 
153  QString title() const {
154  return title_;
155  }
156 
157  QString statusText(StatusTextType type = StatusTextNormal) const {
158  return statusText_[type];
159  }
160 
161  bool canBackward() {
162  return history_.canBackward();
163  }
164 
165  void backward();
166 
167  bool canForward() {
168  return history_.canForward();
169  }
170 
171  void forward();
172 
173  void jumpToHistory(int index);
174 
175  bool canUp();
176 
177  void up();
178 
179  void updateFromSettings(Settings& settings);
180 
181  void setFileLauncher(Fm::FileLauncher* launcher) {
182  folderView_->setFileLauncher(launcher);
183  }
184 
185  Fm::FileLauncher* fileLauncher() {
186  return folderView_->fileLauncher();
187  }
188 
189  QString getFilterStr() {
190  if(proxyFilter_)
191  return proxyFilter_->getFilterStr();
192  return QString();
193  }
194 
195  void setFilterStr(QString str) {
196  if(proxyFilter_)
197  proxyFilter_->setFilterStr(str);
198  }
199 
200  void applyFilter();
201 
202  bool hasCustomizedView() {
203  return folderSettings_.isCustomized();
204  }
205 
206  void setCustomizedView(bool value);
207 
208 Q_SIGNALS:
209  void statusChanged(int type, QString statusText);
210  void titleChanged(QString title);
211  void openDirRequested(FmPath* path, int target);
212  void sortFilterChanged();
213  void forwardRequested();
214  void backwardRequested();
215 
216 protected Q_SLOTS:
217  void onOpenDirRequested(FmPath* path, int target);
218  void onSelChanged(int numSel);
219  void restoreScrollPos();
220 
221 private:
222  void freeFolder();
223  QString formatStatusText();
224 
225  static void onFolderStartLoading(FmFolder* _folder, TabPage* pThis);
226  static void onFolderFinishLoading(FmFolder* _folder, TabPage* pThis);
227  static FmJobErrorAction onFolderError(FmFolder* _folder, GError* err, FmJobErrorSeverity severity, TabPage* pThis);
228  static void onFolderFsInfo(FmFolder* _folder, TabPage* pThis);
229  static void onFolderRemoved(FmFolder* _folder, TabPage* pThis);
230  static void onFolderUnmount(FmFolder* _folder, TabPage* pThis);
231  static void onFolderContentChanged(FmFolder* _folder, TabPage* pThis);
232 
233 private:
234  View* folderView_;
235  Fm::CachedFolderModel* folderModel_;
236  Fm::ProxyFolderModel* proxyModel_;
237  ProxyFilter* proxyFilter_;
238  QVBoxLayout* verticalLayout;
239  Fm::Folder folder_;
240  QString title_;
241  QString statusText_[StatusTextNum];
242  Fm::BrowseHistory history_; // browsing history
243  Fm::Path lastFolderPath_; // last browsed folder
244  bool overrideCursor_;
245  FolderSettings folderSettings_;
246 };
247 
248 }
249 
250 #endif // FM_TABPAGE_H
Definition: desktopwindow.h:32
Definition: settings.h:121
Definition: view.h:35
Definition: tabpage.h:62
Definition: tabpage.h:45
Definition: application.cpp:57
Definition: settings.h:41