1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dbinteraction.cxx,v $
10 * $Revision: 1.17.6.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef _DBAUI_INTERACTION_HXX_
35 #include "dbinteraction.hxx"
37 #ifndef _DBU_REGHELPER_HXX_
38 #include "dbu_reghelper.hxx"
40 #ifndef _TOOLS_DEBUG_HXX
41 #include <tools/debug.hxx>
43 #ifndef TOOLS_DIAGNOSE_EX_H
44 #include <tools/diagnose_ex.h>
46 #ifndef _SV_MSGBOX_HXX
47 #include <vcl/msgbox.hxx>
49 #ifndef _DBHELPER_DBEXCEPTION_HXX_
50 #include <connectivity/dbexception.hxx>
52 #ifndef _DBAUI_SQLMESSAGE_HXX_
53 #include "sqlmessage.hxx"
55 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONAPPROVE_HPP_
56 #include <com/sun/star/task/XInteractionApprove.hpp>
58 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONDISAPPROVE_HPP_
59 #include <com/sun/star/task/XInteractionDisapprove.hpp>
61 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONRETRY_HPP_
62 #include <com/sun/star/task/XInteractionRetry.hpp>
64 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONABORT_HPP_
65 #include <com/sun/star/task/XInteractionAbort.hpp>
67 #ifndef _COM_SUN_STAR_SDB_XINTERACTIONSUPPLYPARAMETERS_HPP_
68 #include <com/sun/star/sdb/XInteractionSupplyParameters.hpp>
70 #ifndef _COM_SUN_STAR_SDB_XINTERACTIONDOCUMENTSAVE_HPP_
71 #include <com/sun/star/sdb/XInteractionDocumentSave.hpp>
73 #ifndef _SVTOOLS_LOGINDLG_HXX_
74 #include <svtools/logindlg.hxx>
76 #ifndef SFX_QUERYSAVEDOCUMENT_HXX
77 #include <sfx2/QuerySaveDocument.hxx>
80 #include "dbu_uno.hrc"
82 #ifndef _DBAUI_PARAMDIALOG_HXX_
83 #include "paramdialog.hxx"
86 #include <vcl/svapp.hxx>
88 #ifndef _VOS_MUTEX_HXX_
89 #include <vos/mutex.hxx>
91 #ifndef DBAUI_COLLECTIONVIEW_HXX
92 #include "CollectionView.hxx"
94 #ifndef DBAUI_TOOLS_HXX
95 #include "UITools.hxx"
99 //==========================================================================
101 extern "C" void SAL_CALL
createRegistryInfo_OInteractionHandler()
103 static ::dbaui::OMultiInstanceAutoRegistration
< ::dbaui::OInteractionHandler
> aOInteractionHandler_AutoRegistration
;
106 //.........................................................................
109 //.........................................................................
110 using namespace ::com::sun::star::uno
;
111 using namespace ::com::sun::star::ucb
;
112 using namespace ::com::sun::star::sdb
;
113 using namespace ::com::sun::star::lang
;
114 using namespace ::com::sun::star::task
;
115 using namespace ::com::sun::star::beans
;
116 using namespace ::dbtools
;
118 //=========================================================================
119 //= OInteractionHandler
120 //=========================================================================
121 //-------------------------------------------------------------------------
122 OInteractionHandler::OInteractionHandler(const Reference
< XMultiServiceFactory
>& _rxORB
)
127 //-------------------------------------------------------------------------
128 IMPLEMENT_SERVICE_INFO1_STATIC(OInteractionHandler
, "com.sun.star.comp.dbu.OInteractionHandler", "com.sun.star.sdb.InteractionHandler");
130 //-------------------------------------------------------------------------
131 void SAL_CALL
OInteractionHandler::handle(const Reference
< XInteractionRequest
>& _rxRequest
) throw(RuntimeException
)
136 try { aRequest
= _rxRequest
->getRequest(); }
137 catch(RuntimeException
&) { }
139 DBG_ASSERT(aRequest
.hasValue(), "OInteractionHandler::handle: invalid request!");
140 if (!aRequest
.hasValue())
141 // no request -> no handling
144 Sequence
< Reference
< XInteractionContinuation
> > aContinuations
;
145 try { aContinuations
= _rxRequest
->getContinuations(); }
146 catch(RuntimeException
&) { }
148 // try to extract an SQLException (or one of it's derived members
149 SQLExceptionInfo
aInfo(aRequest
);
152 implHandle(aInfo
, aContinuations
);
156 ParametersRequest aParamRequest
;
157 if (aRequest
>>= aParamRequest
)
158 { // it's an authentication request
159 implHandle(aParamRequest
, aContinuations
);
163 DocumentSaveRequest aDocuRequest
;
164 if (aRequest
>>= aDocuRequest
)
165 { // it's an document request
166 implHandle(aDocuRequest
, aContinuations
);
170 OSL_VERIFY( implHandleUnknown( _rxRequest
) );
173 //-------------------------------------------------------------------------
174 void OInteractionHandler::implHandle(const ParametersRequest
& _rParamRequest
, const Sequence
< Reference
< XInteractionContinuation
> >& _rContinuations
)
176 ::vos::OGuard
aGuard(Application::GetSolarMutex());
177 // want to open a dialog ....
179 sal_Int32 nAbortPos
= getContinuation(ABORT
, _rContinuations
);
180 sal_Int32 nParamPos
= getContinuation(SUPPLY_PARAMETERS
, _rContinuations
);
182 Reference
< XInteractionSupplyParameters
> xParamCallback
;
184 xParamCallback
= Reference
< XInteractionSupplyParameters
>(_rContinuations
[nParamPos
], UNO_QUERY
);
185 DBG_ASSERT(xParamCallback
.is(), "OInteractionHandler::implHandle(ParametersRequest): can't set the parameters without an appropriate interaction handler!s");
187 // determine the style of the dialog, dependent on the present continuation types
188 WinBits nDialogStyle
= WB_OK
| WB_DEF_OK
;
190 nDialogStyle
= WB_OK_CANCEL
;
192 OParameterDialog
aDlg(NULL
, _rParamRequest
.Parameters
, _rParamRequest
.Connection
, m_xORB
);
193 sal_Int16 nResult
= aDlg
.Execute();
199 if (xParamCallback
.is())
201 xParamCallback
->setParameters(aDlg
.getValues());
202 xParamCallback
->select();
207 _rContinuations
[nAbortPos
]->select();
211 catch( const Exception
& )
213 DBG_UNHANDLED_EXCEPTION();
217 //-------------------------------------------------------------------------
218 void OInteractionHandler::implHandle(const SQLExceptionInfo
& _rSqlInfo
, const Sequence
< Reference
< XInteractionContinuation
> >& _rContinuations
)
220 ::vos::OGuard
aGuard(Application::GetSolarMutex());
221 // want to open a dialog ....
223 sal_Int32 nApprovePos
= getContinuation(APPROVE
, _rContinuations
);
224 sal_Int32 nDisapprovePos
= getContinuation(DISAPPROVE
, _rContinuations
);
225 sal_Int32 nAbortPos
= getContinuation(ABORT
, _rContinuations
);
226 sal_Int32 nRetryPos
= getContinuation(RETRY
, _rContinuations
);
228 // determine the style of the dialog, dependent on the present continuation types
229 WinBits nDialogStyle
= 0;
230 bool bHaveCancel
= nAbortPos
!= -1;
231 // "approve" means "Yes", "disapprove" means "No"
232 // VCL only supports having both (which makes sense ...)
233 if ( ( nApprovePos
!= -1 ) || ( nDisapprovePos
!= -1 ) )
234 nDialogStyle
= ( bHaveCancel
? WB_YES_NO_CANCEL
: WB_YES_NO
) | WB_DEF_YES
;
237 // if there's no yes/no, then use a default OK button
238 nDialogStyle
= ( bHaveCancel
? WB_OK_CANCEL
: WB_OK
) | WB_DEF_OK
;
241 // If there's a "Retry" continuation, have a "Retry" button
242 if ( nRetryPos
!= -1 )
244 nDialogStyle
= WB_RETRY_CANCEL
| WB_DEF_RETRY
;
248 OSQLMessageBox
aDialog(NULL
, _rSqlInfo
, nDialogStyle
);
249 // TODO: need a way to specify the parent window
250 sal_Int16 nResult
= aDialog
.Execute();
257 if ( nApprovePos
!= -1 )
258 _rContinuations
[ nApprovePos
]->select();
260 OSL_ENSURE( nResult
!= RET_YES
, "OInteractionHandler::implHandle: no handler for YES!" );
264 if ( nDisapprovePos
!= -1 )
265 _rContinuations
[ nDisapprovePos
]->select();
267 OSL_ENSURE( false, "OInteractionHandler::implHandle: no handler for NO!" );
271 if ( nAbortPos
!= -1 )
272 _rContinuations
[ nAbortPos
]->select();
273 else if ( nDisapprovePos
!= -1 )
274 _rContinuations
[ nDisapprovePos
]->select();
276 OSL_ENSURE( false, "OInteractionHandler::implHandle: no handler for CANCEL!" );
279 if ( nRetryPos
!= -1 )
280 _rContinuations
[ nRetryPos
]->select();
282 OSL_ENSURE( false, "OInteractionHandler::implHandle: where does the RETRY come from?" );
286 catch( const Exception
& )
288 DBG_UNHANDLED_EXCEPTION();
291 //-------------------------------------------------------------------------
292 void OInteractionHandler::implHandle(const DocumentSaveRequest
& _rDocuRequest
, const Sequence
< Reference
< XInteractionContinuation
> >& _rContinuations
)
294 ::vos::OGuard
aGuard(Application::GetSolarMutex());
295 // want to open a dialog ....
297 sal_Int32 nApprovePos
= getContinuation(APPROVE
, _rContinuations
);
298 sal_Int32 nDisApprovePos
= getContinuation(DISAPPROVE
, _rContinuations
);
299 sal_Int32 nAbortPos
= getContinuation(ABORT
, _rContinuations
);
301 short nRet
= RET_YES
;
302 if ( -1 != nApprovePos
)
304 // fragen, ob gespeichert werden soll
305 nRet
= ExecuteQuerySaveDocument(NULL
,_rDocuRequest
.Name
);
308 if ( RET_CANCEL
== nRet
)
311 _rContinuations
[nAbortPos
]->select();
314 else if ( RET_YES
== nRet
)
316 sal_Int32 nDocuPos
= getContinuation(SUPPLY_DOCUMENTSAVE
, _rContinuations
);
320 Reference
< XInteractionDocumentSave
> xCallback(_rContinuations
[nDocuPos
], UNO_QUERY
);
321 DBG_ASSERT(xCallback
.is(), "OInteractionHandler::implHandle(DocumentSaveRequest): can't save document without an appropriate interaction handler!s");
323 // determine the style of the dialog, dependent on the present continuation types
324 WinBits nDialogStyle
= WB_OK
| WB_DEF_OK
;
326 nDialogStyle
= WB_OK_CANCEL
;
328 OCollectionView
aDlg(NULL
,_rDocuRequest
.Content
,_rDocuRequest
.Name
,m_xORB
);
329 sal_Int16 nResult
= aDlg
.Execute();
337 xCallback
->setName(aDlg
.getName(),aDlg
.getSelectedFolder());
343 _rContinuations
[nAbortPos
]->select();
347 catch( const Exception
& )
349 DBG_UNHANDLED_EXCEPTION();
352 else if ( -1 != nApprovePos
)
353 _rContinuations
[nApprovePos
]->select();
355 else if ( -1 != nDisApprovePos
)
356 _rContinuations
[nDisApprovePos
]->select();
359 //-------------------------------------------------------------------------
360 bool OInteractionHandler::implHandleUnknown( const Reference
< XInteractionRequest
>& _rxRequest
)
362 Reference
< XInteractionHandler
> xFallbackHandler
;
364 xFallbackHandler
= xFallbackHandler
.query( m_xORB
->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.InteractionHandler" ) ) ) );
365 if ( xFallbackHandler
.is() )
367 xFallbackHandler
->handle( _rxRequest
);
373 //-------------------------------------------------------------------------
374 sal_Int32
OInteractionHandler::getContinuation(Continuation _eCont
, const Sequence
< Reference
< XInteractionContinuation
> >& _rContinuations
)
376 const Reference
< XInteractionContinuation
>* pContinuations
= _rContinuations
.getConstArray();
377 for (sal_Int32 i
=0; i
<_rContinuations
.getLength(); ++i
, ++pContinuations
)
382 if (Reference
< XInteractionApprove
>(*pContinuations
, UNO_QUERY
).is())
386 if (Reference
< XInteractionDisapprove
>(*pContinuations
, UNO_QUERY
).is())
390 if (Reference
< XInteractionRetry
>(*pContinuations
, UNO_QUERY
).is())
394 if (Reference
< XInteractionAbort
>(*pContinuations
, UNO_QUERY
).is())
397 case SUPPLY_PARAMETERS
:
398 if (Reference
< XInteractionSupplyParameters
>(*pContinuations
, UNO_QUERY
).is())
401 case SUPPLY_DOCUMENTSAVE
:
402 if (Reference
< XInteractionDocumentSave
>(*pContinuations
, UNO_QUERY
).is())
412 //.........................................................................
414 //.........................................................................