Repository.mk | 1 connectivity/Executable_mork_helper.mk | 29 ++ connectivity/Library_mork.mk | 4 connectivity/Module_connectivity.mk | 1 connectivity/source/drivers/mork/MDriver.cxx | 4 connectivity/source/drivers/mork/MDriver.hxx | 16 - connectivity/source/drivers/mork/MNSFolders.cxx | 156 +++++++++++ connectivity/source/drivers/mork/MNSFolders.hxx | 34 ++ connectivity/source/drivers/mork/MNSINIParser.cxx | 103 +++++++ connectivity/source/drivers/mork/MNSINIParser.hxx | 74 +++++ connectivity/source/drivers/mork/MNSProfileDiscover.cxx | 224 ++++++++++++++++ connectivity/source/drivers/mork/MNSProfileDiscover.hxx | 96 ++++++ connectivity/source/drivers/mork/mork_helper.cxx | 9 13 files changed, 746 insertions(+), 5 deletions(-)
New commits: commit 8950f9ffeed6cecbcfc9996bc01c7d6a9025d866 Author: David Ostrovsky <da...@ostrovsky.org> Date: Tue Jul 24 23:16:47 2012 +0200 mork driver: more files added Change-Id: Ia4e3e0be9426c785b8d25a968111b153ca45f363 diff --git a/Repository.mk b/Repository.mk index f689f5a..e4142c1 100644 --- a/Repository.mk +++ b/Repository.mk @@ -43,6 +43,7 @@ $(eval $(call gb_Helper_register_executables,NONE, \ idxdict \ lngconvex \ localize \ + mork_helper \ mkunroll \ osl_process_child \ pdf2xml \ diff --git a/connectivity/Executable_mork_helper.mk b/connectivity/Executable_mork_helper.mk new file mode 100644 index 0000000..90c06e4 --- /dev/null +++ b/connectivity/Executable_mork_helper.mk @@ -0,0 +1,29 @@ +# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*- +# +# 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/. +# + +$(eval $(call gb_Executable_Executable,mork_helper)) + +# hack, how to do it right? +$(eval $(call gb_Executable_set_include,mork_helper,\ + -I$(SRCDIR)/connectivity/source/inc \ + -I$(SRCDIR)/solver/unxlngx6.pro/inc/offapi \ + $$(INCLUDE) \ +)) + +$(eval $(call gb_Executable_use_sdk_api,mozbootstrap)) + +$(eval $(call gb_Executable_use_libraries,mork_helper,\ + mork \ +)) + +$(eval $(call gb_Executable_add_exception_objects,mork_helper,\ + connectivity/source/drivers/mork/mork_helper \ +)) + +# vim:set shiftwidth=4 softtabstop=4 expandtab: diff --git a/connectivity/Library_mork.mk b/connectivity/Library_mork.mk index 85e0f81..4a6621f 100644 --- a/connectivity/Library_mork.mk +++ b/connectivity/Library_mork.mk @@ -20,12 +20,16 @@ $(eval $(call gb_Library_use_libraries,mork, \ cppu \ cppuhelper \ sal \ + dbtools \ $(gb_STDLIBS) \ )) $(eval $(call gb_Library_use_sdk_api,mork)) $(eval $(call gb_Library_add_exception_objects,mork, \ + connectivity/source/drivers/mork/MNSFolders \ + connectivity/source/drivers/mork/MNSINIParser \ + connectivity/source/drivers/mork/MNSProfileDiscover \ connectivity/source/drivers/mork/MorkParser \ connectivity/source/drivers/mork/MDriver \ connectivity/source/drivers/mork/MConnection \ diff --git a/connectivity/Module_connectivity.mk b/connectivity/Module_connectivity.mk index a438066..c3d7c2d 100644 --- a/connectivity/Module_connectivity.mk +++ b/connectivity/Module_connectivity.mk @@ -38,6 +38,7 @@ $(eval $(call gb_Module_add_targets,connectivity,\ Configuration_flat \ Configuration_mysql \ Configuration_odbc \ + Executable_mork_helper \ Library_calc \ Library_dbase \ Library_dbpool2 \ diff --git a/connectivity/source/drivers/mork/MDriver.cxx b/connectivity/source/drivers/mork/MDriver.cxx index 7c73eef..1bc336d 100644 --- a/connectivity/source/drivers/mork/MDriver.cxx +++ b/connectivity/source/drivers/mork/MDriver.cxx @@ -9,8 +9,10 @@ #include "MDriver.hxx" #include "MConnection.hxx" +#include "MNSProfileDiscover.hxx" using namespace connectivity::mork; +using namespace connectivity::mozab; namespace connectivity { @@ -26,6 +28,7 @@ namespace connectivity MorkDriver::MorkDriver(css::uno::Reference< css::uno::XComponentContext > const context): context_(context) { + m_ProfileAccess = new ProfileAccess(); assert(context.is()); } @@ -73,7 +76,6 @@ css::uno::Reference< css::sdbc::XConnection > MorkDriver::connect( css::uno::Sequence< css::beans::PropertyValue > const & info) throw (css::sdbc::SQLException, css::uno::RuntimeException) { - //... TODO (void) url; (void) info; // avoid warnings // return static_cast< cppu::OWeakObject * >(new MConnection(this)); return NULL; diff --git a/connectivity/source/drivers/mork/MDriver.hxx b/connectivity/source/drivers/mork/MDriver.hxx index 08ecf46..74bb556 100644 --- a/connectivity/source/drivers/mork/MDriver.hxx +++ b/connectivity/source/drivers/mork/MDriver.hxx @@ -40,14 +40,20 @@ namespace com { namespace sun { namespace star { } } } namespace rtl { class OUString; } +namespace connectivity +{ + namespace mozab + { + class ProfileAccess; + } +} + namespace connectivity { namespace mork { namespace css = com::sun::star; -com::sun::star::uno::Reference< com::sun::star::uno::XInterface > SAL_CALL -create( - com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext > - const &); +css::uno::Reference< css::uno::XInterface > SAL_CALL +create(css::uno::Reference< css::uno::XComponentContext > const &); class MorkDriver: public cppu::WeakImplHelper2< css::lang::XServiceInfo, css::sdbc::XDriver >, @@ -60,6 +66,8 @@ public: static css::uno::Sequence< ::rtl::OUString > getSupportedServiceNames_Static() throw (css::uno::RuntimeException); private: + + connectivity::mozab::ProfileAccess* m_ProfileAccess; virtual ~MorkDriver() {} virtual rtl::OUString SAL_CALL getImplementationName() diff --git a/connectivity/source/drivers/mork/MNSFolders.cxx b/connectivity/source/drivers/mork/MNSFolders.cxx new file mode 100644 index 0000000..e0da768 --- /dev/null +++ b/connectivity/source/drivers/mork/MNSFolders.cxx @@ -0,0 +1,156 @@ +/* -*- 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 <MNSFolders.hxx> + +#ifdef UNIX +#include <sys/types.h> +#include <strings.h> +#include <string.h> +#endif // End UNIX + +#ifdef WNT +#include "pre_include_windows.h" +#include <windows.h> +#include <stdlib.h> +#include <shlobj.h> +#include <objidl.h> +#include "post_include_windows.h" +#endif // End WNT +#include <osl/security.hxx> +#include <osl/file.hxx> +#include <osl/thread.h> + +using namespace ::com::sun::star::mozilla; + +namespace +{ + // ------------------------------------------------------------------- + static ::rtl::OUString lcl_getUserDataDirectory() + { + ::osl::Security aSecurity; + ::rtl::OUString aConfigPath; + + #if defined(XP_WIN) || defined(MACOSX) + aSecurity.getConfigDir( aConfigPath ); + #else + //This is to find the dir under which .mozilla/.thunderbird is created. + //mozilla doesn't honour XDG_CONFIG_HOME, so raw home dir required here + //not xdg-config dir + aSecurity.getHomeDir( aConfigPath ); + #endif + + return aConfigPath + ::rtl::OUString("/"); + } + + // ------------------------------------------------------------------- + const size_t NB_PRODUCTS = 3; + const size_t NB_CANDIDATES = 4; + + static const char* DefaultProductDir[NB_PRODUCTS][NB_CANDIDATES] = + { + #if defined(XP_WIN) + { "Mozilla/SeaMonkey/", NULL, NULL, NULL }, + { "Mozilla/Firefox/", NULL, NULL, NULL }, + { "Thunderbird/", "Mozilla/Thunderbird/", NULL, NULL } + #elif(MACOSX) + { "../Mozilla/SeaMonkey/", NULL, NULL, NULL }, + { "Firefox/", NULL, NULL, NULL }, + { "../Thunderbird/", NULL, NULL, NULL } + #else + { ".mozilla/seamonkey/", NULL, NULL, NULL }, + { ".mozilla/firefox/", NULL, NULL, NULL }, + { ".thunderbird/", ".mozilla-thunderbird/", ".mozilla/thunderbird/", ".icedove" } + #endif + }; + + static const char* ProductRootEnvironmentVariable[NB_PRODUCTS] = + { + "MOZILLA_PROFILE_ROOT", + "MOZILLA_FIREFOX_PROFILE_ROOT", + "MOZILLA_THUNDERBIRD_PROFILE_ROOT", + }; + + // ------------------------------------------------------------------- + static ::rtl::OUString lcl_guessProfileRoot( MozillaProductType _product ) + { + size_t productIndex = _product - 1; + + static ::rtl::OUString s_productDirectories[NB_PRODUCTS]; + + if ( s_productDirectories[ productIndex ].isEmpty() ) + { + ::rtl::OUString sProductPath; + + // check whether we have an anevironment variable which helps us + const char* pProfileByEnv = getenv( ProductRootEnvironmentVariable[ productIndex ] ); + if ( pProfileByEnv ) + { + sProductPath = ::rtl::OUString( pProfileByEnv, rtl_str_getLength( pProfileByEnv ), osl_getThreadTextEncoding() ); + // asume that this is fine, no further checks + } + else + { + ::rtl::OUString sProductDirCandidate; + const char* pProfileRegistry = "profiles.ini"; + + // check all possible candidates + for ( size_t i=0; i<NB_CANDIDATES; ++i ) + { + if ( NULL == DefaultProductDir[ productIndex ][ i ] ) + break; + + sProductDirCandidate = lcl_getUserDataDirectory() + + ::rtl::OUString::createFromAscii( DefaultProductDir[ productIndex ][ i ] ); + + // check existence + ::osl::DirectoryItem aRegistryItem; + ::osl::FileBase::RC result = ::osl::DirectoryItem::get( sProductDirCandidate + ::rtl::OUString::createFromAscii( pProfileRegistry ), aRegistryItem ); + if ( result == ::osl::FileBase::E_None ) + { + ::osl::FileStatus aStatus( osl_FileStatus_Mask_Validate ); + result = aRegistryItem.getFileStatus( aStatus ); + if ( result == ::osl::FileBase::E_None ) + { + // the registry file exists + break; + } + } + } + + ::osl::FileBase::getSystemPathFromFileURL( sProductDirCandidate, sProductPath ); + } + + s_productDirectories[ productIndex ] = sProductPath; + } + + return s_productDirectories[ productIndex ]; + } +} + +// ----------------------------------------------------------------------- +::rtl::OUString getRegistryDir(MozillaProductType product) +{ + if (product == MozillaProductType_Default) + return ::rtl::OUString(); + + return lcl_guessProfileRoot( product ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MNSFolders.hxx b/connectivity/source/drivers/mork/MNSFolders.hxx new file mode 100644 index 0000000..609d0ea --- /dev/null +++ b/connectivity/source/drivers/mork/MNSFolders.hxx @@ -0,0 +1,34 @@ +/* -*- 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 . + */ + +#ifndef _MNSFOLDERS_HXX_ +#define _MNSFOLDERS_HXX_ + +#include <sal/types.h> +#include <osl/diagnose.h> +#include <osl/conditn.hxx> +#include <com/sun/star/mozilla/MozillaProductType.hpp> + +#include <rtl/ustring.hxx> + +::rtl::OUString getRegistryDir(::com::sun::star::mozilla::MozillaProductType product); + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MNSINIParser.cxx b/connectivity/source/drivers/mork/MNSINIParser.cxx new file mode 100644 index 0000000..55e57f5 --- /dev/null +++ b/connectivity/source/drivers/mork/MNSINIParser.cxx @@ -0,0 +1,103 @@ +/* -*- 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 <MNSINIParser.hxx> +#include <rtl/byteseq.hxx> + +IniParser::IniParser(OUString const & rIniName) throw(com::sun::star::io::IOException ) +{ + OUString iniUrl; + if (osl_File_E_None != osl_getFileURLFromSystemPath(rIniName.pData, &iniUrl.pData)) + return; + + +#if OSL_DEBUG_LEVEL > 0 + OString sFile = OUStringToOString(iniUrl, RTL_TEXTENCODING_ASCII_US); + OSL_TRACE(__FILE__" -- parser() - %s\n", sFile.getStr()); +#endif + oslFileHandle handle=NULL; + oslFileError fileError = osl_File_E_INVAL; + try{ + if (!iniUrl.isEmpty()) + fileError = osl_openFile(iniUrl.pData, &handle, osl_File_OpenFlag_Read); + } + catch(const ::com::sun::star::io::IOException&) + { +#if OSL_DEBUG_LEVEL > 0 + OString file_tmp = OUStringToOString(iniUrl, RTL_TEXTENCODING_ASCII_US); + OSL_TRACE( __FILE__" -- couldn't open file: %s", file_tmp.getStr() ); +#endif + } + + if (osl_File_E_None == fileError) + { + rtl::ByteSequence seq; + sal_uInt64 nSize = 0; + + osl_getFileSize(handle, &nSize); + OUString sectionName( "no name section" ); + while (true) + { + sal_uInt64 nPos; + if (osl_File_E_None != osl_getFilePos(handle, &nPos) || nPos >= nSize) + break; + if (osl_File_E_None != osl_readLine(handle , (sal_Sequence **) &seq)) + break; + OString line( (const sal_Char *) seq.getConstArray(), seq.getLength() ); + sal_Int32 nIndex = line.indexOf('='); + if (nIndex >= 1) + { + ini_Section *aSection = &mAllSection[sectionName]; + struct ini_NameValue nameValue; + nameValue.sName = OStringToOUString( + line.copy(0,nIndex).trim(), RTL_TEXTENCODING_ASCII_US ); + nameValue.sValue = OStringToOUString( + line.copy(nIndex+1).trim(), RTL_TEXTENCODING_UTF8 ); + + aSection->lList.push_back(nameValue); + + } + else + { + sal_Int32 nIndexStart = line.indexOf('['); + sal_Int32 nIndexEnd = line.indexOf(']'); + if ( nIndexEnd > nIndexStart && nIndexStart >=0) + { + sectionName = OStringToOUString( + line.copy(nIndexStart + 1,nIndexEnd - nIndexStart -1).trim(), RTL_TEXTENCODING_ASCII_US ); + if (sectionName.isEmpty()) + sectionName = OUString("no name section"); + + ini_Section *aSection = &mAllSection[sectionName]; + aSection->sName = sectionName; + } + } + } + osl_closeFile(handle); + } +#if OSL_DEBUG_LEVEL > 0 + else + { + OString file_tmp = OUStringToOString(iniUrl, RTL_TEXTENCODING_ASCII_US); + OSL_TRACE( __FILE__" -- couldn't open file: %s", file_tmp.getStr() ); + } +#endif +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MNSINIParser.hxx b/connectivity/source/drivers/mork/MNSINIParser.hxx new file mode 100644 index 0000000..e6941bc --- /dev/null +++ b/connectivity/source/drivers/mork/MNSINIParser.hxx @@ -0,0 +1,74 @@ +/* -*- 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 . + */ +#ifndef __MNSINIPARSER_HXX__ +#define __MNSINIPARSER_HXX__ + +#include <rtl/ustring.hxx> +#include <com/sun/star/io/IOException.hpp> +#include <osl/process.h> + +#include <map> +#include <list> + +#if OSL_DEBUG_LEVEL > 0 +#include <stdio.h> +#endif + +using ::rtl::OUString; +using ::rtl::OString; + +struct ini_NameValue +{ + rtl::OUString sName; + rtl::OUString sValue; + + inline ini_NameValue() SAL_THROW(()) + {} + inline ini_NameValue( + OUString const & name, OUString const & value ) SAL_THROW(()) + : sName( name ), + sValue( value ) + {} +}; + +typedef std::list< + ini_NameValue +> NameValueList; + +struct ini_Section +{ + rtl::OUString sName; + NameValueList lList; +}; +typedef std::map<rtl::OUString, + ini_Section + >IniSectionMap; + + +class IniParser +{ + IniSectionMap mAllSection; +public: + IniSectionMap * getAllSection(){return &mAllSection;}; + IniParser(OUString const & rIniName) throw(com::sun::star::io::IOException); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/MNSProfileDiscover.cxx b/connectivity/source/drivers/mork/MNSProfileDiscover.cxx new file mode 100644 index 0000000..ec9eb0a --- /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 mozab + { + 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: */ diff --git a/connectivity/source/drivers/mork/MNSProfileDiscover.hxx b/connectivity/source/drivers/mork/MNSProfileDiscover.hxx new file mode 100644 index 0000000..ce9865e --- /dev/null +++ b/connectivity/source/drivers/mork/MNSProfileDiscover.hxx @@ -0,0 +1,96 @@ +/* -*- 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 . + */ + +#ifndef __MNSProfileDiscover_h___ +#define __MNSProfileDiscover_h___ + +#include <sal/types.h> +#include <osl/diagnose.h> +#include <osl/conditn.hxx> +#include <com/sun/star/mozilla/MozillaProductType.hpp> +#include <com/sun/star/uno/RuntimeException.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <rtl/ustring.hxx> + +#include <vector> +#include <map> + +using namespace com::sun::star::mozilla; +namespace connectivity +{ + namespace mozab + { + class ProfileStruct; + } +} +typedef ::std::map < ::rtl::OUString, ::connectivity::mozab::ProfileStruct* > ProfileList; +namespace connectivity +{ + namespace mozab + { + class ProfileStruct + { + public: + ProfileStruct(MozillaProductType aProduct,::rtl::OUString aProfileName, + const ::rtl::OUString &aProfilePath + ); + MozillaProductType getProductType() { return product;} + ::rtl::OUString getProfileName(){ return profileName;} + ::rtl::OUString getProfilePath() ; + protected: + MozillaProductType product; + ::rtl::OUString profileName; + ::rtl::OUString profilePath; + }; + + class ProductStruct + { + public: + void setCurrentProfile(::rtl::OUString aProfileName){mCurrentProfileName = aProfileName;} + + ::rtl::OUString mCurrentProfileName; + + ProfileList mProfileList; + }; + + //Used to query profiles information + class ProfileAccess + { + public: + + virtual ~ProfileAccess(); + ProfileAccess(); + ::rtl::OUString getProfilePath( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException); + ::sal_Int32 getProfileCount( ::com::sun::star::mozilla::MozillaProductType product ) throw (::com::sun::star::uno::RuntimeException); + ::sal_Int32 getProfileList( ::com::sun::star::mozilla::MozillaProductType product, ::com::sun::star::uno::Sequence< ::rtl::OUString >& list ) throw (::com::sun::star::uno::RuntimeException); + ::rtl::OUString getDefaultProfile( ::com::sun::star::mozilla::MozillaProductType product ) throw (::com::sun::star::uno::RuntimeException); + ::sal_Bool SAL_CALL isProfileLocked( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException); + ::sal_Bool SAL_CALL getProfileExists( ::com::sun::star::mozilla::MozillaProductType product, const ::rtl::OUString& profileName ) throw (::com::sun::star::uno::RuntimeException); + protected: + ProductStruct m_ProductProfileList[4]; + sal_Int32 LoadProductsInfo(); + sal_Int32 LoadXPToolkitProfiles(MozillaProductType product); + }; + + } +} + +#endif // __MNSProfileDiscover_h___ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/connectivity/source/drivers/mork/mork_helper.cxx b/connectivity/source/drivers/mork/mork_helper.cxx new file mode 100644 index 0000000..9853d8c --- /dev/null +++ b/connectivity/source/drivers/mork/mork_helper.cxx @@ -0,0 +1,9 @@ +#include "MNSProfileDiscover.hxx" + +using namespace connectivity::mozab; + +int main( int argc, const char* argv[] ) +{ + ProfileAccess* access = new ProfileAccess(); + ::rtl::OUString profile = access->getDefaultProfile(::com::sun::star::mozilla::MozillaProductType_Thunderbird); +} _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits