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/task/XInteractionApprove.hpp>
27 #include <com/sun/star/task/XInteractionDisapprove.hpp>
28 #include <com/sun/star/task/XInteractionAbort.hpp>
29 #include <com/sun/star/task/XInteractionRequest.hpp>
30 #include <com/sun/star/task/XInteractionRetry.hpp>
32 #include <unotools/resmgr.hxx>
33 #include <vcl/svapp.hxx>
34 #include <officecfg/Office/Common.hxx>
36 #include <strings.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"
43 #include "lockcorrupt.hxx"
47 #define UUI_DOC_LOAD_LOCK 0
48 #define UUI_DOC_OWN_LOAD_LOCK 1
49 #define UUI_DOC_SAVE_LOCK 2
50 #define UUI_DOC_OWN_SAVE_LOCK 3
52 using namespace com::sun::star
;
57 handleLockedDocumentRequest_(
58 weld::Window
* pParent
,
59 const OUString
& aDocumentURL
,
60 const OUString
& aInfo
,
61 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
65 uno::Reference
< task::XInteractionApprove
> xApprove
;
66 uno::Reference
< task::XInteractionDisapprove
> xDisapprove
;
67 uno::Reference
< task::XInteractionAbort
> xAbort
;
68 // In case an option to ignore lock and open the file is available
69 uno::Reference
< task::XInteractionRetry
> xRetry
;
70 getContinuations(rContinuations
, &xApprove
, &xDisapprove
, &xAbort
, &xRetry
);
72 if ( !xApprove
.is() || !xDisapprove
.is() || !xAbort
.is() )
75 SolarMutexGuard aGuard
;
76 std::locale aResLocale
= Translate::Create("uui");
79 std::vector
< OUString
> aArguments
;
80 aArguments
.push_back( aDocumentURL
);
82 bool bAllowOverride
= xRetry
.is() && officecfg::Office::Common::Misc::AllowOverrideLocking::get();
84 sal_Int32 nResult
= RET_CANCEL
;
85 if ( nMode
== UUI_DOC_LOAD_LOCK
)
87 aArguments
.push_back( !aInfo
.isEmpty()
89 : Translate::get( STR_UNKNOWNUSER
, aResLocale
) );
90 aArguments
.push_back( bAllowOverride
91 ? Translate::get( STR_OPENLOCKED_ALLOWIGNORE_MSG
, aResLocale
)
93 aMessage
= Translate::get(STR_OPENLOCKED_MSG
, aResLocale
);
94 aMessage
= UUIInteractionHelper::replaceMessageWithArguments(
95 aMessage
, aArguments
);
97 OpenLockedQueryBox
aDialog(pParent
, aResLocale
, aMessage
, bAllowOverride
);
98 nResult
= aDialog
.run();
100 else if ( nMode
== UUI_DOC_SAVE_LOCK
)
102 aArguments
.push_back( !aInfo
.isEmpty()
104 : Translate::get( STR_UNKNOWNUSER
,
106 aMessage
= Translate::get(bAllowOverride
? STR_OVERWRITE_IGNORELOCK_MSG
: STR_TRYLATER_MSG
,
108 aMessage
= UUIInteractionHelper::replaceMessageWithArguments(
109 aMessage
, aArguments
);
111 TryLaterQueryBox
aDialog(pParent
, aResLocale
, aMessage
, bAllowOverride
);
112 nResult
= aDialog
.run();
114 else if ( nMode
== UUI_DOC_OWN_LOAD_LOCK
||
115 nMode
== UUI_DOC_OWN_SAVE_LOCK
)
117 aArguments
.push_back( aInfo
);
118 aMessage
= Translate::get(nMode
== UUI_DOC_OWN_SAVE_LOCK
119 ? STR_ALREADYOPEN_SAVE_MSG
120 : STR_ALREADYOPEN_MSG
,
122 aMessage
= UUIInteractionHelper::replaceMessageWithArguments(
123 aMessage
, aArguments
);
125 AlreadyOpenQueryBox
aDialog(pParent
, aResLocale
, aMessage
, nMode
== UUI_DOC_OWN_SAVE_LOCK
);
126 nResult
= aDialog
.run();
129 if ( nResult
== RET_YES
)
131 else if ( nResult
== RET_NO
)
132 xDisapprove
->select();
133 else if ( nResult
== RET_IGNORE
&& xRetry
.is() )
140 handleChangedByOthersRequest_(
141 weld::Window
* pParent
,
142 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
145 uno::Reference
< task::XInteractionApprove
> xApprove
;
146 uno::Reference
< task::XInteractionAbort
> xAbort
;
147 getContinuations(rContinuations
, &xApprove
, &xAbort
);
149 if ( !xApprove
.is() || !xAbort
.is() )
152 SolarMutexGuard aGuard
;
153 std::locale aResLocale
= Translate::Create("uui");
154 FileChangedQueryBox
aDialog(pParent
, aResLocale
);
155 sal_Int32 nResult
= aDialog
.run();
157 if ( nResult
== RET_YES
)
163 const sal_uInt16 UUI_DOC_CreateErrDlg
= 0;
164 const sal_uInt16 UUI_DOC_CorruptErrDlg
= 1;
169 handleLockFileProblemRequest_(
170 weld::Window
* pParent
,
171 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
172 rContinuations
, sal_uInt16 nWhichDlg
)
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");
186 if (nWhichDlg
== UUI_DOC_CreateErrDlg
)
188 LockFailedQueryBox
aDialog(pParent
, aResLocale
);
189 nResult
= aDialog
.run();
193 LockCorruptQueryBox
aDialog(pParent
, aResLocale
);
194 nResult
= aDialog
.run();
197 if ( nResult
== RET_OK
)
206 UUIInteractionHelper::handleLockedDocumentRequest(
207 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
209 uno::Any
aAnyRequest(rRequest
->getRequest());
211 document::LockedDocumentRequest aLockedDocumentRequest
;
212 if (aAnyRequest
>>= aLockedDocumentRequest
)
214 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
215 handleLockedDocumentRequest_(Application::GetFrameWeld(xParent
),
216 aLockedDocumentRequest
.DocumentURL
,
217 aLockedDocumentRequest
.UserInfo
,
218 rRequest
->getContinuations(),
223 document::OwnLockOnDocumentRequest aOwnLockOnDocumentRequest
;
224 if (aAnyRequest
>>= aOwnLockOnDocumentRequest
)
226 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
227 handleLockedDocumentRequest_(Application::GetFrameWeld(xParent
),
228 aOwnLockOnDocumentRequest
.DocumentURL
,
229 aOwnLockOnDocumentRequest
.TimeInfo
,
230 rRequest
->getContinuations(),
231 aOwnLockOnDocumentRequest
.IsStoring
232 ? UUI_DOC_OWN_SAVE_LOCK
233 : UUI_DOC_OWN_LOAD_LOCK
);
237 document::LockedOnSavingRequest aLockedOnSavingRequest
;
238 if (aAnyRequest
>>= aLockedOnSavingRequest
)
240 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
241 handleLockedDocumentRequest_(Application::GetFrameWeld(xParent
),
242 aLockedOnSavingRequest
.DocumentURL
,
243 aLockedOnSavingRequest
.UserInfo
,
244 rRequest
->getContinuations(),
252 UUIInteractionHelper::handleChangedByOthersRequest(
253 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
255 uno::Any
aAnyRequest(rRequest
->getRequest());
257 document::ChangedByOthersRequest aChangedByOthersRequest
;
258 if (aAnyRequest
>>= aChangedByOthersRequest
)
260 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
261 handleChangedByOthersRequest_(Application::GetFrameWeld(xParent
),
262 rRequest
->getContinuations());
270 UUIInteractionHelper::handleLockFileProblemRequest(
271 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
273 uno::Any
aAnyRequest(rRequest
->getRequest());
275 document::LockFileIgnoreRequest aLockFileIgnoreRequest
;
276 if (aAnyRequest
>>= aLockFileIgnoreRequest
)
278 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
279 handleLockFileProblemRequest_(Application::GetFrameWeld(xParent
),
280 rRequest
->getContinuations(), UUI_DOC_CreateErrDlg
);
284 document::LockFileCorruptRequest aLockFileCorruptRequest
;
285 if (aAnyRequest
>>= aLockFileCorruptRequest
)
287 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
288 handleLockFileProblemRequest_(Application::GetFrameWeld(xParent
),
289 rRequest
->getContinuations(), UUI_DOC_CorruptErrDlg
);
297 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */