diff --git a/.github/workflows/job-changelog-check.yml b/.github/workflows/job-changelog-check.yml index 074cde40d..10c2ffb98 100644 --- a/.github/workflows/job-changelog-check.yml +++ b/.github/workflows/job-changelog-check.yml @@ -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 diff --git a/ChangeLog b/ChangeLog index 752f2cb6a..66ec45c16 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 =========== diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index ce81e0734..f26ca7c9c 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -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*) diff --git a/src/gui/src/ScreenNameValidator.cpp b/src/gui/src/ScreenNameValidator.cpp deleted file mode 100644 index a3e502728..000000000 --- a/src/gui/src/ScreenNameValidator.cpp +++ /dev/null @@ -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 . - */ -#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()); - m_Validators.push_back(std::make_unique()); - m_Validators.push_back(std::make_unique()); - m_Validators.push_back(std::make_unique(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(); - } - } -} diff --git a/src/gui/src/ScreenSettingsDialog.cpp b/src/gui/src/ScreenSettingsDialog.cpp index 01855c133..c919357ab 100644 --- a/src/gui/src/ScreenSettingsDialog.cpp +++ b/src/gui/src/ScreenSettingsDialog.cpp @@ -22,7 +22,6 @@ #include #include #include -#include 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(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(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() diff --git a/src/gui/src/ScreenSettingsDialog.h b/src/gui/src/ScreenSettingsDialog.h index 45f6f0292..3153d9399 100644 --- a/src/gui/src/ScreenSettingsDialog.h +++ b/src/gui/src/ScreenSettingsDialog.h @@ -19,8 +19,11 @@ #if !defined(SCREENSETTINGSDIALOG__H) #define SCREENSETTINGSDIALOG__H +#include #include +#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 m_NameValidator; + std::unique_ptr m_AliasValidator; + }; #endif diff --git a/src/gui/src/ScreenSettingsDialogBase.ui b/src/gui/src/ScreenSettingsDialogBase.ui index 1ba7b5f68..bb81bfc58 100644 --- a/src/gui/src/ScreenSettingsDialogBase.ui +++ b/src/gui/src/ScreenSettingsDialogBase.ui @@ -27,7 +27,11 @@ - + + + 255 + + @@ -67,7 +71,11 @@ font-weight: bold; - + + + 255 + + @@ -79,24 +87,7 @@ font-weight: bold; - - - - QAbstractItemView::ExtendedSelection - - - - - - - false - - - &Remove - - - - + Qt::Vertical @@ -109,6 +100,36 @@ font-weight: bold; + + + + QAbstractItemView::ExtendedSelection + + + + + + + false + + + &Remove + + + + + + + color: #EC4C47; +font-size: 13px; +font-family: Arial; +font-weight: bold; + + + + + + diff --git a/src/gui/src/SettingsDialog.cpp b/src/gui/src/SettingsDialog.cpp index 7cc5da2e3..87af94aa2 100644 --- a/src/gui/src/SettingsDialog.cpp +++ b/src/gui/src/SettingsDialog.cpp @@ -26,7 +26,6 @@ #include "MainWindow.h" #include "BonjourWindows.h" #include "Zeroconf.h" -#include "ScreenNameValidator.h" #include #include @@ -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(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())); diff --git a/src/gui/src/SettingsDialog.h b/src/gui/src/SettingsDialog.h index 7345d546a..7c8f4fc4b 100644 --- a/src/gui/src/SettingsDialog.h +++ b/src/gui/src/SettingsDialog.h @@ -20,8 +20,10 @@ #define SETTINGSDIALOG_H +#include #include #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 m_ScreenNameValidator; /// @brief Stores settings scope at start of settings dialog /// This is neccessary to restore state if user changes diff --git a/src/gui/src/SettingsDialogBase.ui b/src/gui/src/SettingsDialogBase.ui index 5bc8889df..898bc27db 100644 --- a/src/gui/src/SettingsDialogBase.ui +++ b/src/gui/src/SettingsDialogBase.ui @@ -92,7 +92,7 @@ true - 15 + 255 diff --git a/src/gui/src/SetupWizard.cpp b/src/gui/src/SetupWizard.cpp index 640c023bf..5c9187ee3 100644 --- a/src/gui/src/SetupWizard.cpp +++ b/src/gui/src/SetupWizard.cpp @@ -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(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())); diff --git a/src/gui/src/SetupWizard.h b/src/gui/src/SetupWizard.h index 78a403a51..17a2c2c9f 100644 --- a/src/gui/src/SetupWizard.h +++ b/src/gui/src/SetupWizard.h @@ -16,9 +16,10 @@ */ #pragma once - +#include #include "ui_SetupWizardBase.h" #include +#include "validators/ScreenNameValidator.h" class MainWindow; @@ -35,6 +36,7 @@ protected: private: MainWindow& m_MainWindow; + std::unique_ptr m_ScreenNameValidator; private slots: void onNameChanged(); diff --git a/src/gui/src/validators/AliasValidator.cpp b/src/gui/src/validators/AliasValidator.cpp new file mode 100644 index 000000000..fdf122f3f --- /dev/null +++ b/src/gui/src/validators/AliasValidator.cpp @@ -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 . + */ +#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("Remove spaces")); + addValidator(std::make_unique("Remove unsupported characters", QRegExp("[a-z0-9\\._-]{,255}", Qt::CaseInsensitive))); +} + +} diff --git a/src/gui/src/validators/AliasValidator.h b/src/gui/src/validators/AliasValidator.h new file mode 100644 index 000000000..f3cc68c03 --- /dev/null +++ b/src/gui/src/validators/AliasValidator.h @@ -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 . + */ +#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 diff --git a/src/gui/src/validators/EmptyStringValidator.cpp b/src/gui/src/validators/EmptyStringValidator.cpp new file mode 100644 index 000000000..a695aa197 --- /dev/null +++ b/src/gui/src/validators/EmptyStringValidator.cpp @@ -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 . + */ +#include "EmptyStringValidator.h" + +namespace validators +{ + +EmptyStringValidator::EmptyStringValidator(const QString& message) : + IStringValidator(message) +{ + +} + +bool EmptyStringValidator::validate(const QString& input) const +{ + return !input.isEmpty(); +} + +} diff --git a/src/gui/src/validators/EmptyStringValidator.h b/src/gui/src/validators/EmptyStringValidator.h new file mode 100644 index 000000000..e3b0077cd --- /dev/null +++ b/src/gui/src/validators/EmptyStringValidator.h @@ -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 . + */ +#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 diff --git a/src/gui/src/validators/IStringValidator.cpp b/src/gui/src/validators/IStringValidator.cpp new file mode 100644 index 000000000..7fb26511d --- /dev/null +++ b/src/gui/src/validators/IStringValidator.cpp @@ -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 . + */ +#include "EmptyStringValidator.h" + +namespace validators +{ + +IStringValidator::IStringValidator(const QString& message) : + m_Message(message) +{ + +} + +const QString& IStringValidator::getMessage() const +{ + return m_Message; +} + +} diff --git a/src/gui/src/validators/IStringValidator.h b/src/gui/src/validators/IStringValidator.h new file mode 100644 index 000000000..dfd9b4e95 --- /dev/null +++ b/src/gui/src/validators/IStringValidator.h @@ -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 . + */ +#ifndef IVALIDATOR_H +#define IVALIDATOR_H + +#include + +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 diff --git a/src/gui/src/validators/LineEditValidator.cpp b/src/gui/src/validators/LineEditValidator.cpp new file mode 100644 index 000000000..ef8140771 --- /dev/null +++ b/src/gui/src/validators/LineEditValidator.cpp @@ -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 . + */ +#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 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(); + } + } +} + +} diff --git a/src/gui/src/ScreenNameValidator.h b/src/gui/src/validators/LineEditValidator.h similarity index 64% rename from src/gui/src/ScreenNameValidator.h rename to src/gui/src/validators/LineEditValidator.h index 6bf45abfe..2d9a5b15c 100644 --- a/src/gui/src/ScreenNameValidator.h +++ b/src/gui/src/validators/LineEditValidator.h @@ -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 . */ -#ifndef SCREENNAMEVALIDATOR_H -#define SCREENNAMEVALIDATOR_H +#ifndef LINEEDITVALIDATOR_H +#define LINEEDITVALIDATOR_H -#include -#include -#include #include #include -#include "Screen.h" -class INameValidator +#include +#include +#include + +#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 validator); private: QLabel* m_pErrors = nullptr; QLineEdit* m_pControl = nullptr; - std::vector> m_Validators; + std::vector> m_Validators; void showError(const QString& message) const; + }; -#endif // SCREENNAMEVALIDATOR_H +} + +#endif // LINEEDITVALIDATOR_H diff --git a/src/gui/src/validators/RegExpValidator.cpp b/src/gui/src/validators/RegExpValidator.cpp new file mode 100644 index 000000000..53bd66db7 --- /dev/null +++ b/src/gui/src/validators/RegExpValidator.cpp @@ -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 . + */ +#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)); +} + +} + diff --git a/src/gui/src/validators/RegExpValidator.h b/src/gui/src/validators/RegExpValidator.h new file mode 100644 index 000000000..bcaeabead --- /dev/null +++ b/src/gui/src/validators/RegExpValidator.h @@ -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 . + */ +#ifndef REGEXPVALIDATOR_H +#define REGEXPVALIDATOR_H + +#include +#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 diff --git a/src/gui/src/validators/ScreenDuplicationsValidator.cpp b/src/gui/src/validators/ScreenDuplicationsValidator.cpp new file mode 100644 index 000000000..8a6d245f7 --- /dev/null +++ b/src/gui/src/validators/ScreenDuplicationsValidator.cpp @@ -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 . + */ +#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; +} + +} diff --git a/src/gui/src/validators/ScreenDuplicationsValidator.h b/src/gui/src/validators/ScreenDuplicationsValidator.h new file mode 100644 index 000000000..48deec244 --- /dev/null +++ b/src/gui/src/validators/ScreenDuplicationsValidator.h @@ -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 . + */ +#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 diff --git a/src/gui/src/validators/ScreenNameValidator.cpp b/src/gui/src/validators/ScreenNameValidator.cpp new file mode 100644 index 000000000..5df62b883 --- /dev/null +++ b/src/gui/src/validators/ScreenNameValidator.cpp @@ -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 . + */ +#include + +#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("Computer name can't be empty")); + addValidator(std::make_unique("Remove spaces")); + addValidator(std::make_unique("Remove unsupported characters", QRegExp("[a-z0-9\\._-]{,255}", Qt::CaseInsensitive))); + addValidator(std::make_unique("A computer with this name already exists", parent ? parent->text() : "", pScreens)); +} + +} diff --git a/src/gui/src/validators/ScreenNameValidator.h b/src/gui/src/validators/ScreenNameValidator.h new file mode 100644 index 000000000..bebe1284a --- /dev/null +++ b/src/gui/src/validators/ScreenNameValidator.h @@ -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 . + */ +#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 diff --git a/src/gui/src/validators/SpacesValidator.cpp b/src/gui/src/validators/SpacesValidator.cpp new file mode 100644 index 000000000..a58663510 --- /dev/null +++ b/src/gui/src/validators/SpacesValidator.cpp @@ -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 . + */ +#include "SpacesValidator.h" + +namespace validators +{ + +SpacesValidator::SpacesValidator(const QString& message) : + IStringValidator(message) +{ + +} + +bool SpacesValidator::validate(const QString& input) const +{ + return !input.contains(' '); +} + +} diff --git a/src/gui/src/validators/SpacesValidator.h b/src/gui/src/validators/SpacesValidator.h new file mode 100644 index 000000000..df51caee4 --- /dev/null +++ b/src/gui/src/validators/SpacesValidator.h @@ -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 . + */ +#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