File indexing completed on 2024-05-12 05:28:35

0001 
0002 //////////////////////////////////////////////////////////////////////////////
0003 // breezedetectwidget.cpp
0004 // Note: this class is a stripped down version of
0005 // /kdebase/workspace/kwin/kcmkwin/kwinrules/detectwidget.cpp
0006 // SPDX-FileCopyrightText: 2004 Lubos Lunak <l.lunak@kde.org>
0007 // -------------------
0008 //
0009 // SPDX-FileCopyrightText: 2009 Hugo Pereira Da Costa <hugo.pereira@free.fr>
0010 //
0011 // SPDX-License-Identifier: MIT
0012 //////////////////////////////////////////////////////////////////////////////
0013 
0014 #include "breezedetectwidget.h"
0015 
0016 #include <QDBusConnection>
0017 #include <QDBusMessage>
0018 #include <QDBusPendingCallWatcher>
0019 #include <QDBusPendingReply>
0020 
0021 namespace Breeze
0022 {
0023 //_________________________________________________________
0024 DetectDialog::DetectDialog(QObject *parent)
0025     : QObject(parent)
0026 {
0027 }
0028 
0029 //_________________________________________________________
0030 void DetectDialog::detect()
0031 {
0032     QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.KWin"),
0033                                                           QStringLiteral("/KWin"),
0034                                                           QStringLiteral("org.kde.KWin"),
0035                                                           QStringLiteral("queryWindowInfo"));
0036 
0037     QDBusPendingReply<QVariantMap> asyncReply = QDBusConnection::sessionBus().asyncCall(message);
0038     QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(asyncReply, this);
0039     connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *self) {
0040         QDBusPendingReply<QVariantMap> reply = *self;
0041         self->deleteLater();
0042         if (!reply.isValid()) {
0043             Q_EMIT detectionDone(false);
0044             return;
0045         }
0046         m_properties = reply.value();
0047         Q_EMIT detectionDone(true);
0048     });
0049 }
0050 
0051 //_________________________________________________________
0052 QVariantMap DetectDialog::properties() const
0053 {
0054     return m_properties;
0055 }
0056 
0057 }