Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #ifndef _FILTASK_HXX_
29 : : #define _FILTASK_HXX_
30 : : #endif
31 : :
32 : : #include <boost/unordered_map.hpp>
33 : : #include <rtl/ustring.hxx>
34 : :
35 : : #include "osl/mutex.hxx"
36 : : #include <com/sun/star/ucb/DuplicateCommandIdentifierException.hpp>
37 : : #include <com/sun/star/ucb/XCommandEnvironment.hpp>
38 : : #include <com/sun/star/ucb/XProgressHandler.hpp>
39 : : #include <com/sun/star/task/XInteractionHandler.hpp>
40 : : #include <com/sun/star/task/XInteractionRequest.hpp>
41 : : #include "filerror.hxx"
42 : :
43 : : namespace fileaccess
44 : : {
45 : : class BaseContent;
46 : :
47 : : /*
48 : : * This implementation is inherited by class fileaccess::shell.
49 : : * The relevant methods in this class all have as first argument the CommandId,
50 : : * so if necessary, every method has access to its relevant XInteractionHandler and
51 : : * XProgressHandler.
52 : : */
53 : :
54 : :
55 : : class TaskManager
56 : : {
57 : : protected:
58 : :
59 : 469332 : class TaskHandling
60 : : {
61 : : private:
62 : :
63 : : bool m_bAbort,m_bHandled;
64 : : sal_Int32 m_nErrorCode,m_nMinorCode;
65 : : com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > m_xInteractionHandler;
66 : : com::sun::star::uno::Reference< com::sun::star::ucb::XProgressHandler > m_xProgressHandler;
67 : : com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment > m_xCommandEnvironment;
68 : :
69 : :
70 : : public:
71 : :
72 : 312888 : TaskHandling(
73 : : const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& xCommandEnv
74 : : = com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >( 0 ) )
75 : : : m_bAbort( false ),
76 : : m_bHandled( false ),
77 : : m_nErrorCode( TASKHANDLER_NO_ERROR ),
78 : : m_nMinorCode( TASKHANDLER_NO_ERROR ),
79 : : m_xInteractionHandler( 0 ),
80 : : m_xProgressHandler( 0 ),
81 [ + - ]: 312888 : m_xCommandEnvironment( xCommandEnv )
82 : : {
83 : 312888 : }
84 : :
85 : 0 : void SAL_CALL abort()
86 : : {
87 : 0 : m_bAbort = true;
88 : 0 : }
89 : :
90 : 93 : void setHandled()
91 : : {
92 : 93 : m_bHandled = true;
93 : 93 : }
94 : :
95 : 156444 : bool isHandled() const
96 : : {
97 : 156444 : return true;
98 : : }
99 : :
100 : 0 : void clearError()
101 : : {
102 : 0 : m_nErrorCode = TASKHANDLER_NO_ERROR;
103 : 0 : m_nMinorCode = TASKHANDLER_NO_ERROR;
104 : 0 : }
105 : :
106 : 17486 : void SAL_CALL installError( sal_Int32 nErrorCode,
107 : : sal_Int32 nMinorCode = TASKHANDLER_NO_ERROR )
108 : : {
109 : 17486 : m_nErrorCode = nErrorCode;
110 : 17486 : m_nMinorCode = nMinorCode;
111 : 17486 : }
112 : :
113 : 156537 : sal_Int32 SAL_CALL getInstalledError()
114 : : {
115 : 156537 : return m_nErrorCode;
116 : : }
117 : :
118 : 156537 : sal_Int32 SAL_CALL getMinorErrorCode()
119 : : {
120 : 156537 : return m_nMinorCode;
121 : : }
122 : :
123 : : com::sun::star::uno::Reference< com::sun::star::ucb::XProgressHandler > SAL_CALL
124 : : getProgressHandler()
125 : : {
126 : : if( ! m_xProgressHandler.is() && m_xCommandEnvironment.is() )
127 : : m_xProgressHandler = m_xCommandEnvironment->getProgressHandler();
128 : :
129 : : return m_xProgressHandler;
130 : : }
131 : :
132 : : com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > SAL_CALL
133 : 93 : getInteractionHandler()
134 : : {
135 [ + - ][ - + ]: 93 : if( ! m_xInteractionHandler.is() && m_xCommandEnvironment.is() )
[ - + ]
136 [ # # ]: 0 : m_xInteractionHandler = m_xCommandEnvironment->getInteractionHandler();
137 : :
138 : 93 : return m_xInteractionHandler;
139 : : }
140 : :
141 : : com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment > SAL_CALL
142 : 156444 : getCommandEnvironment()
143 : : {
144 : 156444 : return m_xCommandEnvironment;
145 : : }
146 : :
147 : : }; // end class TaskHandling
148 : :
149 : :
150 : : typedef boost::unordered_map< sal_Int32,TaskHandling,boost::hash< sal_Int32 > > TaskMap;
151 : :
152 : :
153 : : private:
154 : :
155 : : osl::Mutex m_aMutex;
156 : : sal_Int32 m_nCommandId;
157 : : TaskMap m_aTaskMap;
158 : :
159 : :
160 : : public:
161 : :
162 : : TaskManager();
163 : : virtual ~TaskManager();
164 : :
165 : : void SAL_CALL startTask(
166 : : sal_Int32 CommandId,
167 : : const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& xCommandEnv )
168 : : throw( com::sun::star::ucb::DuplicateCommandIdentifierException );
169 : :
170 : : sal_Int32 SAL_CALL getCommandId( void );
171 : : void SAL_CALL abort( sal_Int32 CommandId );
172 : :
173 : :
174 : : /**
175 : : * The error code may be one of the error codes defined in
176 : : * filerror.hxx.
177 : : * The minor code refines the information given in ErrorCode.
178 : : */
179 : :
180 : : void SAL_CALL clearError();
181 : :
182 : : void SAL_CALL installError( sal_Int32 CommandId,
183 : : sal_Int32 ErrorCode,
184 : : sal_Int32 minorCode = TASKHANDLER_NO_ERROR );
185 : :
186 : : void SAL_CALL retrieveError( sal_Int32 CommandId,
187 : : sal_Int32 &ErrorCode,
188 : : sal_Int32 &minorCode);
189 : :
190 : : /**
191 : : * Deinstalls the task and evaluates a possibly set error code.
192 : : * "endTask" throws in case an error code is set the corresponding exception.
193 : : */
194 : :
195 : : void SAL_CALL endTask( sal_Int32 CommandId,
196 : : // the physical URL of the object
197 : : const rtl::OUString& aUnqPath,
198 : : BaseContent* pContent);
199 : :
200 : :
201 : : /**
202 : : * Handles an interactionrequest
203 : : */
204 : :
205 : : void SAL_CALL handleTask( sal_Int32 CommandId,
206 : : const com::sun::star::uno::Reference< com::sun::star::task::XInteractionRequest >& request );
207 : :
208 : : /**
209 : : * Clears any error which are set on the commandid
210 : : */
211 : :
212 : : void SAL_CALL clearError( sal_Int32 );
213 : :
214 : : };
215 : :
216 : : } // end namespace TaskHandling
217 : :
218 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|