1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 #include "MDriver.hxx"
11 #include "MConnection.hxx"
13 #include <com/sun/star/mozilla/XMozillaBootstrap.hpp>
15 using namespace connectivity::mork
;
17 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
com_sun_star_comp_sdbc_MorkDriver_get_implementation(
18 css::uno::XComponentContext
* context
,
19 css::uno::Sequence
<css::uno::Any
> const &)
21 return cppu::acquire(new MorkDriver(context
));
24 MorkDriver::MorkDriver(const css::uno::Reference
< css::uno::XComponentContext
>& context
):
26 m_xFactory(context_
->getServiceManager(), css::uno::UNO_QUERY
)
28 SAL_INFO("connectivity.mork", "=> MorkDriver::MorkDriver()" );
31 OUString SAL_CALL
MorkDriver::getImplementationName()
32 throw (css::uno::RuntimeException
, std::exception
)
34 return OUString(MORK_DRIVER_IMPL_NAME
);
37 sal_Bool SAL_CALL
MorkDriver::supportsService(const OUString
& serviceName
)
38 throw (css::uno::RuntimeException
, std::exception
)
40 return cppu::supportsService(this, serviceName
);
43 css::uno::Sequence
< OUString
> MorkDriver::getSupportedServiceNames()
44 throw (css::uno::RuntimeException
, std::exception
)
46 return { "com.sun.star.sdbc.Driver" };
49 css::uno::Reference
< css::sdbc::XConnection
> MorkDriver::connect(
51 css::uno::Sequence
< css::beans::PropertyValue
> const & info
)
52 throw (css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
)
54 SAL_INFO("connectivity.mork", "=> MorkDriver::connect()" );
56 (void) url
; (void) info
; // avoid warnings
59 css::uno::Reference
<css::uno::XInterface
> xInstance
= context_
->getServiceManager()->createInstanceWithContext("com.sun.star.mozilla.MozillaBootstrap", context_
);
60 OSL_ENSURE( xInstance
.is(), "failed to create instance" );
62 css::uno::Reference
<css::mozilla::XMozillaBootstrap
> xMozillaBootstrap(xInstance
, css::uno::UNO_QUERY
);
63 OSL_ENSURE( xMozillaBootstrap
.is(), "failed to create instance" );
65 if (xMozillaBootstrap
.is())
67 OUString defaultProfile
= xMozillaBootstrap
->getDefaultProfile(css::mozilla::MozillaProductType_Thunderbird
);
69 if (!defaultProfile
.isEmpty())
71 m_sProfilePath
= xMozillaBootstrap
->getProfilePath(css::mozilla::MozillaProductType_Thunderbird
, defaultProfile
);
72 SAL_INFO("connectivity.mork", "Using Thunderbird profile " << m_sProfilePath
);
76 css::uno::Reference
< css::sdbc::XConnection
> xCon
;
77 OConnection
* pCon
= new OConnection(this);
78 xCon
= pCon
; // important here because otherwise the connection could be deleted inside (refcount goes -> 0)
79 pCon
->construct(url
, info
);
83 sal_Bool
MorkDriver::acceptsURL(OUString
const & url
)
84 throw (css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
)
86 SAL_INFO("connectivity.mork", "=> MorkDriver::acceptsURL()" );
87 // Skip 'sdbc:mozab: part of URL
89 sal_Int32 nLen
= url
.indexOf(':');
90 nLen
= url
.indexOf(':',nLen
+1);
91 OUString
aAddrbookURI(url
.copy(nLen
+1));
93 nLen
= aAddrbookURI
.indexOf(':');
94 OUString aAddrbookScheme
;
97 // There isn't any subschema: - but could be just subschema
98 if ( !aAddrbookURI
.isEmpty() )
100 aAddrbookScheme
= aAddrbookURI
;
102 else if( url
== "sdbc:address:" )
113 aAddrbookScheme
= aAddrbookURI
.copy(0, nLen
);
116 return aAddrbookScheme
== "thunderbird" || aAddrbookScheme
== "mozilla";
119 css::uno::Sequence
< css::sdbc::DriverPropertyInfo
> MorkDriver::getPropertyInfo(
120 OUString
const & url
,
121 css::uno::Sequence
< css::beans::PropertyValue
> const & info
)
122 throw (css::sdbc::SQLException
, css::uno::RuntimeException
, std::exception
)
125 (void) url
; (void) info
; // avoid warnings
126 return css::uno::Sequence
< css::sdbc::DriverPropertyInfo
>();
129 sal_Int32
MorkDriver::getMajorVersion() throw (css::uno::RuntimeException
, std::exception
) {
134 sal_Int32
MorkDriver::getMinorVersion() throw (css::uno::RuntimeException
, std::exception
) {
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */