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 OUString
& aDocumentURL
,
61 const 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"));
83 std::vector
< 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(OUString("out of memory"),
144 uno::Reference
< uno::XInterface
>());
149 handleChangedByOthersRequest_(
151 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
153 SAL_THROW((uno::RuntimeException
))
155 uno::Reference
< task::XInteractionApprove
> xApprove
;
156 uno::Reference
< task::XInteractionAbort
> xAbort
;
157 getContinuations(rContinuations
, &xApprove
, &xAbort
);
159 if ( !xApprove
.is() || !xAbort
.is() )
164 SolarMutexGuard aGuard
;
165 boost::scoped_ptr
< ResMgr
> xManager(ResMgr::CreateResMgr("uui"));
169 boost::scoped_ptr
< FileChangedQueryBox
> xDialog(
170 new FileChangedQueryBox( pParent
, xManager
.get() ) );
171 sal_Int32 nResult
= xDialog
->Execute();
173 if ( nResult
== RET_YES
)
178 catch (std::bad_alloc
const &)
180 throw uno::RuntimeException(OUString("out of memory"),
181 uno::Reference
< uno::XInterface
>());
186 handleLockFileIgnoreRequest_(
188 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
190 SAL_THROW((uno::RuntimeException
))
192 uno::Reference
< task::XInteractionApprove
> xApprove
;
193 uno::Reference
< task::XInteractionAbort
> xAbort
;
194 getContinuations(rContinuations
, &xApprove
, &xAbort
);
196 if ( !xApprove
.is() || !xAbort
.is() )
201 SolarMutexGuard aGuard
;
202 boost::scoped_ptr
< ResMgr
> xManager(ResMgr::CreateResMgr("uui"));
206 boost::scoped_ptr
< LockFailedQueryBox
> xDialog(
207 new LockFailedQueryBox( pParent
, xManager
.get() ) );
208 sal_Int32 nResult
= xDialog
->Execute();
210 if ( nResult
== RET_OK
)
215 catch (std::bad_alloc
const &)
217 throw uno::RuntimeException(OUString("out of memory"),
218 uno::Reference
< uno::XInterface
>());
225 UUIInteractionHelper::handleLockedDocumentRequest(
226 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
227 SAL_THROW((::com::sun::star::uno::RuntimeException
))
229 uno::Any
aAnyRequest(rRequest
->getRequest());
231 document::LockedDocumentRequest aLockedDocumentRequest
;
232 if (aAnyRequest
>>= aLockedDocumentRequest
)
234 handleLockedDocumentRequest_( getParentProperty(),
235 aLockedDocumentRequest
.DocumentURL
,
236 aLockedDocumentRequest
.UserInfo
,
237 rRequest
->getContinuations(),
242 document::OwnLockOnDocumentRequest aOwnLockOnDocumentRequest
;
243 if (aAnyRequest
>>= aOwnLockOnDocumentRequest
)
245 handleLockedDocumentRequest_( getParentProperty(),
246 aOwnLockOnDocumentRequest
.DocumentURL
,
247 aOwnLockOnDocumentRequest
.TimeInfo
,
248 rRequest
->getContinuations(),
249 aOwnLockOnDocumentRequest
.IsStoring
250 ? UUI_DOC_OWN_SAVE_LOCK
251 : UUI_DOC_OWN_LOAD_LOCK
);
255 document::LockedOnSavingRequest aLockedOnSavingRequest
;
256 if (aAnyRequest
>>= aLockedOnSavingRequest
)
258 handleLockedDocumentRequest_( getParentProperty(),
259 aLockedOnSavingRequest
.DocumentURL
,
260 aLockedOnSavingRequest
.UserInfo
,
261 rRequest
->getContinuations(),
269 UUIInteractionHelper::handleChangedByOthersRequest(
270 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
271 SAL_THROW((uno::RuntimeException
))
273 uno::Any
aAnyRequest(rRequest
->getRequest());
275 document::ChangedByOthersRequest aChangedByOthersRequest
;
276 if (aAnyRequest
>>= aChangedByOthersRequest
)
278 handleChangedByOthersRequest_( getParentProperty(),
279 rRequest
->getContinuations() );
286 UUIInteractionHelper::handleLockFileIgnoreRequest(
287 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
288 SAL_THROW((uno::RuntimeException
))
290 uno::Any
aAnyRequest(rRequest
->getRequest());
292 document::LockFileIgnoreRequest aLockFileIgnoreRequest
;
293 if (aAnyRequest
>>= aLockFileIgnoreRequest
)
295 handleLockFileIgnoreRequest_( getParentProperty(),
296 rRequest
->getContinuations() );
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */