SYNERGY-799 Add validation for aliases (#6969)
* SYNERGY-799 Add validation for aliases * SYNERGY-799 Update ChangeLog * SYNERGY-799 Fix code smells * SYNERGY-799 Use new version of "trilom/file-changes-action"
This commit is contained in:
parent
cf66eeaf08
commit
3c2810a3e0
28 changed files with 684 additions and 205 deletions
2
.github/workflows/job-changelog-check.yml
vendored
2
.github/workflows/job-changelog-check.yml
vendored
|
|
@ -16,7 +16,7 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- id: file_changes
|
- id: file_changes
|
||||||
name: Get changed files
|
name: Get changed files
|
||||||
uses: trilom/file-changes-action@v1.2.3
|
uses: trilom/file-changes-action@v1.2.4
|
||||||
with:
|
with:
|
||||||
output: ','
|
output: ','
|
||||||
- name: echo changes
|
- name: echo changes
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ Bug fixes:
|
||||||
Enhancements:
|
Enhancements:
|
||||||
- #6954 Move language selection to advanced section
|
- #6954 Move language selection to advanced section
|
||||||
- #6959 Update synergy UI. Setup wizard
|
- #6959 Update synergy UI. Setup wizard
|
||||||
|
- #6969 Update synergy UI. Validation for aliases.
|
||||||
- #6962 | #6965 Add macOS 10.13 builder
|
- #6962 | #6965 Add macOS 10.13 builder
|
||||||
===========
|
===========
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,12 @@ set (CMAKE_AUTORCC ON)
|
||||||
set (CMAKE_AUTOUIC ON)
|
set (CMAKE_AUTOUIC ON)
|
||||||
set (CMAKE_INCLUDE_CURRENT_DIR ON)
|
set (CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
|
||||||
file (GLOB LEGACY_GUI_SOURCE_FILES src/*.cpp src/*.h)
|
file (GLOB LEGACY_GUI_SOURCE_FILES
|
||||||
|
src/*.cpp
|
||||||
|
src/*.h
|
||||||
|
src/validators/*
|
||||||
|
src/validators/*.h
|
||||||
|
)
|
||||||
file (GLOB LEGACY_GUI_UI_FILES src/*.ui)
|
file (GLOB LEGACY_GUI_UI_FILES src/*.ui)
|
||||||
file (GLOB LEGACY_ACTIVATION_FILES src/*Activation* src/*License*)
|
file (GLOB LEGACY_ACTIVATION_FILES src/*Activation* src/*License*)
|
||||||
file (GLOB LEGACY_ZEROCONF_FILES src/Zeroconf*)
|
file (GLOB LEGACY_ZEROCONF_FILES src/Zeroconf*)
|
||||||
|
|
|
||||||
|
|
@ -1,154 +0,0 @@
|
||||||
/*
|
|
||||||
* synergy -- mouse and keyboard sharing utility
|
|
||||||
* Copyright (C) 2012-2016 Symless Ltd.
|
|
||||||
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
|
||||||
*
|
|
||||||
* This package is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License
|
|
||||||
* found in the file LICENSE that should have accompanied this file.
|
|
||||||
*
|
|
||||||
* This package 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 "ScreenNameValidator.h"
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
|
|
||||||
class EmptyNameValidator : public INameValidator
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool validate(const QString& input) const override
|
|
||||||
{
|
|
||||||
return !input.isEmpty();
|
|
||||||
}
|
|
||||||
|
|
||||||
QString getMessage() const override
|
|
||||||
{
|
|
||||||
return "Computer name can't be empty";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class SpacesValidator : public INameValidator
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool validate(const QString& input) const override
|
|
||||||
{
|
|
||||||
return !input.contains(' ');
|
|
||||||
}
|
|
||||||
|
|
||||||
QString getMessage() const override
|
|
||||||
{
|
|
||||||
return "Remove spaces";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class SpecialCharactersValidator : public INameValidator
|
|
||||||
{
|
|
||||||
|
|
||||||
public:
|
|
||||||
bool validate(const QString& input) const override
|
|
||||||
{
|
|
||||||
auto validator = QRegExp("[a-z0-9\\._-]{,255}", Qt::CaseInsensitive);
|
|
||||||
return (validator.exactMatch(input));
|
|
||||||
}
|
|
||||||
|
|
||||||
QString getMessage() const override
|
|
||||||
{
|
|
||||||
return "Remove unsupported characters";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class DuplicationsValidator : public INameValidator
|
|
||||||
{
|
|
||||||
const QString m_defaultName;
|
|
||||||
const ScreenList* m_pScreenList = nullptr;
|
|
||||||
|
|
||||||
public:
|
|
||||||
DuplicationsValidator(const QString defaultName,const ScreenList* pScreens) :
|
|
||||||
m_defaultName(defaultName),
|
|
||||||
m_pScreenList(pScreens)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
bool validate(const QString& input) const override
|
|
||||||
{
|
|
||||||
bool result = true;
|
|
||||||
|
|
||||||
if (m_pScreenList)
|
|
||||||
{
|
|
||||||
for(const auto& screen : (*m_pScreenList))
|
|
||||||
{
|
|
||||||
if (m_defaultName != input && input == screen.name())
|
|
||||||
{
|
|
||||||
result = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString getMessage() const override
|
|
||||||
{
|
|
||||||
return "Computer with this name already exists";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
ScreenNameValidator::ScreenNameValidator(QLineEdit* parent, QLabel* errors, const ScreenList* pScreens) :
|
|
||||||
m_pErrors(errors),
|
|
||||||
m_pControl(parent)
|
|
||||||
{
|
|
||||||
if (m_pErrors) {
|
|
||||||
m_pErrors->hide();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_Validators.push_back(std::make_unique<EmptyNameValidator>());
|
|
||||||
m_Validators.push_back(std::make_unique<SpacesValidator>());
|
|
||||||
m_Validators.push_back(std::make_unique<SpecialCharactersValidator>());
|
|
||||||
m_Validators.push_back(std::make_unique<DuplicationsValidator>(m_pControl ? m_pControl->text() : "", pScreens));
|
|
||||||
}
|
|
||||||
|
|
||||||
QValidator::State ScreenNameValidator::validate(QString& input, int& pos) const
|
|
||||||
{
|
|
||||||
if (m_pControl) {
|
|
||||||
showError("");
|
|
||||||
m_pControl->setStyleSheet("");
|
|
||||||
|
|
||||||
for(const auto& validator : m_Validators)
|
|
||||||
{
|
|
||||||
if (!validator->validate(input))
|
|
||||||
{
|
|
||||||
m_pControl->setStyleSheet("border: 1px solid #EC4C47");
|
|
||||||
showError(validator->getMessage());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return Acceptable;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ScreenNameValidator::showError(const QString& message) const
|
|
||||||
{
|
|
||||||
if (m_pErrors) {
|
|
||||||
m_pErrors->setText(message);
|
|
||||||
if (m_pErrors->text().isEmpty()) {
|
|
||||||
m_pErrors->hide();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
m_pErrors->show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -22,7 +22,6 @@
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <ScreenNameValidator.h>
|
|
||||||
|
|
||||||
ScreenSettingsDialog::ScreenSettingsDialog(QWidget* parent, Screen* pScreen,const ScreenList* pScreens) :
|
ScreenSettingsDialog::ScreenSettingsDialog(QWidget* parent, Screen* pScreen,const ScreenList* pScreens) :
|
||||||
QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
|
||||||
|
|
@ -32,10 +31,12 @@ ScreenSettingsDialog::ScreenSettingsDialog(QWidget* parent, Screen* pScreen,cons
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
m_pLineEditName->setText(m_pScreen->name());
|
m_pLineEditName->setText(m_pScreen->name());
|
||||||
m_pLineEditName->setValidator(new ScreenNameValidator(m_pLineEditName, m_pLabelNameError, pScreens));
|
m_NameValidator = std::make_unique<validators::ScreenNameValidator>(m_pLineEditName, m_pLabelNameError, pScreens);
|
||||||
|
m_pLineEditName->setValidator(m_NameValidator.get());
|
||||||
m_pLineEditName->selectAll();
|
m_pLineEditName->selectAll();
|
||||||
|
|
||||||
m_pLineEditAlias->setValidator(new ScreenNameValidator(m_pLineEditName));
|
m_AliasValidator = std::make_unique<validators::AliasValidator>(m_pLineEditAlias, m_pLabelAliasError);
|
||||||
|
m_pLineEditAlias->setValidator(m_AliasValidator.get());
|
||||||
|
|
||||||
for (int i = 0; i < m_pScreen->aliases().count(); i++)
|
for (int i = 0; i < m_pScreen->aliases().count(); i++)
|
||||||
new QListWidgetItem(m_pScreen->aliases()[i], m_pListAliases);
|
new QListWidgetItem(m_pScreen->aliases()[i], m_pListAliases);
|
||||||
|
|
@ -121,7 +122,7 @@ void ScreenSettingsDialog::on_m_pButtonAddAlias_clicked()
|
||||||
|
|
||||||
void ScreenSettingsDialog::on_m_pLineEditAlias_textChanged(const QString& text)
|
void ScreenSettingsDialog::on_m_pLineEditAlias_textChanged(const QString& text)
|
||||||
{
|
{
|
||||||
m_pButtonAddAlias->setEnabled(!text.isEmpty());
|
m_pButtonAddAlias->setEnabled(!text.isEmpty() && m_pLabelAliasError->text().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenSettingsDialog::on_m_pButtonRemoveAlias_clicked()
|
void ScreenSettingsDialog::on_m_pButtonRemoveAlias_clicked()
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,11 @@
|
||||||
#if !defined(SCREENSETTINGSDIALOG__H)
|
#if !defined(SCREENSETTINGSDIALOG__H)
|
||||||
|
|
||||||
#define SCREENSETTINGSDIALOG__H
|
#define SCREENSETTINGSDIALOG__H
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include "validators/ScreenNameValidator.h"
|
||||||
|
#include "validators/AliasValidator.h"
|
||||||
|
|
||||||
#include "ui_ScreenSettingsDialogBase.h"
|
#include "ui_ScreenSettingsDialogBase.h"
|
||||||
|
|
||||||
|
|
@ -48,6 +51,9 @@ class ScreenSettingsDialog : public QDialog, public Ui::ScreenSettingsDialogBase
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Screen* m_pScreen;
|
Screen* m_pScreen;
|
||||||
|
std::unique_ptr<validators::ScreenNameValidator> m_NameValidator;
|
||||||
|
std::unique_ptr<validators::AliasValidator> m_AliasValidator;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,11 @@
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLineEdit" name="m_pLineEditName"/>
|
<widget class="QLineEdit" name="m_pLineEditName">
|
||||||
|
<property name="maxLength">
|
||||||
|
<number>255</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
|
@ -67,7 +71,11 @@ font-weight: bold;</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout">
|
<layout class="QGridLayout">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLineEdit" name="m_pLineEditAlias"/>
|
<widget class="QLineEdit" name="m_pLineEditAlias">
|
||||||
|
<property name="maxLength">
|
||||||
|
<number>255</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="0" column="1">
|
<item row="0" column="1">
|
||||||
<widget class="QPushButton" name="m_pButtonAddAlias">
|
<widget class="QPushButton" name="m_pButtonAddAlias">
|
||||||
|
|
@ -79,24 +87,7 @@ font-weight: bold;</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0" rowspan="2">
|
<item row="3" column="1">
|
||||||
<widget class="QListWidget" name="m_pListAliases">
|
|
||||||
<property name="selectionMode">
|
|
||||||
<enum>QAbstractItemView::ExtendedSelection</enum>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="1">
|
|
||||||
<widget class="QPushButton" name="m_pButtonRemoveAlias">
|
|
||||||
<property name="enabled">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
<property name="text">
|
|
||||||
<string>&Remove</string>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item row="2" column="1">
|
|
||||||
<spacer>
|
<spacer>
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Vertical</enum>
|
<enum>Qt::Vertical</enum>
|
||||||
|
|
@ -109,6 +100,36 @@ font-weight: bold;</string>
|
||||||
</property>
|
</property>
|
||||||
</spacer>
|
</spacer>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="2" column="0" rowspan="2">
|
||||||
|
<widget class="QListWidget" name="m_pListAliases">
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::ExtendedSelection</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QPushButton" name="m_pButtonRemoveAlias">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>&Remove</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0" colspan="2">
|
||||||
|
<widget class="QLabel" name="m_pLabelAliasError">
|
||||||
|
<property name="styleSheet">
|
||||||
|
<string notr="true">color: #EC4C47;
|
||||||
|
font-size: 13px;
|
||||||
|
font-family: Arial;
|
||||||
|
font-weight: bold;</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string/>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "BonjourWindows.h"
|
#include "BonjourWindows.h"
|
||||||
#include "Zeroconf.h"
|
#include "Zeroconf.h"
|
||||||
#include "ScreenNameValidator.h"
|
|
||||||
|
|
||||||
#include <QtCore>
|
#include <QtCore>
|
||||||
#include <QtGui>
|
#include <QtGui>
|
||||||
|
|
@ -53,7 +52,8 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) :
|
||||||
enableControls(appConfig().isWritable());
|
enableControls(appConfig().isWritable());
|
||||||
|
|
||||||
const auto& serveConfig = m_pMainWindow->serverConfig();
|
const auto& serveConfig = m_pMainWindow->serverConfig();
|
||||||
m_pLineEditScreenName->setValidator(new ScreenNameValidator(m_pLineEditScreenName, m_pLabelNameError, (&serveConfig.screens())));
|
m_ScreenNameValidator = std::make_unique<validators::ScreenNameValidator>(m_pLineEditScreenName, m_pLabelNameError, (&serveConfig.screens()));
|
||||||
|
m_pLineEditScreenName->setValidator(m_ScreenNameValidator.get());
|
||||||
|
|
||||||
connect(m_pLineEditLogFilename, SIGNAL(textChanged(QString)), this, SLOT(onChange()));
|
connect(m_pLineEditLogFilename, SIGNAL(textChanged(QString)), this, SLOT(onChange()));
|
||||||
connect(m_pComboLogLevel, SIGNAL(currentIndexChanged(int)), this, SLOT(onChange()));
|
connect(m_pComboLogLevel, SIGNAL(currentIndexChanged(int)), this, SLOT(onChange()));
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,10 @@
|
||||||
|
|
||||||
#define SETTINGSDIALOG_H
|
#define SETTINGSDIALOG_H
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include "ui_SettingsDialogBase.h"
|
#include "ui_SettingsDialogBase.h"
|
||||||
|
#include "validators/ScreenNameValidator.h"
|
||||||
#include "SynergyLocale.h"
|
#include "SynergyLocale.h"
|
||||||
#include "CoreInterface.h"
|
#include "CoreInterface.h"
|
||||||
|
|
||||||
|
|
@ -68,6 +70,7 @@ class SettingsDialog : public QDialog, public Ui::SettingsDialogBase
|
||||||
SynergyLocale m_Locale;
|
SynergyLocale m_Locale;
|
||||||
CoreInterface m_CoreInterface;
|
CoreInterface m_CoreInterface;
|
||||||
BonjourWindows* m_pBonjourWindows;
|
BonjourWindows* m_pBonjourWindows;
|
||||||
|
std::unique_ptr<validators::ScreenNameValidator> m_ScreenNameValidator;
|
||||||
|
|
||||||
/// @brief Stores settings scope at start of settings dialog
|
/// @brief Stores settings scope at start of settings dialog
|
||||||
/// This is neccessary to restore state if user changes
|
/// This is neccessary to restore state if user changes
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
<property name="maxLength">
|
<property name="maxLength">
|
||||||
<number>15</number>
|
<number>255</number>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
#include "SetupWizard.h"
|
#include "SetupWizard.h"
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
#include "ScreenNameValidator.h"
|
#include "validators/ScreenNameValidator.h"
|
||||||
|
|
||||||
SetupWizard::SetupWizard(MainWindow& mainWindow) :
|
SetupWizard::SetupWizard(MainWindow& mainWindow) :
|
||||||
m_MainWindow(mainWindow)
|
m_MainWindow(mainWindow)
|
||||||
|
|
@ -25,7 +25,8 @@ SetupWizard::SetupWizard(MainWindow& mainWindow) :
|
||||||
setupUi(this);
|
setupUi(this);
|
||||||
|
|
||||||
m_pLineEditName->setText(m_MainWindow.appConfig().screenName());
|
m_pLineEditName->setText(m_MainWindow.appConfig().screenName());
|
||||||
m_pLineEditName->setValidator(new ScreenNameValidator(m_pLineEditName, label_ErrorMessage));
|
m_ScreenNameValidator = std::make_unique<validators::ScreenNameValidator>(m_pLineEditName, label_ErrorMessage);
|
||||||
|
m_pLineEditName->setValidator(m_ScreenNameValidator.get());
|
||||||
|
|
||||||
connect(m_pButtonApply, SIGNAL(clicked()), this, SLOT(accept()));
|
connect(m_pButtonApply, SIGNAL(clicked()), this, SLOT(accept()));
|
||||||
connect(m_pLineEditName, SIGNAL(textEdited(QString)), this, SLOT(onNameChanged()));
|
connect(m_pLineEditName, SIGNAL(textEdited(QString)), this, SLOT(onNameChanged()));
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,10 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <memory>
|
||||||
#include "ui_SetupWizardBase.h"
|
#include "ui_SetupWizardBase.h"
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include "validators/ScreenNameValidator.h"
|
||||||
|
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
|
|
||||||
|
|
@ -35,6 +36,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MainWindow& m_MainWindow;
|
MainWindow& m_MainWindow;
|
||||||
|
std::unique_ptr<validators::ScreenNameValidator> m_ScreenNameValidator;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onNameChanged();
|
void onNameChanged();
|
||||||
|
|
|
||||||
33
src/gui/src/validators/AliasValidator.cpp
Normal file
33
src/gui/src/validators/AliasValidator.cpp
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2012-2021 Symless Ltd.
|
||||||
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
||||||
|
*
|
||||||
|
* This package is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* found in the file LICENSE that should have accompanied this file.
|
||||||
|
*
|
||||||
|
* This package 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 "validators/SpacesValidator.h"
|
||||||
|
#include "validators/RegExpValidator.h"
|
||||||
|
|
||||||
|
#include "AliasValidator.h"
|
||||||
|
|
||||||
|
namespace validators
|
||||||
|
{
|
||||||
|
|
||||||
|
AliasValidator::AliasValidator(QLineEdit* parent, QLabel* errors) :
|
||||||
|
LineEditValidator(parent, errors)
|
||||||
|
{
|
||||||
|
addValidator(std::make_unique<SpacesValidator>("Remove spaces"));
|
||||||
|
addValidator(std::make_unique<RegExpValidator>("Remove unsupported characters", QRegExp("[a-z0-9\\._-]{,255}", Qt::CaseInsensitive)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
34
src/gui/src/validators/AliasValidator.h
Normal file
34
src/gui/src/validators/AliasValidator.h
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2012-2021 Symless Ltd.
|
||||||
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
||||||
|
*
|
||||||
|
* This package is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* found in the file LICENSE that should have accompanied this file.
|
||||||
|
*
|
||||||
|
* This package 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 ALIASVALIDATOR_H
|
||||||
|
#define ALIASVALIDATOR_H
|
||||||
|
|
||||||
|
#include "LineEditValidator.h"
|
||||||
|
|
||||||
|
namespace validators
|
||||||
|
{
|
||||||
|
|
||||||
|
class AliasValidator : public LineEditValidator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit AliasValidator(QLineEdit* parent = nullptr, QLabel* errors = nullptr);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ALIASVALIDATOR_H
|
||||||
34
src/gui/src/validators/EmptyStringValidator.cpp
Normal file
34
src/gui/src/validators/EmptyStringValidator.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2012-2021 Symless Ltd.
|
||||||
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
||||||
|
*
|
||||||
|
* This package is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* found in the file LICENSE that should have accompanied this file.
|
||||||
|
*
|
||||||
|
* This package 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 "EmptyStringValidator.h"
|
||||||
|
|
||||||
|
namespace validators
|
||||||
|
{
|
||||||
|
|
||||||
|
EmptyStringValidator::EmptyStringValidator(const QString& message) :
|
||||||
|
IStringValidator(message)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EmptyStringValidator::validate(const QString& input) const
|
||||||
|
{
|
||||||
|
return !input.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
35
src/gui/src/validators/EmptyStringValidator.h
Normal file
35
src/gui/src/validators/EmptyStringValidator.h
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2012-2021 Symless Ltd.
|
||||||
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
||||||
|
*
|
||||||
|
* This package is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* found in the file LICENSE that should have accompanied this file.
|
||||||
|
*
|
||||||
|
* This package 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 EMPTYSTRINGVALIDATOR_H
|
||||||
|
#define EMPTYSTRINGVALIDATOR_H
|
||||||
|
|
||||||
|
#include "IStringValidator.h"
|
||||||
|
|
||||||
|
namespace validators
|
||||||
|
{
|
||||||
|
|
||||||
|
class EmptyStringValidator : public IStringValidator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit EmptyStringValidator(const QString& message);
|
||||||
|
bool validate(const QString& input) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // EMPTYSTRINGVALIDATOR_H
|
||||||
34
src/gui/src/validators/IStringValidator.cpp
Normal file
34
src/gui/src/validators/IStringValidator.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2012-2021 Symless Ltd.
|
||||||
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
||||||
|
*
|
||||||
|
* This package is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* found in the file LICENSE that should have accompanied this file.
|
||||||
|
*
|
||||||
|
* This package 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 "EmptyStringValidator.h"
|
||||||
|
|
||||||
|
namespace validators
|
||||||
|
{
|
||||||
|
|
||||||
|
IStringValidator::IStringValidator(const QString& message) :
|
||||||
|
m_Message(message)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString& IStringValidator::getMessage() const
|
||||||
|
{
|
||||||
|
return m_Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
42
src/gui/src/validators/IStringValidator.h
Normal file
42
src/gui/src/validators/IStringValidator.h
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2012-2021 Symless Ltd.
|
||||||
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
||||||
|
*
|
||||||
|
* This package is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* found in the file LICENSE that should have accompanied this file.
|
||||||
|
*
|
||||||
|
* This package 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 IVALIDATOR_H
|
||||||
|
#define IVALIDATOR_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
namespace validators
|
||||||
|
{
|
||||||
|
|
||||||
|
class IStringValidator
|
||||||
|
{
|
||||||
|
QString m_Message;
|
||||||
|
|
||||||
|
public:
|
||||||
|
IStringValidator() = default;
|
||||||
|
explicit IStringValidator(const QString& message);
|
||||||
|
const QString& getMessage() const;
|
||||||
|
|
||||||
|
virtual bool validate(const QString& input) const = 0;
|
||||||
|
virtual ~IStringValidator() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // IVALIDATOR_H
|
||||||
75
src/gui/src/validators/LineEditValidator.cpp
Normal file
75
src/gui/src/validators/LineEditValidator.cpp
Normal file
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2012-2021 Symless Ltd.
|
||||||
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
||||||
|
*
|
||||||
|
* This package is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* found in the file LICENSE that should have accompanied this file.
|
||||||
|
*
|
||||||
|
* This package 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 "LineEditValidator.h"
|
||||||
|
|
||||||
|
namespace validators
|
||||||
|
{
|
||||||
|
|
||||||
|
LineEditValidator::LineEditValidator(QLineEdit* parent, QLabel* errors) :
|
||||||
|
m_pErrors(errors),
|
||||||
|
m_pControl(parent)
|
||||||
|
{
|
||||||
|
if (m_pErrors) {
|
||||||
|
m_pErrors->hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void LineEditValidator::addValidator(std::unique_ptr<IStringValidator> validator)
|
||||||
|
{
|
||||||
|
m_Validators.push_back(std::move(validator));
|
||||||
|
}
|
||||||
|
|
||||||
|
QValidator::State LineEditValidator::validate(QString& input, int& pos) const
|
||||||
|
{
|
||||||
|
if (m_pControl)
|
||||||
|
{
|
||||||
|
showError("");
|
||||||
|
m_pControl->setStyleSheet("");
|
||||||
|
|
||||||
|
for (const auto& validator : m_Validators)
|
||||||
|
{
|
||||||
|
if (!validator->validate(input))
|
||||||
|
{
|
||||||
|
m_pControl->setStyleSheet("border: 1px solid #EC4C47");
|
||||||
|
showError(validator->getMessage());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Acceptable;
|
||||||
|
}
|
||||||
|
|
||||||
|
void LineEditValidator::showError(const QString& message) const
|
||||||
|
{
|
||||||
|
if (m_pErrors)
|
||||||
|
{
|
||||||
|
m_pErrors->setText(message);
|
||||||
|
|
||||||
|
if (m_pErrors->text().isEmpty())
|
||||||
|
{
|
||||||
|
m_pErrors->hide();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_pErrors->show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* synergy -- mouse and keyboard sharing utility
|
* synergy -- mouse and keyboard sharing utility
|
||||||
* Copyright (C) 2012-2016 Symless Ltd.
|
* Copyright (C) 2012-2021 Symless Ltd.
|
||||||
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
||||||
*
|
*
|
||||||
* This package is free software; you can redistribute it and/or
|
* This package is free software; you can redistribute it and/or
|
||||||
|
|
@ -15,36 +15,37 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#ifndef SCREENNAMEVALIDATOR_H
|
#ifndef LINEEDITVALIDATOR_H
|
||||||
#define SCREENNAMEVALIDATOR_H
|
#define LINEEDITVALIDATOR_H
|
||||||
|
|
||||||
#include <QtWidgets/QLabel>
|
|
||||||
#include <QtWidgets/QLineEdit>
|
|
||||||
#include <qvalidator.h>
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Screen.h"
|
|
||||||
|
|
||||||
class INameValidator
|
#include <qvalidator.h>
|
||||||
|
#include <QtWidgets/QLabel>
|
||||||
|
#include <QtWidgets/QLineEdit>
|
||||||
|
|
||||||
|
#include "IStringValidator.h"
|
||||||
|
|
||||||
|
namespace validators
|
||||||
|
{
|
||||||
|
|
||||||
|
class LineEditValidator : public QValidator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual bool validate(const QString& input) const = 0;
|
explicit LineEditValidator(QLineEdit* parent = nullptr, QLabel* errors = nullptr);
|
||||||
virtual QString getMessage() const = 0;
|
|
||||||
virtual ~INameValidator() = default;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ScreenNameValidator : public QValidator
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
explicit ScreenNameValidator(QLineEdit* parent = nullptr, QLabel* errors = nullptr, const ScreenList* pScreens = nullptr);
|
|
||||||
QValidator::State validate(QString& input, int& pos) const override;
|
QValidator::State validate(QString& input, int& pos) const override;
|
||||||
|
void addValidator(std::unique_ptr<IStringValidator> validator);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QLabel* m_pErrors = nullptr;
|
QLabel* m_pErrors = nullptr;
|
||||||
QLineEdit* m_pControl = nullptr;
|
QLineEdit* m_pControl = nullptr;
|
||||||
std::vector<std::unique_ptr<INameValidator>> m_Validators;
|
std::vector<std::unique_ptr<IStringValidator>> m_Validators;
|
||||||
|
|
||||||
void showError(const QString& message) const;
|
void showError(const QString& message) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SCREENNAMEVALIDATOR_H
|
}
|
||||||
|
|
||||||
|
#endif // LINEEDITVALIDATOR_H
|
||||||
35
src/gui/src/validators/RegExpValidator.cpp
Normal file
35
src/gui/src/validators/RegExpValidator.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2012-2021 Symless Ltd.
|
||||||
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
||||||
|
*
|
||||||
|
* This package is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* found in the file LICENSE that should have accompanied this file.
|
||||||
|
*
|
||||||
|
* This package 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 "RegExpValidator.h"
|
||||||
|
|
||||||
|
namespace validators
|
||||||
|
{
|
||||||
|
|
||||||
|
RegExpValidator::RegExpValidator(const QString& message, const QRegExp& validator) :
|
||||||
|
IStringValidator(message),
|
||||||
|
m_Validator(validator)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RegExpValidator::validate(const QString& input) const
|
||||||
|
{
|
||||||
|
return (m_Validator.exactMatch(input));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
37
src/gui/src/validators/RegExpValidator.h
Normal file
37
src/gui/src/validators/RegExpValidator.h
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2012-2021 Symless Ltd.
|
||||||
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
||||||
|
*
|
||||||
|
* This package is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* found in the file LICENSE that should have accompanied this file.
|
||||||
|
*
|
||||||
|
* This package 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 REGEXPVALIDATOR_H
|
||||||
|
#define REGEXPVALIDATOR_H
|
||||||
|
|
||||||
|
#include <qregexp.h>
|
||||||
|
#include "IStringValidator.h"
|
||||||
|
|
||||||
|
namespace validators
|
||||||
|
{
|
||||||
|
|
||||||
|
class RegExpValidator : public IStringValidator
|
||||||
|
{
|
||||||
|
QRegExp m_Validator;
|
||||||
|
public:
|
||||||
|
RegExpValidator(const QString& message, const QRegExp& validator);
|
||||||
|
bool validate(const QString& input) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // REGEXPVALIDATOR_H
|
||||||
52
src/gui/src/validators/ScreenDuplicationsValidator.cpp
Normal file
52
src/gui/src/validators/ScreenDuplicationsValidator.cpp
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2012-2021 Symless Ltd.
|
||||||
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
||||||
|
*
|
||||||
|
* This package is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* found in the file LICENSE that should have accompanied this file.
|
||||||
|
*
|
||||||
|
* This package 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 "ScreenDuplicationsValidator.h"
|
||||||
|
|
||||||
|
namespace validators
|
||||||
|
{
|
||||||
|
|
||||||
|
ScreenDuplicationsValidator::ScreenDuplicationsValidator(const QString& message, const QString& defaultName,const ScreenList* pScreens) :
|
||||||
|
IStringValidator(message),
|
||||||
|
m_defaultName(defaultName),
|
||||||
|
m_pScreenList(pScreens)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScreenDuplicationsValidator::validate(const QString& input) const
|
||||||
|
{
|
||||||
|
bool result = true;
|
||||||
|
|
||||||
|
if (m_pScreenList)
|
||||||
|
{
|
||||||
|
for (const auto& screen : (*m_pScreenList))
|
||||||
|
{
|
||||||
|
if (!screen.isNull() &&
|
||||||
|
input != m_defaultName &&
|
||||||
|
input == screen.name())
|
||||||
|
{
|
||||||
|
result = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
39
src/gui/src/validators/ScreenDuplicationsValidator.h
Normal file
39
src/gui/src/validators/ScreenDuplicationsValidator.h
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2012-2021 Symless Ltd.
|
||||||
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
||||||
|
*
|
||||||
|
* This package is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* found in the file LICENSE that should have accompanied this file.
|
||||||
|
*
|
||||||
|
* This package 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 SCREENDUPLICATIONSVALIDATOR_H
|
||||||
|
#define SCREENDUPLICATIONSVALIDATOR_H
|
||||||
|
|
||||||
|
#include "Screen.h"
|
||||||
|
#include "IStringValidator.h"
|
||||||
|
|
||||||
|
namespace validators
|
||||||
|
{
|
||||||
|
|
||||||
|
class ScreenDuplicationsValidator : public IStringValidator
|
||||||
|
{
|
||||||
|
const QString m_defaultName;
|
||||||
|
const ScreenList* m_pScreenList = nullptr;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ScreenDuplicationsValidator(const QString& message, const QString& defaultName,const ScreenList* pScreens);
|
||||||
|
bool validate(const QString& input) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SCREENDUPLICATIONSVALIDATOR_H
|
||||||
38
src/gui/src/validators/ScreenNameValidator.cpp
Normal file
38
src/gui/src/validators/ScreenNameValidator.cpp
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2012-2021 Symless Ltd.
|
||||||
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
||||||
|
*
|
||||||
|
* This package is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* found in the file LICENSE that should have accompanied this file.
|
||||||
|
*
|
||||||
|
* This package 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 <memory>
|
||||||
|
|
||||||
|
#include "validators/SpacesValidator.h"
|
||||||
|
#include "validators/RegExpValidator.h"
|
||||||
|
#include "validators/EmptyStringValidator.h"
|
||||||
|
#include "validators/ScreenDuplicationsValidator.h"
|
||||||
|
#include "ScreenNameValidator.h"
|
||||||
|
|
||||||
|
namespace validators
|
||||||
|
{
|
||||||
|
|
||||||
|
ScreenNameValidator::ScreenNameValidator(QLineEdit* parent, QLabel* errors, const ScreenList* pScreens) :
|
||||||
|
LineEditValidator(parent, errors)
|
||||||
|
{
|
||||||
|
addValidator(std::make_unique<EmptyStringValidator>("Computer name can't be empty"));
|
||||||
|
addValidator(std::make_unique<SpacesValidator>("Remove spaces"));
|
||||||
|
addValidator(std::make_unique<RegExpValidator>("Remove unsupported characters", QRegExp("[a-z0-9\\._-]{,255}", Qt::CaseInsensitive)));
|
||||||
|
addValidator(std::make_unique<ScreenDuplicationsValidator>("A computer with this name already exists", parent ? parent->text() : "", pScreens));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
35
src/gui/src/validators/ScreenNameValidator.h
Normal file
35
src/gui/src/validators/ScreenNameValidator.h
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2012-2021 Symless Ltd.
|
||||||
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
||||||
|
*
|
||||||
|
* This package is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* found in the file LICENSE that should have accompanied this file.
|
||||||
|
*
|
||||||
|
* This package 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 SCREENNAMEVALIDATOR_H
|
||||||
|
#define SCREENNAMEVALIDATOR_H
|
||||||
|
|
||||||
|
#include "Screen.h"
|
||||||
|
#include "LineEditValidator.h"
|
||||||
|
|
||||||
|
namespace validators
|
||||||
|
{
|
||||||
|
|
||||||
|
class ScreenNameValidator : public LineEditValidator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit ScreenNameValidator(QLineEdit* parent = nullptr, QLabel* errors = nullptr, const ScreenList* pScreens = nullptr);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SCREENNAMEVALIDATOR_H
|
||||||
34
src/gui/src/validators/SpacesValidator.cpp
Normal file
34
src/gui/src/validators/SpacesValidator.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2012-2021 Symless Ltd.
|
||||||
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
||||||
|
*
|
||||||
|
* This package is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* found in the file LICENSE that should have accompanied this file.
|
||||||
|
*
|
||||||
|
* This package 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 "SpacesValidator.h"
|
||||||
|
|
||||||
|
namespace validators
|
||||||
|
{
|
||||||
|
|
||||||
|
SpacesValidator::SpacesValidator(const QString& message) :
|
||||||
|
IStringValidator(message)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SpacesValidator::validate(const QString& input) const
|
||||||
|
{
|
||||||
|
return !input.contains(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
35
src/gui/src/validators/SpacesValidator.h
Normal file
35
src/gui/src/validators/SpacesValidator.h
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* synergy -- mouse and keyboard sharing utility
|
||||||
|
* Copyright (C) 2012-2021 Symless Ltd.
|
||||||
|
* Copyright (C) 2008 Volker Lanz (vl@fidra.de)
|
||||||
|
*
|
||||||
|
* This package is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License
|
||||||
|
* found in the file LICENSE that should have accompanied this file.
|
||||||
|
*
|
||||||
|
* This package 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 SPACESVALIDATOR_H
|
||||||
|
#define SPACESVALIDATOR_H
|
||||||
|
|
||||||
|
#include "IStringValidator.h"
|
||||||
|
|
||||||
|
namespace validators
|
||||||
|
{
|
||||||
|
|
||||||
|
class SpacesValidator : public IStringValidator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit SpacesValidator(const QString& message);
|
||||||
|
bool validate(const QString& input) const override;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // SPACESVALIDATOR_H
|
||||||
Loading…
Reference in a new issue