LCOV - code coverage report
Current view: top level - sw/source/uibase/config - dbconfig.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 41 47 87.2 %
Date: 2015-06-13 12:38:46 Functions: 6 9 66.7 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11