Signed-off-by: Mavridis Philippe <mavridisf@gmail.com>pull/6/head
parent
2397c7e9cb
commit
b0aeeeb966
@ -0,0 +1,39 @@
|
||||
/*******************************************************************************
|
||||
XDG desktop portal implementation for TDE
|
||||
Copyright © 2024 Mavridis Philippe <mavridisf@gmail.com>
|
||||
|
||||
This program or library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Improvements and feedback are welcome!
|
||||
*******************************************************************************/
|
||||
|
||||
// Portal
|
||||
#include "dialog_result_sender.h"
|
||||
|
||||
template <class T>
|
||||
DialogResultSender<T>::DialogResultSender(T* portal, int asyncCallId, TQDialog *dlg,
|
||||
ResultPrepareCallback<T> prepareCb, ResultSendCallback<T> sendCb)
|
||||
{}
|
||||
|
||||
template <class T>
|
||||
DialogResultSender<T>::~DialogResultSender()
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void DialogResultSender<T>::run()
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
/*******************************************************************************
|
||||
XDG desktop portal implementation for TDE
|
||||
Copyright © 2024 Mavridis Philippe <mavridisf@gmail.com>
|
||||
|
||||
This program or library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Improvements and feedback are welcome!
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __DIALOG_RESULT_SENDER_H
|
||||
#define __DIALOG_RESULT_SENDER_H
|
||||
|
||||
// TQt
|
||||
#include <tqthread.h>
|
||||
#include <tqdialog.h>
|
||||
|
||||
// Portal
|
||||
#include "util.h"
|
||||
|
||||
struct DialogResult
|
||||
{
|
||||
TQ_UINT32 response;
|
||||
TQT_DBusVariantMap results;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
using ResultPrepareCallback = DialogResult(T::*)(TQDialog*);
|
||||
|
||||
template <class T>
|
||||
using ResultSendCallback = void(T::*)(int, TQ_UINT32, const TQT_DBusVariantMap&);
|
||||
|
||||
template <class T>
|
||||
class DialogResultSender : public TQThread
|
||||
{
|
||||
public:
|
||||
DialogResultSender(T* portal, int asyncCallId, TQDialog *dlg, ResultPrepareCallback<T> prepareCb, ResultSendCallback<T> sendCb)
|
||||
: TQThread(),
|
||||
m_portal(portal),
|
||||
m_asyncCallId(asyncCallId),
|
||||
m_dlg(dlg),
|
||||
m_prepareCb(prepareCb),
|
||||
m_sendCb(sendCb)
|
||||
{}
|
||||
|
||||
~DialogResultSender()
|
||||
{
|
||||
wait();
|
||||
}
|
||||
|
||||
void run()
|
||||
{
|
||||
if (!m_dlg) return;
|
||||
|
||||
while (m_dlg->isVisible())
|
||||
{
|
||||
usleep(1000);
|
||||
}
|
||||
|
||||
DialogResult res = (m_portal->*m_prepareCb)(m_dlg);
|
||||
(m_portal->*m_sendCb)(m_asyncCallId, res.response, res.results);
|
||||
|
||||
m_dlg->deleteLater();
|
||||
}
|
||||
|
||||
private:
|
||||
T *m_portal;
|
||||
int m_asyncCallId;
|
||||
TQDialog *m_dlg;
|
||||
ResultPrepareCallback<T> m_prepareCb;
|
||||
ResultSendCallback<T> m_sendCb;
|
||||
};
|
||||
|
||||
#endif // __DIALOG_RESULT_SENDER_H
|
@ -0,0 +1,70 @@
|
||||
/*******************************************************************************
|
||||
XDG desktop portal implementation for TDE
|
||||
Copyright © 2024 Mavridis Philippe <mavridisf@gmail.com>
|
||||
|
||||
This program or library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Improvements and feedback are welcome!
|
||||
*******************************************************************************/
|
||||
|
||||
// TDE
|
||||
#include <kdebug.h>
|
||||
#include <tdemessagebox.h>
|
||||
|
||||
// Portal
|
||||
#include "request.h"
|
||||
#include "request.moc"
|
||||
|
||||
Request::Request(TQT_DBusConnection connection, const TQT_DBusObjectPath &handle,
|
||||
TQObject *parent, const TQVariant data)
|
||||
: TQObject(parent),
|
||||
m_connection(connection),
|
||||
m_handle(handle),
|
||||
m_data(data),
|
||||
m_registered(false)
|
||||
{
|
||||
if (!m_connection.registerObject(m_handle, this))
|
||||
{
|
||||
kdWarning() << "Could not register Request object on " << m_handle << endl;
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
m_registered = true;
|
||||
}
|
||||
|
||||
Request::~Request()
|
||||
{
|
||||
if (m_registered) m_connection.unregisterObject(m_handle);
|
||||
}
|
||||
|
||||
bool Request::handleMethodCall(const TQT_DBusMessage &message)
|
||||
{
|
||||
if (message.interface() != "org.freedesktop.impl.portal.Request"
|
||||
|| message.member() != "Close")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
TQT_DBusMessage reply = TQT_DBusMessage::methodReply(message);
|
||||
m_connection.send(reply);
|
||||
|
||||
emit closeRequested();
|
||||
emit closeRequested(m_data);
|
||||
|
||||
deleteLater();
|
||||
return true;
|
||||
}
|
||||
|
||||
// kate: replace-tabs true; tab-width 4; indent-width 4;
|
@ -0,0 +1,58 @@
|
||||
/*******************************************************************************
|
||||
XDG desktop portal implementation for TDE
|
||||
Copyright © 2024 Mavridis Philippe <mavridisf@gmail.com>
|
||||
|
||||
This program or library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this library; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Improvements and feedback are welcome!
|
||||
*******************************************************************************/
|
||||
|
||||
#ifndef __REQUEST_H
|
||||
#define __REQUEST_H
|
||||
|
||||
// TQt
|
||||
#include <tqobject.h>
|
||||
#include <tqvariant.h>
|
||||
#include <tqdbusconnection.h>
|
||||
#include <tqdbusmessage.h>
|
||||
#include <tqdbusobject.h>
|
||||
#include <tqdbusobjectpath.h>
|
||||
|
||||
class Request : public TQObject, TQT_DBusObjectBase
|
||||
{
|
||||
TQ_OBJECT
|
||||
|
||||
public:
|
||||
Request(TQT_DBusConnection connection, const TQT_DBusObjectPath &handle,
|
||||
TQObject *parent, const TQVariant data = TQVariant());
|
||||
virtual ~Request();
|
||||
|
||||
protected:
|
||||
virtual bool handleMethodCall(const TQT_DBusMessage& message);
|
||||
|
||||
signals:
|
||||
void closeRequested(); // when we don't care about data
|
||||
void closeRequested(const TQVariant &data);
|
||||
|
||||
private:
|
||||
TQT_DBusConnection m_connection;
|
||||
const TQT_DBusObjectPath &m_handle;
|
||||
const TQVariant m_data;
|
||||
bool m_registered;
|
||||
};
|
||||
|
||||
#endif // __REQUEST_H
|
||||
|
||||
// kate: replace-tabs true; tab-width 4; indent-width 4;
|
Loading…
Reference in new issue