merge the formfield patch from ooo-build
[ooovba.git] / connectivity / source / drivers / mozab / bootstrap / MNSProfileManager.cxx
blob67d405915e87ea3741d0c4ede67030a925f435c8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MNSProfileManager.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
34 #include "MNSProfileManager.hxx"
35 #include "MNSProfile.hxx"
37 #ifndef MAXPATHLEN
38 #define MAXPATHLEN 1024
39 #endif
40 #include <MNSFolders.hxx>
41 #include <MNSINIParser.hxx>
43 static ::sal_Int32 nInitCounter=0;
44 namespace connectivity
46 namespace mozab
49 ProfileManager::~ProfileManager()
52 ProfileManager::ProfileManager()
53 :m_CurrentProduct(MozillaProductType_Mozilla)
54 ,aProfile(NULL)
57 ::sal_Int32 ProfileManager::bootupProfile( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
59 if (!aProfile)
61 aProfile=new nsProfile();
62 aProfile->StartupWithArgs(NULL,sal_False);
65 setCurrentProfile(product,profileName);
66 return ++nInitCounter;
68 ::sal_Int32 ProfileManager::shutdownProfile( ) throw (::com::sun::star::uno::RuntimeException)
70 return --nInitCounter;
72 ::com::sun::star::mozilla::MozillaProductType ProfileManager::getCurrentProduct( ) throw (::com::sun::star::uno::RuntimeException)
74 return m_CurrentProduct;
76 ::rtl::OUString ProfileManager::getCurrentProfile( ) throw (::com::sun::star::uno::RuntimeException)
78 nsresult rv;
79 nsCOMPtr<nsIProfile> theProfile(do_GetService(NS_PROFILE_CONTRACTID,&rv));
80 if (NS_FAILED(rv)) return ::rtl::OUString();
81 nsXPIDLString currentProfileStr;
82 //call GetCurrentProfile before call SetCurrentProfile will get the default profile
83 rv = theProfile->GetCurrentProfile(getter_Copies(currentProfileStr));
84 if (NS_FAILED(rv) || currentProfileStr.get() == nsnull)
85 return ::rtl::OUString();
86 // PRUnichar != sal_Unicode in mingw
87 return ::rtl::OUString(reinterpret_cast_mingw_only<const sal_Unicode *>(currentProfileStr.get()));
89 ::rtl::OUString ProfileManager::setCurrentProfile( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
91 ::rtl::OUString currentProfile = getCurrentProfile();
92 //if profileName not given, then skip and return curernt profile
93 if (!profileName.getLength() && m_CurrentProduct == product)
94 return currentProfile;
96 if (m_CurrentProduct == product && profileName.equals(currentProfile))
97 return currentProfile;
98 //set current product
99 m_CurrentProduct = product;
101 //get profile mozilla profile service
102 nsresult rv;
103 nsCOMPtr<nsIProfile> theProfile(do_GetService(NS_PROFILE_CONTRACTID,&rv));
104 if (NS_FAILED(rv)) return ::rtl::OUString();
106 // PRUnichar != sal_Unicode in mingw
107 const PRUnichar* pUsedProfile = reinterpret_cast_mingw_only<const PRUnichar *>(profileName.getStr());
108 //set current profile
109 rv = theProfile->SetCurrentProfile( pUsedProfile );
110 if (NS_FAILED(rv)) return ::rtl::OUString();
111 return currentProfile;