Blame SOURCES/0007-wizard-Add-Success-page.patch

a562b3
From 725524d8e23fbc5fad9aab00cbaa3d66589baf14 Mon Sep 17 00:00:00 2001
a562b3
From: David Rosca <nowrep@gmail.com>
a562b3
Date: Wed, 31 Dec 2014 12:07:56 +0100
a562b3
Subject: [PATCH 07/20] wizard: Add Success page
a562b3
a562b3
Instead of closing the wizard, show a final page
a562b3
to user to indicate the pairing was completed successfully.
a562b3
---
a562b3
 src/wizard/CMakeLists.txt      |  2 ++
a562b3
 src/wizard/bluewizard.cpp      |  2 ++
a562b3
 src/wizard/bluewizard.h        |  2 +-
a562b3
 src/wizard/pages/fail.cpp      |  2 ++
a562b3
 src/wizard/pages/fail.ui       | 10 +++++++
a562b3
 src/wizard/pages/nopairing.cpp | 46 +++++++++++-----------------
a562b3
 src/wizard/pages/nopairing.h   | 10 +++----
a562b3
 src/wizard/pages/success.cpp   | 64 +++++++++++++++++++++++++++++++++++++++
a562b3
 src/wizard/pages/success.h     | 46 ++++++++++++++++++++++++++++
a562b3
 src/wizard/pages/success.ui    | 68 ++++++++++++++++++++++++++++++++++++++++++
a562b3
 10 files changed, 216 insertions(+), 36 deletions(-)
a562b3
 create mode 100644 src/wizard/pages/success.cpp
a562b3
 create mode 100644 src/wizard/pages/success.h
a562b3
 create mode 100644 src/wizard/pages/success.ui
a562b3
a562b3
diff --git a/src/wizard/CMakeLists.txt b/src/wizard/CMakeLists.txt
a562b3
index 847e672..f2ada0f 100644
a562b3
--- a/src/wizard/CMakeLists.txt
a562b3
+++ b/src/wizard/CMakeLists.txt
a562b3
@@ -10,6 +10,7 @@ set(wizard_SRCS
a562b3
     pages/keyboardpairing.cpp
a562b3
     pages/ssppairing.cpp
a562b3
     pages/fail.cpp
a562b3
+    pages/success.cpp
a562b3
 )
a562b3
 
a562b3
 kde4_add_ui_files(wizard_SRCS
a562b3
@@ -19,6 +20,7 @@ kde4_add_ui_files(wizard_SRCS
a562b3
             pages/keyboardpairing.ui
a562b3
             pages/ssppairing.ui
a562b3
             pages/fail.ui
a562b3
+            pages/success.ui
a562b3
 )
a562b3
 
a562b3
 kde4_add_executable(bluedevil-wizard ${wizard_SRCS})
a562b3
diff --git a/src/wizard/bluewizard.cpp b/src/wizard/bluewizard.cpp
a562b3
index de241b0..91cb28f 100644
a562b3
--- a/src/wizard/bluewizard.cpp
a562b3
+++ b/src/wizard/bluewizard.cpp
a562b3
@@ -24,6 +24,7 @@
a562b3
 #include "pages/legacypairingdatabase.h"
a562b3
 #include "pages/keyboardpairing.h"
a562b3
 #include "pages/ssppairing.h"
a562b3
+#include "pages/success.h"
a562b3
 #include "pages/fail.h"
a562b3
 
a562b3
 #include <QApplication>
a562b3
@@ -57,6 +58,7 @@ BlueWizard::BlueWizard(const KUrl &url) : QWizard(), m_device(0), m_manualPin(fa
a562b3
     setPage(LegacyPairingDatabase, new LegacyPairingPageDatabase(this));
a562b3
     setPage(KeyboardPairing, new KeyboardPairingPage(this));
a562b3
     setPage(SSPPairing, new SSPPairingPage(this));
a562b3
+    setPage(Success, new SuccessPage(this));
a562b3
     setPage(Fail, new FailPage(this));
a562b3
 
a562b3
     setButton(QWizard::BackButton, new KPushButton(KStandardGuiItem::back(KStandardGuiItem::UseRTL)));
a562b3
diff --git a/src/wizard/bluewizard.h b/src/wizard/bluewizard.h
a562b3
index fcb2015..4685aca 100644
a562b3
--- a/src/wizard/bluewizard.h
a562b3
+++ b/src/wizard/bluewizard.h
a562b3
@@ -53,7 +53,7 @@ public:
a562b3
 
a562b3
     WizardAgent* agent() const;
a562b3
 
a562b3
-    enum {Discover, NoPairing, LegacyPairing, LegacyPairingDatabase, KeyboardPairing, SSPPairing, Fail, Connect};
a562b3
+    enum {Discover, NoPairing, LegacyPairing, LegacyPairingDatabase, KeyboardPairing, SSPPairing, Success, Fail, Connect};
a562b3
 
a562b3
 public Q_SLOTS:
a562b3
     void restartWizard();
a562b3
diff --git a/src/wizard/pages/fail.cpp b/src/wizard/pages/fail.cpp
a562b3
index f7c065e..e9f44ef 100644
a562b3
--- a/src/wizard/pages/fail.cpp
a562b3
+++ b/src/wizard/pages/fail.cpp
a562b3
@@ -37,6 +37,8 @@ FailPage::FailPage(BlueWizard* parent) : QWizardPage(parent)
a562b3
 , m_wizard(parent)
a562b3
 {
a562b3
     setupUi(this);
a562b3
+
a562b3
+    failIcon->setPixmap(KIcon("task-reject").pixmap(48));
a562b3
 }
a562b3
 
a562b3
 void FailPage::initializePage()
a562b3
diff --git a/src/wizard/pages/fail.ui b/src/wizard/pages/fail.ui
a562b3
index 0470e8f..375a4fb 100644
a562b3
--- a/src/wizard/pages/fail.ui
a562b3
+++ b/src/wizard/pages/fail.ui
a562b3
@@ -30,6 +30,16 @@
a562b3
       </spacer>
a562b3
      </item>
a562b3
      <item>
a562b3
+      <widget class="QLabel" name="failIcon">
a562b3
+       <property name="maximumSize">
a562b3
+        <size>
a562b3
+         <width>48</width>
a562b3
+         <height>48</height>
a562b3
+        </size>
a562b3
+       </property>
a562b3
+      </widget>
a562b3
+     </item>
a562b3
+     <item>
a562b3
       <widget class="QLabel" name="failLbl">
a562b3
        <property name="text">
a562b3
         <string/>
a562b3
diff --git a/src/wizard/pages/nopairing.cpp b/src/wizard/pages/nopairing.cpp
a562b3
index 65be653..c169a49 100644
a562b3
--- a/src/wizard/pages/nopairing.cpp
a562b3
+++ b/src/wizard/pages/nopairing.cpp
a562b3
@@ -32,9 +32,10 @@
a562b3
 
a562b3
 using namespace BlueDevil;
a562b3
 
a562b3
-NoPairingPage::NoPairingPage(BlueWizard* parent) : QWizardPage(parent)
a562b3
-, m_validPage(false)
a562b3
-, m_wizard(parent)
a562b3
+NoPairingPage::NoPairingPage(BlueWizard *parent)
a562b3
+    : QWizardPage(parent)
a562b3
+    , m_success(false)
a562b3
+    , m_wizard(parent)
a562b3
 {
a562b3
     setupUi(this);
a562b3
     m_working = new KPixmapSequenceOverlayPainter(this);
a562b3
@@ -42,6 +43,14 @@ NoPairingPage::NoPairingPage(BlueWizard* parent) : QWizardPage(parent)
a562b3
     m_working->start();
a562b3
 }
a562b3
 
a562b3
+int NoPairingPage::nextId() const
a562b3
+{
a562b3
+    if (m_success) {
a562b3
+        return BlueWizard::Success;
a562b3
+    }
a562b3
+    return BlueWizard::Fail;
a562b3
+}
a562b3
+
a562b3
 void NoPairingPage::initializePage()
a562b3
 {
a562b3
     kDebug();
a562b3
@@ -49,10 +58,6 @@ void NoPairingPage::initializePage()
a562b3
 
a562b3
     connecting->setText(connecting->text().append(m_wizard->device()->name()));
a562b3
 
a562b3
-    //It can happen that the device is technically connected and trusted but we are not connected
a562b3
-    //to the profile. We have no way to know if the profile was activated or not so we have to relay
a562b3
-    //on a timeout (10s)
a562b3
-    QTimer::singleShot(10000, this, SLOT(timeout()));
a562b3
     connect(m_wizard->device(), SIGNAL(connectedChanged(bool)), SLOT(connectedChanged(bool)));
a562b3
     connect(m_wizard->device(), SIGNAL(trustedChanged(bool)), SLOT(connectedChanged(bool)));
a562b3
 
a562b3
@@ -60,30 +65,14 @@ void NoPairingPage::initializePage()
a562b3
     m_wizard->device()->setTrusted(true);
a562b3
 }
a562b3
 
a562b3
-void NoPairingPage::timeout()
a562b3
-{
a562b3
-    connectedChanged(true);
a562b3
-}
a562b3
-
a562b3
 void NoPairingPage::connectedChanged(bool connected)
a562b3
 {
a562b3
-    kDebug();
a562b3
-
a562b3
-    m_validPage = connected;
a562b3
-    if (m_validPage) {
a562b3
-        kDebug() << "Done";
a562b3
-        m_wizard->done(0);
a562b3
-    }
a562b3
-}
a562b3
-
a562b3
-bool NoPairingPage::validatePage()
a562b3
-{
a562b3
-    return m_validPage;
a562b3
-}
a562b3
+    kDebug() << "Connect finished" << connected;
a562b3
 
a562b3
-int NoPairingPage::nextId() const
a562b3
-{
a562b3
-    return -1;
a562b3
+    // Connect may fail but that doesn't really mean the device was setup incorrectly
a562b3
+    // Device::connectDevice will fail eg. when A2DP profile could not be connected due to missing pulseaudio plugin
a562b3
+    m_success = true;
a562b3
+    QTimer::singleShot(500, m_wizard, SLOT(next()));
a562b3
 }
a562b3
 
a562b3
 QList<QWizard::WizardButton> NoPairingPage::wizardButtonsLayout() const
a562b3
@@ -91,6 +80,5 @@ QList<QWizard::WizardButton> NoPairingPage::wizardButtonsLayout() const
a562b3
     QList <QWizard::WizardButton> list;
a562b3
     list << QWizard::Stretch;
a562b3
     list << QWizard::CancelButton;
a562b3
-
a562b3
     return list;
a562b3
 }
a562b3
diff --git a/src/wizard/pages/nopairing.h b/src/wizard/pages/nopairing.h
a562b3
index 9b9f4bf..ca03fb8 100644
a562b3
--- a/src/wizard/pages/nopairing.h
a562b3
+++ b/src/wizard/pages/nopairing.h
a562b3
@@ -46,21 +46,19 @@ Q_OBJECT
a562b3
 public:
a562b3
     NoPairingPage(BlueWizard* parent = 0);
a562b3
 
a562b3
-    virtual void initializePage();
a562b3
-    virtual bool validatePage();
a562b3
     virtual int nextId() const;
a562b3
+    virtual void initializePage();
a562b3
 
a562b3
 protected:
a562b3
     QList <QWizard::WizardButton> wizardButtonsLayout() const;
a562b3
 
a562b3
 private Q_SLOTS:
a562b3
-    void timeout();
a562b3
     void connectedChanged(bool connected);
a562b3
 
a562b3
 private:
a562b3
-    bool                          m_validPage;
a562b3
-    BlueWizard                    *m_wizard;
a562b3
+    bool m_success;
a562b3
+    BlueWizard *m_wizard;
a562b3
     KPixmapSequenceOverlayPainter *m_working;
a562b3
 };
a562b3
 
a562b3
-#endif // NOPAIRING_H
a562b3
\ No newline at end of file
a562b3
+#endif // NOPAIRING_H
a562b3
diff --git a/src/wizard/pages/success.cpp b/src/wizard/pages/success.cpp
a562b3
new file mode 100644
a562b3
index 0000000..44b70fa
a562b3
--- /dev/null
a562b3
+++ b/src/wizard/pages/success.cpp
a562b3
@@ -0,0 +1,64 @@
a562b3
+/*****************************************************************************
a562b3
+ * This file is part of the KDE project                                      *
a562b3
+ *                                                                           *
a562b3
+ * Copyright (C) 2010 Alejandro Fiestas Olivares <afiestas@kde.org>          *
a562b3
+ * Copyright (C) 2010-2011 UFO Coders <info@ufocoders.com>                   *
a562b3
+ * Copyright (C) 2014 David Rosca <nowrep@gmail.com>                         *
a562b3
+ *                                                                           *
a562b3
+ * This library is free software; you can redistribute it and/or             *
a562b3
+ * modify it under the terms of the GNU Library General Public               *
a562b3
+ * License as published by the Free Software Foundation; either              *
a562b3
+ * version 2 of the License, or (at your option) any later version.          *
a562b3
+ *                                                                           *
a562b3
+ * This library is distributed in the hope that it will be useful,           *
a562b3
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
a562b3
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
a562b3
+ * Library General Public License for more details.                          *
a562b3
+ *                                                                           *
a562b3
+ * You should have received a copy of the GNU Library General Public License *
a562b3
+ * along with this library; see the file COPYING.LIB.  If not, write to      *
a562b3
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,      *
a562b3
+ * Boston, MA 02110-1301, USA.                                               *
a562b3
+ *****************************************************************************/
a562b3
+
a562b3
+#include "success.h"
a562b3
+#include "bluewizard.h"
a562b3
+
a562b3
+#include <KDebug>
a562b3
+#include <KLocalizedString>
a562b3
+
a562b3
+#include <bluedevil/bluedevildevice.h>
a562b3
+
a562b3
+SuccessPage::SuccessPage(BlueWizard *parent)
a562b3
+    : QWizardPage(parent)
a562b3
+    , m_wizard(parent)
a562b3
+{
a562b3
+    setupUi(this);
a562b3
+
a562b3
+    successIcon->setPixmap(KIcon("task-complete").pixmap(48));
a562b3
+}
a562b3
+
a562b3
+void SuccessPage::initializePage()
a562b3
+{
a562b3
+    kDebug() << "Initialize Success Page";
a562b3
+
a562b3
+    QList<QWizard::WizardButton> list;
a562b3
+    list << QWizard::Stretch;
a562b3
+    list << QWizard::FinishButton;
a562b3
+
a562b3
+    m_wizard->setButtonLayout(list);
a562b3
+
a562b3
+    setFinalPage(true);
a562b3
+
a562b3
+    QString deviceName = m_wizard->device()->name();
a562b3
+    if (deviceName.isEmpty()) {
a562b3
+        successLbl->setText(i18nc("This string is shown when the wizard succeeds", "The setup of the device has succeeded"));
a562b3
+    } else {
a562b3
+        successLbl->setText(i18n("The setup of %1 has succeeded", deviceName));
a562b3
+    }
a562b3
+}
a562b3
+
a562b3
+int SuccessPage::nextId() const
a562b3
+{
a562b3
+    return -1;
a562b3
+}
a562b3
diff --git a/src/wizard/pages/success.h b/src/wizard/pages/success.h
a562b3
new file mode 100644
a562b3
index 0000000..a41f73e
a562b3
--- /dev/null
a562b3
+++ b/src/wizard/pages/success.h
a562b3
@@ -0,0 +1,46 @@
a562b3
+/*****************************************************************************
a562b3
+ * This file is part of the KDE project                                      *
a562b3
+ *                                                                           *
a562b3
+ * Copyright (C) 2010 Alejandro Fiestas Olivares <afiestas@kde.org>          *
a562b3
+ * Copyright (C) 2010-2011 UFO Coders <info@ufocoders.com>                   *
a562b3
+ * Copyright (C) 2014 David Rosca <nowrep@gmail.com>                         *
a562b3
+ *                                                                           *
a562b3
+ * This library is free software; you can redistribute it and/or             *
a562b3
+ * modify it under the terms of the GNU Library General Public               *
a562b3
+ * License as published by the Free Software Foundation; either              *
a562b3
+ * version 2 of the License, or (at your option) any later version.          *
a562b3
+ *                                                                           *
a562b3
+ * This library is distributed in the hope that it will be useful,           *
a562b3
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
a562b3
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
a562b3
+ * Library General Public License for more details.                          *
a562b3
+ *                                                                           *
a562b3
+ * You should have received a copy of the GNU Library General Public License *
a562b3
+ * along with this library; see the file COPYING.LIB.  If not, write to      *
a562b3
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,      *
a562b3
+ * Boston, MA 02110-1301, USA.                                               *
a562b3
+ *****************************************************************************/
a562b3
+
a562b3
+#ifndef SUCCESS_H
a562b3
+#define SUCCESS_H
a562b3
+
a562b3
+#include "ui_success.h"
a562b3
+#include <QWizardPage>
a562b3
+
a562b3
+class BlueWizard;
a562b3
+
a562b3
+class SuccessPage : public QWizardPage, Ui::Success
a562b3
+{
a562b3
+    Q_OBJECT
a562b3
+
a562b3
+public:
a562b3
+    SuccessPage(BlueWizard *parent = 0);
a562b3
+
a562b3
+    virtual void initializePage();
a562b3
+    virtual int nextId() const;
a562b3
+
a562b3
+private:
a562b3
+    BlueWizard *m_wizard;
a562b3
+};
a562b3
+
a562b3
+#endif // SUCCESS_H
a562b3
diff --git a/src/wizard/pages/success.ui b/src/wizard/pages/success.ui
a562b3
new file mode 100644
a562b3
index 0000000..3630db3
a562b3
--- /dev/null
a562b3
+++ b/src/wizard/pages/success.ui
a562b3
@@ -0,0 +1,68 @@
a562b3
+
a562b3
+<ui version="4.0">
a562b3
+ <class>Success</class>
a562b3
+ <widget class="QWidget" name="Success">
a562b3
+  <property name="geometry">
a562b3
+   <rect>
a562b3
+    <x>0</x>
a562b3
+    <y>0</y>
a562b3
+    <width>400</width>
a562b3
+    <height>300</height>
a562b3
+   </rect>
a562b3
+  </property>
a562b3
+  <layout class="QVBoxLayout" name="verticalLayout">
a562b3
+   <item>
a562b3
+    <layout class="QHBoxLayout" name="horizontalLayout">
a562b3
+     <item>
a562b3
+      <spacer name="horizontalSpacer">
a562b3
+       <property name="orientation">
a562b3
+        <enum>Qt::Horizontal</enum>
a562b3
+       </property>
a562b3
+       <property name="sizeType">
a562b3
+        <enum>QSizePolicy::Fixed</enum>
a562b3
+       </property>
a562b3
+       <property name="sizeHint" stdset="0">
a562b3
+        <size>
a562b3
+         <width>10</width>
a562b3
+         <height>20</height>
a562b3
+        </size>
a562b3
+       </property>
a562b3
+      </spacer>
a562b3
+     </item>
a562b3
+     <item>
a562b3
+      <widget class="QLabel" name="successIcon">
a562b3
+       <property name="maximumSize">
a562b3
+        <size>
a562b3
+         <width>48</width>
a562b3
+         <height>48</height>
a562b3
+        </size>
a562b3
+       </property>
a562b3
+      </widget>
a562b3
+     </item>
a562b3
+     <item>
a562b3
+      <widget class="QLabel" name="successLbl">
a562b3
+       <property name="text">
a562b3
+        <string/>
a562b3
+       </property>
a562b3
+      </widget>
a562b3
+     </item>
a562b3
+    </layout>
a562b3
+   </item>
a562b3
+   <item>
a562b3
+    <spacer name="verticalSpacer">
a562b3
+     <property name="orientation">
a562b3
+      <enum>Qt::Vertical</enum>
a562b3
+     </property>
a562b3
+     <property name="sizeHint" stdset="0">
a562b3
+      <size>
a562b3
+       <width>20</width>
a562b3
+       <height>40</height>
a562b3
+      </size>
a562b3
+     </property>
a562b3
+    </spacer>
a562b3
+   </item>
a562b3
+  </layout>
a562b3
+ </widget>
a562b3
+ <resources/>
a562b3
+ <connections/>
a562b3
+</ui>
a562b3
-- 
a562b3
2.1.0
a562b3