LibreOffice Module connectivity (master) 1
MNSProfileDiscover.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <utility>
22
24#include "MNSFolders.hxx"
25#include "MNSINIParser.hxx"
26
27namespace connectivity::mozab
28{
30 {
31 }
32
33 ProfileStruct::ProfileStruct(OUString aProfileName,
34 OUString aProfilePath)
35 : profileName(std::move(aProfileName))
36 , profilePath(std::move(aProfilePath))
37 {
38 }
39
40 const OUString& ProfileStruct::getProfilePath() const
41 {
42 return profilePath;
43 }
44
46 {
47 }
48
50 {
52 }
53
55 {
56 //tdf#39279: LO should search Thunderbird first then Seamonkey and finally Firefox
57 //load thunderbird profiles to m_ProductProfileList
58 LoadXPToolkitProfiles(MozillaProductType_Thunderbird);
59
60 //load SeaMonkey 2 profiles to m_ProductProfileList
61 LoadXPToolkitProfiles(MozillaProductType_Mozilla);
62
63 //load firefox profiles to m_ProductProfileList
64 //firefox profile does not contain address book, but maybe others need them
65 LoadXPToolkitProfiles(MozillaProductType_Firefox);
66 }
67 //Thunderbird and firefox profiles are saved in profiles.ini
68 void ProfileAccess::LoadXPToolkitProfiles(MozillaProductType product)
69 {
70 sal_Int32 index=static_cast<sal_Int32>(product);
72
73 OUString regDir = getRegistryDir(product);
74 OUString profilesIni = regDir + "profiles.ini";
75 IniParser parser( profilesIni );
76 IniSectionMap &rAllSection = parser.getAllSection();
77
78 for(auto& rSection : rAllSection)
79 {
80 ini_Section *aSection = &rSection.second;
81 OUString profileName;
82 OUString profilePath;
83 OUString sIsRelative;
84 OUString sIsDefault;
85
86 for(auto& rValue : aSection->vVector)
87 {
88 struct ini_NameValue * aValue = &rValue;
89 if ( aValue->sName == "Name" )
90 {
91 profileName = aValue->sValue;
92 }
93 else if ( aValue->sName == "IsRelative" )
94 {
95 sIsRelative = aValue->sValue;
96 }
97 else if ( aValue->sName == "Path" )
98 {
99 profilePath = aValue->sValue;
100 }
101 else if ( aValue->sName == "Default" )
102 {
103 sIsDefault = aValue->sValue;
104 }
105 }
106 if (!(profileName.isEmpty() && profilePath.isEmpty()))
107 {
108 sal_Int32 isRelative = 0;
109 if (!sIsRelative.isEmpty())
110 {
111 isRelative = sIsRelative.toInt32();
112 }
113
114 OUString fullProfilePath;
115 if(isRelative)
116 {
117 fullProfilePath = regDir + profilePath;
118 }
119 else
120 {
121 fullProfilePath = profilePath;
122 }
123
124 rProduct.mProfileList[profileName] = ProfileStruct(profileName,fullProfilePath);
125
126 sal_Int32 isDefault = 0;
127 if (!sIsDefault.isEmpty())
128 {
129 isDefault = sIsDefault.toInt32();
130 }
131 if (isDefault)
132 rProduct.mCurrentProfileName = profileName;
133
134 }
135
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")
142 {
143 rProduct.mCurrentProfileName = profileName;
144 break;
145 }
146 }
147 }
148
149 OUString ProfileAccess::getProfilePath( css::mozilla::MozillaProductType product, const OUString& profileName )
150 {
151 sal_Int32 index=static_cast<sal_Int32>(product);
153 if (rProduct.mProfileList.empty() || rProduct.mProfileList.find(profileName) == rProduct.mProfileList.end())
154 {
155 //Profile not found
156 return OUString();
157 }
158 else
159 return rProduct.mProfileList[profileName].getProfilePath();
160 }
161
162 ::sal_Int32 ProfileAccess::getProfileCount( css::mozilla::MozillaProductType product)
163 {
164 sal_Int32 index=static_cast<sal_Int32>(product);
166 return static_cast< ::sal_Int32 >(rProduct.mProfileList.size());
167 }
168 ::sal_Int32 ProfileAccess::getProfileList( css::mozilla::MozillaProductType product, css::uno::Sequence< OUString >& list )
169 {
170 sal_Int32 index=static_cast<sal_Int32>(product);
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)
176 {
177 const ProfileStruct& rProfile = rEntry.second;
178 listRange[i] = rProfile.getProfileName();
179 i++;
180 }
181
182 return static_cast< ::sal_Int32 >(rProduct.mProfileList.size());
183 }
184
185 OUString ProfileAccess::getDefaultProfile( css::mozilla::MozillaProductType product )
186 {
187 sal_Int32 index=static_cast<sal_Int32>(product);
189 if (!rProduct.mCurrentProfileName.isEmpty())
190 {
191 //default profile set in mozilla registry
192 return rProduct.mCurrentProfileName;
193 }
194 if (rProduct.mProfileList.empty())
195 {
196 //there are not any profiles
197 return OUString();
198 }
199 const ProfileStruct& rProfile = (*rProduct.mProfileList.begin()).second;
200 return rProfile.getProfileName();
201 }
202
203 bool ProfileAccess::getProfileExists( css::mozilla::MozillaProductType product, const OUString& profileName )
204 {
205 sal_Int32 index=static_cast<sal_Int32>(product);
207 return rProduct.mProfileList.find(profileName) != rProduct.mProfileList.end();
208 }
209}
210
211
212/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString getRegistryDir(MozillaProductType product)
Definition: MNSFolders.cxx:151
std::map< OUString, ini_Section > IniSectionMap
::sal_Int32 getProfileCount(css::mozilla::MozillaProductType product)
::sal_Int32 getProfileList(css::mozilla::MozillaProductType product, css::uno::Sequence< OUString > &list)
OUString getProfilePath(css::mozilla::MozillaProductType product, const OUString &profileName)
void LoadXPToolkitProfiles(MozillaProductType product)
OUString getDefaultProfile(css::mozilla::MozillaProductType product)
bool getProfileExists(css::mozilla::MozillaProductType product, const OUString &profileName)
const OUString & getProfilePath() const
const OUString & getProfileName() const
int i
index
parser
OUString sValue
OUString sName
NameValueVector vVector