/* -*- 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 .
*/
OUString getResString(TranslateId pResId)
{ if (!pResId) return {};
return FpsResId(pResId);
}
// handles the IPC commands for dialog execution and ends the dummy Gtk dialog once the IPC response is there staticvoid handleIpcForExecute(Gtk3KDE5FilePickerIpc* pFilePickerIpc, GtkWidget* pDummyDialog, bool* bResult)
{ auto id = pFilePickerIpc->sendCommand(Commands::Execute);
pFilePickerIpc->readResponse(id, *bResult);
// end the dummy dialog
gtk_widget_set_visible(pDummyDialog, false);
}
if (m_inputWrite)
osl_closeFile(m_inputWrite); if (m_outputRead)
osl_closeFile(m_outputRead);
osl_freeProcessHandle(m_process);
}
sal_Int16 Gtk3KDE5FilePickerIpc::execute()
{ auto restoreMainWindow = blockMainWindow();
// dummy gtk dialog that will take care of processing events, // not meant to be actually seen by user
GtkWidget* pDummyDialog = gtk_dialog_new();
bool accepted = false;
// send IPC command and read response in a separate thread
std::thread aIpcHandler(&handleIpcForExecute, this, pDummyDialog, &accepted);
// make dummy dialog not to be seen by user
gtk_window_set_decorated(GTK_WINDOW(pDummyDialog), false);
gtk_window_set_default_size(GTK_WINDOW(pDummyDialog), 0, 0);
gtk_window_set_accept_focus(GTK_WINDOW(pDummyDialog), false); // gtk_widget_set_opacity() only has the desired effect when widget is already shown
gtk_widget_set_visible(pDummyDialog, true);
gtk_widget_set_opacity(pDummyDialog, 0); // run dialog, leaving event processing to GTK // dialog will be closed by the separate 'aIpcHandler' thread once the IPC response is there
gtk_dialog_run(GTK_DIALOG(pDummyDialog));
// prevent the window from being closed auto ignoreDeleteEventHandler
= g_signal_connect(pMainWindow, "delete_event", G_CALLBACK(ignoreDeleteEvent), nullptr);
std::string Gtk3KDE5FilePickerIpc::readResponseLine()
{ if (!m_responseBuffer.empty()) // check whether we have a line in our buffer
{
std::size_t it = m_responseBuffer.find('\n'); if (it != std::string::npos)
{ auto ret = m_responseBuffer.substr(0, it);
m_responseBuffer.erase(0, it + 1); return ret;
}
}
const sal_uInt64 BUF_SIZE = 1024; char buffer[BUF_SIZE]; while (true)
{
sal_uInt64 bytesRead = 0; auto err = osl_readFile(m_outputRead, buffer, BUF_SIZE, &bytesRead); auto it = std::find(buffer, buffer + bytesRead, '\n'); if (it != buffer + bytesRead) // check whether the chunk we read contains an EOL
{ // if so, append that part to the buffer and return it
std::string ret = m_responseBuffer.append(buffer, it); // but keep anything else we may have read in our buffer
++it;
m_responseBuffer.assign(it, buffer + bytesRead); return ret;
} // otherwise append everything we read to the buffer and try again
m_responseBuffer.append(buffer, bytesRead);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.