2 * Bittorrent Client using Qt and libtorrent.
3 * Copyright (C) 2016 Eugene Shalygin
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * In addition, as a special exception, the copyright holders give permission to
20 * link this program with the OpenSSL project's "OpenSSL" library (or with
21 * modified versions of it that use the same license as the "OpenSSL" library),
22 * and distribute the linked executables. You must obey the GNU General Public
23 * License in all respects for all of the code used other than "OpenSSL". If you
24 * modify file(s), you may extend this exception to your version of the file(s),
25 * but you are not obligated to do so. If you do not wish to do so, delete this
26 * exception statement from your version.
32 #include <QFileIconProvider>
34 #include <QtContainerFwd>
39 class QContextMenuEvent
;
40 class QFileSystemModel
;
45 class FileSystemPathValidator final
: public QValidator
50 FileSystemPathValidator(QObject
*parent
= nullptr);
52 bool strictMode() const;
53 void setStrictMode(bool v
);
55 bool existingOnly() const;
56 void setExistingOnly(bool v
);
58 bool directoriesOnly() const;
59 void setDirectoriesOnly(bool v
);
61 bool checkReadPermission() const;
62 void setCheckReadPermission(bool v
);
64 bool checkWritePermission() const;
65 void setCheckWritePermission(bool v
);
67 QValidator::State
validate(QString
&input
, int &pos
) const override
;
79 TestResult
lastTestResult() const;
80 QValidator::State
lastValidationState() const;
81 QString
lastTestedPath() const;
84 QValidator::State
validate(const QList
<QStringView
> &pathComponents
, bool strict
,
85 int firstComponentToTest
, int lastComponentToTest
) const;
87 TestResult
testPath(QStringView path
, bool pathIsComplete
) const;
91 bool m_directoriesOnly
;
92 bool m_checkReadPermission
;
93 bool m_checkWritePermission
;
95 mutable TestResult m_lastTestResult
;
96 mutable QValidator::State m_lastValidationState
;
97 mutable QString m_lastTestedPath
;
100 class FileEditorWithCompletion
103 virtual ~FileEditorWithCompletion() = default;
104 virtual void completeDirectoriesOnly(bool completeDirsOnly
) = 0;
105 virtual void setFilenameFilters(const QStringList
&filters
) = 0;
106 virtual void setBrowseAction(QAction
*action
) = 0;
107 virtual void setValidator(QValidator
*validator
) = 0;
108 virtual QWidget
*widget() = 0;
111 class FileLineEdit final
: public QLineEdit
, public FileEditorWithCompletion
114 Q_DISABLE_COPY_MOVE(FileLineEdit
)
117 FileLineEdit(QWidget
*parent
= nullptr);
120 void completeDirectoriesOnly(bool completeDirsOnly
) override
;
121 void setFilenameFilters(const QStringList
&filters
) override
;
122 void setBrowseAction(QAction
*action
) override
;
123 void setValidator(QValidator
*validator
) override
;
124 QWidget
*widget() override
;
127 void keyPressEvent(QKeyEvent
*event
) override
;
128 void contextMenuEvent(QContextMenuEvent
*event
) override
;
131 static QString
warningText(FileSystemPathValidator::TestResult r
);
132 void showCompletionPopup();
134 QFileSystemModel
*m_completerModel
;
135 QCompleter
*m_completer
;
136 QAction
*m_browseAction
;
137 QFileIconProvider m_iconProvider
;
138 QAction
*m_warningAction
;
141 class FileComboEdit final
: public QComboBox
, public FileEditorWithCompletion
146 FileComboEdit(QWidget
*parent
= nullptr);
148 void completeDirectoriesOnly(bool completeDirsOnly
) override
;
149 void setFilenameFilters(const QStringList
&filters
) override
;
150 void setBrowseAction(QAction
*action
) override
;
151 void setValidator(QValidator
*validator
) override
;
152 QWidget
*widget() override
;
155 QString
text() const;