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