-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BluetoothObexAgent] Show obex dialog as homewindow
- Loading branch information
Showing
2 changed files
with
79 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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 | ||
|
@@ -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(); | ||
}); | ||
|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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<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 |