Version 7.1.7.1, tag libreoffice-7.1.7.1
[LibreOffice.git] / svx / source / inc / docrecovery.hxx
blob4a954f57b7fa201d3350870d832f2244990cda87
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SVX_SOURCE_INC_DOCRECOVERY_HXX
21 #define INCLUDED_SVX_SOURCE_INC_DOCRECOVERY_HXX
23 #include <vcl/weld.hxx>
24 #include <o3tl/typed_flags_set.hxx>
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>
34 #define RECOVERY_CMDPART_PROTOCOL "vnd.sun.star.autorecovery:"
36 #define RECOVERY_CMDPART_DO_EMERGENCY_SAVE "/doEmergencySave"
37 #define RECOVERY_CMDPART_DO_RECOVERY "/doAutoRecovery"
38 #define RECOVERY_CMDPART_DO_BRINGTOFRONT "/doBringToFront"
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"
46 #define PROP_STATUSINDICATOR "StatusIndicator"
47 #define PROP_DISPATCHASYNCHRON "DispatchAsynchron"
48 #define PROP_SAVEPATH "SavePath"
49 #define PROP_ENTRYID "EntryID"
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"
60 #define RECOVERY_OPERATIONSTATE_START "start"
61 #define RECOVERY_OPERATIONSTATE_STOP "stop"
62 #define RECOVERY_OPERATIONSTATE_UPDATE "update"
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
70 enum class EDocStates
72 /* TEMP STATES */
74 /// default state, if a document was new created or loaded
75 Unknown = 0x000,
76 /** an action was started (saving/loading) ... Can be interesting later if the process may be was interrupted by an exception. */
77 TryLoadBackup = 0x010,
78 TryLoadOriginal = 0x020,
80 /* FINAL STATES */
82 /// the Auto/Emergency saved document isn't usable any longer
83 Damaged = 0x040,
84 /// the Auto/Emergency saved document is not really up-to-date (some changes can be missing)
85 Incomplete = 0x080,
86 /// the Auto/Emergency saved document was processed successfully
87 Succeeded = 0x200
89 namespace o3tl {
90 template<> struct typed_flags<EDocStates> : is_typed_flags<EDocStates, 0x2f0> {};
94 namespace svx{
95 namespace DocRecovery{
98 enum ERecoveryState
100 E_SUCCESSFULLY_RECOVERED,
101 E_ORIGINAL_DOCUMENT_RECOVERED,
102 E_RECOVERY_FAILED,
103 E_RECOVERY_IS_IN_PROGRESS,
104 E_NOT_RECOVERED_YET
108 struct TURLInfo
110 public:
112 /// unique ID, which is specified by the underlying autorecovery core!
113 sal_Int32 ID;
115 /// the full qualified document URL
116 OUString OrgURL;
118 /// the full qualified URL of the temp. file (if it's exists)
119 OUString TempURL;
121 /// a may be existing factory URL (e.g. for untitled documents)
122 OUString FactoryURL;
124 /// may be the document base on a template file !?
125 OUString TemplateURL;
127 /// the pure file name, without path, disc etcpp.
128 OUString DisplayName;
130 /// the application module, where this document was loaded
131 OUString Module;
133 /// state info as e.g. VALID, CORRUPTED, NON EXISTING ...
134 EDocStates DocState;
136 /// ui representation for DocState!
137 ERecoveryState RecoveryState;
139 /// standard icon
140 OUString StandardImageId;
142 public:
144 TURLInfo()
145 : ID (-1 )
146 , DocState (EDocStates::Unknown)
147 , RecoveryState(E_NOT_RECOVERED_YET)
152 typedef ::std::vector< TURLInfo > TURLList;
155 class IRecoveryUpdateListener
157 public:
159 // inform listener about changed items, which should be refreshed
160 virtual void updateItems() = 0;
162 // inform listener about ending of the asynchronous recovery operation
163 virtual void end() = 0;
165 // TODO
166 virtual void stepNext(TURLInfo* pItem) = 0;
168 protected:
169 ~IRecoveryUpdateListener() {}
173 class RecoveryCore : public ::cppu::WeakImplHelper< css::frame::XStatusListener >
176 // types, const
177 public:
180 // member
181 private:
183 /// TODO
184 css::uno::Reference< css::uno::XComponentContext > m_xContext;
186 /// TODO
187 css::uno::Reference< css::frame::XDispatch > m_xRealCore;
189 /// TODO
190 css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
192 /// TODO
193 TURLList m_lURLs;
195 /// TODO
196 IRecoveryUpdateListener* m_pListener;
198 /** @short knows the reason, why we listen on our internal m_xRealCore
199 member.
201 @descr Because we listen for different operations
202 on the core dispatch implementation, we must know,
203 which URL we have to use for deregistration!
205 bool m_bListenForSaving;
208 // native interface
209 public:
212 /** @short TODO */
213 RecoveryCore(const css::uno::Reference< css::uno::XComponentContext >& rxContext,
214 bool bUsedForSaving);
217 /** @short TODO */
218 virtual ~RecoveryCore() override;
221 /** @short TODO */
222 const css::uno::Reference< css::uno::XComponentContext >& getComponentContext() const;
225 /** @short TODO */
226 TURLList& getURLListAccess();
229 /** @short TODO */
230 static bool isBrokenTempEntry(const TURLInfo& rInfo);
231 void saveBrokenTempEntries(const OUString& sSaveDir);
232 void saveAllTempEntries(const OUString& sSaveDir);
233 void forgetBrokenTempEntries();
234 void forgetAllRecoveryEntries();
235 void forgetBrokenRecoveryEntries();
238 /** @short TODO */
239 void setProgressHandler(const css::uno::Reference< css::task::XStatusIndicator >& xProgress);
242 /** @short TODO */
243 void setUpdateListener(IRecoveryUpdateListener* pListener);
246 /** @short TODO */
247 void doEmergencySavePrepare();
248 void doEmergencySave();
249 void doRecovery();
252 /** @short TODO */
253 static ERecoveryState mapDocState2RecoverState(EDocStates eDocState);
256 // uno interface
257 public:
259 // css.frame.XStatusListener
260 virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& aEvent) override;
262 // css.lang.XEventListener
263 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
266 // helper
267 private:
270 /** @short starts listening on the internal EmergencySave/AutoRecovery core.
272 void impl_startListening();
275 /** @short stop listening on the internal EmergencySave/AutoRecovery core.
277 void impl_stopListening();
280 /** @short TODO */
281 css::util::URL impl_getParsedURL(const OUString& sURL);
284 class PluginProgress : public ::cppu::WeakImplHelper<css::task::XStatusIndicator, css::lang::XComponent>
286 // member
287 private:
288 weld::ProgressBar* m_pProgressBar;
289 int m_nRange;
291 // native interface
292 public:
293 PluginProgress(weld::ProgressBar* pProgressBar);
294 virtual ~PluginProgress() override;
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;
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;
311 class SaveDialog : public weld::GenericDialogController
313 // member
314 private:
315 RecoveryCore* m_pCore;
316 std::unique_ptr<weld::TreeView> m_xFileListLB;
317 std::unique_ptr<weld::Button> m_xOkBtn;
319 // interface
320 public:
321 /** @short create all child controls of this dialog.
323 @descr The dialog isn't shown nor it starts any
324 action by itself!
326 @param pParent
327 can point to a parent window.
328 If it's set to 0, the defmodal-dialog-parent
329 is used automatically.
331 @param pCore
332 provides access to the recovery core service
333 and the current list of open documents,
334 which should be shown inside this dialog.
336 SaveDialog(weld::Window* pParent, RecoveryCore* pCore);
337 virtual ~SaveDialog() override;
339 DECL_LINK(OKButtonHdl, weld::Button&, void);
342 class SaveProgressDialog : public weld::GenericDialogController
343 , public IRecoveryUpdateListener
345 // member
346 private:
347 // @short TODO
348 RecoveryCore* m_pCore;
350 std::unique_ptr<weld::ProgressBar> m_xProgressBar;
352 // @short TODO
353 css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
354 // interface
355 public:
356 /** @short create all child controls of this dialog.
358 @descr The dialog isn't shown nor it starts any
359 action by itself!
361 @param pParent
362 can point to a parent window.
363 If it's set to 0, the defmodal-dialog-parent
364 is used automatically.
366 @param pCore
367 used to start emergency save.
369 SaveProgressDialog(weld::Window* pParent,
370 RecoveryCore* pCore);
371 virtual ~SaveProgressDialog() override;
373 /** @short start the emergency save operation. */
374 virtual short run() override;
376 // IRecoveryUpdateListener
377 virtual void updateItems() override;
378 virtual void stepNext(TURLInfo* pItem) override;
379 virtual void end() override;
382 class RecoveryDialog : public weld::GenericDialogController
383 , public IRecoveryUpdateListener
385 // member
386 private:
387 OUString m_aTitleRecoveryInProgress;
388 OUString m_aRecoveryOnlyFinish;
389 OUString m_aRecoveryOnlyFinishDescr;
391 RecoveryCore* m_pCore;
392 css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
393 enum EInternalRecoveryState
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...
404 sal_Int32 m_eRecoveryState;
405 bool m_bWaitForCore;
406 bool m_bWasRecoveryStarted;
408 OUString m_aSuccessRecovStr;
409 OUString m_aOrigDocRecovStr;
410 OUString m_aRecovFailedStr;
411 OUString m_aRecovInProgrStr;
412 OUString m_aNotRecovYetStr;
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;
420 // member
421 public:
422 /** @short TODO */
423 RecoveryDialog(weld::Window* pParent,
424 RecoveryCore* pCore);
426 virtual ~RecoveryDialog() override;
428 // IRecoveryUpdateListener
429 virtual void updateItems() override;
430 virtual void stepNext(TURLInfo* pItem) override;
431 virtual void end() override;
433 short execute();
435 // helper
436 private:
437 DECL_LINK(NextButtonHdl, weld::Button&, void);
438 DECL_LINK(CancelButtonHdl, weld::Button&, void);
440 OUString impl_getStatusString( const TURLInfo& rInfo ) const;
441 static OUString impl_getStatusImage( const TURLInfo& rInfo );
445 class BrokenRecoveryDialog : public weld::GenericDialogController
447 // member
448 private:
449 OUString m_sSavePath;
450 RecoveryCore* m_pCore;
451 bool const m_bBeforeRecovery;
452 bool m_bExecutionNeeded;
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;
460 // interface
461 public:
463 /** @short TODO */
464 BrokenRecoveryDialog(weld::Window* pParent,
465 RecoveryCore* pCore,
466 bool bBeforeRecovery);
467 virtual ~BrokenRecoveryDialog() override;
469 /** @short TODO */
470 bool isExecutionNeeded() const;
473 /** @short TODO */
474 const OUString& getSaveDirURL() const;
477 // helper
478 private:
479 /** @short TODO */
480 void impl_refresh();
483 /** @short TODO */
484 DECL_LINK(SaveButtonHdl, weld::Button&, void);
487 /** @short TODO */
488 DECL_LINK(OkButtonHdl, weld::Button&, void);
491 /** @short TODO */
492 DECL_LINK(CancelButtonHdl, weld::Button&, void);
495 /** @short TODO */
496 void impl_askForSavePath();
501 #endif
503 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */