Do not make m_ui instance a ptr

By having it as a simple member variable, we do not need to take care of deleting it manually
This commit is contained in:
Alexander Lohnau 2023-07-26 10:40:17 +02:00 committed by Albert Vaca Cintora
parent 2e67f95017
commit b54e739753
10 changed files with 79 additions and 139 deletions

View file

@ -5,7 +5,6 @@
*/
#include "clipboard_config.h"
#include "ui_clipboard_config.h"
#include <KPluginFactory>
@ -13,30 +12,24 @@ K_PLUGIN_CLASS(ClipboardConfig)
ClipboardConfig::ClipboardConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &args)
: KdeConnectPluginKcm(parent, data, args)
, m_ui(new Ui::ClipboardConfigUi())
{
m_ui->setupUi(widget());
m_ui.setupUi(widget());
connect(m_ui->check_autoshare, &QCheckBox::toggled, this, &ClipboardConfig::autoShareChanged);
connect(m_ui->check_password, &QCheckBox::toggled, this, &ClipboardConfig::markAsChanged);
}
ClipboardConfig::~ClipboardConfig()
{
delete m_ui;
connect(m_ui.check_autoshare, &QCheckBox::toggled, this, &ClipboardConfig::autoShareChanged);
connect(m_ui.check_password, &QCheckBox::toggled, this, &ClipboardConfig::markAsChanged);
}
void ClipboardConfig::autoShareChanged()
{
m_ui->check_password->setEnabled(m_ui->check_autoshare->isChecked());
m_ui.check_password->setEnabled(m_ui.check_autoshare->isChecked());
markAsChanged();
}
void ClipboardConfig::defaults()
{
KCModule::defaults();
m_ui->check_autoshare->setChecked(true);
m_ui->check_password->setChecked(true);
m_ui.check_autoshare->setChecked(true);
m_ui.check_password->setChecked(true);
markAsChanged();
}
@ -46,15 +39,15 @@ void ClipboardConfig::load()
// "sendUnknown" is the legacy name for this setting
bool autoShare = config()->getBool(QStringLiteral("autoShare"), config()->getBool(QStringLiteral("sendUnknown"), true));
bool password = config()->getBool(QStringLiteral("sendPassword"), true);
m_ui->check_autoshare->setChecked(autoShare);
m_ui->check_password->setChecked(password);
m_ui.check_autoshare->setChecked(autoShare);
m_ui.check_password->setChecked(password);
autoShareChanged();
}
void ClipboardConfig::save()
{
config()->set(QStringLiteral("autoShare"), m_ui->check_autoshare->isChecked());
config()->set(QStringLiteral("sendPassword"), m_ui->check_password->isChecked());
config()->set(QStringLiteral("autoShare"), m_ui.check_autoshare->isChecked());
config()->set(QStringLiteral("sendPassword"), m_ui.check_password->isChecked());
KCModule::save();
}

View file

@ -7,18 +7,13 @@
#pragma once
#include "kcmplugin/kdeconnectpluginkcm.h"
namespace Ui
{
class ClipboardConfigUi;
}
#include "ui_clipboard_config.h"
class ClipboardConfig : public KdeConnectPluginKcm
{
Q_OBJECT
public:
ClipboardConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &);
~ClipboardConfig() override;
void save() override;
void load() override;
@ -26,5 +21,5 @@ public:
private:
void autoShareChanged();
Ui::ClipboardConfigUi *m_ui;
Ui::ClipboardConfigUi m_ui;
};

View file

@ -7,7 +7,6 @@
#include "findthisdevice_config.h"
#include "findthisdeviceplugin.h"
#include "ui_findthisdevice_config.h"
// KF
#include <KLocalizedString>
#include <KPluginFactory>
@ -23,33 +22,27 @@ K_PLUGIN_CLASS(FindThisDeviceConfig)
FindThisDeviceConfig::FindThisDeviceConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &args)
: KdeConnectPluginKcm(parent, data, args)
, m_ui(new Ui::FindThisDeviceConfigUi())
{
m_ui->setupUi(widget());
m_ui.setupUi(widget());
const QStringList soundDirs = QStandardPaths::locateAll(QStandardPaths::GenericDataLocation, QStringLiteral("sounds"), QStandardPaths::LocateDirectory);
if (!soundDirs.isEmpty()) {
m_ui->soundFileRequester->setStartDir(QUrl::fromLocalFile(soundDirs.last()));
m_ui.soundFileRequester->setStartDir(QUrl::fromLocalFile(soundDirs.last()));
}
connect(m_ui->playSoundButton, &QToolButton::clicked, this, [this]() {
if (const QUrl soundUrl = m_ui->soundFileRequester->url(); soundUrl.isValid()) {
connect(m_ui.playSoundButton, &QToolButton::clicked, this, [this]() {
if (const QUrl soundUrl = m_ui.soundFileRequester->url(); soundUrl.isValid()) {
playSound(soundUrl);
}
});
connect(m_ui->soundFileRequester, &KUrlRequester::textChanged, this, &FindThisDeviceConfig::markAsChanged);
}
FindThisDeviceConfig::~FindThisDeviceConfig()
{
delete m_ui;
connect(m_ui.soundFileRequester, &KUrlRequester::textChanged, this, &FindThisDeviceConfig::markAsChanged);
}
void FindThisDeviceConfig::defaults()
{
KCModule::defaults();
m_ui->soundFileRequester->setText(defaultSound());
m_ui.soundFileRequester->setText(defaultSound());
markAsChanged();
}
@ -58,12 +51,12 @@ void FindThisDeviceConfig::load()
KCModule::load();
const QString ringTone = config()->getString(QStringLiteral("ringtone"), defaultSound());
m_ui->soundFileRequester->setText(ringTone);
m_ui.soundFileRequester->setText(ringTone);
}
void FindThisDeviceConfig::save()
{
config()->set(QStringLiteral("ringtone"), m_ui->soundFileRequester->text());
config()->set(QStringLiteral("ringtone"), m_ui.soundFileRequester->text());
KCModule::save();
}

View file

@ -6,19 +6,14 @@
#pragma once
#include "ui_findthisdevice_config.h"
#include <kcmplugin/kdeconnectpluginkcm.h>
namespace Ui
{
class FindThisDeviceConfigUi;
}
class FindThisDeviceConfig : public KdeConnectPluginKcm
{
Q_OBJECT
public:
FindThisDeviceConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &);
~FindThisDeviceConfig() override;
void save() override;
void load() override;
@ -26,5 +21,5 @@ public:
private:
void playSound(const QUrl &soundUrl);
Ui::FindThisDeviceConfigUi *m_ui;
Ui::FindThisDeviceConfigUi m_ui;
};

View file

@ -5,7 +5,6 @@
*/
#include "pausemusic_config.h"
#include "ui_pausemusic_config.h"
#include <KPluginFactory>
@ -13,30 +12,24 @@ K_PLUGIN_CLASS(PauseMusicConfig)
PauseMusicConfig::PauseMusicConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &args)
: KdeConnectPluginKcm(parent, data, args)
, m_ui(new Ui::PauseMusicConfigUi())
{
m_ui->setupUi(widget());
m_ui.setupUi(widget());
connect(m_ui->rad_ringing, &QCheckBox::toggled, this, &PauseMusicConfig::markAsChanged);
connect(m_ui->rad_talking, &QCheckBox::toggled, this, &PauseMusicConfig::markAsChanged);
connect(m_ui->check_pause, &QCheckBox::toggled, this, &PauseMusicConfig::markAsChanged);
connect(m_ui->check_mute, &QCheckBox::toggled, this, &PauseMusicConfig::markAsChanged);
connect(m_ui->check_resume, &QCheckBox::toggled, this, &PauseMusicConfig::markAsChanged);
}
PauseMusicConfig::~PauseMusicConfig()
{
delete m_ui;
connect(m_ui.rad_ringing, &QCheckBox::toggled, this, &PauseMusicConfig::markAsChanged);
connect(m_ui.rad_talking, &QCheckBox::toggled, this, &PauseMusicConfig::markAsChanged);
connect(m_ui.check_pause, &QCheckBox::toggled, this, &PauseMusicConfig::markAsChanged);
connect(m_ui.check_mute, &QCheckBox::toggled, this, &PauseMusicConfig::markAsChanged);
connect(m_ui.check_resume, &QCheckBox::toggled, this, &PauseMusicConfig::markAsChanged);
}
void PauseMusicConfig::defaults()
{
KCModule::defaults();
m_ui->rad_talking->setChecked(false);
m_ui->rad_ringing->setChecked(true);
m_ui->check_pause->setChecked(true);
m_ui->check_mute->setChecked(false);
m_ui->check_resume->setChecked(true);
m_ui.rad_talking->setChecked(false);
m_ui.rad_ringing->setChecked(true);
m_ui.check_pause->setChecked(true);
m_ui.check_mute->setChecked(false);
m_ui.check_resume->setChecked(true);
markAsChanged();
}
@ -44,24 +37,24 @@ void PauseMusicConfig::load()
{
KCModule::load();
bool talking = config()->getBool(QStringLiteral("conditionTalking"), false);
m_ui->rad_talking->setChecked(talking);
m_ui->rad_ringing->setChecked(!talking);
m_ui.rad_talking->setChecked(talking);
m_ui.rad_ringing->setChecked(!talking);
bool pause = config()->getBool(QStringLiteral("actionPause"), true);
bool mute = config()->getBool(QStringLiteral("actionMute"), false);
m_ui->check_pause->setChecked(pause);
m_ui->check_mute->setChecked(mute);
m_ui.check_pause->setChecked(pause);
m_ui.check_mute->setChecked(mute);
const bool autoResume = config()->getBool(QStringLiteral("actionResume"), true);
m_ui->check_resume->setChecked(autoResume);
m_ui.check_resume->setChecked(autoResume);
}
void PauseMusicConfig::save()
{
config()->set(QStringLiteral("conditionTalking"), m_ui->rad_talking->isChecked());
config()->set(QStringLiteral("actionPause"), m_ui->check_pause->isChecked());
config()->set(QStringLiteral("actionMute"), m_ui->check_mute->isChecked());
config()->set(QStringLiteral("actionResume"), m_ui->check_resume->isChecked());
config()->set(QStringLiteral("conditionTalking"), m_ui.rad_talking->isChecked());
config()->set(QStringLiteral("actionPause"), m_ui.check_pause->isChecked());
config()->set(QStringLiteral("actionMute"), m_ui.check_mute->isChecked());
config()->set(QStringLiteral("actionResume"), m_ui.check_resume->isChecked());
KCModule::save();
}

View file

@ -7,23 +7,18 @@
#pragma once
#include "kcmplugin/kdeconnectpluginkcm.h"
namespace Ui
{
class PauseMusicConfigUi;
}
#include "ui_pausemusic_config.h"
class PauseMusicConfig : public KdeConnectPluginKcm
{
Q_OBJECT
public:
PauseMusicConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &);
~PauseMusicConfig() override;
void save() override;
void load() override;
void defaults() override;
private:
Ui::PauseMusicConfigUi *m_ui;
Ui::PauseMusicConfigUi m_ui;
};

View file

@ -6,7 +6,6 @@
#include "sendnotifications_config.h"
#include "notifyingapplicationmodel.h"
#include "ui_sendnotifications_config.h"
#include <KCModule>
#include <KPluginFactory>
@ -15,48 +14,42 @@ K_PLUGIN_CLASS(SendNotificationsConfig)
SendNotificationsConfig::SendNotificationsConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &args)
: KdeConnectPluginKcm(parent, data, args)
, m_ui(new Ui::SendNotificationsConfigUi())
, appModel(new NotifyingApplicationModel)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
qRegisterMetaTypeStreamOperators<NotifyingApplication>("NotifyingApplication");
#endif
m_ui->setupUi(widget());
m_ui->appList->setIconSize(QSize(32, 32));
m_ui.setupUi(widget());
m_ui.appList->setIconSize(QSize(32, 32));
m_ui->appList->setModel(appModel);
m_ui.appList->setModel(appModel);
m_ui->appList->horizontalHeader()->setSectionResizeMode(0, QHeaderView::QHeaderView::Fixed);
m_ui->appList->horizontalHeader()->setSectionResizeMode(1, QHeaderView::QHeaderView::Stretch);
m_ui->appList->horizontalHeader()->setSectionResizeMode(2, QHeaderView::QHeaderView::Stretch);
m_ui.appList->horizontalHeader()->setSectionResizeMode(0, QHeaderView::QHeaderView::Fixed);
m_ui.appList->horizontalHeader()->setSectionResizeMode(1, QHeaderView::QHeaderView::Stretch);
m_ui.appList->horizontalHeader()->setSectionResizeMode(2, QHeaderView::QHeaderView::Stretch);
for (int i = 0; i < 3; i++)
m_ui->appList->resizeColumnToContents(i);
m_ui.appList->resizeColumnToContents(i);
connect(m_ui->appList->horizontalHeader(), &QHeaderView::sortIndicatorChanged, m_ui->appList, &QTableView::sortByColumn);
connect(m_ui.appList->horizontalHeader(), &QHeaderView::sortIndicatorChanged, m_ui.appList, &QTableView::sortByColumn);
connect(m_ui->check_persistent, &QCheckBox::toggled, this, &SendNotificationsConfig::markAsChanged);
connect(m_ui->spin_urgency, &QSpinBox::editingFinished, this, &SendNotificationsConfig::markAsChanged);
connect(m_ui->check_body, &QCheckBox::toggled, this, &SendNotificationsConfig::markAsChanged);
connect(m_ui->check_icons, &QCheckBox::toggled, this, &SendNotificationsConfig::markAsChanged);
connect(m_ui.check_persistent, &QCheckBox::toggled, this, &SendNotificationsConfig::markAsChanged);
connect(m_ui.spin_urgency, &QSpinBox::editingFinished, this, &SendNotificationsConfig::markAsChanged);
connect(m_ui.check_body, &QCheckBox::toggled, this, &SendNotificationsConfig::markAsChanged);
connect(m_ui.check_icons, &QCheckBox::toggled, this, &SendNotificationsConfig::markAsChanged);
connect(appModel, &NotifyingApplicationModel::applicationsChanged, this, &SendNotificationsConfig::markAsChanged);
connect(config(), &KdeConnectPluginConfig::configChanged, this, &SendNotificationsConfig::loadApplications);
}
SendNotificationsConfig::~SendNotificationsConfig()
{
delete m_ui;
}
void SendNotificationsConfig::defaults()
{
KCModule::defaults();
m_ui->check_persistent->setChecked(false);
m_ui->spin_urgency->setValue(0);
m_ui->check_body->setChecked(true);
m_ui->check_icons->setChecked(true);
m_ui.check_persistent->setChecked(false);
m_ui.spin_urgency->setValue(0);
m_ui.check_body->setChecked(true);
m_ui.check_icons->setChecked(true);
markAsChanged();
}
@ -76,13 +69,13 @@ void SendNotificationsConfig::load()
{
KCModule::load();
bool persistent = config()->getBool(QStringLiteral("generalPersistent"), false);
m_ui->check_persistent->setChecked(persistent);
m_ui.check_persistent->setChecked(persistent);
bool body = config()->getBool(QStringLiteral("generalIncludeBody"), true);
m_ui->check_body->setChecked(body);
m_ui.check_body->setChecked(body);
bool icons = config()->getBool(QStringLiteral("generalSynchronizeIcons"), true);
m_ui->check_icons->setChecked(icons);
m_ui.check_icons->setChecked(icons);
int urgency = config()->getInt(QStringLiteral("generalUrgency"), 0);
m_ui->spin_urgency->setValue(urgency);
m_ui.spin_urgency->setValue(urgency);
loadApplications();
}
@ -90,10 +83,10 @@ void SendNotificationsConfig::load()
void SendNotificationsConfig::save()
{
KCModule::save();
config()->set(QStringLiteral("generalPersistent"), m_ui->check_persistent->isChecked());
config()->set(QStringLiteral("generalIncludeBody"), m_ui->check_body->isChecked());
config()->set(QStringLiteral("generalSynchronizeIcons"), m_ui->check_icons->isChecked());
config()->set(QStringLiteral("generalUrgency"), m_ui->spin_urgency->value());
config()->set(QStringLiteral("generalPersistent"), m_ui.check_persistent->isChecked());
config()->set(QStringLiteral("generalIncludeBody"), m_ui.check_body->isChecked());
config()->set(QStringLiteral("generalSynchronizeIcons"), m_ui.check_icons->isChecked());
config()->set(QStringLiteral("generalUrgency"), m_ui.spin_urgency->value());
QVariantList list;
const auto apps = appModel->apps();

View file

@ -7,11 +7,7 @@
#pragma once
#include "kcmplugin/kdeconnectpluginkcm.h"
namespace Ui
{
class SendNotificationsConfigUi;
}
#include "ui_sendnotifications_config.h"
class NotifyingApplicationModel;
@ -20,7 +16,6 @@ class SendNotificationsConfig : public KdeConnectPluginKcm
Q_OBJECT
public:
SendNotificationsConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &);
~SendNotificationsConfig() override;
void save() override;
void load() override;
@ -28,6 +23,6 @@ public:
private:
void loadApplications();
Ui::SendNotificationsConfigUi *m_ui;
Ui::SendNotificationsConfigUi m_ui;
NotifyingApplicationModel *appModel;
};

View file

@ -5,7 +5,6 @@
*/
#include "share_config.h"
#include "ui_share_config.h"
#include <QStandardPaths>
@ -16,26 +15,20 @@ K_PLUGIN_CLASS(ShareConfig)
ShareConfig::ShareConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &args)
: KdeConnectPluginKcm(parent, data, args)
, m_ui(new Ui::ShareConfigUi())
{
m_ui->setupUi(widget());
m_ui.setupUi(widget());
// xgettext:no-c-format
m_ui->commentLabel->setTextFormat(Qt::RichText);
m_ui->commentLabel->setText(i18n("&percnt;1 in the path will be replaced with the specific device name."));
m_ui.commentLabel->setTextFormat(Qt::RichText);
m_ui.commentLabel->setText(i18n("&percnt;1 in the path will be replaced with the specific device name."));
connect(m_ui->kurlrequester, &KUrlRequester::textChanged, this, &ShareConfig::markAsChanged);
}
ShareConfig::~ShareConfig()
{
delete m_ui;
connect(m_ui.kurlrequester, &KUrlRequester::textChanged, this, &ShareConfig::markAsChanged);
}
void ShareConfig::defaults()
{
KCModule::defaults();
m_ui->kurlrequester->setText(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
m_ui.kurlrequester->setText(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
markAsChanged();
}
@ -45,13 +38,13 @@ void ShareConfig::load()
KCModule::load();
const auto standardPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
m_ui->kurlrequester->setText(config()->getString(QStringLiteral("incoming_path"), standardPath));
m_ui.kurlrequester->setText(config()->getString(QStringLiteral("incoming_path"), standardPath));
}
void ShareConfig::save()
{
KCModule::save();
config()->set(QStringLiteral("incoming_path"), m_ui->kurlrequester->text());
config()->set(QStringLiteral("incoming_path"), m_ui.kurlrequester->text());
}
#include "moc_share_config.cpp"

View file

@ -7,23 +7,18 @@
#pragma once
#include "kcmplugin/kdeconnectpluginkcm.h"
namespace Ui
{
class ShareConfigUi;
}
#include "ui_share_config.h"
class ShareConfig : public KdeConnectPluginKcm
{
Q_OBJECT
public:
ShareConfig(QObject *parent, const KPluginMetaData &data, const QVariantList &args);
~ShareConfig() override;
void save() override;
void load() override;
void defaults() override;
private:
Ui::ShareConfigUi *m_ui;
Ui::ShareConfigUi m_ui;
};