LibreOffice Module svx (master) 1
docrecovery.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef INCLUDED_SVX_SOURCE_INC_DOCRECOVERY_HXX
21#define INCLUDED_SVX_SOURCE_INC_DOCRECOVERY_HXX
22
23#include <vcl/weld.hxx>
25
27#include <com/sun/star/task/XStatusIndicator.hpp>
28#include <com/sun/star/frame/XStatusListener.hpp>
29#include <com/sun/star/frame/XDispatch.hpp>
30#include <com/sun/star/lang/XComponent.hpp>
31#include <com/sun/star/uno/XComponentContext.hpp>
32
33
34#define RECOVERY_CMDPART_PROTOCOL "vnd.sun.star.autorecovery:"
35
36#define RECOVERY_CMDPART_DO_EMERGENCY_SAVE "/doEmergencySave"
37#define RECOVERY_CMDPART_DO_RECOVERY "/doAutoRecovery"
38#define RECOVERY_CMDPART_DO_BRINGTOFRONT "/doBringToFront"
39
40inline constexpr OUStringLiteral RECOVERY_CMD_DO_PREPARE_EMERGENCY_SAVE = u"vnd.sun.star.autorecovery:/doPrepareEmergencySave";
41inline constexpr OUStringLiteral RECOVERY_CMD_DO_EMERGENCY_SAVE = u"vnd.sun.star.autorecovery:/doEmergencySave";
42inline constexpr OUStringLiteral RECOVERY_CMD_DO_RECOVERY = u"vnd.sun.star.autorecovery:/doAutoRecovery";
43inline constexpr OUStringLiteral RECOVERY_CMD_DO_ENTRY_BACKUP = u"vnd.sun.star.autorecovery:/doEntryBackup";
44inline constexpr OUStringLiteral RECOVERY_CMD_DO_ENTRY_CLEANUP = u"vnd.sun.star.autorecovery:/doEntryCleanUp";
45
46inline constexpr OUStringLiteral PROP_STATUSINDICATOR = u"StatusIndicator";
47inline constexpr OUStringLiteral PROP_DISPATCHASYNCHRON = u"DispatchAsynchron";
48inline constexpr OUStringLiteral PROP_SAVEPATH = u"SavePath";
49inline constexpr OUStringLiteral PROP_ENTRYID = u"EntryID";
50
51inline constexpr OUStringLiteral STATEPROP_ID = u"ID";
52inline constexpr OUStringLiteral STATEPROP_STATE = u"DocumentState";
53inline constexpr OUStringLiteral STATEPROP_ORGURL = u"OriginalURL";
54inline constexpr OUStringLiteral STATEPROP_TEMPURL = u"TempURL";
55inline constexpr OUStringLiteral STATEPROP_FACTORYURL = u"FactoryURL";
56inline constexpr OUStringLiteral STATEPROP_TEMPLATEURL = u"TemplateURL";
57inline constexpr OUStringLiteral STATEPROP_TITLE = u"Title";
58inline constexpr OUStringLiteral STATEPROP_MODULE = u"Module";
59
60#define RECOVERY_OPERATIONSTATE_START "start"
61#define RECOVERY_OPERATIONSTATE_STOP "stop"
62#define RECOVERY_OPERATIONSTATE_UPDATE "update"
63
64#define DLG_RET_UNKNOWN -1
65#define DLG_RET_OK RET_OK
66#define DLG_RET_CANCEL RET_CANCEL
67#define DLG_RET_OK_AUTOLUNCH 101
68
69
70enum class EDocStates
71{
72 /* TEMP STATES */
73
75 Unknown = 0x000,
77 TryLoadBackup = 0x010,
78 TryLoadOriginal = 0x020,
79
80 /* FINAL STATES */
81
83 Damaged = 0x040,
85 Incomplete = 0x080,
87 Succeeded = 0x200
88};
89namespace o3tl {
90 template<> struct typed_flags<EDocStates> : is_typed_flags<EDocStates, 0x2f0> {};
91}
92
93
94namespace svx{
95 namespace DocRecovery{
96
97
99{
106};
107
108
110{
111 public:
112
114 sal_Int32 ID;
115
117 OUString OrgURL;
118
120 OUString TempURL;
121
123 OUString FactoryURL;
124
126 OUString TemplateURL;
127
129 OUString DisplayName;
130
132 OUString Module;
133
136
139
142
145
146 public:
147
149 : ID (-1 )
152 , ShouldDiscard(false)
153 {}
154};
155
156
157typedef ::std::vector< TURLInfo > TURLList;
158
159
161{
162 public:
163
164 // inform listener about changed items, which should be refreshed
165 virtual void updateItems() = 0;
166
167 // inform listener about ending of the asynchronous recovery operation
168 virtual void end() = 0;
169
170 // TODO
171 virtual void stepNext(TURLInfo* pItem) = 0;
172
173 protected:
175};
176
177
178class RecoveryCore final : public ::cppu::WeakImplHelper< css::frame::XStatusListener >
179{
180
181 // types, const
182 public:
183
184
185 // member
186 private:
187
189 css::uno::Reference< css::uno::XComponentContext > m_xContext;
190
192 css::uno::Reference< css::frame::XDispatch > m_xRealCore;
193
195 css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
196
199
202
211
212
213 // native interface
214 public:
215
216
218 RecoveryCore(css::uno::Reference< css::uno::XComponentContext > xContext,
219 bool bUsedForSaving);
220
221
223 virtual ~RecoveryCore() override;
224
225
227 const css::uno::Reference< css::uno::XComponentContext >& getComponentContext() const;
228
229
232
233
235 static bool isBrokenTempEntry(const TURLInfo& rInfo);
236 void saveBrokenTempEntries(const OUString& sSaveDir);
237 void saveAllTempEntries(const OUString& sSaveDir);
242
243
245 void setProgressHandler(const css::uno::Reference< css::task::XStatusIndicator >& xProgress);
246
247
250
251
254 void doEmergencySave();
255 void doRecovery();
256
257
260
261
262 // uno interface
263 public:
264
265 // css.frame.XStatusListener
266 virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& aEvent) override;
267
268 // css.lang.XEventListener
269 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
270
271
272 // helper
273 private:
274
275
278 void impl_startListening();
279
280
283 void impl_stopListening();
284
285
287 css::util::URL impl_getParsedURL(const OUString& sURL);
288};
289
290class PluginProgress final : public ::cppu::WeakImplHelper<css::task::XStatusIndicator, css::lang::XComponent>
291{
292// member
293private:
296
297// native interface
298public:
299 PluginProgress(weld::ProgressBar* pProgressBar);
300 virtual ~PluginProgress() override;
301
302// uno interface
303public:
304 // XStatusIndicator
305 virtual void SAL_CALL start(const OUString& sText, sal_Int32 nRange) override;
306 virtual void SAL_CALL end() override;
307 virtual void SAL_CALL setText(const OUString& sText) override;
308 virtual void SAL_CALL setValue(sal_Int32 nValue) override;
309 virtual void SAL_CALL reset() override;
310
311 // XComponent
312 virtual void SAL_CALL dispose() override;
313 virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener >& xListener) override;
314 virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener) override;
315};
316
318{
319// member
320private:
322 std::unique_ptr<weld::TreeView> m_xFileListLB;
323 std::unique_ptr<weld::Button> m_xOkBtn;
324
325// interface
326public:
342 SaveDialog(weld::Window* pParent, RecoveryCore* pCore);
343 virtual ~SaveDialog() override;
344
345 DECL_LINK(OKButtonHdl, weld::Button&, void);
346};
347
350{
351 // member
352 private:
353 // @short TODO
355
356 std::unique_ptr<weld::ProgressBar> m_xProgressBar;
357
358 // @short TODO
359 css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
360 // interface
361 public:
376 RecoveryCore* pCore);
377 virtual ~SaveProgressDialog() override;
378
380 virtual short run() override;
381
382 // IRecoveryUpdateListener
383 virtual void updateItems() override;
384 virtual void stepNext(TURLInfo* pItem) override;
385 virtual void end() override;
386};
387
390{
391 // member
392 private:
396
398 css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
400 {
401 E_RECOVERY_PREPARED, // dialog started... recovery prepared
402 E_RECOVERY_IN_PROGRESS, // recovery core still in progress
403 E_RECOVERY_CORE_DONE, // recovery core finished it's task
404 E_RECOVERY_DONE, // user clicked "next" button
405 E_RECOVERY_CANCELED, // user clicked "cancel" button
406 E_RECOVERY_CANCELED_BEFORE, // user clicked "cancel" button before recovery was started
407 E_RECOVERY_CANCELED_AFTERWARDS, // user clicked "cancel" button after recovery was finished
408 E_RECOVERY_HANDLED // the recovery wizard page was shown already... and will be shown now again...
409 };
414
421
422 std::unique_ptr<weld::Label> m_xDescrFT;
423 std::unique_ptr<weld::ProgressBar> m_xProgressBar;
424 std::unique_ptr<weld::TreeView> m_xFileListLB;
425 std::unique_ptr<weld::Button> m_xNextBtn;
426 std::unique_ptr<weld::Button> m_xCancelBtn;
427
428 // member
429 public:
432 RecoveryCore* pCore);
433
434 virtual ~RecoveryDialog() override;
435
436 // IRecoveryUpdateListener
437 virtual void updateItems() override;
438 virtual void stepNext(TURLInfo* pItem) override;
439 virtual void end() override;
440
441 short execute();
442
443 // helper
444 private:
445 DECL_LINK(NextButtonHdl, weld::Button&, void);
446 DECL_LINK(CancelButtonHdl, weld::Button&, void);
447 DECL_LINK(ToggleRowHdl, const weld::TreeView::iter_col&, void);
448
449 OUString impl_getStatusString( const TURLInfo& rInfo ) const;
450 static OUString impl_getStatusImage( const TURLInfo& rInfo );
451 void impl_updateItemDescription(int row, const TriState& rState);
452};
453
454
456{
457// member
458private:
459 OUString m_sSavePath;
463
464 std::unique_ptr<weld::TreeView> m_xFileListLB;
465 std::unique_ptr<weld::Entry> m_xSaveDirED;
466 std::unique_ptr<weld::Button> m_xSaveDirBtn;
467 std::unique_ptr<weld::Button> m_xOkBtn;
468 std::unique_ptr<weld::Button> m_xCancelBtn;
469
470// interface
471public:
472
475 RecoveryCore* pCore,
476 bool bBeforeRecovery);
477 virtual ~BrokenRecoveryDialog() override;
478
480 bool isExecutionNeeded() const;
481
482
484 const OUString& getSaveDirURL() const;
485
486
487// helper
488private:
490 void impl_refresh();
491
492
494 DECL_LINK(SaveButtonHdl, weld::Button&, void);
495
496
498 DECL_LINK(OkButtonHdl, weld::Button&, void);
499
500
502 DECL_LINK(CancelButtonHdl, weld::Button&, void);
503
504
506 void impl_askForSavePath();
507};
508 }
509}
510
511#endif
512
513/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUString & getSaveDirURL() const
TODO.
DECL_LINK(OkButtonHdl, weld::Button &, void)
TODO.
DECL_LINK(CancelButtonHdl, weld::Button &, void)
TODO.
DECL_LINK(SaveButtonHdl, weld::Button &, void)
TODO.
BrokenRecoveryDialog(weld::Window *pParent, RecoveryCore *pCore, bool bBeforeRecovery)
TODO.
std::unique_ptr< weld::Button > m_xSaveDirBtn
std::unique_ptr< weld::Button > m_xCancelBtn
std::unique_ptr< weld::Entry > m_xSaveDirED
std::unique_ptr< weld::Button > m_xOkBtn
std::unique_ptr< weld::TreeView > m_xFileListLB
virtual void stepNext(TURLInfo *pItem)=0
PluginProgress(weld::ProgressBar *pProgressBar)
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
virtual void SAL_CALL setValue(sal_Int32 nValue) override
virtual void SAL_CALL setText(const OUString &sText) override
virtual void SAL_CALL start(const OUString &sText, sal_Int32 nRange) override
virtual void SAL_CALL reset() override
weld::ProgressBar * m_pProgressBar
virtual void SAL_CALL dispose() override
virtual ~PluginProgress() override
virtual void SAL_CALL end() override
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
IRecoveryUpdateListener * m_pListener
TODO.
css::uno::Reference< css::task::XStatusIndicator > m_xProgress
TODO.
TURLList & getURLListAccess()
TODO.
Definition: docrecovery.cxx:77
css::uno::Reference< css::uno::XComponentContext > m_xContext
TODO.
virtual void SAL_CALL disposing(const css::lang::EventObject &aEvent) override
void saveBrokenTempEntries(const OUString &sSaveDir)
virtual ~RecoveryCore() override
TODO.
Definition: docrecovery.cxx:65
virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent &aEvent) override
void setUpdateListener(IRecoveryUpdateListener *pListener)
TODO.
void impl_stopListening()
stop listening on the internal EmergencySave/AutoRecovery core.
static ERecoveryState mapDocState2RecoverState(EDocStates eDocState)
TODO.
void impl_startListening()
starts listening on the internal EmergencySave/AutoRecovery core.
const css::uno::Reference< css::uno::XComponentContext > & getComponentContext() const
TODO.
Definition: docrecovery.cxx:71
bool m_bListenForSaving
knows the reason, why we listen on our internal m_xRealCore member.
css::util::URL impl_getParsedURL(const OUString &sURL)
TODO.
void setProgressHandler(const css::uno::Reference< css::task::XStatusIndicator > &xProgress)
TODO.
void saveAllTempEntries(const OUString &sSaveDir)
static bool isBrokenTempEntry(const TURLInfo &rInfo)
TODO.
Definition: docrecovery.cxx:83
RecoveryCore(css::uno::Reference< css::uno::XComponentContext > xContext, bool bUsedForSaving)
TODO.
Definition: docrecovery.cxx:55
css::uno::Reference< css::frame::XDispatch > m_xRealCore
TODO.
DECL_LINK(NextButtonHdl, weld::Button &, void)
std::unique_ptr< weld::Button > m_xCancelBtn
DECL_LINK(ToggleRowHdl, const weld::TreeView::iter_col &, void)
std::unique_ptr< weld::TreeView > m_xFileListLB
virtual void stepNext(TURLInfo *pItem) override
virtual ~RecoveryDialog() override
RecoveryDialog(weld::Window *pParent, RecoveryCore *pCore)
TODO.
OUString impl_getStatusString(const TURLInfo &rInfo) const
virtual void updateItems() override
std::unique_ptr< weld::Button > m_xNextBtn
static OUString impl_getStatusImage(const TURLInfo &rInfo)
std::unique_ptr< weld::ProgressBar > m_xProgressBar
css::uno::Reference< css::task::XStatusIndicator > m_xProgress
std::unique_ptr< weld::Label > m_xDescrFT
virtual void end() override
void impl_updateItemDescription(int row, const TriState &rState)
DECL_LINK(CancelButtonHdl, weld::Button &, void)
SaveDialog(weld::Window *pParent, RecoveryCore *pCore)
create all child controls of this dialog.
std::unique_ptr< weld::Button > m_xOkBtn
DECL_LINK(OKButtonHdl, weld::Button &, void)
virtual ~SaveDialog() override
std::unique_ptr< weld::TreeView > m_xFileListLB
virtual void updateItems() override
css::uno::Reference< css::task::XStatusIndicator > m_xProgress
std::unique_ptr< weld::ProgressBar > m_xProgressBar
SaveProgressDialog(weld::Window *pParent, RecoveryCore *pCore)
create all child controls of this dialog.
virtual short run() override
start the emergency save operation.
virtual void stepNext(TURLInfo *pItem) override
std::pair< const TreeIter &, int > iter_col
constexpr OUStringLiteral RECOVERY_CMD_DO_PREPARE_EMERGENCY_SAVE
Definition: docrecovery.hxx:40
constexpr OUStringLiteral RECOVERY_CMD_DO_EMERGENCY_SAVE
Definition: docrecovery.hxx:41
constexpr OUStringLiteral STATEPROP_ORGURL
Definition: docrecovery.hxx:53
constexpr OUStringLiteral STATEPROP_TEMPURL
Definition: docrecovery.hxx:54
constexpr OUStringLiteral STATEPROP_TITLE
Definition: docrecovery.hxx:57
constexpr OUStringLiteral RECOVERY_CMD_DO_ENTRY_BACKUP
Definition: docrecovery.hxx:43
constexpr OUStringLiteral STATEPROP_MODULE
Definition: docrecovery.hxx:58
constexpr OUStringLiteral STATEPROP_STATE
Definition: docrecovery.hxx:52
constexpr OUStringLiteral RECOVERY_CMD_DO_RECOVERY
Definition: docrecovery.hxx:42
constexpr OUStringLiteral STATEPROP_ID
Definition: docrecovery.hxx:51
constexpr OUStringLiteral RECOVERY_CMD_DO_ENTRY_CLEANUP
Definition: docrecovery.hxx:44
constexpr OUStringLiteral PROP_DISPATCHASYNCHRON
Definition: docrecovery.hxx:47
constexpr OUStringLiteral PROP_SAVEPATH
Definition: docrecovery.hxx:48
constexpr OUStringLiteral PROP_STATUSINDICATOR
Definition: docrecovery.hxx:46
constexpr OUStringLiteral STATEPROP_TEMPLATEURL
Definition: docrecovery.hxx:56
constexpr OUStringLiteral STATEPROP_FACTORYURL
Definition: docrecovery.hxx:55
constexpr OUStringLiteral PROP_ENTRYID
Definition: docrecovery.hxx:49
EDocStates
Definition: docrecovery.hxx:71
@ Incomplete
the Auto/Emergency saved document is not really up-to-date (some changes can be missing)
@ Succeeded
the Auto/Emergency saved document was processed successfully
@ TryLoadBackup
an action was started (saving/loading) ... Can be interesting later if the process may be was interru...
@ Damaged
the Auto/Emergency saved document isn't usable any longer
float u
sal_Int16 nValue
Definition: fmsrccfg.cxx:81
TriState
Unknown
::std::vector< TURLInfo > TURLList
bool ShouldDiscard
user choice to discard
OUString TemplateURL
may be the document base on a template file !?
ERecoveryState RecoveryState
ui representation for DocState!
OUString FactoryURL
a may be existing factory URL (e.g. for untitled documents)
OUString DisplayName
the pure file name, without path, disc etcpp.
OUString TempURL
the full qualified URL of the temp. file (if it's exists)
EDocStates DocState
state info as e.g. VALID, CORRUPTED, NON EXISTING ...
OUString StandardImageId
standard icon
OUString OrgURL
the full qualified document URL
OUString Module
the application module, where this document was loaded
sal_Int32 ID
unique ID, which is specified by the underlying autorecovery core!