Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
28 :
29 : using namespace dbaui;
30 : using namespace dbtools;
31 :
32 : using namespace ::com::sun::star::sdbc;
33 : using namespace ::com::sun::star::sdb;
34 :
35 12 : extern "C" void SAL_CALL createRegistryInfo_OSQLMessageDialog()
36 : {
37 12 : static OMultiInstanceAutoRegistration< OSQLMessageDialog > aAutoRegistration;
38 12 : }
39 :
40 : namespace dbaui
41 : {
42 :
43 : using namespace ::com::sun::star::uno;
44 : using namespace ::com::sun::star::lang;
45 : using namespace ::com::sun::star::beans;
46 :
47 2 : OSQLMessageDialog::OSQLMessageDialog(const Reference< XComponentContext >& _rxORB)
48 2 : :OSQLMessageDialogBase(_rxORB)
49 : {
50 : registerMayBeVoidProperty(PROPERTY_SQLEXCEPTION, PROPERTY_ID_SQLEXCEPTION, PropertyAttribute::TRANSIENT | PropertyAttribute::MAYBEVOID,
51 2 : &m_aException, ::cppu::UnoType<SQLException>::get());
52 : registerProperty( PROPERTY_HELP_URL, PROPERTY_ID_HELP_URL, PropertyAttribute::TRANSIENT,
53 2 : &m_sHelpURL, cppu::UnoType<decltype(m_sHelpURL)>::get() );
54 2 : }
55 :
56 0 : Sequence<sal_Int8> SAL_CALL OSQLMessageDialog::getImplementationId( ) throw(RuntimeException, std::exception)
57 : {
58 0 : return css::uno::Sequence<sal_Int8>();
59 : }
60 :
61 2 : Reference< XInterface > SAL_CALL OSQLMessageDialog::Create(const Reference< XMultiServiceFactory >& _rxFactory)
62 : {
63 2 : return *(new OSQLMessageDialog( comphelper::getComponentContext(_rxFactory) ));
64 : }
65 :
66 0 : OUString SAL_CALL OSQLMessageDialog::getImplementationName() throw(RuntimeException, std::exception)
67 : {
68 0 : return getImplementationName_Static();
69 : }
70 :
71 24 : OUString OSQLMessageDialog::getImplementationName_Static() throw(RuntimeException)
72 : {
73 24 : return OUString("org.openoffice.comp.dbu.OSQLMessageDialog");
74 : }
75 :
76 1 : ::comphelper::StringSequence SAL_CALL OSQLMessageDialog::getSupportedServiceNames() throw(RuntimeException, std::exception)
77 : {
78 1 : return getSupportedServiceNames_Static();
79 : }
80 :
81 13 : ::comphelper::StringSequence OSQLMessageDialog::getSupportedServiceNames_Static() throw(RuntimeException)
82 : {
83 13 : ::comphelper::StringSequence aSupported(1);
84 13 : aSupported.getArray()[0] = "com.sun.star.sdb.ErrorMessageDialog";
85 13 : return aSupported;
86 : }
87 :
88 1 : void OSQLMessageDialog::initialize(Sequence<Any> const & args) throw (com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException, std::exception)
89 : {
90 1 : OUString title;
91 2 : Reference< com::sun::star::awt::XWindow > parentWindow;
92 2 : com::sun::star::uno::Any sqlException;
93 :
94 1 : if ((args.getLength() == 3) && (args[0] >>= title) && (args[1] >>= parentWindow) && (args[2] >>= sqlException)) {
95 0 : Sequence<Any> s(3);
96 0 : s[0] <<= PropertyValue( "Title", -1, makeAny(title), PropertyState_DIRECT_VALUE);
97 0 : s[1] <<= PropertyValue( "ParentWindow", -1, makeAny(parentWindow), PropertyState_DIRECT_VALUE);
98 0 : s[2] <<= PropertyValue( "SQLException", -1, sqlException, PropertyState_DIRECT_VALUE);
99 0 : OGenericUnoDialog::initialize(s);
100 : } else {
101 1 : OGenericUnoDialog::initialize(args);
102 1 : }
103 1 : }
104 :
105 5 : sal_Bool SAL_CALL OSQLMessageDialog::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue) throw(IllegalArgumentException)
106 : {
107 5 : switch (_nHandle)
108 : {
109 : case PROPERTY_ID_SQLEXCEPTION:
110 : {
111 0 : SQLExceptionInfo aInfo(_rValue);
112 0 : if (!aInfo.isValid())
113 0 : throw IllegalArgumentException();
114 :
115 0 : _rOldValue = m_aException;
116 0 : _rConvertedValue = aInfo.get();
117 :
118 0 : return sal_True;
119 : // always assume "modified", don't bother with comparing the two values
120 : }
121 : default:
122 5 : return OSQLMessageDialogBase::convertFastPropertyValue(_rConvertedValue, _rOldValue, _nHandle, _rValue);
123 : }
124 : }
125 :
126 6 : Reference<XPropertySetInfo> SAL_CALL OSQLMessageDialog::getPropertySetInfo() throw(RuntimeException, std::exception)
127 : {
128 6 : Reference<XPropertySetInfo> xInfo( createPropertySetInfo( getInfoHelper() ) );
129 6 : return xInfo;
130 : }
131 :
132 43 : ::cppu::IPropertyArrayHelper& OSQLMessageDialog::getInfoHelper()
133 : {
134 43 : return *getArrayHelper();
135 : }
136 :
137 1 : ::cppu::IPropertyArrayHelper* OSQLMessageDialog::createArrayHelper( ) const
138 : {
139 1 : Sequence< Property > aProps;
140 1 : describeProperties(aProps);
141 1 : return new ::cppu::OPropertyArrayHelper(aProps);
142 : }
143 :
144 0 : VclPtr<Dialog> OSQLMessageDialog::createDialog(vcl::Window* _pParent)
145 : {
146 0 : if ( m_aException.hasValue() )
147 0 : return VclPtr<OSQLMessageBox>::Create( _pParent, SQLExceptionInfo( m_aException ), WB_OK | WB_DEF_OK, m_sHelpURL );
148 :
149 : OSL_FAIL("OSQLMessageDialog::createDialog : You should use the SQLException property to specify the error to display!");
150 0 : return VclPtr<OSQLMessageBox>::Create(_pParent, SQLException());
151 : }
152 :
153 36 : } // namespace dbaui
154 :
155 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|