diff --git a/src/apps/deskflow-gui/MainWindow.cpp b/src/apps/deskflow-gui/MainWindow.cpp index 24384e745..4abca9ecf 100644 --- a/src/apps/deskflow-gui/MainWindow.cpp +++ b/src/apps/deskflow-gui/MainWindow.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -239,6 +240,9 @@ void MainWindow::setupControls() if (m_appConfig.clientGroupChecked() || m_appConfig.serverGroupChecked()) updateModeControls(m_appConfig.serverGroupChecked()); + ui->lineEditName->setValidator(new QRegularExpressionValidator(m_nameRegEx, this)); + ui->lineEditName->setVisible(false); + #if defined(Q_OS_MAC) ui->rbModeServer->setAttribute(Qt::WA_MacShowFocusRect, 0); @@ -344,6 +348,10 @@ void MainWindow::connectSlots() connect(m_btnUpdate, &QPushButton::clicked, this, &MainWindow::openGetNewVersionUrl); connect(m_guiDupeChecker, &QLocalServer::newConnection, this, &MainWindow::showAndActivate); + + connect(ui->btnEditName, &QPushButton::clicked, this, &MainWindow::showHostNameEditor); + + connect(ui->lineEditName, &QLineEdit::editingFinished, this, &MainWindow::setHostName); } void MainWindow::toggleLogVisible(bool visible) @@ -1047,9 +1055,8 @@ void MainWindow::secureSocket(bool secureSocket) void MainWindow::updateScreenName() { - ui->lblComputerName->setText(tr("This computer's name: %1 " - R"((change))") - .arg(m_appConfig.screenName(), kColorSecondary)); + ui->lblComputerName->setText(m_appConfig.screenName()); + ui->lineEditName->setText(m_appConfig.screenName()); m_serverConfig.updateServerName(); } @@ -1065,6 +1072,48 @@ void MainWindow::showAndActivate() m_actionMinimize->setVisible(true); } +void MainWindow::showHostNameEditor() +{ + ui->lineEditName->show(); + ui->lblComputerName->hide(); + ui->btnEditName->hide(); + ui->lineEditName->setFocus(); +} + +void MainWindow::setHostName() +{ + ui->lineEditName->hide(); + ui->lblComputerName->show(); + ui->btnEditName->show(); + + QString text = ui->lineEditName->text(); + bool existingScreen = serverConfig().screenExists(text) && text != m_appConfig.screenName(); + + if (!ui->lineEditName->hasAcceptableInput() || text.isEmpty() || existingScreen) { + blockSignals(true); + ui->lineEditName->setText(m_appConfig.screenName()); + blockSignals(false); + + const auto title = tr("Invalid Screen Name"); + QString body; + if (existingScreen) { + body = tr("Screen name already exists"); + } else { + body = tr("The name you have chosen is invalid.\n\n" + "Valid names:\n" + "• Use letters and numbers\n" + "• May also use _ or -\n" + "• Are between 1 and 255 characters"); + } + QMessageBox::information(this, title, body); + return; + } + + ui->lblComputerName->setText(ui->lineEditName->text()); + m_appConfig.setScreenName(ui->lineEditName->text()); + applyConfig(); +} + QString MainWindow::getTlsPath() { CoreTool coreTool; diff --git a/src/apps/deskflow-gui/MainWindow.h b/src/apps/deskflow-gui/MainWindow.h index 2d66bbf21..4de4ef55d 100644 --- a/src/apps/deskflow-gui/MainWindow.h +++ b/src/apps/deskflow-gui/MainWindow.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -166,6 +167,8 @@ private: void showFirstConnectedMessage(); void updateStatus(); void showAndActivate(); + void showHostNameEditor(); + void setHostName(); QString getTlsPath(); @@ -203,6 +206,7 @@ private: QSystemTrayIcon *m_trayIcon = nullptr; QLocalServer *m_guiDupeChecker = nullptr; inline static const auto m_guiSocketName = QStringLiteral("deskflow-gui"); + inline static const auto m_nameRegEx = QRegularExpression(QStringLiteral("^[\\w\\-_\\.]{0,255}$")); QLabel *m_lblSecurityStatus = nullptr; QLabel *m_lblStatus = nullptr; diff --git a/src/apps/deskflow-gui/MainWindow.ui b/src/apps/deskflow-gui/MainWindow.ui index 93e435e4b..3477b103e 100644 --- a/src/apps/deskflow-gui/MainWindow.ui +++ b/src/apps/deskflow-gui/MainWindow.ui @@ -25,37 +25,120 @@ 10 - - - QLayout::SizeConstraint::SetMinAndMaxSize + + + + 0 + 28 + - - - - - 0 - 0 - - - - This computer's name: - - - - - - - Qt::Orientation::Horizontal - - - - 20 - 20 - - - - - + + + 16777215 + 28 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + This computer's name: + + + + + + + + 0 + 0 + + + + lblName + + + + + + + + 0 + 0 + + + + <html><head/><body><p>Name can't have have spaces or special characters</p><p>Use Enter to save the name change.</p></body></html> + + + 255 + + + false + + + false + + + + + + + + 0 + 0 + + + + Edit Computer Name + + + + + + + 16 + 16 + + + + true + + + + + + + Qt::Orientation::Horizontal + + + + 40 + 20 + + + + + + diff --git a/src/apps/deskflow-gui/dialogs/SettingsDialog.cpp b/src/apps/deskflow-gui/dialogs/SettingsDialog.cpp index 6167eeb1e..bbcec311d 100644 --- a/src/apps/deskflow-gui/dialogs/SettingsDialog.cpp +++ b/src/apps/deskflow-gui/dialogs/SettingsDialog.cpp @@ -55,11 +55,6 @@ SettingsDialog::SettingsDialog( m_wasOriginallySystemScope = m_appConfig.isActiveScopeSystem(); updateControls(); - m_pScreenNameError = new validators::ValidationError(this); - ui->m_pLineEditScreenName->setValidator( - new validators::ScreenNameValidator(ui->m_pLineEditScreenName, m_pScreenNameError, &serverConfig.screens()) - ); - connect(ui->m_pCheckBoxEnableTls, &QCheckBox::toggled, this, &SettingsDialog::updateTlsControlsEnabled); connect( @@ -167,13 +162,7 @@ void SettingsDialog::showReadOnlyMessage() void SettingsDialog::accept() { - if (!ui->m_pLineEditScreenName->hasAcceptableInput()) { - QMessageBox::warning(this, tr("Invalid screen name"), m_pScreenNameError->message()); - return; - } - m_appConfig.setLoadFromSystemScope(ui->m_pRadioSystemScope->isChecked()); - m_appConfig.setScreenName(ui->m_pLineEditScreenName->text()); m_appConfig.setPort(ui->m_pSpinBoxPort->value()); m_appConfig.setNetworkInterface(ui->m_pLineEditInterface->text()); m_appConfig.setLogLevel(ui->m_pComboLogLevel->currentIndex()); @@ -209,7 +198,6 @@ void SettingsDialog::reject() void SettingsDialog::loadFromConfig() { - ui->m_pLineEditScreenName->setText(m_appConfig.screenName()); ui->m_pSpinBoxPort->setValue(m_appConfig.port()); ui->m_pLineEditInterface->setText(m_appConfig.networkInterface()); ui->m_pComboLogLevel->setCurrentIndex(m_appConfig.logLevel()); @@ -318,7 +306,6 @@ void SettingsDialog::updateControls() const bool serviceChecked = ui->m_pCheckBoxServiceEnabled->isChecked(); const bool logToFile = ui->m_pCheckBoxLogToFile->isChecked(); - ui->m_pLineEditScreenName->setEnabled(writable); ui->m_pSpinBoxPort->setEnabled(writable); ui->m_pLineEditInterface->setEnabled(writable); ui->m_pComboLogLevel->setEnabled(writable); diff --git a/src/apps/deskflow-gui/dialogs/SettingsDialog.h b/src/apps/deskflow-gui/dialogs/SettingsDialog.h index 7a655c739..a7874fd90 100644 --- a/src/apps/deskflow-gui/dialogs/SettingsDialog.h +++ b/src/apps/deskflow-gui/dialogs/SettingsDialog.h @@ -65,8 +65,6 @@ private: /// @brief Enables controls when they should be. void updateControls(); - validators::ValidationError *m_pScreenNameError; - /// @brief Stores settings scope at start of settings dialog /// This is necessary to restore state if user changes /// the scope and doesn't save changes diff --git a/src/apps/deskflow-gui/dialogs/SettingsDialog.ui b/src/apps/deskflow-gui/dialogs/SettingsDialog.ui index fa53dd0b7..632e4d807 100644 --- a/src/apps/deskflow-gui/dialogs/SettingsDialog.ui +++ b/src/apps/deskflow-gui/dialogs/SettingsDialog.ui @@ -54,55 +54,6 @@ Basics - - - - - - - 0 - 0 - - - - - 75 - 0 - - - - Computer name - - - - - - - Qt::Orientation::Horizontal - - - QSizePolicy::Policy::Maximum - - - - 20 - 20 - - - - - - - - true - - - 255 - - - - - @@ -772,7 +723,6 @@ - m_pLineEditScreenName m_pSpinBoxPort m_pLineEditInterface m_pCheckBoxEnableTls diff --git a/src/apps/res/deskflow.qrc b/src/apps/res/deskflow.qrc index 534207e10..e9d94e664 100644 --- a/src/apps/res/deskflow.qrc +++ b/src/apps/res/deskflow.qrc @@ -2,6 +2,7 @@ icons/deskflow-dark/actions/16/configure.svg icons/deskflow-dark/actions/16/edit-copy.svg + icons/deskflow-dark/actions/16/document-edit.svg icons/deskflow-dark/actions/16/document-open.svg icons/deskflow-dark/actions/16/document-save-as.svg icons/deskflow-dark/actions/16/help-about.svg @@ -11,6 +12,7 @@ icons/deskflow-dark/actions/16/view-refresh.svg icons/deskflow-dark/actions/22/configure.svg icons/deskflow-dark/actions/22/edit-copy.svg + icons/deskflow-dark/actions/22/document-edit.svg icons/deskflow-dark/actions/22/document-open.svg icons/deskflow-dark/actions/22/document-save-as.svg icons/deskflow-dark/actions/22/fingerprint.svg @@ -21,6 +23,7 @@ icons/deskflow-dark/actions/22/view-refresh.svg icons/deskflow-dark/actions/24/configure.svg icons/deskflow-dark/actions/24/edit-copy.svg + icons/deskflow-dark/actions/24/document-edit.svg icons/deskflow-dark/actions/24/document-open.svg icons/deskflow-dark/actions/24/document-save-as.svg icons/deskflow-dark/actions/24/edit-clear-all.svg @@ -56,6 +59,7 @@ icons/deskflow-light/actions/16/configure.svg icons/deskflow-light/actions/16/edit-clear-all.svg icons/deskflow-light/actions/16/edit-copy.svg + icons/deskflow-light/actions/16/document-edit.svg icons/deskflow-light/actions/16/document-open.svg icons/deskflow-light/actions/16/document-save-as.svg icons/deskflow-light/actions/16/help-about.svg @@ -66,6 +70,7 @@ icons/deskflow-light/actions/22/configure.svg icons/deskflow-light/actions/22/edit-clear-all.svg icons/deskflow-light/actions/22/edit-copy.svg + icons/deskflow-light/actions/22/document-edit.svg icons/deskflow-light/actions/22/document-open.svg icons/deskflow-light/actions/22/document-save-as.svg icons/deskflow-light/actions/22/fingerprint.svg @@ -78,6 +83,7 @@ icons/deskflow-light/actions/24/edit-clear-all.svg icons/deskflow-light/actions/24/edit-copy.svg icons/deskflow-light/actions/24/fingerprint.svg + icons/deskflow-light/actions/24/document-edit.svg icons/deskflow-light/actions/24/document-open.svg icons/deskflow-light/actions/24/document-save-as.svg icons/deskflow-light/actions/24/help-about.svg