Line data Source code
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 "MNSProfileDiscover.hxx"
22 :
23 : #include <MNSFolders.hxx>
24 : #include <MNSINIParser.hxx>
25 :
26 : namespace connectivity
27 : {
28 : namespace mork
29 : {
30 0 : ProfileStruct::ProfileStruct(MozillaProductType aProduct, const OUString& aProfileName,
31 : const OUString& aProfilePath
32 0 : )
33 : {
34 0 : product=aProduct;
35 0 : profileName = aProfileName;
36 0 : profilePath = aProfilePath;
37 0 : }
38 0 : OUString ProfileStruct::getProfilePath()
39 : {
40 0 : return profilePath;
41 : }
42 :
43 0 : ProfileAccess::~ProfileAccess()
44 : {
45 0 : }
46 0 : ProfileAccess::ProfileAccess()
47 : {
48 0 : LoadProductsInfo();
49 0 : }
50 :
51 0 : sal_Int32 ProfileAccess::LoadProductsInfo()
52 : {
53 : //load SeaMonkey 2 profiles to m_ProductProfileList
54 0 : sal_Int32 count = LoadXPToolkitProfiles(MozillaProductType_Mozilla);
55 :
56 : //load thunderbird profiles to m_ProductProfileList
57 0 : count += LoadXPToolkitProfiles(MozillaProductType_Thunderbird);
58 :
59 : //load firefox profiles to m_ProductProfileList
60 : //firefox profile does not containt address book, but maybe others need them
61 0 : count += LoadXPToolkitProfiles(MozillaProductType_Firefox);
62 0 : return count;
63 : }
64 : //Thunderbird and firefox profiles are saved in profiles.ini
65 0 : sal_Int32 ProfileAccess::LoadXPToolkitProfiles(MozillaProductType product)
66 : {
67 0 : sal_Int32 index=product;
68 0 : ProductStruct &m_Product = m_ProductProfileList[index];
69 :
70 0 : OUString regDir = getRegistryDir(product);
71 0 : OUString profilesIni = regDir + "profiles.ini";
72 0 : IniParser parser( profilesIni );
73 0 : IniSectionMap &mAllSection = *(parser.getAllSection());
74 :
75 0 : IniSectionMap::iterator iBegin = mAllSection.begin();
76 0 : IniSectionMap::iterator iEnd = mAllSection.end();
77 0 : for(;iBegin != iEnd;++iBegin)
78 : {
79 0 : ini_Section *aSection = &(*iBegin).second;
80 0 : OUString profileName;
81 0 : OUString profilePath;
82 0 : OUString sIsRelative;
83 0 : OUString sIsDefault;
84 :
85 0 : for(NameValueList::iterator itor=aSection->lList.begin();
86 0 : itor != aSection->lList.end();
87 : ++itor)
88 : {
89 0 : struct ini_NameValue * aValue = &(*itor);
90 0 : if ( aValue->sName == "Name" )
91 : {
92 0 : profileName = aValue->sValue;
93 : }
94 0 : else if ( aValue->sName == "IsRelative" )
95 : {
96 0 : sIsRelative = aValue->sValue;
97 : }
98 0 : else if ( aValue->sName == "Path" )
99 : {
100 0 : profilePath = aValue->sValue;
101 : }
102 0 : else if ( aValue->sName == "Default" )
103 : {
104 0 : sIsDefault = aValue->sValue;
105 : }
106 : }
107 0 : if (!(profileName.isEmpty() && profilePath.isEmpty()))
108 : {
109 0 : sal_Int32 isRelative = 0;
110 0 : if (!sIsRelative.isEmpty())
111 : {
112 0 : isRelative = sIsRelative.toInt32();
113 : }
114 :
115 0 : OUString fullProfilePath;
116 0 : if(isRelative)
117 : {
118 0 : fullProfilePath = regDir + profilePath;
119 : }
120 : else
121 : {
122 0 : fullProfilePath = profilePath;
123 : }
124 :
125 : ProfileStruct* profileItem = new ProfileStruct(product,profileName,
126 : fullProfilePath
127 0 : );
128 0 : m_Product.mProfileList[profileName] = profileItem;
129 :
130 0 : sal_Int32 isDefault = 0;
131 0 : if (!sIsDefault.isEmpty())
132 : {
133 0 : isDefault = sIsDefault.toInt32();
134 : }
135 0 : if (isDefault)
136 0 : m_Product.mCurrentProfileName = profileName;
137 :
138 : }
139 :
140 0 : }
141 0 : return static_cast< ::sal_Int32 >(m_Product.mProfileList.size());
142 : }
143 :
144 0 : OUString ProfileAccess::getProfilePath( ::com::sun::star::mozilla::MozillaProductType product, const OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
145 : {
146 0 : sal_Int32 index=product;
147 0 : ProductStruct &m_Product = m_ProductProfileList[index];
148 0 : if (!m_Product.mProfileList.size() || m_Product.mProfileList.find(profileName) == m_Product.mProfileList.end())
149 : {
150 : //Profile not found
151 0 : return OUString();
152 : }
153 : else
154 0 : return m_Product.mProfileList[profileName]->getProfilePath();
155 : }
156 :
157 0 : OUString ProfileAccess::getDefaultProfile( ::com::sun::star::mozilla::MozillaProductType product ) throw (::com::sun::star::uno::RuntimeException)
158 : {
159 0 : sal_Int32 index=product;
160 0 : ProductStruct &m_Product = m_ProductProfileList[index];
161 0 : if (!m_Product.mCurrentProfileName.isEmpty())
162 : {
163 : //default profile setted in mozilla registry
164 0 : return m_Product.mCurrentProfileName;
165 : }
166 0 : if (m_Product.mProfileList.empty())
167 : {
168 : //there are not any profiles
169 0 : return OUString();
170 : }
171 0 : ProfileStruct * aProfile = (*m_Product.mProfileList.begin()).second;
172 0 : return aProfile->getProfileName();
173 : }
174 : }
175 : }
176 :
177 :
178 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|