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

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