Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / uui / source / iahndl-locking.cxx
blobe7235e5dc4865447abc3554f9fad02f0397fcb10
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
29 #include <memory>
31 #include "com/sun/star/document/ChangedByOthersRequest.hpp"
32 #include "com/sun/star/document/LockedDocumentRequest.hpp"
33 #include "com/sun/star/document/LockedOnSavingRequest.hpp"
34 #include "com/sun/star/document/LockFileIgnoreRequest.hpp"
35 #include "com/sun/star/document/OwnLockOnDocumentRequest.hpp"
36 #include "com/sun/star/task/XInteractionApprove.hpp"
37 #include "com/sun/star/task/XInteractionDisapprove.hpp"
38 #include "com/sun/star/task/XInteractionAbort.hpp"
39 #include "com/sun/star/task/XInteractionRequest.hpp"
41 #include "osl/mutex.hxx"
42 #include "vcl/svapp.hxx"
43 #include "vcl/msgbox.hxx"
45 #include "ids.hrc"
46 #include "getcontinuations.hxx"
47 #include "openlocked.hxx"
48 #include "trylater.hxx"
49 #include "alreadyopen.hxx"
50 #include "filechanged.hxx"
51 #include "lockfailed.hxx"
53 #include "iahndl.hxx"
55 #include <boost/scoped_ptr.hpp>
57 #define UUI_DOC_LOAD_LOCK 0
58 #define UUI_DOC_OWN_LOAD_LOCK 1
59 #define UUI_DOC_SAVE_LOCK 2
60 #define UUI_DOC_OWN_SAVE_LOCK 3
62 using namespace com::sun::star;
64 namespace {
66 void
67 handleLockedDocumentRequest_(
68 Window * pParent,
69 const ::rtl::OUString& aDocumentURL,
70 const ::rtl::OUString& aInfo,
71 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
72 rContinuations,
73 sal_uInt16 nMode )
74 SAL_THROW((uno::RuntimeException))
76 uno::Reference< task::XInteractionApprove > xApprove;
77 uno::Reference< task::XInteractionDisapprove > xDisapprove;
78 uno::Reference< task::XInteractionAbort > xAbort;
79 getContinuations(rContinuations, &xApprove, &xDisapprove, &xAbort);
81 if ( !xApprove.is() || !xDisapprove.is() || !xAbort.is() )
82 return;
84 try
86 SolarMutexGuard aGuard;
87 boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
88 if (!xManager.get())
89 return;
91 ::rtl::OUString aMessage;
92 std::vector< rtl::OUString > aArguments;
93 aArguments.push_back( aDocumentURL );
95 sal_Int32 nResult = RET_CANCEL;
96 if ( nMode == UUI_DOC_LOAD_LOCK )
98 aArguments.push_back( !aInfo.isEmpty()
99 ? aInfo
100 : ResId( STR_UNKNOWNUSER,
101 *xManager.get() ).toString() );
102 aMessage = ResId(STR_OPENLOCKED_MSG, *xManager.get()).toString();
103 aMessage = UUIInteractionHelper::replaceMessageWithArguments(
104 aMessage, aArguments );
106 boost::scoped_ptr< OpenLockedQueryBox > xDialog(new OpenLockedQueryBox(
107 pParent, xManager.get(), aMessage ) );
108 nResult = xDialog->Execute();
110 else if ( nMode == UUI_DOC_SAVE_LOCK )
112 aArguments.push_back( !aInfo.isEmpty()
113 ? aInfo
114 : ResId( STR_UNKNOWNUSER,
115 *xManager.get() ).toString() );
116 aMessage = ResId(STR_TRYLATER_MSG, *xManager.get()).toString();
117 aMessage = UUIInteractionHelper::replaceMessageWithArguments(
118 aMessage, aArguments );
120 boost::scoped_ptr< TryLaterQueryBox > xDialog(
121 new TryLaterQueryBox( pParent, xManager.get(), aMessage ) );
122 nResult = xDialog->Execute();
124 else if ( nMode == UUI_DOC_OWN_LOAD_LOCK ||
125 nMode == UUI_DOC_OWN_SAVE_LOCK )
127 aArguments.push_back( aInfo );
128 aMessage = ResId(nMode == UUI_DOC_OWN_SAVE_LOCK
129 ? STR_ALREADYOPEN_SAVE_MSG
130 : STR_ALREADYOPEN_MSG,
131 *xManager.get() ).toString();
132 aMessage = UUIInteractionHelper::replaceMessageWithArguments(
133 aMessage, aArguments );
135 boost::scoped_ptr< AlreadyOpenQueryBox > xDialog(
136 new AlreadyOpenQueryBox( pParent,
137 xManager.get(),
138 aMessage,
139 nMode == UUI_DOC_OWN_SAVE_LOCK ) );
140 nResult = xDialog->Execute();
143 if ( nResult == RET_YES )
144 xApprove->select();
145 else if ( nResult == RET_NO )
146 xDisapprove->select();
147 else
148 xAbort->select();
150 catch (std::bad_alloc const &)
152 throw uno::RuntimeException(
153 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
154 uno::Reference< uno::XInterface >());
158 void
159 handleChangedByOthersRequest_(
160 Window * pParent,
161 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
162 rContinuations )
163 SAL_THROW((uno::RuntimeException))
165 uno::Reference< task::XInteractionApprove > xApprove;
166 uno::Reference< task::XInteractionAbort > xAbort;
167 getContinuations(rContinuations, &xApprove, &xAbort);
169 if ( !xApprove.is() || !xAbort.is() )
170 return;
174 SolarMutexGuard aGuard;
175 boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
176 if (!xManager.get())
177 return;
179 boost::scoped_ptr< FileChangedQueryBox > xDialog(
180 new FileChangedQueryBox( pParent, xManager.get() ) );
181 sal_Int32 nResult = xDialog->Execute();
183 if ( nResult == RET_YES )
184 xApprove->select();
185 else
186 xAbort->select();
188 catch (std::bad_alloc const &)
190 throw uno::RuntimeException(
191 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
192 uno::Reference< uno::XInterface >());
196 void
197 handleLockFileIgnoreRequest_(
198 Window * pParent,
199 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
200 rContinuations )
201 SAL_THROW((uno::RuntimeException))
203 uno::Reference< task::XInteractionApprove > xApprove;
204 uno::Reference< task::XInteractionAbort > xAbort;
205 getContinuations(rContinuations, &xApprove, &xAbort);
207 if ( !xApprove.is() || !xAbort.is() )
208 return;
212 SolarMutexGuard aGuard;
213 boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
214 if (!xManager.get())
215 return;
217 boost::scoped_ptr< LockFailedQueryBox > xDialog(
218 new LockFailedQueryBox( pParent, xManager.get() ) );
219 sal_Int32 nResult = xDialog->Execute();
221 if ( nResult == RET_OK )
222 xApprove->select();
223 else
224 xAbort->select();
226 catch (std::bad_alloc const &)
228 throw uno::RuntimeException(
229 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
230 uno::Reference< uno::XInterface >());
234 } // namespace
236 bool
237 UUIInteractionHelper::handleLockedDocumentRequest(
238 uno::Reference< task::XInteractionRequest > const & rRequest)
239 SAL_THROW((::com::sun::star::uno::RuntimeException))
241 uno::Any aAnyRequest(rRequest->getRequest());
243 document::LockedDocumentRequest aLockedDocumentRequest;
244 if (aAnyRequest >>= aLockedDocumentRequest )
246 handleLockedDocumentRequest_( getParentProperty(),
247 aLockedDocumentRequest.DocumentURL,
248 aLockedDocumentRequest.UserInfo,
249 rRequest->getContinuations(),
250 UUI_DOC_LOAD_LOCK );
251 return true;
254 document::OwnLockOnDocumentRequest aOwnLockOnDocumentRequest;
255 if (aAnyRequest >>= aOwnLockOnDocumentRequest )
257 handleLockedDocumentRequest_( getParentProperty(),
258 aOwnLockOnDocumentRequest.DocumentURL,
259 aOwnLockOnDocumentRequest.TimeInfo,
260 rRequest->getContinuations(),
261 aOwnLockOnDocumentRequest.IsStoring
262 ? UUI_DOC_OWN_SAVE_LOCK
263 : UUI_DOC_OWN_LOAD_LOCK );
264 return true;
267 document::LockedOnSavingRequest aLockedOnSavingRequest;
268 if (aAnyRequest >>= aLockedOnSavingRequest )
270 handleLockedDocumentRequest_( getParentProperty(),
271 aLockedOnSavingRequest.DocumentURL,
272 aLockedOnSavingRequest.UserInfo,
273 rRequest->getContinuations(),
274 UUI_DOC_SAVE_LOCK );
275 return true;
277 return false;
280 bool
281 UUIInteractionHelper::handleChangedByOthersRequest(
282 uno::Reference< task::XInteractionRequest > const & rRequest)
283 SAL_THROW((uno::RuntimeException))
285 uno::Any aAnyRequest(rRequest->getRequest());
287 document::ChangedByOthersRequest aChangedByOthersRequest;
288 if (aAnyRequest >>= aChangedByOthersRequest )
290 handleChangedByOthersRequest_( getParentProperty(),
291 rRequest->getContinuations() );
292 return true;
294 return false;
297 bool
298 UUIInteractionHelper::handleLockFileIgnoreRequest(
299 uno::Reference< task::XInteractionRequest > const & rRequest)
300 SAL_THROW((uno::RuntimeException))
302 uno::Any aAnyRequest(rRequest->getRequest());
304 document::LockFileIgnoreRequest aLockFileIgnoreRequest;
305 if (aAnyRequest >>= aLockFileIgnoreRequest )
307 handleLockFileIgnoreRequest_( getParentProperty(),
308 rRequest->getContinuations() );
309 return true;
311 return false;
315 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */