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 sortCaseSensitive() {
146  return folderSettings_.sortCaseSensitive();
147  }
148 
149  void setSortCaseSensitive(bool value);
150 
151  bool showHidden() {
152  return proxyModel_->showHidden();
153  }
154 
155  void setShowHidden(bool showHidden);
156 
157  Fm::FilePath path() {
158  return folder_ ? folder_->path() : Fm::FilePath();
159  }
160 
161  QString pathName();
162 
163  const std::shared_ptr<Fm::Folder>& folder() {
164  return folder_;
165  }
166 
167  Fm::FolderModel* folderModel() {
168  return reinterpret_cast<Fm::FolderModel*>(folderModel_);
169  }
170 
171  View* folderView() {
172  return folderView_;
173  }
174 
175  Fm::BrowseHistory& browseHistory() {
176  return history_;
177  }
178 
179  Fm::FileInfoList selectedFiles() {
180  return folderView_->selectedFiles();
181  }
182 
183  Fm::FilePathList selectedFilePaths() {
184  return folderView_->selectedFilePaths();
185  }
186 
187  void selectAll();
188 
189  void invertSelection();
190 
191  void reload();
192 
193  QString statusText(StatusTextType type = StatusTextNormal) const {
194  return statusText_[type];
195  }
196 
197  bool canBackward() {
198  return history_.canBackward();
199  }
200 
201  void backward();
202 
203  bool canForward() {
204  return history_.canForward();
205  }
206 
207  void forward();
208 
209  void jumpToHistory(int index);
210 
211  bool canUp();
212 
213  void up();
214 
215  void updateFromSettings(Settings& settings);
216 
217  void setFileLauncher(Fm::FileLauncher* launcher) {
218  folderView_->setFileLauncher(launcher);
219  }
220 
221  Fm::FileLauncher* fileLauncher() {
222  return folderView_->fileLauncher();
223  }
224 
225  QString getFilterStr() {
226  if(proxyFilter_) {
227  return proxyFilter_->getFilterStr();
228  }
229  return QString();
230  }
231 
232  void setFilterStr(QString str) {
233  if(proxyFilter_) {
234  proxyFilter_->setFilterStr(str);
235  }
236  }
237 
238  void applyFilter();
239 
240  bool hasCustomizedView() {
241  return folderSettings_.isCustomized();
242  }
243 
244  void setCustomizedView(bool value);
245 
246  void transientFilterBar(bool transient);
247 
248  void showFilterBar();
249  bool isFilterBarVisible() const {
250  return (filterBar_ && filterBar_->isVisible());
251  }
252  void clearFilter() {
253  if(filterBar_) {
254  filterBar_->clear();
255  }
256  }
257 
258  void backspacePressed();
259 
260 Q_SIGNALS:
261  void statusChanged(int type, QString statusText);
262  void titleChanged(QString title);
263  void openDirRequested(const Fm::FilePath& path, int target);
264  void sortFilterChanged();
265  void forwardRequested();
266  void backwardRequested();
267  void folderUnmounted();
268 
269 protected:
270  virtual bool eventFilter(QObject* watched, QEvent* event);
271 
272 protected Q_SLOTS:
273  void onSelChanged();
274  void onUiUpdated();
275  void onFileSizeChanged(const QModelIndex& index);
276  void onFilesAdded(const Fm::FileInfoList files);
277  void onFilterStringChanged(QString str);
278  void onLosingFilterBarFocus();
279 
280 private:
281  void freeFolder();
282  QString formatStatusText();
283 
284  // Adds bidi marks (RLM/LRM/RLE/LRE/POP) around the text for the statusbar.
285  QString encloseWithBidiMarks(const QString& text);
286 
287  void onFolderStartLoading();
288  void onFolderFinishLoading();
289 
290  // FIXME: this API design is bad and might be removed later
291  void onFolderError(const Fm::GErrorPtr& err, Fm::Job::ErrorSeverity severity, Fm::Job::ErrorAction& response);
292 
293  void onFolderFsInfo();
294  void onFolderRemoved();
295  void onFolderUnmount();
296  void onFolderContentChanged();
297 
298 private:
299  View* folderView_;
300  Fm::CachedFolderModel* folderModel_;
301  Fm::ProxyFolderModel* proxyModel_;
302  ProxyFilter* proxyFilter_;
303  QVBoxLayout* verticalLayout;
304  std::shared_ptr<Fm::Folder> folder_;
305  QString statusText_[StatusTextNum];
306  Fm::BrowseHistory history_; // browsing history
307  Fm::FilePath lastFolderPath_; // last browsed folder
308  bool overrideCursor_;
309  FolderSettings folderSettings_;
310  QTimer* selectionTimer_;
311  FilterBar* filterBar_;
312 };
313 
314 }
315 
316 #endif // FM_TABPAGE_H
Definition: settings.h:122
Definition: view.h:37
Definition: tabpage.h:107
Definition: tabpage.h:46
Definition: settings.h:42
Definition: tabpage.h:63
Definition: tabpage.h:81