Line data Source code
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/Any.hxx>
23 : #include <com/sun/star/uno/Sequence.hxx>
24 : #include <swdbdata.hxx>
25 :
26 : #include <unomid.h>
27 :
28 : using namespace utl;
29 : using rtl::OUString;
30 : using namespace com::sun::star::uno;
31 :
32 : /*--------------------------------------------------------------------
33 : Description: Ctor
34 : --------------------------------------------------------------------*/
35 :
36 5 : const Sequence<OUString>& SwDBConfig::GetPropertyNames()
37 : {
38 5 : static Sequence<OUString> aNames;
39 5 : if(!aNames.getLength())
40 : {
41 : static const char* aPropNames[] =
42 : {
43 : "AddressBook/DataSourceName", // 0
44 : "AddressBook/Command", // 1
45 : "AddressBook/CommandType", // 2
46 : "Bibliography/CurrentDataSource/DataSourceName", // 4
47 : "Bibliography/CurrentDataSource/Command", // 5
48 : "Bibliography/CurrentDataSource/CommandType" // 6
49 : };
50 5 : const int nCount = sizeof(aPropNames)/sizeof(const char*);
51 5 : aNames.realloc(nCount);
52 5 : OUString* pNames = aNames.getArray();
53 35 : for(int i = 0; i < nCount; i++)
54 30 : pNames[i] = OUString::createFromAscii(aPropNames[i]);
55 : }
56 5 : return aNames;
57 : }
58 :
59 5 : SwDBConfig::SwDBConfig() :
60 : ConfigItem("Office.DataAccess",
61 : CONFIG_MODE_DELAYED_UPDATE|CONFIG_MODE_RELEASE_TREE),
62 : pAdrImpl(0),
63 5 : pBibImpl(0)
64 : {
65 5 : };
66 :
67 0 : SwDBConfig::~SwDBConfig()
68 : {
69 0 : delete pAdrImpl;
70 0 : delete pBibImpl;
71 0 : }
72 :
73 5 : void SwDBConfig::Load()
74 : {
75 5 : const Sequence<OUString>& rNames = GetPropertyNames();
76 5 : if(!pAdrImpl)
77 : {
78 :
79 5 : pAdrImpl = new SwDBData;
80 5 : pAdrImpl->nCommandType = 0;
81 5 : pBibImpl = new SwDBData;
82 5 : pBibImpl->nCommandType = 0;
83 : }
84 5 : Sequence<Any> aValues = GetProperties(rNames);
85 5 : const Any* pValues = aValues.getConstArray();
86 : OSL_ENSURE(aValues.getLength() == rNames.getLength(), "GetProperties failed");
87 5 : if(aValues.getLength() == rNames.getLength())
88 : {
89 35 : for(int nProp = 0; nProp < rNames.getLength(); nProp++)
90 : {
91 30 : switch(nProp)
92 : {
93 5 : case 0: pValues[nProp] >>= pAdrImpl->sDataSource; break;
94 5 : case 1: pValues[nProp] >>= pAdrImpl->sCommand; break;
95 5 : case 2: pValues[nProp] >>= pAdrImpl->nCommandType; break;
96 5 : case 3: pValues[nProp] >>= pBibImpl->sDataSource; break;
97 5 : case 4: pValues[nProp] >>= pBibImpl->sCommand; break;
98 5 : case 5: pValues[nProp] >>= pBibImpl->nCommandType; break;
99 : }
100 : }
101 5 : }
102 5 : }
103 :
104 58 : const SwDBData& SwDBConfig::GetAddressSource()
105 : {
106 58 : if(!pAdrImpl)
107 5 : Load();
108 58 : return *pAdrImpl;
109 : }
110 :
111 0 : const SwDBData& SwDBConfig::GetBibliographySource()
112 : {
113 0 : if(!pBibImpl)
114 0 : Load();
115 0 : return *pBibImpl;
116 : }
117 :
118 0 : void SwDBConfig::Commit() {}
119 0 : void SwDBConfig::Notify( const ::com::sun::star::uno::Sequence< rtl::OUString >& ) {}
120 :
121 :
122 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|