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

Generated by: LCOV version 1.11