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 statusText(StatusTextType type = StatusTextNormal) const {
203  return statusText_[type];
204  }
205 
206  bool canBackward() {
207  return history_.canBackward();
208  }
209 
210  void backward();
211 
212  bool canForward() {
213  return history_.canForward();
214  }
215 
216  void forward();
217 
218  void jumpToHistory(int index);
219 
220  bool canUp();
221 
222  void up();
223 
224  void updateFromSettings(Settings& settings);
225 
226  void setFileLauncher(Fm::FileLauncher* launcher) {
227  folderView_->setFileLauncher(launcher);
228  }
229 
230  Fm::FileLauncher* fileLauncher() {
231  return folderView_->fileLauncher();
232  }
233 
234  QString getFilterStr() {
235  if(proxyFilter_) {
236  return proxyFilter_->getFilterStr();
237  }
238  return QString();
239  }
240 
241  void setFilterStr(QString str) {
242  if(proxyFilter_) {
243  proxyFilter_->setFilterStr(str);
244  }
245  }
246 
247  void applyFilter();
248 
249  bool hasCustomizedView() {
250  return folderSettings_.isCustomized();
251  }
252 
253  void setCustomizedView(bool value);
254 
255  void transientFilterBar(bool transient);
256 
257  void showFilterBar();
258  bool isFilterBarVisible() const {
259  return (filterBar_ && filterBar_->isVisible());
260  }
261  void clearFilter() {
262  if(filterBar_) {
263  filterBar_->clear();
264  }
265  }
266 
267  void backspacePressed();
268 
269 Q_SIGNALS:
270  void statusChanged(int type, QString statusText);
271  void titleChanged(QString title);
272  void sortFilterChanged();
273  void forwardRequested();
274  void backwardRequested();
275  void folderUnmounted();
276 
277 protected:
278  virtual bool eventFilter(QObject* watched, QEvent* event);
279 
280 protected Q_SLOTS:
281  void onSelChanged();
282  void onUiUpdated();
283  void onFileSizeChanged(const QModelIndex& index);
284  void onFilesAdded(const Fm::FileInfoList files);
285  void onFilterStringChanged(QString str);
286  void onLosingFilterBarFocus();
287 
288 private:
289  void freeFolder();
290  QString formatStatusText();
291 
292  // Adds bidi marks (RLM/LRM/RLE/LRE/POP) around the text for the statusbar.
293  QString encloseWithBidiMarks(const QString& text);
294 
295  void onFolderStartLoading();
296  void onFolderFinishLoading();
297 
298  // FIXME: this API design is bad and might be removed later
299  void onFolderError(const Fm::GErrorPtr& err, Fm::Job::ErrorSeverity severity, Fm::Job::ErrorAction& response);
300 
301  void onFolderFsInfo();
302  void onFolderRemoved();
303  void onFolderUnmount();
304  void onFolderContentChanged();
305 
306 private:
307  View* folderView_;
308  Fm::CachedFolderModel* folderModel_;
309  Fm::ProxyFolderModel* proxyModel_;
310  ProxyFilter* proxyFilter_;
311  QVBoxLayout* verticalLayout;
312  std::shared_ptr<Fm::Folder> folder_;
313  QString statusText_[StatusTextNum];
314  Fm::BrowseHistory history_; // browsing history
315  Fm::FilePath lastFolderPath_; // last browsed folder
316  bool overrideCursor_;
317  FolderSettings folderSettings_;
318  QTimer* selectionTimer_;
319  FilterBar* filterBar_;
320 };
321 
322 }
323 
324 #endif // FM_TABPAGE_H
PCManFM::View
Definition: view.h:37
PCManFM::TabPage
Definition: tabpage.h:107
PCManFM::FilterBar
Definition: tabpage.h:81
PCManFM::FilterEdit
Definition: tabpage.h:63
PCManFM::FolderSettings
Definition: settings.h:42
PCManFM::ProxyFilter
Definition: tabpage.h:46
PCManFM::Settings
Definition: settings.h:134