Blame SOURCES/0002-KCM-SystemCheck-Add-NoUsableAdapter-error.patch

b668ef
From 6566e8d25e41eed5bf03124740320bc92caaca93 Mon Sep 17 00:00:00 2001
b668ef
From: David Rosca <nowrep@gmail.com>
b668ef
Date: Thu, 25 Dec 2014 18:04:10 +0100
b668ef
Subject: [PATCH 02/20] KCM SystemCheck: Add NoUsableAdapter error
b668ef
b668ef
Show "Your Bluetooth adapter is powered off" instead of
b668ef
"No Bluetooth adapters found" when there are adapters
b668ef
in system, but all of them powered off.
b668ef
b668ef
Also drop support to build with kdelibs < 4.7
b668ef
---
b668ef
 src/kcmodule/systemcheck.cpp | 143 ++++++++-----------------------------------
b668ef
 src/kcmodule/systemcheck.h   |  31 ++--------
b668ef
 2 files changed, 29 insertions(+), 145 deletions(-)
b668ef
b668ef
diff --git a/src/kcmodule/systemcheck.cpp b/src/kcmodule/systemcheck.cpp
b668ef
index 44c47e5..6ad75d2 100644
b668ef
--- a/src/kcmodule/systemcheck.cpp
b668ef
+++ b/src/kcmodule/systemcheck.cpp
b668ef
@@ -32,6 +32,7 @@
b668ef
 #include <kcolorscheme.h>
b668ef
 #include <kstandarddirs.h>
b668ef
 #include <klocalizedstring.h>
b668ef
+#include <kmessagewidget.h>
b668ef
 
b668ef
 #include <QtGui/QLabel>
b668ef
 #include <QtGui/QWidget>
b668ef
@@ -39,93 +40,12 @@
b668ef
 #include <QtGui/QBoxLayout>
b668ef
 #include <QtGui/QPaintEvent>
b668ef
 
b668ef
-#if KDE_IS_VERSION(4,6,41)
b668ef
-#include <kmessagewidget.h>
b668ef
-#else
b668ef
-
b668ef
-class ErrorWidget
b668ef
-    : public QWidget
b668ef
-{
b668ef
-public:
b668ef
-    ErrorWidget(QWidget *parent = 0);
b668ef
-    virtual ~ErrorWidget();
b668ef
-
b668ef
-    void setIcon(const QString &icon);
b668ef
-    void setText(const QString &reason);
b668ef
-    void addAction(KPushButton *action);
b668ef
-
b668ef
-protected:
b668ef
-    virtual void paintEvent(QPaintEvent *event);
b668ef
-
b668ef
-private:
b668ef
-    QLabel      *m_icon;
b668ef
-    QLabel      *m_reason;
b668ef
-    QHBoxLayout *m_actions;
b668ef
-};
b668ef
-
b668ef
-ErrorWidget::ErrorWidget(QWidget *parent)
b668ef
-    : QWidget(parent)
b668ef
-    , m_icon(new QLabel(this))
b668ef
-    , m_reason(new QLabel(this))
b668ef
-    , m_actions(new QHBoxLayout)
b668ef
-{
b668ef
-    setAutoFillBackground(false);
b668ef
-
b668ef
-    m_actions->addStretch();
b668ef
-
b668ef
-    QHBoxLayout *layout = new QHBoxLayout;
b668ef
-    layout->addWidget(m_icon);
b668ef
-    layout->addWidget(m_reason, 1);
b668ef
-
b668ef
-    QVBoxLayout *outter = new QVBoxLayout;
b668ef
-    outter->addLayout(layout);
b668ef
-    outter->addLayout(m_actions);
b668ef
-
b668ef
-    setLayout(outter);
b668ef
-}
b668ef
-
b668ef
-ErrorWidget::~ErrorWidget()
b668ef
-{
b668ef
-}
b668ef
-
b668ef
-void ErrorWidget::setIcon(const QString &icon)
b668ef
-{
b668ef
-    m_icon->setPixmap(KIconLoader::global()->loadIcon(icon, KIconLoader::Dialog));
b668ef
-}
b668ef
-
b668ef
-void ErrorWidget::setText(const QString &reason)
b668ef
-{
b668ef
-    m_reason->setText(reason);
b668ef
-}
b668ef
-
b668ef
-void ErrorWidget::addAction(KPushButton *action)
b668ef
-{
b668ef
-    action->setAutoFillBackground(false);
b668ef
-    m_actions->addWidget(action);
b668ef
-}
b668ef
-
b668ef
-void ErrorWidget::paintEvent(QPaintEvent *event)
b668ef
-{
b668ef
-    const QRect r = event->rect();
b668ef
-    const KColorScheme colorScheme(QPalette::Active, KColorScheme::Window);
b668ef
-
b668ef
-    QPainter p(this);
b668ef
-    p.setRenderHint(QPainter::Antialiasing);
b668ef
-
b668ef
-    QPainterPath path;
b668ef
-    path.addRoundedRect(0, 0, r.width(), r.height(), 10, 10);
b668ef
-    p.fillPath(path, colorScheme.background(KColorScheme::NegativeBackground));
b668ef
-
b668ef
-    QWidget::paintEvent(event);
b668ef
-}
b668ef
-#endif
b668ef
-////////////////////////////////////////////////////////////////////////////////////////////////////
b668ef
-
b668ef
 SystemCheck::SystemCheck(QWidget *parent)
b668ef
     : QObject(parent)
b668ef
     , m_kded(new KDED("org.kde.kded", "/kded", QDBusConnection::sessionBus()))
b668ef
     , m_parent(parent)
b668ef
     , m_noAdaptersError(0)
b668ef
+    , m_noUsableAdapterError(0)
b668ef
     , m_notDiscoverableAdapterError(0)
b668ef
     , m_disabledNotificationsError(0)
b668ef
 {
b668ef
@@ -133,9 +53,6 @@ SystemCheck::SystemCheck(QWidget *parent)
b668ef
 
b668ef
 SystemCheck::~SystemCheck()
b668ef
 {
b668ef
-    m_noAdaptersError = 0;
b668ef
-    m_notDiscoverableAdapterError = 0;
b668ef
-    m_disabledNotificationsError = 0;
b668ef
     delete m_kded;
b668ef
 }
b668ef
 
b668ef
@@ -145,18 +62,22 @@ void SystemCheck::createWarnings(QVBoxLayout *layout)
b668ef
         return;
b668ef
     }
b668ef
 
b668ef
-#if KDE_IS_VERSION(4,6,41)
b668ef
     m_noAdaptersError = new KMessageWidget(m_parent);
b668ef
     m_noAdaptersError->setMessageType(KMessageWidget::Error);
b668ef
     m_noAdaptersError->setCloseButtonVisible(false);
b668ef
-#else
b668ef
-    m_noAdaptersError = new ErrorWidget(m_parent);
b668ef
-    m_noAdaptersError->setIcon("window-close");
b668ef
-#endif
b668ef
     m_noAdaptersError->setText(i18n("No Bluetooth adapters have been found."));
b668ef
     layout->addWidget(m_noAdaptersError);
b668ef
 
b668ef
-#if KDE_IS_VERSION(4,6,41)
b668ef
+    m_noUsableAdapterError = new KMessageWidget(m_parent);
b668ef
+    m_noUsableAdapterError->setMessageType(KMessageWidget::Warning);
b668ef
+    m_noUsableAdapterError->setCloseButtonVisible(false);
b668ef
+    m_noUsableAdapterError->setText(i18n("Your Bluetooth adapter is powered off."));
b668ef
+
b668ef
+    KAction *fixNoUsableAdapter = new KAction(KIcon("dialog-ok-apply"), i18nc("Action to fix a problem", "Fix it"), m_noUsableAdapterError);
b668ef
+    connect(fixNoUsableAdapter, SIGNAL(triggered(bool)), this, SLOT(fixNoUsableAdapterError()));
b668ef
+    m_noUsableAdapterError->addAction(fixNoUsableAdapter);
b668ef
+    layout->addWidget(m_noUsableAdapterError);
b668ef
+
b668ef
     m_notDiscoverableAdapterError = new KMessageWidget(m_parent);
b668ef
     m_notDiscoverableAdapterError->setMessageType(KMessageWidget::Warning);
b668ef
     m_notDiscoverableAdapterError->setCloseButtonVisible(false);
b668ef
@@ -164,19 +85,10 @@ void SystemCheck::createWarnings(QVBoxLayout *layout)
b668ef
     KAction *fixNotDiscoverableAdapter = new KAction(KIcon("dialog-ok-apply"), i18nc("Action to fix a problem", "Fix it"), m_notDiscoverableAdapterError);
b668ef
     connect(fixNotDiscoverableAdapter, SIGNAL(triggered(bool)), this, SLOT(fixNotDiscoverableAdapterError()));
b668ef
     m_notDiscoverableAdapterError->addAction(fixNotDiscoverableAdapter);
b668ef
-#else
b668ef
-    m_notDiscoverableAdapterError = new ErrorWidget(m_parent);
b668ef
-    m_notDiscoverableAdapterError->setIcon("edit-find");
b668ef
-
b668ef
-    KPushButton *fixNotDiscoverableAdapter = new KPushButton(KIcon("dialog-ok-apply"), i18nc("Action to fix a problem", "Fix it"), m_notDiscoverableAdapterError);
b668ef
-    connect(fixNotDiscoverableAdapter, SIGNAL(clicked()), this, SLOT(fixNotDiscoverableAdapterError()));
b668ef
-    m_notDiscoverableAdapterError->addAction(fixNotDiscoverableAdapter);
b668ef
-#endif
b668ef
     m_notDiscoverableAdapterError->setText(i18n("Your default Bluetooth adapter is not visible for remote devices."));
b668ef
 
b668ef
     layout->addWidget(m_notDiscoverableAdapterError);
b668ef
 
b668ef
-#if KDE_IS_VERSION(4,6,41)
b668ef
     m_disabledNotificationsError = new KMessageWidget(m_parent);
b668ef
     m_disabledNotificationsError->setMessageType(KMessageWidget::Warning);
b668ef
     m_disabledNotificationsError->setCloseButtonVisible(false);
b668ef
@@ -184,19 +96,10 @@ void SystemCheck::createWarnings(QVBoxLayout *layout)
b668ef
     KAction *fixDisabledNotifications = new KAction(KIcon("dialog-ok-apply"), i18nc("Action to fix a problem", "Fix it"), m_disabledNotificationsError);
b668ef
     connect(fixDisabledNotifications, SIGNAL(triggered(bool)), this, SLOT(fixDisabledNotificationsError()));
b668ef
     m_disabledNotificationsError->addAction(fixDisabledNotifications);
b668ef
-#else
b668ef
-    m_disabledNotificationsError = new ErrorWidget(m_parent);
b668ef
-    m_disabledNotificationsError->setIcon("preferences-desktop-notification");
b668ef
-
b668ef
-    KPushButton *fixDisabledNotifications = new KPushButton(KIcon("dialog-ok-apply"), i18nc("Action to fix a problem", "Fix it"), m_disabledNotificationsError);
b668ef
-    connect(fixDisabledNotifications, SIGNAL(clicked()), this, SLOT(fixDisabledNotificationsError()));
b668ef
-    m_disabledNotificationsError->addAction(fixDisabledNotifications);
b668ef
-#endif
b668ef
     m_disabledNotificationsError->setText(i18n("Interaction with Bluetooth system is not optimal."));
b668ef
 
b668ef
     layout->addWidget(m_disabledNotificationsError);
b668ef
 
b668ef
-#if KDE_IS_VERSION(4,6,41)
b668ef
     m_noKDEDRunning = new KMessageWidget(m_parent);
b668ef
     m_noKDEDRunning ->setMessageType(KMessageWidget::Warning);
b668ef
     m_noKDEDRunning->setCloseButtonVisible(false);
b668ef
@@ -204,14 +107,6 @@ void SystemCheck::createWarnings(QVBoxLayout *layout)
b668ef
     KAction *fixNoKDEDRunning = new KAction(KIcon("dialog-ok-apply"), i18nc("Action to fix a problem", "Fix it"), m_noKDEDRunning);
b668ef
     connect(fixNoKDEDRunning, SIGNAL(triggered(bool)), this, SLOT(fixNoKDEDRunning()));
b668ef
     m_noKDEDRunning->addAction(fixNoKDEDRunning);
b668ef
-#else
b668ef
-    m_noKDEDRunning = new ErrorWidget(m_parent);
b668ef
-    m_noKDEDRunning->setIcon("dialog-warning");
b668ef
-
b668ef
-    KPushButton *fixNoKDEDRunning = new KPushButton(KIcon("dialog-ok-apply"), i18nc("Action to fix a problem", "Fix it"), m_noKDEDRunning);
b668ef
-    connect(fixNoKDEDRunning, SIGNAL(clicked()), this, SLOT(fixNoKDEDRunning()));
b668ef
-    m_noKDEDRunning->addAction(fixNoKDEDRunning);
b668ef
-#endif
b668ef
     m_noKDEDRunning->setText(i18n("Bluetooth is not completely enabled."));
b668ef
 
b668ef
     layout->addWidget(m_noKDEDRunning);
b668ef
@@ -259,6 +154,7 @@ void SystemCheck::updateInformationState()
b668ef
 {
b668ef
     m_noAdaptersError->setEnabled(true);
b668ef
     m_noAdaptersError->setVisible(false);
b668ef
+    m_noUsableAdapterError->setVisible(false);
b668ef
     m_notDiscoverableAdapterError->setVisible(false);
b668ef
     m_disabledNotificationsError->setVisible(false);
b668ef
     m_noKDEDRunning->setVisible(false);
b668ef
@@ -268,9 +164,14 @@ void SystemCheck::updateInformationState()
b668ef
         return;
b668ef
     }
b668ef
 
b668ef
+    if (BlueDevil::Manager::self()->adapters().isEmpty()) {
b668ef
+        m_noAdaptersError->setVisible(true);
b668ef
+        return;
b668ef
+    }
b668ef
+
b668ef
     BlueDevil::Adapter *const usableAdapter = BlueDevil::Manager::self()->usableAdapter();
b668ef
     if (!usableAdapter) {
b668ef
-        m_noAdaptersError->setVisible(true);
b668ef
+        m_noUsableAdapterError->setVisible(true);
b668ef
         return;
b668ef
     }
b668ef
     if (!usableAdapter->isDiscoverable()) {
b668ef
@@ -293,6 +194,12 @@ void SystemCheck::fixNoKDEDRunning()
b668ef
     m_kded->loadModule("bluedevil");
b668ef
 }
b668ef
 
b668ef
+void SystemCheck::fixNoUsableAdapterError()
b668ef
+{
b668ef
+    m_noUsableAdapterError->setVisible(false);
b668ef
+    BlueDevil::Manager::self()->adapters().first()->setPowered(true);
b668ef
+}
b668ef
+
b668ef
 void SystemCheck::fixNotDiscoverableAdapterError()
b668ef
 {
b668ef
     m_notDiscoverableAdapterError->setVisible(false);
b668ef
diff --git a/src/kcmodule/systemcheck.h b/src/kcmodule/systemcheck.h
b668ef
index e03daf9..ee94f7e 100644
b668ef
--- a/src/kcmodule/systemcheck.h
b668ef
+++ b/src/kcmodule/systemcheck.h
b668ef
@@ -22,19 +22,12 @@
b668ef
 #define BLUEDEVIL_SYSTEM_CHECK_H
b668ef
 #include <QtCore/QObject>
b668ef
 
b668ef
-#include <kdeversion.h>
b668ef
-
b668ef
 class QVBoxLayout;
b668ef
 
b668ef
 class KDED;
b668ef
-#if KDE_IS_VERSION(4,6,41)
b668ef
 class KMessageWidget;
b668ef
-#else
b668ef
-class ErrorWidget;
b668ef
-#endif
b668ef
 
b668ef
-class SystemCheck
b668ef
-    : public QObject
b668ef
+class SystemCheck : public QObject
b668ef
 {
b668ef
     Q_OBJECT
b668ef
 
b668ef
@@ -42,17 +35,6 @@ public:
b668ef
     SystemCheck(QWidget *parent);
b668ef
     virtual ~SystemCheck();
b668ef
 
b668ef
-    struct SystemCheckResult {
b668ef
-        enum Result {
b668ef
-            NoWarnings = 0,
b668ef
-            BluetoothDisabled,
b668ef
-            NoAdapters,
b668ef
-            NotificationsDisabled,
b668ef
-            DefaultAdapterHidden
b668ef
-        } result;
b668ef
-        QWidget *warningWidget;
b668ef
-    };
b668ef
-
b668ef
     void createWarnings(QVBoxLayout *layout);
b668ef
 
b668ef
     bool checkKDEDModuleLoaded();
b668ef
@@ -67,23 +49,18 @@ public Q_SLOTS:
b668ef
 
b668ef
 private Q_SLOTS:
b668ef
     void fixNoKDEDRunning();
b668ef
+    void fixNoUsableAdapterError();
b668ef
     void fixNotDiscoverableAdapterError();
b668ef
     void fixDisabledNotificationsError();
b668ef
 
b668ef
 private:
b668ef
     KDED        *m_kded;
b668ef
     QWidget     *m_parent;
b668ef
-#if KDE_IS_VERSION(4,6,41)
b668ef
     KMessageWidget *m_noAdaptersError;
b668ef
+    KMessageWidget *m_noUsableAdapterError;
b668ef
     KMessageWidget *m_noKDEDRunning;
b668ef
     KMessageWidget *m_notDiscoverableAdapterError;
b668ef
     KMessageWidget *m_disabledNotificationsError;
b668ef
-#else
b668ef
-    ErrorWidget *m_noAdaptersError;
b668ef
-    ErrorWidget *m_noKDEDRunning;
b668ef
-    ErrorWidget *m_notDiscoverableAdapterError;
b668ef
-    ErrorWidget *m_disabledNotificationsError;
b668ef
-#endif
b668ef
 };
b668ef
 
b668ef
-#endif //BLUEDEVIL_SYSTEM_CHECK_H
b668ef
\ No newline at end of file
b668ef
+#endif //BLUEDEVIL_SYSTEM_CHECK_H
b668ef
-- 
b668ef
2.1.0
b668ef