Commit ce73c50c authored by Xaver Hugl's avatar Xaver Hugl
Browse files

port to C++ smart pointers

parent 4d8f959f
Pipeline #184539 passed with stage
in 2 minutes and 40 seconds
......@@ -179,7 +179,7 @@ App::App(int &argc, char *argv[])
, m_watcher(new QDBusServiceWatcher(this))
{
m_syms = xcb_key_symbols_alloc(QX11Info::connection());
installNativeEventFilter(m_eventFilter.data());
installNativeEventFilter(m_eventFilter.get());
initIconMap(m_iconMap);
m_watcher->setConnection(QDBusConnection::sessionBus());
......
......@@ -16,6 +16,7 @@
#include <QGuiApplication>
#include <QMap>
#include <QPair>
#include <memory>
class QDBusServiceWatcher;
class XcbEventFilter : public QAbstractNativeEventFilter
......@@ -58,7 +59,7 @@ public Q_SLOTS:
bool grabXKeyboard();
private:
QScopedPointer<XcbEventFilter> m_eventFilter;
std::unique_ptr<XcbEventFilter> m_eventFilter;
bool m_init;
IBusBus *m_bus;
IBusPanelImpanel *m_impanel;
......
......@@ -10,6 +10,7 @@
#include <QAbstractListModel>
#include <QQmlParserStatus>
#include <memory>
#include <qwindowdefs.h>
#if HAVE_X11
......@@ -118,7 +119,7 @@ Q_SIGNALS:
private:
class Private;
QScopedPointer<Private> d;
std::unique_ptr<Private> d;
};
#endif
......@@ -8,6 +8,8 @@
#include "taskfilterproxymodel.h"
#include <memory>
class PagerModel;
class WindowModel : public TaskManager::TaskFilterProxyModel
......@@ -31,7 +33,7 @@ public:
private:
class Private;
QScopedPointer<Private> d;
std::unique_ptr<Private> d;
};
#endif
......@@ -36,7 +36,6 @@
#include <QMenu>
#include <QQuickItem>
#include <QQuickWindow>
#include <QScopedPointer>
#include <QStandardPaths>
#include <QTimer>
#include <QVersionNumber>
......@@ -260,7 +259,7 @@ QVariantList Backend::placesActions(const QUrl &launcherUrl, bool showAllPlaces,
QString previousGroup;
QMenu *subMenu = nullptr;
QScopedPointer<KFilePlacesModel> placesModel(new KFilePlacesModel());
std::unique_ptr<KFilePlacesModel> placesModel(new KFilePlacesModel());
for (int i = 0; i < placesModel->rowCount(); ++i) {
QModelIndex idx = placesModel->index(i, 0);
......
......@@ -14,15 +14,15 @@ using namespace SmartLauncher;
Item::Item(QObject *parent)
: QObject(parent)
{
m_backendPtr = s_backend.toStrongRef();
m_backendPtr = s_backend.lock();
if (!m_backendPtr) {
QSharedPointer<Backend> backendSharedPtr(new Backend);
s_backend = backendSharedPtr;
m_backendPtr = s_backend.toStrongRef();
auto ptr = std::make_shared<Backend>();
s_backend = ptr;
m_backendPtr = s_backend.lock();
}
}
QWeakPointer<Backend> Item::s_backend;
std::weak_ptr<Backend> Item::s_backend;
void Item::init()
{
......@@ -30,43 +30,43 @@ void Item::init()
return;
}
connect(m_backendPtr.data(), &Backend::reloadRequested, this, [this](const QString &uri) {
connect(m_backendPtr.get(), &Backend::reloadRequested, this, [this](const QString &uri) {
if (uri.isEmpty() || m_storageId == uri) {
populate();
}
});
connect(m_backendPtr.data(), &Backend::launcherRemoved, this, [this](const QString &uri) {
connect(m_backendPtr.get(), &Backend::launcherRemoved, this, [this](const QString &uri) {
if (uri.isEmpty() || m_storageId == uri) {
clear();
}
});
connect(m_backendPtr.data(), &Backend::countChanged, this, [this](const QString &uri, int count) {
connect(m_backendPtr.get(), &Backend::countChanged, this, [this](const QString &uri, int count) {
if (uri.isEmpty() || m_storageId == uri) {
setCount(count);
}
});
connect(m_backendPtr.data(), &Backend::countVisibleChanged, this, [this](const QString &uri, bool countVisible) {
connect(m_backendPtr.get(), &Backend::countVisibleChanged, this, [this](const QString &uri, bool countVisible) {
if (uri.isEmpty() || m_storageId == uri) {
setCountVisible(countVisible);
}
});
connect(m_backendPtr.data(), &Backend::progressChanged, this, [this](const QString &uri, int progress) {
connect(m_backendPtr.get(), &Backend::progressChanged, this, [this](const QString &uri, int progress) {
if (uri.isEmpty() || m_storageId == uri) {
setProgress(progress);
}
});
connect(m_backendPtr.data(), &Backend::progressVisibleChanged, this, [this](const QString &uri, bool progressVisible) {
connect(m_backendPtr.get(), &Backend::progressVisibleChanged, this, [this](const QString &uri, bool progressVisible) {
if (uri.isEmpty() || m_storageId == uri) {
setProgressVisible(progressVisible);
}
});
connect(m_backendPtr.data(), &Backend::urgentChanged, this, [this](const QString &uri, bool urgent) {
connect(m_backendPtr.get(), &Backend::urgentChanged, this, [this](const QString &uri, bool urgent) {
if (uri.isEmpty() || m_storageId == uri) {
setUrgent(urgent);
}
......
......@@ -8,7 +8,6 @@
#define SMARTLAUNCHER_ITEM_H
#include <QObject>
#include <QSharedPointer>
#include <QUrl>
#include <QWeakPointer>
......@@ -62,9 +61,9 @@ private:
void setProgressVisible(bool progressVisible);
void setUrgent(bool urgent);
static QWeakPointer<Backend> s_backend;
static std::weak_ptr<Backend> s_backend;
QSharedPointer<Backend> m_backendPtr;
std::shared_ptr<Backend> m_backendPtr;
QUrl m_launcherUrl;
QString m_storageId;
......
......@@ -11,6 +11,7 @@
#define __GLOBALPATHS_H
#include <KCModule>
#include <memory>
namespace Ui
{
......@@ -37,7 +38,7 @@ private Q_SLOTS:
private:
void setDefaultIndicatorVisible(KUrlRequester *widget, const QVariant &defaultValue);
QScopedPointer<Ui::DesktopPathsView> m_ui;
std::unique_ptr<Ui::DesktopPathsView> m_ui;
DesktopPathsData *const m_data;
};
......
......@@ -10,7 +10,7 @@
#define SHORTCUTSMODEL_H
#include <QAbstractItemModel>
#include <QScopedPointer>
#include <memory>
/*
* This class is based on KConcatenateRowsProxyModel adapted to handle trees with two levels.
......@@ -119,7 +119,7 @@ private:
private:
friend class ShortcutsModelPrivate;
const QScopedPointer<ShortcutsModelPrivate> d;
const std::unique_ptr<ShortcutsModelPrivate> d;
};
#endif
......@@ -9,6 +9,7 @@
#include <KCModule>
#include <KConfigGroup>
#include <KSharedConfig>
#include <memory>
namespace Ui
{
......@@ -32,6 +33,6 @@ public:
~KCMQtQuickSettingsModule() override;
private:
QScopedPointer<Ui::KCMQtQuickSettingsWidget> m_ui;
QScopedPointer<PlasmaQtQuickSettings::RendererSettings> m_settings;
std::unique_ptr<Ui::KCMQtQuickSettingsWidget> m_ui;
std::unique_ptr<PlasmaQtQuickSettings::RendererSettings> m_settings;
};
......@@ -72,7 +72,7 @@ int main(int argc, char *argv[])
return 1;
}
QScopedPointer<AbstractJob> job;
std::unique_ptr<AbstractJob> job;
QFileInfo fileInfo(file);
const QString mimeType = QMimeDatabase().mimeTypeForFile(fileInfo).name();
if (mimeType == QLatin1String("application/x-rpm") && KOSRelease().idLike().contains(u"suse")) {
......@@ -88,7 +88,7 @@ int main(int argc, char *argv[])
}
QObject::connect(
job.data(),
job.get(),
&AbstractJob::finished,
qApp,
[]() {
......@@ -96,7 +96,7 @@ int main(int argc, char *argv[])
},
Qt::QueuedConnection);
QObject::connect(
job.data(),
job.get(),
&AbstractJob::error,
qApp,
[](const QString &error) {
......
......@@ -20,7 +20,7 @@ bool InputDevice::Prop<T>::save()
return false;
}
auto iface = m_device->m_iface.data();
auto iface = m_device->m_iface.get();
const bool ret = m_prop.write(iface, *m_value);
if (ret) {
m_configValue = *m_value;
......
......@@ -111,7 +111,7 @@ private:
T value() const
{
if (!m_value.has_value()) {
auto iface = m_device->m_iface.data();
auto iface = m_device->m_iface.get();
if (isSupported()) {
m_value = m_prop.read(iface).value<T>();
}
......@@ -133,7 +133,7 @@ private:
void set(T newVal);
T defaultValue() const
{
return m_defaultValueFunction ? (m_device->m_iface.data()->*m_defaultValueFunction)() : T();
return m_defaultValueFunction ? (m_device->m_iface.get()->*m_defaultValueFunction)() : T();
}
bool changed() const;
void set(const Prop<T> &p)
......@@ -143,7 +143,7 @@ private:
bool isSupported() const
{
auto iface = m_device->m_iface.data();
auto iface = m_device->m_iface.get();
return !m_supportedFunction || (iface->*m_supportedFunction)();
}
......@@ -177,7 +177,7 @@ private:
Prop<int>(this, "orientationDBus", nullptr, &OrgKdeKWinInputDeviceInterface::supportsCalibrationMatrix, &InputDevice::orientationChanged);
Prop<QString> m_outputName = Prop<QString>(this, "outputName", nullptr, nullptr, &InputDevice::outputNameChanged);
QScopedPointer<OrgKdeKWinInputDeviceInterface> m_iface;
std::unique_ptr<OrgKdeKWinInputDeviceInterface> m_iface;
};
#endif // KWINWAYLANDDEVICE_H
/*
SPDX-FileCopyrightText: 2022 Xaver Hugl <xaver.hugl@gmail.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
struct CDeleter {
template<typename T>
void operator()(T *ptr)
{
if (ptr) {
free(ptr);
}
};
};
......@@ -345,7 +345,7 @@ int LibinputTouchpad::touchpadOff()
XcbAtom &LibinputTouchpad::touchpadOffAtom()
{
return *m_atoms[QLatin1String(LIBINPUT_PROP_SENDEVENTS_ENABLED)].data();
return *m_atoms[QLatin1String(LIBINPUT_PROP_SENDEVENTS_ENABLED)].get();
}
template<typename T>
......
......@@ -46,7 +46,7 @@ PropertyInfo::PropertyInfo(Display *display, int device, Atom prop, Atom floatTy
unsigned char *dataPtr = nullptr;
unsigned long bytes_after;
XIGetProperty(display, device, prop, 0, 1000, False, AnyPropertyType, &type, &format, &nitems, &bytes_after, &dataPtr);
data = QSharedPointer<unsigned char>(dataPtr, XDeleter);
data = std::shared_ptr<unsigned char>(dataPtr, XDeleter);
if (format == CHAR_BIT && type == XA_INTEGER) {
b = reinterpret_cast<char *>(dataPtr);
......@@ -81,5 +81,5 @@ QVariant PropertyInfo::value(unsigned offset) const
void PropertyInfo::set()
{
XIChangeProperty(display, device, prop, type, format, XIPropModeReplace, data.data(), nitems);
XIChangeProperty(display, device, prop, type, format, XIPropModeReplace, data.get(), nitems);
}
......@@ -7,20 +7,21 @@
#ifndef PROPERTYINFO_H
#define PROPERTYINFO_H
#include <QSharedPointer>
#include <QVersionNumber>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QX11Info>
#else
#include <QtGui/private/qtx11extras_p.h>
#endif
#include <X11/Xdefs.h>
#include <memory>
void XDeleter(void *p);
struct PropertyInfo {
Atom type;
int format;
QSharedPointer<unsigned char> data;
std::shared_ptr<unsigned char> data;
unsigned long nitems;
float *f;
......
......@@ -32,7 +32,7 @@
#include <xserver-properties.h>
struct DeviceListDeleter {
static void cleanup(XDeviceInfo *p)
void operator()(XDeviceInfo *p)
{
if (p) {
XFreeDeviceList(p);
......@@ -40,7 +40,7 @@ struct DeviceListDeleter {
}
};
void XlibBackend::XDisplayCleanup::cleanup(Display *p)
void XlibBackend::XDisplayCleanup::operator()(Display *p)
{
if (p) {
XCloseDisplay(p);
......@@ -67,7 +67,7 @@ XlibBackend::XlibBackend(QObject *parent)
, m_connection(nullptr)
{
if (m_display) {
m_connection = XGetXCBConnection(m_display.data());
m_connection = XGetXCBConnection(m_display.get());
}
if (!m_connection) {
......@@ -94,28 +94,29 @@ XlibBackend::XlibBackend(QObject *parent)
XlibTouchpad *XlibBackend::findTouchpad()
{
int nDevices = 0;
QScopedPointer<XDeviceInfo, DeviceListDeleter> deviceInfo(XListInputDevices(m_display.data(), &nDevices));
std::unique_ptr<XDeviceInfo, DeviceListDeleter> deviceInfo(XListInputDevices(m_display.get(), &nDevices));
for (XDeviceInfo *info = deviceInfo.data(); info < deviceInfo.data() + nDevices; info++) {
for (XDeviceInfo *info = deviceInfo.get(); info < deviceInfo.get() + nDevices; info++) {
// Make sure device is touchpad
if (info->type != m_touchpadAtom.atom()) {
continue;
}
int nProperties = 0;
QSharedPointer<Atom> properties(XIListProperties(m_display.data(), info->id, &nProperties), XDeleter);
std::shared_ptr<Atom> properties(XIListProperties(m_display.get(), info->id, &nProperties), XDeleter);
Atom *atom = properties.data(), *atomEnd = properties.data() + nProperties;
Atom *atom = properties.get();
Atom *atomEnd = properties.get() + nProperties;
for (; atom != atomEnd; atom++) {
#if HAVE_XORGLIBINPUT
if (*atom == m_libinputIdentifierAtom.atom()) {
setMode(TouchpadInputBackendMode::XLibinput);
return new LibinputTouchpad(m_display.data(), info->id);
return new LibinputTouchpad(m_display.get(), info->id);
}
#endif
#if HAVE_SYNAPTICS
if (*atom == m_synapticsIdentifierAtom.atom()) {
setMode(TouchpadInputBackendMode::XSynaptics);
return new SynapticsTouchpad(m_display.data(), info->id);
return new SynapticsTouchpad(m_display.get(), info->id);
}
#endif
}
......@@ -243,7 +244,7 @@ void XlibBackend::setTouchpadOff(TouchpadBackend::TouchpadOffState state)
bool XlibBackend::isTouchpadAvailable()
{
return !m_device.isNull();
return m_device != nullptr;
}
bool XlibBackend::isTouchpadEnabled()
......@@ -288,7 +289,7 @@ void XlibBackend::devicePlugged(int device)
if (m_device) {
qWarning() << "Touchpad reset";
m_notifications.reset();
watchForEvents(!m_keyboard.isNull());
watchForEvents(m_keyboard != nullptr);
Q_EMIT touchpadReset();
}
}
......@@ -307,9 +308,9 @@ void XlibBackend::propertyChanged(xcb_atom_t prop)
QStringList XlibBackend::listMouses(const QStringList &blacklist)
{
int nDevices = 0;
QScopedPointer<XDeviceInfo, DeviceListDeleter> info(XListInputDevices(m_display.data(), &nDevices));
std::unique_ptr<XDeviceInfo, DeviceListDeleter> info(XListInputDevices(m_display.get(), &nDevices));
QStringList list;
for (XDeviceInfo *i = info.data(); i != info.data() + nDevices; i++) {
for (XDeviceInfo *i = info.get(); i != info.get() + nDevices; i++) {
if (m_device && i->id == static_cast<XID>(m_device->deviceId())) {
continue;
}
......@@ -325,7 +326,7 @@ QStringList XlibBackend::listMouses(const QStringList &blacklist)
if (blacklist.contains(name, Qt::CaseInsensitive)) {
continue;
}
PropertyInfo enabled(m_display.data(), i->id, m_enabledAtom.atom(), 0);
PropertyInfo enabled(m_display.get(), i->id, m_enabledAtom.atom(), 0);
if (enabled.value(0) == false) {
continue;
}
......@@ -340,14 +341,14 @@ QVector<QObject *> XlibBackend::getDevices() const
QVector<QObject *> touchpads;
#if HAVE_XORGLIBINPUT
LibinputTouchpad *libinputtouchpad = dynamic_cast<LibinputTouchpad *>(m_device.data());
LibinputTouchpad *libinputtouchpad = dynamic_cast<LibinputTouchpad *>(m_device.get());
if (libinputtouchpad) {
touchpads.push_back(libinputtouchpad);
}
#endif
#if HAVE_SYNAPTICS
SynapticsTouchpad *synaptics = dynamic_cast<SynapticsTouchpad *>(m_device.data());
SynapticsTouchpad *synaptics = dynamic_cast<SynapticsTouchpad *>(m_device.get());
if (synaptics) {
touchpads.push_back(synaptics);
}
......@@ -359,13 +360,13 @@ QVector<QObject *> XlibBackend::getDevices() const
void XlibBackend::watchForEvents(bool keyboard)
{
if (!m_notifications) {
m_notifications.reset(new XlibNotifications(m_display.data(), m_device ? m_device->deviceId() : XIAllDevices));
connect(m_notifications.data(), SIGNAL(devicePlugged(int)), SLOT(devicePlugged(int)));
connect(m_notifications.data(), SIGNAL(touchpadDetached()), SLOT(touchpadDetached()));
connect(m_notifications.data(), SIGNAL(propertyChanged(xcb_atom_t)), SLOT(propertyChanged(xcb_atom_t)));
m_notifications.reset(new XlibNotifications(m_display.get(), m_device ? m_device->deviceId() : XIAllDevices));
connect(m_notifications.get(), SIGNAL(devicePlugged(int)), SLOT(devicePlugged(int)));
connect(m_notifications.get(), SIGNAL(touchpadDetached()), SLOT(touchpadDetached()));
connect(m_notifications.get(), SIGNAL(propertyChanged(xcb_atom_t)), SLOT(propertyChanged(xcb_atom_t)));
}
if (keyboard == !m_keyboard.isNull()) {
if (keyboard == (m_keyboard != nullptr)) {
return;
}
......@@ -374,7 +375,7 @@ void XlibBackend::watchForEvents(bool keyboard)
return;
}
m_keyboard.reset(new XRecordKeyboardMonitor(m_display.data()));
connect(m_keyboard.data(), SIGNAL(keyboardActivityStarted()), SIGNAL(keyboardActivityStarted()));
connect(m_keyboard.data(), SIGNAL(keyboardActivityFinished()), SIGNAL(keyboardActivityFinished()));
m_keyboard.reset(new XRecordKeyboardMonitor(m_display.get()));
connect(m_keyboard.get(), SIGNAL(keyboardActivityStarted()), SIGNAL(keyboardActivityStarted()));
connect(m_keyboard.get(), SIGNAL(keyboardActivityFinished()), SIGNAL(keyboardActivityFinished()));
}
......@@ -9,9 +9,7 @@
#include <QLatin1String>
#include <QMap>
#include <QScopedPointer>
#include <QSet>
#include <QSharedPointer>
#include <QStringList>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <QX11Info>
......@@ -83,10 +81,10 @@ protected:
explicit XlibBackend(QObject *parent);
struct XDisplayCleanup {
static void cleanup(Display *);
void operator()(Display *);
};
QScopedPointer<Display, XDisplayCleanup> m_display;
std::unique_ptr<Display, XDisplayCleanup> m_display;
xcb_connection_t *m_connection;
XcbAtom m_enabledAtom, m_mouseAtom, m_keyboardAtom, m_touchpadAtom;
......@@ -94,11 +92,11 @@ protected:
XcbAtom m_libinputIdentifierAtom;
XlibTouchpad *findTouchpad();
QScopedPointer<XlibTouchpad> m_device;
std::unique_ptr<XlibTouchpad> m_device;
QString m_errorString;
QScopedPointer<XlibNotifications> m_notifications;
QScopedPointer<XRecordKeyboardMonitor> m_keyboard;
std::unique_ptr<XlibNotifications> m_notifications;
std::unique_ptr<XRecordKeyboardMonitor> m_keyboard;
};
#endif // XLIBBACKEND_H
......@@ -5,6 +5,7 @@
*/
#include "xlibnotifications.h"
#include "c_ptr.h"
#include <cstring>
......@@ -22,7 +23,7 @@ XlibNotifications::XlibNotifications(Display *display, int device)
m_notifier = new QSocketNotifier(xcb_get_file_descriptor(m_connection), QSocketNotifier::Read, this);
xcb_query_extension_cookie_t inputExtCookie = xcb_query_extension(m_connection, std::strlen(INAME), INAME);
QScopedPointer<xcb_query_extension_reply_t, QScopedPointerPodDeleter> inputExt(xcb_query_extension_reply(m_connection, inputExtCookie, nullptr));
std::unique_ptr<xcb_query_extension_reply_t, CDeleter> inputExt(xcb_query_extension_reply(m_connection, inputExtCookie, nullptr));
if (!inputExt) {
return;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment