bump product version to 5.0.4.1
[LibreOffice.git] / uui / source / iahndl-locking.cxx
blobdb43be75048857db12cf418a2f34703690a6066d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <memory>
22 #include <com/sun/star/document/ChangedByOthersRequest.hpp>
23 #include <com/sun/star/document/LockedDocumentRequest.hpp>
24 #include <com/sun/star/document/LockedOnSavingRequest.hpp>
25 #include <com/sun/star/document/LockFileIgnoreRequest.hpp>
26 #include <com/sun/star/document/OwnLockOnDocumentRequest.hpp>
27 #include <com/sun/star/task/XInteractionApprove.hpp>
28 #include <com/sun/star/task/XInteractionDisapprove.hpp>
29 #include <com/sun/star/task/XInteractionAbort.hpp>
30 #include <com/sun/star/task/XInteractionRequest.hpp>
32 #include <osl/mutex.hxx>
33 #include <vcl/svapp.hxx>
34 #include <vcl/msgbox.hxx>
36 #include "ids.hrc"
37 #include "getcontinuations.hxx"
38 #include "openlocked.hxx"
39 #include "trylater.hxx"
40 #include "alreadyopen.hxx"
41 #include "filechanged.hxx"
42 #include "lockfailed.hxx"
44 #include "iahndl.hxx"
46 #include <boost/scoped_ptr.hpp>
48 #define UUI_DOC_LOAD_LOCK 0
49 #define UUI_DOC_OWN_LOAD_LOCK 1
50 #define UUI_DOC_SAVE_LOCK 2
51 #define UUI_DOC_OWN_SAVE_LOCK 3
53 using namespace com::sun::star;
55 namespace {
57 void
58 handleLockedDocumentRequest_(
59 vcl::Window * pParent,
60 const OUString& aDocumentURL,
61 const OUString& aInfo,
62 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
63 rContinuations,
64 sal_uInt16 nMode )
66 uno::Reference< task::XInteractionApprove > xApprove;
67 uno::Reference< task::XInteractionDisapprove > xDisapprove;
68 uno::Reference< task::XInteractionAbort > xAbort;
69 getContinuations(rContinuations, &xApprove, &xDisapprove, &xAbort);
71 if ( !xApprove.is() || !xDisapprove.is() || !xAbort.is() )
72 return;
74 try
76 SolarMutexGuard aGuard;
77 boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
78 if (!xManager.get())
79 return;
81 OUString aMessage;
82 std::vector< OUString > aArguments;
83 aArguments.push_back( aDocumentURL );
85 sal_Int32 nResult = RET_CANCEL;
86 if ( nMode == UUI_DOC_LOAD_LOCK )
88 aArguments.push_back( !aInfo.isEmpty()
89 ? aInfo
90 : ResId( STR_UNKNOWNUSER,
91 *xManager.get() ).toString() );
92 aMessage = ResId(STR_OPENLOCKED_MSG, *xManager.get()).toString();
93 aMessage = UUIInteractionHelper::replaceMessageWithArguments(
94 aMessage, aArguments );
96 ScopedVclPtrInstance< OpenLockedQueryBox > xDialog(pParent, xManager.get(), aMessage);
97 nResult = xDialog->Execute();
99 else if ( nMode == UUI_DOC_SAVE_LOCK )
101 aArguments.push_back( !aInfo.isEmpty()
102 ? aInfo
103 : ResId( STR_UNKNOWNUSER,
104 *xManager.get() ).toString() );
105 aMessage = ResId(STR_TRYLATER_MSG, *xManager.get()).toString();
106 aMessage = UUIInteractionHelper::replaceMessageWithArguments(
107 aMessage, aArguments );
109 ScopedVclPtrInstance< TryLaterQueryBox > xDialog( pParent, xManager.get(), aMessage );
110 nResult = xDialog->Execute();
112 else if ( nMode == UUI_DOC_OWN_LOAD_LOCK ||
113 nMode == UUI_DOC_OWN_SAVE_LOCK )
115 aArguments.push_back( aInfo );
116 aMessage = ResId(nMode == UUI_DOC_OWN_SAVE_LOCK
117 ? STR_ALREADYOPEN_SAVE_MSG
118 : STR_ALREADYOPEN_MSG,
119 *xManager.get() ).toString();
120 aMessage = UUIInteractionHelper::replaceMessageWithArguments(
121 aMessage, aArguments );
123 ScopedVclPtrInstance< AlreadyOpenQueryBox > xDialog( pParent,
124 xManager.get(),
125 aMessage,
126 nMode == UUI_DOC_OWN_SAVE_LOCK );
127 nResult = xDialog->Execute();
130 if ( nResult == RET_YES )
131 xApprove->select();
132 else if ( nResult == RET_NO )
133 xDisapprove->select();
134 else
135 xAbort->select();
137 catch (std::bad_alloc const &)
139 throw uno::RuntimeException("out of memory");
143 void
144 handleChangedByOthersRequest_(
145 vcl::Window * pParent,
146 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
147 rContinuations )
149 uno::Reference< task::XInteractionApprove > xApprove;
150 uno::Reference< task::XInteractionAbort > xAbort;
151 getContinuations(rContinuations, &xApprove, &xAbort);
153 if ( !xApprove.is() || !xAbort.is() )
154 return;
158 SolarMutexGuard aGuard;
159 boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
160 if (!xManager.get())
161 return;
163 ScopedVclPtrInstance< FileChangedQueryBox > xDialog(pParent, xManager.get());
164 sal_Int32 nResult = xDialog->Execute();
166 if ( nResult == RET_YES )
167 xApprove->select();
168 else
169 xAbort->select();
171 catch (std::bad_alloc const &)
173 throw uno::RuntimeException("out of memory");
177 void
178 handleLockFileIgnoreRequest_(
179 vcl::Window * pParent,
180 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
181 rContinuations )
183 uno::Reference< task::XInteractionApprove > xApprove;
184 uno::Reference< task::XInteractionAbort > xAbort;
185 getContinuations(rContinuations, &xApprove, &xAbort);
187 if ( !xApprove.is() || !xAbort.is() )
188 return;
192 SolarMutexGuard aGuard;
193 boost::scoped_ptr< ResMgr > xManager(ResMgr::CreateResMgr("uui"));
194 if (!xManager.get())
195 return;
197 ScopedVclPtrInstance< LockFailedQueryBox > xDialog(pParent, xManager.get());
198 sal_Int32 nResult = xDialog->Execute();
200 if ( nResult == RET_OK )
201 xApprove->select();
202 else
203 xAbort->select();
205 catch (std::bad_alloc const &)
207 throw uno::RuntimeException("out of memory");
211 } // namespace
213 bool
214 UUIInteractionHelper::handleLockedDocumentRequest(
215 uno::Reference< task::XInteractionRequest > const & rRequest)
217 uno::Any aAnyRequest(rRequest->getRequest());
219 document::LockedDocumentRequest aLockedDocumentRequest;
220 if (aAnyRequest >>= aLockedDocumentRequest )
222 handleLockedDocumentRequest_( getParentProperty(),
223 aLockedDocumentRequest.DocumentURL,
224 aLockedDocumentRequest.UserInfo,
225 rRequest->getContinuations(),
226 UUI_DOC_LOAD_LOCK );
227 return true;
230 document::OwnLockOnDocumentRequest aOwnLockOnDocumentRequest;
231 if (aAnyRequest >>= aOwnLockOnDocumentRequest )
233 handleLockedDocumentRequest_( getParentProperty(),
234 aOwnLockOnDocumentRequest.DocumentURL,
235 aOwnLockOnDocumentRequest.TimeInfo,
236 rRequest->getContinuations(),
237 aOwnLockOnDocumentRequest.IsStoring
238 ? UUI_DOC_OWN_SAVE_LOCK
239 : UUI_DOC_OWN_LOAD_LOCK );
240 return true;
243 document::LockedOnSavingRequest aLockedOnSavingRequest;
244 if (aAnyRequest >>= aLockedOnSavingRequest )
246 handleLockedDocumentRequest_( getParentProperty(),
247 aLockedOnSavingRequest.DocumentURL,
248 aLockedOnSavingRequest.UserInfo,
249 rRequest->getContinuations(),
250 UUI_DOC_SAVE_LOCK );
251 return true;
253 return false;
256 bool
257 UUIInteractionHelper::handleChangedByOthersRequest(
258 uno::Reference< task::XInteractionRequest > const & rRequest)
260 uno::Any aAnyRequest(rRequest->getRequest());
262 document::ChangedByOthersRequest aChangedByOthersRequest;
263 if (aAnyRequest >>= aChangedByOthersRequest )
265 handleChangedByOthersRequest_( getParentProperty(),
266 rRequest->getContinuations() );
267 return true;
269 return false;
272 bool
273 UUIInteractionHelper::handleLockFileIgnoreRequest(
274 uno::Reference< task::XInteractionRequest > const & rRequest)
276 uno::Any aAnyRequest(rRequest->getRequest());
278 document::LockFileIgnoreRequest aLockFileIgnoreRequest;
279 if (aAnyRequest >>= aLockFileIgnoreRequest )
281 handleLockFileIgnoreRequest_( getParentProperty(),
282 rRequest->getContinuations() );
283 return true;
285 return false;
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */