Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <dbconfig.hxx>
30 : : #include <osl/diagnose.h>
31 : : #include <com/sun/star/uno/Any.hxx>
32 : : #include <com/sun/star/uno/Sequence.hxx>
33 : : #include <swdbdata.hxx>
34 : :
35 : : #include <unomid.h>
36 : :
37 : : using namespace utl;
38 : : using rtl::OUString;
39 : : using namespace com::sun::star::uno;
40 : :
41 : : /*--------------------------------------------------------------------
42 : : Description: Ctor
43 : : --------------------------------------------------------------------*/
44 : :
45 : 45 : const Sequence<OUString>& SwDBConfig::GetPropertyNames()
46 : : {
47 [ + - ][ + - ]: 45 : static Sequence<OUString> aNames;
[ + - ][ # # ]
48 [ + - ]: 45 : if(!aNames.getLength())
49 : : {
50 : : static const char* aPropNames[] =
51 : : {
52 : : "AddressBook/DataSourceName", // 0
53 : : "AddressBook/Command", // 1
54 : : "AddressBook/CommandType", // 2
55 : : "Bibliography/CurrentDataSource/DataSourceName", // 4
56 : : "Bibliography/CurrentDataSource/Command", // 5
57 : : "Bibliography/CurrentDataSource/CommandType" // 6
58 : : };
59 : 45 : const int nCount = sizeof(aPropNames)/sizeof(const char*);
60 : 45 : aNames.realloc(nCount);
61 : 45 : OUString* pNames = aNames.getArray();
62 [ + + ]: 315 : for(int i = 0; i < nCount; i++)
63 : 270 : pNames[i] = OUString::createFromAscii(aPropNames[i]);
64 : : }
65 : 45 : return aNames;
66 : : }
67 : :
68 : 45 : SwDBConfig::SwDBConfig() :
69 : : ConfigItem("Office.DataAccess",
70 : : CONFIG_MODE_DELAYED_UPDATE|CONFIG_MODE_RELEASE_TREE),
71 : : pAdrImpl(0),
72 [ + - ]: 45 : pBibImpl(0)
73 : : {
74 : 45 : };
75 : :
76 : 20 : SwDBConfig::~SwDBConfig()
77 : : {
78 [ + - ]: 20 : delete pAdrImpl;
79 [ + - ]: 20 : delete pBibImpl;
80 [ - + ]: 40 : }
81 : :
82 : 45 : void SwDBConfig::Load()
83 : : {
84 [ + - ]: 45 : const Sequence<OUString>& rNames = GetPropertyNames();
85 [ + - ]: 45 : if(!pAdrImpl)
86 : : {
87 : :
88 [ + - ]: 45 : pAdrImpl = new SwDBData;
89 : 45 : pAdrImpl->nCommandType = 0;
90 [ + - ]: 45 : pBibImpl = new SwDBData;
91 : 45 : pBibImpl->nCommandType = 0;
92 : : }
93 [ + - ]: 45 : Sequence<Any> aValues = GetProperties(rNames);
94 : 45 : const Any* pValues = aValues.getConstArray();
95 : : OSL_ENSURE(aValues.getLength() == rNames.getLength(), "GetProperties failed");
96 [ + - ]: 45 : if(aValues.getLength() == rNames.getLength())
97 : : {
98 [ + + ]: 315 : for(int nProp = 0; nProp < rNames.getLength(); nProp++)
99 : : {
100 [ + + + + : 270 : switch(nProp)
+ + - ]
101 : : {
102 : 45 : case 0: pValues[nProp] >>= pAdrImpl->sDataSource; break;
103 : 45 : case 1: pValues[nProp] >>= pAdrImpl->sCommand; break;
104 : 45 : case 2: pValues[nProp] >>= pAdrImpl->nCommandType; break;
105 : 45 : case 3: pValues[nProp] >>= pBibImpl->sDataSource; break;
106 : 45 : case 4: pValues[nProp] >>= pBibImpl->sCommand; break;
107 : 45 : case 5: pValues[nProp] >>= pBibImpl->nCommandType; break;
108 : : }
109 : : }
110 [ + - ]: 45 : }
111 : 45 : }
112 : :
113 : 316 : const SwDBData& SwDBConfig::GetAddressSource()
114 : : {
115 [ + + ]: 316 : if(!pAdrImpl)
116 : 45 : Load();
117 : 316 : return *pAdrImpl;
118 : : }
119 : :
120 : 0 : const SwDBData& SwDBConfig::GetBibliographySource()
121 : : {
122 [ # # ]: 0 : if(!pBibImpl)
123 : 0 : Load();
124 : 0 : return *pBibImpl;
125 : : }
126 : :
127 : 0 : void SwDBConfig::Commit() {}
128 : 0 : void SwDBConfig::Notify( const ::com::sun::star::uno::Sequence< rtl::OUString >& ) {}
129 : :
130 : :
131 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|