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_(
59 vcl::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 getContinuations(rContinuations
, &xApprove
, &xDisapprove
, &xAbort
);
71 if ( !xApprove
.is() || !xDisapprove
.is() || !xAbort
.is() )
76 SolarMutexGuard aGuard
;
77 boost::scoped_ptr
< ResMgr
> xManager(ResMgr::CreateResMgr("uui"));
82 std::vector
< OUString
> aArguments
;
83 aArguments
.push_back( aDocumentURL
);
85 sal_Int32 nResult
= RET_CANCEL
;
86 if ( nMode
== UUI_DOC_LOAD_LOCK
)
88 aArguments
.push_back( !aInfo
.isEmpty()
90 : ResId( STR_UNKNOWNUSER
,
91 *xManager
.get() ).toString() );
92 aMessage
= ResId(STR_OPENLOCKED_MSG
, *xManager
.get()).toString();
93 aMessage
= UUIInteractionHelper::replaceMessageWithArguments(
94 aMessage
, aArguments
);
96 ScopedVclPtrInstance
< OpenLockedQueryBox
> xDialog(pParent
, xManager
.get(), aMessage
);
97 nResult
= xDialog
->Execute();
99 else if ( nMode
== UUI_DOC_SAVE_LOCK
)
101 aArguments
.push_back( !aInfo
.isEmpty()
103 : ResId( STR_UNKNOWNUSER
,
104 *xManager
.get() ).toString() );
105 aMessage
= ResId(STR_TRYLATER_MSG
, *xManager
.get()).toString();
106 aMessage
= UUIInteractionHelper::replaceMessageWithArguments(
107 aMessage
, aArguments
);
109 ScopedVclPtrInstance
< TryLaterQueryBox
> xDialog( pParent
, xManager
.get(), aMessage
);
110 nResult
= xDialog
->Execute();
112 else if ( nMode
== UUI_DOC_OWN_LOAD_LOCK
||
113 nMode
== UUI_DOC_OWN_SAVE_LOCK
)
115 aArguments
.push_back( aInfo
);
116 aMessage
= ResId(nMode
== UUI_DOC_OWN_SAVE_LOCK
117 ? STR_ALREADYOPEN_SAVE_MSG
118 : STR_ALREADYOPEN_MSG
,
119 *xManager
.get() ).toString();
120 aMessage
= UUIInteractionHelper::replaceMessageWithArguments(
121 aMessage
, aArguments
);
123 ScopedVclPtrInstance
< AlreadyOpenQueryBox
> xDialog( pParent
,
126 nMode
== UUI_DOC_OWN_SAVE_LOCK
);
127 nResult
= xDialog
->Execute();
130 if ( nResult
== RET_YES
)
132 else if ( nResult
== RET_NO
)
133 xDisapprove
->select();
137 catch (std::bad_alloc
const &)
139 throw uno::RuntimeException("out of memory");
144 handleChangedByOthersRequest_(
145 vcl::Window
* pParent
,
146 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
149 uno::Reference
< task::XInteractionApprove
> xApprove
;
150 uno::Reference
< task::XInteractionAbort
> xAbort
;
151 getContinuations(rContinuations
, &xApprove
, &xAbort
);
153 if ( !xApprove
.is() || !xAbort
.is() )
158 SolarMutexGuard aGuard
;
159 boost::scoped_ptr
< ResMgr
> xManager(ResMgr::CreateResMgr("uui"));
163 ScopedVclPtrInstance
< FileChangedQueryBox
> xDialog(pParent
, xManager
.get());
164 sal_Int32 nResult
= xDialog
->Execute();
166 if ( nResult
== RET_YES
)
171 catch (std::bad_alloc
const &)
173 throw uno::RuntimeException("out of memory");
178 handleLockFileIgnoreRequest_(
179 vcl::Window
* pParent
,
180 uno::Sequence
< uno::Reference
< task::XInteractionContinuation
> > const &
183 uno::Reference
< task::XInteractionApprove
> xApprove
;
184 uno::Reference
< task::XInteractionAbort
> xAbort
;
185 getContinuations(rContinuations
, &xApprove
, &xAbort
);
187 if ( !xApprove
.is() || !xAbort
.is() )
192 SolarMutexGuard aGuard
;
193 boost::scoped_ptr
< ResMgr
> xManager(ResMgr::CreateResMgr("uui"));
197 ScopedVclPtrInstance
< LockFailedQueryBox
> xDialog(pParent
, xManager
.get());
198 sal_Int32 nResult
= xDialog
->Execute();
200 if ( nResult
== RET_OK
)
205 catch (std::bad_alloc
const &)
207 throw uno::RuntimeException("out of memory");
214 UUIInteractionHelper::handleLockedDocumentRequest(
215 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
217 uno::Any
aAnyRequest(rRequest
->getRequest());
219 document::LockedDocumentRequest aLockedDocumentRequest
;
220 if (aAnyRequest
>>= aLockedDocumentRequest
)
222 handleLockedDocumentRequest_( getParentProperty(),
223 aLockedDocumentRequest
.DocumentURL
,
224 aLockedDocumentRequest
.UserInfo
,
225 rRequest
->getContinuations(),
230 document::OwnLockOnDocumentRequest aOwnLockOnDocumentRequest
;
231 if (aAnyRequest
>>= aOwnLockOnDocumentRequest
)
233 handleLockedDocumentRequest_( getParentProperty(),
234 aOwnLockOnDocumentRequest
.DocumentURL
,
235 aOwnLockOnDocumentRequest
.TimeInfo
,
236 rRequest
->getContinuations(),
237 aOwnLockOnDocumentRequest
.IsStoring
238 ? UUI_DOC_OWN_SAVE_LOCK
239 : UUI_DOC_OWN_LOAD_LOCK
);
243 document::LockedOnSavingRequest aLockedOnSavingRequest
;
244 if (aAnyRequest
>>= aLockedOnSavingRequest
)
246 handleLockedDocumentRequest_( getParentProperty(),
247 aLockedOnSavingRequest
.DocumentURL
,
248 aLockedOnSavingRequest
.UserInfo
,
249 rRequest
->getContinuations(),
257 UUIInteractionHelper::handleChangedByOthersRequest(
258 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
260 uno::Any
aAnyRequest(rRequest
->getRequest());
262 document::ChangedByOthersRequest aChangedByOthersRequest
;
263 if (aAnyRequest
>>= aChangedByOthersRequest
)
265 handleChangedByOthersRequest_( getParentProperty(),
266 rRequest
->getContinuations() );
273 UUIInteractionHelper::handleLockFileIgnoreRequest(
274 uno::Reference
< task::XInteractionRequest
> const & rRequest
)
276 uno::Any
aAnyRequest(rRequest
->getRequest());
278 document::LockFileIgnoreRequest aLockFileIgnoreRequest
;
279 if (aAnyRequest
>>= aLockFileIgnoreRequest
)
281 handleLockFileIgnoreRequest_( getParentProperty(),
282 rRequest
->getContinuations() );
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */