tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / svx / source / inc / docrecovery.hxx
blob559592ab98787a744c155f9d13f8b396d18eee17
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 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
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,
105 E_WILL_BE_DISCARDED,
109 struct TURLInfo
111 public:
113 /// unique ID, which is specified by the underlying autorecovery core!
114 sal_Int32 ID;
116 /// the full qualified document URL
117 OUString OrgURL;
119 /// the full qualified URL of the temp. file (if it's exists)
120 OUString TempURL;
122 /// a may be existing factory URL (e.g. for untitled documents)
123 OUString FactoryURL;
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
132 OUString Module;
134 /// state info as e.g. VALID, CORRUPTED, NON EXISTING ...
135 EDocStates DocState;
137 /// ui representation for DocState!
138 ERecoveryState RecoveryState;
140 /// standard icon
141 OUString StandardImageId;
143 /// user choice to discard
144 bool ShouldDiscard;
146 public:
148 TURLInfo()
149 : ID (-1 )
150 , DocState (EDocStates::Unknown)
151 , RecoveryState(E_NOT_RECOVERED_YET)
152 , ShouldDiscard(false)
157 typedef ::std::vector< TURLInfo > TURLList;
160 class IRecoveryUpdateListener
162 public:
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;
170 // TODO
171 virtual void stepNext(TURLInfo* pItem) = 0;
173 protected:
174 ~IRecoveryUpdateListener() {}
178 class RecoveryCore final : public ::cppu::WeakImplHelper< css::frame::XStatusListener >
181 // types, const
182 public:
185 // member
186 private:
188 /// TODO
189 css::uno::Reference< css::uno::XComponentContext > m_xContext;
191 /// TODO
192 css::uno::Reference< css::frame::XDispatch > m_xRealCore;
194 /// TODO
195 css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
197 /// TODO
198 TURLList m_lURLs;
200 /// TODO
201 IRecoveryUpdateListener* m_pListener;
203 /** @short knows the reason, why we listen on our internal m_xRealCore
204 member.
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;
213 // native interface
214 public:
217 /** @short TODO */
218 RecoveryCore(css::uno::Reference< css::uno::XComponentContext > xContext,
219 bool bUsedForSaving);
222 /** @short TODO */
223 virtual ~RecoveryCore() override;
226 /** @short TODO */
227 const css::uno::Reference< css::uno::XComponentContext >& getComponentContext() const;
230 /** @short TODO */
231 TURLList& getURLListAccess();
234 /** @short TODO */
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();
244 /** @short TODO */
245 void setProgressHandler(const css::uno::Reference< css::task::XStatusIndicator >& xProgress);
248 /** @short TODO */
249 void setUpdateListener(IRecoveryUpdateListener* pListener);
252 /** @short TODO */
253 void doEmergencySavePrepare();
254 void doEmergencySave();
255 void doRecovery();
258 /** @short TODO */
259 static ERecoveryState mapDocState2RecoverState(EDocStates eDocState);
262 // uno interface
263 public:
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;
272 // helper
273 private:
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();
286 /** @short TODO */
287 css::util::URL impl_getParsedURL(const OUString& sURL);
290 class PluginProgress final : public ::cppu::WeakImplHelper<css::task::XStatusIndicator, css::lang::XComponent>
292 // member
293 private:
294 weld::ProgressBar* m_pProgressBar;
295 int m_nRange;
297 // native interface
298 public:
299 PluginProgress(weld::ProgressBar* pProgressBar);
300 virtual ~PluginProgress() override;
302 // uno interface
303 public:
304 // XStatusIndicator
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;
311 // XComponent
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
319 // member
320 private:
321 RecoveryCore* m_pCore;
322 std::unique_ptr<weld::TreeView> m_xFileListLB;
323 std::unique_ptr<weld::Button> m_xOkBtn;
325 // interface
326 public:
327 /** @short create all child controls of this dialog.
329 @descr The dialog isn't shown nor it starts any
330 action by itself!
332 @param pParent
333 can point to a parent window.
334 If it's set to 0, the defmodal-dialog-parent
335 is used automatically.
337 @param pCore
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
351 // member
352 private:
353 // @short TODO
354 RecoveryCore* m_pCore;
356 std::unique_ptr<weld::ProgressBar> m_xProgressBar;
358 // @short TODO
359 rtl::Reference< PluginProgress > m_xProgress;
360 // interface
361 public:
362 /** @short create all child controls of this dialog.
364 @descr The dialog isn't shown nor it starts any
365 action by itself!
367 @param pParent
368 can point to a parent window.
369 If it's set to 0, the defmodal-dialog-parent
370 is used automatically.
372 @param pCore
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
391 // member
392 private:
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;
411 bool m_bWaitForCore;
412 bool m_bWasRecoveryStarted;
413 int m_aToggleCount;
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;
428 // member
429 public:
430 /** @short TODO */
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();
443 short execute();
445 // helper
446 private:
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
459 // member
460 private:
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;
472 // interface
473 public:
475 /** @short TODO */
476 BrokenRecoveryDialog(weld::Window* pParent,
477 RecoveryCore* pCore,
478 bool bBeforeRecovery);
479 virtual ~BrokenRecoveryDialog() override;
481 /** @short TODO */
482 bool isExecutionNeeded() const;
485 /** @short TODO */
486 const OUString& getSaveDirURL() const;
489 // helper
490 private:
491 /** @short TODO */
492 void impl_refresh();
495 /** @short TODO */
496 DECL_LINK(SaveButtonHdl, weld::Button&, void);
499 /** @short TODO */
500 DECL_LINK(OkButtonHdl, weld::Button&, void);
503 /** @short TODO */
504 DECL_LINK(CancelButtonHdl, weld::Button&, void);
507 /** @short TODO */
508 void impl_askForSavePath();
513 #endif
515 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */