Skip to content

Commit

Permalink
[BluetoothObexAgent] Show obex dialog as homewindow
Browse files Browse the repository at this point in the history
  • Loading branch information
neochapay committed May 7, 2024
1 parent a996996 commit 567473f
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 8 deletions.
63 changes: 57 additions & 6 deletions src/bluetooth/bluetoothobexagent.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Chupligin Sergey <[email protected]>
* Copyright (C) 2021-2024 Chupligin Sergey <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand All @@ -18,26 +18,35 @@
*/

#include "bluetoothobexagent.h"
#include "homewindow.h"
#include "logging.h"
#include "lipstickqmlpath.h"
#include "utilities/closeeventeater.h"

#include <QDebug>
#include <QDir>
#include <QScreen>
#include <QDBusObjectPath>
#include <QStandardPaths>
#include <QTimer>
#include <QGuiApplication>

#include <BluezQt/ObexManager>
#include <BluezQt/ObexSession>

BluetoothObexAgent::BluetoothObexAgent(QObject *parent)
: BluezQt::ObexAgent(parent)
, m_requestODialogWindow(nullptr)
{
BluezQt::PendingCall* startCall = BluezQt::ObexManager::startService();

connect(startCall, &BluezQt::PendingCall::finished, this, &BluetoothObexAgent::startServiceFinished);

QTimer::singleShot(0, this, SLOT(createWindow()));
}

BluetoothObexAgent::~BluetoothObexAgent()
{

delete m_requestODialogWindow;
}

QDBusObjectPath BluetoothObexAgent::objectPath() const
Expand All @@ -47,7 +56,10 @@ QDBusObjectPath BluetoothObexAgent::objectPath() const

void BluetoothObexAgent::authorizePush(BluezQt::ObexTransferPtr transfer, BluezQt::ObexSessionPtr session, const BluezQt::Request<QString> &request)
{
emit showRequiesDialog(session->destination(), transfer->name());
m_fileName = transfer->name();
m_deviceName = session->destination();
emit showRequiesDialog();

connect(this, &BluetoothObexAgent::requestConfirmationReject, this, [=]() {
request.reject();
});
Expand Down Expand Up @@ -77,7 +89,7 @@ void BluetoothObexAgent::authorizePush(BluezQt::ObexTransferPtr transfer, BluezQ
void BluetoothObexAgent::startServiceFinished(BluezQt::PendingCall *call)
{
if(call->error()) {
qWarning() << Q_FUNC_INFO << call->errorText();
qCDebug(lcLipstickBluetooth) << Q_FUNC_INFO << call->errorText();
return;
}

Expand All @@ -91,7 +103,7 @@ void BluetoothObexAgent::startServiceFinished(BluezQt::PendingCall *call)
void BluetoothObexAgent::obexManagerStartResult(BluezQt::InitObexManagerJob *job)
{
if(job->error()) {
qWarning() << Q_FUNC_INFO << job->errorText();
qCDebug(lcLipstickBluetooth) << Q_FUNC_INFO << job->errorText();
return;
}
m_obexManager->registerAgent(this);
Expand All @@ -118,3 +130,42 @@ void BluetoothObexAgent::obexDataTransferFinished(BluezQt::ObexTransfer::Status
emit transferError();
}
}

void BluetoothObexAgent::createWindow()
{
m_requestODialogWindow = new HomeWindow();
m_requestODialogWindow->setGeometry(QRect(QPoint(), QGuiApplication::primaryScreen()->size()));
m_requestODialogWindow->setCategory(QLatin1String("notification"));
m_requestODialogWindow->setWindowTitle("Bluetooth file transfer");
m_requestODialogWindow->setContextProperty("initialSize", QGuiApplication::primaryScreen()->size());
m_requestODialogWindow->setSource(QmlPath::to("bluetooth/RequestObexDialog.qml"));
m_requestODialogWindow->installEventFilter(new CloseEventEater(this));
}

bool BluetoothObexAgent::windowVisible() const
{
return m_requestODialogWindow != 0 && m_requestODialogWindow->isVisible();
}

void BluetoothObexAgent::setWindowVisible(bool visible)
{
if(visible) {
if(m_requestODialogWindow && !m_requestODialogWindow->isVisible()) {
m_requestODialogWindow->show();
emit windowVisibleChanged();
}
} else if(m_requestODialogWindow != 0 && m_requestODialogWindow->isVisible()) {
m_requestODialogWindow->hide();
emit windowVisibleChanged();
}
}

QString BluetoothObexAgent::deviceName() const
{
return m_deviceName;
}

QString BluetoothObexAgent::fileName() const
{
return m_fileName;
}
24 changes: 22 additions & 2 deletions src/bluetooth/bluetoothobexagent.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021 Chupligin Sergey <[email protected]>
* Copyright (C) 2021-2024 Chupligin Sergey <[email protected]>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
Expand Down Expand Up @@ -28,8 +28,13 @@

#include "lipstickglobal.h"

class HomeWindow;

class LIPSTICK_EXPORT BluetoothObexAgent : public BluezQt::ObexAgent {
Q_OBJECT
Q_PROPERTY(bool windowVisible READ windowVisible WRITE setWindowVisible NOTIFY windowVisibleChanged)
Q_PROPERTY(QString deviceName READ deviceName NOTIFY transferChanged)
Q_PROPERTY(QString fileName READ fileName NOTIFY transferChanged)

public:
explicit BluetoothObexAgent(QObject* parent = nullptr);
Expand All @@ -38,23 +43,38 @@ class LIPSTICK_EXPORT BluetoothObexAgent : public BluezQt::ObexAgent {
QDBusObjectPath objectPath() const override;
void authorizePush(BluezQt::ObexTransferPtr transfer, BluezQt::ObexSessionPtr session, const BluezQt::Request<QString>& request) override;

bool windowVisible() const;
void setWindowVisible(bool visible);

QString deviceName() const;
QString fileName() const;

signals:
void showRequiesDialog(const QString deviceName, const QString fileName);
void showRequiesDialog();
void requestConfirmationAccept();
void requestConfirmationReject();
void transferError();
void transferFinished(QString resultPath);

void windowVisibleChanged();
void transferChanged();

private slots:
void startServiceFinished(BluezQt::PendingCall *call);
void obexManagerStartResult(BluezQt::InitObexManagerJob *job);
void obexDataTransferFinished(BluezQt::ObexTransfer::Status status);

void createWindow();

private:
HomeWindow *m_requestODialogWindow;

BluezQt::ObexManager *m_obexManager;
QString m_temporaryPath;
QString m_transferName;

QString m_deviceName;
QString m_fileName;
};

#endif // BLUETOOTHOBEXAGENT_H

0 comments on commit 567473f

Please sign in to comment.