Commit 849914b6 authored by Jan Grulich's avatar Jan Grulich
Browse files

Initial version

parent 295ca79c
project(xdg-desktop-portal-kde)
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
set(QT_MIN_VERSION "5.4.0")
################# set KDE specific information #################
find_package(ECM 1.3.0 REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings NO_POLICY_SCOPE)
include(ECMPackageConfigHelpers)
include(ECMOptionalAddSubdirectory)
include(FeatureSummary)
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
Core
DBus
Widgets
)
add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0 -DQT_NO_KEYWORDS)
add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS)
remove_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_STRICT_ITERATORS -DQT_NO_CAST_FROM_BYTEARRAY)
add_subdirectory(data)
add_subdirectory(src)
feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAGES)
This diff is collapsed.
#! /usr/bin/env bash
$EXTRACTRC `find . -name "*.ui" -o -name "*.rc"` >> rc.cpp
$XGETTEXT `find . -name "*.cpp"` -o $podir/xdg-desktop-portal-kde.pot
rm -f rc.cpp
# xdg-desktop-portal-kde
\ No newline at end of file
# xdg-desktop-portal-kde
A backend implementation for [xdg-desktop-portal](http://github.com/flatpak/xdg-desktop-portal)
that is using Qt/KDE.
## Building xdg-desktop-portal-gtk
### Dependencies:
- xdg-desktop-portal (runtime)
- flatpak (runtime)
- Qt 5 (build)
- KDE Frameworks (build)
### Build instructions:
```
$ ./src/dbus/generate-interfaces-adaptors.sh
$ mkdir build && cd build
$ cmake .. [your_options]
$ make -j5
$ make install
```
configure_file(org.freedesktop.impl.portal.desktop.kde.cmake.in org.freedesktop.impl.portal.desktop.kde.service @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.freedesktop.impl.portal.desktop.kde.service DESTINATION ${KDE_INSTALL_DBUSSERVICEDIR})
install(FILES kde.portal DESTINATION ${DATA_INSTALL_DIR}/xdg-desktop-portal/portals)
[portal]
DBusName=org.freedesktop.impl.portal.desktop.kde
Interfaces=org.freedesktop.impl.portal.FileChooser
UseIn=KDE
[D-BUS Service]
Name=org.freedesktop.impl.portal.desktop.kde
Exec=@CMAKE_INSTALL_LIBEXECDIR@/xdg-desktop-portal-kde
add_definitions(-DTRANSLATION_DOMAIN="xdg-desktop-portal-kde")
set(xdg_desktop_portal_kde_SRCS
xdg-desktop-portal-kde.cpp
filechooser.cpp
# DBus related stuff
dbus/FileChooserAdaptor.cpp
dbus/FileChooserInterface.cpp
)
add_executable(xdg-desktop-portal-kde ${xdg_desktop_portal_kde_SRCS})
target_link_libraries(xdg-desktop-portal-kde
Qt5::Core
Qt5::DBus
Qt5::Widgets
)
install(TARGETS xdg-desktop-portal-kde DESTINATION ${KDE_INSTALL_LIBEXECDIR})
#! /bin/sh
# TODO: do not hardcore path to xml files
DESKTOP_PORTALS=( # Access - missing Qt annotations
"AppChooser"
"FileChooser"
"Inhibit"
"Notification"
"Print"
"Request"
"Screenshot")
for x in ${DESKTOP_PORTALS[@]}; do
qdbusxml2cpp -N -m -l ${x} -i "`echo "$x" | awk '{print tolower($0)}'`.h" -a "${x}Adaptor" "/usr/share/dbus-1/interfaces/org.freedesktop.impl.portal.${x}.xml"
qdbusxml2cpp -N -m -p "${x}Interface" "/usr/share/dbus-1/interfaces/org.freedesktop.impl.portal.${x}.xml"
done
/*
* 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>
*/
#include "filechooser.h"
#include <QLoggingCategory>
#include <QFileDialog>
Q_LOGGING_CATEGORY(XdgDesktopPortalKdeFileChooser, "xdg-desktop-portal-kde-file-chooser")
FileChooser::FileChooser(QObject *parent)
: QObject(parent)
{
}
FileChooser::~FileChooser()
{
}
uint FileChooser::OpenFile(const QDBusObjectPath &handle,
const QString &app_id,
const QString &parent_window,
const QString &title,
const QVariantMap &options,
QVariantMap &results)
{
Q_UNUSED(app_id);
qCDebug(XdgDesktopPortalKdeFileChooser) << "OpenFile called with parameters:";
qCDebug(XdgDesktopPortalKdeFileChooser) << " handle: " << handle.path();
qCDebug(XdgDesktopPortalKdeFileChooser) << " parent_window: " << parent_window;
qCDebug(XdgDesktopPortalKdeFileChooser) << " title: " << title;
qCDebug(XdgDesktopPortalKdeFileChooser) << " options: " << options;
QString acceptLabel;
bool modalDialog = true;
bool multipleFiles = false;
// TODO parse options - filters, choices
if (options.contains(QLatin1String("multiple"))) {
multipleFiles = options.value(QLatin1String("multiple")).toBool();
}
if (options.contains(QLatin1String("modal"))) {
modalDialog = options.value(QLatin1String("modal")).toBool();
}
if (options.contains(QLatin1String("accept_label"))) {
acceptLabel = options.value(QLatin1String("accept_label")).toString();
}
QFileDialog *fileDialog = new QFileDialog();
fileDialog->setWindowTitle(title);
fileDialog->setModal(modalDialog);
fileDialog->setFileMode(multipleFiles ? QFileDialog::ExistingFiles : QFileDialog::ExistingFile);
if (!acceptLabel.isEmpty()) {
fileDialog->setLabelText(QFileDialog::Accept, acceptLabel);
}
if (fileDialog->exec() == QDialog::Accepted) {
QStringList files;
Q_FOREACH (const QString &filename, fileDialog->selectedFiles()) {
QUrl url = QUrl::fromLocalFile(filename);
files << url.toDisplayString();
}
results.insert(QLatin1String("uris"), files);
return 0;
}
return 1;
}
uint FileChooser::SaveFile(const QDBusObjectPath &handle,
const QString &app_id,
const QString &parent_window,
const QString &title,
const QVariantMap &options,
QVariantMap &results)
{
Q_UNUSED(app_id);
qCDebug(XdgDesktopPortalKdeFileChooser) << "SaveFile called with parameters:";
qCDebug(XdgDesktopPortalKdeFileChooser) << " handle: " << handle.path();
qCDebug(XdgDesktopPortalKdeFileChooser) << " parent_window: " << parent_window;
qCDebug(XdgDesktopPortalKdeFileChooser) << " title: " << title;
qCDebug(XdgDesktopPortalKdeFileChooser) << " options: " << options;
QString acceptLabel;
QString currentName;
QString currentFolder;
QString currentFile;
bool modalDialog = true;
// TODO parse options - filters, choices
if (options.contains(QLatin1String("modal"))) {
modalDialog = options.value(QLatin1String("modal")).toBool();
}
if (options.contains(QLatin1String("accept_label"))) {
acceptLabel = options.value(QLatin1String("accept_label")).toString();
}
if (options.contains(QLatin1String("current_name"))) {
currentName = options.value(QLatin1String("current_name")).toString();
}
if (options.contains(QLatin1String("current_folder"))) {
currentFolder = options.value(QLatin1String("current_folder")).toString();
}
if (options.contains(QLatin1String("current_file"))) {
currentFile = options.value(QLatin1String("current_file")).toString();
}
QFileDialog *fileDialog = new QFileDialog();
fileDialog->setWindowTitle(title);
fileDialog->setModal(modalDialog);
fileDialog->setAcceptMode(QFileDialog::AcceptSave);
if (!currentName.isEmpty()) {
fileDialog->selectFile(currentName);
}
if (!currentFolder.isEmpty()) {
fileDialog->setDirectory(currentFolder);
}
if (!currentFile.isEmpty()) {
fileDialog->selectFile(currentName);
}
if (!acceptLabel.isEmpty()) {
fileDialog->setLabelText(QFileDialog::Accept, acceptLabel);
}
if (fileDialog->exec() == QDialog::Accepted) {
QStringList files;
Q_FOREACH (const QString &filename, fileDialog->selectedFiles()) {
QUrl url = QUrl::fromLocalFile(filename);
files << url.toDisplayString();
}
results.insert(QLatin1String("uris"), files);
return 0;
}
return 1;
}
/*
* 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_FILECHOOSER_H
#define XDG_DESKTOP_PORTAL_KDE_FILECHOOSER_H
#include <QObject>
#include <QDBusObjectPath>
class FileChooser : public QObject
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.freedesktop.impl.portal.FileChooser")
public:
FileChooser(QObject *parent = 0);
~FileChooser();
public Q_SLOTS:
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,
const QString &app_id,
const QString &parent_window,
const QString &title,
const QVariantMap &options,
QVariantMap &results);
};
#endif // XDG_DESKTOP_PORTAL_KDE_FILECHOOSER_H
/*
* 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>
*/
#include <QApplication>
#include <QDBusConnection>
#include <QLoggingCategory>
#include "filechooser.h"
#include "dbus/FileChooserAdaptor.h"
Q_LOGGING_CATEGORY(XdgDesktopPortalKde, "xdg-desktop-portal-kde")
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setQuitOnLastWindowClosed(false);
QDBusConnection sessionBus = QDBusConnection::sessionBus();
if (sessionBus.registerService(QLatin1String("org.freedesktop.impl.portal.desktop.kde"))) {
qCDebug(XdgDesktopPortalKde) << "Service org.freedesktop.impl.portal.desktop.kde registered successfuly";
FileChooser *fileChooser = new FileChooser(&a);
FileChooserAdaptor *fileChooserAdaptor = new FileChooserAdaptor(fileChooser);
if (sessionBus.registerObject(QLatin1String("/org/freedesktop/portal/desktop"), fileChooser)) {
qCDebug(XdgDesktopPortalKde) << "Interface FileChooser registered successfuly";
} else {
qCDebug(XdgDesktopPortalKde) << "Failed to register FileChooser interface";
}
} else {
qCDebug(XdgDesktopPortalKde) << "Failed to register org.freedesktop.impl.portal.desktop.kde service";
}
return a.exec();
}
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