1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <com/sun/star/document/ChangedByOthersRequest.hpp>
#include <com/sun/star/document/LockedDocumentRequest.hpp>
#include <com/sun/star/document/LockedOnSavingRequest.hpp>
#include <com/sun/star/document/LockFileIgnoreRequest.hpp>
#include <com/sun/star/document/LockFileCorruptRequest.hpp>
#include <com/sun/star/document/OwnLockOnDocumentRequest.hpp>
#include <com/sun/star/task/XInteractionApprove.hpp>
#include <com/sun/star/task/XInteractionDisapprove.hpp>
#include <com/sun/star/task/XInteractionAbort.hpp>
#include <com/sun/star/task/XInteractionRequest.hpp>
#include <com/sun/star/task/XInteractionRetry.hpp>
#include <unotools/resmgr.hxx>
#include <vcl/svapp.hxx>
#include <officecfg/Office/Common.hxx>
#include <strings.hrc>
#include "getcontinuations.hxx"
#include "openlocked.hxx"
#include "trylater.hxx"
#include "alreadyopen.hxx"
#include "filechanged.hxx"
#include "lockfailed.hxx"
#include "lockcorrupt.hxx"
#include "iahndl.hxx"
#define UUI_DOC_LOAD_LOCK 0
#define UUI_DOC_OWN_LOAD_LOCK 1
#define UUI_DOC_SAVE_LOCK 2
#define UUI_DOC_OWN_SAVE_LOCK 3
using namespace com::sun::star;
namespace {
void
handleLockedDocumentRequest_(
weld::Window * pParent,
const OUString& aDocumentURL,
const OUString& aInfo,
uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
rContinuations,
sal_uInt16 nMode )
{
uno::Reference< task::XInteractionApprove > xApprove;
uno::Reference< task::XInteractionDisapprove > xDisapprove;
uno::Reference< task::XInteractionAbort > xAbort;
// In case an option to ignore lock and open the file is available
uno::Reference< task::XInteractionRetry > xRetry;
getContinuations(rContinuations, &xApprove, &xDisapprove, &xAbort, &xRetry);
if ( !xApprove.is() || !xDisapprove.is() || !xAbort.is() )
return;
SolarMutexGuard aGuard;
std::locale aResLocale = Translate::Create("uui");
OUString aMessage;
std::vector< OUString > aArguments;
aArguments.push_back( aDocumentURL );
bool bAllowOverride = xRetry.is() && officecfg::Office::Common::Misc::AllowOverrideLocking::get();
sal_Int32 nResult = RET_CANCEL;
if ( nMode == UUI_DOC_LOAD_LOCK )
{
aArguments.push_back( !aInfo.isEmpty()
? aInfo
: Translate::get( STR_UNKNOWNUSER, aResLocale) );
aArguments.push_back( bAllowOverride
? Translate::get( STR_OPENLOCKED_ALLOWIGNORE_MSG, aResLocale )
: "" );
aMessage = Translate::get(STR_OPENLOCKED_MSG, aResLocale);
aMessage = UUIInteractionHelper::replaceMessageWithArguments(
aMessage, aArguments );
OpenLockedQueryBox aDialog(pParent, aResLocale, aMessage, bAllowOverride);
nResult = aDialog.run();
}
else if ( nMode == UUI_DOC_SAVE_LOCK )
{
aArguments.push_back( !aInfo.isEmpty()
? aInfo
: Translate::get( STR_UNKNOWNUSER,
aResLocale ) );
aMessage = Translate::get(bAllowOverride ? STR_OVERWRITE_IGNORELOCK_MSG : STR_TRYLATER_MSG,
aResLocale);
aMessage = UUIInteractionHelper::replaceMessageWithArguments(
aMessage, aArguments );
TryLaterQueryBox aDialog(pParent, aResLocale, aMessage, bAllowOverride);
nResult = aDialog.run();
}
else if ( nMode == UUI_DOC_OWN_LOAD_LOCK ||
nMode == UUI_DOC_OWN_SAVE_LOCK )
{
aArguments.push_back( aInfo );
aMessage = Translate::get(nMode == UUI_DOC_OWN_SAVE_LOCK
? STR_ALREADYOPEN_SAVE_MSG
: STR_ALREADYOPEN_MSG,
aResLocale );
aMessage = UUIInteractionHelper::replaceMessageWithArguments(
aMessage, aArguments );
AlreadyOpenQueryBox aDialog(pParent, aResLocale, aMessage, nMode == UUI_DOC_OWN_SAVE_LOCK);
nResult = aDialog.run();
}
if ( nResult == RET_YES )
xApprove->select();
else if ( nResult == RET_NO )
xDisapprove->select();
else if ( nResult == RET_IGNORE && xRetry.is() )
xRetry->select();
else
xAbort->select();
}
void
handleChangedByOthersRequest_(
weld::Window * pParent,
uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
rContinuations )
{
uno::Reference< task::XInteractionApprove > xApprove;
uno::Reference< task::XInteractionAbort > xAbort;
getContinuations(rContinuations, &xApprove, &xAbort);
if ( !xApprove.is() || !xAbort.is() )
return;
SolarMutexGuard aGuard;
std::locale aResLocale = Translate::Create("uui");
FileChangedQueryBox aDialog(pParent, aResLocale);
sal_Int32 nResult = aDialog.run();
if ( nResult == RET_YES )
xApprove->select();
else
xAbort->select();
}
const sal_uInt16 UUI_DOC_CreateErrDlg = 0;
const sal_uInt16 UUI_DOC_CorruptErrDlg = 1;
void
handleLockFileProblemRequest_(
weld::Window * pParent,
uno::Sequence< uno::Reference< task::XInteractionContinuation > > const &
rContinuations, sal_uInt16 nWhichDlg )
{
uno::Reference< task::XInteractionApprove > xApprove;
uno::Reference< task::XInteractionAbort > xAbort;
getContinuations(rContinuations, &xApprove, &xAbort);
if ( !xApprove.is() || !xAbort.is() )
return;
SolarMutexGuard aGuard;
std::locale aResLocale = Translate::Create("uui");
sal_Int32 nResult;
if (nWhichDlg == UUI_DOC_CreateErrDlg)
{
LockFailedQueryBox aDialog(pParent, aResLocale);
nResult = aDialog.run();
}
else
{
LockCorruptQueryBox aDialog(pParent, aResLocale);
nResult = aDialog.run();
}
if ( nResult == RET_OK )
xApprove->select();
else
xAbort->select();
}
} // namespace
bool
UUIInteractionHelper::handleLockedDocumentRequest(
uno::Reference< task::XInteractionRequest > const & rRequest)
{
uno::Any aAnyRequest(rRequest->getRequest());
document::LockedDocumentRequest aLockedDocumentRequest;
if (aAnyRequest >>= aLockedDocumentRequest )
{
uno::Reference<awt::XWindow> xParent = getParentXWindow();
handleLockedDocumentRequest_(Application::GetFrameWeld(xParent),
aLockedDocumentRequest.DocumentURL,
aLockedDocumentRequest.UserInfo,
rRequest->getContinuations(),
UUI_DOC_LOAD_LOCK);
return true;
}
document::OwnLockOnDocumentRequest aOwnLockOnDocumentRequest;
if (aAnyRequest >>= aOwnLockOnDocumentRequest )
{
uno::Reference<awt::XWindow> xParent = getParentXWindow();
handleLockedDocumentRequest_(Application::GetFrameWeld(xParent),
aOwnLockOnDocumentRequest.DocumentURL,
aOwnLockOnDocumentRequest.TimeInfo,
rRequest->getContinuations(),
aOwnLockOnDocumentRequest.IsStoring
? UUI_DOC_OWN_SAVE_LOCK
: UUI_DOC_OWN_LOAD_LOCK);
return true;
}
document::LockedOnSavingRequest aLockedOnSavingRequest;
if (aAnyRequest >>= aLockedOnSavingRequest )
{
uno::Reference<awt::XWindow> xParent = getParentXWindow();
handleLockedDocumentRequest_(Application::GetFrameWeld(xParent),
aLockedOnSavingRequest.DocumentURL,
aLockedOnSavingRequest.UserInfo,
rRequest->getContinuations(),
UUI_DOC_SAVE_LOCK);
return true;
}
return false;
}
bool
UUIInteractionHelper::handleChangedByOthersRequest(
uno::Reference< task::XInteractionRequest > const & rRequest)
{
uno::Any aAnyRequest(rRequest->getRequest());
document::ChangedByOthersRequest aChangedByOthersRequest;
if (aAnyRequest >>= aChangedByOthersRequest )
{
uno::Reference<awt::XWindow> xParent = getParentXWindow();
handleChangedByOthersRequest_(Application::GetFrameWeld(xParent),
rRequest->getContinuations());
return true;
}
return false;
}
bool
UUIInteractionHelper::handleLockFileProblemRequest(
uno::Reference< task::XInteractionRequest > const & rRequest)
{
uno::Any aAnyRequest(rRequest->getRequest());
document::LockFileIgnoreRequest aLockFileIgnoreRequest;
if (aAnyRequest >>= aLockFileIgnoreRequest )
{
uno::Reference<awt::XWindow> xParent = getParentXWindow();
handleLockFileProblemRequest_(Application::GetFrameWeld(xParent),
rRequest->getContinuations(), UUI_DOC_CreateErrDlg);
return true;
}
document::LockFileCorruptRequest aLockFileCorruptRequest;
if (aAnyRequest >>= aLockFileCorruptRequest )
{
uno::Reference<awt::XWindow> xParent = getParentXWindow();
handleLockFileProblemRequest_(Application::GetFrameWeld(xParent),
rRequest->getContinuations(), UUI_DOC_CorruptErrDlg);
return true;
}
return false;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|