LCOV - code coverage report
Current view: top level - connectivity/source/drivers/mork - MNSProfileDiscover.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 21 73 28.8 %
Date: 2014-11-03 Functions: 5 8 62.5 %
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             : 
      21             : #include "MNSProfileDiscover.hxx"
      22             : 
      23             : #include "MNSFolders.hxx"
      24             : #include "MNSINIParser.hxx"
      25             : 
      26             : namespace connectivity
      27             : {
      28             :     namespace mork
      29             :     {
      30           0 :         ProfileStruct::ProfileStruct(MozillaProductType aProduct, const OUString& aProfileName,
      31             :             const OUString& aProfilePath
      32           0 :           )
      33             :         {
      34           0 :             product=aProduct;
      35           0 :             profileName = aProfileName;
      36           0 :             profilePath = aProfilePath;
      37           0 :         }
      38             : 
      39          12 :         ProfileAccess::~ProfileAccess()
      40             :         {
      41          12 :         }
      42           6 :         ProfileAccess::ProfileAccess()
      43             :         {
      44           6 :             LoadProductsInfo();
      45           6 :         }
      46             : 
      47           6 :         sal_Int32 ProfileAccess::LoadProductsInfo()
      48             :         {
      49             :             //load SeaMonkey 2 profiles to m_ProductProfileList
      50           6 :             sal_Int32 count = LoadXPToolkitProfiles(MozillaProductType_Mozilla);
      51             : 
      52             :             //load thunderbird profiles to m_ProductProfileList
      53           6 :             count += LoadXPToolkitProfiles(MozillaProductType_Thunderbird);
      54             : 
      55             :             //load firefox profiles to m_ProductProfileList
      56             :             //firefox profile does not containt address book, but maybe others need them
      57           6 :             count += LoadXPToolkitProfiles(MozillaProductType_Firefox);
      58           6 :             return count;
      59             :         }
      60             :         //Thunderbird and firefox profiles are saved in profiles.ini
      61          18 :         sal_Int32 ProfileAccess::LoadXPToolkitProfiles(MozillaProductType product)
      62             :         {
      63          18 :             sal_Int32 index=product;
      64          18 :             ProductStruct &m_Product = m_ProductProfileList[index];
      65             : 
      66          18 :             OUString regDir = getRegistryDir(product);
      67          36 :             OUString profilesIni = regDir + "profiles.ini";
      68          36 :             IniParser parser( profilesIni );
      69          18 :             IniSectionMap &mAllSection = parser.getAllSection();
      70             : 
      71          18 :             IniSectionMap::iterator iBegin = mAllSection.begin();
      72          18 :             IniSectionMap::iterator iEnd = mAllSection.end();
      73          18 :             for(;iBegin != iEnd;++iBegin)
      74             :             {
      75           0 :                 ini_Section *aSection = &(*iBegin).second;
      76           0 :                 OUString profileName;
      77           0 :                 OUString profilePath;
      78           0 :                 OUString sIsRelative;
      79           0 :                 OUString sIsDefault;
      80             : 
      81           0 :                 for(NameValueList::iterator itor=aSection->lList.begin();
      82           0 :                     itor != aSection->lList.end();
      83             :                     ++itor)
      84             :                 {
      85           0 :                         struct ini_NameValue * aValue = &(*itor);
      86           0 :                         if ( aValue->sName == "Name" )
      87             :                         {
      88           0 :                             profileName = aValue->sValue;
      89             :                         }
      90           0 :                         else if ( aValue->sName == "IsRelative" )
      91             :                         {
      92           0 :                             sIsRelative = aValue->sValue;
      93             :                         }
      94           0 :                         else if ( aValue->sName == "Path" )
      95             :                         {
      96           0 :                             profilePath = aValue->sValue;
      97             :                         }
      98           0 :                         else if ( aValue->sName == "Default" )
      99             :                         {
     100           0 :                             sIsDefault = aValue->sValue;
     101             :                         }
     102             :                 }
     103           0 :                 if (!(profileName.isEmpty() && profilePath.isEmpty()))
     104             :                 {
     105           0 :                     sal_Int32 isRelative = 0;
     106           0 :                     if (!sIsRelative.isEmpty())
     107             :                     {
     108           0 :                         isRelative = sIsRelative.toInt32();
     109             :                     }
     110             : 
     111           0 :                     OUString fullProfilePath;
     112           0 :                     if(isRelative)
     113             :                     {
     114           0 :                         fullProfilePath = regDir + profilePath;
     115             :                     }
     116             :                     else
     117             :                     {
     118           0 :                         fullProfilePath = profilePath;
     119             :                     }
     120             : 
     121           0 :                     m_Product.mProfileList[profileName] = ProfileStruct(product,profileName,
     122             :                             fullProfilePath
     123           0 :                         );
     124             : 
     125           0 :                     sal_Int32 isDefault = 0;
     126           0 :                     if (!sIsDefault.isEmpty())
     127             :                     {
     128           0 :                         isDefault = sIsDefault.toInt32();
     129             :                     }
     130           0 :                     if (isDefault)
     131           0 :                         m_Product.mCurrentProfileName = profileName;
     132             : 
     133             :                 }
     134             : 
     135           0 :             }
     136          36 :             return static_cast< ::sal_Int32 >(m_Product.mProfileList.size());
     137             :         }
     138             : 
     139           0 :         OUString ProfileAccess::getProfilePath( ::com::sun::star::mozilla::MozillaProductType product, const OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
     140             :         {
     141           0 :             sal_Int32 index=product;
     142           0 :             ProductStruct &m_Product = m_ProductProfileList[index];
     143           0 :             if (!m_Product.mProfileList.size() || m_Product.mProfileList.find(profileName) == m_Product.mProfileList.end())
     144             :             {
     145             :                 //Profile not found
     146           0 :                 return OUString();
     147             :             }
     148             :             else
     149           0 :                 return m_Product.mProfileList[profileName].getProfilePath();
     150             :         }
     151             : 
     152           0 :         OUString ProfileAccess::getDefaultProfile( ::com::sun::star::mozilla::MozillaProductType product ) throw (::com::sun::star::uno::RuntimeException)
     153             :         {
     154           0 :             sal_Int32 index=product;
     155           0 :             ProductStruct &m_Product = m_ProductProfileList[index];
     156           0 :             if (!m_Product.mCurrentProfileName.isEmpty())
     157             :             {
     158             :                 //default profile setted in mozilla registry
     159           0 :                 return m_Product.mCurrentProfileName;
     160             :             }
     161           0 :             if (m_Product.mProfileList.empty())
     162             :             {
     163             :                 //there are not any profiles
     164           0 :                 return OUString();
     165             :             }
     166           0 :             return (*m_Product.mProfileList.begin()).second.getProfileName();
     167             :         }
     168             :     }
     169             : }
     170             : 
     171             : 
     172             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10