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>
24 #include <o3tl/typed_flags_set.hxx>
25 
26 #include <cppuhelper/implbase.hxx>
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 
40 #define RECOVERY_CMD_DO_PREPARE_EMERGENCY_SAVE "vnd.sun.star.autorecovery:/doPrepareEmergencySave"
41 #define RECOVERY_CMD_DO_EMERGENCY_SAVE "vnd.sun.star.autorecovery:/doEmergencySave"
42 #define RECOVERY_CMD_DO_RECOVERY "vnd.sun.star.autorecovery:/doAutoRecovery"
43 #define RECOVERY_CMD_DO_ENTRY_BACKUP "vnd.sun.star.autorecovery:/doEntryBackup"
44 #define RECOVERY_CMD_DO_ENTRY_CLEANUP "vnd.sun.star.autorecovery:/doEntryCleanUp"
45 
46 #define PROP_STATUSINDICATOR "StatusIndicator"
47 #define PROP_DISPATCHASYNCHRON "DispatchAsynchron"
48 #define PROP_SAVEPATH "SavePath"
49 #define PROP_ENTRYID "EntryID"
50 
51 #define STATEPROP_ID "ID"
52 #define STATEPROP_STATE "DocumentState"
53 #define STATEPROP_ORGURL "OriginalURL"
54 #define STATEPROP_TEMPURL "TempURL"
55 #define STATEPROP_FACTORYURL "FactoryURL"
56 #define STATEPROP_TEMPLATEURL "TemplateURL"
57 #define STATEPROP_TITLE "Title"
58 #define STATEPROP_MODULE "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 
70 enum 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 };
89 namespace o3tl {
90  template<> struct typed_flags<EDocStates> : is_typed_flags<EDocStates, 0x2f0> {};
91 }
92 
93 
94 namespace svx{
95  namespace DocRecovery{
96 
97 
99 {
105 };
106 
107 
108 struct TURLInfo
109 {
110  public:
111 
113  sal_Int32 ID;
114 
116  OUString OrgURL;
117 
119  OUString TempURL;
120 
122  OUString FactoryURL;
123 
125  OUString TemplateURL;
126 
128  OUString DisplayName;
129 
131  OUString Module;
132 
135 
138 
140  OUString StandardImageId;
141 
142  public:
143 
145  : ID (-1 )
146  , DocState (EDocStates::Unknown)
147  , RecoveryState(E_NOT_RECOVERED_YET)
148  {}
149 };
150 
151 
152 typedef ::std::vector< TURLInfo > TURLList;
153 
154 
156 {
157  public:
158 
159  // inform listener about changed items, which should be refreshed
160  virtual void updateItems() = 0;
161 
162  // inform listener about ending of the asynchronous recovery operation
163  virtual void end() = 0;
164 
165  // TODO
166  virtual void stepNext(TURLInfo* pItem) = 0;
167 
168  protected:
170 };
171 
172 
173 class RecoveryCore : public ::cppu::WeakImplHelper< css::frame::XStatusListener >
174 {
175 
176  // types, const
177  public:
178 
179 
180  // member
181  private:
182 
184  css::uno::Reference< css::uno::XComponentContext > m_xContext;
185 
187  css::uno::Reference< css::frame::XDispatch > m_xRealCore;
188 
190  css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
191 
193  TURLList m_lURLs;
194 
197 
205  bool const m_bListenForSaving;
206 
207 
208  // native interface
209  public:
210 
211 
213  RecoveryCore(const css::uno::Reference< css::uno::XComponentContext >& rxContext,
214  bool bUsedForSaving);
215 
216 
218  virtual ~RecoveryCore() override;
219 
220 
222  const css::uno::Reference< css::uno::XComponentContext >& getComponentContext() const;
223 
224 
226  TURLList& getURLListAccess();
227 
228 
230  static bool isBrokenTempEntry(const TURLInfo& rInfo);
231  void saveBrokenTempEntries(const OUString& sSaveDir);
232  void saveAllTempEntries(const OUString& sSaveDir);
236 
237 
239  void setProgressHandler(const css::uno::Reference< css::task::XStatusIndicator >& xProgress);
240 
241 
244 
245 
247  void doEmergencySavePrepare();
248  void doEmergencySave();
249  void doRecovery();
250 
251 
254 
255 
256  // uno interface
257  public:
258 
259  // css.frame.XStatusListener
260  virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& aEvent) override;
261 
262  // css.lang.XEventListener
263  virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
264 
265 
266  // helper
267  private:
268 
269 
272  void impl_startListening();
273 
274 
277  void impl_stopListening();
278 
279 
281  css::util::URL impl_getParsedURL(const OUString& sURL);
282 };
283 
284 class PluginProgress : public ::cppu::WeakImplHelper<css::task::XStatusIndicator, css::lang::XComponent>
285 {
286 // member
287 private:
289  int m_nRange;
290 
291 // native interface
292 public:
293  PluginProgress(weld::ProgressBar* pProgressBar);
294  virtual ~PluginProgress() override;
295 
296 // uno interface
297 public:
298  // XStatusIndicator
299  virtual void SAL_CALL start(const OUString& sText, sal_Int32 nRange) override;
300  virtual void SAL_CALL end() override;
301  virtual void SAL_CALL setText(const OUString& sText) override;
302  virtual void SAL_CALL setValue(sal_Int32 nValue) override;
303  virtual void SAL_CALL reset() override;
304 
305  // XComponent
306  virtual void SAL_CALL dispose() override;
307  virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener >& xListener) override;
308  virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener) override;
309 };
310 
312 {
313 // member
314 private:
316  std::unique_ptr<weld::TreeView> m_xFileListLB;
317  std::unique_ptr<weld::Button> m_xOkBtn;
318 
319 // interface
320 public:
336  SaveDialog(weld::Window* pParent, RecoveryCore* pCore);
337  virtual ~SaveDialog() override;
338 
339  DECL_LINK(OKButtonHdl, weld::Button&, void);
340 };
341 
343  , public IRecoveryUpdateListener
344 {
345  // member
346  private:
347  // @short TODO
349 
350  std::unique_ptr<weld::ProgressBar> m_xProgressBar;
351 
352  // @short TODO
353  css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
354  // interface
355  public:
370  RecoveryCore* pCore);
371  virtual ~SaveProgressDialog() override;
372 
374  virtual short run() override;
375 
376  // IRecoveryUpdateListener
377  virtual void updateItems() override;
378  virtual void stepNext(TURLInfo* pItem) override;
379  virtual void end() override;
380 };
381 
383  , public IRecoveryUpdateListener
384 {
385  // member
386  private:
388  OUString const m_aRecoveryOnlyFinish;
390 
392  css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
394  {
395  E_RECOVERY_PREPARED, // dialog started... recovery prepared
396  E_RECOVERY_IN_PROGRESS, // recovery core still in progress
397  E_RECOVERY_CORE_DONE, // recovery core finished it's task
398  E_RECOVERY_DONE, // user clicked "next" button
399  E_RECOVERY_CANCELED, // user clicked "cancel" button
400  E_RECOVERY_CANCELED_BEFORE, // user clicked "cancel" button before recovery was started
401  E_RECOVERY_CANCELED_AFTERWARDS, // user clicked "cancel" button after recovery was finished
402  E_RECOVERY_HANDLED // the recovery wizard page was shown already... and will be shown now again...
403  };
404  sal_Int32 m_eRecoveryState;
407 
413 
414  std::unique_ptr<weld::Label> m_xDescrFT;
415  std::unique_ptr<weld::ProgressBar> m_xProgressBar;
416  std::unique_ptr<weld::TreeView> m_xFileListLB;
417  std::unique_ptr<weld::Button> m_xNextBtn;
418  std::unique_ptr<weld::Button> m_xCancelBtn;
419 
420  // member
421  public:
423  RecoveryDialog(weld::Window* pParent,
424  RecoveryCore* pCore);
425 
426  virtual ~RecoveryDialog() override;
427 
428  // IRecoveryUpdateListener
429  virtual void updateItems() override;
430  virtual void stepNext(TURLInfo* pItem) override;
431  virtual void end() override;
432 
433  short execute();
434 
435  // helper
436  private:
437  DECL_LINK(NextButtonHdl, weld::Button&, void);
438  DECL_LINK(CancelButtonHdl, weld::Button&, void);
439 
440  OUString impl_getStatusString( const TURLInfo& rInfo ) const;
441  static OUString impl_getStatusImage( const TURLInfo& rInfo );
442 };
443 
444 
446 {
447 // member
448 private:
449  OUString m_sSavePath;
451  bool const m_bBeforeRecovery;
453 
454  std::unique_ptr<weld::TreeView> m_xFileListLB;
455  std::unique_ptr<weld::Entry> m_xSaveDirED;
456  std::unique_ptr<weld::Button> m_xSaveDirBtn;
457  std::unique_ptr<weld::Button> m_xOkBtn;
458  std::unique_ptr<weld::Button> m_xCancelBtn;
459 
460 // interface
461 public:
462 
465  RecoveryCore* pCore,
466  bool bBeforeRecovery);
467  virtual ~BrokenRecoveryDialog() override;
468 
470  bool isExecutionNeeded() const;
471 
472 
474  const OUString& getSaveDirURL() const;
475 
476 
477 // helper
478 private:
480  void impl_refresh();
481 
482 
484  DECL_LINK(SaveButtonHdl, weld::Button&, void);
485 
486 
488  DECL_LINK(OkButtonHdl, weld::Button&, void);
489 
490 
492  DECL_LINK(CancelButtonHdl, weld::Button&, void);
493 
494 
496  void impl_askForSavePath();
497 };
498  }
499 }
500 
501 #endif
502 
503 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SaveDialog(weld::Window *pParent, RecoveryCore *pCore)
create all child controls of this dialog.
virtual ~RecoveryCore() override
TODO.
Definition: docrecovery.cxx:55
virtual void stepNext(TURLInfo *pItem) override
bool const m_bListenForSaving
knows the reason, why we listen on our internal m_xRealCore member.
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent &aEvent) override
OUString const m_aTitleRecoveryInProgress
RecoveryDialog(weld::Window *pParent, RecoveryCore *pCore)
TODO.
OUString OrgURL
the full qualified document URL
EDocStates DocState
state info as e.g. VALID, CORRUPTED, NON EXISTING ...
virtual void SAL_CALL setText(const OUString &sText) override
std::unique_ptr< weld::Button > m_xSaveDirBtn
void saveAllTempEntries(const OUString &sSaveDir)
virtual void updateItems() override
OUString Module
the application module, where this document was loaded
virtual ~PluginProgress() override
weld::ProgressBar * m_pProgressBar
css::uno::Reference< css::task::XStatusIndicator > m_xProgress
TODO.
virtual void SAL_CALL setValue(sal_Int32 nValue) override
OUString StandardImageId
standard icon
Unknown
virtual ~SaveDialog() override
virtual void SAL_CALL start(const OUString &sText, sal_Int32 nRange) override
void saveBrokenTempEntries(const OUString &sSaveDir)
Definition: docrecovery.cxx:90
OUString const m_aRecoveryOnlyFinishDescr
static ERecoveryState mapDocState2RecoverState(EDocStates eDocState)
TODO.
virtual void SAL_CALL disposing(const css::lang::EventObject &aEvent) override
::std::vector< TURLInfo > TURLList
sal_Int16 const nValue
Definition: fmsrccfg.cxx:82
virtual void stepNext(TURLInfo *pItem) override
virtual void SAL_CALL end() override
DECL_LINK(NextButtonHdl, weld::Button &, void)
std::unique_ptr< weld::Button > m_xCancelBtn
OUString impl_getStatusString(const TURLInfo &rInfo) const
virtual ~RecoveryDialog() override
std::unique_ptr< weld::TreeView > m_xFileListLB
virtual void SAL_CALL dispose() override
sal_Int32 ID
unique ID, which is specified by the underlying autorecovery core!
RecoveryCore(const css::uno::Reference< css::uno::XComponentContext > &rxContext, bool bUsedForSaving)
TODO.
Definition: docrecovery.cxx:45
std::unique_ptr< weld::Entry > m_xSaveDirED
std::unique_ptr< weld::ProgressBar > m_xProgressBar
std::unique_ptr< weld::ProgressBar > m_xProgressBar
css::uno::Reference< css::uno::XComponentContext > m_xContext
TODO.
OUString FactoryURL
a may be existing factory URL (e.g. for untitled documents)
default state, if a document was new created or loaded
virtual void updateItems() override
const OUString & getSaveDirURL() const
TODO.
OUString TemplateURL
may be the document base on a template file !?
const css::uno::Reference< css::uno::XComponentContext > & getComponentContext() const
TODO.
Definition: docrecovery.cxx:61
ERecoveryState RecoveryState
ui representation for DocState!
EDocStates
Definition: docrecovery.hxx:70
virtual void stepNext(TURLInfo *pItem)=0
SaveProgressDialog(weld::Window *pParent, RecoveryCore *pCore)
create all child controls of this dialog.
std::unique_ptr< weld::Button > m_xNextBtn
static bool isBrokenTempEntry(const TURLInfo &rInfo)
TODO.
Definition: docrecovery.cxx:73
void impl_startListening()
starts listening on the internal EmergencySave/AutoRecovery core.
css::uno::Reference< css::task::XStatusIndicator > m_xProgress
css::uno::Reference< css::task::XStatusIndicator > m_xProgress
void setUpdateListener(IRecoveryUpdateListener *pListener)
TODO.
BrokenRecoveryDialog(weld::Window *pParent, RecoveryCore *pCore, bool bBeforeRecovery)
TODO.
DECL_LINK(OKButtonHdl, weld::Button &, void)
virtual short run() override
start the emergency save operation.
css::util::URL impl_getParsedURL(const OUString &sURL)
TODO.
std::unique_ptr< weld::Button > m_xCancelBtn
PluginProgress(weld::ProgressBar *pProgressBar)
the Auto/Emergency saved document is not really up-to-date (some changes can be missing) ...
an action was started (saving/loading) ...
virtual void end() override
DECL_LINK(SaveButtonHdl, weld::Button &, void)
TODO.
OUString TempURL
the full qualified URL of the temp. file (if it's exists)
IRecoveryUpdateListener * m_pListener
TODO.
std::unique_ptr< weld::Button > m_xOkBtn
std::unique_ptr< weld::Button > m_xOkBtn
std::unique_ptr< weld::Label > m_xDescrFT
static OUString impl_getStatusImage(const TURLInfo &rInfo)
std::unique_ptr< weld::TreeView > m_xFileListLB
OUString DisplayName
the pure file name, without path, disc etcpp.
virtual void SAL_CALL reset() override
the Auto/Emergency saved document was processed successfully
std::unique_ptr< weld::TreeView > m_xFileListLB
TURLList & getURLListAccess()
TODO.
Definition: docrecovery.cxx:67
void impl_stopListening()
stop listening on the internal EmergencySave/AutoRecovery core.
the Auto/Emergency saved document isn't usable any longer
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
void setProgressHandler(const css::uno::Reference< css::task::XStatusIndicator > &xProgress)
TODO.
css::uno::Reference< css::frame::XDispatch > m_xRealCore
TODO.