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