diff --git a/src/bluetooth/bluetoothobexagent.cpp b/src/bluetooth/bluetoothobexagent.cpp index 959643e9..dcf3b3a0 100644 --- a/src/bluetooth/bluetoothobexagent.cpp +++ b/src/bluetooth/bluetoothobexagent.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Chupligin Sergey + * Copyright (C) 2021-2024 Chupligin Sergey * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -18,26 +18,35 @@ */ #include "bluetoothobexagent.h" +#include "homewindow.h" +#include "logging.h" +#include "lipstickqmlpath.h" +#include "utilities/closeeventeater.h" -#include #include +#include #include #include +#include +#include #include #include 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 @@ -47,7 +56,10 @@ QDBusObjectPath BluetoothObexAgent::objectPath() const void BluetoothObexAgent::authorizePush(BluezQt::ObexTransferPtr transfer, BluezQt::ObexSessionPtr session, const BluezQt::Request &request) { - emit showRequiesDialog(session->destination(), transfer->name()); + m_fileName = transfer->name(); + m_deviceName = session->destination(); + emit showRequiesDialog(); + connect(this, &BluetoothObexAgent::requestConfirmationReject, this, [=]() { request.reject(); }); @@ -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; } @@ -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); @@ -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; +} diff --git a/src/bluetooth/bluetoothobexagent.h b/src/bluetooth/bluetoothobexagent.h index f1564df8..bdbaf058 100644 --- a/src/bluetooth/bluetoothobexagent.h +++ b/src/bluetooth/bluetoothobexagent.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Chupligin Sergey + * Copyright (C) 2021-2024 Chupligin Sergey * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -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); @@ -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& 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