From kde-commits Thu Apr 30 20:59:25 2015 From: David Rosca Date: Thu, 30 Apr 2015 20:59:25 +0000 To: kde-commits Subject: [bluedevil] src/sendfile: sendfile: Add FailPage when connecting to the device fails Message-Id: X-MARC-Message: https://marc.info/?l=kde-commits&m=143042757714704 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/co= nnectingpage.cpp - 065% similarity] C +12 -9 src/sendfile/pages/failpage.h [from: src/sendfile/pages/conn= ectingpage.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/con= nectingpage.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 +#include = #include = #include +#include +#include = -ConnectingPage::ConnectingPage(QWidget *parent) - : QWizardPage(parent) +ConnectingPage::ConnectingPage(SendFileWizard *wizard) + : QWizardPage(wizard) + , m_wizard(wizard) { setupUi(this); } = void ConnectingPage::initializePage() { - SendFileWizard *w =3D static_cast(wizard()); + m_device =3D m_wizard->device(); + connLabel->setText(i18nc("Connecting to a Bluetooth device", "Connecti= ng to %1...", m_device->name())); = - connLabel->setText(i18nc("Connecting to a Bluetooth device", "Connecti= ng 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 =3D new BluezQt::ObexManager(this); + BluezQt::InitObexManagerJob *job =3D manager->init(); + job->start(); + connect(job, &BluezQt::InitObexManagerJob::result, this, &ConnectingPa= ge::initJobResult); } = bool ConnectingPage::isComplete() const { return false; } + +void ConnectingPage::initJobResult(BluezQt::InitObexManagerJob *job) +{ + if (job->error()) { + qCWarning(SENDFILE) << "Error initializing obex manager" << job->e= rrorText(); + m_wizard->next(); + return; + } + + // Create ObjectPush session + QVariantMap map; + map[QStringLiteral("Target")] =3D QStringLiteral("opp"); + BluezQt::PendingCall *call =3D 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()); +} + +QList ConnectingPage::wizardButtonsLayout() const +{ + QList list; + list << QWizard::Stretch; + list << QWizard::CancelButton; + return list; +} diff --git a/src/sendfile/pages/connectingpage.h b/src/sendfile/pages/conne= ctingpage.h index b607408..fc2a1a6 100644 --- a/src/sendfile/pages/connectingpage.h +++ b/src/sendfile/pages/connectingpage.h @@ -27,15 +27,29 @@ = #include = +#include + +class SendFileWizard; + class ConnectingPage : public QWizardPage, public Ui::Connecting { Q_OBJECT = public: - explicit ConnectingPage(QWidget *parent =3D 0); + explicit ConnectingPage(SendFileWizard *wizard =3D 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 wizardButtonsLayout() const; + + SendFileWizard *m_wizard; + BluezQt::DevicePtr m_device; }; = #endif // CONNECTINGPAGE_H diff --git a/src/sendfile/pages/connectingpage.cpp b/src/sendfile/pages/fai= lpage.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 = * - * Copyright (C) 2010-2011 UFO Coders = * + * Copyright (C) 2015 David Rosca = * * = * * 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 +#include = +#include #include +#include = #include = -ConnectingPage::ConnectingPage(QWidget *parent) +FailPage::FailPage(SendFileWizard *parent) : QWizardPage(parent) + , m_wizard(parent) { setupUi(this); + + failIcon->setPixmap(QIcon::fromTheme(QStringLiteral("task-reject")).pi= xmap(48)); } = -void ConnectingPage::initializePage() +void FailPage::initializePage() { - SendFileWizard *w =3D static_cast(wizard()); + qCDebug(SENDFILE) << "Initialize Fail Page"; = - connLabel->setText(i18nc("Connecting to a Bluetooth device", "Connecti= ng to %1...", w->device()->name())); - w->setWindowTitle(QString()); + QList 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 =3D 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->n= ame())); + } } diff --git a/src/sendfile/pages/connectingpage.h b/src/sendfile/pages/failp= age.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 = * - * Copyright (C) 2010-2011 UFO Coders = * + * Copyright (C) 2015 David Rosca = * * = * * 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 = -class ConnectingPage : public QWizardPage, public Ui::Connecting +class SendFileWizard; + +class FailPage : public QWizardPage, Ui::FailPage { Q_OBJECT = public: - explicit ConnectingPage(QWidget *parent =3D 0); + explicit FailPage(SendFileWizard *parent =3D 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 @@ + + + FailPage + + + + 0 + 0 + 400 + 300 + + + + + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 20 + + + + + + + + + 48 + 48 + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + 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 #include = -SendFilesJob::SendFilesJob(const QStringList &files, BluezQt::DevicePtr de= vice, QObject *parent) +SendFilesJob::SendFilesJob(const QStringList &files, BluezQt::DevicePtr de= vice, const QDBusObjectPath &session, QObject *parent) : KJob(parent) , m_files(files) , m_progress(0) @@ -44,7 +44,6 @@ SendFilesJob::SendFilesJob(const QStringList &files, Blue= zQt::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, Blue= zQt::DevicePtr device, } = setCapabilities(Killable); + + m_objectPush =3D 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->e= rrorText(); - setError(UserDefinedError); - setErrorText(job->errorText()); - emitResult(); - return; - } - - // Create ObjectPush session - QVariantMap map; - map[QStringLiteral("Target")] =3D QStringLiteral("opp"); - BluezQt::PendingCall *call =3D job->manager()->createSession(m_device-= >address(), map); - connect(call, &BluezQt::PendingCall::finished, this, &SendFilesJob::cr= eateSessionFinished); -} - -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 =3D new BluezQt::ObexObjectPush(call->value().value(), this); - nextJob(); -} - void SendFilesJob::doStart() { qCDebug(SENDFILE) << "SendFilesJob-DoStart"; @@ -112,11 +82,7 @@ void SendFilesJob::doStart() QPair(i18nc("File transfer origin= ", "From"), m_files.first()), QPair(i18nc("File transfer destin= ation", "To"), m_device->name())); = - // Init BluezQt - BluezQt::ObexManager *manager =3D new BluezQt::ObexManager(this); - BluezQt::InitObexManagerJob *job =3D 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 dev= ice, QObject *parent =3D 0); + explicit SendFilesJob(const QStringList &files, BluezQt::DevicePtr dev= ice, const QDBusObjectPath &session, QObject *parent =3D 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 #include @@ -111,7 +112,7 @@ void SendFileWizard::setDevice(BluezQt::DevicePtr devic= e) m_device =3D 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 =3D new SendFilesJob(m_files, m_device); + m_job =3D 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::InitManager= Job *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);