Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef INCLUDED_SVX_SOURCE_INC_DOCRECOVERY_HXX
21 : #define INCLUDED_SVX_SOURCE_INC_DOCRECOVERY_HXX
22 :
23 : #include <vcl/dialog.hxx>
24 : #include <vcl/button.hxx>
25 : #include <vcl/fixed.hxx>
26 : #include <vcl/lstbox.hxx>
27 : #include <vcl/tabdlg.hxx>
28 : #include <vcl/tabpage.hxx>
29 : #include <svtools/simptabl.hxx>
30 : #include <svtools/svlbitm.hxx>
31 : #include <svtools/svmedit2.hxx>
32 : #include <svtools/treelistbox.hxx>
33 :
34 : #include <cppuhelper/implbase1.hxx>
35 : #include <cppuhelper/implbase2.hxx>
36 : #include <com/sun/star/task/StatusIndicatorFactory.hpp>
37 : #include <com/sun/star/frame/XStatusListener.hpp>
38 : #include <com/sun/star/frame/XDispatch.hpp>
39 : #include <com/sun/star/lang/XComponent.hpp>
40 :
41 :
42 : #define RECOVERY_CMDPART_PROTOCOL "vnd.sun.star.autorecovery:"
43 :
44 : #define RECOVERY_CMDPART_DO_EMERGENCY_SAVE "/doEmergencySave"
45 : #define RECOVERY_CMDPART_DO_RECOVERY "/doAutoRecovery"
46 :
47 : #define RECOVERY_CMD_DO_PREPARE_EMERGENCY_SAVE "vnd.sun.star.autorecovery:/doPrepareEmergencySave"
48 : #define RECOVERY_CMD_DO_EMERGENCY_SAVE "vnd.sun.star.autorecovery:/doEmergencySave"
49 : #define RECOVERY_CMD_DO_RECOVERY "vnd.sun.star.autorecovery:/doAutoRecovery"
50 : #define RECOVERY_CMD_DO_ENTRY_BACKUP "vnd.sun.star.autorecovery:/doEntryBackup"
51 : #define RECOVERY_CMD_DO_ENTRY_CLEANUP "vnd.sun.star.autorecovery:/doEntryCleanUp"
52 :
53 : #define PROP_STATUSINDICATOR "StatusIndicator"
54 : #define PROP_DISPATCHASYNCHRON "DispatchAsynchron"
55 : #define PROP_SAVEPATH "SavePath"
56 : #define PROP_ENTRYID "EntryID"
57 :
58 : #define STATEPROP_ID "ID"
59 : #define STATEPROP_STATE "DocumentState"
60 : #define STATEPROP_ORGURL "OriginalURL"
61 : #define STATEPROP_TEMPURL "TempURL"
62 : #define STATEPROP_FACTORYURL "FactoryURL"
63 : #define STATEPROP_TEMPLATEURL "TemplateURL"
64 : #define STATEPROP_TITLE "Title"
65 : #define STATEPROP_MODULE "Module"
66 :
67 : #define RECOVERY_OPERATIONSTATE_START "start"
68 : #define RECOVERY_OPERATIONSTATE_STOP "stop"
69 : #define RECOVERY_OPERATIONSTATE_UPDATE "update"
70 :
71 : #define DLG_RET_UNKNOWN -1
72 : #define DLG_RET_OK 1
73 : #define DLG_RET_CANCEL 0
74 : #define DLG_RET_OK_AUTOLUNCH 101
75 :
76 :
77 : namespace svx{
78 : namespace DocRecovery{
79 :
80 :
81 : enum EDocStates
82 : {
83 : /* TEMP STATES */
84 :
85 : /// default state, if a document was new created or loaded
86 : E_UNKNOWN = 0,
87 : /// modified against the original file
88 : E_MODIFIED = 1,
89 : /// an active document can be postponed to be saved later.
90 : E_POSTPONED = 2,
91 : /// was already handled during one AutoSave/Recovery session.
92 : E_HANDLED = 4,
93 : /** an action was started (saving/loading) ... Can be interesting later if the process may be was interrupted by an exception. */
94 : E_TRY_SAVE = 8,
95 : E_TRY_LOAD_BACKUP = 16,
96 : E_TRY_LOAD_ORIGINAL = 32,
97 :
98 : /* FINAL STATES */
99 :
100 : /// the Auto/Emergency saved document isn't useable any longer
101 : E_DAMAGED = 64,
102 : /// the Auto/Emergency saved document is not really up-to-date (some changes can be missing)
103 : E_INCOMPLETE = 128,
104 : /// the Auto/Emergency saved document was processed successfully
105 : E_SUCCEDED = 512
106 : };
107 :
108 :
109 : enum ERecoveryState
110 : {
111 : E_SUCCESSFULLY_RECOVERED,
112 : E_ORIGINAL_DOCUMENT_RECOVERED,
113 : E_RECOVERY_FAILED,
114 : E_RECOVERY_IS_IN_PROGRESS,
115 : E_NOT_RECOVERED_YET
116 : };
117 :
118 :
119 0 : struct TURLInfo
120 : {
121 : public:
122 :
123 : /// unique ID, which is specified by the underlying autorecovery core!
124 : sal_Int32 ID;
125 :
126 : /// the full qualified document URL
127 : OUString OrgURL;
128 :
129 : /// the full qualified URL of the temp. file (if it's exists)
130 : OUString TempURL;
131 :
132 : /// a may be existing factory URL (e.g. for untitled documents)
133 : OUString FactoryURL;
134 :
135 : /// may be the document base on a template file !?
136 : OUString TemplateURL;
137 :
138 : /// the pure file name, without path, disc etcpp.
139 : OUString DisplayName;
140 :
141 : /// the application module, where this document was loaded
142 : OUString Module;
143 :
144 : /// state info as e.g. VALID, CORRUPTED, NON EXISTING ...
145 : sal_Int32 DocState;
146 :
147 : /// ui representation for DocState!
148 : ERecoveryState RecoveryState;
149 :
150 : /// standard icon
151 : Image StandardImage;
152 :
153 : public:
154 :
155 0 : TURLInfo()
156 : : ID (-1 )
157 : , DocState (E_UNKNOWN )
158 0 : , RecoveryState(E_NOT_RECOVERED_YET)
159 0 : {}
160 : };
161 :
162 :
163 : typedef ::std::vector< TURLInfo > TURLList;
164 :
165 :
166 0 : class IRecoveryUpdateListener
167 : {
168 : public:
169 :
170 : // inform listener about changed items, which should be refreshed
171 : virtual void updateItems() = 0;
172 :
173 : // inform listener about starting of the asynchronous recovery operation
174 : virtual void start() = 0;
175 :
176 : // inform listener about ending of the asynchronous recovery operation
177 : virtual void end() = 0;
178 :
179 : // TODO
180 : virtual void stepNext(TURLInfo* pItem) = 0;
181 :
182 : protected:
183 0 : ~IRecoveryUpdateListener() {}
184 : };
185 :
186 :
187 : class RecoveryCore : public ::cppu::WeakImplHelper1< css::frame::XStatusListener >
188 : {
189 :
190 : // types, const
191 : public:
192 :
193 :
194 : // member
195 : private:
196 :
197 : /// TODO
198 : css::uno::Reference< css::uno::XComponentContext > m_xContext;
199 :
200 : /// TODO
201 : css::uno::Reference< css::frame::XDispatch > m_xRealCore;
202 :
203 : /// TODO
204 : css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
205 :
206 : /// TODO
207 : TURLList m_lURLs;
208 :
209 : /// TODO
210 : IRecoveryUpdateListener* m_pListener;
211 :
212 : /** @short knows the reason, why we listen on our internal m_xRealCore
213 : member.
214 :
215 : @descr Because we listen for different operations
216 : on the core dispatch implementation, we must know,
217 : which URL we have to use for deregistration!
218 : */
219 : bool m_bListenForSaving;
220 :
221 :
222 : // native interface
223 : public:
224 :
225 :
226 : /** @short TODO */
227 : RecoveryCore(const css::uno::Reference< css::uno::XComponentContext >& rxContext,
228 : bool bUsedForSaving);
229 :
230 :
231 : /** @short TODO */
232 : virtual ~RecoveryCore();
233 :
234 :
235 : /** @short TODO */
236 : css::uno::Reference< css::uno::XComponentContext > getComponentContext();
237 :
238 :
239 : /** @short TODO */
240 : TURLList& getURLListAccess();
241 :
242 :
243 : /** @short TODO */
244 : static bool isBrokenTempEntry(const TURLInfo& rInfo);
245 : void saveBrokenTempEntries(const OUString& sSaveDir);
246 : void saveAllTempEntries(const OUString& sSaveDir);
247 : void forgetBrokenTempEntries();
248 : void forgetAllRecoveryEntries();
249 : void forgetBrokenRecoveryEntries();
250 :
251 :
252 : /** @short TODO */
253 : void setProgressHandler(const css::uno::Reference< css::task::XStatusIndicator >& xProgress);
254 :
255 :
256 : /** @short TODO */
257 : void setUpdateListener(IRecoveryUpdateListener* pListener);
258 :
259 :
260 : /** @short TODO */
261 : void doEmergencySavePrepare();
262 : void doEmergencySave();
263 : void doRecovery();
264 :
265 :
266 : /** @short TODO */
267 : static ERecoveryState mapDocState2RecoverState(sal_Int32 eDocState);
268 :
269 :
270 : // uno interface
271 : public:
272 :
273 : // css.frame.XStatusListener
274 : virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& aEvent)
275 : throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
276 :
277 : // css.lang.XEventListener
278 : virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent)
279 : throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
280 :
281 :
282 : // helper
283 : private:
284 :
285 :
286 : /** @short starts listening on the internal EmergencySave/AutoRecovery core.
287 : */
288 : void impl_startListening();
289 :
290 :
291 : /** @short stop listening on the internal EmergencySave/AutoRecovery core.
292 : */
293 : void impl_stopListening();
294 :
295 :
296 : /** @short TODO */
297 : css::util::URL impl_getParsedURL(const OUString& sURL);
298 : };
299 :
300 :
301 : class PluginProgressWindow : public vcl::Window
302 : {
303 : private:
304 : css::uno::Reference< css::lang::XComponent > m_xProgress;
305 : public:
306 : PluginProgressWindow( vcl::Window* pParent ,
307 : const css::uno::Reference< css::lang::XComponent >& xProgress);
308 : virtual ~PluginProgressWindow();
309 : virtual void dispose() SAL_OVERRIDE;
310 : };
311 :
312 : class PluginProgress : public ::cppu::WeakImplHelper2< css::task::XStatusIndicator ,
313 : css::lang::XComponent >
314 : {
315 : // member
316 : private:
317 : /** @short TODO */
318 : css::uno::Reference< css::task::XStatusIndicatorFactory > m_xProgressFactory;
319 :
320 : css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
321 :
322 : VclPtr<PluginProgressWindow> m_pPlugProgressWindow;
323 :
324 :
325 : // native interface
326 : public:
327 : /** @short TODO */
328 : PluginProgress( vcl::Window* pParent,
329 : const css::uno::Reference< css::uno::XComponentContext >& xContext );
330 :
331 :
332 : /** @short TODO */
333 : virtual ~PluginProgress();
334 :
335 :
336 : // uno interface
337 : public:
338 :
339 :
340 : // XStatusIndicator
341 : virtual void SAL_CALL start(const OUString& sText ,
342 : sal_Int32 nRange)
343 : throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
344 :
345 : virtual void SAL_CALL end()
346 : throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
347 :
348 : virtual void SAL_CALL setText(const OUString& sText)
349 : throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
350 :
351 : virtual void SAL_CALL setValue(sal_Int32 nValue)
352 : throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
353 :
354 : virtual void SAL_CALL reset()
355 : throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
356 :
357 :
358 : // XComponent
359 : virtual void SAL_CALL dispose()
360 : throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
361 :
362 : virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener >& xListener)
363 : throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
364 :
365 : virtual void SAL_CALL removeEventListener( const css::uno::Reference< css::lang::XEventListener >& xListener)
366 : throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
367 : };
368 :
369 : class SaveDialog : public Dialog
370 : {
371 : // member
372 : private:
373 : VclPtr<FixedText> m_pTitleFT;
374 : VclPtr<ListBox> m_pFileListLB;
375 : VclPtr<OKButton> m_pOkBtn;
376 : RecoveryCore* m_pCore;
377 :
378 : // interface
379 : public:
380 : /** @short create all child controls of this dialog.
381 :
382 : @descr The dialog isn't shown nor it starts any
383 : action by itself!
384 :
385 : @param pParent
386 : can point to a parent window.
387 : If its set to 0, the defmodal-dialog-parent
388 : is used automatically.
389 :
390 : @param pCore
391 : provides access to the recovery core service
392 : and the current list of open documents,
393 : which should be shown inside this dialog.
394 : */
395 : SaveDialog(vcl::Window* pParent, RecoveryCore* pCore);
396 : virtual ~SaveDialog();
397 : virtual void dispose() SAL_OVERRIDE;
398 :
399 : DECL_LINK(OKButtonHdl, void*);
400 : };
401 :
402 : class SaveProgressDialog : public ModalDialog
403 : , public IRecoveryUpdateListener
404 : {
405 : // member
406 : private:
407 : VclPtr<vcl::Window> m_pProgrParent;
408 :
409 : // @short TODO
410 : RecoveryCore* m_pCore;
411 :
412 : // @short TODO
413 : css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
414 : // interface
415 : public:
416 : /** @short create all child controls of this dialog.
417 :
418 : @descr The dialog isn't shown nor it starts any
419 : action by itself!
420 :
421 : @param pParent
422 : can point to a parent window.
423 : If its set to 0, the defmodal-dialog-parent
424 : is used automatically.
425 :
426 : @param pCore
427 : used to start emegrency save.
428 : */
429 : SaveProgressDialog(vcl::Window* pParent,
430 : RecoveryCore* pCore );
431 : virtual ~SaveProgressDialog();
432 : virtual void dispose() SAL_OVERRIDE;
433 :
434 : /** @short start the emergency save operation. */
435 : virtual short Execute() SAL_OVERRIDE;
436 :
437 : // IRecoveryUpdateListener
438 : virtual void updateItems() SAL_OVERRIDE;
439 : virtual void stepNext(TURLInfo* pItem) SAL_OVERRIDE;
440 : virtual void start() SAL_OVERRIDE;
441 : virtual void end() SAL_OVERRIDE;
442 : };
443 :
444 :
445 0 : class RecovDocListEntry : public SvLBoxString
446 : {
447 : public:
448 :
449 :
450 : /** @short TODO */
451 : RecovDocListEntry( SvTreeListEntry* pEntry,
452 : sal_uInt16 nFlags,
453 : const OUString& sText );
454 :
455 :
456 : /** @short TODO */
457 : virtual void Paint(const Point& rPos, SvTreeListBox& rOutDev, vcl::RenderContext& rRenderContext,
458 : const SvViewDataEntry* pView, const SvTreeListEntry& rEntry) SAL_OVERRIDE;
459 : };
460 :
461 :
462 0 : class RecovDocList : public SvSimpleTable
463 : {
464 :
465 : // member
466 : public:
467 :
468 : Image m_aGreenCheckImg;
469 : Image m_aYellowCheckImg;
470 : Image m_aRedCrossImg;
471 :
472 : OUString m_aSuccessRecovStr;
473 : OUString m_aOrigDocRecovStr;
474 : OUString m_aRecovFailedStr;
475 : OUString m_aRecovInProgrStr;
476 : OUString m_aNotRecovYetStr;
477 :
478 :
479 : // interface
480 : public:
481 :
482 :
483 : /** @short TODO */
484 : RecovDocList(SvSimpleTableContainer& rParent, ResMgr& rResMgr);
485 :
486 : /** @short TODO */
487 : virtual void InitEntry(SvTreeListEntry* pEntry,
488 : const OUString& rText,
489 : const Image& rImage1,
490 : const Image& rImage2,
491 : SvLBoxButtonKind eButtonKind) SAL_OVERRIDE;
492 : };
493 :
494 :
495 : class RecoveryDialog : public Dialog
496 : , public IRecoveryUpdateListener
497 : {
498 : // member
499 : private:
500 : VclPtr<FixedText> m_pTitleFT;
501 : VclPtr<FixedText> m_pDescrFT;
502 : VclPtr<vcl::Window> m_pProgrParent;
503 : VclPtr<RecovDocList> m_pFileListLB;
504 : VclPtr<PushButton> m_pNextBtn;
505 : VclPtr<PushButton> m_pCancelBtn;
506 : OUString m_aTitleRecoveryInProgress;
507 : OUString m_aRecoveryOnlyFinish;
508 : OUString m_aRecoveryOnlyFinishDescr;
509 :
510 : RecoveryCore* m_pCore;
511 : css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
512 : enum EInternalRecoveryState
513 : {
514 : E_RECOVERY_PREPARED, // dialog started ... recovery prepared
515 : E_RECOVERY_IN_PROGRESS, // recovery core still in progress
516 : E_RECOVERY_CORE_DONE, // recovery core finished it's task
517 : E_RECOVERY_DONE, // user clicked "next" button
518 : E_RECOVERY_CANCELED, // user clicked "cancel" button
519 : E_RECOVERY_CANCELED_BEFORE, // user clicked "cancel" button before recovery was started
520 : E_RECOVERY_CANCELED_AFTERWARDS, // user clicked "cancel" button after reovery was finished
521 : E_RECOVERY_HANDLED // the recovery wizard page was shown already ... and will be shown now again ...
522 : };
523 : sal_Int32 m_eRecoveryState;
524 : bool m_bWaitForCore;
525 : bool m_bWasRecoveryStarted;
526 :
527 : // member
528 : public:
529 : /** @short TODO */
530 : RecoveryDialog(vcl::Window* pParent,
531 : RecoveryCore* pCore );
532 :
533 : virtual ~RecoveryDialog();
534 : virtual void dispose() SAL_OVERRIDE;
535 :
536 : // IRecoveryUpdateListener
537 : virtual void updateItems() SAL_OVERRIDE;
538 : virtual void stepNext(TURLInfo* pItem) SAL_OVERRIDE;
539 : virtual void start() SAL_OVERRIDE;
540 : virtual void end() SAL_OVERRIDE;
541 :
542 : short execute();
543 :
544 : // helper
545 : private:
546 : /** @short TODO */
547 : DECL_LINK(NextButtonHdl, void*);
548 : DECL_LINK(CancelButtonHdl, void*);
549 :
550 :
551 : /** @short TODO */
552 : OUString impl_getStatusString( const TURLInfo& rInfo ) const;
553 : };
554 :
555 :
556 : class BrokenRecoveryDialog : public ModalDialog
557 : {
558 :
559 : // member
560 : private:
561 : VclPtr<ListBox> m_pFileListLB;
562 : VclPtr<Edit> m_pSaveDirED;
563 : VclPtr<PushButton> m_pSaveDirBtn;
564 : VclPtr<PushButton> m_pOkBtn;
565 : VclPtr<CancelButton> m_pCancelBtn;
566 :
567 : OUString m_sSavePath;
568 : RecoveryCore* m_pCore;
569 : bool m_bBeforeRecovery;
570 : bool m_bExecutionNeeded;
571 :
572 :
573 : // interface
574 : public:
575 :
576 :
577 : /** @short TODO */
578 : BrokenRecoveryDialog(vcl::Window* pParent ,
579 : RecoveryCore* pCore ,
580 : bool bBeforeRecovery);
581 : virtual ~BrokenRecoveryDialog();
582 : virtual void dispose() SAL_OVERRIDE;
583 :
584 :
585 : /** @short TODO */
586 : bool isExecutionNeeded();
587 :
588 :
589 : /** @short TODO */
590 : OUString getSaveDirURL();
591 :
592 :
593 : // helper
594 : private:
595 :
596 :
597 : /** @short TODO */
598 : void impl_refresh();
599 :
600 :
601 : /** @short TODO */
602 : DECL_LINK(SaveButtonHdl, void*);
603 :
604 :
605 : /** @short TODO */
606 : DECL_LINK(OkButtonHdl, void*);
607 :
608 :
609 : /** @short TODO */
610 : DECL_LINK(CancelButtonHdl, void*);
611 :
612 :
613 : /** @short TODO */
614 : void impl_askForSavePath();
615 : };
616 : }
617 : }
618 :
619 : #endif
620 :
621 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|