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::mozab
27 ProfileStruct::ProfileStruct()
31 ProfileStruct::ProfileStruct(const OUString
& aProfileName
,
32 const OUString
& aProfilePath
)
33 : profileName(aProfileName
)
34 , profilePath(aProfilePath
)
38 const OUString
& ProfileStruct::getProfilePath() const
43 ProfileAccess::~ProfileAccess()
47 ProfileAccess::ProfileAccess()
52 void ProfileAccess::LoadProductsInfo()
54 //tdf#39279: LO should search Thunderbird first then Seamonkey and finally Firefox
55 //load thunderbird profiles to m_ProductProfileList
56 LoadXPToolkitProfiles(MozillaProductType_Thunderbird
);
58 //load SeaMonkey 2 profiles to m_ProductProfileList
59 LoadXPToolkitProfiles(MozillaProductType_Mozilla
);
61 //load firefox profiles to m_ProductProfileList
62 //firefox profile does not contain address book, but maybe others need them
63 LoadXPToolkitProfiles(MozillaProductType_Firefox
);
65 //Thunderbird and firefox profiles are saved in profiles.ini
66 void ProfileAccess::LoadXPToolkitProfiles(MozillaProductType product
)
68 sal_Int32 index
=static_cast<sal_Int32
>(product
);
69 ProductStruct
&rProduct
= m_ProductProfileList
[index
];
71 OUString regDir
= getRegistryDir(product
);
72 OUString profilesIni
= regDir
+ "profiles.ini";
73 IniParser
parser( profilesIni
);
74 IniSectionMap
&rAllSection
= parser
.getAllSection();
76 for(auto& rSection
: rAllSection
)
78 ini_Section
*aSection
= &rSection
.second
;
84 for(auto& rValue
: aSection
->vVector
)
86 struct ini_NameValue
* aValue
= &rValue
;
87 if ( aValue
->sName
== "Name" )
89 profileName
= aValue
->sValue
;
91 else if ( aValue
->sName
== "IsRelative" )
93 sIsRelative
= aValue
->sValue
;
95 else if ( aValue
->sName
== "Path" )
97 profilePath
= aValue
->sValue
;
99 else if ( aValue
->sName
== "Default" )
101 sIsDefault
= aValue
->sValue
;
104 if (!(profileName
.isEmpty() && profilePath
.isEmpty()))
106 sal_Int32 isRelative
= 0;
107 if (!sIsRelative
.isEmpty())
109 isRelative
= sIsRelative
.toInt32();
112 OUString fullProfilePath
;
115 fullProfilePath
= regDir
+ profilePath
;
119 fullProfilePath
= profilePath
;
122 rProduct
.mProfileList
[profileName
] = ProfileStruct(profileName
,fullProfilePath
);
124 sal_Int32 isDefault
= 0;
125 if (!sIsDefault
.isEmpty())
127 isDefault
= sIsDefault
.toInt32();
130 rProduct
.mCurrentProfileName
= profileName
;
134 // Depending on TB versions, some generate "default" profile
135 // others "default-release" profile
136 // See https://support.mozilla.org/gl/questions/1264072
137 // for some background info (the link quotes Firefox but it seems
139 if (profileName
== "default-release")
141 rProduct
.mCurrentProfileName
= profileName
;
147 OUString
ProfileAccess::getProfilePath( css::mozilla::MozillaProductType product
, const OUString
& profileName
)
149 sal_Int32 index
=static_cast<sal_Int32
>(product
);
150 ProductStruct
&rProduct
= m_ProductProfileList
[index
];
151 if (rProduct
.mProfileList
.empty() || rProduct
.mProfileList
.find(profileName
) == rProduct
.mProfileList
.end())
157 return rProduct
.mProfileList
[profileName
].getProfilePath();
160 ::sal_Int32
ProfileAccess::getProfileCount( css::mozilla::MozillaProductType product
)
162 sal_Int32 index
=static_cast<sal_Int32
>(product
);
163 ProductStruct
&rProduct
= m_ProductProfileList
[index
];
164 return static_cast< ::sal_Int32
>(rProduct
.mProfileList
.size());
166 ::sal_Int32
ProfileAccess::getProfileList( css::mozilla::MozillaProductType product
, css::uno::Sequence
< OUString
>& list
)
168 sal_Int32 index
=static_cast<sal_Int32
>(product
);
169 ProductStruct
&rProduct
= m_ProductProfileList
[index
];
170 list
.realloc(static_cast<sal_Int32
>(rProduct
.mProfileList
.size()));
172 for(const auto& rEntry
: rProduct
.mProfileList
)
174 const ProfileStruct
& rProfile
= rEntry
.second
;
175 list
[i
] = rProfile
.getProfileName();
179 return static_cast< ::sal_Int32
>(rProduct
.mProfileList
.size());
182 OUString
ProfileAccess::getDefaultProfile( css::mozilla::MozillaProductType product
)
184 sal_Int32 index
=static_cast<sal_Int32
>(product
);
185 ProductStruct
&rProduct
= m_ProductProfileList
[index
];
186 if (!rProduct
.mCurrentProfileName
.isEmpty())
188 //default profile set in mozilla registry
189 return rProduct
.mCurrentProfileName
;
191 if (rProduct
.mProfileList
.empty())
193 //there are not any profiles
196 const ProfileStruct
& rProfile
= (*rProduct
.mProfileList
.begin()).second
;
197 return rProfile
.getProfileName();
200 bool ProfileAccess::getProfileExists( css::mozilla::MozillaProductType product
, const OUString
& profileName
)
202 sal_Int32 index
=static_cast<sal_Int32
>(product
);
203 ProductStruct
&rProduct
= m_ProductProfileList
[index
];
204 return rProduct
.mProfileList
.find(profileName
) != rProduct
.mProfileList
.end();
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */