Tag: cws_src680_kabrefine User: fs Date: 06/01/06 07:09:28 Modified: /dba/connectivity/source/drivers/kab/ KDEInit.cxx, KDEInit.h, KDriver.cxx, KDriver.hxx, kabdrv.map
Log: add a maximum supported version (not finished, yet) File Changes: Directory: /dba/connectivity/source/drivers/kab/ ================================================ File [changed]: KDEInit.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/kab/KDEInit.cxx?r1=1.1.2.5&r2=1.1.2.6 Delta lines: +23 -19 --------------------- --- KDEInit.cxx 6 Jan 2006 13:40:09 -0000 1.1.2.5 +++ KDEInit.cxx 6 Jan 2006 15:09:23 -0000 1.1.2.6 @@ -4,9 +4,9 @@ * * $RCSfile: KDEInit.cxx,v $ * - * $Revision: 1.1.2.5 $ + * $Revision: 1.1.2.6 $ * - * last change: $Author: fs $ $Date: 2006/01/06 13:40:09 $ + * last change: $Author: fs $ $Date: 2006/01/06 15:09:23 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -116,6 +116,14 @@ } // ======================================================================= +namespace +{ + double normalizeVersion( unsigned int major, unsigned int minor ) + { + return major + 1.0 * minor / 1000; + } +} + // ----------------------------------------------------------------------- extern "C" void SAL_CALL initKApplication() { @@ -138,27 +146,23 @@ has to be called, else the results are unpredictable. @return - <code>0</code> if the KDE version is not supported, non-<code>0</code> otherwise + <ul><li><code>0</code> if the KDE version is supportednon</li> + <li>a negative value if the version is too old</li> + <li>a positive value if the version is too new to know whether it works with this driver</li> + </ul> #i60062# / 2006-01-06 / [EMAIL PROTECTED] */ -extern "C" int SAL_CALL isKDEVersionSupported() +extern "C" int SAL_CALL matchKDEVersion() { - if ( ::KDE::versionMajor() < MIN_KDE_VERSION_MAJOR ) - return 0; - if ( ::KDE::versionMajor() > MIN_KDE_VERSION_MAJOR ) + double nMinVersion = normalizeVersion( MIN_KDE_VERSION_MAJOR, MIN_KDE_VERSION_MINOR ); + double nCurVersion = normalizeVersion( ::KDE::versionMajor(), ::KDE::versionMinor() ); + double nMaxVersion = normalizeVersion( MAX_KDE_VERSION_MAJOR, MAX_KDE_VERSION_MINOR ); + + if ( nCurVersion < nMinVersion ) + return -1; + if ( nCurVersion > nMaxVersion ) return 1; - if ( ::KDE::versionMinor() < MIN_KDE_VERSION_MINOR ) return 0; - if ( ::KDE::versionMinor() > MIN_KDE_VERSION_MINOR ) - return 1; - - if ( ::KDE::versionRelease() < MIN_KDE_VERSION_RELEASE ) - return 0; - return 1; - - // TODO: The problem described in #i60062# might happen again with newer KDE versions, in case they - // change their API incompatibly. In this case, we will most probably crash, again. Perhaps we should also - // add a check for a *maximum* supported KDE version. } File [changed]: KDEInit.h Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/kab/KDEInit.h?r1=1.1.2.3&r2=1.1.2.4 Delta lines: +6 -3 ------------------- --- KDEInit.h 6 Jan 2006 08:56:48 -0000 1.1.2.3 +++ KDEInit.h 6 Jan 2006 15:09:24 -0000 1.1.2.4 @@ -4,9 +4,9 @@ * * $RCSfile: KDEInit.h,v $ * - * $Revision: 1.1.2.3 $ + * $Revision: 1.1.2.4 $ * - * last change: $Author: fs $ $Date: 2006/01/06 08:56:48 $ + * last change: $Author: fs $ $Date: 2006/01/06 15:09:24 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -39,6 +39,9 @@ // the minimum KDE version which is required at runtime #define MIN_KDE_VERSION_MAJOR 3 #define MIN_KDE_VERSION_MINOR 2 -#define MIN_KDE_VERSION_RELEASE 0 + +#define MAX_KDE_VERSION_MAJOR 3 +#define MAX_KDE_VERSION_MINOR 5 + #endif // CONNECTIVITY_KAB_KDEINIT_H File [changed]: KDriver.cxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/kab/KDriver.cxx?r1=1.2.10.3&r2=1.2.10.4 Delta lines: +76 -35 --------------------- --- KDriver.cxx 6 Jan 2006 08:56:21 -0000 1.2.10.3 +++ KDriver.cxx 6 Jan 2006 15:09:24 -0000 1.2.10.4 @@ -4,9 +4,9 @@ * * $RCSfile: KDriver.cxx,v $ * - * $Revision: 1.2.10.3 $ + * $Revision: 1.2.10.4 $ * - * last change: $Author: fs $ $Date: 2006/01/06 08:56:21 $ + * last change: $Author: fs $ $Date: 2006/01/06 15:09:24 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -47,10 +47,15 @@ #include <rtl/ustrbuf.hxx> #endif +#ifndef _COM_SUN_STAR_SDB_SQLCONTEXT_HPP_ +#include <com/sun/star/sdb/SQLContext.hpp> +#endif + using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::beans; using namespace com::sun::star::sdbc; +using namespace com::sun::star::sdb; using namespace connectivity::kab; // ======================================================================= @@ -78,12 +83,16 @@ } // -------------------------------------------------------------------------------- -bool KabImplModule::isKDEVersionSupported() +KabImplModule::KDEVersionType KabImplModule::isKDEVersionSupported() { - if ( !impl_loadModule() ) - return false; + OSL_PRECOND( m_pKDEVersionCheckFunc, "KabImplModule::isKDEVersionSupported: module not loaded!" ); - return ( (*m_pKDEVersionCheckFunc)() != 0 ); + int nVersionInfo = (*m_pKDEVersionCheckFunc)(); + if ( nVersionInfo < 0 ) + return eTooOld; + if ( nVersionInfo > 0 ) + return eToNew; + return eSupported; } // -------------------------------------------------------------------------------- @@ -128,7 +137,7 @@ lcl_getFunctionFromModuleOrUnload( m_hConnectorModule, "createKabConnection", m_pConnectionFactoryFunc ); lcl_getFunctionFromModuleOrUnload( m_hConnectorModule, "initKApplication", m_pApplicationInitFunc ); lcl_getFunctionFromModuleOrUnload( m_hConnectorModule, "shutdownKApplication", m_pApplicationShutdownFunc ); - lcl_getFunctionFromModuleOrUnload( m_hConnectorModule, "isKDEVersionSupported", m_pKDEVersionCheckFunc ); + lcl_getFunctionFromModuleOrUnload( m_hConnectorModule, "matchKDEVersion", m_pKDEVersionCheckFunc ); if ( !m_hConnectorModule ) // one of the symbols did not exist @@ -154,55 +163,87 @@ } // -------------------------------------------------------------------------------- +void KabImplModule::init() +{ + if ( !impl_loadModule() ) + impl_throwNoKdeException(); + + // if we're not running on a supported version, throw + KabImplModule::KDEVersionType eKDEVersion= isKDEVersionSupported(); + + if ( eKDEVersion == eTooOld ) + impl_throwKdeTooOldException(); + + if ( ( eKDEVersion == eToNew ) && !impl_doAllowNewKDEVersion() ) + impl_throwKdeTooNewException(); + + if ( !m_bAttemptedInitialize ) + { + m_bAttemptedInitialize = true; + (*m_pApplicationInitFunc)(); + } +} + +// -------------------------------------------------------------------------------- +bool KabImplModule::impl_doAllowNewKDEVersion() +{ + // TODO + return false; +} + +// -------------------------------------------------------------------------------- void KabImplModule::impl_throwNoKdeException() { - SQLException aError; - aError.Message = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No suitable KDE installation was found." ) ); - aError.SQLState = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "S1000" ) ); - aError.ErrorCode = 0; - throw aError; + impl_throwGenericSQLException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "No suitable KDE installation was found." ) ) ); } // -------------------------------------------------------------------------------- -void KabImplModule::impl_throwWrongKdeVersionException() +void KabImplModule::impl_throwKdeTooOldException() { ::rtl::OUStringBuffer aMessage; aMessage.appendAscii( "KDE version " ); aMessage.append( (sal_Int32)MIN_KDE_VERSION_MAJOR ); - if ( MIN_KDE_VERSION_MINOR || MIN_KDE_VERSION_RELEASE ) - { aMessage.append( (sal_Unicode)'.' ); aMessage.append( (sal_Int32)MIN_KDE_VERSION_MINOR ); - if ( MIN_KDE_VERSION_RELEASE ) - { - aMessage.append( (sal_Unicode)'.' ); - aMessage.append( (sal_Int32)MIN_KDE_VERSION_RELEASE ); - } - } aMessage.appendAscii( " or higher is required to access the KDE Address Book." ); + impl_throwGenericSQLException( aMessage.makeStringAndClear() ); +} + +// -------------------------------------------------------------------------------- +void KabImplModule::impl_throwGenericSQLException( const ::rtl::OUString& _rMessage ) +{ SQLException aError; - aError.Message = aMessage.makeStringAndClear(); + aError.Message = _rMessage; aError.SQLState = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "S1000" ) ); aError.ErrorCode = 0; throw aError; } // -------------------------------------------------------------------------------- -void KabImplModule::init() +void KabImplModule::impl_throwKdeTooNewException() { - if ( !impl_loadModule() ) - impl_throwNoKdeException(); + ::rtl::OUStringBuffer aMessage; + aMessage.appendAscii( "The found KDE version is too new. Only KDE up to version " ); + aMessage.append( (sal_Int32)MAX_KDE_VERSION_MAJOR ); + aMessage.append( (sal_Unicode)'.' ); + aMessage.append( (sal_Int32)MAX_KDE_VERSION_MINOR ); + aMessage.appendAscii( " is known to work with this product.\n" ); - // if we're not running on a supported version, throw - if ( !isKDEVersionSupported() ) - impl_throwWrongKdeVersionException(); + SQLException aError; + aError.Message = aMessage.makeStringAndClear(); + aError.SQLState = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "S1000" ) ); + aError.ErrorCode = 0; - if ( !m_bAttemptedInitialize ) - { - m_bAttemptedInitialize = true; - (*m_pApplicationInitFunc)(); - } + SQLContext aDetails; + aMessage.appendAscii( "If you are sure that your KDE version works, " ); + aMessage.appendAscii( "you might execute the following Basic macro to disable this version check:\n\n" ); + aMessage.appendAscii( "\n\n---- TODO ----" ); + aDetails.Message = aMessage.makeStringAndClear(); + + aError.NextException <<= aDetails; + + throw aError; } // -------------------------------------------------------------------------------- File [changed]: KDriver.hxx Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/kab/KDriver.hxx?r1=1.2.10.3&r2=1.2.10.4 Delta lines: +25 -5 -------------------- --- KDriver.hxx 6 Jan 2006 08:56:24 -0000 1.2.10.3 +++ KDriver.hxx 6 Jan 2006 15:09:24 -0000 1.2.10.4 @@ -4,9 +4,9 @@ * * $RCSfile: KDriver.hxx,v $ * - * $Revision: 1.2.10.3 $ + * $Revision: 1.2.10.4 $ * - * last change: $Author: fs $ $Date: 2006/01/06 08:56:24 $ + * last change: $Author: fs $ $Date: 2006/01/06 15:09:24 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -89,9 +89,17 @@ */ bool isKDEPresent(); + enum KDEVersionType + { + eTooOld, + eSupported, + eToNew + }; /** checks whether the KDE version we're running against is supported + @precond + the module is loaded, i.e impl_loadModule has successfully been called */ - bool isKDEVersionSupported(); + KDEVersionType isKDEVersionSupported(); /** initializes the implementation module. @@ -135,9 +143,21 @@ */ void impl_throwNoKdeException(); - /** throws an SQLException saying that the found KDE version is not supported + /** throws an SQLException saying that the found KDE version is too old + */ + void impl_throwKdeTooOldException(); + + /** throws an SQLException saying that the found KDE version is too new + */ + void impl_throwKdeTooNewException(); + + /** throws a generic SQL exception with SQLState S1000 and error code 0 + */ + void impl_throwGenericSQLException( const ::rtl::OUString& _rMessage ); + + /** determines whether it's allowed to run on a too-new (not confirmed to work) version */ - void impl_throwWrongKdeVersionException(); + bool impl_doAllowNewKDEVersion(); }; // =============================================================== File [changed]: kabdrv.map Url: http://dba.openoffice.org/source/browse/dba/connectivity/source/drivers/kab/kabdrv.map?r1=1.1.2.2&r2=1.1.2.3 Delta lines: +1 -1 ------------------- --- kabdrv.map 6 Jan 2006 08:56:24 -0000 1.1.2.2 +++ kabdrv.map 6 Jan 2006 15:09:25 -0000 1.1.2.3 @@ -3,7 +3,7 @@ createKabConnection; initKApplication; shutdownKApplication; - isKDEVersionSupported; + matchKDEVersion; local: *; }; --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
