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