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-qt6/browsehistory.h>
28#include "view.h"
29#include "settings.h"
30
31#include <libfm-qt6/core/fileinfo.h>
32#include <libfm-qt6/core/filepath.h>
33#include <libfm-qt6/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 deselectAll();
204
205 void invertSelection();
206
207 void reload();
208
209 QString title() const {
210 return title_;
211 }
212
213 QString statusText(StatusTextType type = StatusTextNormal) const {
214 return statusText_[type];
215 }
216
217 bool canBackward() {
218 return history_.canBackward();
219 }
220
221 void backward();
222
223 bool canForward() {
224 return history_.canForward();
225 }
226
227 void forward();
228
229 void jumpToHistory(int index);
230
231 bool canUp();
232
233 void up();
234
235 void updateFromSettings(Settings& settings);
236
237 void setFileLauncher(Fm::FileLauncher* launcher) {
238 folderView_->setFileLauncher(launcher);
239 }
240
241 Fm::FileLauncher* fileLauncher() {
242 return folderView_->fileLauncher();
243 }
244
245 QString getFilterStr() {
246 if(proxyFilter_) {
247 return proxyFilter_->getFilterStr();
248 }
249 return QString();
250 }
251
252 void setFilterStr(QString str) {
253 if(proxyFilter_) {
254 proxyFilter_->setFilterStr(str);
255 }
256 }
257
258 void applyFilter();
259
260 bool hasCustomizedView() const {
261 return folderSettings_.isCustomized();
262 }
263 bool hasRecursiveCustomizedView() const {
264 return folderSettings_.isCustomized() && folderSettings_.recursive();
265 }
266 bool hasInheritedCustomizedView() const {
267 return !folderSettings_.isCustomized() && folderSettings_.inheritedPath().isValid();
268 }
269
270 void setCustomizedView(bool value, bool recursive = false);
271
272 void goToCustomizedViewSource();
273
274 void transientFilterBar(bool transient);
275
276 void showFilterBar();
277 bool isFilterBarVisible() const {
278 return (filterBar_ && filterBar_->isVisible());
279 }
280 void clearFilter() {
281 if(filterBar_) {
282 filterBar_->clear();
283 }
284 }
285
286 void backspacePressed();
287
288 void createShortcut();
289
290 void setFilesToSelect(const Fm::FilePathList& files) {
291 filesToSelect_ = files;
292 }
293
294Q_SIGNALS:
295 void statusChanged(int type, QString statusText);
296 void titleChanged();
297 void sortFilterChanged();
298 void forwardRequested();
299 void backwardRequested();
300 void folderUnmounted();
301
302protected:
303 virtual bool eventFilter(QObject* watched, QEvent* event);
304
305protected Q_SLOTS:
306 void onSelChanged();
307 void onUiUpdated();
308 void onFileSizeChanged(const QModelIndex& index);
309 void onFilesAdded(const Fm::FileInfoList files);
310 void onFilterStringChanged(QString str);
311 void onLosingFilterBarFocus();
312
313private:
314 void freeFolder();
315 QString formatStatusText();
316 void localizeTitle(const Fm::FilePath& path);
317
318 void onFolderStartLoading();
319 void onFolderFinishLoading();
320
321 // FIXME: this API design is bad and might be removed later
322 void onFolderError(const Fm::GErrorPtr& err, Fm::Job::ErrorSeverity severity, Fm::Job::ErrorAction& response);
323
324 void onFolderFsInfo();
325 void onFolderRemoved();
326 void onFolderUnmount();
327 void onFolderContentChanged();
328
329 bool canOpenAdmin();
330
331private:
332 View* folderView_;
333 Fm::CachedFolderModel* folderModel_;
334 Fm::ProxyFolderModel* proxyModel_;
335 ProxyFilter* proxyFilter_;
336 QVBoxLayout* verticalLayout;
337 std::shared_ptr<Fm::Folder> folder_;
338 QString title_;
339 QString statusText_[StatusTextNum];
340 Fm::BrowseHistory history_; // browsing history
341 Fm::FilePath lastFolderPath_; // last browsed folder
342 bool overrideCursor_;
343 FolderSettings folderSettings_;
344 QTimer* selectionTimer_;
345 FilterBar* filterBar_;
346 QStringList filesToTrust_;
347 Fm::FilePathList filesToSelect_; // files to select
348};
349
350}
351
352#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