/* -*- 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 .
*/
void OConnectionHelper::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue)
{ // check whether or not the selection is invalid or readonly (invalid implies readonly, but not vice versa) bool bValid, bReadonly;
getFlags(_rSet, bValid, bReadonly);
bool bDoBrowse = false;
OUString sOldPath = getURLNoPrefix(); do
{ if (!sOldPath.isEmpty())
xFolderPicker->setDisplayDirectory(sOldPath); if (0 == xFolderPicker->execute()) // cancelled by the user return;
sOldPath = xFolderPicker->getDirectory(); switch (checkPathExistence(sOldPath))
{ case RET_RETRY:
bDoBrowse = true; break; case RET_CANCEL: return; default: break;
}
} while (bDoBrowse);
// for UI purpose, we don't want to have the path encoded
sSelectedDirectory = aSelectedDirectory.GetMainURL( INetURLObject::DecodeMechanism::WithCharset );
void OConnectionHelper::impl_setURL( std::u16string_view _rURL, bool _bPrefix )
{
OUString sURL( comphelper::string::stripEnd(_rURL, '*') );
OSL_ENSURE( m_pCollection, "OConnectionHelper::impl_setURL: have no interpreter for the URLs!" );
if ( m_pCollection && !sURL.isEmpty() )
{ if ( m_pCollection->isFileSystemBased( m_eType ) )
{ // get the two parts: prefix and file URL
OUString sTypePrefix, sFileURLEncoded; if ( _bPrefix )
{
sTypePrefix = m_pCollection->getPrefix( m_eType );
sFileURLEncoded = m_pCollection->cutPrefix( sURL );
} else
{
sFileURLEncoded = sURL;
}
// substitute any variables
sFileURLEncoded = SvtPathOptions().SubstituteVariable( sFileURLEncoded );
// decode the URL
sURL = sTypePrefix; if ( !sFileURLEncoded.isEmpty() )
{
OFileNotation aFileNotation(sFileURLEncoded); // set this decoded URL as text
sURL += aFileNotation.get(OFileNotation::N_SYSTEM);
}
}
}
OUString OConnectionHelper::impl_getURL() const
{ // get the pure text
OUString sURL = m_xConnectionURL->GetTextNoPrefix();
OSL_ENSURE( m_pCollection, "OConnectionHelper::impl_getURL: have no interpreter for the URLs!" );
if ( m_pCollection && !sURL.isEmpty() )
{ if ( m_pCollection->isFileSystemBased( m_eType ) )
{ // get the two parts: prefix and file URL
OUString sFileURLDecoded = sURL;
switch (nQueryResult)
{ case RET_YES:
{ bool bTryCreate = false; do
{ if ( !createDirectoryDeep(_rURL) )
{ // could not create the directory
sQuery = DBA_RES(STR_COULD_NOT_CREATE_DIRECTORY);
sQuery = sQuery.replaceFirst("$name$", aTransformer.get(OFileNotation::N_SYSTEM));
IMPL_LINK_NOARG(OConnectionHelper, GetFocusHdl, weld::Widget&, void)
{ if (!m_pCollection->isFileSystemBased(m_eType)) return; if (!m_bUserGrabFocus) return; // URL edit field got the focus
m_xConnectionURL->SaveValueNoPrefix();
}
IMPL_LINK_NOARG(OConnectionHelper, LoseFocusHdl, weld::Widget&, void)
{ if (!m_pCollection->isFileSystemBased(m_eType)) return; if (!m_bUserGrabFocus) return; // URL edit field lost the focus
commitURL();
}
bool OConnectionHelper::createDirectoryDeep(std::u16string_view _rPathURL)
{ // get a URL object analyzing the URL for us ...
INetURLObject aParser;
aParser.SetURL(_rPathURL);
INetProtocol eProtocol = aParser.GetProtocol();
std::vector< OUString > aToBeCreated; // the to-be-created levels
// search a level which exists
IS_PATH_EXIST eParentExists = PATH_NOT_EXIST; while ( eParentExists == PATH_NOT_EXIST && aParser.getSegmentCount())
{
aToBeCreated.push_back(aParser.getName()); // remember the local name for creation
aParser.removeSegment(); // cut the local name
eParentExists = pathExists(aParser.GetMainURL(INetURLObject::DecodeMechanism::NONE), false);
}
if (!aParser.getSegmentCount()) returnfalse;
// create all the missing levels try
{ // the parent content
Reference< XCommandEnvironment > xEmptyEnv;
::ucbhelper::Content aParent(aParser.GetMainURL(INetURLObject::DecodeMechanism::NONE), xEmptyEnv, comphelper::getProcessComponentContext());
OUString sContentType; if ( INetProtocol::File == eProtocol )
{
sContentType = "application/vnd.sun.staroffice.fsys-folder"; // the file UCP currently does not support the ContentType property
} else
{
Any aContentType = aParent.getPropertyValue(u"ContentType"_ustr);
aContentType >>= sContentType;
}
// the properties which need to be set on the new content
Sequence< OUString > aNewDirectoryProperties { u"Title"_ustr };
// loop for ( std::vector< OUString >::const_reverse_iterator aLocalName = aToBeCreated.rbegin();
aLocalName != aToBeCreated.rend();
++aLocalName
)
{ // the values to be set
Sequence< Any > aNewDirectoryAttributes{ Any(* aLocalName) }; if (!aParent.insertNewContent(sContentType, aNewDirectoryProperties, aNewDirectoryAttributes, aParent)) returnfalse;
}
} catch ( const Exception& )
{
DBG_UNHANDLED_EXCEPTION("dbaccess"); 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.