From 9f479b8f76238a03bce5d13aee14efd34e659c6e Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Sun, 30 Oct 2022 20:34:23 +0100 Subject: Clean up and modernize code - static "new-style" signal->slot connections - Fix a lot of things Clang-Tidy complained about - Move includes to .cpp files and use forward decls in .h - Don't use and , but specific includes instead --- src/client/toolbar/toolbar.cpp | 67 ++++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 28 deletions(-) (limited to 'src/client/toolbar/toolbar.cpp') diff --git a/src/client/toolbar/toolbar.cpp b/src/client/toolbar/toolbar.cpp index 880e24f..bd5d689 100644 --- a/src/client/toolbar/toolbar.cpp +++ b/src/client/toolbar/toolbar.cpp @@ -2,7 +2,6 @@ #include "../net/serverconnection.h" #include "../vnc/vncwindow.h" #include "../vnc/vncserver.h" -#include "../util/util.h" #include "../informationdialog/informationdialog.h" #include "../clientapp/clientapp.h" #include "../addons/addons.h" @@ -10,9 +9,11 @@ #include "toolbar.h" #include "ui_toolbar.h" -#include #include -#include +#include +#include +#include +#include /** * @brief @@ -24,8 +25,13 @@ * another widget, this widget becomes a child window inside parent. The new * widget is deleted when its parent is deleted. */ -Toolbar::Toolbar(const QByteArray sessionName, QWidget *parent) - : QWidget(parent), _showTimer(this), _hideTimer(this), _hideCountdown(10), _blinkTimer(this), _beWatchedEye(":eye") +Toolbar::Toolbar(const QByteArray& sessionName, QWidget *parent) + : QWidget(parent) + , _showTimer(this) + , _hideTimer(this) + , _hideCountdown(10) + , _blinkTimer(this) + , _beWatchedEye(":eye") { qDebug() << "sessionName - constructor"; init(); @@ -44,7 +50,12 @@ Toolbar::Toolbar(const QByteArray sessionName, QWidget *parent) * widget is deleted when its parent is deleted. */ Toolbar::Toolbar(const bool autoConnect, QWidget *parent) - : QWidget(parent), _showTimer(this), _hideTimer(this), _hideCountdown(10), _blinkTimer(this), _beWatchedEye(":eye") + : QWidget(parent) + , _showTimer(this) + , _hideTimer(this) + , _hideCountdown(10) + , _blinkTimer(this) + , _beWatchedEye(":eye") { qDebug() << "auto - constructor!"; init(); @@ -100,9 +111,9 @@ void Toolbar::init() /* Create the connect window */ clientApp->connectWindow()->setAvailableRooms(myRooms()); // Connect the signals - connect(clientApp->connectWindow(), SIGNAL(disconnect()), this, SLOT(onDoDisconnect())); - connect(clientApp->connectWindow(), SIGNAL(connected(ServerConnection*)), this, SLOT(onConnected(ServerConnection*))); - connect(_ui->btnAttention, SIGNAL(toggled(bool)), this, SLOT(onBtnAttention())); + connect(clientApp->connectWindow(), &ConnectWindow::disconnect, this, &Toolbar::onDoDisconnect); + connect(clientApp->connectWindow(), &ConnectWindow::connected, this, &Toolbar::onConnected); + connect(_ui->btnAttention, &QToolButton::toggled, this, &Toolbar::onBtnAttention); /* Setup menu */ initButtonsAndMenus(); @@ -112,7 +123,7 @@ void Toolbar::init() _ui->btnAttention->setMaximumWidth(30); /* Connect the signals from vnc server */ - connect(VncServer::instance(), SIGNAL(started(int, QString&, QString&)), this, SLOT(onVncServerIsRunning(int))); + connect(VncServer::instance(), &VncServer::started, this, &Toolbar::onVncServerIsRunning); /* React to screen geometry change */ connect(QGuiApplication::primaryScreen(), &QScreen::availableGeometryChanged, this, &Toolbar::setToolbarPosition); @@ -124,10 +135,10 @@ void Toolbar::init() /* Setup show & hide timer */ _showTimer.setInterval(500); _showTimer.setSingleShot(true); - connect(&_showTimer, SIGNAL(timeout()), this, SLOT(showBar())); + connect(&_showTimer, &QTimer::timeout, this, &Toolbar::showBar); _hideTimer.setInterval(50); _hideTimer.setSingleShot(false); - connect(&_hideTimer, SIGNAL(timeout()), this, SLOT(hideBar())); + connect(&_hideTimer, &QTimer::timeout, this, &Toolbar::hideBar); setVisible(true); raise(); @@ -135,11 +146,11 @@ void Toolbar::init() /* Setup blink timer */ _blinkTimer.setInterval(500); - connect(&_blinkTimer, SIGNAL(timeout()), this, SLOT(cameraBlink())); + connect(&_blinkTimer, &QTimer::timeout, this, &Toolbar::cameraBlink); } static QFrame* makeVerticalLine() { - QFrame *f = new QFrame(); + auto *f = new QFrame(); f->setFrameShape(QFrame::HLine); f->setFrameShadow(QFrame::Sunken); return f; @@ -191,12 +202,12 @@ void Toolbar::initButtonsAndMenus() _acnQuit->setVisible(allow); // Connect the signals - connect(_menu, SIGNAL(aboutToHide()), this, SLOT(delayedHideBar())); - connect(_acnConnect, SIGNAL(triggered()), clientApp->connectWindow(), SLOT(doShow())); - connect(_acnDisconnect, SIGNAL(triggered()), clientApp->connectWindow(), SLOT(DoDisconnect())); - connect(_acnInformation, SIGNAL(triggered()), this, SLOT(showInformationDialog())); - connect(_acnAbout, SIGNAL(triggered()), this, SLOT(showAboutDialog())); - connect(_acnQuit, SIGNAL(triggered()), this, SLOT(exit())); + connect(_menu, &QMenu::aboutToHide, this, &Toolbar::delayedHideBar); + connect(_acnConnect, &QAction::triggered, clientApp->connectWindow(), &ConnectWindow::doShow); + connect(_acnDisconnect, &QAction::triggered, clientApp->connectWindow(), &ConnectWindow::DoDisconnect); + connect(_acnInformation, &QAction::triggered, this, &Toolbar::showInformationDialog); + connect(_acnAbout, &QAction::triggered, this, &Toolbar::showAboutDialog); + connect(_acnQuit, &QAction::triggered, this, &Toolbar::exit); // Delay until bar is visible QTimer::singleShot(10, [=]() { @@ -363,7 +374,7 @@ void Toolbar::onVncServerIsRunning(int port) void Toolbar::onDisconnected(ServerConnection* connection) { if (connection != nullptr) { - disconnect(connection, SIGNAL(disconnected(ServerConnection*)), this, SLOT(onDisconnected(ServerConnection*))); + disconnect(connection, &ServerConnection::disconnected, this, &Toolbar::onDisconnected); } _ui->lblStatus->setStyleSheet("color:red"); _ui->lblStatus->setText(tr("Offline")); @@ -394,12 +405,12 @@ void Toolbar::onConnected(ServerConnection* connection) _ui->btnAttention->setVisible(true); AddonManager::connectEvent(connection->isLocalConnection(), connection->getPeerAdress()); // - connect(connection, SIGNAL(disconnected(ServerConnection*)), this, SLOT(onDisconnected(ServerConnection*))); - connect(connection, SIGNAL(openVnc(const QString&, int, const QString&, bool, bool, const QString&, const int, const QByteArray&)), - _vnc, SLOT(open(const QString&, int, const QString&, bool, bool, const QString&, const int, const QByteArray&))); - connect(connection, SIGNAL(closeVnc()), _vnc, SLOT(close())); - connect(connection, SIGNAL(attentionChanged(const bool)), this, SLOT(onServerAttentionChanged(const bool))); - connect(_vnc, SIGNAL(running(const bool, const int)), connection, SLOT(onVncViewerStartStop(const bool, const int))); + connect(connection, &ServerConnection::disconnected, this, &Toolbar::onDisconnected); + connect(connection, &ServerConnection::openVnc, + _vnc, &VncWindow::open); + connect(connection, &ServerConnection::closeVnc, _vnc, &VncWindow::close); + connect(connection, &ServerConnection::attentionChanged, this, &Toolbar::onServerAttentionChanged); + connect(_vnc, &VncWindow::running, connection, &ServerConnection::onVncViewerStartStop); } /** @@ -489,7 +500,7 @@ void Toolbar::showAboutDialog() void Toolbar::showInformationDialog() { - InformationDialog* d = new InformationDialog(); + auto* d = new InformationDialog(); d->exec(); d->deleteLater(); } -- cgit v1.2.3-55-g7522