Branch data 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 : :
21 : : #include "dbinteraction.hxx"
22 : : #include "dbu_reghelper.hxx"
23 : : #include <tools/diagnose_ex.h>
24 : : #include <osl/diagnose.h>
25 : : #include <vcl/msgbox.hxx>
26 : : #include <connectivity/dbexception.hxx>
27 : : #include "sqlmessage.hxx"
28 : : #include <com/sun/star/task/XInteractionApprove.hpp>
29 : : #include <com/sun/star/task/XInteractionDisapprove.hpp>
30 : : #include <com/sun/star/task/XInteractionRetry.hpp>
31 : : #include <com/sun/star/task/XInteractionAbort.hpp>
32 : : #include <com/sun/star/sdb/XInteractionSupplyParameters.hpp>
33 : : #include <com/sun/star/sdb/XInteractionDocumentSave.hpp>
34 : : #include <sfx2/QuerySaveDocument.hxx>
35 : : #include "dbu_uno.hrc"
36 : : #include "paramdialog.hxx"
37 : : #include <vcl/svapp.hxx>
38 : : #include <osl/mutex.hxx>
39 : : #include "CollectionView.hxx"
40 : : #include "UITools.hxx"
41 : :
42 : :
43 : : //==========================================================================
44 : :
45 : 8 : extern "C" void SAL_CALL createRegistryInfo_OInteractionHandler()
46 : : {
47 [ + - ][ + - ]: 8 : static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::SQLExceptionInteractionHandler > aSQLExceptionInteractionHandler_AutoRegistration;
[ + - ][ # # ]
48 [ + - ][ + - ]: 8 : static ::dbaui::OMultiInstanceAutoRegistration< ::dbaui::LegacyInteractionHandler > aLegacyInteractionHandler_AutoRegistration;
[ + - ][ # # ]
49 : 8 : }
50 : :
51 : : //.........................................................................
52 : : namespace dbaui
53 : : {
54 : : //.........................................................................
55 : : using namespace ::com::sun::star::uno;
56 : : using namespace ::com::sun::star::ucb;
57 : : using namespace ::com::sun::star::sdb;
58 : : using namespace ::com::sun::star::lang;
59 : : using namespace ::com::sun::star::task;
60 : : using namespace ::com::sun::star::beans;
61 : : using namespace ::dbtools;
62 : :
63 : : //=========================================================================
64 : : //= BasicInteractionHandler
65 : : //=========================================================================
66 : : //-------------------------------------------------------------------------
67 : 4 : BasicInteractionHandler::BasicInteractionHandler( const Reference< XMultiServiceFactory >& _rxORB, const bool i_bFallbackToGeneric )
68 : : :m_xORB( _rxORB )
69 [ + - ]: 4 : ,m_bFallbackToGeneric( i_bFallbackToGeneric )
70 : : {
71 : : OSL_ENSURE( !m_bFallbackToGeneric,
72 : : "BasicInteractionHandler::BasicInteractionHandler: enabling legacy behavior, there should be no clients of this anymore!" );
73 : 4 : }
74 : :
75 : : //-------------------------------------------------------------------------
76 : 0 : ::sal_Bool SAL_CALL BasicInteractionHandler::handleInteractionRequest( const Reference< XInteractionRequest >& i_rRequest ) throw (RuntimeException)
77 : : {
78 : 0 : return impl_handle_throw( i_rRequest );
79 : : }
80 : :
81 : : //-------------------------------------------------------------------------
82 : 0 : void SAL_CALL BasicInteractionHandler::handle( const Reference< XInteractionRequest >& i_rRequest ) throw(RuntimeException)
83 : : {
84 : 0 : impl_handle_throw( i_rRequest );
85 : 0 : }
86 : :
87 : : //-------------------------------------------------------------------------
88 : 0 : sal_Bool BasicInteractionHandler::impl_handle_throw( const Reference< XInteractionRequest >& i_Request )
89 : : {
90 [ # # ][ # # ]: 0 : Any aRequest( i_Request->getRequest() );
91 : : OSL_ENSURE(aRequest.hasValue(), "BasicInteractionHandler::handle: invalid request!");
92 [ # # ]: 0 : if ( !aRequest.hasValue() )
93 : : // no request -> no handling
94 : 0 : return sal_False;
95 : :
96 [ # # ][ # # ]: 0 : Sequence< Reference< XInteractionContinuation > > aContinuations( i_Request->getContinuations() );
97 : :
98 : : // try to extract an SQLException (or one of it's derived members
99 [ # # ]: 0 : SQLExceptionInfo aInfo( aRequest );
100 [ # # ]: 0 : if ( aInfo.isValid() )
101 : : {
102 [ # # ]: 0 : implHandle( aInfo, aContinuations );
103 : 0 : return sal_True;
104 : : }
105 : :
106 [ # # ]: 0 : ParametersRequest aParamRequest;
107 [ # # ][ # # ]: 0 : if ( aRequest >>= aParamRequest )
108 : : {
109 [ # # ]: 0 : implHandle( aParamRequest, aContinuations );
110 : 0 : return sal_True;
111 : : }
112 : :
113 [ # # ]: 0 : DocumentSaveRequest aDocuRequest;
114 [ # # ][ # # ]: 0 : if ( aRequest >>= aDocuRequest )
115 : : {
116 [ # # ]: 0 : implHandle( aDocuRequest, aContinuations );
117 : 0 : return sal_True;
118 : : }
119 : :
120 [ # # ]: 0 : if ( m_bFallbackToGeneric )
121 [ # # ]: 0 : return implHandleUnknown( i_Request );
122 : :
123 [ # # ][ # # ]: 0 : return sal_False;
[ # # ][ # # ]
124 : : }
125 : :
126 : : //-------------------------------------------------------------------------
127 : 0 : void BasicInteractionHandler::implHandle(const ParametersRequest& _rParamRequest, const Sequence< Reference< XInteractionContinuation > >& _rContinuations)
128 : : {
129 [ # # ]: 0 : SolarMutexGuard aGuard;
130 : : // want to open a dialog ....
131 : :
132 [ # # ]: 0 : sal_Int32 nAbortPos = getContinuation(ABORT, _rContinuations);
133 [ # # ]: 0 : sal_Int32 nParamPos = getContinuation(SUPPLY_PARAMETERS, _rContinuations);
134 : :
135 : 0 : Reference< XInteractionSupplyParameters > xParamCallback;
136 [ # # ]: 0 : if (-1 != nParamPos)
137 [ # # ][ # # ]: 0 : xParamCallback = Reference< XInteractionSupplyParameters >(_rContinuations[nParamPos], UNO_QUERY);
138 : : OSL_ENSURE(xParamCallback.is(), "BasicInteractionHandler::implHandle(ParametersRequest): can't set the parameters without an appropriate interaction handler!s");
139 : :
140 [ # # ]: 0 : OParameterDialog aDlg(NULL, _rParamRequest.Parameters, _rParamRequest.Connection, m_xORB);
141 [ # # ]: 0 : sal_Int16 nResult = aDlg.Execute();
142 : : try
143 : : {
144 [ # # ]: 0 : switch (nResult)
145 : : {
146 : : case RET_OK:
147 [ # # ]: 0 : if (xParamCallback.is())
148 : : {
149 [ # # ][ # # ]: 0 : xParamCallback->setParameters(aDlg.getValues());
[ # # ]
[ # # # # ]
150 [ # # ][ # # ]: 0 : xParamCallback->select();
151 : : }
152 : 0 : break;
153 : : default:
154 [ # # ]: 0 : if (-1 != nAbortPos)
155 [ # # ][ # # ]: 0 : _rContinuations[nAbortPos]->select();
156 : 0 : break;
157 : : }
158 : : }
159 [ # # ]: 0 : catch( const Exception& )
160 : : {
161 : : DBG_UNHANDLED_EXCEPTION();
162 [ # # ][ # # ]: 0 : }
163 : 0 : }
164 : :
165 : : //-------------------------------------------------------------------------
166 : 0 : void BasicInteractionHandler::implHandle(const SQLExceptionInfo& _rSqlInfo, const Sequence< Reference< XInteractionContinuation > >& _rContinuations)
167 : : {
168 [ # # ]: 0 : SolarMutexGuard aGuard;
169 : : // want to open a dialog ....
170 : :
171 [ # # ]: 0 : sal_Int32 nApprovePos = getContinuation(APPROVE, _rContinuations);
172 [ # # ]: 0 : sal_Int32 nDisapprovePos = getContinuation(DISAPPROVE, _rContinuations);
173 [ # # ]: 0 : sal_Int32 nAbortPos = getContinuation(ABORT, _rContinuations);
174 [ # # ]: 0 : sal_Int32 nRetryPos = getContinuation(RETRY, _rContinuations);
175 : :
176 : : // determine the style of the dialog, dependent on the present continuation types
177 : 0 : WinBits nDialogStyle = 0;
178 : 0 : bool bHaveCancel = nAbortPos != -1;
179 : : // "approve" means "Yes", "disapprove" means "No"
180 : : // VCL only supports having both (which makes sense ...)
181 [ # # ][ # # ]: 0 : if ( ( nApprovePos != -1 ) || ( nDisapprovePos != -1 ) )
182 [ # # ]: 0 : nDialogStyle = ( bHaveCancel ? WB_YES_NO_CANCEL : WB_YES_NO ) | WB_DEF_YES;
183 : : else
184 : : {
185 : : // if there's no yes/no, then use a default OK button
186 [ # # ]: 0 : nDialogStyle = ( bHaveCancel ? WB_OK_CANCEL : WB_OK ) | WB_DEF_OK;
187 : : }
188 : :
189 : : // If there's a "Retry" continuation, have a "Retry" button
190 [ # # ]: 0 : if ( nRetryPos != -1 )
191 : : {
192 : 0 : nDialogStyle = WB_RETRY_CANCEL | WB_DEF_RETRY;
193 : : }
194 : :
195 : : // execute the dialog
196 [ # # ][ # # ]: 0 : OSQLMessageBox aDialog(NULL, _rSqlInfo, nDialogStyle);
197 : : // TODO: need a way to specify the parent window
198 [ # # ]: 0 : sal_Int16 nResult = aDialog.Execute();
199 : : try
200 : : {
201 [ # # # # : 0 : switch (nResult)
# ]
202 : : {
203 : : case RET_YES:
204 : : case RET_OK:
205 [ # # ]: 0 : if ( nApprovePos != -1 )
206 [ # # ][ # # ]: 0 : _rContinuations[ nApprovePos ]->select();
207 : : else
208 : : OSL_ENSURE( nResult != RET_YES, "BasicInteractionHandler::implHandle: no handler for YES!" );
209 : 0 : break;
210 : :
211 : : case RET_NO:
212 [ # # ]: 0 : if ( nDisapprovePos != -1 )
213 [ # # ][ # # ]: 0 : _rContinuations[ nDisapprovePos ]->select();
214 : : else
215 : : OSL_FAIL( "BasicInteractionHandler::implHandle: no handler for NO!" );
216 : 0 : break;
217 : :
218 : : case RET_CANCEL:
219 [ # # ]: 0 : if ( nAbortPos != -1 )
220 [ # # ][ # # ]: 0 : _rContinuations[ nAbortPos ]->select();
221 [ # # ]: 0 : else if ( nDisapprovePos != -1 )
222 [ # # ][ # # ]: 0 : _rContinuations[ nDisapprovePos ]->select();
223 : : else
224 : : OSL_FAIL( "BasicInteractionHandler::implHandle: no handler for CANCEL!" );
225 : 0 : break;
226 : : case RET_RETRY:
227 [ # # ]: 0 : if ( nRetryPos != -1 )
228 [ # # ][ # # ]: 0 : _rContinuations[ nRetryPos ]->select();
229 : : else
230 : : OSL_FAIL( "BasicInteractionHandler::implHandle: where does the RETRY come from?" );
231 : 0 : break;
232 : : }
233 : : }
234 [ # # ]: 0 : catch( const Exception& )
235 : : {
236 : : DBG_UNHANDLED_EXCEPTION();
237 [ # # ][ # # ]: 0 : }
238 : 0 : }
239 : : //-------------------------------------------------------------------------
240 : 0 : void BasicInteractionHandler::implHandle(const DocumentSaveRequest& _rDocuRequest, const Sequence< Reference< XInteractionContinuation > >& _rContinuations)
241 : : {
242 [ # # ]: 0 : SolarMutexGuard aGuard;
243 : : // want to open a dialog ....
244 : :
245 [ # # ]: 0 : sal_Int32 nApprovePos = getContinuation(APPROVE, _rContinuations);
246 [ # # ]: 0 : sal_Int32 nDisApprovePos = getContinuation(DISAPPROVE, _rContinuations);
247 [ # # ]: 0 : sal_Int32 nAbortPos = getContinuation(ABORT, _rContinuations);
248 : :
249 : 0 : short nRet = RET_YES;
250 [ # # ]: 0 : if ( -1 != nApprovePos )
251 : : {
252 : : // fragen, ob gespeichert werden soll
253 [ # # ][ # # ]: 0 : nRet = ExecuteQuerySaveDocument(NULL,_rDocuRequest.Name);
[ # # ]
254 : : }
255 : :
256 [ # # ]: 0 : if ( RET_CANCEL == nRet )
257 : : {
258 [ # # ]: 0 : if (-1 != nAbortPos)
259 [ # # ][ # # ]: 0 : _rContinuations[nAbortPos]->select();
260 : 0 : return;
261 : : }
262 [ # # ]: 0 : else if ( RET_YES == nRet )
263 : : {
264 [ # # ]: 0 : sal_Int32 nDocuPos = getContinuation(SUPPLY_DOCUMENTSAVE, _rContinuations);
265 : :
266 [ # # ]: 0 : if (-1 != nDocuPos)
267 : : {
268 [ # # ]: 0 : Reference< XInteractionDocumentSave > xCallback(_rContinuations[nDocuPos], UNO_QUERY);
269 : : OSL_ENSURE(xCallback.is(), "BasicInteractionHandler::implHandle(DocumentSaveRequest): can't save document without an appropriate interaction handler!s");
270 : :
271 [ # # ]: 0 : OCollectionView aDlg(NULL,_rDocuRequest.Content,_rDocuRequest.Name,m_xORB);
272 [ # # ]: 0 : sal_Int16 nResult = aDlg.Execute();
273 : : try
274 : : {
275 [ # # ]: 0 : switch (nResult)
276 : : {
277 : : case RET_OK:
278 [ # # ]: 0 : if (xCallback.is())
279 : : {
280 [ # # ][ # # ]: 0 : xCallback->setName(aDlg.getName(),aDlg.getSelectedFolder());
[ # # ][ # # ]
[ # # ]
281 [ # # ][ # # ]: 0 : xCallback->select();
282 : : }
283 : 0 : break;
284 : : default:
285 [ # # ]: 0 : if (-1 != nAbortPos)
286 [ # # ][ # # ]: 0 : _rContinuations[nAbortPos]->select();
287 : 0 : break;
288 : : }
289 : : }
290 [ # # ]: 0 : catch( const Exception& )
291 : : {
292 : : DBG_UNHANDLED_EXCEPTION();
293 [ # # ]: 0 : }
294 : : }
295 [ # # ]: 0 : else if ( -1 != nApprovePos )
296 [ # # ][ # # ]: 0 : _rContinuations[nApprovePos]->select();
297 : : }
298 [ # # ]: 0 : else if ( -1 != nDisApprovePos )
299 [ # # ][ # # ]: 0 : _rContinuations[nDisApprovePos]->select();
[ # # ][ # # ]
300 : : }
301 : :
302 : : //-------------------------------------------------------------------------
303 : 0 : bool BasicInteractionHandler::implHandleUnknown( const Reference< XInteractionRequest >& _rxRequest )
304 : : {
305 : 0 : Reference< XInteractionHandler > xFallbackHandler;
306 [ # # ]: 0 : if ( m_xORB.is() )
307 [ # # ][ # # ]: 0 : xFallbackHandler = xFallbackHandler.query( m_xORB->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) ) ) );
[ # # ][ # # ]
[ # # ]
308 [ # # ]: 0 : if ( xFallbackHandler.is() )
309 : : {
310 [ # # ][ # # ]: 0 : xFallbackHandler->handle( _rxRequest );
311 : 0 : return true;
312 : : }
313 : 0 : return false;
314 : : }
315 : :
316 : : //-------------------------------------------------------------------------
317 : 0 : sal_Int32 BasicInteractionHandler::getContinuation(Continuation _eCont, const Sequence< Reference< XInteractionContinuation > >& _rContinuations)
318 : : {
319 : 0 : const Reference< XInteractionContinuation >* pContinuations = _rContinuations.getConstArray();
320 [ # # ]: 0 : for (sal_Int32 i=0; i<_rContinuations.getLength(); ++i, ++pContinuations)
321 : : {
322 [ # # # # : 0 : switch (_eCont)
# # # ]
323 : : {
324 : : case APPROVE:
325 [ # # ]: 0 : if (Reference< XInteractionApprove >(*pContinuations, UNO_QUERY).is())
326 : 0 : return i;
327 : 0 : break;
328 : : case DISAPPROVE:
329 [ # # ]: 0 : if (Reference< XInteractionDisapprove >(*pContinuations, UNO_QUERY).is())
330 : 0 : return i;
331 : 0 : break;
332 : : case RETRY:
333 [ # # ]: 0 : if (Reference< XInteractionRetry >(*pContinuations, UNO_QUERY).is())
334 : 0 : return i;
335 : 0 : break;
336 : : case ABORT:
337 [ # # ]: 0 : if (Reference< XInteractionAbort >(*pContinuations, UNO_QUERY).is())
338 : 0 : return i;
339 : 0 : break;
340 : : case SUPPLY_PARAMETERS:
341 [ # # ]: 0 : if (Reference< XInteractionSupplyParameters >(*pContinuations, UNO_QUERY).is())
342 : 0 : return i;
343 : 0 : break;
344 : : case SUPPLY_DOCUMENTSAVE:
345 [ # # ]: 0 : if (Reference< XInteractionDocumentSave >(*pContinuations, UNO_QUERY).is())
346 : 0 : return i;
347 : 0 : break;
348 : : }
349 : : }
350 : :
351 : 0 : return -1;
352 : : }
353 : :
354 : : //==========================================================================
355 : : //= SQLExceptionInteractionHandler
356 : : //==========================================================================
357 [ # # ][ # # ]: 24 : IMPLEMENT_SERVICE_INFO1_STATIC( SQLExceptionInteractionHandler, "com.sun.star.comp.dbaccess.DatabaseInteractionHandler", "com.sun.star.sdb.DatabaseInteractionHandler" );
[ + - ][ # # ]
[ # # ][ # # ]
[ # # ]
358 : :
359 : : //==========================================================================
360 : : //= LegacyInteractionHandler
361 : : //==========================================================================
362 [ + - ][ + - ]: 28 : IMPLEMENT_SERVICE_INFO1_STATIC( LegacyInteractionHandler, "com.sun.star.comp.dbaccess.LegacyInteractionHandler", "com.sun.star.sdb.InteractionHandler" );
[ + - ][ # # ]
[ # # ][ # # ]
[ # # ]
363 : :
364 : : //.........................................................................
365 : : } // namespace dbaui
366 : : //.........................................................................
367 : :
368 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|