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 .
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/LockFileCorruptRequest.hpp>
27 #include <com/sun/star/document/OwnLockOnDocumentRequest.hpp>
28 #include <com/sun/star/task/XInteractionApprove.hpp>
29 #include <com/sun/star/task/XInteractionDisapprove.hpp>
30 #include <com/sun/star/task/XInteractionAbort.hpp>
31 #include <com/sun/star/task/XInteractionRequest.hpp>
32 #include <com/sun/star/task/XInteractionRetry.hpp>
34 #include <unotools/resmgr.hxx>
35 #include <vcl/svapp.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"
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
;
58 handleLockedDocumentRequest_(
59 weld::Window
* pParent
,
60 const OUString
& aDocumentURL
,
61 const OUString
& aInfo
,
62 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
66 uno::Reference
< task::XInteractionApprove
> xApprove
;
67 uno::Reference
< task::XInteractionDisapprove
> xDisapprove
;
68 uno::Reference
< task::XInteractionAbort
> xAbort
;
69 // In case an option to ignore lock and open the file is available
70 uno::Reference
< task::XInteractionRetry
> xRetry
;
71 getContinuations(rContinuations
, &xApprove
, &xDisapprove
, &xAbort
, &xRetry
);
73 if ( !xApprove
.is() || !xDisapprove
.is() || !xAbort
.is() )
76 SolarMutexGuard aGuard
;
77 std::locale aResLocale
= Translate::Create("uui");
80 std::vector
< OUString
> aArguments
;
81 aArguments
.push_back( aDocumentURL
);
83 sal_Int32 nResult
= RET_CANCEL
;
84 if ( nMode
== UUI_DOC_LOAD_LOCK
)
86 aArguments
.push_back( !aInfo
.isEmpty()
88 : Translate::get( STR_UNKNOWNUSER
, aResLocale
) );
89 aArguments
.push_back( xRetry
.is()
90 ? Translate::get( STR_OPENLOCKED_ALLOWIGNORE_MSG
, aResLocale
)
92 aMessage
= Translate::get(STR_OPENLOCKED_MSG
, aResLocale
);
93 aMessage
= UUIInteractionHelper::replaceMessageWithArguments(
94 aMessage
, aArguments
);
96 OpenLockedQueryBox
aDialog(pParent
, aResLocale
, aMessage
, xRetry
.is());
97 nResult
= aDialog
.run();
99 else if ( nMode
== UUI_DOC_SAVE_LOCK
)
101 aArguments
.push_back( !aInfo
.isEmpty()
103 : Translate::get( STR_UNKNOWNUSER
,
105 aMessage
= Translate::get(xRetry
.is() ? STR_OVERWRITE_IGNORELOCK_MSG
: STR_TRYLATER_MSG
,
107 aMessage
= UUIInteractionHelper::replaceMessageWithArguments(
108 aMessage
, aArguments
);
110 TryLaterQueryBox
aDialog(pParent
, aResLocale
, aMessage
, xRetry
.is());
111 nResult
= aDialog
.run();
113 else if ( nMode
== UUI_DOC_OWN_LOAD_LOCK
||
114 nMode
== UUI_DOC_OWN_SAVE_LOCK
)
116 aArguments
.push_back( aInfo
);
117 aMessage
= Translate::get(nMode
== UUI_DOC_OWN_SAVE_LOCK
118 ? STR_ALREADYOPEN_SAVE_MSG
119 : STR_ALREADYOPEN_MSG
,
121 aMessage
= UUIInteractionHelper::replaceMessageWithArguments(
122 aMessage
, aArguments
);
124 AlreadyOpenQueryBox
aDialog(pParent
, aResLocale
, aMessage
, nMode
== UUI_DOC_OWN_SAVE_LOCK
);
125 nResult
= aDialog
.run();
128 if ( nResult
== RET_YES
)
130 else if ( nResult
== RET_NO
)
131 xDisapprove
->select();
132 else if ( nResult
== RET_IGNORE
&& xRetry
.is() )
139 handleChangedByOthersRequest_(
140 weld::Window
* pParent
,
141 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
144 uno::Reference
< task::XInteractionApprove
> xApprove
;
145 uno::Reference
< task::XInteractionAbort
> xAbort
;
146 getContinuations(rContinuations
, &xApprove
, &xAbort
);
148 if ( !xApprove
.is() || !xAbort
.is() )
151 SolarMutexGuard aGuard
;
152 std::locale aResLocale
= Translate::Create("uui");
153 FileChangedQueryBox
aDialog(pParent
, aResLocale
);
154 sal_Int32 nResult
= aDialog
.run();
156 if ( nResult
== RET_YES
)
162 const sal_uInt16 UUI_DOC_CreateErrDlg
= 0;
163 const sal_uInt16 UUI_DOC_CorruptErrDlg
= 1;
168 handleLockFileProblemRequest_(
169 weld::Window
* pParent
,
170 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
171 rContinuations
, sal_uInt16 nWhichDlg
)
173 uno::Reference
< task::XInteractionApprove
> xApprove
;
174 uno::Reference
< task::XInteractionAbort
> xAbort
;
175 getContinuations(rContinuations
, &xApprove
, &xAbort
);
177 if ( !xApprove
.is() || !xAbort
.is() )
180 SolarMutexGuard aGuard
;
181 std::locale aResLocale
= Translate::Create("uui");
185 if (nWhichDlg
== UUI_DOC_CreateErrDlg
)
187 LockFailedQueryBox
aDialog(pParent
, aResLocale
);
188 nResult
= aDialog
.run();
192 LockCorruptQueryBox
aDialog(pParent
, aResLocale
);
193 nResult
= aDialog
.run();
196 if ( nResult
== RET_OK
)
205 UUIInteractionHelper::handleLockedDocumentRequest(
206 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
208 uno::Any
aAnyRequest(rRequest
->getRequest());
210 document::LockedDocumentRequest aLockedDocumentRequest
;
211 if (aAnyRequest
>>= aLockedDocumentRequest
)
213 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
214 handleLockedDocumentRequest_(Application::GetFrameWeld(xParent
),
215 aLockedDocumentRequest
.DocumentURL
,
216 aLockedDocumentRequest
.UserInfo
,
217 rRequest
->getContinuations(),
222 document::OwnLockOnDocumentRequest aOwnLockOnDocumentRequest
;
223 if (aAnyRequest
>>= aOwnLockOnDocumentRequest
)
225 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
226 handleLockedDocumentRequest_(Application::GetFrameWeld(xParent
),
227 aOwnLockOnDocumentRequest
.DocumentURL
,
228 aOwnLockOnDocumentRequest
.TimeInfo
,
229 rRequest
->getContinuations(),
230 aOwnLockOnDocumentRequest
.IsStoring
231 ? UUI_DOC_OWN_SAVE_LOCK
232 : UUI_DOC_OWN_LOAD_LOCK
);
236 document::LockedOnSavingRequest aLockedOnSavingRequest
;
237 if (aAnyRequest
>>= aLockedOnSavingRequest
)
239 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
240 handleLockedDocumentRequest_(Application::GetFrameWeld(xParent
),
241 aLockedOnSavingRequest
.DocumentURL
,
242 aLockedOnSavingRequest
.UserInfo
,
243 rRequest
->getContinuations(),
251 UUIInteractionHelper::handleChangedByOthersRequest(
252 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
254 uno::Any
aAnyRequest(rRequest
->getRequest());
256 document::ChangedByOthersRequest aChangedByOthersRequest
;
257 if (aAnyRequest
>>= aChangedByOthersRequest
)
259 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
260 handleChangedByOthersRequest_(Application::GetFrameWeld(xParent
),
261 rRequest
->getContinuations());
269 UUIInteractionHelper::handleLockFileProblemRequest(
270 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
272 uno::Any
aAnyRequest(rRequest
->getRequest());
274 document::LockFileIgnoreRequest aLockFileIgnoreRequest
;
275 if (aAnyRequest
>>= aLockFileIgnoreRequest
)
277 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
278 handleLockFileProblemRequest_(Application::GetFrameWeld(xParent
),
279 rRequest
->getContinuations(), UUI_DOC_CreateErrDlg
);
283 document::LockFileCorruptRequest aLockFileCorruptRequest
;
284 if (aAnyRequest
>>= aLockFileCorruptRequest
)
286 uno::Reference
<awt::XWindow
> xParent
= getParentXWindow();
287 handleLockFileProblemRequest_(Application::GetFrameWeld(xParent
),
288 rRequest
->getContinuations(), UUI_DOC_CorruptErrDlg
);
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */