2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2024 Vladimir Golovnev <glassez@yandex.ru>
4 * Copyright (C) 2016 Eugene Shalygin
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * In addition, as a special exception, the copyright holders give permission to
21 * link this program with the OpenSSL project's "OpenSSL" library (or with
22 * modified versions of it that use the same license as the "OpenSSL" library),
23 * and distribute the linked executables. You must obey the GNU General Public
24 * License in all respects for all of the code used other than "OpenSSL". If you
25 * modify file(s), you may extend this exception to your version of the file(s),
26 * but you are not obligated to do so. If you do not wish to do so, delete this
27 * exception statement from your version.
34 #include <QtContainerFwd>
37 #include "base/pathfwd.h"
40 class QContextMenuEvent
;
41 class QFileIconProvider
;
42 class QFileSystemModel
;
47 class FileSystemPathValidator final
: public QValidator
50 Q_DISABLE_COPY_MOVE(FileSystemPathValidator
)
63 FileSystemPathValidator(QObject
*parent
= nullptr);
65 bool strictMode() const;
66 void setStrictMode(bool value
);
68 bool existingOnly() const;
69 void setExistingOnly(bool value
);
71 bool filesOnly() const;
72 void setFilesOnly(bool value
);
74 bool directoriesOnly() const;
75 void setDirectoriesOnly(bool value
);
77 bool checkReadPermission() const;
78 void setCheckReadPermission(bool value
);
80 bool checkWritePermission() const;
81 void setCheckWritePermission(bool value
);
83 TestResult
lastTestResult() const;
84 QValidator::State
lastValidationState() const;
86 QValidator::State
validate(QString
&input
, int &pos
) const override
;
89 TestResult
testPath(const Path
&path
) const;
91 bool m_strictMode
= false;
92 bool m_existingOnly
= false;
93 bool m_filesOnly
= false;
94 bool m_directoriesOnly
= false;
95 bool m_checkReadPermission
= false;
96 bool m_checkWritePermission
= false;
98 mutable TestResult m_lastTestResult
= TestResult::DoesNotExist
;
99 mutable QValidator::State m_lastValidationState
= QValidator::Invalid
;
102 class IFileEditorWithCompletion
105 virtual ~IFileEditorWithCompletion() = default;
106 virtual void completeDirectoriesOnly(bool completeDirsOnly
) = 0;
107 virtual void setFilenameFilters(const QStringList
&filters
) = 0;
108 virtual void setBrowseAction(QAction
*action
) = 0;
109 virtual void setValidator(QValidator
*validator
) = 0;
110 virtual Path
placeholder() const = 0;
111 virtual void setPlaceholder(const Path
&val
) = 0;
112 virtual QWidget
*widget() = 0;
115 class FileLineEdit final
: public QLineEdit
, public IFileEditorWithCompletion
118 Q_DISABLE_COPY_MOVE(FileLineEdit
)
121 FileLineEdit(QWidget
*parent
= nullptr);
124 void completeDirectoriesOnly(bool completeDirsOnly
) override
;
125 void setFilenameFilters(const QStringList
&filters
) override
;
126 void setBrowseAction(QAction
*action
) override
;
127 void setValidator(QValidator
*validator
) override
;
128 Path
placeholder() const override
;
129 void setPlaceholder(const Path
&val
) override
;
130 QWidget
*widget() override
;
133 void keyPressEvent(QKeyEvent
*event
) override
;
134 void contextMenuEvent(QContextMenuEvent
*event
) override
;
137 void showCompletionPopup();
140 static QString
warningText(FileSystemPathValidator::TestResult result
);
142 QFileSystemModel
*m_completerModel
= nullptr;
143 QAction
*m_browseAction
= nullptr;
144 QAction
*m_warningAction
= nullptr;
145 QFileIconProvider
*m_iconProvider
= nullptr;
146 bool m_completeDirectoriesOnly
= false;
147 QStringList m_filenameFilters
;
150 class FileComboEdit final
: public QComboBox
, public IFileEditorWithCompletion
153 Q_DISABLE_COPY_MOVE(FileComboEdit
)
156 FileComboEdit(QWidget
*parent
= nullptr);
158 void completeDirectoriesOnly(bool completeDirsOnly
) override
;
159 void setFilenameFilters(const QStringList
&filters
) override
;
160 void setBrowseAction(QAction
*action
) override
;
161 void setValidator(QValidator
*validator
) override
;
162 Path
placeholder() const override
;
163 void setPlaceholder(const Path
&val
) override
;
164 QWidget
*widget() override
;
167 QString
text() const;