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 <libfm/fm.h>
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 class TabPage : public QWidget {
62  Q_OBJECT
63 
64 public:
65  enum StatusTextType {
66  StatusTextNormal,
67  StatusTextSelectedFiles,
68  StatusTextFSInfo,
69  StatusTextNum
70  };
71 
72 public:
73  explicit TabPage(QWidget* parent = nullptr);
74  virtual ~TabPage();
75 
76  void chdir(Fm::FilePath newPath, bool addHistory = true);
77 
78  Fm::FolderView::ViewMode viewMode() {
79  return folderSettings_.viewMode();
80  }
81 
82  void setViewMode(Fm::FolderView::ViewMode mode);
83 
84  void sort(int col, Qt::SortOrder order = Qt::AscendingOrder);
85 
86  int sortColumn() {
87  return folderSettings_.sortColumn();
88  }
89 
90  Qt::SortOrder sortOrder() {
91  return folderSettings_.sortOrder();
92  }
93 
94  bool sortFolderFirst() {
95  return folderSettings_.sortFolderFirst();
96  }
97  void setSortFolderFirst(bool value);
98 
99  bool sortCaseSensitive() {
100  return folderSettings_.sortCaseSensitive();
101  }
102 
103  void setSortCaseSensitive(bool value);
104 
105  bool showHidden() {
106  return proxyModel_->showHidden();
107  }
108 
109  void setShowHidden(bool showHidden);
110 
111  Fm::FilePath path() {
112  return folder_ ? folder_->path() : Fm::FilePath();
113  }
114 
115  QString pathName();
116 
117  const std::shared_ptr<Fm::Folder>& folder() {
118  return folder_;
119  }
120 
121  Fm::FolderModel* folderModel() {
122  return reinterpret_cast<Fm::FolderModel*>(folderModel_);
123  }
124 
125  View* folderView() {
126  return folderView_;
127  }
128 
129  Fm::BrowseHistory& browseHistory() {
130  return history_;
131  }
132 
133  Fm::FileInfoList selectedFiles() {
134  return folderView_->selectedFiles();
135  }
136 
137  Fm::FilePathList selectedFilePaths() {
138  return folderView_->selectedFilePaths();
139  }
140 
141  void selectAll();
142 
143  void invertSelection();
144 
145  void reload();
146 
147  QString statusText(StatusTextType type = StatusTextNormal) const {
148  return statusText_[type];
149  }
150 
151  bool canBackward() {
152  return history_.canBackward();
153  }
154 
155  void backward();
156 
157  bool canForward() {
158  return history_.canForward();
159  }
160 
161  void forward();
162 
163  void jumpToHistory(int index);
164 
165  bool canUp();
166 
167  void up();
168 
169  void updateFromSettings(Settings& settings);
170 
171  void setFileLauncher(Fm::FileLauncher* launcher) {
172  folderView_->setFileLauncher(launcher);
173  }
174 
175  Fm::FileLauncher* fileLauncher() {
176  return folderView_->fileLauncher();
177  }
178 
179  QString getFilterStr() {
180  if(proxyFilter_) {
181  return proxyFilter_->getFilterStr();
182  }
183  return QString();
184  }
185 
186  void setFilterStr(QString str) {
187  if(proxyFilter_) {
188  proxyFilter_->setFilterStr(str);
189  }
190  }
191 
192  void applyFilter();
193 
194  bool hasCustomizedView() {
195  return folderSettings_.isCustomized();
196  }
197 
198  void setCustomizedView(bool value);
199 
200 Q_SIGNALS:
201  void statusChanged(int type, QString statusText);
202  void titleChanged(QString title);
203  void openDirRequested(const Fm::FilePath& path, int target);
204  void sortFilterChanged();
205  void forwardRequested();
206  void backwardRequested();
207 
208 protected Q_SLOTS:
209  void onSelChanged();
210  void onUiUpdated();
211  void onFileSizeChanged(const QModelIndex& index);
212  void onFilesAdded(const Fm::FileInfoList files);
213 
214 private:
215  void freeFolder();
216  QString formatStatusText();
217 
218  // Adds bidi marks (RLM/LRM/RLE/LRE/POP) around the text for the statusbar.
219  QString encloseWithBidiMarks(const QString& text);
220 
221  void onFolderStartLoading();
222  void onFolderFinishLoading();
223 
224  // FIXME: this API design is bad and might be removed later
225  void onFolderError(const Fm::GErrorPtr& err, Fm::Job::ErrorSeverity severity, Fm::Job::ErrorAction& response);
226 
227  void onFolderFsInfo();
228  void onFolderRemoved();
229  void onFolderUnmount();
230  void onFolderContentChanged();
231 
232 private:
233  View* folderView_;
234  Fm::CachedFolderModel* folderModel_;
235  Fm::ProxyFolderModel* proxyModel_;
236  ProxyFilter* proxyFilter_;
237  QVBoxLayout* verticalLayout;
238  std::shared_ptr<Fm::Folder> folder_;
239  QString statusText_[StatusTextNum];
240  Fm::BrowseHistory history_; // browsing history
241  Fm::FilePath lastFolderPath_; // last browsed folder
242  bool overrideCursor_;
243  FolderSettings folderSettings_;
244  QTimer* selectionTimer_;
245 };
246 
247 }
248 
249 #endif // FM_TABPAGE_H
Definition: desktopwindow.h:35
Definition: settings.h:122
Definition: view.h:37
Definition: tabpage.h:61
Definition: tabpage.h:46
Definition: application.cpp:58
Definition: settings.h:42