PCManFM-Qt
Loading...
Searching...
No Matches
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
35namespace Fm {
36class FileLauncher;
37class FolderModel;
38class ProxyFolderModel;
39class CachedFolderModel;
40}
41
42namespace PCManFM {
43
44class Launcher;
45
46class ProxyFilter : public Fm::ProxyFolderModelFilter {
47public:
48 ProxyFilter() : fullName_{true} {}
49 bool filterAcceptsRow(const Fm::ProxyFolderModel* model, const std::shared_ptr<const Fm::FileInfo>& info) const;
50 virtual ~ProxyFilter() {}
51 QString getFilterStr() {
52 return filterStr_;
53 }
54 void setFilterStr(QString str) {
55 filterStr_ = str;
56 }
57 void filterFullName(bool fullName) {
58 fullName_ = fullName;
59 }
60
61private:
62 bool fullName_;
63 QString filterStr_;
64};
65
66//==================================================
67
68class FilterEdit : public QLineEdit {
69 Q_OBJECT
70public:
71 FilterEdit(QWidget *parent = nullptr);
72 ~FilterEdit() {};
73 void keyPressed(QKeyEvent* event);
74
75protected:
76 virtual void focusOutEvent(QFocusEvent* event) override {
77 Q_EMIT lostFocus();
78 QLineEdit::focusOutEvent(event);
79 }
80 virtual void keyPressEvent(QKeyEvent* event) override;
81
82Q_SIGNALS:
83 void lostFocus();
84};
85
86class FilterBar : public QWidget {
87 Q_OBJECT
88public:
89 FilterBar(QWidget *parent = nullptr);
90 ~FilterBar() {};
91
92 void focusBar() {
93 filterEdit_->setFocus();
94 }
95 void clear() {
96 filterEdit_->clear();
97 }
98 void keyPressed(QKeyEvent* event) {
99 filterEdit_->keyPressed(event);
100 }
101
102Q_SIGNALS:
103 void textChanged(const QString &text);
104 void lostFocus();
105
106private:
107 FilterEdit* filterEdit_;
108};
109
110//==================================================
111
112class TabPage : public QWidget {
113 Q_OBJECT
114
115public:
116 enum StatusTextType {
117 StatusTextNormal,
118 StatusTextSelectedFiles,
119 StatusTextFSInfo,
120 StatusTextNum
121 };
122
123public:
124 explicit TabPage(QWidget* parent = nullptr);
125 virtual ~TabPage();
126
127 void chdir(Fm::FilePath newPath, bool addHistory = true);
128
129 Fm::FolderView::ViewMode viewMode() {
130 return folderSettings_.viewMode();
131 }
132
133 void setViewMode(Fm::FolderView::ViewMode mode);
134
135 void sort(int col, Qt::SortOrder order = Qt::AscendingOrder);
136
137 int sortColumn() {
138 return folderSettings_.sortColumn();
139 }
140
141 Qt::SortOrder sortOrder() {
142 return folderSettings_.sortOrder();
143 }
144
145 bool sortFolderFirst() {
146 return folderSettings_.sortFolderFirst();
147 }
148 void setSortFolderFirst(bool value);
149
150 bool sortHiddenLast() {
151 return folderSettings_.sortHiddenLast();
152 }
153 void setSortHiddenLast(bool value);
154
155 bool sortCaseSensitive() {
156 return folderSettings_.sortCaseSensitive();
157 }
158
159 void setSortCaseSensitive(bool value);
160
161 bool showHidden() {
162 return proxyModel_->showHidden();
163 }
164
165 void setShowHidden(bool showHidden);
166
167 void setShowThumbnails(bool showThumbnails);
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 title() const {
208 return title_;
209 }
210
211 QString statusText(StatusTextType type = StatusTextNormal) const {
212 return statusText_[type];
213 }
214
215 bool canBackward() {
216 return history_.canBackward();
217 }
218
219 void backward();
220
221 bool canForward() {
222 return history_.canForward();
223 }
224
225 void forward();
226
227 void jumpToHistory(int index);
228
229 bool canUp();
230
231 void up();
232
233 void updateFromSettings(Settings& settings);
234
235 void setFileLauncher(Fm::FileLauncher* launcher) {
236 folderView_->setFileLauncher(launcher);
237 }
238
239 Fm::FileLauncher* fileLauncher() {
240 return folderView_->fileLauncher();
241 }
242
243 QString getFilterStr() {
244 if(proxyFilter_) {
245 return proxyFilter_->getFilterStr();
246 }
247 return QString();
248 }
249
250 void setFilterStr(QString str) {
251 if(proxyFilter_) {
252 proxyFilter_->setFilterStr(str);
253 }
254 }
255
256 void applyFilter();
257
258 bool hasCustomizedView() const {
259 return folderSettings_.isCustomized();
260 }
261 bool hasRecursiveCustomizedView() const {
262 return folderSettings_.isCustomized() && folderSettings_.recursive();
263 }
264 bool hasInheritedCustomizedView() const {
265 return !folderSettings_.isCustomized() && folderSettings_.inheritedPath().isValid();
266 }
267
268 void setCustomizedView(bool value, bool recursive = false);
269
270 void goToCustomizedViewSource();
271
272 void transientFilterBar(bool transient);
273
274 void showFilterBar();
275 bool isFilterBarVisible() const {
276 return (filterBar_ && filterBar_->isVisible());
277 }
278 void clearFilter() {
279 if(filterBar_) {
280 filterBar_->clear();
281 }
282 }
283
284 void backspacePressed();
285
286 void ceateShortcut();
287
288 void setFilesToSelect(const Fm::FilePathList& files) {
289 filesToSelect_ = files;
290 }
291
292Q_SIGNALS:
293 void statusChanged(int type, QString statusText);
294 void titleChanged();
295 void sortFilterChanged();
296 void forwardRequested();
297 void backwardRequested();
298 void folderUnmounted();
299
300protected:
301 virtual bool eventFilter(QObject* watched, QEvent* event);
302
303protected Q_SLOTS:
304 void onSelChanged();
305 void onUiUpdated();
306 void onFileSizeChanged(const QModelIndex& index);
307 void onFilesAdded(const Fm::FileInfoList files);
308 void onFilterStringChanged(QString str);
309 void onLosingFilterBarFocus();
310
311private:
312 void freeFolder();
313 QString formatStatusText();
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 bool canOpenAdmin();
327
328private:
329 View* folderView_;
330 Fm::CachedFolderModel* folderModel_;
331 Fm::ProxyFolderModel* proxyModel_;
332 ProxyFilter* proxyFilter_;
333 QVBoxLayout* verticalLayout;
334 std::shared_ptr<Fm::Folder> folder_;
335 QString title_;
336 QString statusText_[StatusTextNum];
337 Fm::BrowseHistory history_; // browsing history
338 Fm::FilePath lastFolderPath_; // last browsed folder
339 bool overrideCursor_;
340 FolderSettings folderSettings_;
341 QTimer* selectionTimer_;
342 FilterBar* filterBar_;
343 QStringList filesToTrust_;
344 Fm::FilePathList filesToSelect_; // files to select
345};
346
347}
348
349#endif // FM_TABPAGE_H
Definition: tabpage.h:86
Definition: tabpage.h:68
Definition: settings.h:42
Definition: tabpage.h:46
Definition: settings.h:154
Definition: tabpage.h:112
Definition: view.h:37