Qt6 build fixes in plugins and KCM

This commit is contained in:
Alexander Lohnau 2023-04-17 19:10:08 +02:00
parent a5a375d7d9
commit 5dcb60eb99
15 changed files with 58 additions and 90 deletions

View file

@ -27,32 +27,19 @@ static QString createId()
return QStringLiteral("kcm") + QString::number(QCoreApplication::applicationPid());
}
KdeConnectKcm::KdeConnectKcm(QWidget *parent, const QVariantList &args)
KdeConnectKcm::KdeConnectKcm(QObject *parent, const QVariantList &args)
: KCModule(parent)
, kcmUi(new Ui::KdeConnectKcmUi())
, daemon(new DaemonDbusInterface(this))
, devicesModel(new DevicesModel(this))
, currentDevice(nullptr)
{
KAboutData *about = new KAboutData(QStringLiteral("kdeconnect-kcm"),
i18n("KDE Connect Settings"),
QStringLiteral(KDECONNECT_VERSION_STRING),
i18n("KDE Connect Settings module"),
KAboutLicense::KAboutLicense::GPL_V2,
i18n("(C) 2015 Albert Vaca Cintora"),
QString(),
QStringLiteral("https://community.kde.org/KDEConnect"));
about->addAuthor(i18n("Albert Vaca Cintora"));
about->setProgramLogo(QIcon(QStringLiteral(":/icons/kdeconnect/kdeconnect.svg")));
setAboutData(about);
#ifdef Q_OS_WIN
KColorSchemeManager manager;
QApplication::setStyle(QStringLiteral("breeze"));
#endif
kcmUi->setupUi(this);
kcmUi->setupUi(widget());
sortProxyModel = new DevicesSortProxyModel(devicesModel);
@ -95,8 +82,6 @@ KdeConnectKcm::KdeConnectKcm(QWidget *parent, const QVariantList &args)
daemon->acquireDiscoveryMode(createId());
#if KCMUTILS_VERSION >= QT_VERSION_CHECK(5, 45, 0)
if (!args.isEmpty() && args.first().type() == QVariant::String) {
const QString input = args.first().toString();
const auto colonIdx = input.indexOf(QLatin1Char(':'));
@ -115,8 +100,6 @@ KdeConnectKcm::KdeConnectKcm(QWidget *parent, const QVariantList &args)
disconnect(devicesModel, &DevicesModel::rowsInserted, this, nullptr);
});
}
#endif
}
void KdeConnectKcm::renameShow()
@ -251,7 +234,7 @@ void KdeConnectKcm::resetDeviceView()
KSharedConfigPtr deviceConfig = KSharedConfig::openConfig(currentDevice->pluginsConfigFile());
kcmUi->pluginSelector->clear();
kcmUi->pluginSelector->setConfigurationArguments(QStringList(currentDevice->id()));
kcmUi->pluginSelector->setConfigurationArguments({currentDevice->id()});
kcmUi->pluginSelector->addPlugins(availablePluginInfo, i18n("Available plugins"));
kcmUi->pluginSelector->setConfig(deviceConfig->group("Plugins"));
connect(kcmUi->pluginSelector, &KPluginWidget::changed, this, &KdeConnectKcm::pluginsConfigChanged);
@ -362,15 +345,5 @@ void KdeConnectKcm::sendPing()
currentDevice->pluginCall(QStringLiteral("ping"), QStringLiteral("sendPing"));
}
QSize KdeConnectKcm::sizeHint() const
{
return QSize(890, 550); // Golden ratio :D
}
QSize KdeConnectKcm::minimumSizeHint() const
{
return QSize(500, 300);
}
#include "kcm.moc"
#include "moc_kcm.cpp"

View file

@ -25,13 +25,11 @@ class KdeConnectKcm : public KCModule
{
Q_OBJECT
public:
KdeConnectKcm(QWidget *parent, const QVariantList &);
KdeConnectKcm(QObject *parent, const QVariantList &);
~KdeConnectKcm() override;
private:
void save() override;
QSize sizeHint() const override;
QSize minimumSizeHint() const override;
private Q_SLOTS:
void deviceSelected(const QModelIndex &current);

View file

@ -4,12 +4,12 @@ add_library(kdeconnectpluginkcm kdeconnectpluginkcm.cpp)
target_link_libraries(kdeconnectpluginkcm
PUBLIC
kdeconnectcore
KF${QT_MAJOR_VERSION}::KCMUtils
PRIVATE
Qt::DBus
Qt::Gui
KF${QT_MAJOR_VERSION}::I18n
KF${QT_MAJOR_VERSION}::ConfigCore
KF${QT_MAJOR_VERSION}::KCMUtils
)
set_target_properties(kdeconnectpluginkcm PROPERTIES

View file

@ -15,7 +15,7 @@ struct KdeConnectPluginKcmPrivate {
KdeConnectPluginConfig *m_config = nullptr;
};
KdeConnectPluginKcm::KdeConnectPluginKcm(QWidget *parent, const QVariantList &args, const QString &pluginName)
KdeConnectPluginKcm::KdeConnectPluginKcm(QObject *parent, const QVariantList &args, const QString &pluginName)
: KCModule(parent, args)
, d(new KdeConnectPluginKcmPrivate())
{

View file

@ -23,7 +23,7 @@ class KDECONNECTPLUGINKCM_EXPORT KdeConnectPluginKcm : public KCModule
Q_OBJECT
public:
KdeConnectPluginKcm(QWidget *parent, const QVariantList &args, const QString &componentName);
KdeConnectPluginKcm(QObject *parent, const QVariantList &args, const QString &componentName);
~KdeConnectPluginKcm() override;
/**

View file

@ -11,11 +11,11 @@
K_PLUGIN_FACTORY(ClipboardConfigFactory, registerPlugin<ClipboardConfig>();)
ClipboardConfig::ClipboardConfig(QWidget* parent, const QVariantList &args)
ClipboardConfig::ClipboardConfig(QObject *parent, const QVariantList &args)
: KdeConnectPluginKcm(parent, args, QStringLiteral("kdeconnect_clipboard"))
, m_ui(new Ui::ClipboardConfigUi())
{
m_ui->setupUi(this);
m_ui->setupUi(widget());
connect(m_ui->check_unknown, SIGNAL(toggled(bool)), this, SLOT(changed()));
connect(m_ui->check_password, SIGNAL(toggled(bool)), this, SLOT(changed()));
@ -31,7 +31,7 @@ void ClipboardConfig::defaults()
KCModule::defaults();
m_ui->check_unknown->setChecked(true);
m_ui->check_password->setChecked(true);
Q_EMIT changed(true);
markAsChanged();
}
void ClipboardConfig::load()
@ -41,8 +41,6 @@ void ClipboardConfig::load()
bool password = config()->getBool(QStringLiteral("sendPassword"), true);
m_ui->check_unknown->setChecked(unknown);
m_ui->check_password->setChecked(password);
Q_EMIT changed(false);
}
void ClipboardConfig::save()
@ -50,7 +48,6 @@ void ClipboardConfig::save()
config()->set(QStringLiteral("sendUnknown"), m_ui->check_unknown->isChecked());
config()->set(QStringLiteral("sendPassword"), m_ui->check_password->isChecked());
KCModule::save();
Q_EMIT changed(false);
}
#include "clipboard_config.moc"

View file

@ -9,16 +9,16 @@
#include "kcmplugin/kdeconnectpluginkcm.h"
namespace Ui {
namespace Ui
{
class ClipboardConfigUi;
}
class ClipboardConfig
: public KdeConnectPluginKcm
class ClipboardConfig : public KdeConnectPluginKcm
{
Q_OBJECT
public:
ClipboardConfig(QWidget *parent, const QVariantList&);
ClipboardConfig(QObject *parent, const QVariantList &);
~ClipboardConfig() override;
public Q_SLOTS:
@ -28,7 +28,6 @@ public Q_SLOTS:
private:
Ui::ClipboardConfigUi *m_ui;
};
#endif

View file

@ -7,11 +7,11 @@
#include "runcommand_config.h"
#include <QDebug>
#include <QFileDialog>
#include <QHBoxLayout>
#include <QHeaderView>
#include <QJsonDocument>
#include <QJsonArray>
#include <QFileDialog>
#include <QJsonDocument>
#include <QMenu>
#include <QPushButton>
#include <QStandardItemModel>
@ -26,7 +26,7 @@
K_PLUGIN_FACTORY(ShareConfigFactory, registerPlugin<RunCommandConfig>();)
RunCommandConfig::RunCommandConfig(QWidget *parent, const QVariantList &args)
RunCommandConfig::RunCommandConfig(QObject *parent, const QVariantList &args)
: KdeConnectPluginKcm(parent, args, QStringLiteral("kdeconnect_runcommand"))
{
// The qdbus executable name is different on some systems
@ -35,7 +35,7 @@ RunCommandConfig::RunCommandConfig(QWidget *parent, const QVariantList &args)
qdbusExe = QStringLiteral("qdbus");
}
QMenu *defaultMenu = new QMenu(this);
QMenu *defaultMenu = new QMenu(widget());
#ifdef Q_OS_WIN
addSuggestedCommand(defaultMenu, i18n("Schedule a shutdown"), QStringLiteral("shutdown /s /t 60"));
@ -67,25 +67,25 @@ RunCommandConfig::RunCommandConfig(QWidget *parent, const QVariantList &args)
QStringLiteral("%0 org.kde.kded5 /modules/plasmavault forceCloseAllVaults").arg(qdbusExe));
#endif
QTableView *table = new QTableView(this);
QTableView *table = new QTableView(widget());
table->horizontalHeader()->setStretchLastSection(true);
table->verticalHeader()->setVisible(false);
QVBoxLayout *layout = new QVBoxLayout(this);
QVBoxLayout *layout = new QVBoxLayout(widget());
layout->addWidget(table);
QPushButton *button = new QPushButton(QIcon::fromTheme(QStringLiteral("list-add")), i18n("Sample commands"), this);
QPushButton *button = new QPushButton(QIcon::fromTheme(QStringLiteral("list-add")), i18n("Sample commands"), widget());
button->setMenu(defaultMenu);
layout->addWidget(button);
QHBoxLayout *importExportLayout = new QHBoxLayout(this);
QPushButton *exportButton = new QPushButton(i18n("Export"), this);
QHBoxLayout *importExportLayout = new QHBoxLayout(widget());
QPushButton *exportButton = new QPushButton(i18n("Export"), widget());
importExportLayout->addWidget(exportButton);
connect(exportButton, &QPushButton::clicked, this, &RunCommandConfig::exportCommands);
QPushButton *importButton = new QPushButton(i18n("Import"), this);
QPushButton *importButton = new QPushButton(i18n("Import"), widget());
importExportLayout->addWidget(importButton);
connect(importButton, &QPushButton::clicked, this, &RunCommandConfig::importCommands);
layout->addLayout(importExportLayout);
setLayout(layout);
widget()->setLayout(layout);
m_entriesModel = new QStandardItemModel(this);
table->setModel(m_entriesModel);
@ -99,7 +99,7 @@ RunCommandConfig::~RunCommandConfig()
void RunCommandConfig::exportCommands()
{
QString filePath = QFileDialog::getSaveFileName(this, i18n("Export Commands"), QDir::homePath(), QStringLiteral("JSON (*.json)"));
QString filePath = QFileDialog::getSaveFileName(widget(), i18n("Export Commands"), QDir::homePath(), QStringLiteral("JSON (*.json)"));
if (filePath.isEmpty())
return;
@ -124,7 +124,7 @@ void RunCommandConfig::exportCommands()
void RunCommandConfig::importCommands()
{
QString filePath = QFileDialog::getOpenFileName(this, i18n("Import Commands"), QDir::homePath(), QStringLiteral("JSON (*.json)"));
QString filePath = QFileDialog::getOpenFileName(widget(), i18n("Import Commands"), QDir::homePath(), QStringLiteral("JSON (*.json)"));
if (filePath.isEmpty())
return;
@ -155,7 +155,7 @@ void RunCommandConfig::importCommands()
insertRow(m_entriesModel->rowCount(), name, command);
}
Q_EMIT changed(true);
markAsChanged();
}
void RunCommandConfig::addSuggestedCommand(QMenu *menu, const QString &name, const QString &command)
@ -163,7 +163,7 @@ void RunCommandConfig::addSuggestedCommand(QMenu *menu, const QString &name, con
auto action = new QAction(name);
connect(action, &QAction::triggered, action, [this, name, command]() {
insertRow(0, name, command);
Q_EMIT changed(true);
markAsChanged();
});
menu->addAction(action);
}
@ -173,7 +173,7 @@ void RunCommandConfig::defaults()
KCModule::defaults();
m_entriesModel->removeRows(0, m_entriesModel->rowCount());
Q_EMIT changed(true);
markAsChanged();
}
void RunCommandConfig::load()
@ -201,12 +201,11 @@ void RunCommandConfig::load()
insertEmptyRow();
connect(m_entriesModel, &QAbstractItemModel::dataChanged, this, &RunCommandConfig::onDataChanged);
Q_EMIT changed(false);
}
void RunCommandConfig::save()
{
KCModule::save();
QJsonObject jsonConfig;
for (int i = 0; i < m_entriesModel->rowCount(); i++) {
QString key = m_entriesModel->item(i, 0)->data().toString();
@ -229,10 +228,6 @@ void RunCommandConfig::save()
QJsonDocument document;
document.setObject(jsonConfig);
config()->set(QStringLiteral("commands"), document.toJson(QJsonDocument::Compact));
KCModule::save();
Q_EMIT changed(false);
}
void RunCommandConfig::insertEmptyRow()
@ -252,7 +247,7 @@ void RunCommandConfig::insertRow(int i, const QString &name, const QString &comm
void RunCommandConfig::onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
Q_EMIT changed(true);
markAsChanged();
Q_UNUSED(topLeft);
if (bottomRight.row() == m_entriesModel->rowCount() - 1) {
// TODO check both entries are still empty

View file

@ -16,7 +16,7 @@ class RunCommandConfig : public KdeConnectPluginKcm
{
Q_OBJECT
public:
RunCommandConfig(QWidget *parent, const QVariantList &);
RunCommandConfig(QObject *parent, const QVariantList &);
~RunCommandConfig() override;
public Q_SLOTS:

View file

@ -13,14 +13,16 @@
K_PLUGIN_FACTORY(SendNotificationsConfigFactory, registerPlugin<SendNotificationsConfig>();)
SendNotificationsConfig::SendNotificationsConfig(QWidget *parent, const QVariantList &args)
SendNotificationsConfig::SendNotificationsConfig(QObject *parent, const QVariantList &args)
: KdeConnectPluginKcm(parent, args, QStringLiteral("kdeconnect_sendnotifications"))
, m_ui(new Ui::SendNotificationsConfigUi())
, appModel(new NotifyingApplicationModel)
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
qRegisterMetaTypeStreamOperators<NotifyingApplication>("NotifyingApplication");
#endif
m_ui->setupUi(this);
m_ui->setupUi(widget());
m_ui->appList->setIconSize(QSize(32, 32));
m_ui->appList->setModel(appModel);
@ -55,7 +57,7 @@ void SendNotificationsConfig::defaults()
m_ui->spin_urgency->setValue(0);
m_ui->check_body->setChecked(true);
m_ui->check_icons->setChecked(true);
Q_EMIT changed(true);
markAsChanged();
}
void SendNotificationsConfig::loadApplications()
@ -83,11 +85,11 @@ void SendNotificationsConfig::load()
m_ui->spin_urgency->setValue(urgency);
loadApplications();
Q_EMIT changed(false);
}
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());
@ -100,8 +102,6 @@ void SendNotificationsConfig::save()
list.append(QVariant::fromValue<NotifyingApplication>(a));
}
config()->setList(QStringLiteral("applications"), list);
KCModule::save();
Q_EMIT changed(false);
}
#include "sendnotifications_config.moc"

View file

@ -20,7 +20,7 @@ class SendNotificationsConfig : public KdeConnectPluginKcm
{
Q_OBJECT
public:
SendNotificationsConfig(QWidget *parent, const QVariantList &);
SendNotificationsConfig(QObject *parent, const QVariantList &);
~SendNotificationsConfig() override;
public Q_SLOTS:

View file

@ -124,7 +124,13 @@ bool SftpPlugin::startBrowsing()
bool SftpPlugin::receivePacket(const NetworkPacket &np)
{
if (!(fields_c - np.body().keys().toSet()).isEmpty() && !np.has(QStringLiteral("errorMessage"))) {
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
const auto keys = np.body().keys().toSet();
#else
const QStringList keysList = np.body().keys();
const auto keys = QSet(keysList.begin(), keysList.end());
#endif
if (!(fields_c - keys).isEmpty() && !np.has(QStringLiteral("errorMessage"))) {
// packet is invalid
return false;
}

View file

@ -14,11 +14,11 @@
K_PLUGIN_FACTORY(ShareConfigFactory, registerPlugin<ShareConfig>();)
ShareConfig::ShareConfig(QWidget *parent, const QVariantList &args)
ShareConfig::ShareConfig(QObject *parent, const QVariantList &args)
: KdeConnectPluginKcm(parent, args, QStringLiteral("kdeconnect_share"))
, m_ui(new Ui::ShareConfigUi())
{
m_ui->setupUi(this);
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."));
@ -37,7 +37,7 @@ void ShareConfig::defaults()
m_ui->kurlrequester->setText(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
Q_EMIT changed(true);
markAsChanged();
}
void ShareConfig::load()
@ -46,17 +46,12 @@ void ShareConfig::load()
const auto standardPath = QStandardPaths::writableLocation(QStandardPaths::DownloadLocation);
m_ui->kurlrequester->setText(config()->getString(QStringLiteral("incoming_path"), standardPath));
Q_EMIT changed(false);
}
void ShareConfig::save()
{
config()->set(QStringLiteral("incoming_path"), m_ui->kurlrequester->text());
KCModule::save();
Q_EMIT changed(false);
config()->set(QStringLiteral("incoming_path"), m_ui->kurlrequester->text());
}
#include "share_config.moc"

View file

@ -18,7 +18,7 @@ class ShareConfig : public KdeConnectPluginKcm
{
Q_OBJECT
public:
ShareConfig(QWidget *parent, const QVariantList &);
ShareConfig(QObject *parent, const QVariantList &);
~ShareConfig() override;
public Q_SLOTS:

View file

@ -28,3 +28,8 @@ target_link_libraries(kdeconnect_sms
KF${QT_MAJOR_VERSION}::Notifications
Qt::Widgets
)
if (QT_MAJOR_VERSION STREQUAL "6")
find_package(Qt6 REQUIRED COMPONENTS Core5Compat)
target_link_libraries(kdeconnect_sms Qt::Core5Compat) # for QTextCodec
endif()