1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <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>
33 #include <unotools/resmgr.hxx>
34 #include <vcl/svapp.hxx>
35 #include <officecfg/Office/Common.hxx>
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"
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
54 using namespace com::sun::star
;
58 void handleReloadEditableRequest_(
59 weld::Window
* pParent
, const OUString
& aDocumentURL
,
60 uno::Sequence
<uno::Reference
<task::XInteractionContinuation
>> const& rContinuations
)
62 uno::Reference
<task::XInteractionApprove
> xApprove
;
63 uno::Reference
<task::XInteractionAbort
> xAbort
;
64 getContinuations(rContinuations
, &xApprove
, &xAbort
);
66 if (!xApprove
.is() || !xAbort
.is())
69 SolarMutexGuard aGuard
;
70 std::locale aResLocale
= Translate::Create("uui");
73 std::vector
<OUString
> aArguments
{ aDocumentURL
};
75 aMessage
= Translate::get(STR_RELOADEDITABLE_MSG
, aResLocale
);
76 aMessage
= UUIInteractionHelper::replaceMessageWithArguments(aMessage
, aArguments
);
78 ReloadEditableQueryBox
aDialog(pParent
, aResLocale
, aMessage
);
79 int nResult
= aDialog
.run();
81 if (nResult
== RET_YES
)
88 handleLockedDocumentRequest_(
89 weld::Window
* pParent
,
90 const OUString
& aDocumentURL
,
91 const OUString
& aInfo
,
92 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
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
);
103 if ( !xApprove
.is() || !xDisapprove
.is() || !xAbort
.is() )
106 SolarMutexGuard aGuard
;
107 std::locale aResLocale
= Translate::Create("uui");
110 OUString aHiddenData
;
111 std::vector
< OUString
> aArguments
{ aDocumentURL
};
113 bool bAllowOverride
= xRetry
.is() && officecfg::Office::Common::Misc::AllowOverrideLocking::get();
115 sal_Int32 nResult
= RET_CANCEL
;
116 if ( nMode
== UUI_DOC_LOAD_LOCK
)
118 aArguments
.push_back( !aInfo
.isEmpty()
120 : Translate::get( STR_UNKNOWNUSER
, aResLocale
) );
122 aHiddenData
= Translate::get(STR_OPENLOCKED_HIDDEN_DATA
, aResLocale
);
123 aHiddenData
= UUIInteractionHelper::replaceMessageWithArguments(
124 aHiddenData
, aArguments
);
126 vcl::OpenLockedQueryBox
aDialog(pParent
, aHiddenData
, bAllowOverride
);
127 nResult
= aDialog
.run();
129 else if ( nMode
== UUI_DOC_SAVE_LOCK
)
131 aArguments
.push_back( !aInfo
.isEmpty()
133 : Translate::get( STR_UNKNOWNUSER
,
135 aMessage
= Translate::get(bAllowOverride
? STR_OVERWRITE_IGNORELOCK_MSG
: STR_TRYLATER_MSG
,
137 aMessage
= UUIInteractionHelper::replaceMessageWithArguments(
138 aMessage
, aArguments
);
140 TryLaterQueryBox
aDialog(pParent
, aResLocale
, aMessage
, bAllowOverride
);
141 nResult
= aDialog
.run();
143 else if ( nMode
== UUI_DOC_OWN_LOAD_LOCK
||
144 nMode
== UUI_DOC_OWN_SAVE_LOCK
)
146 aArguments
.push_back( aInfo
);
147 aMessage
= Translate::get(nMode
== UUI_DOC_OWN_SAVE_LOCK
148 ? STR_ALREADYOPEN_SAVE_MSG
149 : STR_ALREADYOPEN_MSG
,
151 aMessage
= UUIInteractionHelper::replaceMessageWithArguments(
152 aMessage
, aArguments
);
154 AlreadyOpenQueryBox
aDialog(pParent
, aResLocale
, aMessage
, nMode
== UUI_DOC_OWN_SAVE_LOCK
);
155 nResult
= aDialog
.run();
158 if ( nResult
== RET_YES
)
160 else if ( nResult
== RET_NO
)
161 xDisapprove
->select();
162 else if ( nResult
== RET_IGNORE
&& xRetry
.is() )
164 else if ( nResult
!= RET_RETRY
)
169 handleChangedByOthersRequest_(
170 weld::Window
* pParent
,
171 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
174 uno::Reference
< task::XInteractionApprove
> xApprove
;
175 uno::Reference
< task::XInteractionAbort
> xAbort
;
176 getContinuations(rContinuations
, &xApprove
, &xAbort
);
178 if ( !xApprove
.is() || !xAbort
.is() )
181 SolarMutexGuard aGuard
;
182 std::locale aResLocale
= Translate::Create("uui");
183 FileChangedQueryBox
aDialog(pParent
, aResLocale
);
184 sal_Int32 nResult
= aDialog
.run();
186 if ( nResult
== RET_YES
)
192 const sal_uInt16 UUI_DOC_CreateErrDlg
= 0;
193 const sal_uInt16 UUI_DOC_CorruptErrDlg
= 1;
198 handleLockFileProblemRequest_(
199 weld::Window
* pParent
,
200 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
201 rContinuations
, sal_uInt16 nWhichDlg
)
203 uno::Reference
< task::XInteractionApprove
> xApprove
;
204 uno::Reference
< task::XInteractionAbort
> xAbort
;
205 getContinuations(rContinuations
, &xApprove
, &xAbort
);
207 if ( !xApprove
.is() || !xAbort
.is() )
210 SolarMutexGuard aGuard
;
211 std::locale aResLocale
= Translate::Create("uui");
215 if (nWhichDlg
== UUI_DOC_CreateErrDlg
)
217 LockFailedQueryBox
aDialog(pParent
, aResLocale
);
218 nResult
= aDialog
.run();
222 LockCorruptQueryBox
aDialog(pParent
, aResLocale
);
223 nResult
= aDialog
.run();
226 if ( nResult
== RET_OK
)
228 else if ( nResult
!= RET_RETRY
)
235 UUIInteractionHelper::handleLockedDocumentRequest(
236 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
238 uno::Any
aAnyRequest(rRequest
->getRequest());
240 document::LockedDocumentRequest aLockedDocumentRequest
;
241 if (aAnyRequest
>>= aLockedDocumentRequest
)
243 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
244 handleLockedDocumentRequest_(Application::GetFrameWeld(xParent
),
245 aLockedDocumentRequest
.DocumentURL
,
246 aLockedDocumentRequest
.UserInfo
,
247 rRequest
->getContinuations(),
252 document::OwnLockOnDocumentRequest aOwnLockOnDocumentRequest
;
253 if (aAnyRequest
>>= aOwnLockOnDocumentRequest
)
255 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
256 handleLockedDocumentRequest_(Application::GetFrameWeld(xParent
),
257 aOwnLockOnDocumentRequest
.DocumentURL
,
258 aOwnLockOnDocumentRequest
.TimeInfo
,
259 rRequest
->getContinuations(),
260 aOwnLockOnDocumentRequest
.IsStoring
261 ? UUI_DOC_OWN_SAVE_LOCK
262 : UUI_DOC_OWN_LOAD_LOCK
);
266 document::LockedOnSavingRequest aLockedOnSavingRequest
;
267 if (aAnyRequest
>>= aLockedOnSavingRequest
)
269 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
270 handleLockedDocumentRequest_(Application::GetFrameWeld(xParent
),
271 aLockedOnSavingRequest
.DocumentURL
,
272 aLockedOnSavingRequest
.UserInfo
,
273 rRequest
->getContinuations(),
281 UUIInteractionHelper::handleChangedByOthersRequest(
282 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
284 uno::Any
aAnyRequest(rRequest
->getRequest());
286 document::ChangedByOthersRequest aChangedByOthersRequest
;
287 if (aAnyRequest
>>= aChangedByOthersRequest
)
289 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
290 handleChangedByOthersRequest_(Application::GetFrameWeld(xParent
),
291 rRequest
->getContinuations());
299 UUIInteractionHelper::handleLockFileProblemRequest(
300 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
302 uno::Any
aAnyRequest(rRequest
->getRequest());
304 document::LockFileIgnoreRequest aLockFileIgnoreRequest
;
305 if (aAnyRequest
>>= aLockFileIgnoreRequest
)
307 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
308 handleLockFileProblemRequest_(Application::GetFrameWeld(xParent
),
309 rRequest
->getContinuations(), UUI_DOC_CreateErrDlg
);
313 document::LockFileCorruptRequest aLockFileCorruptRequest
;
314 if (aAnyRequest
>>= aLockFileCorruptRequest
)
316 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
317 handleLockFileProblemRequest_(Application::GetFrameWeld(xParent
),
318 rRequest
->getContinuations(), UUI_DOC_CorruptErrDlg
);
325 bool UUIInteractionHelper::handleReloadEditableRequest(
326 uno::Reference
<task::XInteractionRequest
> const& rRequest
)
328 uno::Any
aAnyRequest(rRequest
->getRequest());
330 document::ReloadEditableRequest aReloadEditableRequest
;
331 if (aAnyRequest
>>= aReloadEditableRequest
)
333 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
334 handleReloadEditableRequest_(
335 Application::GetFrameWeld(xParent
), aReloadEditableRequest
.DocumentURL
,
336 rRequest
->getContinuations());
344 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */