refactor: use new-style qt connections

This commit is contained in:
Evgenii Alekseev 2024-03-28 02:40:17 +02:00
parent d71f85eaad
commit f27050afbc
14 changed files with 70 additions and 73 deletions

View File

@ -37,13 +37,13 @@ AWAbstractPairConfig::AWAbstractPairConfig(QWidget *_parent, const bool _hasEdit
ui->setupUi(this);
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &AWAbstractPairConfig::accept);
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &AWAbstractPairConfig::reject);
// edit feature
if (m_hasEdit) {
m_editButton = ui->buttonBox->addButton(i18n("Edit"), QDialogButtonBox::ActionRole);
connect(m_editButton, SIGNAL(clicked(bool)), this, SLOT(edit()));
connect(m_editButton, &QPushButton::clicked, [this]() { return edit(); });
}
}
@ -84,14 +84,14 @@ void AWAbstractPairConfig::edit()
void AWAbstractPairConfig::updateUi()
{
QPair<QString, QString> current = dynamic_cast<AWAbstractSelector *>(sender())->current();
int index = m_selectors.indexOf(dynamic_cast<AWAbstractSelector *>(sender()));
auto current = dynamic_cast<AWAbstractSelector *>(sender())->current();
auto index = m_selectors.indexOf(dynamic_cast<AWAbstractSelector *>(sender()));
if ((current.first.isEmpty()) && (current.second.isEmpty())) {
// remove current selector if it is empty and does not last
if (sender() == m_selectors.last())
return;
AWAbstractSelector *selector = m_selectors.takeAt(index);
auto *selector = m_selectors.takeAt(index);
ui->verticalLayout->removeWidget(selector);
selector->deleteLater();
} else {
@ -112,7 +112,7 @@ void AWAbstractPairConfig::addSelector(const QStringList &_keys, const QStringLi
auto *selector = new AWAbstractSelector(ui->scrollAreaWidgetContents, m_editable);
selector->init(_keys, _values, _current);
ui->verticalLayout->insertWidget(ui->verticalLayout->count() - 1, selector);
connect(selector, SIGNAL(selectionChanged()), this, SLOT(updateUi()));
connect(selector, &AWAbstractSelector::selectionChanged, this, &AWAbstractPairConfig::updateUi);
m_selectors.append(selector);
}
@ -120,7 +120,7 @@ void AWAbstractPairConfig::addSelector(const QStringList &_keys, const QStringLi
void AWAbstractPairConfig::clearSelectors()
{
for (auto &selector : m_selectors) {
disconnect(selector, SIGNAL(selectionChanged()), this, SLOT(updateUi()));
disconnect(selector, &AWAbstractSelector::selectionChanged, this, &AWAbstractPairConfig::updateUi);
ui->verticalLayout->removeWidget(selector);
selector->deleteLater();
}
@ -164,7 +164,7 @@ QPair<QStringList, QStringList> AWAbstractPairConfig::initKeys() const
right.append(m_helper->rightKeys().isEmpty() ? m_keys : m_helper->rightKeys());
right.sort();
return QPair<QStringList, QStringList>(left, right);
return {left, right};
}
@ -175,7 +175,7 @@ void AWAbstractPairConfig::updateDialog()
auto keys = initKeys();
for (auto &key : m_helper->keys())
addSelector(keys.first, keys.second, QPair<QString, QString>(key, m_helper->pairs()[key]));
addSelector(keys.first, keys.second, QPair<QString, QString>(key, pairs[key]));
// empty one
addSelector(keys.first, keys.second, QPair<QString, QString>());
}

View File

@ -44,7 +44,7 @@ AWBugReporter::~AWBugReporter()
void AWBugReporter::doConnect()
{
// additional method for testing needs
connect(this, SIGNAL(replyReceived(const int, const QString &)), this, SLOT(showInformation(int, const QString &)));
connect(this, &AWBugReporter::replyReceived, this, &AWBugReporter::showInformation);
}
@ -72,25 +72,25 @@ void AWBugReporter::sendBugReport(const QString &_title, const QString &_body)
qCDebug(LOG_AW) << "Send bug report with title" << _title << "and body" << _body;
auto *manager = new QNetworkAccessManager(nullptr);
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(issueReplyRecieved(QNetworkReply *)));
connect(manager, &QNetworkAccessManager::finished, this, &AWBugReporter::issueReplyReceived);
QNetworkRequest request = QNetworkRequest(QUrl(BUGTRACKER_API));
auto request = QNetworkRequest(QUrl(BUGTRACKER_API));
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
// generate payload
QVariantMap payload;
payload["title"] = _title;
payload["body"] = _body;
payload["labels"] = QStringList() << "from application";
payload["labels"] = QStringList({"from application"});
// convert to QByteArray to send request
QByteArray data = QJsonDocument::fromVariant(payload).toJson(QJsonDocument::Compact);
auto data = QJsonDocument::fromVariant(payload).toJson(QJsonDocument::Compact);
qCInfo(LOG_AW) << "Send request with _body" << data.data() << "and size" << data.size();
manager->post(request, data);
}
void AWBugReporter::issueReplyRecieved(QNetworkReply *_reply)
void AWBugReporter::issueReplyReceived(QNetworkReply *_reply)
{
if (_reply->error() != QNetworkReply::NoError) {
qCWarning(LOG_AW) << "An error occurs" << _reply->error() << "with message" << _reply->errorString();
@ -98,7 +98,7 @@ void AWBugReporter::issueReplyRecieved(QNetworkReply *_reply)
}
QJsonParseError error{};
QJsonDocument jsonDoc = QJsonDocument::fromJson(_reply->readAll(), &error);
auto jsonDoc = QJsonDocument::fromJson(_reply->readAll(), &error);
if (error.error != QJsonParseError::NoError) {
qCWarning(LOG_AW) << "Parse error" << error.errorString();
return emit(replyReceived(0, ""));
@ -106,9 +106,9 @@ void AWBugReporter::issueReplyRecieved(QNetworkReply *_reply)
_reply->deleteLater();
// convert to map
QVariantMap response = jsonDoc.toVariant().toMap();
QString url = response["html_url"].toString();
int number = response["number"].toInt();
auto response = jsonDoc.toVariant().toMap();
auto url = response["html_url"].toString();
auto number = response["number"].toInt();
return emit(replyReceived(number, url));
}
@ -135,7 +135,7 @@ void AWBugReporter::showInformation(const int _number, const QString &_url)
void AWBugReporter::userReplyOnBugReport(QAbstractButton *_button)
{
QMessageBox::ButtonRole ret = dynamic_cast<QMessageBox *>(sender())->buttonRole(_button);
auto ret = dynamic_cast<QMessageBox *>(sender())->buttonRole(_button);
qCInfo(LOG_AW) << "User select" << ret;
switch (ret) {

View File

@ -41,7 +41,7 @@ signals:
void replyReceived(int _number, const QString &_url);
private slots:
void issueReplyRecieved(QNetworkReply *_reply);
void issueReplyReceived(QNetworkReply *_reply);
void showInformation(int _number, const QString &_url);
void userReplyOnBugReport(QAbstractButton *_button);

View File

@ -127,7 +127,7 @@ void AWTelemetryHandler::uploadTelemetry(const QString &_group, const QString &_
}
auto *manager = new QNetworkAccessManager(nullptr);
connect(manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(telemetryReplyRecieved(QNetworkReply *)));
connect(manager, &QNetworkAccessManager::finished, this, &AWTelemetryHandler::telemetryReplyReceived);
QUrl url(REMOTE_TELEMETRY_URL);
QNetworkRequest request(url);
@ -140,14 +140,14 @@ void AWTelemetryHandler::uploadTelemetry(const QString &_group, const QString &_
payload["metadata"] = _value;
payload["type"] = _group;
// convert to QByteArray to send request
QByteArray data = QJsonDocument::fromVariant(payload).toJson(QJsonDocument::Compact);
auto data = QJsonDocument::fromVariant(payload).toJson(QJsonDocument::Compact);
qCInfo(LOG_AW) << "Send request with body" << data.data() << "and size" << data.size();
manager->post(request, data);
}
void AWTelemetryHandler::telemetryReplyRecieved(QNetworkReply *_reply)
void AWTelemetryHandler::telemetryReplyReceived(QNetworkReply *_reply)
{
if (_reply->error() != QNetworkReply::NoError) {
qCWarning(LOG_AW) << "An error occurs" << _reply->error() << "with message" << _reply->errorString();
@ -155,7 +155,7 @@ void AWTelemetryHandler::telemetryReplyRecieved(QNetworkReply *_reply)
}
QJsonParseError error{};
QJsonDocument jsonDoc = QJsonDocument::fromJson(_reply->readAll(), &error);
auto jsonDoc = QJsonDocument::fromJson(_reply->readAll(), &error);
if (error.error != QJsonParseError::NoError) {
qCWarning(LOG_AW) << "Parse error" << error.errorString();
return;
@ -163,8 +163,8 @@ void AWTelemetryHandler::telemetryReplyRecieved(QNetworkReply *_reply)
_reply->deleteLater();
// convert to map
QVariantMap response = jsonDoc.toVariant().toMap();
QString message = response["message"].toString();
auto response = jsonDoc.toVariant().toMap();
auto message = response["message"].toString();
qCInfo(LOG_AW) << "Server reply on telemetry" << message;
return emit(replyReceived(message));

View File

@ -43,7 +43,7 @@ signals:
void replyReceived(const QString &_message);
private slots:
void telemetryReplyRecieved(QNetworkReply *_reply);
void telemetryReplyReceived(QNetworkReply *_reply);
private:
static QString getKey(int _count);

View File

@ -54,7 +54,7 @@ void AWUpdateHelper::checkUpdates(const bool _showAnyway)
// request. In case of automatic check no message will be shown
auto *manager = new QNetworkAccessManager(nullptr);
connect(manager, &QNetworkAccessManager::finished,
[_showAnyway, this](QNetworkReply *reply) { return versionReplyRecieved(reply, _showAnyway); });
[_showAnyway, this](QNetworkReply *reply) { return versionReplyReceived(reply, _showAnyway); });
manager->get(QNetworkRequest(QUrl(VERSION_API)));
}
@ -63,7 +63,7 @@ void AWUpdateHelper::checkUpdates(const bool _showAnyway)
bool AWUpdateHelper::checkVersion()
{
QSettings settings(m_genericConfig, QSettings::IniFormat);
QVersionNumber version = QVersionNumber::fromString(settings.value("Version", QString(VERSION)).toString());
auto version = QVersionNumber::fromString(settings.value("Version", QString(VERSION)).toString());
// update version
settings.setValue("Version", QString(VERSION));
settings.sync();
@ -88,7 +88,7 @@ void AWUpdateHelper::showInfo(const QVersionNumber &_version)
{
qCDebug(LOG_AW) << "Version" << _version;
QString text = i18n("You are using the actual version %1", _version.toString());
auto text = i18n("You are using the actual version %1", _version.toString());
if (!QString(COMMIT_SHA).isEmpty())
text += QString(" (%1)").arg(QString(COMMIT_SHA));
return genMessageBox(i18n("No new version found"), text, QMessageBox::Ok)->open();
@ -112,7 +112,7 @@ void AWUpdateHelper::showUpdates(const QVersionNumber &_version)
void AWUpdateHelper::userReplyOnUpdates(QAbstractButton *_button)
{
QMessageBox::ButtonRole ret = dynamic_cast<QMessageBox *>(sender())->buttonRole(_button);
auto ret = dynamic_cast<QMessageBox *>(sender())->buttonRole(_button);
qCInfo(LOG_AW) << "User select" << ret;
switch (ret) {
@ -126,7 +126,7 @@ void AWUpdateHelper::userReplyOnUpdates(QAbstractButton *_button)
}
void AWUpdateHelper::versionReplyRecieved(QNetworkReply *_reply, const bool _showAnyway)
void AWUpdateHelper::versionReplyReceived(QNetworkReply *_reply, const bool _showAnyway)
{
qCDebug(LOG_AW) << "Show message anyway" << _showAnyway;
if (_reply->error() != QNetworkReply::NoError) {
@ -134,8 +134,8 @@ void AWUpdateHelper::versionReplyRecieved(QNetworkReply *_reply, const bool _sho
return;
}
QJsonParseError error = QJsonParseError();
QJsonDocument jsonDoc = QJsonDocument::fromJson(_reply->readAll(), &error);
auto error = QJsonParseError();
auto jsonDoc = QJsonDocument::fromJson(_reply->readAll(), &error);
if (error.error != QJsonParseError::NoError) {
qCWarning(LOG_AW) << "Parse error" << error.errorString();
return;
@ -143,13 +143,13 @@ void AWUpdateHelper::versionReplyRecieved(QNetworkReply *_reply, const bool _sho
_reply->deleteLater();
// convert to map
QVariantMap firstRelease = jsonDoc.toVariant().toList().first().toMap();
QString version = firstRelease["tag_name"].toString();
auto firstRelease = jsonDoc.toVariant().toList().first().toMap();
auto version = firstRelease["tag_name"].toString();
version.remove("V.");
m_foundVersion = QVersionNumber::fromString(version);
qCInfo(LOG_AW) << "Update found version to" << m_foundVersion;
QVersionNumber oldVersion = QVersionNumber::fromString(VERSION);
auto oldVersion = QVersionNumber::fromString(VERSION);
if (oldVersion < m_foundVersion)
return showUpdates(m_foundVersion);
else if (_showAnyway)

View File

@ -40,7 +40,7 @@ private slots:
static void showInfo(const QVersionNumber &_version);
void showUpdates(const QVersionNumber &_version);
void userReplyOnUpdates(QAbstractButton *_button);
void versionReplyRecieved(QNetworkReply *_reply, bool _showAnyway);
void versionReplyReceived(QNetworkReply *_reply, bool _showAnyway);
private:
static QMessageBox *genMessageBox(const QString &_title, const QString &_body,

View File

@ -198,7 +198,7 @@ void AbstractExtItem::setCron(const QString &_cron)
qCDebug(LOG_LIB) << "Cron string" << _cron;
// deinit module first
if (m_scheduler) {
disconnect(m_scheduler, SIGNAL(activated()), this, SIGNAL(requestDataUpdate()));
disconnect(m_scheduler, &QCronScheduler::activated, this, &AbstractExtItem::requestDataUpdate);
delete m_scheduler;
}
@ -209,7 +209,7 @@ void AbstractExtItem::setCron(const QString &_cron)
// init scheduler
m_scheduler = new QCronScheduler(this);
m_scheduler->parse(cron());
connect(m_scheduler, SIGNAL(activated()), this, SIGNAL(requestDataUpdate()));
connect(m_scheduler, &QCronScheduler::activated, this, &AbstractExtItem::requestDataUpdate);
}
@ -234,7 +234,7 @@ void AbstractExtItem::setName(const QString &_name)
void AbstractExtItem::setNumber(int _number)
{
qCDebug(LOG_LIB) << "Number" << _number;
bool generateNumber = (_number == -1);
auto generateNumber = (_number == -1);
if (generateNumber) {
_number = []() {
qCWarning(LOG_LIB) << "Number is empty, generate new one";
@ -267,7 +267,7 @@ void AbstractExtItem::deinitSocket()
m_socket->close();
QLocalServer::removeServer(socket());
disconnect(m_socket, SIGNAL(newConnection()), this, SLOT(newConnectionReceived()));
disconnect(m_socket, &QLocalServer::newConnection, this, &AbstractExtItem::newConnectionReceived);
delete m_socket;
}
@ -278,9 +278,9 @@ void AbstractExtItem::initSocket()
deinitSocket();
m_socket = new QLocalServer(this);
bool listening = m_socket->listen(socket());
auto listening = m_socket->listen(socket());
qCInfo(LOG_LIB) << "Server listening on" << socket() << listening;
connect(m_socket, SIGNAL(newConnection()), this, SLOT(newConnectionReceived()));
connect(m_socket, &QLocalServer::newConnection, this, &AbstractExtItem::newConnectionReceived);
}
@ -303,7 +303,7 @@ void AbstractExtItem::readConfiguration()
bool AbstractExtItem::tryDelete() const
{
bool status = QFile::remove(m_fileName);
auto status = QFile::remove(m_fileName);
qCInfo(LOG_LIB) << "Remove file" << m_fileName << status;
return status;

View File

@ -40,9 +40,8 @@ ExtNetworkRequest::ExtNetworkRequest(QObject *_parent, const QString &_filePath)
// HACK declare as child of nullptr to avoid crash with plasmawindowed
// in the destructor
m_manager = new QNetworkAccessManager(nullptr);
connect(m_manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(networkReplyReceived(QNetworkReply *)));
connect(this, SIGNAL(requestDataUpdate()), this, SLOT(sendRequest()));
connect(m_manager, &QNetworkAccessManager::finished, this, &ExtNetworkRequest::networkReplyReceived);
connect(this, &ExtNetworkRequest::requestDataUpdate, this, &ExtNetworkRequest::sendRequest);
}
@ -50,8 +49,8 @@ ExtNetworkRequest::~ExtNetworkRequest()
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
disconnect(m_manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(networkReplyReceived(QNetworkReply *)));
disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(sendRequest()));
disconnect(m_manager, &QNetworkAccessManager::finished, this, &ExtNetworkRequest::networkReplyReceived);
disconnect(this, &ExtNetworkRequest::requestDataUpdate, this, &ExtNetworkRequest::sendRequest);
m_manager->deleteLater();
}

View File

@ -40,10 +40,10 @@ ExtScript::ExtScript(QObject *_parent, const QString &_filePath)
m_values[tag("custom")] = "";
m_process = new QProcess(nullptr);
connect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(updateValue()));
connect(m_process, &QProcess::finished, [this]() { return updateValue(); });
m_process->waitForFinished(0);
connect(this, SIGNAL(requestDataUpdate()), this, SLOT(startProcess()));
connect(this, &ExtScript::requestDataUpdate, this, &ExtScript::startProcess);
}
@ -51,10 +51,9 @@ ExtScript::~ExtScript()
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
disconnect(m_process, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(updateValue()));
m_process->kill();
m_process->deleteLater();
disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(startProcess()));
disconnect(this, &ExtScript::requestDataUpdate, this, &ExtScript::startProcess);
}
@ -227,11 +226,11 @@ void ExtScript::readJsonFilters()
qCWarning(LOG_LIB) << "Could not open" << fileName;
return;
}
QString jsonText = jsonFile.readAll();
auto jsonText = jsonFile.readAll();
jsonFile.close();
QJsonParseError error{};
auto jsonDoc = QJsonDocument::fromJson(jsonText.toUtf8(), &error);
auto jsonDoc = QJsonDocument::fromJson(jsonText, &error);
if (error.error != QJsonParseError::NoError) {
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
return;

View File

@ -36,10 +36,10 @@ ExtUpgrade::ExtUpgrade(QObject *_parent, const QString &_filePath)
m_values[tag("pkgcount")] = 0;
m_process = new QProcess(nullptr);
connect(m_process, SIGNAL(finished(int)), this, SLOT(updateValue()));
connect(m_process, &QProcess::finished, [this]() { return updateValue(); });
m_process->waitForFinished(0);
connect(this, SIGNAL(requestDataUpdate()), this, SLOT(startProcess()));
connect(this, &ExtUpgrade::requestDataUpdate, this, &ExtUpgrade::startProcess);
}
@ -49,7 +49,7 @@ ExtUpgrade::~ExtUpgrade()
m_process->kill();
m_process->deleteLater();
disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(startProcess()));
disconnect(this, &ExtUpgrade::requestDataUpdate, this, &ExtUpgrade::startProcess);
}

View File

@ -49,9 +49,8 @@ ExtWeather::ExtWeather(QObject *_parent, const QString &_filePath)
// HACK declare as child of nullptr to avoid crash with plasmawindowed
// in the destructor
m_manager = new QNetworkAccessManager(nullptr);
connect(m_manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(weatherReplyReceived(QNetworkReply *)));
connect(this, SIGNAL(requestDataUpdate()), this, SLOT(sendRequest()));
connect(m_manager, &QNetworkAccessManager::finished, this, &ExtWeather::weatherReplyReceived);
connect(this, &ExtWeather::requestDataUpdate, this, &ExtWeather::sendRequest);
}
@ -59,8 +58,8 @@ ExtWeather::~ExtWeather()
{
qCDebug(LOG_LIB) << __PRETTY_FUNCTION__;
disconnect(m_manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(weatherReplyReceived(QNetworkReply *)));
disconnect(this, SIGNAL(requestDataUpdate()), this, SLOT(sendRequest()));
disconnect(m_manager, &QNetworkAccessManager::finished, this, &ExtWeather::weatherReplyReceived);
disconnect(this, &ExtWeather::requestDataUpdate, this, &ExtWeather::sendRequest);
m_manager->deleteLater();
}
@ -150,7 +149,7 @@ int ExtWeather::ts() const
QString ExtWeather::uniq() const
{
return QString("%1 (%2) at %3").arg(city()).arg(country()).arg(ts());
return QString("%1 (%2) at %3").arg(city(), country()).arg(ts());
}
@ -237,11 +236,11 @@ void ExtWeather::readJsonMap()
qCWarning(LOG_LIB) << "Could not open" << fileName;
return;
}
QString jsonText = jsonFile.readAll();
auto jsonText = jsonFile.readAll();
jsonFile.close();
QJsonParseError error{};
auto jsonDoc = QJsonDocument::fromJson(jsonText.toUtf8(), &error);
auto jsonDoc = QJsonDocument::fromJson(jsonText, &error);
if (error.error != QJsonParseError::NoError) {
qCWarning(LOG_LIB) << "Parse error" << error.errorString();
return;

View File

@ -33,7 +33,7 @@ QCronScheduler::QCronScheduler(QObject *_parent)
m_timer->setSingleShot(false);
m_timer->setInterval(60 * 1000);
connect(m_timer, SIGNAL(timeout()), this, SLOT(expired()));
connect(m_timer, &QTimer::timeout, this, &QCronScheduler::expired);
m_timer->start();
}

View File

@ -42,9 +42,9 @@ PlayerSource::PlayerSource(QObject *_parent, const QStringList &_args)
m_mpris = _args.at(3);
m_symbols = _args.at(4).toInt();
connect(&m_mpdSocket, SIGNAL(connected()), this, SLOT(mpdSocketConnected()));
connect(&m_mpdSocket, SIGNAL(readyRead()), this, SLOT(mpdSocketReadyRead()));
connect(&m_mpdSocket, SIGNAL(bytesWritten(qint64)), this, SLOT(mpdSocketWritten(const qint64)));
connect(&m_mpdSocket, &QTcpSocket::connected, this, &PlayerSource::mpdSocketConnected);
connect(&m_mpdSocket, &QTcpSocket::readyRead, this, &PlayerSource::mpdSocketReadyRead);
connect(&m_mpdSocket, &QTcpSocket::bytesWritten, this, &PlayerSource::mpdSocketWritten);
m_mpdCached = defaultInfo();
}