1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
30 ProfileStruct::ProfileStruct(MozillaProductType aProduct
, const OUString
& aProfileName
,
31 const OUString
& aProfilePath
35 profileName
= aProfileName
;
36 profilePath
= aProfilePath
;
38 OUString
ProfileStruct::getProfilePath()
43 ProfileAccess::~ProfileAccess()
46 ProfileAccess::ProfileAccess()
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
);
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
;
85 for(NameValueList::iterator itor
=aSection
->lList
.begin();
86 itor
!= aSection
->lList
.end();
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
;
118 fullProfilePath
= regDir
+ profilePath
;
122 fullProfilePath
= profilePath
;
125 ProfileStruct
* profileItem
= new ProfileStruct(product
,profileName
,
128 m_Product
.mProfileList
[profileName
] = profileItem
;
130 sal_Int32 isDefault
= 0;
131 if (!sIsDefault
.isEmpty())
133 isDefault
= sIsDefault
.toInt32();
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())
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
171 ProfileStruct
* aProfile
= (*m_Product
.mProfileList
.begin()).second
;
172 return aProfile
->getProfileName();
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */