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