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/OwnLockOnDocumentRequest.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"
32 #include "osl/mutex.hxx"
33 #include "vcl/svapp.hxx"
34 #include "vcl/msgbox.hxx"
37 #include "getcontinuations.hxx"
38 #include "openlocked.hxx"
39 #include "trylater.hxx"
40 #include "alreadyopen.hxx"
41 #include "filechanged.hxx"
42 #include "lockfailed.hxx"
46 #include <boost/scoped_ptr.hpp>
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_(
60 const ::rtl::OUString
& aDocumentURL
,
61 const ::rtl::OUString
& aInfo
,
62 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
65 SAL_THROW((uno::RuntimeException
))
67 uno::Reference
< task::XInteractionApprove
> xApprove
;
68 uno::Reference
< task::XInteractionDisapprove
> xDisapprove
;
69 uno::Reference
< task::XInteractionAbort
> xAbort
;
70 getContinuations(rContinuations
, &xApprove
, &xDisapprove
, &xAbort
);
72 if ( !xApprove
.is() || !xDisapprove
.is() || !xAbort
.is() )
77 SolarMutexGuard aGuard
;
78 boost::scoped_ptr
< ResMgr
> xManager(ResMgr::CreateResMgr("uui"));
82 ::rtl::OUString aMessage
;
83 std::vector
< rtl::OUString
> aArguments
;
84 aArguments
.push_back( aDocumentURL
);
86 sal_Int32 nResult
= RET_CANCEL
;
87 if ( nMode
== UUI_DOC_LOAD_LOCK
)
89 aArguments
.push_back( !aInfo
.isEmpty()
91 : ResId( STR_UNKNOWNUSER
,
92 *xManager
.get() ).toString() );
93 aMessage
= ResId(STR_OPENLOCKED_MSG
, *xManager
.get()).toString();
94 aMessage
= UUIInteractionHelper::replaceMessageWithArguments(
95 aMessage
, aArguments
);
97 boost::scoped_ptr
< OpenLockedQueryBox
> xDialog(new OpenLockedQueryBox(
98 pParent
, xManager
.get(), aMessage
) );
99 nResult
= xDialog
->Execute();
101 else if ( nMode
== UUI_DOC_SAVE_LOCK
)
103 aArguments
.push_back( !aInfo
.isEmpty()
105 : ResId( STR_UNKNOWNUSER
,
106 *xManager
.get() ).toString() );
107 aMessage
= ResId(STR_TRYLATER_MSG
, *xManager
.get()).toString();
108 aMessage
= UUIInteractionHelper::replaceMessageWithArguments(
109 aMessage
, aArguments
);
111 boost::scoped_ptr
< TryLaterQueryBox
> xDialog(
112 new TryLaterQueryBox( pParent
, xManager
.get(), aMessage
) );
113 nResult
= xDialog
->Execute();
115 else if ( nMode
== UUI_DOC_OWN_LOAD_LOCK
||
116 nMode
== UUI_DOC_OWN_SAVE_LOCK
)
118 aArguments
.push_back( aInfo
);
119 aMessage
= ResId(nMode
== UUI_DOC_OWN_SAVE_LOCK
120 ? STR_ALREADYOPEN_SAVE_MSG
121 : STR_ALREADYOPEN_MSG
,
122 *xManager
.get() ).toString();
123 aMessage
= UUIInteractionHelper::replaceMessageWithArguments(
124 aMessage
, aArguments
);
126 boost::scoped_ptr
< AlreadyOpenQueryBox
> xDialog(
127 new AlreadyOpenQueryBox( pParent
,
130 nMode
== UUI_DOC_OWN_SAVE_LOCK
) );
131 nResult
= xDialog
->Execute();
134 if ( nResult
== RET_YES
)
136 else if ( nResult
== RET_NO
)
137 xDisapprove
->select();
141 catch (std::bad_alloc
const &)
143 throw uno::RuntimeException(
144 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
145 uno::Reference
< uno::XInterface
>());
150 handleChangedByOthersRequest_(
152 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
154 SAL_THROW((uno::RuntimeException
))
156 uno::Reference
< task::XInteractionApprove
> xApprove
;
157 uno::Reference
< task::XInteractionAbort
> xAbort
;
158 getContinuations(rContinuations
, &xApprove
, &xAbort
);
160 if ( !xApprove
.is() || !xAbort
.is() )
165 SolarMutexGuard aGuard
;
166 boost::scoped_ptr
< ResMgr
> xManager(ResMgr::CreateResMgr("uui"));
170 boost::scoped_ptr
< FileChangedQueryBox
> xDialog(
171 new FileChangedQueryBox( pParent
, xManager
.get() ) );
172 sal_Int32 nResult
= xDialog
->Execute();
174 if ( nResult
== RET_YES
)
179 catch (std::bad_alloc
const &)
181 throw uno::RuntimeException(
182 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
183 uno::Reference
< uno::XInterface
>());
188 handleLockFileIgnoreRequest_(
190 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
192 SAL_THROW((uno::RuntimeException
))
194 uno::Reference
< task::XInteractionApprove
> xApprove
;
195 uno::Reference
< task::XInteractionAbort
> xAbort
;
196 getContinuations(rContinuations
, &xApprove
, &xAbort
);
198 if ( !xApprove
.is() || !xAbort
.is() )
203 SolarMutexGuard aGuard
;
204 boost::scoped_ptr
< ResMgr
> xManager(ResMgr::CreateResMgr("uui"));
208 boost::scoped_ptr
< LockFailedQueryBox
> xDialog(
209 new LockFailedQueryBox( pParent
, xManager
.get() ) );
210 sal_Int32 nResult
= xDialog
->Execute();
212 if ( nResult
== RET_OK
)
217 catch (std::bad_alloc
const &)
219 throw uno::RuntimeException(
220 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("out of memory")),
221 uno::Reference
< uno::XInterface
>());
228 UUIInteractionHelper::handleLockedDocumentRequest(
229 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
230 SAL_THROW((::com::sun::star::uno::RuntimeException
))
232 uno::Any
aAnyRequest(rRequest
->getRequest());
234 document::LockedDocumentRequest aLockedDocumentRequest
;
235 if (aAnyRequest
>>= aLockedDocumentRequest
)
237 handleLockedDocumentRequest_( getParentProperty(),
238 aLockedDocumentRequest
.DocumentURL
,
239 aLockedDocumentRequest
.UserInfo
,
240 rRequest
->getContinuations(),
245 document::OwnLockOnDocumentRequest aOwnLockOnDocumentRequest
;
246 if (aAnyRequest
>>= aOwnLockOnDocumentRequest
)
248 handleLockedDocumentRequest_( getParentProperty(),
249 aOwnLockOnDocumentRequest
.DocumentURL
,
250 aOwnLockOnDocumentRequest
.TimeInfo
,
251 rRequest
->getContinuations(),
252 aOwnLockOnDocumentRequest
.IsStoring
253 ? UUI_DOC_OWN_SAVE_LOCK
254 : UUI_DOC_OWN_LOAD_LOCK
);
258 document::LockedOnSavingRequest aLockedOnSavingRequest
;
259 if (aAnyRequest
>>= aLockedOnSavingRequest
)
261 handleLockedDocumentRequest_( getParentProperty(),
262 aLockedOnSavingRequest
.DocumentURL
,
263 aLockedOnSavingRequest
.UserInfo
,
264 rRequest
->getContinuations(),
272 UUIInteractionHelper::handleChangedByOthersRequest(
273 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
274 SAL_THROW((uno::RuntimeException
))
276 uno::Any
aAnyRequest(rRequest
->getRequest());
278 document::ChangedByOthersRequest aChangedByOthersRequest
;
279 if (aAnyRequest
>>= aChangedByOthersRequest
)
281 handleChangedByOthersRequest_( getParentProperty(),
282 rRequest
->getContinuations() );
289 UUIInteractionHelper::handleLockFileIgnoreRequest(
290 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
291 SAL_THROW((uno::RuntimeException
))
293 uno::Any
aAnyRequest(rRequest
->getRequest());
295 document::LockFileIgnoreRequest aLockFileIgnoreRequest
;
296 if (aAnyRequest
>>= aLockFileIgnoreRequest
)
298 handleLockFileIgnoreRequest_( getParentProperty(),
299 rRequest
->getContinuations() );
306 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */