diff --git a/harbour-seaprint.pro b/harbour-seaprint.pro index f5a4757..cd68859 100644 --- a/harbour-seaprint.pro +++ b/harbour-seaprint.pro @@ -34,7 +34,8 @@ DEFINES += PDF_CREATOR='\\"SeaPrint\ $$VERSION\\"' DEFINES += SEAPRINT_VERSION='\\"$$VERSION\\"' SOURCES += src/harbour-seaprint.cpp \ - src/dbusadaptor.cpp \ + src/dbusadaptorbase.cpp \ + src/freedesktopdbusadaptor.cpp \ src/rangelistchecker.cpp \ src/convertchecker.cpp \ src/curlrequester.cpp \ @@ -50,6 +51,7 @@ SOURCES += src/harbour-seaprint.cpp \ ppm2pwg/bytestream/bytestream.cpp \ src/overrider.cpp \ src/printerworker.cpp \ + src/seaprintdbusadaptor.cpp \ src/settings.cpp DISTFILES += qml/harbour-seaprint.qml \ @@ -83,7 +85,8 @@ TRANSLATIONS += translations/harbour-seaprint-de.ts \ translations/harbour-seaprint-pl.ts HEADERS += \ - src/dbusadaptor.h \ + src/dbusadaptorbase.h \ + src/freedesktopdbusadaptor.h \ src/rangelistchecker.h \ src/convertchecker.h \ src/curlrequester.h \ @@ -107,6 +110,7 @@ HEADERS += \ src/overrider.h \ src/papersizes.h \ src/printerworker.h \ + src/seaprintdbusadaptor.h \ src/settings.h INCLUDEPATH += ppm2pwg \ diff --git a/src/dbusadaptor.cpp b/src/dbusadaptor.cpp deleted file mode 100644 index 86a5d3e..0000000 --- a/src/dbusadaptor.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "dbusadaptor.h" - -#include - -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"); -} diff --git a/src/dbusadaptor.h b/src/dbusadaptor.h deleted file mode 100644 index 1cb708f..0000000 --- a/src/dbusadaptor.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef DBUSADAPTOR_H -#define DBUSADAPTOR_H - -#include -#include -#include - -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 diff --git a/src/dbusadaptorbase.cpp b/src/dbusadaptorbase.cpp new file mode 100644 index 0000000..b06426d --- /dev/null +++ b/src/dbusadaptorbase.cpp @@ -0,0 +1,25 @@ +#include "dbusadaptorbase.h" +#include + +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(); +} diff --git a/src/dbusadaptorbase.h b/src/dbusadaptorbase.h new file mode 100644 index 0000000..5c1b7dc --- /dev/null +++ b/src/dbusadaptorbase.h @@ -0,0 +1,24 @@ +#ifndef DBUSADAPTORBASE_H +#define DBUSADAPTORBASE_H + +#include +#include +#include + +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 diff --git a/src/freedesktopdbusadaptor.cpp b/src/freedesktopdbusadaptor.cpp new file mode 100644 index 0000000..726586b --- /dev/null +++ b/src/freedesktopdbusadaptor.cpp @@ -0,0 +1,31 @@ +#include "freedesktopdbusadaptor.h" + +#include + +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"); +} diff --git a/src/freedesktopdbusadaptor.h b/src/freedesktopdbusadaptor.h new file mode 100644 index 0000000..a5c51ec --- /dev/null +++ b/src/freedesktopdbusadaptor.h @@ -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 diff --git a/src/harbour-seaprint.cpp b/src/harbour-seaprint.cpp index ca7766d..032d6ef 100644 --- a/src/harbour-seaprint.cpp +++ b/src/harbour-seaprint.cpp @@ -10,7 +10,8 @@ #include #include #include -#include +#include +#include #include "argget.h" #include @@ -70,7 +71,8 @@ int main(int argc, char *argv[]) view->engine()->addImportPath(SailfishApp::pathTo("qml/pages").toString()); view->setSource(SailfishApp::pathToMainQml()); - DBusAdaptor dbus(view); + FreedesktopDBusAdaptor freedesktopDbus(view); + SeaPrintDBusAdaptor seaprintDbus(view); if (!QDBusConnection::sessionBus().registerObject("/net/attah/seaprint", view)) qWarning() << "Could not register /net/attah/seaprint D-Bus object.";