summaryrefslogtreecommitdiff
path: root/connectivity/source/drivers/mork/MNSProfileDiscover.cxx
diff options
context:
space:
mode:
authorDavid Ostrovsky <david@ostrovsky.org>2012-09-17 22:50:49 +0200
committerMiklos Vajna <vmiklos@suse.cz>2012-09-18 08:30:01 +0000
commit77e4adbe4759f21f6cf095d954391a9ddbbec2cf (patch)
treeeb124e090a1b9029cdb34f122a2b0ed557603ce5 /connectivity/source/drivers/mork/MNSProfileDiscover.cxx
parenta60c63fd66a5a2069ea812f94c000dc4273e8ceb (diff)
mork driver implementation
This is a preparation for merge into master, feature/mork branch is obsoslete and shouldn't be used any more. In context of this change the usage of old mozilla based mork driver depends on platform: all non windows platforms use this new mork driver, windows still uses mozilla. Because mozilla driver shipping was stripped on feature/mork branch for all platforms, the corresponding commits were changed prior to creating this change (the build file changes are reverted now). So the build and shipping of different mork driver implementation should be implemented from scratch: mozilla on windows, new mork dirver on all other platforms. Currently the new mork dirver is compiled (on all platforms), but not used. It can be tested with mork_helper executable. fdo#51004 Change-Id: Ib2413ab6856f163337aa311c4bf7b1182d6c6f63 Reviewed-on: https://gerrit.libreoffice.org/635 Reviewed-by: Miklos Vajna <vmiklos@suse.cz> Tested-by: Miklos Vajna <vmiklos@suse.cz>
Diffstat (limited to 'connectivity/source/drivers/mork/MNSProfileDiscover.cxx')
-rw-r--r--connectivity/source/drivers/mork/MNSProfileDiscover.cxx224
1 files changed, 224 insertions, 0 deletions
diff --git a/connectivity/source/drivers/mork/MNSProfileDiscover.cxx b/connectivity/source/drivers/mork/MNSProfileDiscover.cxx
new file mode 100644
index 000000000000..014e17cc89e9
--- /dev/null
+++ b/connectivity/source/drivers/mork/MNSProfileDiscover.cxx
@@ -0,0 +1,224 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include "MNSProfileDiscover.hxx"
+
+#ifndef MAXPATHLEN
+#define MAXPATHLEN 1024
+#endif
+#include <MNSFolders.hxx>
+#include <MNSINIParser.hxx>
+
+namespace connectivity
+{
+ namespace mork
+ {
+ ProfileStruct::ProfileStruct(MozillaProductType aProduct,::rtl::OUString aProfileName,
+ const ::rtl::OUString& aProfilePath
+ )
+ {
+ product=aProduct;
+ profileName = aProfileName;
+ profilePath = aProfilePath;
+ }
+ ::rtl::OUString ProfileStruct::getProfilePath()
+ {
+ return profilePath;
+ }
+
+ ProfileAccess::~ProfileAccess()
+ {
+ }
+ ProfileAccess::ProfileAccess()
+ {
+ LoadProductsInfo();
+ }
+
+ sal_Int32 ProfileAccess::LoadProductsInfo()
+ {
+ //load SeaMonkey 2 profiles to m_ProductProfileList
+ sal_Int32 count = LoadXPToolkitProfiles(MozillaProductType_Mozilla);
+
+ //load thunderbird profiles to m_ProductProfileList
+ count += LoadXPToolkitProfiles(MozillaProductType_Thunderbird);
+
+ //load firefox profiles to m_ProductProfileList
+ //firefox profile does not containt address book, but maybe others need them
+ count += LoadXPToolkitProfiles(MozillaProductType_Firefox);
+ return count;
+ }
+ //Thunderbird and firefox profiles are saved in profiles.ini
+ sal_Int32 ProfileAccess::LoadXPToolkitProfiles(MozillaProductType product)
+ {
+ sal_Int32 index=product;
+ ProductStruct &m_Product = m_ProductProfileList[index];
+
+ ::rtl::OUString regDir = getRegistryDir(product);
+ ::rtl::OUString profilesIni( regDir );
+ profilesIni += ::rtl::OUString("profiles.ini");
+ IniParser parser( profilesIni );
+ IniSectionMap &mAllSection = *(parser.getAllSection());
+
+ IniSectionMap::iterator iBegin = mAllSection.begin();
+ IniSectionMap::iterator iEnd = mAllSection.end();
+ for(;iBegin != iEnd;++iBegin)
+ {
+ ini_Section *aSection = &(*iBegin).second;
+ ::rtl::OUString profileName;
+ ::rtl::OUString profilePath;
+ ::rtl::OUString sIsRelative;
+ ::rtl::OUString sIsDefault;
+
+ for(NameValueList::iterator itor=aSection->lList.begin();
+ itor != aSection->lList.end();
+ ++itor)
+ {
+ struct ini_NameValue * aValue = &(*itor);
+ if ( aValue->sName == "Name" )
+ {
+ profileName = aValue->sValue;
+ }
+ else if ( aValue->sName == "IsRelative" )
+ {
+ sIsRelative = aValue->sValue;
+ }
+ else if ( aValue->sName == "Path" )
+ {
+ profilePath = aValue->sValue;
+ }
+ else if ( aValue->sName == "Default" )
+ {
+ sIsDefault = aValue->sValue;
+ }
+ }
+ if (!(profileName.isEmpty() && profilePath.isEmpty()))
+ {
+ sal_Int32 isRelative = 0;
+ if (!sIsRelative.isEmpty())
+ {
+ isRelative = sIsRelative.toInt32();
+ }
+
+ rtl::OUString fullProfilePath;
+ if(isRelative)
+ {
+ fullProfilePath = regDir + profilePath;
+ }
+ else
+ {
+ fullProfilePath = profilePath;
+ }
+
+ ProfileStruct* profileItem = new ProfileStruct(product,profileName,
+ fullProfilePath
+ );
+ m_Product.mProfileList[profileName] = profileItem;
+
+ sal_Int32 isDefault = 0;
+ if (!sIsDefault.isEmpty())
+ {
+ isDefault = sIsDefault.toInt32();
+ }
+ if (isDefault)
+ m_Product.mCurrentProfileName = profileName;
+
+ }
+
+ }
+ return static_cast< ::sal_Int32 >(m_Product.mProfileList.size());
+ }
+
+ ::rtl::OUString ProfileAccess::getProfilePath( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
+ {
+ sal_Int32 index=product;
+ ProductStruct &m_Product = m_ProductProfileList[index];
+ if (!m_Product.mProfileList.size() || m_Product.mProfileList.find(profileName) == m_Product.mProfileList.end())
+ {
+ //Profile not found
+ return ::rtl::OUString();
+ }
+ else
+ return m_Product.mProfileList[profileName]->getProfilePath();
+ }
+
+ ::sal_Int32 ProfileAccess::getProfileCount( ::com::sun::star::mozilla::MozillaProductType product) throw (::com::sun::star::uno::RuntimeException)
+ {
+ sal_Int32 index=product;
+ ProductStruct &m_Product = m_ProductProfileList[index];
+ return static_cast< ::sal_Int32 >(m_Product.mProfileList.size());
+ }
+ ::sal_Int32 ProfileAccess::getProfileList( ::com::sun::star::mozilla::MozillaProductType product, ::com::sun::star::uno::Sequence< ::rtl::OUString >& list ) throw (::com::sun::star::uno::RuntimeException)
+ {
+ sal_Int32 index=product;
+ ProductStruct &m_Product = m_ProductProfileList[index];
+ list.realloc(static_cast<sal_Int32>(m_Product.mProfileList.size()));
+ sal_Int32 i=0;
+ for(ProfileList::iterator itor=m_Product.mProfileList.begin();
+ itor != m_Product.mProfileList.end();
+ ++itor)
+ {
+ ProfileStruct * aProfile = (*itor).second;
+ list[i] = aProfile->getProfileName();
+ i++;
+ }
+
+ return static_cast< ::sal_Int32 >(m_Product.mProfileList.size());
+ }
+
+ ::rtl::OUString ProfileAccess::getDefaultProfile( ::com::sun::star::mozilla::MozillaProductType product ) throw (::com::sun::star::uno::RuntimeException)
+ {
+ sal_Int32 index=product;
+ ProductStruct &m_Product = m_ProductProfileList[index];
+ if (!m_Product.mCurrentProfileName.isEmpty())
+ {
+ //default profile setted in mozilla registry
+ return m_Product.mCurrentProfileName;
+ }
+ if (m_Product.mProfileList.empty())
+ {
+ //there are not any profiles
+ return ::rtl::OUString();
+ }
+ ProfileStruct * aProfile = (*m_Product.mProfileList.begin()).second;
+ return aProfile->getProfileName();
+ }
+ ::sal_Bool ProfileAccess::isProfileLocked( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
+ {
+ (void)product; /* avoid warning about unused parameter */
+ (void)profileName; /* avoid warning about unused parameter */
+ return sal_True;
+ }
+
+ ::sal_Bool ProfileAccess::getProfileExists( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException)
+ {
+ sal_Int32 index=product;
+ ProductStruct &m_Product = m_ProductProfileList[index];
+ if (!m_Product.mProfileList.size() || m_Product.mProfileList.find(profileName) == m_Product.mProfileList.end())
+ {
+ return sal_False;
+ }
+ else
+ return sal_True;
+ }
+ }
+}
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */