Version 4.3.0.0.beta1, tag libreoffice-4.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / mork / MNSProfileDiscover.cxx
blob4b7ac559f5e74303647defb1af7da58f26d1d2b3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "MNSProfileDiscover.hxx"
23 #include <MNSFolders.hxx>
24 #include <MNSINIParser.hxx>
26 namespace connectivity
28 namespace mork
30 ProfileStruct::ProfileStruct(MozillaProductType aProduct, const OUString& aProfileName,
31 const OUString& aProfilePath
34 product=aProduct;
35 profileName = aProfileName;
36 profilePath = aProfilePath;
38 OUString ProfileStruct::getProfilePath()
40 return profilePath;
43 ProfileAccess::~ProfileAccess()
46 ProfileAccess::ProfileAccess()
48 LoadProductsInfo();
51 sal_Int32 ProfileAccess::LoadProductsInfo()
53 //load SeaMonkey 2 profiles to m_ProductProfileList
54 sal_Int32 count = LoadXPToolkitProfiles(MozillaProductType_Mozilla);
56 //load thunderbird profiles to m_ProductProfileList
57 count += LoadXPToolkitProfiles(MozillaProductType_Thunderbird);
59 //load firefox profiles to m_ProductProfileList
60 //firefox profile does not containt address book, but maybe others need them
61 count += LoadXPToolkitProfiles(MozillaProductType_Firefox);
62 return count;
64 //Thunderbird and firefox profiles are saved in profiles.ini
65 sal_Int32 ProfileAccess::LoadXPToolkitProfiles(MozillaProductType product)
67 sal_Int32 index=product;
68 ProductStruct &m_Product = m_ProductProfileList[index];
70 OUString regDir = getRegistryDir(product);
71 OUString profilesIni = regDir + "profiles.ini";
72 IniParser parser( profilesIni );
73 IniSectionMap &mAllSection = *(parser.getAllSection());
75 IniSectionMap::iterator iBegin = mAllSection.begin();
76 IniSectionMap::iterator iEnd = mAllSection.end();
77 for(;iBegin != iEnd;++iBegin)
79 ini_Section *aSection = &(*iBegin).second;
80 OUString profileName;
81 OUString profilePath;
82 OUString sIsRelative;
83 OUString sIsDefault;
85 for(NameValueList::iterator itor=aSection->lList.begin();
86 itor != aSection->lList.end();
87 ++itor)
89 struct ini_NameValue * aValue = &(*itor);
90 if ( aValue->sName == "Name" )
92 profileName = aValue->sValue;
94 else if ( aValue->sName == "IsRelative" )
96 sIsRelative = aValue->sValue;
98 else if ( aValue->sName == "Path" )
100 profilePath = aValue->sValue;
102 else if ( aValue->sName == "Default" )
104 sIsDefault = aValue->sValue;
107 if (!(profileName.isEmpty() && profilePath.isEmpty()))
109 sal_Int32 isRelative = 0;
110 if (!sIsRelative.isEmpty())
112 isRelative = sIsRelative.toInt32();
115 OUString fullProfilePath;
116 if(isRelative)
118 fullProfilePath = regDir + profilePath;
120 else
122 fullProfilePath = profilePath;
125 ProfileStruct* profileItem = new ProfileStruct(product,profileName,
126 fullProfilePath
128 m_Product.mProfileList[profileName] = profileItem;
130 sal_Int32 isDefault = 0;
131 if (!sIsDefault.isEmpty())
133 isDefault = sIsDefault.toInt32();
135 if (isDefault)
136 m_Product.mCurrentProfileName = profileName;
141 return static_cast< ::sal_Int32 >(m_Product.mProfileList.size());
144 OUString ProfileAccess::getProfilePath( ::com::sun::star::mozilla::MozillaProductType product, const OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
146 sal_Int32 index=product;
147 ProductStruct &m_Product = m_ProductProfileList[index];
148 if (!m_Product.mProfileList.size() || m_Product.mProfileList.find(profileName) == m_Product.mProfileList.end())
150 //Profile not found
151 return OUString();
153 else
154 return m_Product.mProfileList[profileName]->getProfilePath();
157 OUString ProfileAccess::getDefaultProfile( ::com::sun::star::mozilla::MozillaProductType product ) throw (::com::sun::star::uno::RuntimeException)
159 sal_Int32 index=product;
160 ProductStruct &m_Product = m_ProductProfileList[index];
161 if (!m_Product.mCurrentProfileName.isEmpty())
163 //default profile setted in mozilla registry
164 return m_Product.mCurrentProfileName;
166 if (m_Product.mProfileList.empty())
168 //there are not any profiles
169 return OUString();
171 ProfileStruct * aProfile = (*m_Product.mProfileList.begin()).second;
172 return aProfile->getProfileName();
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */