16a653dafSJuergen Schmidt /************************************************************** 26a653dafSJuergen Schmidt * 36a653dafSJuergen Schmidt * Licensed to the Apache Software Foundation (ASF) under one 46a653dafSJuergen Schmidt * or more contributor license agreements. See the NOTICE file 56a653dafSJuergen Schmidt * distributed with this work for additional information 66a653dafSJuergen Schmidt * regarding copyright ownership. The ASF licenses this file 76a653dafSJuergen Schmidt * to you under the Apache License, Version 2.0 (the 86a653dafSJuergen Schmidt * "License"); you may not use this file except in compliance 96a653dafSJuergen Schmidt * with the License. You may obtain a copy of the License at 106a653dafSJuergen Schmidt * 116a653dafSJuergen Schmidt * http://www.apache.org/licenses/LICENSE-2.0 126a653dafSJuergen Schmidt * 136a653dafSJuergen Schmidt * Unless required by applicable law or agreed to in writing, 146a653dafSJuergen Schmidt * software distributed under the License is distributed on an 156a653dafSJuergen Schmidt * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 166a653dafSJuergen Schmidt * KIND, either express or implied. See the License for the 176a653dafSJuergen Schmidt * specific language governing permissions and limitations 186a653dafSJuergen Schmidt * under the License. 196a653dafSJuergen Schmidt * 206a653dafSJuergen Schmidt *************************************************************/ 216a653dafSJuergen Schmidt 226a653dafSJuergen Schmidt // MARKER(update_precomp.py): autogen include statement, do not remove 236a653dafSJuergen Schmidt #include "precompiled_extensions.hxx" 246a653dafSJuergen Schmidt #include "MNSProfileDiscover.hxx" 256a653dafSJuergen Schmidt 266a653dafSJuergen Schmidt // Registry Keys 276a653dafSJuergen Schmidt 286a653dafSJuergen Schmidt static ::rtl::OUString szProfileSubtreeString=::rtl::OUString::createFromAscii("Profiles"); 296a653dafSJuergen Schmidt static ::rtl::OUString szCurrentProfileString= ::rtl::OUString::createFromAscii("CurrentProfile"); 306a653dafSJuergen Schmidt static ::rtl::OUString szDirectoryString =::rtl::OUString::createFromAscii("directory"); 316a653dafSJuergen Schmidt 326a653dafSJuergen Schmidt #ifndef MAXPATHLEN 336a653dafSJuergen Schmidt #define MAXPATHLEN 1024 346a653dafSJuergen Schmidt #endif 356a653dafSJuergen Schmidt #include <MNSFolders.hxx> 366a653dafSJuergen Schmidt #include <MNSINIParser.hxx> 376a653dafSJuergen Schmidt 386a653dafSJuergen Schmidt namespace connectivity 396a653dafSJuergen Schmidt { 406a653dafSJuergen Schmidt namespace mozab 416a653dafSJuergen Schmidt { ProfileStruct(MozillaProductType aProduct,::rtl::OUString aProfileName,const::rtl::OUString & aProfilePath)426a653dafSJuergen Schmidt ProfileStruct::ProfileStruct(MozillaProductType aProduct,::rtl::OUString aProfileName, 436a653dafSJuergen Schmidt const ::rtl::OUString& aProfilePath) 446a653dafSJuergen Schmidt { 456a653dafSJuergen Schmidt product=aProduct; 466a653dafSJuergen Schmidt profileName = aProfileName; 476a653dafSJuergen Schmidt profilePath = aProfilePath; 486a653dafSJuergen Schmidt } getProfilePath()496a653dafSJuergen Schmidt ::rtl::OUString ProfileStruct::getProfilePath() 506a653dafSJuergen Schmidt { 516a653dafSJuergen Schmidt return profilePath; 526a653dafSJuergen Schmidt } 536a653dafSJuergen Schmidt ~ProfileAccess()546a653dafSJuergen Schmidt ProfileAccess::~ProfileAccess() 556a653dafSJuergen Schmidt { 566a653dafSJuergen Schmidt } ProfileAccess()576a653dafSJuergen Schmidt ProfileAccess::ProfileAccess() 586a653dafSJuergen Schmidt { 596a653dafSJuergen Schmidt LoadProductsInfo(); 606a653dafSJuergen Schmidt } 616a653dafSJuergen Schmidt LoadProductsInfo()626a653dafSJuergen Schmidt sal_Int32 ProfileAccess::LoadProductsInfo() 636a653dafSJuergen Schmidt { 646a653dafSJuergen Schmidt //load SeaMonkey 2 profiles to m_ProductProfileList 656a653dafSJuergen Schmidt sal_Int32 count = LoadXPToolkitProfiles(MozillaProductType_Mozilla); 666a653dafSJuergen Schmidt 676a653dafSJuergen Schmidt //load thunderbird profiles to m_ProductProfileList 686a653dafSJuergen Schmidt count += LoadXPToolkitProfiles(MozillaProductType_Thunderbird); 696a653dafSJuergen Schmidt 706a653dafSJuergen Schmidt //load firefox profiles to m_ProductProfileList 716a653dafSJuergen Schmidt //firefox profile does not containt address book, but maybe others need them 726a653dafSJuergen Schmidt count += LoadXPToolkitProfiles(MozillaProductType_Firefox); 736a653dafSJuergen Schmidt return count; 746a653dafSJuergen Schmidt } 756a653dafSJuergen Schmidt //Thunderbird and firefox profiles are saved in profiles.ini LoadXPToolkitProfiles(MozillaProductType product)766a653dafSJuergen Schmidt sal_Int32 ProfileAccess::LoadXPToolkitProfiles(MozillaProductType product) 776a653dafSJuergen Schmidt { 786a653dafSJuergen Schmidt sal_Int32 index=product; 796a653dafSJuergen Schmidt ProductStruct &m_Product = m_ProductProfileList[index]; 806a653dafSJuergen Schmidt 816a653dafSJuergen Schmidt ::rtl::OUString regDir = getRegistryDir(product); 826a653dafSJuergen Schmidt ::rtl::OUString profilesIni( regDir ); 836a653dafSJuergen Schmidt profilesIni += ::rtl::OUString::createFromAscii( "profiles.ini" ); 846a653dafSJuergen Schmidt IniParser parser( profilesIni ); 856a653dafSJuergen Schmidt IniSectionMap &mAllSection = *(parser.getAllSection()); 866a653dafSJuergen Schmidt 876a653dafSJuergen Schmidt IniSectionMap::iterator iBegin = mAllSection.begin(); 886a653dafSJuergen Schmidt IniSectionMap::iterator iEnd = mAllSection.end(); 896a653dafSJuergen Schmidt for(;iBegin != iEnd;iBegin++) 906a653dafSJuergen Schmidt { 916a653dafSJuergen Schmidt ini_Section *aSection = &(*iBegin).second; 926a653dafSJuergen Schmidt ::rtl::OUString profileName; 936a653dafSJuergen Schmidt ::rtl::OUString profilePath; 946a653dafSJuergen Schmidt ::rtl::OUString sIsRelative; 956a653dafSJuergen Schmidt ::rtl::OUString sIsDefault; 966a653dafSJuergen Schmidt 976a653dafSJuergen Schmidt for(NameValueList::iterator itor=aSection->lList.begin(); 986a653dafSJuergen Schmidt itor != aSection->lList.end(); 996a653dafSJuergen Schmidt itor++) 1006a653dafSJuergen Schmidt { 1016a653dafSJuergen Schmidt struct ini_NameValue * aValue = &(*itor); 1026a653dafSJuergen Schmidt if (aValue->sName.equals(::rtl::OUString::createFromAscii("Name"))) 1036a653dafSJuergen Schmidt { 1046a653dafSJuergen Schmidt profileName = aValue->sValue; 1056a653dafSJuergen Schmidt } 1066a653dafSJuergen Schmidt else if (aValue->sName.equals(::rtl::OUString::createFromAscii("IsRelative"))) 1076a653dafSJuergen Schmidt { 1086a653dafSJuergen Schmidt sIsRelative = aValue->sValue; 1096a653dafSJuergen Schmidt } 1106a653dafSJuergen Schmidt else if (aValue->sName.equals(::rtl::OUString::createFromAscii("Path"))) 1116a653dafSJuergen Schmidt { 1126a653dafSJuergen Schmidt profilePath = aValue->sValue; 1136a653dafSJuergen Schmidt } 1146a653dafSJuergen Schmidt else if (aValue->sName.equals(::rtl::OUString::createFromAscii("Default"))) 1156a653dafSJuergen Schmidt { 1166a653dafSJuergen Schmidt sIsDefault = aValue->sValue; 1176a653dafSJuergen Schmidt } 1186a653dafSJuergen Schmidt } 1196a653dafSJuergen Schmidt if (profileName.getLength() != 0 || profilePath.getLength() != 0) 1206a653dafSJuergen Schmidt { 1216a653dafSJuergen Schmidt sal_Int32 isRelative = 0; 1226a653dafSJuergen Schmidt if (sIsRelative.getLength() != 0) 1236a653dafSJuergen Schmidt { 1246a653dafSJuergen Schmidt isRelative = sIsRelative.toInt32(); 1256a653dafSJuergen Schmidt } 1267f7eeadaSDamjan Jovanovic if (isRelative) 1277f7eeadaSDamjan Jovanovic { 1287f7eeadaSDamjan Jovanovic // Make it absolute 1297f7eeadaSDamjan Jovanovic profilePath = regDir + profilePath; 1307f7eeadaSDamjan Jovanovic } 1316a653dafSJuergen Schmidt 1326a653dafSJuergen Schmidt ProfileStruct* profileItem = new ProfileStruct(product,profileName, 1337f7eeadaSDamjan Jovanovic profilePath); 1346a653dafSJuergen Schmidt m_Product.mProfileList[profileName] = profileItem; 1356a653dafSJuergen Schmidt 1366a653dafSJuergen Schmidt sal_Int32 isDefault = 0; 1376a653dafSJuergen Schmidt if (sIsDefault.getLength() != 0) 1386a653dafSJuergen Schmidt { 1396a653dafSJuergen Schmidt isDefault = sIsDefault.toInt32(); 1406a653dafSJuergen Schmidt } 1416a653dafSJuergen Schmidt if (isDefault) 1426a653dafSJuergen Schmidt m_Product.mCurrentProfileName = profileName; 1436a653dafSJuergen Schmidt 1446a653dafSJuergen Schmidt } 1456a653dafSJuergen Schmidt 1466a653dafSJuergen Schmidt } 1476a653dafSJuergen Schmidt return static_cast< ::sal_Int32 >(m_Product.mProfileList.size()); 1486a653dafSJuergen Schmidt } 1496a653dafSJuergen Schmidt getProfilePath(::com::sun::star::mozilla::MozillaProductType product,const::rtl::OUString & profileName)1506a653dafSJuergen Schmidt ::rtl::OUString ProfileAccess::getProfilePath( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException) 1516a653dafSJuergen Schmidt { 1526a653dafSJuergen Schmidt sal_Int32 index=product; 1536a653dafSJuergen Schmidt ProductStruct &m_Product = m_ProductProfileList[index]; 1546a653dafSJuergen Schmidt if (!m_Product.mProfileList.size() || m_Product.mProfileList.find(profileName) == m_Product.mProfileList.end()) 1556a653dafSJuergen Schmidt { 1566a653dafSJuergen Schmidt //Profile not found 1576a653dafSJuergen Schmidt return ::rtl::OUString(); 1586a653dafSJuergen Schmidt } 1596a653dafSJuergen Schmidt else 1606a653dafSJuergen Schmidt return m_Product.mProfileList[profileName]->getProfilePath(); 1616a653dafSJuergen Schmidt } 1626a653dafSJuergen Schmidt getProfileCount(::com::sun::star::mozilla::MozillaProductType product)1636a653dafSJuergen Schmidt ::sal_Int32 ProfileAccess::getProfileCount( ::com::sun::star::mozilla::MozillaProductType product) throw (::com::sun::star::uno::RuntimeException) 1646a653dafSJuergen Schmidt { 1656a653dafSJuergen Schmidt sal_Int32 index=product; 1666a653dafSJuergen Schmidt ProductStruct &m_Product = m_ProductProfileList[index]; 1676a653dafSJuergen Schmidt return static_cast< ::sal_Int32 >(m_Product.mProfileList.size()); 1686a653dafSJuergen Schmidt } getProfileList(::com::sun::star::mozilla::MozillaProductType product,::com::sun::star::uno::Sequence<::rtl::OUString> & list)1696a653dafSJuergen 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) 1706a653dafSJuergen Schmidt { 1716a653dafSJuergen Schmidt sal_Int32 index=product; 1726a653dafSJuergen Schmidt ProductStruct &m_Product = m_ProductProfileList[index]; 1736a653dafSJuergen Schmidt list.realloc(static_cast<sal_Int32>(m_Product.mProfileList.size())); 1746a653dafSJuergen Schmidt sal_Int32 i=0; 1756a653dafSJuergen Schmidt for(ProfileList::iterator itor=m_Product.mProfileList.begin(); 1766a653dafSJuergen Schmidt itor != m_Product.mProfileList.end(); 1776a653dafSJuergen Schmidt itor++) 1786a653dafSJuergen Schmidt { 1796a653dafSJuergen Schmidt ProfileStruct * aProfile = (*itor).second; 1806a653dafSJuergen Schmidt list[i] = aProfile->getProfileName(); 1816a653dafSJuergen Schmidt i++; 1826a653dafSJuergen Schmidt } 1836a653dafSJuergen Schmidt 1846a653dafSJuergen Schmidt return static_cast< ::sal_Int32 >(m_Product.mProfileList.size()); 1856a653dafSJuergen Schmidt } 1866a653dafSJuergen Schmidt getDefaultProfile(::com::sun::star::mozilla::MozillaProductType product)1876a653dafSJuergen Schmidt ::rtl::OUString ProfileAccess::getDefaultProfile( ::com::sun::star::mozilla::MozillaProductType product ) throw (::com::sun::star::uno::RuntimeException) 1886a653dafSJuergen Schmidt { 1896a653dafSJuergen Schmidt sal_Int32 index=product; 1906a653dafSJuergen Schmidt ProductStruct &m_Product = m_ProductProfileList[index]; 1916a653dafSJuergen Schmidt if (m_Product.mCurrentProfileName.getLength() != 0) 1926a653dafSJuergen Schmidt { 193*30acf5e8Spfg //default profile set in mozilla registry 1946a653dafSJuergen Schmidt return m_Product.mCurrentProfileName; 1956a653dafSJuergen Schmidt } 1966a653dafSJuergen Schmidt if (m_Product.mProfileList.size() == 0) 1976a653dafSJuergen Schmidt { 1986a653dafSJuergen Schmidt //there are not any profiles 1996a653dafSJuergen Schmidt return ::rtl::OUString(); 2006a653dafSJuergen Schmidt } 2016a653dafSJuergen Schmidt ProfileStruct * aProfile = (*m_Product.mProfileList.begin()).second; 2026a653dafSJuergen Schmidt return aProfile->getProfileName(); 2036a653dafSJuergen Schmidt } 2046a653dafSJuergen Schmidt isProfileLocked(::com::sun::star::mozilla::MozillaProductType product,const::rtl::OUString & profileName)2056a653dafSJuergen Schmidt ::sal_Bool ProfileAccess::isProfileLocked( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException) 2066a653dafSJuergen Schmidt { 2076a653dafSJuergen Schmidt (void)product; /* avoid warning about unused parameter */ 2086a653dafSJuergen Schmidt (void)profileName; /* avoid warning about unused parameter */ 2096a653dafSJuergen Schmidt return sal_True; 2106a653dafSJuergen Schmidt } 2116a653dafSJuergen Schmidt getProfileExists(::com::sun::star::mozilla::MozillaProductType product,const::rtl::OUString & profileName)2126a653dafSJuergen Schmidt ::sal_Bool ProfileAccess::getProfileExists( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException) 2136a653dafSJuergen Schmidt { 2146a653dafSJuergen Schmidt sal_Int32 index=product; 2156a653dafSJuergen Schmidt ProductStruct &m_Product = m_ProductProfileList[index]; 2166a653dafSJuergen Schmidt if (!m_Product.mProfileList.size() || m_Product.mProfileList.find(profileName) == m_Product.mProfileList.end()) 2176a653dafSJuergen Schmidt { 2186a653dafSJuergen Schmidt return sal_False; 2196a653dafSJuergen Schmidt } 2206a653dafSJuergen Schmidt else 2216a653dafSJuergen Schmidt return sal_True; 2226a653dafSJuergen Schmidt } 2236a653dafSJuergen Schmidt } 2246a653dafSJuergen Schmidt } 225