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/StatusIndicatorFactory.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 
32 
33 #define RECOVERY_CMDPART_PROTOCOL "vnd.sun.star.autorecovery:"
34 
35 #define RECOVERY_CMDPART_DO_EMERGENCY_SAVE "/doEmergencySave"
36 #define RECOVERY_CMDPART_DO_RECOVERY "/doAutoRecovery"
37 #define RECOVERY_CMDPART_DO_BRINGTOFRONT "/doBringToFront"
38 
39 #define RECOVERY_CMD_DO_PREPARE_EMERGENCY_SAVE "vnd.sun.star.autorecovery:/doPrepareEmergencySave"
40 #define RECOVERY_CMD_DO_EMERGENCY_SAVE "vnd.sun.star.autorecovery:/doEmergencySave"
41 #define RECOVERY_CMD_DO_RECOVERY "vnd.sun.star.autorecovery:/doAutoRecovery"
42 #define RECOVERY_CMD_DO_ENTRY_BACKUP "vnd.sun.star.autorecovery:/doEntryBackup"
43 #define RECOVERY_CMD_DO_ENTRY_CLEANUP "vnd.sun.star.autorecovery:/doEntryCleanUp"
44 
45 #define PROP_STATUSINDICATOR "StatusIndicator"
46 #define PROP_DISPATCHASYNCHRON "DispatchAsynchron"
47 #define PROP_SAVEPATH "SavePath"
48 #define PROP_ENTRYID "EntryID"
49 
50 #define STATEPROP_ID "ID"
51 #define STATEPROP_STATE "DocumentState"
52 #define STATEPROP_ORGURL "OriginalURL"
53 #define STATEPROP_TEMPURL "TempURL"
54 #define STATEPROP_FACTORYURL "FactoryURL"
55 #define STATEPROP_TEMPLATEURL "TemplateURL"
56 #define STATEPROP_TITLE "Title"
57 #define STATEPROP_MODULE "Module"
58 
59 #define RECOVERY_OPERATIONSTATE_START "start"
60 #define RECOVERY_OPERATIONSTATE_STOP "stop"
61 #define RECOVERY_OPERATIONSTATE_UPDATE "update"
62 
63 #define DLG_RET_UNKNOWN -1
64 #define DLG_RET_OK RET_OK
65 #define DLG_RET_CANCEL RET_CANCEL
66 #define DLG_RET_OK_AUTOLUNCH 101
67 
68 
69 enum class EDocStates
70 {
71  /* TEMP STATES */
72 
74  Unknown = 0x000,
76  TryLoadBackup = 0x010,
77  TryLoadOriginal = 0x020,
78 
79  /* FINAL STATES */
80 
82  Damaged = 0x040,
84  Incomplete = 0x080,
86  Succeeded = 0x200
87 };
88 namespace o3tl {
89  template<> struct typed_flags<EDocStates> : is_typed_flags<EDocStates, 0x2f0> {};
90 }
91 
92 
93 namespace svx{
94  namespace DocRecovery{
95 
96 
98 {
104 };
105 
106 
107 struct TURLInfo
108 {
109  public:
110 
112  sal_Int32 ID;
113 
115  OUString OrgURL;
116 
118  OUString TempURL;
119 
121  OUString FactoryURL;
122 
124  OUString TemplateURL;
125 
127  OUString DisplayName;
128 
130  OUString Module;
131 
134 
137 
139  OUString StandardImageId;
140 
141  public:
142 
144  : ID (-1 )
145  , DocState (EDocStates::Unknown)
146  , RecoveryState(E_NOT_RECOVERED_YET)
147  {}
148 };
149 
150 
151 typedef ::std::vector< TURLInfo > TURLList;
152 
153 
155 {
156  public:
157 
158  // inform listener about changed items, which should be refreshed
159  virtual void updateItems() = 0;
160 
161  // inform listener about ending of the asynchronous recovery operation
162  virtual void end() = 0;
163 
164  // TODO
165  virtual void stepNext(TURLInfo* pItem) = 0;
166 
167  protected:
169 };
170 
171 
172 class RecoveryCore : public ::cppu::WeakImplHelper< css::frame::XStatusListener >
173 {
174 
175  // types, const
176  public:
177 
178 
179  // member
180  private:
181 
183  css::uno::Reference< css::uno::XComponentContext > m_xContext;
184 
186  css::uno::Reference< css::frame::XDispatch > m_xRealCore;
187 
189  css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
190 
192  TURLList m_lURLs;
193 
196 
204  bool const m_bListenForSaving;
205 
206 
207  // native interface
208  public:
209 
210 
212  RecoveryCore(const css::uno::Reference< css::uno::XComponentContext >& rxContext,
213  bool bUsedForSaving);
214 
215 
217  virtual ~RecoveryCore() override;
218 
219 
221  const css::uno::Reference< css::uno::XComponentContext >& getComponentContext() const;
222 
223 
225  TURLList& getURLListAccess();
226 
227 
229  static bool isBrokenTempEntry(const TURLInfo& rInfo);
230  void saveBrokenTempEntries(const OUString& sSaveDir);
231  void saveAllTempEntries(const OUString& sSaveDir);
235 
236 
238  void setProgressHandler(const css::uno::Reference< css::task::XStatusIndicator >& xProgress);
239 
240 
243 
244 
246  void doEmergencySavePrepare();
247  void doEmergencySave();
248  void doRecovery();
249 
250 
253 
254 
255  // uno interface
256  public:
257 
258  // css.frame.XStatusListener
259  virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& aEvent) override;
260 
261  // css.lang.XEventListener
262  virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
263 
264 
265  // helper
266  private:
267 
268 
271  void impl_startListening();
272 
273 
276  void impl_stopListening();
277 
278 
280  css::util::URL impl_getParsedURL(const OUString& sURL);
281 };
282 
283 class PluginProgress : public ::cppu::WeakImplHelper<css::task::XStatusIndicator, css::lang::XComponent>
284 {
285 // member
286 private:
288  int m_nRange;
289 
290 // native interface
291 public:
292  PluginProgress(weld::ProgressBar* pProgressBar);
293  virtual ~PluginProgress() override;
294 
295 // uno interface
296 public:
297  // XStatusIndicator
298  virtual void SAL_CALL start(const OUString& sText, sal_Int32 nRange) override;
299  virtual void SAL_CALL end() override;
300  virtual void SAL_CALL setText(const OUString& sText) override;
301  virtual void SAL_CALL setValue(sal_Int32 nValue) override;
302  virtual void SAL_CALL reset() override;
303 
304  // XComponent
305  virtual void SAL_CALL dispose() override;
306  virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener >& xListener) override;
307  virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener) override;
308 };
309 
311 {
312 // member
313 private:
315  std::unique_ptr<weld::TreeView> m_xFileListLB;
316  std::unique_ptr<weld::Button> m_xOkBtn;
317 
318 // interface
319 public:
335  SaveDialog(weld::Window* pParent, RecoveryCore* pCore);
336  virtual ~SaveDialog() override;
337 
338  DECL_LINK(OKButtonHdl, weld::Button&, void);
339 };
340 
342  , public IRecoveryUpdateListener
343 {
344  // member
345  private:
346  // @short TODO
348 
349  std::unique_ptr<weld::ProgressBar> m_xProgressBar;
350 
351  // @short TODO
352  css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
353  // interface
354  public:
369  RecoveryCore* pCore);
370  virtual ~SaveProgressDialog() override;
371 
373  virtual short run() override;
374 
375  // IRecoveryUpdateListener
376  virtual void updateItems() override;
377  virtual void stepNext(TURLInfo* pItem) override;
378  virtual void end() override;
379 };
380 
382  , public IRecoveryUpdateListener
383 {
384  // member
385  private:
387  OUString const m_aRecoveryOnlyFinish;
389 
391  css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
393  {
394  E_RECOVERY_PREPARED, // dialog started... recovery prepared
395  E_RECOVERY_IN_PROGRESS, // recovery core still in progress
396  E_RECOVERY_CORE_DONE, // recovery core finished it's task
397  E_RECOVERY_DONE, // user clicked "next" button
398  E_RECOVERY_CANCELED, // user clicked "cancel" button
399  E_RECOVERY_CANCELED_BEFORE, // user clicked "cancel" button before recovery was started
400  E_RECOVERY_CANCELED_AFTERWARDS, // user clicked "cancel" button after recovery was finished
401  E_RECOVERY_HANDLED // the recovery wizard page was shown already... and will be shown now again...
402  };
403  sal_Int32 m_eRecoveryState;
406 
412 
413  std::unique_ptr<weld::Label> m_xDescrFT;
414  std::unique_ptr<weld::ProgressBar> m_xProgressBar;
415  std::unique_ptr<weld::TreeView> m_xFileListLB;
416  std::unique_ptr<weld::Button> m_xNextBtn;
417  std::unique_ptr<weld::Button> m_xCancelBtn;
418 
419  // member
420  public:
422  RecoveryDialog(weld::Window* pParent,
423  RecoveryCore* pCore);
424 
425  virtual ~RecoveryDialog() override;
426 
427  // IRecoveryUpdateListener
428  virtual void updateItems() override;
429  virtual void stepNext(TURLInfo* pItem) override;
430  virtual void end() override;
431 
432  short execute();
433 
434  // helper
435  private:
436  DECL_LINK(NextButtonHdl, weld::Button&, void);
437  DECL_LINK(CancelButtonHdl, weld::Button&, void);
438 
439  OUString impl_getStatusString( const TURLInfo& rInfo ) const;
440  static OUString impl_getStatusImage( const TURLInfo& rInfo );
441 };
442 
443 
445 {
446 // member
447 private:
448  OUString m_sSavePath;
450  bool const m_bBeforeRecovery;
452 
453  std::unique_ptr<weld::TreeView> m_xFileListLB;
454  std::unique_ptr<weld::Entry> m_xSaveDirED;
455  std::unique_ptr<weld::Button> m_xSaveDirBtn;
456  std::unique_ptr<weld::Button> m_xOkBtn;
457  std::unique_ptr<weld::Button> m_xCancelBtn;
458 
459 // interface
460 public:
461 
464  RecoveryCore* pCore,
465  bool bBeforeRecovery);
466  virtual ~BrokenRecoveryDialog() override;
467 
469  bool isExecutionNeeded() const;
470 
471 
473  const OUString& getSaveDirURL() const;
474 
475 
476 // helper
477 private:
479  void impl_refresh();
480 
481 
483  DECL_LINK(SaveButtonHdl, weld::Button&, void);
484 
485 
487  DECL_LINK(OkButtonHdl, weld::Button&, void);
488 
489 
491  DECL_LINK(CancelButtonHdl, weld::Button&, void);
492 
493 
495  void impl_askForSavePath();
496 };
497  }
498 }
499 
500 #endif
501 
502 /* 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:72
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)
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:62
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:78
ERecoveryState RecoveryState
ui representation for DocState!
EDocStates
Definition: docrecovery.hxx:69
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:90
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:84
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.