xref: /AOO41X/main/extensions/source/mozbootstrap/MNSProfileDiscover.cxx (revision 9874e4f6d986ac5869ea45d8ed5f7bf59eeaff2e)
1*9874e4f6SJuergen Schmidt /**************************************************************
2*9874e4f6SJuergen Schmidt  *
3*9874e4f6SJuergen Schmidt  * Licensed to the Apache Software Foundation (ASF) under one
4*9874e4f6SJuergen Schmidt  * or more contributor license agreements.  See the NOTICE file
5*9874e4f6SJuergen Schmidt  * distributed with this work for additional information
6*9874e4f6SJuergen Schmidt  * regarding copyright ownership.  The ASF licenses this file
7*9874e4f6SJuergen Schmidt  * to you under the Apache License, Version 2.0 (the
8*9874e4f6SJuergen Schmidt  * "License"); you may not use this file except in compliance
9*9874e4f6SJuergen Schmidt  * with the License.  You may obtain a copy of the License at
10*9874e4f6SJuergen Schmidt  *
11*9874e4f6SJuergen Schmidt  *   http://www.apache.org/licenses/LICENSE-2.0
12*9874e4f6SJuergen Schmidt  *
13*9874e4f6SJuergen Schmidt  * Unless required by applicable law or agreed to in writing,
14*9874e4f6SJuergen Schmidt  * software distributed under the License is distributed on an
15*9874e4f6SJuergen Schmidt  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9874e4f6SJuergen Schmidt  * KIND, either express or implied.  See the License for the
17*9874e4f6SJuergen Schmidt  * specific language governing permissions and limitations
18*9874e4f6SJuergen Schmidt  * under the License.
19*9874e4f6SJuergen Schmidt  *
20*9874e4f6SJuergen Schmidt  *************************************************************/
21*9874e4f6SJuergen Schmidt 
22*9874e4f6SJuergen Schmidt // MARKER(update_precomp.py): autogen include statement, do not remove
23*9874e4f6SJuergen Schmidt #include "precompiled_extensions.hxx"
24*9874e4f6SJuergen Schmidt #include "MNSProfileDiscover.hxx"
25*9874e4f6SJuergen Schmidt 
26*9874e4f6SJuergen Schmidt // Registry Keys
27*9874e4f6SJuergen Schmidt 
28*9874e4f6SJuergen Schmidt static ::rtl::OUString szProfileSubtreeString=::rtl::OUString::createFromAscii("Profiles");
29*9874e4f6SJuergen Schmidt static ::rtl::OUString szCurrentProfileString= ::rtl::OUString::createFromAscii("CurrentProfile");
30*9874e4f6SJuergen Schmidt static ::rtl::OUString szDirectoryString =::rtl::OUString::createFromAscii("directory");
31*9874e4f6SJuergen Schmidt 
32*9874e4f6SJuergen Schmidt #ifndef MAXPATHLEN
33*9874e4f6SJuergen Schmidt #define MAXPATHLEN 1024
34*9874e4f6SJuergen Schmidt #endif
35*9874e4f6SJuergen Schmidt #include <MNSFolders.hxx>
36*9874e4f6SJuergen Schmidt #include <MNSINIParser.hxx>
37*9874e4f6SJuergen Schmidt 
38*9874e4f6SJuergen Schmidt namespace connectivity
39*9874e4f6SJuergen Schmidt {
40*9874e4f6SJuergen Schmidt     namespace mozab
41*9874e4f6SJuergen Schmidt     {
42*9874e4f6SJuergen Schmidt         ProfileStruct::ProfileStruct(MozillaProductType aProduct,::rtl::OUString aProfileName,
43*9874e4f6SJuergen Schmidt             const ::rtl::OUString& aProfilePath)
44*9874e4f6SJuergen Schmidt         {
45*9874e4f6SJuergen Schmidt             product=aProduct;
46*9874e4f6SJuergen Schmidt             profileName = aProfileName;
47*9874e4f6SJuergen Schmidt             profilePath = aProfilePath;
48*9874e4f6SJuergen Schmidt         }
49*9874e4f6SJuergen Schmidt         ::rtl::OUString ProfileStruct::getProfilePath()
50*9874e4f6SJuergen Schmidt         {
51*9874e4f6SJuergen Schmidt             return profilePath;
52*9874e4f6SJuergen Schmidt         }
53*9874e4f6SJuergen Schmidt 
54*9874e4f6SJuergen Schmidt         ProfileAccess::~ProfileAccess()
55*9874e4f6SJuergen Schmidt         {
56*9874e4f6SJuergen Schmidt         }
57*9874e4f6SJuergen Schmidt         ProfileAccess::ProfileAccess()
58*9874e4f6SJuergen Schmidt         {
59*9874e4f6SJuergen Schmidt             LoadProductsInfo();
60*9874e4f6SJuergen Schmidt         }
61*9874e4f6SJuergen Schmidt 
62*9874e4f6SJuergen Schmidt         sal_Int32 ProfileAccess::LoadProductsInfo()
63*9874e4f6SJuergen Schmidt         {
64*9874e4f6SJuergen Schmidt             //load SeaMonkey 2 profiles to m_ProductProfileList
65*9874e4f6SJuergen Schmidt             sal_Int32 count = LoadXPToolkitProfiles(MozillaProductType_Mozilla);
66*9874e4f6SJuergen Schmidt 
67*9874e4f6SJuergen Schmidt             //load thunderbird profiles to m_ProductProfileList
68*9874e4f6SJuergen Schmidt             count += LoadXPToolkitProfiles(MozillaProductType_Thunderbird);
69*9874e4f6SJuergen Schmidt 
70*9874e4f6SJuergen Schmidt             //load firefox profiles to m_ProductProfileList
71*9874e4f6SJuergen Schmidt             //firefox profile does not containt address book, but maybe others need them
72*9874e4f6SJuergen Schmidt             count += LoadXPToolkitProfiles(MozillaProductType_Firefox);
73*9874e4f6SJuergen Schmidt             return count;
74*9874e4f6SJuergen Schmidt         }
75*9874e4f6SJuergen Schmidt         //Thunderbird and firefox profiles are saved in profiles.ini
76*9874e4f6SJuergen Schmidt         sal_Int32 ProfileAccess::LoadXPToolkitProfiles(MozillaProductType product)
77*9874e4f6SJuergen Schmidt         {
78*9874e4f6SJuergen Schmidt             sal_Int32 index=product;
79*9874e4f6SJuergen Schmidt             ProductStruct &m_Product = m_ProductProfileList[index];
80*9874e4f6SJuergen Schmidt 
81*9874e4f6SJuergen Schmidt             ::rtl::OUString regDir = getRegistryDir(product);
82*9874e4f6SJuergen Schmidt             ::rtl::OUString profilesIni( regDir );
83*9874e4f6SJuergen Schmidt             profilesIni += ::rtl::OUString::createFromAscii( "profiles.ini" );
84*9874e4f6SJuergen Schmidt             IniParser parser( profilesIni );
85*9874e4f6SJuergen Schmidt             IniSectionMap &mAllSection = *(parser.getAllSection());
86*9874e4f6SJuergen Schmidt 
87*9874e4f6SJuergen Schmidt             IniSectionMap::iterator iBegin = mAllSection.begin();
88*9874e4f6SJuergen Schmidt             IniSectionMap::iterator iEnd = mAllSection.end();
89*9874e4f6SJuergen Schmidt             for(;iBegin != iEnd;iBegin++)
90*9874e4f6SJuergen Schmidt             {
91*9874e4f6SJuergen Schmidt                 ini_Section *aSection = &(*iBegin).second;
92*9874e4f6SJuergen Schmidt                 ::rtl::OUString profileName;
93*9874e4f6SJuergen Schmidt                 ::rtl::OUString profilePath;
94*9874e4f6SJuergen Schmidt                 ::rtl::OUString sIsRelative;
95*9874e4f6SJuergen Schmidt                 ::rtl::OUString sIsDefault;
96*9874e4f6SJuergen Schmidt 
97*9874e4f6SJuergen Schmidt                 for(NameValueList::iterator itor=aSection->lList.begin();
98*9874e4f6SJuergen Schmidt                     itor != aSection->lList.end();
99*9874e4f6SJuergen Schmidt                     itor++)
100*9874e4f6SJuergen Schmidt                 {
101*9874e4f6SJuergen Schmidt                         struct ini_NameValue * aValue = &(*itor);
102*9874e4f6SJuergen Schmidt                         if (aValue->sName.equals(::rtl::OUString::createFromAscii("Name")))
103*9874e4f6SJuergen Schmidt                         {
104*9874e4f6SJuergen Schmidt                             profileName = aValue->sValue;
105*9874e4f6SJuergen Schmidt                         }
106*9874e4f6SJuergen Schmidt                         else if (aValue->sName.equals(::rtl::OUString::createFromAscii("IsRelative")))
107*9874e4f6SJuergen Schmidt                         {
108*9874e4f6SJuergen Schmidt                             sIsRelative = aValue->sValue;
109*9874e4f6SJuergen Schmidt                         }
110*9874e4f6SJuergen Schmidt                         else if (aValue->sName.equals(::rtl::OUString::createFromAscii("Path")))
111*9874e4f6SJuergen Schmidt                         {
112*9874e4f6SJuergen Schmidt                             profilePath = aValue->sValue;
113*9874e4f6SJuergen Schmidt                         }
114*9874e4f6SJuergen Schmidt                         else if (aValue->sName.equals(::rtl::OUString::createFromAscii("Default")))
115*9874e4f6SJuergen Schmidt                         {
116*9874e4f6SJuergen Schmidt                             sIsDefault = aValue->sValue;
117*9874e4f6SJuergen Schmidt                         }
118*9874e4f6SJuergen Schmidt                 }
119*9874e4f6SJuergen Schmidt                 if (profileName.getLength() != 0 || profilePath.getLength() != 0)
120*9874e4f6SJuergen Schmidt                 {
121*9874e4f6SJuergen Schmidt                     sal_Int32 isRelative = 0;
122*9874e4f6SJuergen Schmidt                     if (sIsRelative.getLength() != 0)
123*9874e4f6SJuergen Schmidt                     {
124*9874e4f6SJuergen Schmidt                         isRelative = sIsRelative.toInt32();
125*9874e4f6SJuergen Schmidt                     }
126*9874e4f6SJuergen Schmidt 
127*9874e4f6SJuergen Schmidt                     ProfileStruct*  profileItem     = new ProfileStruct(product,profileName,
128*9874e4f6SJuergen Schmidt                             regDir + profilePath);
129*9874e4f6SJuergen Schmidt                     m_Product.mProfileList[profileName] = profileItem;
130*9874e4f6SJuergen Schmidt 
131*9874e4f6SJuergen Schmidt                     sal_Int32 isDefault = 0;
132*9874e4f6SJuergen Schmidt                     if (sIsDefault.getLength() != 0)
133*9874e4f6SJuergen Schmidt                     {
134*9874e4f6SJuergen Schmidt                         isDefault = sIsDefault.toInt32();
135*9874e4f6SJuergen Schmidt                     }
136*9874e4f6SJuergen Schmidt                     if (isDefault)
137*9874e4f6SJuergen Schmidt                         m_Product.mCurrentProfileName = profileName;
138*9874e4f6SJuergen Schmidt 
139*9874e4f6SJuergen Schmidt                 }
140*9874e4f6SJuergen Schmidt 
141*9874e4f6SJuergen Schmidt             }
142*9874e4f6SJuergen Schmidt             return static_cast< ::sal_Int32 >(m_Product.mProfileList.size());
143*9874e4f6SJuergen Schmidt         }
144*9874e4f6SJuergen Schmidt 
145*9874e4f6SJuergen Schmidt         ::rtl::OUString ProfileAccess::getProfilePath( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
146*9874e4f6SJuergen Schmidt         {
147*9874e4f6SJuergen Schmidt             sal_Int32 index=product;
148*9874e4f6SJuergen Schmidt             ProductStruct &m_Product = m_ProductProfileList[index];
149*9874e4f6SJuergen Schmidt             if (!m_Product.mProfileList.size() || m_Product.mProfileList.find(profileName) == m_Product.mProfileList.end())
150*9874e4f6SJuergen Schmidt             {
151*9874e4f6SJuergen Schmidt                 //Profile not found
152*9874e4f6SJuergen Schmidt                 return ::rtl::OUString();
153*9874e4f6SJuergen Schmidt             }
154*9874e4f6SJuergen Schmidt             else
155*9874e4f6SJuergen Schmidt                 return m_Product.mProfileList[profileName]->getProfilePath();
156*9874e4f6SJuergen Schmidt         }
157*9874e4f6SJuergen Schmidt 
158*9874e4f6SJuergen Schmidt         ::sal_Int32 ProfileAccess::getProfileCount( ::com::sun::star::mozilla::MozillaProductType product) throw (::com::sun::star::uno::RuntimeException)
159*9874e4f6SJuergen Schmidt         {
160*9874e4f6SJuergen Schmidt             sal_Int32 index=product;
161*9874e4f6SJuergen Schmidt             ProductStruct &m_Product = m_ProductProfileList[index];
162*9874e4f6SJuergen Schmidt             return static_cast< ::sal_Int32 >(m_Product.mProfileList.size());
163*9874e4f6SJuergen Schmidt         }
164*9874e4f6SJuergen Schmidt         ::sal_Int32 ProfileAccess::getProfileList( ::com::sun::star::mozilla::MozillaProductType product, ::com::sun::star::uno::Sequence< ::rtl::OUString >& list ) throw (::com::sun::star::uno::RuntimeException)
165*9874e4f6SJuergen Schmidt         {
166*9874e4f6SJuergen Schmidt             sal_Int32 index=product;
167*9874e4f6SJuergen Schmidt             ProductStruct &m_Product = m_ProductProfileList[index];
168*9874e4f6SJuergen Schmidt             list.realloc(static_cast<sal_Int32>(m_Product.mProfileList.size()));
169*9874e4f6SJuergen Schmidt             sal_Int32 i=0;
170*9874e4f6SJuergen Schmidt             for(ProfileList::iterator itor=m_Product.mProfileList.begin();
171*9874e4f6SJuergen Schmidt                 itor != m_Product.mProfileList.end();
172*9874e4f6SJuergen Schmidt                 itor++)
173*9874e4f6SJuergen Schmidt             {
174*9874e4f6SJuergen Schmidt                 ProfileStruct * aProfile = (*itor).second;
175*9874e4f6SJuergen Schmidt                 list[i] = aProfile->getProfileName();
176*9874e4f6SJuergen Schmidt                 i++;
177*9874e4f6SJuergen Schmidt             }
178*9874e4f6SJuergen Schmidt 
179*9874e4f6SJuergen Schmidt             return static_cast< ::sal_Int32 >(m_Product.mProfileList.size());
180*9874e4f6SJuergen Schmidt         }
181*9874e4f6SJuergen Schmidt 
182*9874e4f6SJuergen Schmidt         ::rtl::OUString ProfileAccess::getDefaultProfile( ::com::sun::star::mozilla::MozillaProductType product ) throw (::com::sun::star::uno::RuntimeException)
183*9874e4f6SJuergen Schmidt         {
184*9874e4f6SJuergen Schmidt             sal_Int32 index=product;
185*9874e4f6SJuergen Schmidt             ProductStruct &m_Product = m_ProductProfileList[index];
186*9874e4f6SJuergen Schmidt             if (m_Product.mCurrentProfileName.getLength() != 0)
187*9874e4f6SJuergen Schmidt             {
188*9874e4f6SJuergen Schmidt                 //default profile setted in mozilla registry
189*9874e4f6SJuergen Schmidt                 return m_Product.mCurrentProfileName;
190*9874e4f6SJuergen Schmidt             }
191*9874e4f6SJuergen Schmidt             if (m_Product.mProfileList.size() == 0)
192*9874e4f6SJuergen Schmidt             {
193*9874e4f6SJuergen Schmidt                 //there are not any profiles
194*9874e4f6SJuergen Schmidt                 return ::rtl::OUString();
195*9874e4f6SJuergen Schmidt             }
196*9874e4f6SJuergen Schmidt             ProfileStruct * aProfile = (*m_Product.mProfileList.begin()).second;
197*9874e4f6SJuergen Schmidt             return aProfile->getProfileName();
198*9874e4f6SJuergen Schmidt         }
199*9874e4f6SJuergen Schmidt 
200*9874e4f6SJuergen Schmidt         ::sal_Bool ProfileAccess::isProfileLocked( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
201*9874e4f6SJuergen Schmidt         {
202*9874e4f6SJuergen Schmidt             (void)product; /* avoid warning about unused parameter */
203*9874e4f6SJuergen Schmidt             (void)profileName; /* avoid warning about unused parameter */
204*9874e4f6SJuergen Schmidt             return sal_True;
205*9874e4f6SJuergen Schmidt         }
206*9874e4f6SJuergen Schmidt 
207*9874e4f6SJuergen Schmidt         ::sal_Bool ProfileAccess::getProfileExists( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
208*9874e4f6SJuergen Schmidt         {
209*9874e4f6SJuergen Schmidt             sal_Int32 index=product;
210*9874e4f6SJuergen Schmidt             ProductStruct &m_Product = m_ProductProfileList[index];
211*9874e4f6SJuergen Schmidt             if (!m_Product.mProfileList.size() || m_Product.mProfileList.find(profileName) == m_Product.mProfileList.end())
212*9874e4f6SJuergen Schmidt             {
213*9874e4f6SJuergen Schmidt                 return sal_False;
214*9874e4f6SJuergen Schmidt             }
215*9874e4f6SJuergen Schmidt             else
216*9874e4f6SJuergen Schmidt                 return sal_True;
217*9874e4f6SJuergen Schmidt         }
218*9874e4f6SJuergen Schmidt     }
219*9874e4f6SJuergen Schmidt }
220*9874e4f6SJuergen Schmidt 
221*9874e4f6SJuergen Schmidt 
222