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"
22 #include "MNSFolders.hxx"
23 #include "MNSINIParser.hxx"
25 namespace connectivity
29 ProfileStruct::ProfileStruct()
33 ProfileStruct::ProfileStruct(const OUString
& aProfileName
,
34 const OUString
& aProfilePath
)
35 : profileName(aProfileName
)
36 , profilePath(aProfilePath
)
40 const OUString
& ProfileStruct::getProfilePath() const
45 ProfileAccess::~ProfileAccess()
49 ProfileAccess::ProfileAccess()
54 void ProfileAccess::LoadProductsInfo()
56 //tdf#39279: LO should search Thunderbird first then Seamonkey and finally Firefox
57 //load thunderbird profiles to m_ProductProfileList
58 LoadXPToolkitProfiles(MozillaProductType_Thunderbird
);
60 //load SeaMonkey 2 profiles to m_ProductProfileList
61 LoadXPToolkitProfiles(MozillaProductType_Mozilla
);
63 //load firefox profiles to m_ProductProfileList
64 //firefox profile does not contain address book, but maybe others need them
65 LoadXPToolkitProfiles(MozillaProductType_Firefox
);
67 //Thunderbird and firefox profiles are saved in profiles.ini
68 void ProfileAccess::LoadXPToolkitProfiles(MozillaProductType product
)
70 sal_Int32 index
=static_cast<sal_Int32
>(product
);
71 ProductStruct
&rProduct
= m_ProductProfileList
[index
];
73 OUString regDir
= getRegistryDir(product
);
74 OUString profilesIni
= regDir
+ "profiles.ini";
75 IniParser
parser( profilesIni
);
76 IniSectionMap
&rAllSection
= parser
.getAllSection();
78 for(auto& rSection
: rAllSection
)
80 ini_Section
*aSection
= &rSection
.second
;
86 for(auto& rValue
: aSection
->vVector
)
88 struct ini_NameValue
* aValue
= &rValue
;
89 if ( aValue
->sName
== "Name" )
91 profileName
= aValue
->sValue
;
93 else if ( aValue
->sName
== "IsRelative" )
95 sIsRelative
= aValue
->sValue
;
97 else if ( aValue
->sName
== "Path" )
99 profilePath
= aValue
->sValue
;
101 else if ( aValue
->sName
== "Default" )
103 sIsDefault
= aValue
->sValue
;
106 if (!(profileName
.isEmpty() && profilePath
.isEmpty()))
108 sal_Int32 isRelative
= 0;
109 if (!sIsRelative
.isEmpty())
111 isRelative
= sIsRelative
.toInt32();
114 OUString fullProfilePath
;
117 fullProfilePath
= regDir
+ profilePath
;
121 fullProfilePath
= profilePath
;
124 rProduct
.mProfileList
[profileName
] = ProfileStruct(profileName
,fullProfilePath
);
126 sal_Int32 isDefault
= 0;
127 if (!sIsDefault
.isEmpty())
129 isDefault
= sIsDefault
.toInt32();
132 rProduct
.mCurrentProfileName
= profileName
;
139 OUString
ProfileAccess::getProfilePath( css::mozilla::MozillaProductType product
, const OUString
& profileName
)
141 sal_Int32 index
=static_cast<sal_Int32
>(product
);
142 ProductStruct
&rProduct
= m_ProductProfileList
[index
];
143 if (rProduct
.mProfileList
.empty() || rProduct
.mProfileList
.find(profileName
) == rProduct
.mProfileList
.end())
149 return rProduct
.mProfileList
[profileName
].getProfilePath();
152 ::sal_Int32
ProfileAccess::getProfileCount( css::mozilla::MozillaProductType product
)
154 sal_Int32 index
=static_cast<sal_Int32
>(product
);
155 ProductStruct
&rProduct
= m_ProductProfileList
[index
];
156 return static_cast< ::sal_Int32
>(rProduct
.mProfileList
.size());
158 ::sal_Int32
ProfileAccess::getProfileList( css::mozilla::MozillaProductType product
, css::uno::Sequence
< OUString
>& list
)
160 sal_Int32 index
=static_cast<sal_Int32
>(product
);
161 ProductStruct
&rProduct
= m_ProductProfileList
[index
];
162 list
.realloc(static_cast<sal_Int32
>(rProduct
.mProfileList
.size()));
164 for(const auto& rEntry
: rProduct
.mProfileList
)
166 const ProfileStruct
& rProfile
= rEntry
.second
;
167 list
[i
] = rProfile
.getProfileName();
171 return static_cast< ::sal_Int32
>(rProduct
.mProfileList
.size());
174 OUString
ProfileAccess::getDefaultProfile( css::mozilla::MozillaProductType product
)
176 sal_Int32 index
=static_cast<sal_Int32
>(product
);
177 ProductStruct
&rProduct
= m_ProductProfileList
[index
];
178 if (!rProduct
.mCurrentProfileName
.isEmpty())
180 //default profile set in mozilla registry
181 return rProduct
.mCurrentProfileName
;
183 if (rProduct
.mProfileList
.empty())
185 //there are not any profiles
188 const ProfileStruct
& rProfile
= (*rProduct
.mProfileList
.begin()).second
;
189 return rProfile
.getProfileName();
192 bool ProfileAccess::getProfileExists( css::mozilla::MozillaProductType product
, const OUString
& profileName
)
194 sal_Int32 index
=static_cast<sal_Int32
>(product
);
195 ProductStruct
&rProduct
= m_ProductProfileList
[index
];
196 return rProduct
.mProfileList
.find(profileName
) != rProduct
.mProfileList
.end();
202 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */