/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ /* * 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 .
*/
QtFilePicker::~QtFilePicker()
{
SolarMutexGuard g;
GetQtInstance().RunInMainThread([this]() { // must delete it in main thread, otherwise // QSocketNotifier::setEnabled() will crash us
m_pFileDialog.reset();
});
}
void QtFilePicker::prepareExecute()
{
QWidget* pTransientParent = m_pParentWidget; if (!pTransientParent)
{
vcl::Window* pWindow = ::Application::GetActiveTopWindow(); if (pWindow)
{
QtFrame* pFrame = dynamic_cast<QtFrame*>(pWindow->ImplGetFrame());
assert(pFrame); if (pFrame)
pTransientParent = pFrame->asChild();
}
}
if (!m_aNamedFilterList.isEmpty())
m_pFileDialog->setNameFilters(m_aNamedFilterList); if (!m_aCurrentFilter.isEmpty())
m_pFileDialog->selectNameFilter(m_aCurrentFilter);
uno::Sequence<OUString> seq(urls.size()); auto seqRange = asNonConstRange(seq);
autoconst trans = css::uri::ExternalUriReferenceTranslator::create(m_context);
size_t i = 0; for (const QUrl& aURL : urls)
{ // Unlike LO, QFileDialog (<https://doc.qt.io/qt-5/qfiledialog.html>) apparently always // treats file-system pathnames as UTF-8--encoded, regardless of LANG/LC_CTYPE locale // setting. And pathnames containing byte sequences that are not valid UTF-8 are apparently // filtered out and not even displayed by QFileDialog, so aURL will always have a "payload" // that matches the pathname's byte sequence. So the pathname's byte sequence (which // happens to also be aURL's payload) in the LANG/LC_CTYPE encoding needs to be converted // into LO's internal UTF-8 file URL encoding via // XExternalUriReferenceTranslator::translateToInternal (which looks somewhat paradoxical as // aURL.toEncoded() nominally already has a UTF-8 payload): autoconst extUrl = toOUString(aURL.toEncoded()); auto intUrl = trans->translateToInternal(extUrl); if (intUrl.isEmpty())
{ // If translation failed, fall back to original URL:
SAL_WARN("vcl.qt", "cannot convert <" << extUrl << "> from locale encoding to UTF-8");
intUrl = extUrl;
}
seqRange[i++] = intUrl;
}
// '/' need to be escaped else they are assumed to be mime types
QString sTitle = toQString(title).replace("/", "\\/");
QString sFilterName = sTitle; // the Qt non-native file picker adds the extensions to the filter title, so strip them if (m_pFileDialog->testOption(QFileDialog::DontUseNativeDialog))
{ int pos = sFilterName.indexOf(" ("); if (pos >= 0)
sFilterName.truncate(pos);
}
QString sGlobFilter = toQString(filter);
// LibreOffice gives us filters separated by ';' qt dialogs just want space separated
sGlobFilter.replace(";", " ");
// make sure "*.*" is not used as "all files"
sGlobFilter.replace("*.*", "*");
switch (controlId)
{ case CHECKBOX_AUTOEXTENSION:
resId = STR_SVT_FILEPICKER_AUTO_EXTENSION; break; case CHECKBOX_PASSWORD:
resId = STR_SVT_FILEPICKER_PASSWORD; break; case CHECKBOX_FILTEROPTIONS:
resId = STR_SVT_FILEPICKER_FILTER_OPTIONS; break; case CHECKBOX_READONLY:
resId = STR_SVT_FILEPICKER_READONLY; break; case CHECKBOX_LINK:
resId = STR_SVT_FILEPICKER_INSERT_AS_LINK; break; case CHECKBOX_PREVIEW:
resId = STR_SVT_FILEPICKER_SHOW_PREVIEW; break; case CHECKBOX_SELECTION:
resId = STR_SVT_FILEPICKER_SELECTION; break; case CHECKBOX_GPGENCRYPTION:
resId = STR_SVT_FILEPICKER_GPGENCRYPT; break; case CHECKBOX_GPGSIGN:
resId = STR_SVT_FILEPICKER_GPGSIGN; break; case PUSHBUTTON_PLAY:
resId = STR_SVT_FILEPICKER_PLAY; break; case LISTBOX_VERSION:
resId = STR_SVT_FILEPICKER_VERSION; break; case LISTBOX_TEMPLATE:
resId = STR_SVT_FILEPICKER_TEMPLATES; break; case LISTBOX_IMAGE_TEMPLATE:
resId = STR_SVT_FILEPICKER_IMAGE_TEMPLATE; break; case LISTBOX_IMAGE_ANCHOR:
resId = STR_SVT_FILEPICKER_IMAGE_ANCHOR; break; case LISTBOX_VERSION_LABEL: case LISTBOX_TEMPLATE_LABEL: case LISTBOX_IMAGE_TEMPLATE_LABEL: case LISTBOX_IMAGE_ANCHOR_LABEL: case LISTBOX_FILTER_SELECTOR: break;
}
switch (controlId)
{ case CHECKBOX_AUTOEXTENSION:
pCheckbox = new QCheckBox(getResString(resId), m_pExtraControls); // to add/remove automatic file extension based on checkbox #if QT_VERSION >= QT_VERSION_CHECK(6, 7, 0)
connect(pCheckbox, &QCheckBox::checkStateChanged, this,
&QtFilePicker::updateAutomaticFileExtension); #else
connect(pCheckbox, &QCheckBox::stateChanged, this,
&QtFilePicker::updateAutomaticFileExtension); #endif
widget = pCheckbox; break; case CHECKBOX_PASSWORD: case CHECKBOX_FILTEROPTIONS: case CHECKBOX_READONLY: case CHECKBOX_LINK: case CHECKBOX_PREVIEW: case CHECKBOX_SELECTION: case CHECKBOX_GPGENCRYPTION: case CHECKBOX_GPGSIGN:
widget = new QCheckBox(getResString(resId), m_pExtraControls); break; case PUSHBUTTON_PLAY: break; case LISTBOX_VERSION: case LISTBOX_TEMPLATE: case LISTBOX_IMAGE_ANCHOR: case LISTBOX_IMAGE_TEMPLATE: case LISTBOX_FILTER_SELECTOR:
label = new QLabel(getResString(resId), m_pExtraControls);
widget = new QComboBox(m_pExtraControls);
label->setBuddy(widget); break; case LISTBOX_VERSION_LABEL: case LISTBOX_TEMPLATE_LABEL: case LISTBOX_IMAGE_TEMPLATE_LABEL: case LISTBOX_IMAGE_ANCHOR_LABEL: break;
}
if (widget)
{ constint row = m_pLayout->rowCount(); if (label)
m_pLayout->addWidget(label, row, 0);
m_pLayout->addWidget(widget, row, 1);
m_aCustomWidgetsMap.insert(controlId, widget);
}
}
void QtFilePicker::updateAutomaticFileExtension()
{ bool bSetAutoExtension
= getValue(CHECKBOX_AUTOEXTENSION, ControlActions::GET_SELECTED_ITEM).get<bool>(); if (bSetAutoExtension)
{
QString sSuffix = m_aNamedFilterToExtensionMap.value(m_pFileDialog->selectedNameFilter()); // string is "*.<SUFFIX>" if a specific filter was selected that has exactly one possible file extension if (sSuffix.lastIndexOf("*.") == 0)
{
sSuffix = sSuffix.remove("*.");
m_pFileDialog->setDefaultSuffix(sSuffix);
} else
{ // fall back to setting none otherwise
SAL_INFO( "vcl.qt", "Unable to retrieve unambiguous file extension. Will not add any automatically.");
bSetAutoExtension = false;
}
}
if (!bSetAutoExtension)
m_pFileDialog->setDefaultSuffix("");
}
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.