LibreOffice Module uui (master) 1
iahndl-locking.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <com/sun/star/document/ChangedByOthersRequest.hpp>
21#include <com/sun/star/document/LockedDocumentRequest.hpp>
22#include <com/sun/star/document/LockedOnSavingRequest.hpp>
23#include <com/sun/star/document/LockFileIgnoreRequest.hpp>
24#include <com/sun/star/document/LockFileCorruptRequest.hpp>
25#include <com/sun/star/document/OwnLockOnDocumentRequest.hpp>
26#include <com/sun/star/document/ReloadEditableRequest.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>
31#include <com/sun/star/task/XInteractionRetry.hpp>
32
33#include <unotools/resmgr.hxx>
34#include <vcl/svapp.hxx>
35#include <officecfg/Office/Common.hxx>
36
37#include <strings.hrc>
38#include "getcontinuations.hxx"
39#include "openlocked.hxx"
40#include "trylater.hxx"
41#include "alreadyopen.hxx"
42#include "filechanged.hxx"
43#include "lockfailed.hxx"
44#include "lockcorrupt.hxx"
45#include "reloadeditable.hxx"
46
47#include "iahndl.hxx"
48
49#define UUI_DOC_LOAD_LOCK 0
50#define UUI_DOC_OWN_LOAD_LOCK 1
51#define UUI_DOC_SAVE_LOCK 2
52#define UUI_DOC_OWN_SAVE_LOCK 3
53
54using namespace com::sun::star;
55
56namespace {
57
58void handleReloadEditableRequest_(
59 weld::Window* pParent, const OUString& aDocumentURL,
60 uno::Sequence<uno::Reference<task::XInteractionContinuation>> const& rContinuations)
61{
62 uno::Reference<task::XInteractionApprove> xApprove;
63 uno::Reference<task::XInteractionAbort> xAbort;
64 getContinuations(rContinuations, &xApprove, &xAbort);
65
66 if (!xApprove.is() || !xAbort.is())
67 return;
68
69 SolarMutexGuard aGuard;
70 std::locale aResLocale = Translate::Create("uui");
71
72 OUString aMessage;
73 std::vector<OUString> aArguments { aDocumentURL };
74
75 aMessage = Translate::get(STR_RELOADEDITABLE_MSG, aResLocale);
77
78 ReloadEditableQueryBox aDialog(pParent, aResLocale, aMessage);
79 int nResult = aDialog.run();
80
81 if (nResult == RET_YES)
82 xApprove->select();
83 else
84 xAbort->select();
85}
86
87void
88handleLockedDocumentRequest_(
89 weld::Window * pParent,
90 const OUString& aDocumentURL,
91 const OUString& aInfo,
92 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
93 rContinuations,
94 sal_uInt16 nMode )
95{
96 uno::Reference< task::XInteractionApprove > xApprove;
97 uno::Reference< task::XInteractionDisapprove > xDisapprove;
98 uno::Reference< task::XInteractionAbort > xAbort;
99 // In case an option to ignore lock and open the file is available
100 uno::Reference< task::XInteractionRetry > xRetry;
101 getContinuations(rContinuations, &xApprove, &xDisapprove, &xAbort, &xRetry);
102
103 if ( !xApprove.is() || !xDisapprove.is() || !xAbort.is() )
104 return;
105
106 SolarMutexGuard aGuard;
107 std::locale aResLocale = Translate::Create("uui");
108
109 OUString aMessage;
110 OUString aHiddenData;
111 std::vector< OUString > aArguments { aDocumentURL };
112
113 bool bAllowOverride = xRetry.is() && officecfg::Office::Common::Misc::AllowOverrideLocking::get();
114
115 sal_Int32 nResult = RET_CANCEL;
116 if ( nMode == UUI_DOC_LOAD_LOCK )
117 {
118 aArguments.push_back( !aInfo.isEmpty()
119 ? aInfo
120 : Translate::get( STR_UNKNOWNUSER, aResLocale) );
121
122 aHiddenData = Translate::get(STR_OPENLOCKED_HIDDEN_DATA, aResLocale);
124 aHiddenData, aArguments );
125
126 vcl::OpenLockedQueryBox aDialog(pParent, aHiddenData, bAllowOverride);
127 nResult = aDialog.run();
128 }
129 else if ( nMode == UUI_DOC_SAVE_LOCK )
130 {
131 aArguments.push_back( !aInfo.isEmpty()
132 ? aInfo
133 : Translate::get( STR_UNKNOWNUSER,
134 aResLocale ) );
135 aMessage = Translate::get(bAllowOverride ? STR_OVERWRITE_IGNORELOCK_MSG : STR_TRYLATER_MSG,
136 aResLocale);
138 aMessage, aArguments );
139
140 TryLaterQueryBox aDialog(pParent, aResLocale, aMessage, bAllowOverride);
141 nResult = aDialog.run();
142 }
143 else if ( nMode == UUI_DOC_OWN_LOAD_LOCK ||
144 nMode == UUI_DOC_OWN_SAVE_LOCK )
145 {
146 aArguments.push_back( aInfo );
147 aMessage = Translate::get(nMode == UUI_DOC_OWN_SAVE_LOCK
148 ? STR_ALREADYOPEN_SAVE_MSG
149 : STR_ALREADYOPEN_MSG,
150 aResLocale );
152 aMessage, aArguments );
153
154 AlreadyOpenQueryBox aDialog(pParent, aResLocale, aMessage, nMode == UUI_DOC_OWN_SAVE_LOCK);
155 nResult = aDialog.run();
156 }
157
158 if ( nResult == RET_YES )
159 xApprove->select();
160 else if ( nResult == RET_NO )
161 xDisapprove->select();
162 else if ( nResult == RET_IGNORE && xRetry.is() )
163 xRetry->select();
164 else if ( nResult != RET_RETRY )
165 xAbort->select();
166}
167
168void
169handleChangedByOthersRequest_(
170 weld::Window * pParent,
171 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
172 rContinuations )
173{
174 uno::Reference< task::XInteractionApprove > xApprove;
175 uno::Reference< task::XInteractionAbort > xAbort;
176 getContinuations(rContinuations, &xApprove, &xAbort);
177
178 if ( !xApprove.is() || !xAbort.is() )
179 return;
180
181 SolarMutexGuard aGuard;
182 std::locale aResLocale = Translate::Create("uui");
183 FileChangedQueryBox aDialog(pParent, aResLocale);
184 sal_Int32 nResult = aDialog.run();
185
186 if ( nResult == RET_YES )
187 xApprove->select();
188 else
189 xAbort->select();
190}
191
192const sal_uInt16 UUI_DOC_CreateErrDlg = 0;
193const sal_uInt16 UUI_DOC_CorruptErrDlg = 1;
194
195
196
197void
198handleLockFileProblemRequest_(
199 weld::Window * pParent,
200 uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
201 rContinuations, sal_uInt16 nWhichDlg )
202{
203 uno::Reference< task::XInteractionApprove > xApprove;
204 uno::Reference< task::XInteractionAbort > xAbort;
205 getContinuations(rContinuations, &xApprove, &xAbort);
206
207 if ( !xApprove.is() || !xAbort.is() )
208 return;
209
210 SolarMutexGuard aGuard;
211 std::locale aResLocale = Translate::Create("uui");
212
213 sal_Int32 nResult;
214
215 if (nWhichDlg == UUI_DOC_CreateErrDlg)
216 {
217 LockFailedQueryBox aDialog(pParent, aResLocale);
218 nResult = aDialog.run();
219 }
220 else
221 {
222 LockCorruptQueryBox aDialog(pParent, aResLocale);
223 nResult = aDialog.run();
224 }
225
226 if ( nResult == RET_OK )
227 xApprove->select();
228 else if ( nResult != RET_RETRY )
229 xAbort->select();
230}
231
232} // namespace
233
234bool
236 uno::Reference< task::XInteractionRequest > const & rRequest)
237{
238 uno::Any aAnyRequest(rRequest->getRequest());
239
240 document::LockedDocumentRequest aLockedDocumentRequest;
241 if (aAnyRequest >>= aLockedDocumentRequest )
242 {
243 uno::Reference<awt::XWindow> xParent = getParentXWindow();
244 handleLockedDocumentRequest_(Application::GetFrameWeld(xParent),
245 aLockedDocumentRequest.DocumentURL,
246 aLockedDocumentRequest.UserInfo,
247 rRequest->getContinuations(),
249 return true;
250 }
251
252 document::OwnLockOnDocumentRequest aOwnLockOnDocumentRequest;
253 if (aAnyRequest >>= aOwnLockOnDocumentRequest )
254 {
255 uno::Reference<awt::XWindow> xParent = getParentXWindow();
256 handleLockedDocumentRequest_(Application::GetFrameWeld(xParent),
257 aOwnLockOnDocumentRequest.DocumentURL,
258 aOwnLockOnDocumentRequest.TimeInfo,
259 rRequest->getContinuations(),
260 aOwnLockOnDocumentRequest.IsStoring
263 return true;
264 }
265
266 document::LockedOnSavingRequest aLockedOnSavingRequest;
267 if (aAnyRequest >>= aLockedOnSavingRequest )
268 {
269 uno::Reference<awt::XWindow> xParent = getParentXWindow();
270 handleLockedDocumentRequest_(Application::GetFrameWeld(xParent),
271 aLockedOnSavingRequest.DocumentURL,
272 aLockedOnSavingRequest.UserInfo,
273 rRequest->getContinuations(),
275 return true;
276 }
277 return false;
278}
279
280bool
282 uno::Reference< task::XInteractionRequest > const & rRequest)
283{
284 uno::Any aAnyRequest(rRequest->getRequest());
285
286 document::ChangedByOthersRequest aChangedByOthersRequest;
287 if (aAnyRequest >>= aChangedByOthersRequest )
288 {
289 uno::Reference<awt::XWindow> xParent = getParentXWindow();
290 handleChangedByOthersRequest_(Application::GetFrameWeld(xParent),
291 rRequest->getContinuations());
292 return true;
293 }
294 return false;
295}
296
297
298bool
300 uno::Reference< task::XInteractionRequest > const & rRequest)
301{
302 uno::Any aAnyRequest(rRequest->getRequest());
303
304 document::LockFileIgnoreRequest aLockFileIgnoreRequest;
305 if (aAnyRequest >>= aLockFileIgnoreRequest )
306 {
307 uno::Reference<awt::XWindow> xParent = getParentXWindow();
308 handleLockFileProblemRequest_(Application::GetFrameWeld(xParent),
309 rRequest->getContinuations(), UUI_DOC_CreateErrDlg);
310 return true;
311 }
312
313 document::LockFileCorruptRequest aLockFileCorruptRequest;
314 if (aAnyRequest >>= aLockFileCorruptRequest )
315 {
316 uno::Reference<awt::XWindow> xParent = getParentXWindow();
317 handleLockFileProblemRequest_(Application::GetFrameWeld(xParent),
318 rRequest->getContinuations(), UUI_DOC_CorruptErrDlg);
319 return true;
320 }
321
322 return false;
323}
324
326 uno::Reference<task::XInteractionRequest> const& rRequest)
327{
328 uno::Any aAnyRequest(rRequest->getRequest());
329
330 document::ReloadEditableRequest aReloadEditableRequest;
331 if (aAnyRequest >>= aReloadEditableRequest)
332 {
333 uno::Reference<awt::XWindow> xParent = getParentXWindow();
334 handleReloadEditableRequest_(
335 Application::GetFrameWeld(xParent), aReloadEditableRequest.DocumentURL,
336 rRequest->getContinuations());
337 return true;
338 }
339
340 return false;
341}
342
343
344/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static weld::Window * GetFrameWeld(const css::uno::Reference< css::awt::XWindow > &rWindow)
bool handleReloadEditableRequest(css::uno::Reference< css::task::XInteractionRequest > const &rRequest)
bool handleLockedDocumentRequest(css::uno::Reference< css::task::XInteractionRequest > const &rRequest)
bool handleChangedByOthersRequest(css::uno::Reference< css::task::XInteractionRequest > const &rRequest)
static OUString replaceMessageWithArguments(const OUString &aMessage, std::vector< OUString > const &rArguments)
Definition: iahndl.cxx:222
bool handleLockFileProblemRequest(css::uno::Reference< css::task::XInteractionRequest > const &rRequest)
const css::uno::Reference< css::awt::XWindow > & getParentXWindow() const
Definition: iahndl.cxx:907
virtual short run()
void getContinuations(css::uno::Sequence< css::uno::Reference< css::task::XInteractionContinuation > > const &rContinuations, css::uno::Reference< t1 > *pContinuation1, css::uno::Reference< t2 > *pContinuation2)
#define UUI_DOC_LOAD_LOCK
#define UUI_DOC_SAVE_LOCK
#define UUI_DOC_OWN_LOAD_LOCK
#define UUI_DOC_OWN_SAVE_LOCK
Sequence< PropertyValue > aArguments
std::locale Create(std::string_view aPrefixName, const LanguageTag &rLocale)
OUString get(TranslateId sContextAndId, const std::locale &loc)
RET_OK
RET_CANCEL
RET_NO
RET_IGNORE
RET_RETRY
RET_YES