LibreOffice Module sw (master)  1
dbconfig.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 
20 #include <dbconfig.hxx>
21 #include <osl/diagnose.h>
22 #include <com/sun/star/uno/Sequence.hxx>
23 #include <swdbdata.hxx>
24 
25 #include <unomid.h>
26 
27 using namespace utl;
28 using namespace com::sun::star::uno;
29 
31 {
32  static Sequence<OUString> aNames {
33  "AddressBook/DataSourceName", // 0
34  "AddressBook/Command", // 1
35  "AddressBook/CommandType", // 2
36  "Bibliography/CurrentDataSource/DataSourceName", // 4
37  "Bibliography/CurrentDataSource/Command", // 5
38  "Bibliography/CurrentDataSource/CommandType" // 6
39  };
40  return aNames;
41 }
42 
44  ConfigItem("Office.DataAccess", ConfigItemMode::ReleaseTree)
45 {
46 };
47 
49 {
50  pAdrImpl.reset();
51  pBibImpl.reset();
52 }
53 
55 {
56  const Sequence<OUString>& rNames = GetPropertyNames();
57  if(!pAdrImpl)
58  {
59  pAdrImpl.reset(new SwDBData);
60  pAdrImpl->nCommandType = 0;
61  pBibImpl.reset(new SwDBData);
62  pBibImpl->nCommandType = 0;
63  }
64  Sequence<Any> aValues = GetProperties(rNames);
65  const Any* pValues = aValues.getConstArray();
66  OSL_ENSURE(aValues.getLength() == rNames.getLength(), "GetProperties failed");
67  if(aValues.getLength() == rNames.getLength())
68  {
69  for(int nProp = 0; nProp < rNames.getLength(); nProp++)
70  {
71  switch(nProp)
72  {
73  case 0: pValues[nProp] >>= pAdrImpl->sDataSource; break;
74  case 1: pValues[nProp] >>= pAdrImpl->sCommand; break;
75  case 2: pValues[nProp] >>= pAdrImpl->nCommandType; break;
76  case 3: pValues[nProp] >>= pBibImpl->sDataSource; break;
77  case 4: pValues[nProp] >>= pBibImpl->sCommand; break;
78  case 5: pValues[nProp] >>= pBibImpl->nCommandType; break;
79  }
80  }
81  }
82 }
83 
85 {
86  if(!pAdrImpl)
87  Load();
88  return *pAdrImpl;
89 }
90 
92 {
93  if(!pBibImpl)
94  Load();
95  return *pBibImpl;
96 }
97 
99 void SwDBConfig::Notify( const css::uno::Sequence< OUString >& ) {}
100 
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ConfigItemMode
virtual void Notify(const css::uno::Sequence< OUString > &aPropertyNames) override
Definition: dbconfig.cxx:99
void Load()
Definition: dbconfig.cxx:54
css::uno::Sequence< css::uno::Any > GetProperties(const css::uno::Sequence< OUString > &rNames)
std::unique_ptr< SwDBData > pAdrImpl
Definition: dbconfig.hxx:33
std::unique_ptr< SwDBData > pBibImpl
Definition: dbconfig.hxx:34
virtual void ImplCommit() override
Definition: dbconfig.cxx:98
static SAL_DLLPRIVATE const css::uno::Sequence< OUString > & GetPropertyNames()
Definition: dbconfig.cxx:30
const SwDBData & GetAddressSource()
Definition: dbconfig.cxx:84
const SwDBData & GetBibliographySource()
Definition: dbconfig.cxx:91
virtual ~SwDBConfig() override
Definition: dbconfig.cxx:48