KdeConnectKcm: Do not make generated UI class instance a ptr
This commit is contained in:
parent
b54e739753
commit
dd5e61ab0a
2 changed files with 61 additions and 71 deletions
119
kcm/kcm.cpp
119
kcm/kcm.cpp
|
@ -19,13 +19,11 @@
|
|||
#include "devicesmodel.h"
|
||||
#include "devicessortproxymodel.h"
|
||||
#include "kdeconnect-version.h"
|
||||
#include "ui_kcm.h"
|
||||
|
||||
K_PLUGIN_CLASS_WITH_JSON(KdeConnectKcm, "kcm_kdeconnect.json")
|
||||
|
||||
KdeConnectKcm::KdeConnectKcm(QObject *parent, const QVariantList &args)
|
||||
: KCModule(qobject_cast<QWidget *>(parent))
|
||||
, kcmUi(new Ui::KdeConnectKcmUi())
|
||||
, daemon(new DaemonDbusInterface(this))
|
||||
, devicesModel(new DevicesModel(this))
|
||||
, currentDevice(nullptr)
|
||||
|
@ -35,48 +33,48 @@ KdeConnectKcm::KdeConnectKcm(QObject *parent, const QVariantList &args)
|
|||
QApplication::setStyle(QStringLiteral("breeze"));
|
||||
#endif
|
||||
|
||||
kcmUi->setupUi(widget());
|
||||
kcmUi.setupUi(widget());
|
||||
|
||||
sortProxyModel = new DevicesSortProxyModel(devicesModel);
|
||||
|
||||
kcmUi->deviceList->setModel(sortProxyModel);
|
||||
kcmUi.deviceList->setModel(sortProxyModel);
|
||||
|
||||
kcmUi->deviceInfo->setVisible(false);
|
||||
kcmUi->progressBar->setVisible(false);
|
||||
kcmUi->messages->setVisible(false);
|
||||
kcmUi.deviceInfo->setVisible(false);
|
||||
kcmUi.progressBar->setVisible(false);
|
||||
kcmUi.messages->setVisible(false);
|
||||
|
||||
// Workaround: If we set this directly (or if we set it in the .ui file), the layout breaks
|
||||
kcmUi->noDeviceLinks->setWordWrap(false);
|
||||
kcmUi.noDeviceLinks->setWordWrap(false);
|
||||
QTimer::singleShot(0, this, [this] {
|
||||
kcmUi->noDeviceLinks->setWordWrap(true);
|
||||
kcmUi.noDeviceLinks->setWordWrap(true);
|
||||
});
|
||||
|
||||
setWhenAvailable(
|
||||
daemon->announcedName(),
|
||||
[this](const QString &announcedName) {
|
||||
kcmUi->rename_label->setText(announcedName);
|
||||
kcmUi->rename_edit->setText(announcedName);
|
||||
kcmUi.rename_label->setText(announcedName);
|
||||
kcmUi.rename_edit->setText(announcedName);
|
||||
},
|
||||
this);
|
||||
connect(daemon, SIGNAL(announcedNameChanged(QString)), kcmUi->rename_edit, SLOT(setText(QString)));
|
||||
connect(daemon, SIGNAL(announcedNameChanged(QString)), kcmUi->rename_label, SLOT(setText(QString)));
|
||||
connect(daemon, SIGNAL(announcedNameChanged(QString)), kcmUi.rename_edit, SLOT(setText(QString)));
|
||||
connect(daemon, SIGNAL(announcedNameChanged(QString)), kcmUi.rename_label, SLOT(setText(QString)));
|
||||
setRenameMode(false);
|
||||
|
||||
setButtons(KCModule::Help | KCModule::NoAdditionalButton);
|
||||
|
||||
connect(devicesModel, &QAbstractItemModel::dataChanged, this, &KdeConnectKcm::resetSelection);
|
||||
connect(kcmUi->deviceList->selectionModel(), &QItemSelectionModel::currentChanged, this, &KdeConnectKcm::deviceSelected);
|
||||
connect(kcmUi->accept_button, &QAbstractButton::clicked, this, &KdeConnectKcm::acceptPairing);
|
||||
connect(kcmUi->reject_button, &QAbstractButton::clicked, this, &KdeConnectKcm::cancelPairing);
|
||||
connect(kcmUi->cancel_button, &QAbstractButton::clicked, this, &KdeConnectKcm::cancelPairing);
|
||||
connect(kcmUi->pair_button, &QAbstractButton::clicked, this, &KdeConnectKcm::requestPairing);
|
||||
connect(kcmUi->unpair_button, &QAbstractButton::clicked, this, &KdeConnectKcm::unpair);
|
||||
connect(kcmUi->ping_button, &QAbstractButton::clicked, this, &KdeConnectKcm::sendPing);
|
||||
connect(kcmUi->refresh_button, &QAbstractButton::clicked, this, &KdeConnectKcm::refresh);
|
||||
connect(kcmUi->rename_edit, &QLineEdit::returnPressed, this, &KdeConnectKcm::renameDone);
|
||||
connect(kcmUi->renameDone_button, &QAbstractButton::clicked, this, &KdeConnectKcm::renameDone);
|
||||
connect(kcmUi->renameShow_button, &QAbstractButton::clicked, this, &KdeConnectKcm::renameShow);
|
||||
connect(kcmUi->pluginSelector, &KPluginWidget::changed, this, &KdeConnectKcm::pluginsConfigChanged);
|
||||
connect(kcmUi.deviceList->selectionModel(), &QItemSelectionModel::currentChanged, this, &KdeConnectKcm::deviceSelected);
|
||||
connect(kcmUi.accept_button, &QAbstractButton::clicked, this, &KdeConnectKcm::acceptPairing);
|
||||
connect(kcmUi.reject_button, &QAbstractButton::clicked, this, &KdeConnectKcm::cancelPairing);
|
||||
connect(kcmUi.cancel_button, &QAbstractButton::clicked, this, &KdeConnectKcm::cancelPairing);
|
||||
connect(kcmUi.pair_button, &QAbstractButton::clicked, this, &KdeConnectKcm::requestPairing);
|
||||
connect(kcmUi.unpair_button, &QAbstractButton::clicked, this, &KdeConnectKcm::unpair);
|
||||
connect(kcmUi.ping_button, &QAbstractButton::clicked, this, &KdeConnectKcm::sendPing);
|
||||
connect(kcmUi.refresh_button, &QAbstractButton::clicked, this, &KdeConnectKcm::refresh);
|
||||
connect(kcmUi.rename_edit, &QLineEdit::returnPressed, this, &KdeConnectKcm::renameDone);
|
||||
connect(kcmUi.renameDone_button, &QAbstractButton::clicked, this, &KdeConnectKcm::renameDone);
|
||||
connect(kcmUi.renameShow_button, &QAbstractButton::clicked, this, &KdeConnectKcm::renameShow);
|
||||
connect(kcmUi.pluginSelector, &KPluginWidget::changed, this, &KdeConnectKcm::pluginsConfigChanged);
|
||||
|
||||
if (!args.isEmpty() && args.first().type() == QVariant::String) {
|
||||
const QString input = args.first().toString();
|
||||
|
@ -88,10 +86,10 @@ KdeConnectKcm::KdeConnectKcm(QObject *parent, const QVariantList &args)
|
|||
auto row = devicesModel->rowForDevice(deviceId);
|
||||
if (row >= 0) {
|
||||
const QModelIndex idx = sortProxyModel->mapFromSource(devicesModel->index(row));
|
||||
kcmUi->deviceList->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect);
|
||||
kcmUi.deviceList->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect);
|
||||
}
|
||||
if (!pluginCM.isEmpty()) {
|
||||
kcmUi->pluginSelector->showConfiguration(pluginCM);
|
||||
kcmUi.pluginSelector->showConfiguration(pluginCM);
|
||||
}
|
||||
disconnect(devicesModel, &DevicesModel::rowsInserted, this, nullptr);
|
||||
});
|
||||
|
@ -105,12 +103,12 @@ void KdeConnectKcm::renameShow()
|
|||
|
||||
void KdeConnectKcm::renameDone()
|
||||
{
|
||||
QString newName = kcmUi->rename_edit->text();
|
||||
QString newName = kcmUi.rename_edit->text();
|
||||
if (newName.isEmpty()) {
|
||||
// Rollback changes
|
||||
kcmUi->rename_edit->setText(kcmUi->rename_label->text());
|
||||
kcmUi.rename_edit->setText(kcmUi.rename_label->text());
|
||||
} else {
|
||||
kcmUi->rename_label->setText(newName);
|
||||
kcmUi.rename_label->setText(newName);
|
||||
daemon->setAnnouncedName(newName);
|
||||
}
|
||||
setRenameMode(false);
|
||||
|
@ -118,15 +116,14 @@ void KdeConnectKcm::renameDone()
|
|||
|
||||
void KdeConnectKcm::setRenameMode(bool b)
|
||||
{
|
||||
kcmUi->renameDone_button->setVisible(b);
|
||||
kcmUi->rename_edit->setVisible(b);
|
||||
kcmUi->renameShow_button->setVisible(!b);
|
||||
kcmUi->rename_label->setVisible(!b);
|
||||
kcmUi.renameDone_button->setVisible(b);
|
||||
kcmUi.rename_edit->setVisible(b);
|
||||
kcmUi.renameShow_button->setVisible(!b);
|
||||
kcmUi.rename_label->setVisible(!b);
|
||||
}
|
||||
|
||||
KdeConnectKcm::~KdeConnectKcm()
|
||||
{
|
||||
delete kcmUi;
|
||||
}
|
||||
|
||||
void KdeConnectKcm::refresh()
|
||||
|
@ -139,7 +136,7 @@ void KdeConnectKcm::resetSelection()
|
|||
if (!currentDevice) {
|
||||
return;
|
||||
}
|
||||
kcmUi->deviceList->selectionModel()->setCurrentIndex(sortProxyModel->mapFromSource(currentIndex), QItemSelectionModel::ClearAndSelect);
|
||||
kcmUi.deviceList->selectionModel()->setCurrentIndex(sortProxyModel->mapFromSource(currentIndex), QItemSelectionModel::ClearAndSelect);
|
||||
}
|
||||
|
||||
void KdeConnectKcm::deviceSelected(const QModelIndex ¤t)
|
||||
|
@ -150,21 +147,21 @@ void KdeConnectKcm::deviceSelected(const QModelIndex ¤t)
|
|||
|
||||
if (!current.isValid()) {
|
||||
currentDevice = nullptr;
|
||||
kcmUi->deviceInfo->setVisible(false);
|
||||
kcmUi.deviceInfo->setVisible(false);
|
||||
return;
|
||||
}
|
||||
|
||||
currentIndex = sortProxyModel->mapToSource(current);
|
||||
currentDevice = devicesModel->getDevice(currentIndex.row());
|
||||
|
||||
kcmUi->noDevicePlaceholder->setVisible(false);
|
||||
kcmUi.noDevicePlaceholder->setVisible(false);
|
||||
bool valid = (currentDevice != nullptr && currentDevice->isValid());
|
||||
kcmUi->deviceInfo->setVisible(valid);
|
||||
kcmUi.deviceInfo->setVisible(valid);
|
||||
if (!valid) {
|
||||
return;
|
||||
}
|
||||
|
||||
kcmUi->messages->setVisible(false);
|
||||
kcmUi.messages->setVisible(false);
|
||||
resetDeviceView();
|
||||
|
||||
connect(currentDevice, SIGNAL(pluginsChanged()), this, SLOT(resetCurrentDevice()));
|
||||
|
@ -183,9 +180,9 @@ void KdeConnectKcm::resetCurrentDevice()
|
|||
|
||||
void KdeConnectKcm::resetDeviceView()
|
||||
{
|
||||
kcmUi->verificationKey->setText(i18n("Key: %1", QString::fromUtf8(currentDevice->verificationKey())));
|
||||
kcmUi.verificationKey->setText(i18n("Key: %1", QString::fromUtf8(currentDevice->verificationKey())));
|
||||
|
||||
kcmUi->name_label->setText(currentDevice->name());
|
||||
kcmUi.name_label->setText(currentDevice->name());
|
||||
setWhenAvailable(
|
||||
currentDevice->pairStateAsInt(),
|
||||
[this](int pairStateAsInt) {
|
||||
|
@ -204,10 +201,10 @@ void KdeConnectKcm::resetDeviceView()
|
|||
}
|
||||
|
||||
KSharedConfigPtr deviceConfig = KSharedConfig::openConfig(currentDevice->pluginsConfigFile());
|
||||
kcmUi->pluginSelector->clear();
|
||||
kcmUi->pluginSelector->setConfigurationArguments({currentDevice->id()});
|
||||
kcmUi->pluginSelector->addPlugins(availablePluginInfo, i18n("Available plugins"));
|
||||
kcmUi->pluginSelector->setConfig(deviceConfig->group("Plugins"));
|
||||
kcmUi.pluginSelector->clear();
|
||||
kcmUi.pluginSelector->setConfigurationArguments({currentDevice->id()});
|
||||
kcmUi.pluginSelector->addPlugins(availablePluginInfo, i18n("Available plugins"));
|
||||
kcmUi.pluginSelector->setConfig(deviceConfig->group("Plugins"));
|
||||
}
|
||||
|
||||
void KdeConnectKcm::requestPairing()
|
||||
|
@ -216,7 +213,7 @@ void KdeConnectKcm::requestPairing()
|
|||
return;
|
||||
}
|
||||
|
||||
kcmUi->messages->hide();
|
||||
kcmUi.messages->hide();
|
||||
|
||||
currentDevice->requestPairing();
|
||||
}
|
||||
|
@ -253,32 +250,32 @@ void KdeConnectKcm::pairingFailed(const QString &error)
|
|||
if (sender() != currentDevice)
|
||||
return;
|
||||
|
||||
kcmUi->messages->setText(i18n("Error trying to pair: %1", error));
|
||||
kcmUi->messages->animatedShow();
|
||||
kcmUi.messages->setText(i18n("Error trying to pair: %1", error));
|
||||
kcmUi.messages->animatedShow();
|
||||
}
|
||||
|
||||
void KdeConnectKcm::setCurrentDevicePairState(int pairStateAsInt)
|
||||
{
|
||||
PairState state = (PairState)pairStateAsInt; // Hack because qdbus doesn't like enums
|
||||
kcmUi->accept_button->setVisible(state == PairState::RequestedByPeer);
|
||||
kcmUi->reject_button->setVisible(state == PairState::RequestedByPeer);
|
||||
kcmUi->cancel_button->setVisible(state == PairState::Requested);
|
||||
kcmUi->pair_button->setVisible(state == PairState::NotPaired);
|
||||
kcmUi->unpair_button->setVisible(state == PairState::Paired);
|
||||
kcmUi->progressBar->setVisible(state == PairState::Requested);
|
||||
kcmUi->ping_button->setVisible(state == PairState::Paired);
|
||||
kcmUi.accept_button->setVisible(state == PairState::RequestedByPeer);
|
||||
kcmUi.reject_button->setVisible(state == PairState::RequestedByPeer);
|
||||
kcmUi.cancel_button->setVisible(state == PairState::Requested);
|
||||
kcmUi.pair_button->setVisible(state == PairState::NotPaired);
|
||||
kcmUi.unpair_button->setVisible(state == PairState::Paired);
|
||||
kcmUi.progressBar->setVisible(state == PairState::Requested);
|
||||
kcmUi.ping_button->setVisible(state == PairState::Paired);
|
||||
switch (state) {
|
||||
case PairState::Paired:
|
||||
kcmUi->status_label->setText(i18n("(paired)"));
|
||||
kcmUi.status_label->setText(i18n("(paired)"));
|
||||
break;
|
||||
case PairState::NotPaired:
|
||||
kcmUi->status_label->setText(i18n("(not paired)"));
|
||||
kcmUi.status_label->setText(i18n("(not paired)"));
|
||||
break;
|
||||
case PairState::RequestedByPeer:
|
||||
kcmUi->status_label->setText(i18n("(incoming pair request)"));
|
||||
kcmUi.status_label->setText(i18n("(incoming pair request)"));
|
||||
break;
|
||||
case PairState::Requested:
|
||||
kcmUi->status_label->setText(i18n("(pairing requested)"));
|
||||
kcmUi.status_label->setText(i18n("(pairing requested)"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -291,7 +288,7 @@ void KdeConnectKcm::pluginsConfigChanged(bool changed)
|
|||
if (!currentDevice)
|
||||
return;
|
||||
|
||||
kcmUi->pluginSelector->save();
|
||||
kcmUi.pluginSelector->save();
|
||||
currentDevice->reloadPlugins();
|
||||
}
|
||||
|
||||
|
|
13
kcm/kcm.h
13
kcm/kcm.h
|
@ -4,13 +4,13 @@
|
|||
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
*/
|
||||
|
||||
#ifndef KDECONNECTKCM_H
|
||||
#define KDECONNECTKCM_H
|
||||
#pragma once
|
||||
|
||||
#include <KCModule>
|
||||
#include <QStandardItemModel>
|
||||
#include <kconfigwidgets_version.h>
|
||||
|
||||
#include "ui_kcm.h"
|
||||
#include <core/pairstate.h>
|
||||
|
||||
class QModelIndex;
|
||||
|
@ -19,11 +19,6 @@ class DaemonDbusInterface;
|
|||
class DevicesModel;
|
||||
class DevicesSortProxyModel;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class KdeConnectKcmUi;
|
||||
}
|
||||
|
||||
class KdeConnectKcm : public KCModule
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -60,7 +55,7 @@ private Q_SLOTS:
|
|||
private:
|
||||
void resetDeviceView();
|
||||
|
||||
Ui::KdeConnectKcmUi *kcmUi;
|
||||
Ui::KdeConnectKcmUi kcmUi;
|
||||
DaemonDbusInterface *daemon;
|
||||
DevicesModel *devicesModel;
|
||||
DevicesSortProxyModel *sortProxyModel;
|
||||
|
@ -71,5 +66,3 @@ private:
|
|||
public Q_SLOTS:
|
||||
void unpair();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue