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 #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
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
,
112 /// unique ID, which is specified by the underlying autorecovery core!
115 /// the full qualified document URL
118 /// the full qualified URL of the temp. file (if it's exists)
121 /// a may be existing factory URL (e.g. for untitled documents)
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
133 /// state info as e.g. VALID, CORRUPTED, NON EXISTING ...
136 /// ui representation for DocState!
137 ERecoveryState RecoveryState
;
140 OUString StandardImageId
;
146 , DocState (EDocStates::Unknown
)
147 , RecoveryState(E_NOT_RECOVERED_YET
)
152 typedef ::std::vector
< TURLInfo
> TURLList
;
155 class IRecoveryUpdateListener
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;
166 virtual void stepNext(TURLInfo
* pItem
) = 0;
169 ~IRecoveryUpdateListener() {}
173 class RecoveryCore
: public ::cppu::WeakImplHelper
< css::frame::XStatusListener
>
184 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
187 css::uno::Reference
< css::frame::XDispatch
> m_xRealCore
;
190 css::uno::Reference
< css::task::XStatusIndicator
> m_xProgress
;
196 IRecoveryUpdateListener
* m_pListener
;
198 /** @short knows the reason, why we listen on our internal m_xRealCore
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
;
213 RecoveryCore(const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
214 bool bUsedForSaving
);
218 virtual ~RecoveryCore() override
;
222 const css::uno::Reference
< css::uno::XComponentContext
>& getComponentContext() const;
226 TURLList
& getURLListAccess();
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();
239 void setProgressHandler(const css::uno::Reference
< css::task::XStatusIndicator
>& xProgress
);
243 void setUpdateListener(IRecoveryUpdateListener
* pListener
);
247 void doEmergencySavePrepare();
248 void doEmergencySave();
253 static ERecoveryState
mapDocState2RecoverState(EDocStates eDocState
);
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
;
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();
281 css::util::URL
impl_getParsedURL(const OUString
& sURL
);
284 class PluginProgress
: public ::cppu::WeakImplHelper
<css::task::XStatusIndicator
, css::lang::XComponent
>
288 weld::ProgressBar
* m_pProgressBar
;
293 PluginProgress(weld::ProgressBar
* pProgressBar
);
294 virtual ~PluginProgress() override
;
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
;
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
315 RecoveryCore
* m_pCore
;
316 std::unique_ptr
<weld::TreeView
> m_xFileListLB
;
317 std::unique_ptr
<weld::Button
> m_xOkBtn
;
321 /** @short create all child controls of this dialog.
323 @descr The dialog isn't shown nor it starts any
327 can point to a parent window.
328 If it's set to 0, the defmodal-dialog-parent
329 is used automatically.
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
348 RecoveryCore
* m_pCore
;
350 std::unique_ptr
<weld::ProgressBar
> m_xProgressBar
;
353 css::uno::Reference
< css::task::XStatusIndicator
> m_xProgress
;
356 /** @short create all child controls of this dialog.
358 @descr The dialog isn't shown nor it starts any
362 can point to a parent window.
363 If it's set to 0, the defmodal-dialog-parent
364 is used automatically.
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
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
;
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
;
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
;
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
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
;
464 BrokenRecoveryDialog(weld::Window
* pParent
,
466 bool bBeforeRecovery
);
467 virtual ~BrokenRecoveryDialog() override
;
470 bool isExecutionNeeded() const;
474 const OUString
& getSaveDirURL() const;
484 DECL_LINK(SaveButtonHdl
, weld::Button
&, void);
488 DECL_LINK(OkButtonHdl
, weld::Button
&, void);
492 DECL_LINK(CancelButtonHdl
, weld::Button
&, void);
496 void impl_askForSavePath();
503 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */