Bump version to 6.4-15
[LibreOffice.git] / svx / source / inc / docrecovery.hxx
blob525f589f3896953edd2c5001a88a310b2e94b4a7
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/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>
33 #define RECOVERY_CMDPART_PROTOCOL "vnd.sun.star.autorecovery:"
35 #define RECOVERY_CMDPART_DO_EMERGENCY_SAVE "/doEmergencySave"
36 #define RECOVERY_CMDPART_DO_RECOVERY "/doAutoRecovery"
37 #define RECOVERY_CMDPART_DO_BRINGTOFRONT "/doBringToFront"
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"
45 #define PROP_STATUSINDICATOR "StatusIndicator"
46 #define PROP_DISPATCHASYNCHRON "DispatchAsynchron"
47 #define PROP_SAVEPATH "SavePath"
48 #define PROP_ENTRYID "EntryID"
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"
59 #define RECOVERY_OPERATIONSTATE_START "start"
60 #define RECOVERY_OPERATIONSTATE_STOP "stop"
61 #define RECOVERY_OPERATIONSTATE_UPDATE "update"
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
69 enum class EDocStates
71 /* TEMP STATES */
73 /// default state, if a document was new created or loaded
74 Unknown = 0x000,
75 /** an action was started (saving/loading) ... Can be interesting later if the process may be was interrupted by an exception. */
76 TryLoadBackup = 0x010,
77 TryLoadOriginal = 0x020,
79 /* FINAL STATES */
81 /// the Auto/Emergency saved document isn't usable any longer
82 Damaged = 0x040,
83 /// the Auto/Emergency saved document is not really up-to-date (some changes can be missing)
84 Incomplete = 0x080,
85 /// the Auto/Emergency saved document was processed successfully
86 Succeeded = 0x200
88 namespace o3tl {
89 template<> struct typed_flags<EDocStates> : is_typed_flags<EDocStates, 0x2f0> {};
93 namespace svx{
94 namespace DocRecovery{
97 enum ERecoveryState
99 E_SUCCESSFULLY_RECOVERED,
100 E_ORIGINAL_DOCUMENT_RECOVERED,
101 E_RECOVERY_FAILED,
102 E_RECOVERY_IS_IN_PROGRESS,
103 E_NOT_RECOVERED_YET
107 struct TURLInfo
109 public:
111 /// unique ID, which is specified by the underlying autorecovery core!
112 sal_Int32 ID;
114 /// the full qualified document URL
115 OUString OrgURL;
117 /// the full qualified URL of the temp. file (if it's exists)
118 OUString TempURL;
120 /// a may be existing factory URL (e.g. for untitled documents)
121 OUString FactoryURL;
123 /// may be the document base on a template file !?
124 OUString TemplateURL;
126 /// the pure file name, without path, disc etcpp.
127 OUString DisplayName;
129 /// the application module, where this document was loaded
130 OUString Module;
132 /// state info as e.g. VALID, CORRUPTED, NON EXISTING ...
133 EDocStates DocState;
135 /// ui representation for DocState!
136 ERecoveryState RecoveryState;
138 /// standard icon
139 OUString StandardImageId;
141 public:
143 TURLInfo()
144 : ID (-1 )
145 , DocState (EDocStates::Unknown)
146 , RecoveryState(E_NOT_RECOVERED_YET)
151 typedef ::std::vector< TURLInfo > TURLList;
154 class IRecoveryUpdateListener
156 public:
158 // inform listener about changed items, which should be refreshed
159 virtual void updateItems() = 0;
161 // inform listener about ending of the asynchronous recovery operation
162 virtual void end() = 0;
164 // TODO
165 virtual void stepNext(TURLInfo* pItem) = 0;
167 protected:
168 ~IRecoveryUpdateListener() {}
172 class RecoveryCore : public ::cppu::WeakImplHelper< css::frame::XStatusListener >
175 // types, const
176 public:
179 // member
180 private:
182 /// TODO
183 css::uno::Reference< css::uno::XComponentContext > m_xContext;
185 /// TODO
186 css::uno::Reference< css::frame::XDispatch > m_xRealCore;
188 /// TODO
189 css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
191 /// TODO
192 TURLList m_lURLs;
194 /// TODO
195 IRecoveryUpdateListener* m_pListener;
197 /** @short knows the reason, why we listen on our internal m_xRealCore
198 member.
200 @descr Because we listen for different operations
201 on the core dispatch implementation, we must know,
202 which URL we have to use for deregistration!
204 bool const m_bListenForSaving;
207 // native interface
208 public:
211 /** @short TODO */
212 RecoveryCore(const css::uno::Reference< css::uno::XComponentContext >& rxContext,
213 bool bUsedForSaving);
216 /** @short TODO */
217 virtual ~RecoveryCore() override;
220 /** @short TODO */
221 const css::uno::Reference< css::uno::XComponentContext >& getComponentContext() const;
224 /** @short TODO */
225 TURLList& getURLListAccess();
228 /** @short TODO */
229 static bool isBrokenTempEntry(const TURLInfo& rInfo);
230 void saveBrokenTempEntries(const OUString& sSaveDir);
231 void saveAllTempEntries(const OUString& sSaveDir);
232 void forgetBrokenTempEntries();
233 void forgetAllRecoveryEntries();
234 void forgetBrokenRecoveryEntries();
237 /** @short TODO */
238 void setProgressHandler(const css::uno::Reference< css::task::XStatusIndicator >& xProgress);
241 /** @short TODO */
242 void setUpdateListener(IRecoveryUpdateListener* pListener);
245 /** @short TODO */
246 void doEmergencySavePrepare();
247 void doEmergencySave();
248 void doRecovery();
251 /** @short TODO */
252 static ERecoveryState mapDocState2RecoverState(EDocStates eDocState);
255 // uno interface
256 public:
258 // css.frame.XStatusListener
259 virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& aEvent) override;
261 // css.lang.XEventListener
262 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
265 // helper
266 private:
269 /** @short starts listening on the internal EmergencySave/AutoRecovery core.
271 void impl_startListening();
274 /** @short stop listening on the internal EmergencySave/AutoRecovery core.
276 void impl_stopListening();
279 /** @short TODO */
280 css::util::URL impl_getParsedURL(const OUString& sURL);
283 class PluginProgress : public ::cppu::WeakImplHelper<css::task::XStatusIndicator, css::lang::XComponent>
285 // member
286 private:
287 weld::ProgressBar* m_pProgressBar;
288 int m_nRange;
290 // native interface
291 public:
292 PluginProgress(weld::ProgressBar* pProgressBar);
293 virtual ~PluginProgress() override;
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;
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;
310 class SaveDialog : public weld::GenericDialogController
312 // member
313 private:
314 RecoveryCore* m_pCore;
315 std::unique_ptr<weld::TreeView> m_xFileListLB;
316 std::unique_ptr<weld::Button> m_xOkBtn;
318 // interface
319 public:
320 /** @short create all child controls of this dialog.
322 @descr The dialog isn't shown nor it starts any
323 action by itself!
325 @param pParent
326 can point to a parent window.
327 If its set to 0, the defmodal-dialog-parent
328 is used automatically.
330 @param pCore
331 provides access to the recovery core service
332 and the current list of open documents,
333 which should be shown inside this dialog.
335 SaveDialog(weld::Window* pParent, RecoveryCore* pCore);
336 virtual ~SaveDialog() override;
338 DECL_LINK(OKButtonHdl, weld::Button&, void);
341 class SaveProgressDialog : public weld::GenericDialogController
342 , public IRecoveryUpdateListener
344 // member
345 private:
346 // @short TODO
347 RecoveryCore* m_pCore;
349 std::unique_ptr<weld::ProgressBar> m_xProgressBar;
351 // @short TODO
352 css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
353 // interface
354 public:
355 /** @short create all child controls of this dialog.
357 @descr The dialog isn't shown nor it starts any
358 action by itself!
360 @param pParent
361 can point to a parent window.
362 If its set to 0, the defmodal-dialog-parent
363 is used automatically.
365 @param pCore
366 used to start emergency save.
368 SaveProgressDialog(weld::Window* pParent,
369 RecoveryCore* pCore);
370 virtual ~SaveProgressDialog() override;
372 /** @short start the emergency save operation. */
373 virtual short run() override;
375 // IRecoveryUpdateListener
376 virtual void updateItems() override;
377 virtual void stepNext(TURLInfo* pItem) override;
378 virtual void end() override;
381 class RecoveryDialog : public weld::GenericDialogController
382 , public IRecoveryUpdateListener
384 // member
385 private:
386 OUString const m_aTitleRecoveryInProgress;
387 OUString const m_aRecoveryOnlyFinish;
388 OUString const m_aRecoveryOnlyFinishDescr;
390 RecoveryCore* m_pCore;
391 css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
392 enum EInternalRecoveryState
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...
403 sal_Int32 m_eRecoveryState;
404 bool m_bWaitForCore;
405 bool m_bWasRecoveryStarted;
407 OUString m_aSuccessRecovStr;
408 OUString m_aOrigDocRecovStr;
409 OUString m_aRecovFailedStr;
410 OUString m_aRecovInProgrStr;
411 OUString m_aNotRecovYetStr;
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;
419 // member
420 public:
421 /** @short TODO */
422 RecoveryDialog(weld::Window* pParent,
423 RecoveryCore* pCore);
425 virtual ~RecoveryDialog() override;
427 // IRecoveryUpdateListener
428 virtual void updateItems() override;
429 virtual void stepNext(TURLInfo* pItem) override;
430 virtual void end() override;
432 short execute();
434 // helper
435 private:
436 DECL_LINK(NextButtonHdl, weld::Button&, void);
437 DECL_LINK(CancelButtonHdl, weld::Button&, void);
439 OUString impl_getStatusString( const TURLInfo& rInfo ) const;
440 static OUString impl_getStatusImage( const TURLInfo& rInfo );
444 class BrokenRecoveryDialog : public weld::GenericDialogController
446 // member
447 private:
448 OUString m_sSavePath;
449 RecoveryCore* m_pCore;
450 bool const m_bBeforeRecovery;
451 bool m_bExecutionNeeded;
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;
459 // interface
460 public:
462 /** @short TODO */
463 BrokenRecoveryDialog(weld::Window* pParent,
464 RecoveryCore* pCore,
465 bool bBeforeRecovery);
466 virtual ~BrokenRecoveryDialog() override;
468 /** @short TODO */
469 bool isExecutionNeeded() const;
472 /** @short TODO */
473 const OUString& getSaveDirURL() const;
476 // helper
477 private:
478 /** @short TODO */
479 void impl_refresh();
482 /** @short TODO */
483 DECL_LINK(SaveButtonHdl, weld::Button&, void);
486 /** @short TODO */
487 DECL_LINK(OkButtonHdl, weld::Button&, void);
490 /** @short TODO */
491 DECL_LINK(CancelButtonHdl, weld::Button&, void);
494 /** @short TODO */
495 void impl_askForSavePath();
500 #endif
502 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */