Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Plasma
KDE Portal for XDG Desktop
Commits
249ea021
Commit
249ea021
authored
Dec 15, 2016
by
Jan Grulich
Browse files
WIP: add print portal with PreparePrint method implemented
parent
0e5e229b
Changes
13
Expand all
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
249ea021
...
...
@@ -19,6 +19,7 @@ include(FeatureSummary)
find_package
(
Qt5
${
QT_MIN_VERSION
}
CONFIG REQUIRED COMPONENTS
Core
DBus
PrintSupport
Widgets
)
...
...
data/kde.portal
View file @
249ea021
[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
src/CMakeLists.txt
View file @
249ea021
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
...
...
src/appchooser.cpp
View file @
249ea021
...
...
@@ -34,7 +34,7 @@ AppChooser::~AppChooser()
{
}
uint
AppChooser
::
C
hooseApplication
(
const
QDBusObjectPath
&
handle
,
uint
AppChooser
::
c
hooseApplication
(
const
QDBusObjectPath
&
handle
,
const
QString
&
app_id
,
const
QString
&
parent_window
,
const
QStringList
&
choices
,
...
...
src/appchooser.h
View file @
249ea021
...
...
@@ -33,7 +33,7 @@ public:
~
AppChooser
();
public
Q_SLOTS
:
uint
C
hooseApplication
(
const
QDBusObjectPath
&
handle
,
uint
c
hooseApplication
(
const
QDBusObjectPath
&
handle
,
const
QString
&
app_id
,
const
QString
&
parent_window
,
const
QStringList
&
choices
,
...
...
src/desktopportal.cpp
View file @
249ea021
...
...
@@ -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
->
O
penFile
(
qvariant_cast
<
QDBusObjectPath
>
(
message
.
arguments
().
at
(
0
)),
// handle
response
=
m_fileChooser
->
o
penFile
(
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
->
S
aveFile
(
qvariant_cast
<
QDBusObjectPath
>
(
message
.
arguments
().
at
(
0
)),
// handle
response
=
m_fileChooser
->
s
aveFile
(
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
->
R
emoveNotification
(
message
.
arguments
().
at
(
0
).
toString
(),
// app_id
m_notification
->
r
emoveNotification
(
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>"
);
}
...
...
src/desktopportal.h
View file @
249ea021
...
...
@@ -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
...
...
src/filechooser.cpp
View file @
249ea021
...
...
@@ -88,7 +88,7 @@ FileChooser::~FileChooser()
{
}
uint
FileChooser
::
O
penFile
(
const
QDBusObjectPath
&
handle
,
uint
FileChooser
::
o
penFile
(
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
::
S
aveFile
(
const
QDBusObjectPath
&
handle
,
uint
FileChooser
::
s
aveFile
(
const
QDBusObjectPath
&
handle
,
const
QString
&
app_id
,
const
QString
&
parent_window
,
const
QString
&
title
,
...
...
src/filechooser.h
View file @
249ea021
...
...
@@ -47,14 +47,14 @@ public:
~
FileChooser
();
public
Q_SLOTS
:
uint
O
penFile
(
const
QDBusObjectPath
&
handle
,
uint
o
penFile
(
const
QDBusObjectPath
&
handle
,
const
QString
&
app_id
,
const
QString
&
parent_window
,
const
QString
&
title
,
const
QVariantMap
&
options
,
QVariantMap
&
results
);
uint
S
aveFile
(
const
QDBusObjectPath
&
handle
,
uint
s
aveFile
(
const
QDBusObjectPath
&
handle
,
const
QString
&
app_id
,
const
QString
&
parent_window
,
const
QString
&
title
,
...
...
src/notification.cpp
View file @
249ea021
...
...
@@ -36,7 +36,7 @@ Notification::~Notification()
{
}
void
Notification
::
A
ddNotification
(
const
QString
&
app_id
,
void
Notification
::
a
ddNotification
(
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
::
R
emoveNotification
(
const
QString
&
app_id
,
void
Notification
::
r
emoveNotification
(
const
QString
&
app_id
,
const
QString
&
id
)
{
qCDebug
(
XdgDesktopPortalKdeNotification
)
<<
"RemoveNotification called with parameters:"
;
...
...
src/notification.h
View file @
249ea021
...
...
@@ -35,10 +35,10 @@ public:
~
Notification
();
public
Q_SLOTS
:
void
A
ddNotification
(
const
QString
&
app_id
,
void
a
ddNotification
(
const
QString
&
app_id
,
const
QString
&
id
,
const
QVariantMap
&
notification
);
void
R
emoveNotification
(
const
QString
&
app_id
,
void
r
emoveNotification
(
const
QString
&
app_id
,
const
QString
&
id
);
private
Q_SLOTS
:
void
notificationActivated
(
uint
action
);
...
...
src/print.cpp
0 → 100644
View file @
249ea021
This diff is collapsed.
Click to expand it.
src/print.h
0 → 100644
View file @
249ea021
/*
* 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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment