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