Add net.attah.seaprint DBus methods
This commit is contained in:
parent
d473d23d55
commit
317a864ff6
8 changed files with 111 additions and 66 deletions
|
@ -34,7 +34,8 @@ DEFINES += PDF_CREATOR='\\"SeaPrint\ $$VERSION\\"'
|
||||||
DEFINES += SEAPRINT_VERSION='\\"$$VERSION\\"'
|
DEFINES += SEAPRINT_VERSION='\\"$$VERSION\\"'
|
||||||
|
|
||||||
SOURCES += src/harbour-seaprint.cpp \
|
SOURCES += src/harbour-seaprint.cpp \
|
||||||
src/dbusadaptor.cpp \
|
src/dbusadaptorbase.cpp \
|
||||||
|
src/freedesktopdbusadaptor.cpp \
|
||||||
src/rangelistchecker.cpp \
|
src/rangelistchecker.cpp \
|
||||||
src/convertchecker.cpp \
|
src/convertchecker.cpp \
|
||||||
src/curlrequester.cpp \
|
src/curlrequester.cpp \
|
||||||
|
@ -50,6 +51,7 @@ SOURCES += src/harbour-seaprint.cpp \
|
||||||
ppm2pwg/bytestream/bytestream.cpp \
|
ppm2pwg/bytestream/bytestream.cpp \
|
||||||
src/overrider.cpp \
|
src/overrider.cpp \
|
||||||
src/printerworker.cpp \
|
src/printerworker.cpp \
|
||||||
|
src/seaprintdbusadaptor.cpp \
|
||||||
src/settings.cpp
|
src/settings.cpp
|
||||||
|
|
||||||
DISTFILES += qml/harbour-seaprint.qml \
|
DISTFILES += qml/harbour-seaprint.qml \
|
||||||
|
@ -83,7 +85,8 @@ TRANSLATIONS += translations/harbour-seaprint-de.ts \
|
||||||
translations/harbour-seaprint-pl.ts
|
translations/harbour-seaprint-pl.ts
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/dbusadaptor.h \
|
src/dbusadaptorbase.h \
|
||||||
|
src/freedesktopdbusadaptor.h \
|
||||||
src/rangelistchecker.h \
|
src/rangelistchecker.h \
|
||||||
src/convertchecker.h \
|
src/convertchecker.h \
|
||||||
src/curlrequester.h \
|
src/curlrequester.h \
|
||||||
|
@ -107,6 +110,7 @@ HEADERS += \
|
||||||
src/overrider.h \
|
src/overrider.h \
|
||||||
src/papersizes.h \
|
src/papersizes.h \
|
||||||
src/printerworker.h \
|
src/printerworker.h \
|
||||||
|
src/seaprintdbusadaptor.h \
|
||||||
src/settings.h
|
src/settings.h
|
||||||
|
|
||||||
INCLUDEPATH += ppm2pwg \
|
INCLUDEPATH += ppm2pwg \
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
#include "dbusadaptor.h"
|
|
||||||
|
|
||||||
#include <QtQuick>
|
|
||||||
|
|
||||||
DBusAdaptor::DBusAdaptor(QQuickView *view)
|
|
||||||
: QDBusAbstractAdaptor(view)
|
|
||||||
, _view(view)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
DBusAdaptor::~DBusAdaptor()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBusAdaptor::Open(const QStringList& uris, const QVariantMap& platformData)
|
|
||||||
{
|
|
||||||
qDebug() << platformData;
|
|
||||||
if (!uris.isEmpty() && uris[0] != "") {
|
|
||||||
QMetaObject::invokeMethod(_view->rootObject(), "openFile", Q_ARG(QVariant, uris.at(0)));
|
|
||||||
}
|
|
||||||
else if(platformData.contains("data"))
|
|
||||||
{
|
|
||||||
QTemporaryFile tmpfile(QDir::tempPath() + "/" + (platformData.contains("name") ? platformData["name"].toString() : "seaprint"));
|
|
||||||
tmpfile.setAutoRemove(false);
|
|
||||||
tmpfile.open();
|
|
||||||
tmpfile.write(platformData["data"].toString().toUtf8());
|
|
||||||
tmpfile.close();
|
|
||||||
QMetaObject::invokeMethod(_view->rootObject(), "openFile", Q_ARG(QVariant, tmpfile.fileName()));
|
|
||||||
}
|
|
||||||
QMetaObject::invokeMethod(_view->rootObject(), "activate");
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBusAdaptor::Activate(const QVariantMap&)
|
|
||||||
{
|
|
||||||
QMetaObject::invokeMethod(_view->rootObject(), "activate");
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
#ifndef DBUSADAPTOR_H
|
|
||||||
#define DBUSADAPTOR_H
|
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QtDBus/QDBusAbstractAdaptor>
|
|
||||||
#include <QQuickView>
|
|
||||||
|
|
||||||
class DBusAdaptor : public QDBusAbstractAdaptor
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Application")
|
|
||||||
|
|
||||||
public:
|
|
||||||
DBusAdaptor(QQuickView *view);
|
|
||||||
~DBusAdaptor();
|
|
||||||
|
|
||||||
public Q_SLOTS:
|
|
||||||
Q_NOREPLY void Open(const QStringList &uris, const QVariantMap &platformData);
|
|
||||||
Q_NOREPLY void Activate(const QVariantMap &platformData);
|
|
||||||
|
|
||||||
private:
|
|
||||||
QQuickView* _view;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // DBUSADAPTOR_H
|
|
25
src/dbusadaptorbase.cpp
Normal file
25
src/dbusadaptorbase.cpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
#include "dbusadaptorbase.h"
|
||||||
|
#include <QtQuick>
|
||||||
|
|
||||||
|
void DBusAdaptorBase::doActivate()
|
||||||
|
{
|
||||||
|
QMetaObject::invokeMethod(_view->rootObject(), "activate");
|
||||||
|
}
|
||||||
|
|
||||||
|
void DBusAdaptorBase::doOpen(const QString& fileName)
|
||||||
|
{
|
||||||
|
QMetaObject::invokeMethod(_view->rootObject(), "openFile", Q_ARG(QVariant, fileName));
|
||||||
|
doActivate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DBusAdaptorBase::doCreateFileAndOpen(const QString& fileContents, const QString& name)
|
||||||
|
{
|
||||||
|
QTemporaryFile tmpfile(QDir::tempPath() + "/" + name);
|
||||||
|
tmpfile.setAutoRemove(false);
|
||||||
|
tmpfile.open();
|
||||||
|
tmpfile.write(fileContents.toUtf8());
|
||||||
|
tmpfile.close();
|
||||||
|
QMetaObject::invokeMethod(_view->rootObject(), "openFile", Q_ARG(QVariant, tmpfile.fileName()));
|
||||||
|
|
||||||
|
doActivate();
|
||||||
|
}
|
24
src/dbusadaptorbase.h
Normal file
24
src/dbusadaptorbase.h
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#ifndef DBUSADAPTORBASE_H
|
||||||
|
#define DBUSADAPTORBASE_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QtDBus/QDBusAbstractAdaptor>
|
||||||
|
#include <QQuickView>
|
||||||
|
|
||||||
|
class DBusAdaptorBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DBusAdaptorBase(QQuickView* view)
|
||||||
|
: _view(view)
|
||||||
|
{}
|
||||||
|
|
||||||
|
void doActivate();
|
||||||
|
void doOpen(const QString& fileName);
|
||||||
|
void doCreateFileAndOpen(const QString& fileContents, const QString& name);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QQuickView* _view;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // DBUSADAPTORBASE_H
|
31
src/freedesktopdbusadaptor.cpp
Normal file
31
src/freedesktopdbusadaptor.cpp
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
#include "freedesktopdbusadaptor.h"
|
||||||
|
|
||||||
|
#include <QtQuick>
|
||||||
|
|
||||||
|
FreedesktopDBusAdaptor::FreedesktopDBusAdaptor(QQuickView *view)
|
||||||
|
: QDBusAbstractAdaptor(view)
|
||||||
|
, DBusAdaptorBase(view)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
FreedesktopDBusAdaptor::~FreedesktopDBusAdaptor()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void FreedesktopDBusAdaptor::Open(const QStringList& uris, const QVariantMap& platformData)
|
||||||
|
{
|
||||||
|
qDebug() << platformData;
|
||||||
|
if (!uris.isEmpty() && uris[0] != "") {
|
||||||
|
doOpen(uris.at(0));
|
||||||
|
}
|
||||||
|
else if(platformData.contains("data"))
|
||||||
|
{
|
||||||
|
doCreateFileAndOpen(platformData["data"].toString(),
|
||||||
|
(platformData.contains("name") ? platformData["name"].toString() : "seaprint"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FreedesktopDBusAdaptor::Activate(const QVariantMap&)
|
||||||
|
{
|
||||||
|
QMetaObject::invokeMethod(_view->rootObject(), "activate");
|
||||||
|
}
|
21
src/freedesktopdbusadaptor.h
Normal file
21
src/freedesktopdbusadaptor.h
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
#ifndef FREEDESKTOPDBUSADAPTOR_H
|
||||||
|
#define FREEDESKTOPDBUSADAPTOR_H
|
||||||
|
|
||||||
|
#include "dbusadaptorbase.h"
|
||||||
|
|
||||||
|
class FreedesktopDBusAdaptor : public QDBusAbstractAdaptor, public DBusAdaptorBase
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Application")
|
||||||
|
|
||||||
|
public:
|
||||||
|
FreedesktopDBusAdaptor(QQuickView *view);
|
||||||
|
~FreedesktopDBusAdaptor();
|
||||||
|
|
||||||
|
public Q_SLOTS:
|
||||||
|
Q_NOREPLY void Open(const QStringList& uris, const QVariantMap& platformData);
|
||||||
|
Q_NOREPLY void Activate(const QVariantMap& platformData);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // FREEDESKTOPDBUSADAPTOR_H
|
|
@ -10,7 +10,8 @@
|
||||||
#include <src/convertchecker.h>
|
#include <src/convertchecker.h>
|
||||||
#include <src/settings.h>
|
#include <src/settings.h>
|
||||||
#include <src/rangelistchecker.h>
|
#include <src/rangelistchecker.h>
|
||||||
#include <src/dbusadaptor.h>
|
#include <src/freedesktopdbusadaptor.h>
|
||||||
|
#include <src/seaprintdbusadaptor.h>
|
||||||
#include "argget.h"
|
#include "argget.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
@ -70,7 +71,8 @@ int main(int argc, char *argv[])
|
||||||
view->engine()->addImportPath(SailfishApp::pathTo("qml/pages").toString());
|
view->engine()->addImportPath(SailfishApp::pathTo("qml/pages").toString());
|
||||||
view->setSource(SailfishApp::pathToMainQml());
|
view->setSource(SailfishApp::pathToMainQml());
|
||||||
|
|
||||||
DBusAdaptor dbus(view);
|
FreedesktopDBusAdaptor freedesktopDbus(view);
|
||||||
|
SeaPrintDBusAdaptor seaprintDbus(view);
|
||||||
|
|
||||||
if (!QDBusConnection::sessionBus().registerObject("/net/attah/seaprint", view))
|
if (!QDBusConnection::sessionBus().registerObject("/net/attah/seaprint", view))
|
||||||
qWarning() << "Could not register /net/attah/seaprint D-Bus object.";
|
qWarning() << "Could not register /net/attah/seaprint D-Bus object.";
|
||||||
|
|
Loading…
Reference in a new issue