Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / ui / uno / unosqlmessage.cxx
blob914974d9efed3095da916fc279061ff936187d90
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "sqlmessage.hxx"
21 #include "uiservices.hxx"
22 #include "unosqlmessage.hxx"
23 #include "dbu_reghelper.hxx"
24 #include "dbustrings.hrc"
25 #include <comphelper/processfactory.hxx>
26 #include <cppuhelper/typeprovider.hxx>
27 #include <connectivity/dbexception.hxx>
29 using namespace dbaui;
30 using namespace dbtools;
32 using namespace ::com::sun::star::sdbc;
33 using namespace ::com::sun::star::sdb;
35 extern "C" void SAL_CALL createRegistryInfo_OSQLMessageDialog()
37 static OMultiInstanceAutoRegistration< OSQLMessageDialog > aAutoRegistration;
40 namespace dbaui
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::lang;
45 using namespace ::com::sun::star::beans;
47 OSQLMessageDialog::OSQLMessageDialog(const Reference< XComponentContext >& _rxORB)
48 :OSQLMessageDialogBase(_rxORB)
50 registerMayBeVoidProperty(PROPERTY_SQLEXCEPTION, PROPERTY_ID_SQLEXCEPTION, PropertyAttribute::TRANSIENT | PropertyAttribute::MAYBEVOID,
51 &m_aException, ::cppu::UnoType<SQLException>::get());
52 registerProperty( PROPERTY_HELP_URL, PROPERTY_ID_HELP_URL, PropertyAttribute::TRANSIENT,
53 &m_sHelpURL, cppu::UnoType<decltype(m_sHelpURL)>::get() );
56 Sequence<sal_Int8> SAL_CALL OSQLMessageDialog::getImplementationId( ) throw(RuntimeException, std::exception)
58 return css::uno::Sequence<sal_Int8>();
61 Reference< XInterface > SAL_CALL OSQLMessageDialog::Create(const Reference< XMultiServiceFactory >& _rxFactory)
63 return *(new OSQLMessageDialog( comphelper::getComponentContext(_rxFactory) ));
66 OUString SAL_CALL OSQLMessageDialog::getImplementationName() throw(RuntimeException, std::exception)
68 return getImplementationName_Static();
71 OUString OSQLMessageDialog::getImplementationName_Static() throw(RuntimeException)
73 return OUString("org.openoffice.comp.dbu.OSQLMessageDialog");
76 ::comphelper::StringSequence SAL_CALL OSQLMessageDialog::getSupportedServiceNames() throw(RuntimeException, std::exception)
78 return getSupportedServiceNames_Static();
81 ::comphelper::StringSequence OSQLMessageDialog::getSupportedServiceNames_Static() throw(RuntimeException)
83 ::comphelper::StringSequence aSupported(1);
84 aSupported.getArray()[0] = "com.sun.star.sdb.ErrorMessageDialog";
85 return aSupported;
88 void OSQLMessageDialog::initialize(Sequence<Any> const & args) throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException, std::exception)
90 OUString title;
91 Reference< com::sun::star::awt::XWindow > parentWindow;
92 com::sun::star::uno::Any sqlException;
94 if ((args.getLength() == 3) && (args[0] >>= title) && (args[1] >>= parentWindow) && (args[2] >>= sqlException)) {
95 Sequence<Any> s(3);
96 s[0] <<= PropertyValue( "Title", -1, makeAny(title), PropertyState_DIRECT_VALUE);
97 s[1] <<= PropertyValue( "ParentWindow", -1, makeAny(parentWindow), PropertyState_DIRECT_VALUE);
98 s[2] <<= PropertyValue( "SQLException", -1, sqlException, PropertyState_DIRECT_VALUE);
99 OGenericUnoDialog::initialize(s);
100 } else {
101 OGenericUnoDialog::initialize(args);
105 sal_Bool SAL_CALL OSQLMessageDialog::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue) throw(IllegalArgumentException)
107 switch (_nHandle)
109 case PROPERTY_ID_SQLEXCEPTION:
111 SQLExceptionInfo aInfo(_rValue);
112 if (!aInfo.isValid())
113 throw IllegalArgumentException();
115 _rOldValue = m_aException;
116 _rConvertedValue = aInfo.get();
118 return sal_True;
119 // always assume "modified", don't bother with comparing the two values
121 default:
122 return OSQLMessageDialogBase::convertFastPropertyValue(_rConvertedValue, _rOldValue, _nHandle, _rValue);
126 Reference<XPropertySetInfo> SAL_CALL OSQLMessageDialog::getPropertySetInfo() throw(RuntimeException, std::exception)
128 Reference<XPropertySetInfo> xInfo( createPropertySetInfo( getInfoHelper() ) );
129 return xInfo;
132 ::cppu::IPropertyArrayHelper& OSQLMessageDialog::getInfoHelper()
134 return *getArrayHelper();
137 ::cppu::IPropertyArrayHelper* OSQLMessageDialog::createArrayHelper( ) const
139 Sequence< Property > aProps;
140 describeProperties(aProps);
141 return new ::cppu::OPropertyArrayHelper(aProps);
144 VclPtr<Dialog> OSQLMessageDialog::createDialog(vcl::Window* _pParent)
146 if ( m_aException.hasValue() )
147 return VclPtr<OSQLMessageBox>::Create( _pParent, SQLExceptionInfo( m_aException ), WB_OK | WB_DEF_OK, m_sHelpURL );
149 OSL_FAIL("OSQLMessageDialog::createDialog : You should use the SQLException property to specify the error to display!");
150 return VclPtr<OSQLMessageBox>::Create(_pParent, SQLException());
153 } // namespace dbaui
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */