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

Generated by: LCOV version 1.10