Update git submodules
[LibreOffice.git] / connectivity / source / drivers / mozab / bootstrap / MNSProfileDiscover.cxx
blob804c8ccc66d859d7e4f470298a1048a329018604
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 <utility>
23 #include "MNSProfileDiscover.hxx"
24 #include "MNSFolders.hxx"
25 #include "MNSINIParser.hxx"
27 namespace connectivity::mozab
29 ProfileStruct::ProfileStruct()
33 ProfileStruct::ProfileStruct(OUString aProfileName,
34 OUString aProfilePath)
35 : profileName(std::move(aProfileName))
36 , profilePath(std::move(aProfilePath))
40 const OUString& ProfileStruct::getProfilePath() const
42 return profilePath;
45 ProfileAccess::~ProfileAccess()
49 ProfileAccess::ProfileAccess()
51 LoadProductsInfo();
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;
81 OUString profileName;
82 OUString profilePath;
83 OUString sIsRelative;
84 OUString sIsDefault;
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;
115 if(isRelative)
117 fullProfilePath = regDir + profilePath;
119 else
121 fullProfilePath = profilePath;
124 rProduct.mProfileList[profileName] = ProfileStruct(profileName,fullProfilePath);
126 sal_Int32 isDefault = 0;
127 if (!sIsDefault.isEmpty())
129 isDefault = sIsDefault.toInt32();
131 if (isDefault)
132 rProduct.mCurrentProfileName = profileName;
136 // Depending on TB versions, some generate "default" profile
137 // others "default-release" profile
138 // See https://support.mozilla.org/gl/questions/1264072
139 // for some background info (the link quotes Firefox but it seems
140 // the same for TB).
141 if (profileName == "default-release")
143 rProduct.mCurrentProfileName = profileName;
144 break;
149 OUString ProfileAccess::getProfilePath( css::mozilla::MozillaProductType product, const OUString& profileName )
151 sal_Int32 index=static_cast<sal_Int32>(product);
152 ProductStruct &rProduct = m_ProductProfileList[index];
153 if (rProduct.mProfileList.empty() || rProduct.mProfileList.find(profileName) == rProduct.mProfileList.end())
155 //Profile not found
156 return OUString();
158 else
159 return rProduct.mProfileList[profileName].getProfilePath();
162 ::sal_Int32 ProfileAccess::getProfileCount( css::mozilla::MozillaProductType product)
164 sal_Int32 index=static_cast<sal_Int32>(product);
165 ProductStruct &rProduct = m_ProductProfileList[index];
166 return static_cast< ::sal_Int32 >(rProduct.mProfileList.size());
168 ::sal_Int32 ProfileAccess::getProfileList( css::mozilla::MozillaProductType product, css::uno::Sequence< OUString >& list )
170 sal_Int32 index=static_cast<sal_Int32>(product);
171 ProductStruct &rProduct = m_ProductProfileList[index];
172 list.realloc(static_cast<sal_Int32>(rProduct.mProfileList.size()));
173 auto listRange = list.getArray();
174 sal_Int32 i=0;
175 for(const auto& rEntry : rProduct.mProfileList)
177 const ProfileStruct& rProfile = rEntry.second;
178 listRange[i] = rProfile.getProfileName();
179 i++;
182 return static_cast< ::sal_Int32 >(rProduct.mProfileList.size());
185 OUString ProfileAccess::getDefaultProfile( css::mozilla::MozillaProductType product )
187 sal_Int32 index=static_cast<sal_Int32>(product);
188 ProductStruct &rProduct = m_ProductProfileList[index];
189 if (!rProduct.mCurrentProfileName.isEmpty())
191 //default profile set in mozilla registry
192 return rProduct.mCurrentProfileName;
194 if (rProduct.mProfileList.empty())
196 //there are not any profiles
197 return OUString();
199 const ProfileStruct& rProfile = (*rProduct.mProfileList.begin()).second;
200 return rProfile.getProfileName();
203 bool ProfileAccess::getProfileExists( css::mozilla::MozillaProductType product, const OUString& profileName )
205 sal_Int32 index=static_cast<sal_Int32>(product);
206 ProductStruct &rProduct = m_ProductProfileList[index];
207 return rProduct.mProfileList.find(profileName) != rProduct.mProfileList.end();
212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */