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/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
73 /// default state, if a document was new created or loaded
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,
81 /// the Auto/Emergency saved document isn't usable any longer
83 /// the Auto/Emergency saved document is not really up-to-date (some changes can be missing)
85 /// the Auto/Emergency saved document was processed successfully
89 template<> struct typed_flags
<EDocStates
> : is_typed_flags
<EDocStates
, 0x2f0> {};
94 namespace DocRecovery
{
99 E_SUCCESSFULLY_RECOVERED
,
100 E_ORIGINAL_DOCUMENT_RECOVERED
,
102 E_RECOVERY_IS_IN_PROGRESS
,
111 /// unique ID, which is specified by the underlying autorecovery core!
114 /// the full qualified document URL
117 /// the full qualified URL of the temp. file (if it's exists)
120 /// a may be existing factory URL (e.g. for untitled documents)
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
132 /// state info as e.g. VALID, CORRUPTED, NON EXISTING ...
135 /// ui representation for DocState!
136 ERecoveryState RecoveryState
;
139 OUString StandardImageId
;
145 , DocState (EDocStates::Unknown
)
146 , RecoveryState(E_NOT_RECOVERED_YET
)
151 typedef ::std::vector
< TURLInfo
> TURLList
;
154 class IRecoveryUpdateListener
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;
165 virtual void stepNext(TURLInfo
* pItem
) = 0;
168 ~IRecoveryUpdateListener() {}
172 class RecoveryCore
: public ::cppu::WeakImplHelper
< css::frame::XStatusListener
>
183 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
186 css::uno::Reference
< css::frame::XDispatch
> m_xRealCore
;
189 css::uno::Reference
< css::task::XStatusIndicator
> m_xProgress
;
195 IRecoveryUpdateListener
* m_pListener
;
197 /** @short knows the reason, why we listen on our internal m_xRealCore
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
;
212 RecoveryCore(const css::uno::Reference
< css::uno::XComponentContext
>& rxContext
,
213 bool bUsedForSaving
);
217 virtual ~RecoveryCore() override
;
221 const css::uno::Reference
< css::uno::XComponentContext
>& getComponentContext() const;
225 TURLList
& getURLListAccess();
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();
238 void setProgressHandler(const css::uno::Reference
< css::task::XStatusIndicator
>& xProgress
);
242 void setUpdateListener(IRecoveryUpdateListener
* pListener
);
246 void doEmergencySavePrepare();
247 void doEmergencySave();
252 static ERecoveryState
mapDocState2RecoverState(EDocStates eDocState
);
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
;
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();
280 css::util::URL
impl_getParsedURL(const OUString
& sURL
);
283 class PluginProgress
: public ::cppu::WeakImplHelper
<css::task::XStatusIndicator
, css::lang::XComponent
>
287 weld::ProgressBar
* m_pProgressBar
;
292 PluginProgress(weld::ProgressBar
* pProgressBar
);
293 virtual ~PluginProgress() override
;
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
;
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
314 RecoveryCore
* m_pCore
;
315 std::unique_ptr
<weld::TreeView
> m_xFileListLB
;
316 std::unique_ptr
<weld::Button
> m_xOkBtn
;
320 /** @short create all child controls of this dialog.
322 @descr The dialog isn't shown nor it starts any
326 can point to a parent window.
327 If its set to 0, the defmodal-dialog-parent
328 is used automatically.
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
347 RecoveryCore
* m_pCore
;
349 std::unique_ptr
<weld::ProgressBar
> m_xProgressBar
;
352 css::uno::Reference
< css::task::XStatusIndicator
> m_xProgress
;
355 /** @short create all child controls of this dialog.
357 @descr The dialog isn't shown nor it starts any
361 can point to a parent window.
362 If its set to 0, the defmodal-dialog-parent
363 is used automatically.
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
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
;
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
;
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
;
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
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
;
463 BrokenRecoveryDialog(weld::Window
* pParent
,
465 bool bBeforeRecovery
);
466 virtual ~BrokenRecoveryDialog() override
;
469 bool isExecutionNeeded() const;
473 const OUString
& getSaveDirURL() const;
483 DECL_LINK(SaveButtonHdl
, weld::Button
&, void);
487 DECL_LINK(OkButtonHdl
, weld::Button
&, void);
491 DECL_LINK(CancelButtonHdl
, weld::Button
&, void);
495 void impl_askForSavePath();
502 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */