// stop processing once 'Quit' command has been sent if (command == Commands::Quit)
{ return;
}
}
}
FilePickerIpc::FilePickerIpc(KDE5FilePicker* filePicker, QObject* parent)
: QObject(parent)
, m_filePicker(filePicker)
{ // required to be able to pass those via signal/slot
qRegisterMetaType<uint64_t>("uint64_t");
qRegisterMetaType<Commands>("Commands");
// read IPC commands and their args in a separate thread, so this does not block everything else; // 'commandReceived' signal is emitted every time a command and its args have been read; // thread will run until the filepicker process is terminated
m_ipcReaderThread = std::make_unique<std::thread>(readCommands, this);
}
FilePickerIpc::~FilePickerIpc()
{ // join thread that reads commands
m_ipcReaderThread->join();
};
bool FilePickerIpc::handleCommand(uint64_t messageId, Commands command, QList<QVariant> args)
{ switch (command)
{ case Commands::SetTitle:
{
QString title = args.takeFirst().toString();
m_filePicker->setTitle(title); returntrue;
} case Commands::SetWinId:
{
sal_uIntPtr winId = args.takeFirst().value<sal_uIntPtr>();
m_filePicker->setWinId(winId); returntrue;
} case Commands::Execute:
{
sendIpcArgs(std::cout, messageId, m_filePicker->execute()); returntrue;
} case Commands::SetMultiSelectionMode:
{ bool multiSelection = args.takeFirst().toBool();
m_filePicker->setMultiSelectionMode(multiSelection); returntrue;
} case Commands::SetDefaultName:
{
QString name = args.takeFirst().toString();
m_filePicker->setDefaultName(name); returntrue;
} case Commands::SetDisplayDirectory:
{
QString dir = args.takeFirst().toString();
m_filePicker->setDisplayDirectory(dir); returntrue;
} case Commands::GetDisplayDirectory:
{
sendIpcArgs(std::cout, messageId, m_filePicker->getDisplayDirectory()); returntrue;
} case Commands::GetSelectedFiles:
{
QStringList files; for (autoconst& url_ : m_filePicker->getSelectedFiles())
{ auto url = url_; if (url.scheme() == QLatin1String("webdav")
|| url.scheme() == QLatin1String("webdavs"))
{ // translate webdav and webdavs URLs into a format supported by LO
url.setScheme(QLatin1String("vnd.sun.star.") + url.scheme());
} elseif (url.scheme() == QLatin1String("smb"))
{ // clear the user name - the GIO backend does not support this apparently // when no username is available, it will ask for the password
url.setUserName({});
}
files << url.toString();
}
sendIpcArgs(std::cout, messageId, files); returntrue;
} case Commands::AppendFilter:
{
QString title = args.takeFirst().toString();
QString filter = args.takeFirst().toString();
m_filePicker->appendFilter(title, filter); returntrue;
} case Commands::SetCurrentFilter:
{
QString title = args.takeFirst().toString();
m_filePicker->setCurrentFilter(title); returntrue;
} case Commands::GetCurrentFilter:
{
sendIpcArgs(std::cout, messageId, m_filePicker->getCurrentFilter()); returntrue;
} case Commands::SetValue:
{
sal_Int16 controlId = args.takeFirst().value<sal_Int16>();
sal_Int16 nControlAction = args.takeFirst().value<sal_Int16>(); bool value = args.takeFirst().toBool();
m_filePicker->setValue(controlId, nControlAction, value); returntrue;
} case Commands::GetValue:
{
sal_Int16 controlId = args.takeFirst().value<sal_Int16>();
sal_Int16 nControlAction = args.takeFirst().value<sal_Int16>();
sendIpcArgs(std::cout, messageId, m_filePicker->getValue(controlId, nControlAction)); returntrue;
} case Commands::EnableControl:
{
sal_Int16 controlId = args.takeFirst().value<sal_Int16>(); bool enabled = args.takeFirst().toBool();
m_filePicker->enableControl(controlId, enabled); returntrue;
} case Commands::SetLabel:
{
sal_Int16 controlId = args.takeFirst().value<sal_Int16>();
QString label = args.takeFirst().toString();
m_filePicker->setLabel(controlId, label); returntrue;
} case Commands::GetLabel:
{
sal_Int16 controlId = args.takeFirst().value<sal_Int16>();
sendIpcArgs(std::cout, messageId, m_filePicker->getLabel(controlId)); returntrue;
} case Commands::AddCheckBox:
{
sal_Int16 controlId = args.takeFirst().value<sal_Int16>(); bool hidden = args.takeFirst().toBool();
QString label = args.takeFirst().toString();
m_filePicker->addCheckBox(controlId, label, hidden); returntrue;
} case Commands::Initialize:
{ bool saveDialog = args.takeFirst().toBool();
m_filePicker->initialize(saveDialog); returntrue;
} case Commands::EnablePickFolderMode:
{
m_filePicker->enableFolderMode(); returntrue;
} case Commands::Quit:
{
QCoreApplication::quit(); returnfalse;
}
}
qWarning() << "unhandled command " << static_cast<uint16_t>(command);
QCoreApplication::exit(1); returnfalse;
}
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.