Use correct object
[LibreOffice.git] / cui / source / options / dbregisterednamesconfig.cxx
blob737170a17f8a9c23937a1442825790ca2459a258
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "dbregisterednamesconfig.hxx"
21 #include "dbregistersettings.hxx"
22 #include <svx/databaseregistrationui.hxx>
23 #include <com/sun/star/sdb/DatabaseContext.hpp>
24 #include <comphelper/processfactory.hxx>
25 #include <svl/itemset.hxx>
26 #include <comphelper/diagnose_ex.hxx>
29 namespace svx
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::sdb;
36 void DbRegisteredNamesConfig::GetOptions( SfxItemSet& _rFillItems )
38 DatabaseRegistrations aSettings;
40 try
42 const Reference<XComponentContext>& xContext( ::comphelper::getProcessComponentContext() );
43 Reference< XDatabaseContext > xRegistrations(
44 DatabaseContext::create(xContext) );
46 for (auto& registrationName : xRegistrations->getRegistrationNames())
48 aSettings[registrationName] = DatabaseRegistration(
49 xRegistrations->getDatabaseLocation(registrationName),
50 xRegistrations->isDatabaseRegistrationReadOnly(registrationName));
53 catch( const Exception& )
55 DBG_UNHANDLED_EXCEPTION("cui.options");
58 _rFillItems.Put( DatabaseMapItem( SID_SB_DB_REGISTER, std::move(aSettings) ) );
62 void DbRegisteredNamesConfig::SetOptions(const SfxItemSet& _rSourceItems)
64 // the settings for the single drivers
65 const DatabaseMapItem* pRegistrations = _rSourceItems.GetItem<DatabaseMapItem>(SID_SB_DB_REGISTER);
66 if ( !pRegistrations )
67 return;
69 try
71 Reference< XDatabaseContext > xRegistrations(
72 DatabaseContext::create(
73 comphelper::getProcessComponentContext()));
75 const DatabaseRegistrations& rNewRegistrations = pRegistrations->getRegistrations();
76 for ( DatabaseRegistrations::const_iterator reg = rNewRegistrations.begin();
77 reg != rNewRegistrations.end();
78 ++reg
81 const OUString sName = reg->first;
82 const OUString sLocation = reg->second.sLocation;
84 if ( xRegistrations->hasRegisteredDatabase( sName ) )
86 if ( !xRegistrations->isDatabaseRegistrationReadOnly( sName ) )
87 xRegistrations->changeDatabaseLocation( sName, sLocation );
88 else
90 OSL_ENSURE( xRegistrations->getDatabaseLocation( sName ) == sLocation,
91 "DbRegisteredNamesConfig::SetOptions: somebody changed a read-only registration. How unrespectful." );
94 else
95 xRegistrations->registerDatabaseLocation( sName, sLocation );
98 // delete unused entries
99 for (auto& registrationName : xRegistrations->getRegistrationNames())
101 if (rNewRegistrations.find(registrationName) == rNewRegistrations.end())
102 xRegistrations->revokeDatabaseLocation(registrationName);
105 catch( const Exception& )
107 //DBG_UNHANDLED_EXCEPTION();
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */