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 <QLineEdit>
27 #include <libfm-qt/browsehistory.h>
28 #include "view.h"
29 #include "settings.h"
30 
31 #include <libfm-qt/core/fileinfo.h>
32 #include <libfm-qt/core/filepath.h>
33 #include <libfm-qt/core/folder.h>
34 
35 namespace Fm {
36 class FileLauncher;
37 class FolderModel;
38 class ProxyFolderModel;
39 class CachedFolderModel;
40 }
41 
42 namespace PCManFM {
43 
44 class Launcher;
45 
46 class ProxyFilter : public Fm::ProxyFolderModelFilter {
47 public:
48  bool filterAcceptsRow(const Fm::ProxyFolderModel* model, const std::shared_ptr<const Fm::FileInfo>& info) const;
49  virtual ~ProxyFilter() {}
50  QString getFilterStr() {
51  return filterStr_;
52  }
53  void setFilterStr(QString str) {
54  filterStr_ = str;
55  }
56 
57 private:
58  QString filterStr_;
59 };
60 
61 //==================================================
62 
63 class FilterEdit : public QLineEdit {
64  Q_OBJECT
65 public:
66  FilterEdit(QWidget *parent = nullptr);
67  ~FilterEdit() {};
68  void keyPressed(QKeyEvent* event);
69 
70 protected:
71  virtual void focusOutEvent(QFocusEvent* event) override {
72  Q_EMIT lostFocus();
73  QLineEdit::focusOutEvent(event);
74  }
75  virtual void keyPressEvent(QKeyEvent* event) override;
76 
77 Q_SIGNALS:
78  void lostFocus();
79 };
80 
81 class FilterBar : public QWidget {
82  Q_OBJECT
83 public:
84  FilterBar(QWidget *parent = nullptr);
85  ~FilterBar() {};
86 
87  void focusBar() {
88  filterEdit_->setFocus();
89  }
90  void clear() {
91  filterEdit_->clear();
92  }
93  void keyPressed(QKeyEvent* event) {
94  filterEdit_->keyPressed(event);
95  }
96 
97 Q_SIGNALS:
98  void textChanged(const QString &text);
99  void lostFocus();
100 
101 private:
102  FilterEdit* filterEdit_;
103 };
104 
105 //==================================================
106 
107 class TabPage : public QWidget {
108  Q_OBJECT
109 
110 public:
111  enum StatusTextType {
112  StatusTextNormal,
113  StatusTextSelectedFiles,
114  StatusTextFSInfo,
115  StatusTextNum
116  };
117 
118 public:
119  explicit TabPage(QWidget* parent = nullptr);
120  virtual ~TabPage();
121 
122  void chdir(Fm::FilePath newPath, bool addHistory = true);
123 
124  Fm::FolderView::ViewMode viewMode() {
125  return folderSettings_.viewMode();
126  }
127 
128  void setViewMode(Fm::FolderView::ViewMode mode);
129 
130  void sort(int col, Qt::SortOrder order = Qt::AscendingOrder);
131 
132  int sortColumn() {
133  return folderSettings_.sortColumn();
134  }
135 
136  Qt::SortOrder sortOrder() {
137  return folderSettings_.sortOrder();
138  }
139 
140  bool sortFolderFirst() {
141  return folderSettings_.sortFolderFirst();
142  }
143  void setSortFolderFirst(bool value);
144 
145  bool sortHiddenLast() {
146  return folderSettings_.sortHiddenLast();
147  }
148  void setSortHiddenLast(bool value);
149 
150  bool sortCaseSensitive() {
151  return folderSettings_.sortCaseSensitive();
152  }
153 
154  void setSortCaseSensitive(bool value);
155 
156  bool showHidden() {
157  return proxyModel_->showHidden();
158  }
159 
160  void setShowHidden(bool showHidden);
161 
162  void setShowThumbnails(bool showThumbnails);
163 
164  void saveFolderSorting();
165 
166  Fm::FilePath path() {
167  return folder_ ? folder_->path() : Fm::FilePath();
168  }
169 
170  QString pathName();
171 
172  const std::shared_ptr<Fm::Folder>& folder() {
173  return folder_;
174  }
175 
176  Fm::FolderModel* folderModel() {
177  return reinterpret_cast<Fm::FolderModel*>(folderModel_);
178  }
179 
180  View* folderView() {
181  return folderView_;
182  }
183 
184  Fm::BrowseHistory& browseHistory() {
185  return history_;
186  }
187 
188  Fm::FileInfoList selectedFiles() {
189  return folderView_->selectedFiles();
190  }
191 
192  Fm::FilePathList selectedFilePaths() {
193  return folderView_->selectedFilePaths();
194  }
195 
196  void selectAll();
197 
198  void invertSelection();
199 
200  void reload();
201 
202  QString title() const {
203  return title_;
204  }
205 
206  QString statusText(StatusTextType type = StatusTextNormal) const {
207  return statusText_[type];
208  }
209 
210  bool canBackward() {
211  return history_.canBackward();
212  }
213 
214  void backward();
215 
216  bool canForward() {
217  return history_.canForward();
218  }
219 
220  void forward();
221 
222  void jumpToHistory(int index);
223 
224  bool canUp();
225 
226  void up();
227 
228  void updateFromSettings(Settings& settings);
229 
230  void setFileLauncher(Fm::FileLauncher* launcher) {
231  folderView_->setFileLauncher(launcher);
232  }
233 
234  Fm::FileLauncher* fileLauncher() {
235  return folderView_->fileLauncher();
236  }
237 
238  QString getFilterStr() {
239  if(proxyFilter_) {
240  return proxyFilter_->getFilterStr();
241  }
242  return QString();
243  }
244 
245  void setFilterStr(QString str) {
246  if(proxyFilter_) {
247  proxyFilter_->setFilterStr(str);
248  }
249  }
250 
251  void applyFilter();
252 
253  bool hasCustomizedView() const {
254  return folderSettings_.isCustomized();
255  }
256  bool hasRecursiveCustomizedView() const {
257  return folderSettings_.isCustomized() && folderSettings_.recursive();
258  }
259  bool hasInheritedCustomizedView() const {
260  return !folderSettings_.isCustomized() && folderSettings_.inheritedPath().isValid();
261  }
262 
263  void setCustomizedView(bool value, bool recursive = false);
264 
265  void goToCustomizedViewSource();
266 
267  void transientFilterBar(bool transient);
268 
269  void showFilterBar();
270  bool isFilterBarVisible() const {
271  return (filterBar_ && filterBar_->isVisible());
272  }
273  void clearFilter() {
274  if(filterBar_) {
275  filterBar_->clear();
276  }
277  }
278 
279  void backspacePressed();
280 
281  void ceateShortcut();
282 
283 Q_SIGNALS:
284  void statusChanged(int type, QString statusText);
285  void titleChanged();
286  void sortFilterChanged();
287  void forwardRequested();
288  void backwardRequested();
289  void folderUnmounted();
290 
291 protected:
292  virtual bool eventFilter(QObject* watched, QEvent* event);
293 
294 protected Q_SLOTS:
295  void onSelChanged();
296  void onUiUpdated();
297  void onFileSizeChanged(const QModelIndex& index);
298  void onFilesAdded(const Fm::FileInfoList files);
299  void onFilterStringChanged(QString str);
300  void onLosingFilterBarFocus();
301 
302 private:
303  void freeFolder();
304  QString formatStatusText();
305 
306  void onFolderStartLoading();
307  void onFolderFinishLoading();
308 
309  // FIXME: this API design is bad and might be removed later
310  void onFolderError(const Fm::GErrorPtr& err, Fm::Job::ErrorSeverity severity, Fm::Job::ErrorAction& response);
311 
312  void onFolderFsInfo();
313  void onFolderRemoved();
314  void onFolderUnmount();
315  void onFolderContentChanged();
316 
317  bool canOpenAdmin();
318 
319 private:
320  View* folderView_;
321  Fm::CachedFolderModel* folderModel_;
322  Fm::ProxyFolderModel* proxyModel_;
323  ProxyFilter* proxyFilter_;
324  QVBoxLayout* verticalLayout;
325  std::shared_ptr<Fm::Folder> folder_;
326  QString title_;
327  QString statusText_[StatusTextNum];
328  Fm::BrowseHistory history_; // browsing history
329  Fm::FilePath lastFolderPath_; // last browsed folder
330  bool overrideCursor_;
331  FolderSettings folderSettings_;
332  QTimer* selectionTimer_;
333  FilterBar* filterBar_;
334  QStringList filesToTrust_;
335 };
336 
337 }
338 
339 #endif // FM_TABPAGE_H
Definition: tabpage.h:81
Definition: tabpage.h:63
Definition: settings.h:42
Definition: tabpage.h:46
Definition: settings.h:154
Definition: tabpage.h:107
Definition: view.h:37