[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [bluedevil] src/sendfile: sendfile: Add FailPage when connecting to the device fails
From:       David Rosca <nowrep () gmail ! com>
Date:       2015-04-30 20:59:25
Message-ID: E1YnvYL-0005Pt-Hj () scm ! kde ! org
[Download RAW message or body]

Git commit 3833024a47693ae922d2c25e1d700b52e30befef by David Rosca.
Committed on 30/04/2015 at 11:36.
Pushed by drosca into branch 'master'.

sendfile: Add FailPage when connecting to the device fails

This moves the creating of Obex session to ConnectingPage and
shows the FailPage when it fails.

SendFilesJob is now started only after the Obex session is created.

M  +3    -1    src/sendfile/CMakeLists.txt
M  +50   -9    src/sendfile/pages/connectingpage.cpp
M  +15   -1    src/sendfile/pages/connectingpage.h
C  +23   -16   src/sendfile/pages/failpage.cpp [from: \
src/sendfile/pages/connectingpage.cpp - 065% similarity] C  +12   -9    \
src/sendfile/pages/failpage.h [from: src/sendfile/pages/connectingpage.h - 079% \
similarity] A  +68   -0    src/sendfile/pages/failpage.ui
M  +4    -38   src/sendfile/sendfilesjob.cpp
M  +1    -3    src/sendfile/sendfilesjob.h
M  +6    -3    src/sendfile/sendfilewizard.cpp
M  +3    -1    src/sendfile/sendfilewizard.h

http://commits.kde.org/bluedevil/3833024a47693ae922d2c25e1d700b52e30befef

diff --git a/src/sendfile/CMakeLists.txt b/src/sendfile/CMakeLists.txt
index a93203c..683d459 100644
--- a/src/sendfile/CMakeLists.txt
+++ b/src/sendfile/CMakeLists.txt
@@ -9,12 +9,14 @@ set(sendfilehelper_SRCS
     pages/selectdevicepage.cpp
     pages/selectfilespage.cpp
     pages/connectingpage.cpp
+    pages/failpage.cpp
 )
 
 ki18n_wrap_ui(sendfilehelper_SRCS
     discover.ui
-    pages/connecting.ui
     pages/selectfilediscover.ui
+    pages/connecting.ui
+    pages/failpage.ui
 )
 
 add_executable(bluedevil-sendfile ${sendfilehelper_SRCS})
diff --git a/src/sendfile/pages/connectingpage.cpp \
b/src/sendfile/pages/connectingpage.cpp index 34de20c..d01b6b4 100644
--- a/src/sendfile/pages/connectingpage.cpp
+++ b/src/sendfile/pages/connectingpage.cpp
@@ -22,32 +22,73 @@
 
 #include "connectingpage.h"
 #include "../sendfilewizard.h"
+#include "../debug_p.h"
 
-#include <QTimer>
+#include <QDBusObjectPath>
 
 #include <KLocalizedString>
 
 #include <BluezQt/Device>
+#include <BluezQt/PendingCall>
+#include <BluezQt/InitObexManagerJob>
 
-ConnectingPage::ConnectingPage(QWidget *parent)
-    : QWizardPage(parent)
+ConnectingPage::ConnectingPage(SendFileWizard *wizard)
+    : QWizardPage(wizard)
+    , m_wizard(wizard)
 {
     setupUi(this);
 }
 
 void ConnectingPage::initializePage()
 {
-    SendFileWizard *w = static_cast<SendFileWizard*>(wizard());
+    m_device = m_wizard->device();
+    connLabel->setText(i18nc("Connecting to a Bluetooth device", "Connecting to \
%1...", m_device->name()));  
-    connLabel->setText(i18nc("Connecting to a Bluetooth device", "Connecting to \
                %1...", w->device()->name()));
-    w->setWindowTitle(QString());
+    m_wizard->setWindowTitle(QString());
+    m_wizard->setButtonLayout(wizardButtonsLayout());
 
-    QTimer::singleShot(1000, this, [w]() {
-        w->startTransfer();
-    });
+    // Init BluezQt
+    BluezQt::ObexManager *manager = new BluezQt::ObexManager(this);
+    BluezQt::InitObexManagerJob *job = manager->init();
+    job->start();
+    connect(job, &BluezQt::InitObexManagerJob::result, this, \
&ConnectingPage::initJobResult);  }
 
 bool ConnectingPage::isComplete() const
 {
     return false;
 }
+
+void ConnectingPage::initJobResult(BluezQt::InitObexManagerJob *job)
+{
+    if (job->error()) {
+        qCWarning(SENDFILE) << "Error initializing obex manager" << \
job->errorText(); +        m_wizard->next();
+        return;
+    }
+
+    // Create ObjectPush session
+    QVariantMap map;
+    map[QStringLiteral("Target")] = QStringLiteral("opp");
+    BluezQt::PendingCall *call = job->manager()->createSession(m_device->address(), \
map); +    connect(call, &BluezQt::PendingCall::finished, this, \
&ConnectingPage::createSessionFinished); +}
+
+void ConnectingPage::createSessionFinished(BluezQt::PendingCall *call)
+{
+    if (call->error()) {
+        qCWarning(SENDFILE) << "Error creating session" << call->errorText();
+        m_wizard->next();
+        return;
+    }
+
+    m_wizard->startTransfer(call->value().value<QDBusObjectPath>());
+}
+
+QList<QWizard::WizardButton> ConnectingPage::wizardButtonsLayout() const
+{
+    QList <QWizard::WizardButton> list;
+    list << QWizard::Stretch;
+    list << QWizard::CancelButton;
+    return list;
+}
diff --git a/src/sendfile/pages/connectingpage.h \
b/src/sendfile/pages/connectingpage.h index b607408..fc2a1a6 100644
--- a/src/sendfile/pages/connectingpage.h
+++ b/src/sendfile/pages/connectingpage.h
@@ -27,15 +27,29 @@
 
 #include <QWizardPage>
 
+#include <BluezQt/ObexManager>
+
+class SendFileWizard;
+
 class ConnectingPage : public QWizardPage, public Ui::Connecting
 {
     Q_OBJECT
 
 public:
-    explicit ConnectingPage(QWidget *parent = 0);
+    explicit ConnectingPage(SendFileWizard *wizard = Q_NULLPTR);
 
     void initializePage() Q_DECL_OVERRIDE;
     bool isComplete() const Q_DECL_OVERRIDE;
+
+private Q_SLOTS:
+    void initJobResult(BluezQt::InitObexManagerJob *job);
+    void createSessionFinished(BluezQt::PendingCall *call);
+
+private:
+    QList<QWizard::WizardButton> wizardButtonsLayout() const;
+
+    SendFileWizard *m_wizard;
+    BluezQt::DevicePtr m_device;
 };
 
 #endif // CONNECTINGPAGE_H
diff --git a/src/sendfile/pages/connectingpage.cpp b/src/sendfile/pages/failpage.cpp
similarity index 65%
copy from src/sendfile/pages/connectingpage.cpp
copy to src/sendfile/pages/failpage.cpp
index 34de20c..9405436 100644
--- a/src/sendfile/pages/connectingpage.cpp
+++ b/src/sendfile/pages/failpage.cpp
@@ -1,8 +1,7 @@
 /*****************************************************************************
  * This file is part of the KDE project                                      *
  *                                                                           *
- * Copyright (C) 2010-2011 Alejandro Fiestas Olivares <afiestas@kde.org>     *
- * Copyright (C) 2010-2011 UFO Coders <info@ufocoders.com>                   *
+ * Copyright (C) 2015 David Rosca <nowrep@gmail.com>                         *
  *                                                                           *
  * This library is free software; you can redistribute it and/or             *
  * modify it under the terms of the GNU Library General Public               *
@@ -20,34 +19,42 @@
  * Boston, MA 02110-1301, USA.                                               *
  *****************************************************************************/
 
-#include "connectingpage.h"
+#include "failpage.h"
 #include "../sendfilewizard.h"
+#include "debug_p.h"
 
-#include <QTimer>
+#include <QPushButton>
 
+#include <KStandardGuiItem>
 #include <KLocalizedString>
+#include <KPixmapSequenceOverlayPainter>
 
 #include <BluezQt/Device>
 
-ConnectingPage::ConnectingPage(QWidget *parent)
+FailPage::FailPage(SendFileWizard *parent)
     : QWizardPage(parent)
+    , m_wizard(parent)
 {
     setupUi(this);
+
+    failIcon->setPixmap(QIcon::fromTheme(QStringLiteral("task-reject")).pixmap(48));
 }
 
-void ConnectingPage::initializePage()
+void FailPage::initializePage()
 {
-    SendFileWizard *w = static_cast<SendFileWizard*>(wizard());
+    qCDebug(SENDFILE) << "Initialize Fail Page";
 
-    connLabel->setText(i18nc("Connecting to a Bluetooth device", "Connecting to \
                %1...", w->device()->name()));
-    w->setWindowTitle(QString());
+    QList<QWizard::WizardButton> list;
+    list << QWizard::Stretch;
+    list << QWizard::CancelButton;
 
-    QTimer::singleShot(1000, this, [w]() {
-        w->startTransfer();
-    });
-}
+    m_wizard->setButtonLayout(list);
 
-bool ConnectingPage::isComplete() const
-{
-    return false;
+    BluezQt::DevicePtr device = m_wizard->device();
+
+    if (device->name().isEmpty()) {
+        failLbl->setText(i18nc("This string is shown when the wizard fail", "The \
connection to the device has failed")); +    } else {
+        failLbl->setText(i18n("The connection to %1 has failed", device->name()));
+    }
 }
diff --git a/src/sendfile/pages/connectingpage.h b/src/sendfile/pages/failpage.h
similarity index 79%
copy from src/sendfile/pages/connectingpage.h
copy to src/sendfile/pages/failpage.h
index b607408..2e98fbb 100644
--- a/src/sendfile/pages/connectingpage.h
+++ b/src/sendfile/pages/failpage.h
@@ -1,8 +1,7 @@
 /*****************************************************************************
  * This file is part of the KDE project                                      *
  *                                                                           *
- * Copyright (C) 2010-2011 Alejandro Fiestas Olivares <afiestas@kde.org>     *
- * Copyright (C) 2010-2011 UFO Coders <info@ufocoders.com>                   *
+ * Copyright (C) 2015 David Rosca <nowrep@gmail.com>                         *
  *                                                                           *
  * This library is free software; you can redistribute it and/or             *
  * modify it under the terms of the GNU Library General Public               *
@@ -20,22 +19,26 @@
  * Boston, MA 02110-1301, USA.                                               *
  *****************************************************************************/
 
-#ifndef CONNECTINGPAGE_H
-#define CONNECTINGPAGE_H
+#ifndef FAILPAGE_H
+#define FAILPAGE_H
 
-#include "ui_connecting.h"
+#include "ui_failpage.h"
 
 #include <QWizardPage>
 
-class ConnectingPage : public QWizardPage, public Ui::Connecting
+class SendFileWizard;
+
+class FailPage : public QWizardPage, Ui::FailPage
 {
     Q_OBJECT
 
 public:
-    explicit ConnectingPage(QWidget *parent = 0);
+    explicit FailPage(SendFileWizard *parent = Q_NULLPTR);
 
     void initializePage() Q_DECL_OVERRIDE;
-    bool isComplete() const Q_DECL_OVERRIDE;
+
+private:
+    SendFileWizard *m_wizard;
 };
 
-#endif // CONNECTINGPAGE_H
+#endif // FAILPAGE_H
diff --git a/src/sendfile/pages/failpage.ui b/src/sendfile/pages/failpage.ui
new file mode 100644
index 0000000..abc8064
--- /dev/null
+++ b/src/sendfile/pages/failpage.ui
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>FailPage</class>
+ <widget class="QWidget" name="FailPage">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>400</width>
+    <height>300</height>
+   </rect>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <layout class="QHBoxLayout" name="horizontalLayout">
+     <item>
+      <spacer name="horizontalSpacer">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+       <property name="sizeType">
+        <enum>QSizePolicy::Fixed</enum>
+       </property>
+       <property name="sizeHint" stdset="0">
+        <size>
+         <width>10</width>
+         <height>20</height>
+        </size>
+       </property>
+      </spacer>
+     </item>
+     <item>
+      <widget class="QLabel" name="failIcon">
+       <property name="maximumSize">
+        <size>
+         <width>48</width>
+         <height>48</height>
+        </size>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <widget class="QLabel" name="failLbl">
+       <property name="text">
+        <string/>
+       </property>
+      </widget>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <spacer name="verticalSpacer">
+     <property name="orientation">
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>20</width>
+       <height>40</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/sendfile/sendfilesjob.cpp b/src/sendfile/sendfilesjob.cpp
index a9c02c7..e8d314f 100644
--- a/src/sendfile/sendfilesjob.cpp
+++ b/src/sendfile/sendfilesjob.cpp
@@ -35,7 +35,7 @@
 #include <BluezQt/ObexObjectPush>
 #include <BluezQt/InitObexManagerJob>
 
-SendFilesJob::SendFilesJob(const QStringList &files, BluezQt::DevicePtr device, \
QObject *parent) +SendFilesJob::SendFilesJob(const QStringList &files, \
BluezQt::DevicePtr device, const QDBusObjectPath &session, QObject *parent)  : \
KJob(parent)  , m_files(files)
     , m_progress(0)
@@ -44,7 +44,6 @@ SendFilesJob::SendFilesJob(const QStringList &files, \
BluezQt::DevicePtr device,  , m_currentFileSize(0)
     , m_currentFileProgress(0)
     , m_device(device)
-    , m_objectPush(0)
 {
     qCDebug(SENDFILE) << "SendFilesJob:" << files;
 
@@ -55,6 +54,8 @@ SendFilesJob::SendFilesJob(const QStringList &files, \
BluezQt::DevicePtr device,  }
 
     setCapabilities(Killable);
+
+    m_objectPush = new BluezQt::ObexObjectPush(session, this);
 }
 
 void SendFilesJob::start()
@@ -70,37 +71,6 @@ bool SendFilesJob::doKill()
     return true;
 }
 
-void SendFilesJob::initJobResult(BluezQt::InitObexManagerJob *job)
-{
-    if (job->error()) {
-        qCWarning(SENDFILE) << "Error initializing obex manager" << \
                job->errorText();
-        setError(UserDefinedError);
-        setErrorText(job->errorText());
-        emitResult();
-        return;
-    }
-
-    // Create ObjectPush session
-    QVariantMap map;
-    map[QStringLiteral("Target")] = QStringLiteral("opp");
-    BluezQt::PendingCall *call = job->manager()->createSession(m_device->address(), \
                map);
-    connect(call, &BluezQt::PendingCall::finished, this, \
                &SendFilesJob::createSessionFinished);
-}
-
-void SendFilesJob::createSessionFinished(BluezQt::PendingCall *call)
-{
-    if (call->error()) {
-        qCWarning(SENDFILE) << "Error creating session" << call->errorText();
-        setError(UserDefinedError);
-        setErrorText(call->errorText());
-        emitResult();
-        return;
-    }
-
-    m_objectPush = new \
                BluezQt::ObexObjectPush(call->value().value<QDBusObjectPath>(), \
                this);
-    nextJob();
-}
-
 void SendFilesJob::doStart()
 {
     qCDebug(SENDFILE) << "SendFilesJob-DoStart";
@@ -112,11 +82,7 @@ void SendFilesJob::doStart()
                        QPair<QString, QString>(i18nc("File transfer origin", \
                "From"), m_files.first()),
                        QPair<QString, QString>(i18nc("File transfer destination", \
"To"), m_device->name()));  
-    // Init BluezQt
-    BluezQt::ObexManager *manager = new BluezQt::ObexManager(this);
-    BluezQt::InitObexManagerJob *job = manager->init();
-    job->start();
-    connect(job, &BluezQt::InitObexManagerJob::result, this, \
&SendFilesJob::initJobResult); +    nextJob();
 }
 
 void SendFilesJob::nextJob()
diff --git a/src/sendfile/sendfilesjob.h b/src/sendfile/sendfilesjob.h
index 1cf4592..3990518 100644
--- a/src/sendfile/sendfilesjob.h
+++ b/src/sendfile/sendfilesjob.h
@@ -42,14 +42,12 @@ class SendFilesJob : public KJob
     Q_OBJECT
 
 public:
-    explicit SendFilesJob(const QStringList &files, BluezQt::DevicePtr device, \
QObject *parent = 0); +    explicit SendFilesJob(const QStringList &files, \
BluezQt::DevicePtr device, const QDBusObjectPath &session, QObject *parent = \
Q_NULLPTR);  
     void start() Q_DECL_OVERRIDE;
     bool doKill() Q_DECL_OVERRIDE;
 
 private Q_SLOTS:
-    void initJobResult(BluezQt::InitObexManagerJob *job);
-    void createSessionFinished(BluezQt::PendingCall *call);
     void doStart();
     void nextJob();
     void sendFileFinished(BluezQt::PendingCall *call);
diff --git a/src/sendfile/sendfilewizard.cpp b/src/sendfile/sendfilewizard.cpp
index cb9b716..164129b 100644
--- a/src/sendfile/sendfilewizard.cpp
+++ b/src/sendfile/sendfilewizard.cpp
@@ -28,6 +28,7 @@
 #include "pages/selectdevicepage.h"
 #include "pages/selectfilespage.h"
 #include "pages/connectingpage.h"
+#include "pages/failpage.h"
 
 #include <QUrl>
 #include <QPushButton>
@@ -111,7 +112,7 @@ void SendFileWizard::setDevice(BluezQt::DevicePtr device)
     m_device = device;
 }
 
-void SendFileWizard::startTransfer()
+void SendFileWizard::startTransfer(const QDBusObjectPath &session)
 {
     if (m_files.isEmpty()) {
         qCDebug(SENDFILE) << "No files to send";
@@ -120,9 +121,10 @@ void SendFileWizard::startTransfer()
 
     if (!m_device) {
         qCDebug(SENDFILE) << "No device selected";
+        return;
     }
 
-    m_job = new SendFilesJob(m_files, m_device);
+    m_job = new SendFilesJob(m_files, m_device, session);
     connect(m_job, &SendFilesJob::destroyed, qApp, &QCoreApplication::quit);
 
     KIO::getJobTracker()->registerJob(m_job);
@@ -168,7 +170,8 @@ void SendFileWizard::initJobResult(BluezQt::InitManagerJob *job)
         }
     }
 
-    addPage(new ConnectingPage());
+    addPage(new ConnectingPage(this));
+    addPage(new FailPage(this));
 
     // Only show wizard after init is completed
     show();
diff --git a/src/sendfile/sendfilewizard.h b/src/sendfile/sendfilewizard.h
index 6aeb951..ea42698 100644
--- a/src/sendfile/sendfilewizard.h
+++ b/src/sendfile/sendfilewizard.h
@@ -31,6 +31,8 @@
 
 #include "discoverwidget.h"
 
+class QDBusObjectPath;
+
 class SendFilesJob;
 
 class SendFileWizard : public QWizard
@@ -51,7 +53,7 @@ public:
     BluezQt::DevicePtr device() const;
     void setDevice(BluezQt::DevicePtr device);
 
-    void startTransfer();
+    void startTransfer(const QDBusObjectPath &session);
 
 private Q_SLOTS:
     void initJobResult(BluezQt::InitManagerJob *job);


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic