LCOV - code coverage report
Current view: top level - sw/source/core/uibase/config - dbconfig.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 40 46 87.0 %
Date: 2014-04-11 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             : /*--------------------------------------------------------------------
      32             :      Description: Ctor
      33             :  --------------------------------------------------------------------*/
      34             : 
      35          20 : const Sequence<OUString>& SwDBConfig::GetPropertyNames()
      36             : {
      37          20 :     static Sequence<OUString> aNames;
      38          20 :     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          20 :         const int nCount = sizeof(aPropNames)/sizeof(const char*);
      50          20 :         aNames.realloc(nCount);
      51          20 :         OUString* pNames = aNames.getArray();
      52         140 :         for(int i = 0; i < nCount; i++)
      53         120 :             pNames[i] = OUString::createFromAscii(aPropNames[i]);
      54             :     }
      55          20 :     return aNames;
      56             : }
      57             : 
      58          20 : SwDBConfig::SwDBConfig() :
      59             :     ConfigItem("Office.DataAccess",
      60             :         CONFIG_MODE_DELAYED_UPDATE|CONFIG_MODE_RELEASE_TREE),
      61             :     pAdrImpl(0),
      62          20 :     pBibImpl(0)
      63             : {
      64          20 : };
      65             : 
      66          24 : SwDBConfig::~SwDBConfig()
      67             : {
      68           8 :     delete pAdrImpl;
      69           8 :     delete pBibImpl;
      70          16 : }
      71             : 
      72          20 : void SwDBConfig::Load()
      73             : {
      74          20 :     const Sequence<OUString>& rNames = GetPropertyNames();
      75          20 :     if(!pAdrImpl)
      76             :     {
      77             : 
      78          20 :         pAdrImpl = new SwDBData;
      79          20 :         pAdrImpl->nCommandType = 0;
      80          20 :         pBibImpl = new SwDBData;
      81          20 :         pBibImpl->nCommandType = 0;
      82             :     }
      83          20 :     Sequence<Any> aValues = GetProperties(rNames);
      84          20 :     const Any* pValues = aValues.getConstArray();
      85             :     OSL_ENSURE(aValues.getLength() == rNames.getLength(), "GetProperties failed");
      86          20 :     if(aValues.getLength() == rNames.getLength())
      87             :     {
      88         140 :         for(int nProp = 0; nProp < rNames.getLength(); nProp++)
      89             :         {
      90         120 :             switch(nProp)
      91             :             {
      92          20 :                 case  0: pValues[nProp] >>= pAdrImpl->sDataSource;  break;
      93          20 :                 case  1: pValues[nProp] >>= pAdrImpl->sCommand;     break;
      94          20 :                 case  2: pValues[nProp] >>= pAdrImpl->nCommandType; break;
      95          20 :                 case  3: pValues[nProp] >>= pBibImpl->sDataSource;  break;
      96          20 :                 case  4: pValues[nProp] >>= pBibImpl->sCommand;     break;
      97          20 :                 case  5: pValues[nProp] >>= pBibImpl->nCommandType; break;
      98             :             }
      99             :         }
     100          20 :     }
     101          20 : }
     102             : 
     103         392 : const SwDBData& SwDBConfig::GetAddressSource()
     104             : {
     105         392 :     if(!pAdrImpl)
     106          20 :         Load();
     107         392 :     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: */

Generated by: LCOV version 1.10