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 OUString( "vnd.sun.star.autorecovery:")
43 :
44 : #define RECOVERY_CMDPART_DO_EMERGENCY_SAVE OUString( "/doEmergencySave" )
45 : #define RECOVERY_CMDPART_DO_RECOVERY OUString( "/doAutoRecovery" )
46 :
47 : #define RECOVERY_CMD_DO_PREPARE_EMERGENCY_SAVE OUString( "vnd.sun.star.autorecovery:/doPrepareEmergencySave")
48 : #define RECOVERY_CMD_DO_EMERGENCY_SAVE OUString( "vnd.sun.star.autorecovery:/doEmergencySave" )
49 : #define RECOVERY_CMD_DO_RECOVERY OUString( "vnd.sun.star.autorecovery:/doAutoRecovery" )
50 : #define RECOVERY_CMD_DO_ENTRY_BACKUP OUString( "vnd.sun.star.autorecovery:/doEntryBackup" )
51 : #define RECOVERY_CMD_DO_ENTRY_CLEANUP OUString( "vnd.sun.star.autorecovery:/doEntryCleanUp" )
52 :
53 : #define PROP_STATUSINDICATOR OUString( "StatusIndicator" )
54 : #define PROP_DISPATCHASYNCHRON OUString( "DispatchAsynchron")
55 : #define PROP_SAVEPATH OUString( "SavePath" )
56 : #define PROP_ENTRYID OUString( "EntryID" )
57 :
58 : #define STATEPROP_ID OUString( "ID" )
59 : #define STATEPROP_STATE OUString( "DocumentState")
60 : #define STATEPROP_ORGURL OUString( "OriginalURL" )
61 : #define STATEPROP_TEMPURL OUString( "TempURL" )
62 : #define STATEPROP_FACTORYURL OUString( "FactoryURL" )
63 : #define STATEPROP_TEMPLATEURL OUString( "TemplateURL" )
64 : #define STATEPROP_TITLE OUString( "Title" )
65 : #define STATEPROP_MODULE OUString( "Module" )
66 :
67 : #define RECOVERY_OPERATIONSTATE_START OUString( "start" )
68 : #define RECOVERY_OPERATIONSTATE_STOP OUString( "stop" )
69 : #define RECOVERY_OPERATIONSTATE_UPDATE OUString( "update")
70 :
71 : #define DLG_RET_UNKNOWN -1
72 : #define DLG_RET_OK 1
73 : #define DLG_RET_CANCEL 0
74 : #define DLG_RET_BACK 100
75 : #define DLG_RET_OK_AUTOLUNCH 101
76 :
77 :
78 : namespace svx{
79 : namespace DocRecovery{
80 :
81 :
82 : enum EDocStates
83 : {
84 : /* TEMP STATES */
85 :
86 : /// default state, if a document was new created or loaded
87 : E_UNKNOWN = 0,
88 : /// modified against the original file
89 : E_MODIFIED = 1,
90 : /// an active document can be postponed to be saved later.
91 : E_POSTPONED = 2,
92 : /// was already handled during one AutoSave/Recovery session.
93 : E_HANDLED = 4,
94 : /** an action was started (saving/loading) ... Can be interesting later if the process may be was interrupted by an exception. */
95 : E_TRY_SAVE = 8,
96 : E_TRY_LOAD_BACKUP = 16,
97 : E_TRY_LOAD_ORIGINAL = 32,
98 :
99 : /* FINAL STATES */
100 :
101 : /// the Auto/Emergency saved document isn't useable any longer
102 : E_DAMAGED = 64,
103 : /// the Auto/Emergency saved document isnt really up-to-date (some changes can be missing)
104 : E_INCOMPLETE = 128,
105 : /// the Auto/Emergency saved document was processed successfully
106 : E_SUCCEDED = 512
107 : };
108 :
109 :
110 : enum ERecoveryState
111 : {
112 : E_SUCCESSFULLY_RECOVERED,
113 : E_ORIGINAL_DOCUMENT_RECOVERED,
114 : E_RECOVERY_FAILED,
115 : E_RECOVERY_IS_IN_PROGRESS,
116 : E_NOT_RECOVERED_YET
117 : };
118 :
119 :
120 0 : struct TURLInfo
121 : {
122 : public:
123 :
124 : /// unique ID, which is specified by the underlying autorecovery core!
125 : sal_Int32 ID;
126 :
127 : /// the full qualified document URL
128 : OUString OrgURL;
129 :
130 : /// the full qualified URL of the temp. file (if it's exists)
131 : OUString TempURL;
132 :
133 : /// a may be existing factory URL (e.g. for untitled documents)
134 : OUString FactoryURL;
135 :
136 : /// may be the document base on a template file !?
137 : OUString TemplateURL;
138 :
139 : /// the pure file name, without path, disc etcpp.
140 : OUString DisplayName;
141 :
142 : /// the application module, where this document was loaded
143 : OUString Module;
144 :
145 : /// state info as e.g. VALID, CORRUPTED, NON EXISTING ...
146 : sal_Int32 DocState;
147 :
148 : /// ui representation for DocState!
149 : ERecoveryState RecoveryState;
150 :
151 : /// standard icon
152 : Image StandardImage;
153 :
154 : public:
155 :
156 0 : TURLInfo()
157 : : ID (-1 )
158 : , DocState (E_UNKNOWN )
159 0 : , RecoveryState(E_NOT_RECOVERED_YET)
160 0 : {}
161 : };
162 :
163 :
164 : typedef ::std::vector< TURLInfo > TURLList;
165 :
166 :
167 0 : class IRecoveryUpdateListener
168 : {
169 : public:
170 :
171 : // inform listener about changed items, which should be refreshed
172 : virtual void updateItems() = 0;
173 :
174 : // inform listener about starting of the asynchronous recovery operation
175 : virtual void start() = 0;
176 :
177 : // inform listener about ending of the asynchronous recovery operation
178 : virtual void end() = 0;
179 :
180 : // TODO
181 : virtual void stepNext(TURLInfo* pItem) = 0;
182 :
183 : protected:
184 0 : ~IRecoveryUpdateListener() {}
185 : };
186 :
187 :
188 : class RecoveryCore : public ::cppu::WeakImplHelper1< css::frame::XStatusListener >
189 : {
190 :
191 : // types, const
192 : public:
193 :
194 :
195 : // member
196 : private:
197 :
198 : /// TODO
199 : css::uno::Reference< css::uno::XComponentContext > m_xContext;
200 :
201 : /// TODO
202 : css::uno::Reference< css::frame::XDispatch > m_xRealCore;
203 :
204 : /// TODO
205 : css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
206 :
207 : /// TODO
208 : TURLList m_lURLs;
209 :
210 : /// TODO
211 : IRecoveryUpdateListener* m_pListener;
212 :
213 : /** @short knows the reason, why we listen on our internal m_xRealCore
214 : member.
215 :
216 : @descr Because we listen for different operations
217 : on the core dispatch implementation, we must know,
218 : which URL we have to use for deregistration!
219 : */
220 : bool m_bListenForSaving;
221 :
222 :
223 : // native interface
224 : public:
225 :
226 :
227 : /** @short TODO */
228 : RecoveryCore(const css::uno::Reference< css::uno::XComponentContext >& rxContext,
229 : bool bUsedForSaving);
230 :
231 :
232 : /** @short TODO */
233 : virtual ~RecoveryCore();
234 :
235 :
236 : /** @short TODO */
237 : virtual css::uno::Reference< css::uno::XComponentContext > getComponentContext();
238 :
239 :
240 : /** @short TODO */
241 : virtual TURLList* getURLListAccess();
242 :
243 :
244 : /** @short TODO */
245 : static bool isBrokenTempEntry(const TURLInfo& rInfo);
246 : virtual void saveBrokenTempEntries(const OUString& sSaveDir);
247 : virtual void saveAllTempEntries(const OUString& sSaveDir);
248 : virtual void forgetBrokenTempEntries();
249 : virtual void forgetAllRecoveryEntries();
250 : void forgetBrokenRecoveryEntries();
251 :
252 :
253 : /** @short TODO */
254 : virtual void setProgressHandler(const css::uno::Reference< css::task::XStatusIndicator >& xProgress);
255 :
256 :
257 : /** @short TODO */
258 : virtual void setUpdateListener(IRecoveryUpdateListener* pListener);
259 :
260 :
261 : /** @short TODO */
262 : virtual void doEmergencySavePrepare();
263 : virtual void doEmergencySave();
264 : virtual void doRecovery();
265 :
266 :
267 : /** @short TODO */
268 : static ERecoveryState mapDocState2RecoverState(sal_Int32 eDocState);
269 :
270 :
271 : // uno interface
272 : public:
273 :
274 : // css.frame.XStatusListener
275 : virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& aEvent)
276 : throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
277 :
278 : // css.lang.XEventListener
279 : virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent)
280 : throw(css::uno::RuntimeException, std::exception) SAL_OVERRIDE;
281 :
282 :
283 : // helper
284 : private:
285 :
286 :
287 : /** @short starts listening on the internal EmergencySave/AutoRecovery core.
288 : */
289 : void impl_startListening();
290 :
291 :
292 : /** @short stop listening on the internal EmergencySave/AutoRecovery core.
293 : */
294 : void impl_stopListening();
295 :
296 :
297 : /** @short TODO */
298 : css::util::URL impl_getParsedURL(const OUString& sURL);
299 : };
300 :
301 :
302 : class PluginProgressWindow : public vcl::Window
303 : {
304 : private:
305 : css::uno::Reference< css::lang::XComponent > m_xProgress;
306 : public:
307 : PluginProgressWindow( vcl::Window* pParent ,
308 : const css::uno::Reference< css::lang::XComponent >& xProgress);
309 : virtual ~PluginProgressWindow();
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 : 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 0 : class SaveDialog : public Dialog
370 : {
371 : // member
372 : private:
373 : FixedText* m_pTitleFT;
374 : ListBox* m_pFileListLB;
375 : 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 :
397 : DECL_LINK(OKButtonHdl, void*);
398 : };
399 :
400 0 : class SaveProgressDialog : public ModalDialog
401 : , public IRecoveryUpdateListener
402 : {
403 : // member
404 : private:
405 : vcl::Window* m_pProgrParent;
406 :
407 : // @short TODO
408 : RecoveryCore* m_pCore;
409 :
410 : // @short TODO
411 : css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
412 : // interface
413 : public:
414 : /** @short create all child controls of this dialog.
415 :
416 : @descr The dialog isn't shown nor it starts any
417 : action by itself!
418 :
419 : @param pParent
420 : can point to a parent window.
421 : If its set to 0, the defmodal-dialog-parent
422 : is used automatically.
423 :
424 : @param pCore
425 : used to start emegrency save.
426 : */
427 : SaveProgressDialog(vcl::Window* pParent,
428 : RecoveryCore* pCore );
429 :
430 : /** @short start the emergency save operation. */
431 : virtual short Execute() SAL_OVERRIDE;
432 :
433 : // IRecoveryUpdateListener
434 : virtual void updateItems() SAL_OVERRIDE;
435 : virtual void stepNext(TURLInfo* pItem) SAL_OVERRIDE;
436 : virtual void start() SAL_OVERRIDE;
437 : virtual void end() SAL_OVERRIDE;
438 : };
439 :
440 :
441 0 : class RecovDocListEntry : public SvLBoxString
442 : {
443 : public:
444 :
445 :
446 : /** @short TODO */
447 : RecovDocListEntry( SvTreeListEntry* pEntry,
448 : sal_uInt16 nFlags,
449 : const OUString& sText );
450 :
451 :
452 : /** @short TODO */
453 : virtual void Paint(
454 : const Point& rPos, SvTreeListBox& rOutDev, const SvViewDataEntry* pView, const SvTreeListEntry* pEntry) SAL_OVERRIDE;
455 : };
456 :
457 :
458 : class RecovDocList : public SvSimpleTable
459 : {
460 :
461 : // member
462 : public:
463 :
464 : Image m_aGreenCheckImg;
465 : Image m_aYellowCheckImg;
466 : Image m_aRedCrossImg;
467 :
468 : OUString m_aSuccessRecovStr;
469 : OUString m_aOrigDocRecovStr;
470 : OUString m_aRecovFailedStr;
471 : OUString m_aRecovInProgrStr;
472 : OUString m_aNotRecovYetStr;
473 :
474 :
475 : // interface
476 : public:
477 :
478 :
479 : /** @short TODO */
480 : RecovDocList(SvSimpleTableContainer& rParent, ResMgr& rResMgr);
481 :
482 : /** @short TODO */
483 : virtual ~RecovDocList();
484 :
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 : FixedText* m_pTitleFT;
501 : FixedText* m_pDescrFT;
502 : vcl::Window* m_pProgrParent;
503 : RecovDocList* m_pFileListLB;
504 : PushButton* m_pNextBtn;
505 : 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 :
535 : // IRecoveryUpdateListener
536 : virtual void updateItems() SAL_OVERRIDE;
537 : virtual void stepNext(TURLInfo* pItem) SAL_OVERRIDE;
538 : virtual void start() SAL_OVERRIDE;
539 : virtual void end() SAL_OVERRIDE;
540 :
541 : short execute();
542 :
543 : // helper
544 : private:
545 : /** @short TODO */
546 : DECL_LINK(NextButtonHdl, void*);
547 : DECL_LINK(CancelButtonHdl, void*);
548 :
549 :
550 : /** @short TODO */
551 : OUString impl_getStatusString( const TURLInfo& rInfo ) const;
552 : };
553 :
554 :
555 : class BrokenRecoveryDialog : public ModalDialog
556 : {
557 :
558 : // member
559 : private:
560 : ListBox *m_pFileListLB;
561 : Edit *m_pSaveDirED;
562 : PushButton *m_pSaveDirBtn;
563 : PushButton *m_pOkBtn;
564 : CancelButton *m_pCancelBtn;
565 :
566 : OUString m_sSavePath;
567 : RecoveryCore* m_pCore;
568 : bool m_bBeforeRecovery;
569 : bool m_bExecutionNeeded;
570 :
571 :
572 : // interface
573 : public:
574 :
575 :
576 : /** @short TODO */
577 : BrokenRecoveryDialog(vcl::Window* pParent ,
578 : RecoveryCore* pCore ,
579 : bool bBeforeRecovery);
580 :
581 :
582 : /** @short TODO */
583 : virtual ~BrokenRecoveryDialog();
584 :
585 :
586 : /** @short TODO */
587 : virtual bool isExecutionNeeded();
588 :
589 :
590 : /** @short TODO */
591 : virtual OUString getSaveDirURL();
592 :
593 :
594 : // helper
595 : private:
596 :
597 :
598 : /** @short TODO */
599 : void impl_refresh();
600 :
601 :
602 : /** @short TODO */
603 : DECL_LINK(SaveButtonHdl, void*);
604 :
605 :
606 : /** @short TODO */
607 : DECL_LINK(OkButtonHdl, void*);
608 :
609 :
610 : /** @short TODO */
611 : DECL_LINK(CancelButtonHdl, void*);
612 :
613 :
614 : /** @short TODO */
615 : void impl_askForSavePath();
616 : };
617 : } // namespace DocRecovery
618 : } // namespace svx
619 :
620 : #endif
621 :
622 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|