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