author | Milian Wolff <milian.wolff@kdab.com> | 2018-01-10 17:50:43 +0100 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2018-01-23 13:38:46 +0100 |
commit | ecb5fcff336c8b0e5ad2503f0880c439a6c323a5 (patch) | |
tree | 74842b234a07f1c07340bdb50fcda97d1ee6bd8c /vcl/unx/gtk3_kde5/kde5_filepicker_ipc.cxx | |
parent | f811979b0865b15272ce4a62df3ebd0fa8896b55 (diff) |
-rw-r--r-- | vcl/unx/gtk3_kde5/kde5_filepicker_ipc.cxx | 223 |
diff --git a/vcl/unx/gtk3_kde5/kde5_filepicker_ipc.cxx b/vcl/unx/gtk3_kde5/kde5_filepicker_ipc.cxx new file mode 100644 index 000000000000..9911219d010a --- /dev/null +++ b/vcl/unx/gtk3_kde5/kde5_filepicker_ipc.cxx @@ -0,0 +1,223 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "kde5_filepicker_ipc.hxx" + +#include <QSocketNotifier> +#include <QUrl> +#include <QThread> +#include <QApplication> +#include <QDebug> + +#include <iostream> + +#include "filepicker_ipc_commands.hxx" +#include "kde5_filepicker.hxx" + +#include <rtl/ustring.h> + +void readIpcArg(std::istream& stream, QString& string) +{ + const auto buffer = readIpcStringArg(stream); + string = QString::fromUtf8(buffer.data(), buffer.size()); +} + +void sendIpcArg(std::ostream& stream, const QString& string) +{ + const auto utf8 = string.toUtf8(); + sendIpcStringArg(stream, utf8.size(), utf8.data()); +} + +void sendIpcArg(std::ostream& stream, const QList<QUrl>& urls) +{ + stream << static_cast<uint32_t>(urls.size()) << ' '; + for (const auto& url : urls) + { + sendIpcArg(stream, url.toString()); + } +} + +FilePickerIpc::FilePickerIpc(KDE5FilePicker* filePicker, QObject* parent) + : QObject(parent) + , m_filePicker(filePicker) + , m_stdinNotifier(new QSocketNotifier(fileno(stdin), QSocketNotifier::Read, this)) +{ + connect(m_stdinNotifier, &QSocketNotifier::activated, this, &FilePickerIpc::readCommands); +} + +FilePickerIpc::~FilePickerIpc() = default; + +void FilePickerIpc::readCommands() +{ + while (!std::cin.eof()) + { + readCommand(); + } +} + +void FilePickerIpc::readCommand() +{ + uint64_t messageId = 0; + Commands command; + readIpcArgs(std::cin, messageId, command); + + switch (command) + { + case Commands::SetTitle: + { + QString title; + readIpcArgs(std::cin, title); + m_filePicker->setTitle(title); + return; + } + case Commands::SetWinId: + { + sal_uIntPtr winId = 0; + readIpcArgs(std::cin, winId); + m_filePicker->setWinId(winId); + return; + } + case Commands::Execute: + { + sendIpcArgs(std::cout, messageId, m_filePicker->execute()); + return; + } + case Commands::SetMultiSelectionMode: + { + bool multiSelection = false; + readIpcArgs(std::cin, multiSelection); + m_filePicker->setMultiSelectionMode(multiSelection); + return; + } + case Commands::SetDefaultName: + { + QString name; + readIpcArgs(std::cin, name); + m_filePicker->setDefaultName(name); + return; + } + case Commands::SetDisplayDirectory: + { + QString dir; + readIpcArgs(std::cin, dir); + m_filePicker->setDisplayDirectory(dir); + return; + } + case Commands::GetDisplayDirectory: + { + sendIpcArgs(std::cout, messageId, m_filePicker->getDisplayDirectory()); + return; + } + case Commands::GetSelectedFiles: + { + sendIpcArgs(std::cout, messageId, m_filePicker->getSelectedFiles()); + return; + } + case Commands::AppendFilter: + { + QString title, filter; + readIpcArgs(std::cin, title, filter); + m_filePicker->appendFilter(title, filter); + return; + } + case Commands::SetCurrentFilter: + { + QString title; + readIpcArgs(std::cin, title); + m_filePicker->setCurrentFilter(title); + return; + } + case Commands::GetCurrentFilter: + { + sendIpcArgs(std::cout, messageId, m_filePicker->getCurrentFilter()); + return; + } + case Commands::SetValue: + { + sal_Int16 controlId = 0; + sal_Int16 nControlAction = 0; + bool value = false; + readIpcArgs(std::cin, controlId, nControlAction, value); |