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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
|
/* -*- 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 .
*/
#ifndef INCLUDED_SVX_SOURCE_INC_DOCRECOVERY_HXX
#define INCLUDED_SVX_SOURCE_INC_DOCRECOVERY_HXX
#include <vcl/dialog.hxx>
#include <vcl/button.hxx>
#include <vcl/fixed.hxx>
#include <vcl/lstbox.hxx>
#include <vcl/tabdlg.hxx>
#include <vcl/tabpage.hxx>
#include <svtools/simptabl.hxx>
#include <vcl/svlbitm.hxx>
#include <svtools/svmedit2.hxx>
#include <vcl/treelistbox.hxx>
#include <o3tl/typed_flags_set.hxx>
#include <cppuhelper/implbase.hxx>
#include <com/sun/star/task/StatusIndicatorFactory.hpp>
#include <com/sun/star/frame/XStatusListener.hpp>
#include <com/sun/star/frame/XDispatch.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#define RECOVERY_CMDPART_PROTOCOL "vnd.sun.star.autorecovery:"
#define RECOVERY_CMDPART_DO_EMERGENCY_SAVE "/doEmergencySave"
#define RECOVERY_CMDPART_DO_RECOVERY "/doAutoRecovery"
#define RECOVERY_CMDPART_DO_BRINGTOFRONT "/doBringToFront"
#define RECOVERY_CMD_DO_PREPARE_EMERGENCY_SAVE "vnd.sun.star.autorecovery:/doPrepareEmergencySave"
#define RECOVERY_CMD_DO_EMERGENCY_SAVE "vnd.sun.star.autorecovery:/doEmergencySave"
#define RECOVERY_CMD_DO_RECOVERY "vnd.sun.star.autorecovery:/doAutoRecovery"
#define RECOVERY_CMD_DO_ENTRY_BACKUP "vnd.sun.star.autorecovery:/doEntryBackup"
#define RECOVERY_CMD_DO_ENTRY_CLEANUP "vnd.sun.star.autorecovery:/doEntryCleanUp"
#define PROP_STATUSINDICATOR "StatusIndicator"
#define PROP_DISPATCHASYNCHRON "DispatchAsynchron"
#define PROP_SAVEPATH "SavePath"
#define PROP_ENTRYID "EntryID"
#define STATEPROP_ID "ID"
#define STATEPROP_STATE "DocumentState"
#define STATEPROP_ORGURL "OriginalURL"
#define STATEPROP_TEMPURL "TempURL"
#define STATEPROP_FACTORYURL "FactoryURL"
#define STATEPROP_TEMPLATEURL "TemplateURL"
#define STATEPROP_TITLE "Title"
#define STATEPROP_MODULE "Module"
#define RECOVERY_OPERATIONSTATE_START "start"
#define RECOVERY_OPERATIONSTATE_STOP "stop"
#define RECOVERY_OPERATIONSTATE_UPDATE "update"
#define DLG_RET_UNKNOWN -1
#define DLG_RET_OK RET_OK
#define DLG_RET_CANCEL RET_CANCEL
#define DLG_RET_OK_AUTOLUNCH 101
enum class EDocStates
{
/* TEMP STATES */
/// default state, if a document was new created or loaded
Unknown = 0x000,
/** an action was started (saving/loading) ... Can be interesting later if the process may be was interrupted by an exception. */
TryLoadBackup = 0x010,
TryLoadOriginal = 0x020,
/* FINAL STATES */
/// the Auto/Emergency saved document isn't usable any longer
Damaged = 0x040,
/// the Auto/Emergency saved document is not really up-to-date (some changes can be missing)
Incomplete = 0x080,
/// the Auto/Emergency saved document was processed successfully
Succeeded = 0x200
};
namespace o3tl {
template<> struct typed_flags<EDocStates> : is_typed_flags<EDocStates, 0x2f0> {};
}
namespace svx{
namespace DocRecovery{
enum ERecoveryState
{
E_SUCCESSFULLY_RECOVERED,
E_ORIGINAL_DOCUMENT_RECOVERED,
E_RECOVERY_FAILED,
E_RECOVERY_IS_IN_PROGRESS,
E_NOT_RECOVERED_YET
};
struct TURLInfo
{
public:
/// unique ID, which is specified by the underlying autorecovery core!
sal_Int32 ID;
/// the full qualified document URL
OUString OrgURL;
/// the full qualified URL of the temp. file (if it's exists)
OUString TempURL;
/// a may be existing factory URL (e.g. for untitled documents)
OUString FactoryURL;
/// may be the document base on a template file !?
OUString TemplateURL;
/// the pure file name, without path, disc etcpp.
OUString DisplayName;
/// the application module, where this document was loaded
OUString Module;
/// state info as e.g. VALID, CORRUPTED, NON EXISTING ...
EDocStates DocState;
/// ui representation for DocState!
ERecoveryState RecoveryState;
/// standard icon
Image StandardImage;
OUString StandardImageId;
public:
TURLInfo()
: ID (-1 )
, DocState (EDocStates::Unknown)
, RecoveryState(E_NOT_RECOVERED_YET)
{}
};
typedef ::std::vector< TURLInfo > TURLList;
class IRecoveryUpdateListener
{
public:
// inform listener about changed items, which should be refreshed
virtual void updateItems() = 0;
// inform listener about starting of the asynchronous recovery operation
virtual void start() = 0;
// inform listener about ending of the asynchronous recovery operation
virtual void end() = 0;
// TODO
virtual void stepNext(TURLInfo* pItem) = 0;
protected:
~IRecoveryUpdateListener() {}
};
class RecoveryCore : public ::cppu::WeakImplHelper< css::frame::XStatusListener >
{
// types, const
public:
// member
private:
/// TODO
css::uno::Reference< css::uno::XComponentContext > m_xContext;
/// TODO
css::uno::Reference< css::frame::XDispatch > m_xRealCore;
/// TODO
css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
/// TODO
TURLList m_lURLs;
/// TODO
IRecoveryUpdateListener* m_pListener;
/** @short knows the reason, why we listen on our internal m_xRealCore
member.
@descr Because we listen for different operations
on the core dispatch implementation, we must know,
which URL we have to use for deregistration!
*/
bool const m_bListenForSaving;
// native interface
public:
/** @short TODO */
RecoveryCore(const css::uno::Reference< css::uno::XComponentContext >& rxContext,
bool bUsedForSaving);
/** @short TODO */
virtual ~RecoveryCore() override;
/** @short TODO */
const css::uno::Reference< css::uno::XComponentContext >& getComponentContext();
/** @short TODO */
TURLList& getURLListAccess();
/** @short TODO */
static bool isBrokenTempEntry(const TURLInfo& rInfo);
void saveBrokenTempEntries(const OUString& sSaveDir);
void saveAllTempEntries(const OUString& sSaveDir);
void forgetBrokenTempEntries();
void forgetAllRecoveryEntries();
void forgetBrokenRecoveryEntries();
/** @short TODO */
void setProgressHandler(const css::uno::Reference< css::task::XStatusIndicator >& xProgress);
/** @short TODO */
void setUpdateListener(IRecoveryUpdateListener* pListener);
/** @short TODO */
void doEmergencySavePrepare();
void doEmergencySave();
void doRecovery();
/** @short TODO */
static ERecoveryState mapDocState2RecoverState(EDocStates eDocState);
// uno interface
public:
// css.frame.XStatusListener
virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& aEvent) override;
// css.lang.XEventListener
virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
// helper
private:
/** @short starts listening on the internal EmergencySave/AutoRecovery core.
*/
void impl_startListening();
/** @short stop listening on the internal EmergencySave/AutoRecovery core.
*/
void impl_stopListening();
/** @short TODO */
css::util::URL impl_getParsedURL(const OUString& sURL);
};
class PluginProgressWindow : public vcl::Window
{
private:
css::uno::Reference< css::lang::XComponent > m_xProgress;
public:
PluginProgressWindow( vcl::Window* pParent ,
const css::uno::Reference< css::lang::XComponent >& xProgress);
virtual ~PluginProgressWindow() override;
virtual void dispose() override;
};
class PluginProgress : public ::cppu::WeakImplHelper< css::task::XStatusIndicator ,
css::lang::XComponent >
{
// member
private:
/** @short TODO */
css::uno::Reference< css::task::XStatusIndicatorFactory > m_xProgressFactory;
css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
VclPtr<PluginProgressWindow> m_pPlugProgressWindow;
// native interface
public:
/** @short TODO */
PluginProgress( vcl::Window* pParent,
const css::uno::Reference< css::uno::XComponentContext >& xContext );
/** @short TODO */
virtual ~PluginProgress() override;
// uno interface
public:
// XStatusIndicator
virtual void SAL_CALL start(const OUString& sText ,
sal_Int32 nRange) override;
virtual void SAL_CALL end() override;
virtual void SAL_CALL setText(const OUString& sText) override;
virtual void SAL_CALL setValue(sal_Int32 nValue) override;
virtual void SAL_CALL reset() override;
// XComponent
virtual void SAL_CALL dispose() override;
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener >& xListener) override;
virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener) override;
};
class SaveDialog : public Dialog
{
// member
private:
VclPtr<ListBox> m_pFileListLB;
VclPtr<OKButton> m_pOkBtn;
RecoveryCore* m_pCore;
// interface
public:
/** @short create all child controls of this dialog.
@descr The dialog isn't shown nor it starts any
action by itself!
@param pParent
can point to a parent window.
If its set to 0, the defmodal-dialog-parent
is used automatically.
@param pCore
provides access to the recovery core service
and the current list of open documents,
which should be shown inside this dialog.
*/
SaveDialog(vcl::Window* pParent, RecoveryCore* pCore);
virtual ~SaveDialog() override;
virtual void dispose() override;
DECL_LINK(OKButtonHdl, Button*, void);
};
class SaveProgressDialog : public ModalDialog
, public IRecoveryUpdateListener
{
// member
private:
VclPtr<vcl::Window> m_pProgrParent;
// @short TODO
RecoveryCore* m_pCore;
// @short TODO
css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
// interface
public:
/** @short create all child controls of this dialog.
@descr The dialog isn't shown nor it starts any
action by itself!
@param pParent
can point to a parent window.
If its set to 0, the defmodal-dialog-parent
is used automatically.
@param pCore
used to start emergency save.
*/
SaveProgressDialog(vcl::Window* pParent,
RecoveryCore* pCore );
virtual ~SaveProgressDialog() override;
virtual void dispose() override;
/** @short start the emergency save operation. */
virtual short Execute() override;
// IRecoveryUpdateListener
virtual void updateItems() override;
virtual void stepNext(TURLInfo* pItem) override;
virtual void start() override;
virtual void end() override;
};
class RecovDocListEntry : public SvLBoxString
{
public:
/** @short TODO */
RecovDocListEntry( const OUString& sText );
/** @short TODO */
virtual void Paint(const Point& rPos, SvTreeListBox& rOutDev, vcl::RenderContext& rRenderContext,
const SvViewDataEntry* pView, const SvTreeListEntry& rEntry) override;
};
class RecovDocList : public SvSimpleTable
{
// member
public:
Image m_aGreenCheckImg;
Image m_aYellowCheckImg;
Image m_aRedCrossImg;
OUString m_aSuccessRecovStr;
OUString m_aOrigDocRecovStr;
OUString m_aRecovFailedStr;
OUString m_aRecovInProgrStr;
OUString m_aNotRecovYetStr;
// interface
public:
/** @short TODO */
RecovDocList(SvSimpleTableContainer& rParent);
/** @short TODO */
virtual void InitEntry(SvTreeListEntry* pEntry,
const OUString& rText,
const Image& rImage1,
const Image& rImage2,
SvLBoxButtonKind eButtonKind) override;
};
class RecoveryDialog : public Dialog
, public IRecoveryUpdateListener
{
// member
private:
VclPtr<FixedText> m_pDescrFT;
VclPtr<vcl::Window> m_pProgrParent;
VclPtr<RecovDocList> m_pFileListLB;
VclPtr<PushButton> m_pNextBtn;
VclPtr<PushButton> m_pCancelBtn;
OUString const m_aTitleRecoveryInProgress;
OUString const m_aRecoveryOnlyFinish;
OUString const m_aRecoveryOnlyFinishDescr;
RecoveryCore* m_pCore;
css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
enum EInternalRecoveryState
{
E_RECOVERY_PREPARED, // dialog started... recovery prepared
E_RECOVERY_IN_PROGRESS, // recovery core still in progress
E_RECOVERY_CORE_DONE, // recovery core finished it's task
E_RECOVERY_DONE, // user clicked "next" button
E_RECOVERY_CANCELED, // user clicked "cancel" button
E_RECOVERY_CANCELED_BEFORE, // user clicked "cancel" button before recovery was started
E_RECOVERY_CANCELED_AFTERWARDS, // user clicked "cancel" button after recovery was finished
E_RECOVERY_HANDLED // the recovery wizard page was shown already... and will be shown now again...
};
sal_Int32 m_eRecoveryState;
bool m_bWaitForCore;
bool m_bWasRecoveryStarted;
// member
public:
/** @short TODO */
RecoveryDialog(vcl::Window* pParent,
RecoveryCore* pCore );
virtual ~RecoveryDialog() override;
virtual void dispose() override;
// IRecoveryUpdateListener
virtual void updateItems() override;
virtual void stepNext(TURLInfo* pItem) override;
virtual void start() override;
virtual void end() override;
short execute();
// helper
private:
/** @short TODO */
DECL_LINK(NextButtonHdl, Button*, void);
DECL_LINK(CancelButtonHdl, Button*, void);
/** @short TODO */
OUString impl_getStatusString( const TURLInfo& rInfo ) const;
};
class BrokenRecoveryDialog : public weld::GenericDialogController
{
// member
private:
OUString m_sSavePath;
RecoveryCore* m_pCore;
bool const m_bBeforeRecovery;
bool m_bExecutionNeeded;
std::unique_ptr<weld::TreeView> m_xFileListLB;
std::unique_ptr<weld::Entry> m_xSaveDirED;
std::unique_ptr<weld::Button> m_xSaveDirBtn;
std::unique_ptr<weld::Button> m_xOkBtn;
std::unique_ptr<weld::Button> m_xCancelBtn;
// interface
public:
/** @short TODO */
BrokenRecoveryDialog(weld::Window* pParent,
RecoveryCore* pCore,
bool bBeforeRecovery);
virtual ~BrokenRecoveryDialog() override;
/** @short TODO */
bool isExecutionNeeded();
/** @short TODO */
const OUString& getSaveDirURL();
// helper
private:
/** @short TODO */
void impl_refresh();
/** @short TODO */
DECL_LINK(SaveButtonHdl, weld::Button&, void);
/** @short TODO */
DECL_LINK(OkButtonHdl, weld::Button&, void);
/** @short TODO */
DECL_LINK(CancelButtonHdl, weld::Button&, void);
/** @short TODO */
void impl_askForSavePath();
};
}
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|