1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 inline constexpr OUString RECOVERY_CMD_DO_PREPARE_EMERGENCY_SAVE
= u
"vnd.sun.star.autorecovery:/doPrepareEmergencySave"_ustr
;
41 inline constexpr OUString RECOVERY_CMD_DO_EMERGENCY_SAVE
= u
"vnd.sun.star.autorecovery:/doEmergencySave"_ustr
;
42 inline constexpr OUString RECOVERY_CMD_DO_RECOVERY
= u
"vnd.sun.star.autorecovery:/doAutoRecovery"_ustr
;
43 inline constexpr OUString RECOVERY_CMD_DO_ENTRY_BACKUP
= u
"vnd.sun.star.autorecovery:/doEntryBackup"_ustr
;
44 inline constexpr OUString RECOVERY_CMD_DO_ENTRY_CLEANUP
= u
"vnd.sun.star.autorecovery:/doEntryCleanUp"_ustr
;
46 inline constexpr OUString PROP_STATUSINDICATOR
= u
"StatusIndicator"_ustr
;
47 inline constexpr OUString PROP_DISPATCHASYNCHRON
= u
"DispatchAsynchron"_ustr
;
48 inline constexpr OUString PROP_SAVEPATH
= u
"SavePath"_ustr
;
49 inline constexpr OUString PROP_ENTRYID
= u
"EntryID"_ustr
;
51 inline constexpr OUString STATEPROP_ID
= u
"ID"_ustr
;
52 inline constexpr OUString STATEPROP_STATE
= u
"DocumentState"_ustr
;
53 inline constexpr OUString STATEPROP_ORGURL
= u
"OriginalURL"_ustr
;
54 inline constexpr OUString STATEPROP_TEMPURL
= u
"TempURL"_ustr
;
55 inline constexpr OUString STATEPROP_FACTORYURL
= u
"FactoryURL"_ustr
;
56 inline constexpr OUString STATEPROP_TEMPLATEURL
= u
"TemplateURL"_ustr
;
57 inline constexpr OUString STATEPROP_TITLE
= u
"Title"_ustr
;
58 inline constexpr OUString STATEPROP_MODULE
= u
"Module"_ustr
;
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_AUTOLAUNCH 101 // request a restart
74 /// default state, if a document was new created or loaded
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,
82 /// the Auto/Emergency saved document isn't usable any longer
84 /// the Auto/Emergency saved document is not really up-to-date (some changes can be missing)
86 /// the Auto/Emergency saved document was processed successfully
90 template<> struct typed_flags
<EDocStates
> : is_typed_flags
<EDocStates
, 0x2f0> {};
95 namespace DocRecovery
{
100 E_SUCCESSFULLY_RECOVERED
,
101 E_ORIGINAL_DOCUMENT_RECOVERED
,
103 E_RECOVERY_IS_IN_PROGRESS
,
113 /// unique ID, which is specified by the underlying autorecovery core!
116 /// the full qualified document URL
119 /// the full qualified URL of the temp. file (if it's exists)
122 /// a may be existing factory URL (e.g. for untitled documents)
125 /// may be the document base on a template file !?
126 OUString TemplateURL
;
128 /// the pure file name, without path, disc etcpp.
129 OUString DisplayName
;
131 /// the application module, where this document was loaded
134 /// state info as e.g. VALID, CORRUPTED, NON EXISTING ...
137 /// ui representation for DocState!
138 ERecoveryState RecoveryState
;
141 OUString StandardImageId
;
143 /// user choice to discard
150 , DocState (EDocStates::Unknown
)
151 , RecoveryState(E_NOT_RECOVERED_YET
)
152 , ShouldDiscard(false)
157 typedef ::std::vector
< TURLInfo
> TURLList
;
160 class IRecoveryUpdateListener
164 // inform listener about changed items, which should be refreshed
165 virtual void updateItems() = 0;
167 // inform listener about ending of the asynchronous recovery operation
168 virtual void end() = 0;
171 virtual void stepNext(TURLInfo
* pItem
) = 0;
174 ~IRecoveryUpdateListener() {}
178 class RecoveryCore final
: public ::cppu::WeakImplHelper
< css::frame::XStatusListener
>
189 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
192 css::uno::Reference
< css::frame::XDispatch
> m_xRealCore
;
195 css::uno::Reference
< css::task::XStatusIndicator
> m_xProgress
;
201 IRecoveryUpdateListener
* m_pListener
;
203 /** @short knows the reason, why we listen on our internal m_xRealCore
206 @descr Because we listen for different operations
207 on the core dispatch implementation, we must know,
208 which URL we have to use for deregistration!
210 bool m_bListenForSaving
;
218 RecoveryCore(css::uno::Reference
< css::uno::XComponentContext
> xContext
,
219 bool bUsedForSaving
);
223 virtual ~RecoveryCore() override
;
227 const css::uno::Reference
< css::uno::XComponentContext
>& getComponentContext() const;
231 TURLList
& getURLListAccess();
235 static bool isBrokenTempEntry(const TURLInfo
& rInfo
);
236 void saveBrokenTempEntries(const OUString
& sSaveDir
);
237 void saveAllTempEntries(const OUString
& sSaveDir
);
238 void forgetBrokenTempEntries();
239 void forgetAllRecoveryEntries();
240 void forgetBrokenRecoveryEntries();
241 void forgetAllRecoveryEntriesMarkedForDiscard();
245 void setProgressHandler(const css::uno::Reference
< css::task::XStatusIndicator
>& xProgress
);
249 void setUpdateListener(IRecoveryUpdateListener
* pListener
);
253 void doEmergencySavePrepare();
254 void doEmergencySave();
259 static ERecoveryState
mapDocState2RecoverState(EDocStates eDocState
);
265 // css.frame.XStatusListener
266 virtual void SAL_CALL
statusChanged(const css::frame::FeatureStateEvent
& aEvent
) override
;
268 // css.lang.XEventListener
269 virtual void SAL_CALL
disposing(const css::lang::EventObject
& aEvent
) override
;
276 /** @short starts listening on the internal EmergencySave/AutoRecovery core.
278 void impl_startListening();
281 /** @short stop listening on the internal EmergencySave/AutoRecovery core.
283 void impl_stopListening();
287 css::util::URL
impl_getParsedURL(const OUString
& sURL
);
290 class PluginProgress final
: public ::cppu::WeakImplHelper
<css::task::XStatusIndicator
, css::lang::XComponent
>
294 weld::ProgressBar
* m_pProgressBar
;
299 PluginProgress(weld::ProgressBar
* pProgressBar
);
300 virtual ~PluginProgress() override
;
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
;
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
;
317 class SaveDialog final
: public weld::GenericDialogController
321 RecoveryCore
* m_pCore
;
322 std::unique_ptr
<weld::TreeView
> m_xFileListLB
;
323 std::unique_ptr
<weld::Button
> m_xOkBtn
;
327 /** @short create all child controls of this dialog.
329 @descr The dialog isn't shown nor it starts any
333 can point to a parent window.
334 If it's set to 0, the defmodal-dialog-parent
335 is used automatically.
338 provides access to the recovery core service
339 and the current list of open documents,
340 which should be shown inside this dialog.
342 SaveDialog(weld::Window
* pParent
, RecoveryCore
* pCore
);
343 virtual ~SaveDialog() override
;
345 DECL_LINK(OKButtonHdl
, weld::Button
&, void);
348 class SaveProgressDialog final
: public weld::GenericDialogController
349 , public IRecoveryUpdateListener
354 RecoveryCore
* m_pCore
;
356 std::unique_ptr
<weld::ProgressBar
> m_xProgressBar
;
359 rtl::Reference
< PluginProgress
> m_xProgress
;
362 /** @short create all child controls of this dialog.
364 @descr The dialog isn't shown nor it starts any
368 can point to a parent window.
369 If it's set to 0, the defmodal-dialog-parent
370 is used automatically.
373 used to start emergency save.
375 SaveProgressDialog(weld::Window
* pParent
,
376 RecoveryCore
* pCore
);
377 virtual ~SaveProgressDialog() override
;
379 /** @short start the emergency save operation. */
380 virtual short run() override
;
382 // IRecoveryUpdateListener
383 virtual void updateItems() override
;
384 virtual void stepNext(TURLInfo
* pItem
) override
;
385 virtual void end() override
;
388 class RecoveryDialog final
: public weld::GenericDialogController
389 , public IRecoveryUpdateListener
393 OUString m_aTitleRecoveryInProgress
;
394 OUString m_aRecoveryOnlyFinish
;
395 OUString m_aRecoveryOnlyFinishDescr
;
397 RecoveryCore
* m_pCore
;
398 rtl::Reference
< PluginProgress
> m_xProgress
;
399 enum EInternalRecoveryState
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...
410 sal_Int32 m_eRecoveryState
;
412 bool m_bWasRecoveryStarted
;
415 OUString m_aSuccessRecovStr
;
416 OUString m_aOrigDocRecovStr
;
417 OUString m_aRecovFailedStr
;
418 OUString m_aRecovInProgrStr
;
419 OUString m_aNotRecovYetStr
;
420 OUString m_aWillBeDiscStr
;
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
;
431 RecoveryDialog(weld::Window
* pParent
,
432 RecoveryCore
* pCore
);
434 virtual ~RecoveryDialog() override
;
436 // IRecoveryUpdateListener
437 virtual void updateItems() override
;
438 virtual void stepNext(TURLInfo
* pItem
) override
;
439 virtual void end() override
;
441 bool allSuccessfullyRecovered();
447 DECL_LINK(NextButtonHdl
, weld::Button
&, void);
448 DECL_LINK(CancelButtonHdl
, weld::Button
&, void);
449 DECL_LINK(ToggleRowHdl
, const weld::TreeView::iter_col
&, void);
451 OUString
impl_getStatusString( const TURLInfo
& rInfo
) const;
452 static OUString
impl_getStatusImage( const TURLInfo
& rInfo
);
453 void impl_updateItemDescription(int row
, const TriState
& rState
);
457 class BrokenRecoveryDialog final
: public weld::GenericDialogController
461 OUString m_sSavePath
;
462 RecoveryCore
* m_pCore
;
463 bool const m_bBeforeRecovery
;
464 bool m_bExecutionNeeded
;
466 std::unique_ptr
<weld::TreeView
> m_xFileListLB
;
467 std::unique_ptr
<weld::Entry
> m_xSaveDirED
;
468 std::unique_ptr
<weld::Button
> m_xSaveDirBtn
;
469 std::unique_ptr
<weld::Button
> m_xOkBtn
;
470 std::unique_ptr
<weld::Button
> m_xCancelBtn
;
476 BrokenRecoveryDialog(weld::Window
* pParent
,
478 bool bBeforeRecovery
);
479 virtual ~BrokenRecoveryDialog() override
;
482 bool isExecutionNeeded() const;
486 const OUString
& getSaveDirURL() const;
496 DECL_LINK(SaveButtonHdl
, weld::Button
&, void);
500 DECL_LINK(OkButtonHdl
, weld::Button
&, void);
504 DECL_LINK(CancelButtonHdl
, weld::Button
&, void);
508 void impl_askForSavePath();
515 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */