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/.
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 <unosqlmessage.hxx>
22 #include <stringconstants.hxx>
23 #include <strings.hxx>
24 #include <comphelper/propertysequence.hxx>
25 #include <connectivity/dbexception.hxx>
26 #include <vcl/svapp.hxx>
27 #include <com/sun/star/awt/XWindow.hpp>
28 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include <com/sun/star/sdbc/SQLException.hpp>
31 using namespace dbaui
;
32 using namespace dbtools
;
34 using namespace ::com::sun::star::sdbc
;
35 using namespace ::com::sun::star::sdb
;
37 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
38 org_openoffice_comp_dbu_OSQLMessageDialog_get_implementation(
39 css::uno::XComponentContext
* context
, css::uno::Sequence
<css::uno::Any
> const& )
41 return cppu::acquire(new OSQLMessageDialog(context
));
47 using namespace ::com::sun::star::uno
;
48 using namespace ::com::sun::star::lang
;
49 using namespace ::com::sun::star::beans
;
51 OSQLMessageDialog::OSQLMessageDialog(const Reference
< XComponentContext
>& _rxORB
)
52 :OSQLMessageDialogBase(_rxORB
)
54 registerMayBeVoidProperty(PROPERTY_SQLEXCEPTION
, PROPERTY_ID_SQLEXCEPTION
, PropertyAttribute::TRANSIENT
| PropertyAttribute::MAYBEVOID
,
55 &m_aException
, ::cppu::UnoType
<SQLException
>::get());
56 registerProperty( PROPERTY_HELP_URL
, PROPERTY_ID_HELP_URL
, PropertyAttribute::TRANSIENT
,
57 &m_sHelpURL
, cppu::UnoType
<decltype(m_sHelpURL
)>::get() );
60 Sequence
<sal_Int8
> SAL_CALL
OSQLMessageDialog::getImplementationId( )
62 return css::uno::Sequence
<sal_Int8
>();
65 OUString SAL_CALL
OSQLMessageDialog::getImplementationName()
67 return "org.openoffice.comp.dbu.OSQLMessageDialog";
70 css::uno::Sequence
<OUString
> SAL_CALL
OSQLMessageDialog::getSupportedServiceNames()
72 return { "com.sun.star.sdb.ErrorMessageDialog" };
75 void OSQLMessageDialog::initialize(Sequence
<Any
> const & args
)
78 Reference
< css::awt::XWindow
> parentWindow
;
80 if ((args
.getLength() == 3) && (args
[0] >>= title
) && (args
[1] >>= parentWindow
)) {
81 Sequence
<Any
> s(comphelper::InitAnyPropertySequence(
83 {"Title", Any(title
)},
84 {"ParentWindow", Any(parentWindow
)},
85 {"SQLException", args
[2]}
87 OGenericUnoDialog::initialize(s
);
89 OGenericUnoDialog::initialize(args
);
93 sal_Bool SAL_CALL
OSQLMessageDialog::convertFastPropertyValue( Any
& _rConvertedValue
, Any
& _rOldValue
, sal_Int32 _nHandle
, const Any
& _rValue
)
97 case PROPERTY_ID_SQLEXCEPTION
:
99 SQLExceptionInfo
aInfo(_rValue
);
100 if (!aInfo
.isValid())
101 throw IllegalArgumentException();
103 _rOldValue
= m_aException
;
104 _rConvertedValue
= aInfo
.get();
107 // always assume "modified", don't bother with comparing the two values
110 return OSQLMessageDialogBase::convertFastPropertyValue(_rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
114 Reference
<XPropertySetInfo
> SAL_CALL
OSQLMessageDialog::getPropertySetInfo()
116 Reference
<XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
120 ::cppu::IPropertyArrayHelper
& OSQLMessageDialog::getInfoHelper()
122 return *getArrayHelper();
125 ::cppu::IPropertyArrayHelper
* OSQLMessageDialog::createArrayHelper( ) const
127 Sequence
< Property
> aProps
;
128 describeProperties(aProps
);
129 return new ::cppu::OPropertyArrayHelper(aProps
);
132 std::unique_ptr
<weld::DialogController
> OSQLMessageDialog::createDialog(const css::uno::Reference
<css::awt::XWindow
>& rParent
)
134 weld::Window
* pParent
= Application::GetFrameWeld(rParent
);
135 if ( m_aException
.hasValue() )
136 return std::make_unique
<OSQLMessageBox
>(pParent
, SQLExceptionInfo(m_aException
), MessBoxStyle::Ok
| MessBoxStyle::DefaultOk
, m_sHelpURL
);
138 OSL_FAIL("OSQLMessageDialog::createDialog : You should use the SQLException property to specify the error to display!");
139 return std::make_unique
<OSQLMessageBox
>(pParent
, SQLException());
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */