1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_fpicker.hxx"
30 #include "fpinteraction.hxx"
31 #include <tools/debug.hxx>
32 #include <com/sun/star/ucb/InteractiveIOException.hpp>
33 #include <com/sun/star/task/XInteractionAbort.hpp>
34 #include <com/sun/star/task/XInteractionApprove.hpp>
35 #include <com/sun/star/task/XInteractionDisapprove.hpp>
36 #include <com/sun/star/task/XInteractionRetry.hpp>
37 
38 //........................................................................
39 namespace svt
40 {
41 //........................................................................
42 	using namespace ::com::sun::star::uno;
43 	using namespace ::com::sun::star::task;
44 	using namespace ::com::sun::star::ucb;
45 
46 	//====================================================================
47 	//= OFilePickerInteractionHandler
48 	//====================================================================
49 	DBG_NAME( OFilePickerInteractionHandler )
50 	//--------------------------------------------------------------------
51     OFilePickerInteractionHandler::OFilePickerInteractionHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& _rxMaster )
52         :m_xMaster( _rxMaster )
53         ,m_bUsed( sal_False )
54         ,m_eInterceptions( OFilePickerInteractionHandler::E_NOINTERCEPTION )
55 	{
56 		DBG_CTOR( OFilePickerInteractionHandler, NULL );
57         DBG_ASSERT( m_xMaster.is(), "OFilePickerInteractionHandler::OFilePickerInteractionHandler: invalid master handler!" );
58 	}
59 
60 	//--------------------------------------------------------------------
61 	OFilePickerInteractionHandler::~OFilePickerInteractionHandler( )
62 	{
63 		DBG_DTOR( OFilePickerInteractionHandler, NULL );
64 	}
65 
66 	//--------------------------------------------------------------------
67 	void SAL_CALL OFilePickerInteractionHandler::handle( const Reference< XInteractionRequest >& _rxRequest ) throw (RuntimeException)
68 	{
69         if (!_rxRequest.is())
70             return;
71 
72         m_bUsed = sal_True;
73 
74         // extract some generic continuations ... might we need it later
75         // if something goes wrong.
76         Reference< XInteractionAbort >       xAbort;
77         Reference< XInteractionApprove >     xApprove;
78         Reference< XInteractionDisapprove >  xDisapprove;
79         Reference< XInteractionRetry >       xRetry;
80 
81         const Sequence< Reference< XInteractionContinuation > > lConts = _rxRequest->getContinuations();
82         const Reference< XInteractionContinuation >*            pConts = lConts.getConstArray();
83         for (sal_Int32 i=0; i<lConts.getLength(); ++i)
84         {
85             if (!xAbort.is())
86                 xAbort = Reference< XInteractionAbort >(pConts[i], UNO_QUERY);
87             if (!xApprove.is())
88                 xApprove = Reference< XInteractionApprove >(pConts[i], UNO_QUERY);
89             if (!xDisapprove.is())
90                 xDisapprove = Reference< XInteractionDisapprove >(pConts[i], UNO_QUERY);
91             if (!xRetry.is())
92                 xRetry = Reference< XInteractionRetry >(pConts[i], UNO_QUERY);
93         }
94 
95         // safe the original request for later analyzing!
96         m_aException = _rxRequest->getRequest();
97 
98         // intercept some interesting interactions
99 
100         // The "does not exist" interaction will be supressed here completly.
101         if (m_eInterceptions & OFilePickerInteractionHandler::E_DOESNOTEXIST)
102         {
103             InteractiveIOException aIoException;
104             if (
105                 (m_aException             >>= aIoException     ) &&
106                 (IOErrorCode_NOT_EXISTING  == aIoException.Code)
107                )
108             {
109                 if (xAbort.is())
110                     xAbort->select();
111                 return;
112             }
113         }
114 
115         // no master => abort this operation ...
116         if (!m_xMaster.is())
117         {
118             if (xAbort.is())
119                 xAbort->select();
120             return;
121         }
122 
123         // forward it to our master - so he can handle all
124         // not interesting interactions :-)
125         m_xMaster->handle(_rxRequest);
126 	}
127 
128     //--------------------------------------------------------------------
129     void OFilePickerInteractionHandler::enableInterceptions( EInterceptedInteractions eInterceptions )
130     {
131         m_eInterceptions = eInterceptions;
132     }
133 
134     //--------------------------------------------------------------------
135     sal_Bool OFilePickerInteractionHandler::wasUsed() const
136     {
137         return m_bUsed;
138     }
139 
140     //--------------------------------------------------------------------
141     void OFilePickerInteractionHandler::resetUseState()
142     {
143         m_bUsed = sal_False;
144     }
145 
146     //--------------------------------------------------------------------
147     void OFilePickerInteractionHandler::forgetRequest()
148     {
149         m_aException = Any();
150     }
151 
152     //--------------------------------------------------------------------
153     sal_Bool OFilePickerInteractionHandler::wasAccessDenied() const
154     {
155         InteractiveIOException aIoException;
156         if (
157             (m_aException              >>= aIoException     ) &&
158             (IOErrorCode_ACCESS_DENIED  == aIoException.Code)
159            )
160         {
161             return sal_True;
162         }
163         return sal_False;
164     }
165 
166 //........................................................................
167 }	// namespace svt
168 //........................................................................
169 
170