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:
SerhiiGadzhilov 2021-03-24 14:38:50 +02:00 committed by GitHub
parent cf66eeaf08
commit 3c2810a3e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 684 additions and 205 deletions

View file

@ -16,7 +16,7 @@ jobs:
steps:
- id: file_changes
name: Get changed files
uses: trilom/file-changes-action@v1.2.3
uses: trilom/file-changes-action@v1.2.4
with:
output: ','
- name: echo changes

View file

@ -8,6 +8,7 @@ Bug fixes:
Enhancements:
- #6954 Move language selection to advanced section
- #6959 Update synergy UI. Setup wizard
- #6969 Update synergy UI. Validation for aliases.
- #6962 | #6965 Add macOS 10.13 builder
===========

View file

@ -6,7 +6,12 @@ set (CMAKE_AUTORCC ON)
set (CMAKE_AUTOUIC 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_ACTIVATION_FILES src/*Activation* src/*License*)
file (GLOB LEGACY_ZEROCONF_FILES src/Zeroconf*)

View file

@ -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();
}
}
}

View file

@ -22,7 +22,6 @@
#include <QtCore>
#include <QtGui>
#include <QMessageBox>
#include <ScreenNameValidator.h>
ScreenSettingsDialog::ScreenSettingsDialog(QWidget* parent, Screen* pScreen,const ScreenList* pScreens) :
QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint),
@ -32,10 +31,12 @@ ScreenSettingsDialog::ScreenSettingsDialog(QWidget* parent, Screen* pScreen,cons
setupUi(this);
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_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++)
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)
{
m_pButtonAddAlias->setEnabled(!text.isEmpty());
m_pButtonAddAlias->setEnabled(!text.isEmpty() && m_pLabelAliasError->text().isEmpty());
}
void ScreenSettingsDialog::on_m_pButtonRemoveAlias_clicked()

View file

@ -19,8 +19,11 @@
#if !defined(SCREENSETTINGSDIALOG__H)
#define SCREENSETTINGSDIALOG__H
#include <memory>
#include <QDialog>
#include "validators/ScreenNameValidator.h"
#include "validators/AliasValidator.h"
#include "ui_ScreenSettingsDialogBase.h"
@ -48,6 +51,9 @@ class ScreenSettingsDialog : public QDialog, public Ui::ScreenSettingsDialogBase
private:
Screen* m_pScreen;
std::unique_ptr<validators::ScreenNameValidator> m_NameValidator;
std::unique_ptr<validators::AliasValidator> m_AliasValidator;
};
#endif

View file

@ -27,7 +27,11 @@
</widget>
</item>
<item>
<widget class="QLineEdit" name="m_pLineEditName"/>
<widget class="QLineEdit" name="m_pLineEditName">
<property name="maxLength">
<number>255</number>
</property>
</widget>
</item>
</layout>
</item>
@ -67,7 +71,11 @@ font-weight: bold;</string>
</property>
<layout class="QGridLayout">
<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 row="0" column="1">
<widget class="QPushButton" name="m_pButtonAddAlias">
@ -79,24 +87,7 @@ font-weight: bold;</string>
</property>
</widget>
</item>
<item row="1" column="0" rowspan="2">
<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>&amp;Remove</string>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
@ -109,6 +100,36 @@ font-weight: bold;</string>
</property>
</spacer>
</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>&amp;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>
</widget>
</item>

View file

@ -26,7 +26,6 @@
#include "MainWindow.h"
#include "BonjourWindows.h"
#include "Zeroconf.h"
#include "ScreenNameValidator.h"
#include <QtCore>
#include <QtGui>
@ -53,7 +52,8 @@ SettingsDialog::SettingsDialog(QWidget* parent, AppConfig& config) :
enableControls(appConfig().isWritable());
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_pComboLogLevel, SIGNAL(currentIndexChanged(int)), this, SLOT(onChange()));

View file

@ -20,8 +20,10 @@
#define SETTINGSDIALOG_H
#include <memory>
#include <QDialog>
#include "ui_SettingsDialogBase.h"
#include "validators/ScreenNameValidator.h"
#include "SynergyLocale.h"
#include "CoreInterface.h"
@ -68,6 +70,7 @@ class SettingsDialog : public QDialog, public Ui::SettingsDialogBase
SynergyLocale m_Locale;
CoreInterface m_CoreInterface;
BonjourWindows* m_pBonjourWindows;
std::unique_ptr<validators::ScreenNameValidator> m_ScreenNameValidator;
/// @brief Stores settings scope at start of settings dialog
/// This is neccessary to restore state if user changes

View file

@ -92,7 +92,7 @@
<bool>true</bool>
</property>
<property name="maxLength">
<number>15</number>
<number>255</number>
</property>
</widget>
</item>

View file

@ -17,7 +17,7 @@
#include "SetupWizard.h"
#include "MainWindow.h"
#include "ScreenNameValidator.h"
#include "validators/ScreenNameValidator.h"
SetupWizard::SetupWizard(MainWindow& mainWindow) :
m_MainWindow(mainWindow)
@ -25,7 +25,8 @@ SetupWizard::SetupWizard(MainWindow& mainWindow) :
setupUi(this);
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_pLineEditName, SIGNAL(textEdited(QString)), this, SLOT(onNameChanged()));

View file

@ -16,9 +16,10 @@
*/
#pragma once
#include <memory>
#include "ui_SetupWizardBase.h"
#include <QDialog>
#include "validators/ScreenNameValidator.h"
class MainWindow;
@ -35,6 +36,7 @@ protected:
private:
MainWindow& m_MainWindow;
std::unique_ptr<validators::ScreenNameValidator> m_ScreenNameValidator;
private slots:
void onNameChanged();

View 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)));
}
}

View 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

View 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();
}
}

View 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

View 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;
}
}

View 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

View 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();
}
}
}
}

View file

@ -1,6 +1,6 @@
/*
* 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)
*
* 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
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SCREENNAMEVALIDATOR_H
#define SCREENNAMEVALIDATOR_H
#ifndef LINEEDITVALIDATOR_H
#define LINEEDITVALIDATOR_H
#include <QtWidgets/QLabel>
#include <QtWidgets/QLineEdit>
#include <qvalidator.h>
#include <memory>
#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:
virtual bool validate(const QString& input) const = 0;
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);
explicit LineEditValidator(QLineEdit* parent = nullptr, QLabel* errors = nullptr);
QValidator::State validate(QString& input, int& pos) const override;
void addValidator(std::unique_ptr<IStringValidator> validator);
private:
QLabel* m_pErrors = 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;
};
#endif // SCREENNAMEVALIDATOR_H
}
#endif // LINEEDITVALIDATOR_H

View 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));
}
}

View 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

View 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;
}
}

View 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

View 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));
}
}

View 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

View 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(' ');
}
}

View 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