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