-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
varjolintu
committed
Nov 7, 2019
1 parent
d4cb319
commit 3cdc3f7
Showing
5 changed files
with
145 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (C) 2014 Felix Geyer <[email protected]> | ||
* Copyright (C) 2019 KeePassXC Team <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 or (at your option) | ||
* version 3 of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "URLEdit.h" | ||
|
||
#include <QRegularExpression> | ||
#include <QUrl> | ||
|
||
#include "core/Config.h" | ||
#include "core/FilePath.h" | ||
#include "gui/Font.h" | ||
|
||
const QColor URLEdit::CorrectSoFarColor = QColor(255, 205, 15); | ||
const QColor URLEdit::ErrorColor = QColor(255, 125, 125); | ||
|
||
URLEdit::URLEdit(QWidget* parent) | ||
: QLineEdit(parent) | ||
{ | ||
const QIcon errorIcon = filePath()->icon("status", "dialog-error"); | ||
m_errorAction = addAction(errorIcon, QLineEdit::TrailingPosition); | ||
m_errorAction->setVisible(false); | ||
m_errorAction->setToolTip(tr("Invalid URL")); | ||
|
||
const QIcon correctIcon = filePath()->icon("actions", "dialog-ok"); | ||
m_correctAction = addAction(correctIcon, QLineEdit::TrailingPosition); | ||
m_correctAction->setVisible(false); | ||
m_correctAction->setToolTip(tr("URL is valid")); | ||
|
||
updateStylesheet(); | ||
} | ||
|
||
void URLEdit::enableVerifyMode() | ||
{ | ||
updateStylesheet(); | ||
|
||
connect(this, SIGNAL(textChanged(QString)), SLOT(updateStylesheet())); | ||
} | ||
|
||
bool URLEdit::validURL() const | ||
{ | ||
if (text().isEmpty()) { | ||
return true; | ||
} | ||
|
||
QUrl url(text()); | ||
|
||
if (url.host().isEmpty() || url.scheme().isEmpty() || !url.isValid()) { | ||
return false; | ||
} | ||
|
||
// Check for illegal characters | ||
QRegularExpression re("[\"<>\\^`{|}]"); | ||
auto match = re.match(text()); | ||
if (match.hasMatch()) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
void URLEdit::updateStylesheet() | ||
{ | ||
const QString stylesheetTemplate("QLineEdit { background: %1; }"); | ||
|
||
if (!validURL()) { | ||
setStyleSheet(stylesheetTemplate.arg(ErrorColor.name())); | ||
m_correctAction->setVisible(false); | ||
m_errorAction->setVisible(true); | ||
} else { | ||
m_correctAction->setVisible(false); | ||
m_errorAction->setVisible(false); | ||
setStyleSheet(""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (C) 2014 Felix Geyer <[email protected]> | ||
* Copyright (C) 2019 KeePassXC Team <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 or (at your option) | ||
* version 3 of the License. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef KEEPASSX_URLEDIT_H | ||
#define KEEPASSX_URLEDIT_H | ||
|
||
#include <QAction> | ||
#include <QLineEdit> | ||
#include <QPointer> | ||
|
||
class URLEdit : public QLineEdit | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
static const QColor CorrectSoFarColor; | ||
static const QColor ErrorColor; | ||
|
||
explicit URLEdit(QWidget* parent = nullptr); | ||
void enableVerifyMode(); | ||
|
||
private slots: | ||
void updateStylesheet(); | ||
|
||
private: | ||
bool validURL() const; | ||
|
||
QPointer<QAction> m_errorAction; | ||
QPointer<QAction> m_correctAction; | ||
}; | ||
|
||
#endif // KEEPASSX_URLEDIT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters