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

Generated by: LCOV version 1.10