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