diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:06:44 +0000 |
commit | ed5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch) | |
tree | 7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /cui/source/options/dbregisterednamesconfig.cxx | |
parent | Initial commit. (diff) | |
download | libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip |
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'cui/source/options/dbregisterednamesconfig.cxx')
-rw-r--r-- | cui/source/options/dbregisterednamesconfig.cxx | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/cui/source/options/dbregisterednamesconfig.cxx b/cui/source/options/dbregisterednamesconfig.cxx new file mode 100644 index 000000000..b33e9ded6 --- /dev/null +++ b/cui/source/options/dbregisterednamesconfig.cxx @@ -0,0 +1,122 @@ +/* -*- 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 "dbregisterednamesconfig.hxx" +#include "dbregistersettings.hxx" +#include <svx/databaseregistrationui.hxx> +#include <com/sun/star/sdb/DatabaseContext.hpp> +#include <comphelper/processfactory.hxx> +#include <svl/itemset.hxx> +#include <tools/diagnose_ex.h> + + +namespace svx +{ + + + using namespace ::com::sun::star::uno; + using namespace ::com::sun::star::sdb; + using namespace ::com::sun::star::container; + + void DbRegisteredNamesConfig::GetOptions( SfxItemSet& _rFillItems ) + { + DatabaseRegistrations aSettings; + + try + { + Reference<XComponentContext> xContext( ::comphelper::getProcessComponentContext() ); + Reference< XDatabaseContext > xRegistrations( + DatabaseContext::create(xContext) ); + + Sequence< OUString > aRegistrationNames( xRegistrations->getRegistrationNames() ); + const OUString* pRegistrationName = aRegistrationNames.getConstArray(); + const OUString* pRegistrationNamesEnd = pRegistrationName + aRegistrationNames.getLength(); + for ( ; pRegistrationName != pRegistrationNamesEnd; ++pRegistrationName ) + { + OUString sLocation( xRegistrations->getDatabaseLocation( *pRegistrationName ) ); + aSettings[ *pRegistrationName ] = + DatabaseRegistration( sLocation, xRegistrations->isDatabaseRegistrationReadOnly( *pRegistrationName ) ); + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION("cui.options"); + } + + _rFillItems.Put( DatabaseMapItem( SID_SB_DB_REGISTER, std::move(aSettings) ) ); + } + + + void DbRegisteredNamesConfig::SetOptions(const SfxItemSet& _rSourceItems) + { + // the settings for the single drivers + const DatabaseMapItem* pRegistrations = _rSourceItems.GetItem<DatabaseMapItem>(SID_SB_DB_REGISTER); + if ( !pRegistrations ) + return; + + try + { + Reference< XDatabaseContext > xRegistrations( + DatabaseContext::create( + comphelper::getProcessComponentContext())); + + const DatabaseRegistrations& rNewRegistrations = pRegistrations->getRegistrations(); + for ( DatabaseRegistrations::const_iterator reg = rNewRegistrations.begin(); + reg != rNewRegistrations.end(); + ++reg + ) + { + const OUString sName = reg->first; + const OUString sLocation = reg->second.sLocation; + + if ( xRegistrations->hasRegisteredDatabase( sName ) ) + { + if ( !xRegistrations->isDatabaseRegistrationReadOnly( sName ) ) + xRegistrations->changeDatabaseLocation( sName, sLocation ); + else + { + OSL_ENSURE( xRegistrations->getDatabaseLocation( sName ) == sLocation, + "DbRegisteredNamesConfig::SetOptions: somebody changed a read-only registration. How unrespectful." ); + } + } + else + xRegistrations->registerDatabaseLocation( sName, sLocation ); + } + + // delete unused entries + Sequence< OUString > aRegistrationNames = xRegistrations->getRegistrationNames(); + const OUString* pRegistrationName = aRegistrationNames.getConstArray(); + const OUString* pRegistrationNamesEnd = pRegistrationName + aRegistrationNames.getLength(); + for ( ; pRegistrationName != pRegistrationNamesEnd; ++pRegistrationName ) + { + if ( rNewRegistrations.find( *pRegistrationName ) == rNewRegistrations.end() ) + xRegistrations->revokeDatabaseLocation( *pRegistrationName ); + } + } + catch( const Exception& ) + { + //DBG_UNHANDLED_EXCEPTION(); + } + } + + +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |