LibreOffice Module cui (master) 1
dbregisterednamesconfig.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
23#include <com/sun/star/sdb/DatabaseContext.hpp>
25#include <svl/itemset.hxx>
26#include <tools/diagnose_ex.h>
27
28
29namespace svx
30{
31
32
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::sdb;
35 using namespace ::com::sun::star::container;
36
38 {
39 DatabaseRegistrations aSettings;
40
41 try
42 {
43 Reference<XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
44 Reference< XDatabaseContext > xRegistrations(
45 DatabaseContext::create(xContext) );
46
47 Sequence< OUString > aRegistrationNames( xRegistrations->getRegistrationNames() );
48 const OUString* pRegistrationName = aRegistrationNames.getConstArray();
49 const OUString* pRegistrationNamesEnd = pRegistrationName + aRegistrationNames.getLength();
50 for ( ; pRegistrationName != pRegistrationNamesEnd; ++pRegistrationName )
51 {
52 OUString sLocation( xRegistrations->getDatabaseLocation( *pRegistrationName ) );
53 aSettings[ *pRegistrationName ] =
54 DatabaseRegistration( sLocation, xRegistrations->isDatabaseRegistrationReadOnly( *pRegistrationName ) );
55 }
56 }
57 catch( const Exception& )
58 {
59 DBG_UNHANDLED_EXCEPTION("cui.options");
60 }
61
62 _rFillItems.Put( DatabaseMapItem( SID_SB_DB_REGISTER, std::move(aSettings) ) );
63 }
64
65
67 {
68 // the settings for the single drivers
69 const DatabaseMapItem* pRegistrations = _rSourceItems.GetItem<DatabaseMapItem>(SID_SB_DB_REGISTER);
70 if ( !pRegistrations )
71 return;
72
73 try
74 {
75 Reference< XDatabaseContext > xRegistrations(
76 DatabaseContext::create(
78
79 const DatabaseRegistrations& rNewRegistrations = pRegistrations->getRegistrations();
80 for ( DatabaseRegistrations::const_iterator reg = rNewRegistrations.begin();
81 reg != rNewRegistrations.end();
82 ++reg
83 )
84 {
85 const OUString sName = reg->first;
86 const OUString sLocation = reg->second.sLocation;
87
88 if ( xRegistrations->hasRegisteredDatabase( sName ) )
89 {
90 if ( !xRegistrations->isDatabaseRegistrationReadOnly( sName ) )
91 xRegistrations->changeDatabaseLocation( sName, sLocation );
92 else
93 {
94 OSL_ENSURE( xRegistrations->getDatabaseLocation( sName ) == sLocation,
95 "DbRegisteredNamesConfig::SetOptions: somebody changed a read-only registration. How unrespectful." );
96 }
97 }
98 else
99 xRegistrations->registerDatabaseLocation( sName, sLocation );
100 }
101
102 // delete unused entries
103 Sequence< OUString > aRegistrationNames = xRegistrations->getRegistrationNames();
104 const OUString* pRegistrationName = aRegistrationNames.getConstArray();
105 const OUString* pRegistrationNamesEnd = pRegistrationName + aRegistrationNames.getLength();
106 for ( ; pRegistrationName != pRegistrationNamesEnd; ++pRegistrationName )
107 {
108 if ( rNewRegistrations.find( *pRegistrationName ) == rNewRegistrations.end() )
109 xRegistrations->revokeDatabaseLocation( *pRegistrationName );
110 }
111 }
112 catch( const Exception& )
113 {
114 //DBG_UNHANDLED_EXCEPTION();
115 }
116 }
117
118
119}
120
121
122/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const DatabaseRegistrations & getRegistrations() const
static void SetOptions(const SfxItemSet &_rSourceItems)
static void GetOptions(SfxItemSet &_rFillItems)
#define SID_SB_DB_REGISTER
#define DBG_UNHANDLED_EXCEPTION(...)
const char * sName
@ Exception
Reference< XComponentContext > getProcessComponentContext()
std::map< OUString, DatabaseRegistration > DatabaseRegistrations