Commit 249ea021 authored by Jan Grulich's avatar Jan Grulich
Browse files

WIP: add print portal with PreparePrint method implemented

parent 0e5e229b
......@@ -19,6 +19,7 @@ include(FeatureSummary)
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
Core
DBus
PrintSupport
Widgets
)
......
[portal]
DBusName=org.freedesktop.impl.portal.desktop.kde
Interfaces=org.freedesktop.impl.portal.FileChooser;org.freedesktop.impl.portal.AppChooser;org.freedesktop.impl.portal.Notification
Interfaces=org.freedesktop.impl.portal.FileChooser;org.freedesktop.impl.portal.AppChooser;org.freedesktop.impl.portal.Notification;org.freedesktop.impl.portal.Print
UseIn=KDE
add_definitions(-DTRANSLATION_DOMAIN="xdg-desktop-portal-kde")
include_directories(
${Qt5PrintSupport_PRIVATE_INCLUDE_DIRS}
)
set(xdg_desktop_portal_kde_SRCS
xdg-desktop-portal-kde.cpp
appchooser.cpp
......@@ -7,6 +11,7 @@ set(xdg_desktop_portal_kde_SRCS
desktopportal.cpp
filechooser.cpp
notification.cpp
print.cpp
# DBus related stuff (not used right now)
# dbus/AppChooserAdaptor.cpp
......@@ -24,6 +29,7 @@ add_executable(xdg-desktop-portal-kde ${xdg_desktop_portal_kde_SRCS})
target_link_libraries(xdg-desktop-portal-kde
Qt5::Core
Qt5::DBus
Qt5::PrintSupport
Qt5::Widgets
KF5::I18n
KF5::Notifications
......
......@@ -34,7 +34,7 @@ AppChooser::~AppChooser()
{
}
uint AppChooser::ChooseApplication(const QDBusObjectPath& handle,
uint AppChooser::chooseApplication(const QDBusObjectPath& handle,
const QString& app_id,
const QString& parent_window,
const QStringList& choices,
......
......@@ -33,7 +33,7 @@ public:
~AppChooser();
public Q_SLOTS:
uint ChooseApplication(const QDBusObjectPath &handle,
uint chooseApplication(const QDBusObjectPath &handle,
const QString &app_id,
const QString &parent_window,
const QStringList &choices,
......
......@@ -33,6 +33,7 @@ DesktopPortal::DesktopPortal(QObject *parent)
, m_appChooser(new AppChooser())
, m_fileChooser(new FileChooser())
, m_notification(new Notification())
, m_print(new Print())
{
}
......@@ -41,6 +42,7 @@ DesktopPortal::~DesktopPortal()
delete m_appChooser;
delete m_fileChooser;
delete m_notification;
delete m_print;
}
bool DesktopPortal::handleMessage(const QDBusMessage &message, const QDBusConnection &connection)
......@@ -61,12 +63,9 @@ bool DesktopPortal::handleMessage(const QDBusMessage &message, const QDBusConnec
QVariantMap choices;
QDBusArgument dbusArgument = message.arguments().at(4).value<QDBusArgument>();
while (!dbusArgument.atEnd()) {
dbusArgument >> choices;
}
dbusArgument >> choices;
qCDebug(XdgDesktopPortalKdeDesktopPortal) << choices;
uint response = m_appChooser->ChooseApplication(qvariant_cast<QDBusObjectPath>(message.arguments().at(0)), // handle
uint response = m_appChooser->chooseApplication(qvariant_cast<QDBusObjectPath>(message.arguments().at(0)), // handle
message.arguments().at(1).toString(), // app_id
message.arguments().at(2).toString(), // parent_window
message.arguments().at(3).toStringList(), // choices
......@@ -81,19 +80,17 @@ bool DesktopPortal::handleMessage(const QDBusMessage &message, const QDBusConnec
QVariantMap choices;
QDBusArgument dbusArgument = message.arguments().at(4).value<QDBusArgument>();
while (!dbusArgument.atEnd()) {
dbusArgument >> choices;
}
dbusArgument >> choices;
if (message.member() == QLatin1String("OpenFile")) {
response = m_fileChooser->OpenFile(qvariant_cast<QDBusObjectPath>(message.arguments().at(0)), // handle
response = m_fileChooser->openFile(qvariant_cast<QDBusObjectPath>(message.arguments().at(0)), // handle
message.arguments().at(1).toString(), // app_id
message.arguments().at(2).toString(), // parent_window
message.arguments().at(3).toString(), // title
choices, // options
results);
} else if (message.member() == QLatin1String("SaveFile")) {
response = m_fileChooser->SaveFile(qvariant_cast<QDBusObjectPath>(message.arguments().at(0)), // handle
response = m_fileChooser->saveFile(qvariant_cast<QDBusObjectPath>(message.arguments().at(0)), // handle
message.arguments().at(1).toString(), // app_id
message.arguments().at(2).toString(), // parent_window
message.arguments().at(3).toString(), // title
......@@ -103,21 +100,64 @@ bool DesktopPortal::handleMessage(const QDBusMessage &message, const QDBusConnec
arguments << response;
arguments << results;
} else if (message.interface() == QLatin1String("org.freedesktop.impl.portal.Notification")) {
if (message.member() == QLatin1String("AddNotification")) {
QVariantMap notificationParams;
QDBusArgument dbusArgument = message.arguments().at(2).value<QDBusArgument>();
while (!dbusArgument.atEnd()) {
dbusArgument >> notificationParams;
}
m_notification->AddNotification(message.arguments().at(0).toString(), // app_id
dbusArgument >> notificationParams;
m_notification->addNotification(message.arguments().at(0).toString(), // app_id
message.arguments().at(1).toString(), // id
notificationParams); // notification
} else if (message.member() == QLatin1String("RemoveNotification")) {
m_notification->RemoveNotification(message.arguments().at(0).toString(), // app_id
m_notification->removeNotification(message.arguments().at(0).toString(), // app_id
message.arguments().at(1).toString()); // id
}
} else if (message.interface() == QLatin1String("org.freedesktop.impl.portal.Print")) {
uint response;
QVariantMap results;
if (message.member() == QLatin1String("Print")) {
QVariantMap options;
QDBusArgument dbusArgument = message.arguments().at(5).value<QDBusArgument>();
dbusArgument >> options;
response = m_print->print(qvariant_cast<QDBusObjectPath>(message.arguments().at(0)), // handle
message.arguments().at(1).toString(), // app_id
message.arguments().at(2).toString(), // parent_window
message.arguments().at(3).toString(), // title
qvariant_cast<QDBusUnixFileDescriptor>(message.arguments().at(4)), // fd
options, // options
results);
} else if (message.member() == QLatin1String("PreparePrint")) {
QVariantMap settings;
QVariantMap pageSetup;
QVariantMap options;
QDBusArgument dbusArgument = message.arguments().at(4).value<QDBusArgument>();
dbusArgument >> settings;
QDBusArgument dbusArgument1 = message.arguments().at(5).value<QDBusArgument>();
dbusArgument1 >> pageSetup;
QDBusArgument dbusArgument2 = message.arguments().at(6).value<QDBusArgument>();
dbusArgument2 >> options;
response = m_print->preparePrint(qvariant_cast<QDBusObjectPath>(message.arguments().at(0)), // handle
message.arguments().at(1).toString(), // app_id
message.arguments().at(2).toString(), // parent_window
message.arguments().at(3).toString(), // title
settings, // settings
pageSetup, // page_setup
options, // options
results);
}
arguments << response;
arguments << results;
}
QDBusMessage reply = message.createReply();
......@@ -178,6 +218,29 @@ QString DesktopPortal::introspect(const QString &path) const
" <arg type=\"s\" name=\"action\"/>"
" <arg type=\"av\" name=\"parameter\"/>"
" </signal>"
"</interface>"
"<interface name=\"org.freedesktop.impl.portal.Print\">"
" <method name=\"Print\">"
" <arg type=\"o\" name=\"handle\" direction=\"in\"/>"
" <arg type=\"s\" name=\"app_id\" direction=\"in\"/>"
" <arg type=\"s\" name=\"parent_window\" direction=\"in\"/>"
" <arg type=\"s\" name=\"title\" direction=\"in\"/>"
" <arg type=\"h\" name=\"fd\" direction=\"in\"/>"
" <arg type=\"a{sv}\" name=\"options\" direction=\"in\"/>"
" <arg type=\"u\" name=\"response\" direction=\"out\"/>"
" <arg type=\"a{sv}\" name=\"results\" direction=\"out\"/>"
" </method>"
" <method name=\"PreparePrint\">"
" <arg type=\"o\" name=\"handle\" direction=\"in\"/>"
" <arg type=\"s\" name=\"app_id\" direction=\"in\"/>"
" <arg type=\"s\" name=\"parent_window\" direction=\"in\"/>"
" <arg type=\"s\" name=\"title\" direction=\"in\"/>"
" <arg type=\"a{sv}\" name=\"settings\" direction=\"in\"/>"
" <arg type=\"a{sv}\" name=\"page_setup\" direction=\"in\"/>"
" <arg type=\"a{sv}\" name=\"options\" direction=\"in\"/>"
" <arg type=\"u\" name=\"response\" direction=\"out\"/>"
" <arg type=\"a{sv}\" name=\"results\" direction=\"out\"/>"
" </method>"
"</interface>");
}
......
......@@ -27,6 +27,7 @@
#include "appchooser.h"
#include "filechooser.h"
#include "notification.h"
#include "print.h"
class DesktopPortal : public QDBusVirtualObject
{
......@@ -41,6 +42,7 @@ private:
AppChooser *m_appChooser;
FileChooser *m_fileChooser;
Notification *m_notification;
Print *m_print;
};
#endif // XDG_DESKTOP_PORTAL_KDE_DESKTOP_PORTAL_H
......
......@@ -88,7 +88,7 @@ FileChooser::~FileChooser()
{
}
uint FileChooser::OpenFile(const QDBusObjectPath &handle,
uint FileChooser::openFile(const QDBusObjectPath &handle,
const QString &app_id,
const QString &parent_window,
const QString &title,
......@@ -179,7 +179,7 @@ uint FileChooser::OpenFile(const QDBusObjectPath &handle,
return 1;
}
uint FileChooser::SaveFile(const QDBusObjectPath &handle,
uint FileChooser::saveFile(const QDBusObjectPath &handle,
const QString &app_id,
const QString &parent_window,
const QString &title,
......
......@@ -47,14 +47,14 @@ public:
~FileChooser();
public Q_SLOTS:
uint OpenFile(const QDBusObjectPath &handle,
uint openFile(const QDBusObjectPath &handle,
const QString &app_id,
const QString &parent_window,
const QString &title,
const QVariantMap &options,
QVariantMap &results);
uint SaveFile(const QDBusObjectPath &handle,
uint saveFile(const QDBusObjectPath &handle,
const QString &app_id,
const QString &parent_window,
const QString &title,
......
......@@ -36,7 +36,7 @@ Notification::~Notification()
{
}
void Notification::AddNotification(const QString &app_id,
void Notification::addNotification(const QString &app_id,
const QString &id,
const QVariantMap &notification)
{
......@@ -114,7 +114,7 @@ void Notification::notificationActivated(uint action)
QDBusConnection::sessionBus().send(message);
}
void Notification::RemoveNotification(const QString &app_id,
void Notification::removeNotification(const QString &app_id,
const QString &id)
{
qCDebug(XdgDesktopPortalKdeNotification) << "RemoveNotification called with parameters:";
......
......@@ -35,10 +35,10 @@ public:
~Notification();
public Q_SLOTS:
void AddNotification(const QString &app_id,
void addNotification(const QString &app_id,
const QString &id,
const QVariantMap &notification);
void RemoveNotification(const QString &app_id,
void removeNotification(const QString &app_id,
const QString &id);
private Q_SLOTS:
void notificationActivated(uint action);
......
This diff is collapsed.
/*
* Copyright © 2016 Red Hat, Inc
*
* This program 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 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, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Jan Grulich <jgrulich@redhat.com>
*/
#ifndef XDG_DESKTOP_PORTAL_KDE_PRINT_H
#define XDG_DESKTOP_PORTAL_KDE_PRINT_H
#include <QObject>
#include <QDBusObjectPath>
#include <QDBusUnixFileDescriptor>
#include <QPrinter>
#include <QPageSize>
class Print : public QObject
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.freedesktop.impl.portal.Print")
public:
Print(QObject *parent = 0);
~Print();
public Q_SLOTS:
uint print(const QDBusObjectPath &handle,
const QString &app_id,
const QString &parent_window,
const QString &title,
const QDBusUnixFileDescriptor &fd,
const QVariantMap &options,
QVariantMap &results);
uint preparePrint(const QDBusObjectPath &handle,
const QString &app_id,
const QString &parent_window,
const QString &title,
const QVariantMap &settings,
const QVariantMap &page_setup,
const QVariantMap &options,
QVariantMap &results);
private:
QMap<uint, QPrinter*> m_printers;
};
#endif // XDG_DESKTOP_PORTAL_KDE_PRINT_H
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment