1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef __FRAMEWORK_SERVICES_AUTORECOVERY_HXX_
29*cdf0e10cSrcweir #define __FRAMEWORK_SERVICES_AUTORECOVERY_HXX_
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir //_______________________________________________
32*cdf0e10cSrcweir // own includes
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include <threadhelp/threadhelpbase.hxx>
35*cdf0e10cSrcweir #include <macros/xinterface.hxx>
36*cdf0e10cSrcweir #include <macros/xtypeprovider.hxx>
37*cdf0e10cSrcweir #include <macros/xserviceinfo.hxx>
38*cdf0e10cSrcweir #include <general.h>
39*cdf0e10cSrcweir #include <stdtypes.h>
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir //_______________________________________________
42*cdf0e10cSrcweir // interface includes
43*cdf0e10cSrcweir #include <com/sun/star/uno/XInterface.hpp>
44*cdf0e10cSrcweir #include <com/sun/star/lang/XTypeProvider.hpp>
45*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
46*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
47*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp>
48*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
49*cdf0e10cSrcweir #include <com/sun/star/document/XEventListener.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/document/XEventBroadcaster.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/util/XChangesListener.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/task/XStatusIndicator.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/util/XModifyListener.hpp>
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir //_______________________________________________
57*cdf0e10cSrcweir // other includes
58*cdf0e10cSrcweir #include <comphelper/mediadescriptor.hxx>
59*cdf0e10cSrcweir #include <vcl/timer.hxx>
60*cdf0e10cSrcweir #include <vcl/evntpost.hxx>
61*cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
62*cdf0e10cSrcweir #include <cppuhelper/propshlp.hxx>
63*cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir //_______________________________________________
66*cdf0e10cSrcweir // definition
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir #ifndef css
69*cdf0e10cSrcweir namespace css = ::com::sun::star;
70*cdf0e10cSrcweir #endif
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir namespace framework
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir //---------------------------------------
76*cdf0e10cSrcweir /** @short  hold all needed informations for an asynchronous dispatch alive.
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir     @descr  Because some operations are forced to be executed asynchronously
79*cdf0e10cSrcweir             (e.g. requested by our CreashSave/Recovery dialog) ... we must make sure
80*cdf0e10cSrcweir             that these informations wont be set as "normal" members of our AtoRecovery
81*cdf0e10cSrcweir             instance. Otherwise they can disturb our normal AutoSave-timer handling.
82*cdf0e10cSrcweir             e.g. it can be unclear then, which progress has to be used for storing documents ...
83*cdf0e10cSrcweir  */
84*cdf0e10cSrcweir struct DispatchParams
85*cdf0e10cSrcweir {
86*cdf0e10cSrcweir     public:
87*cdf0e10cSrcweir          DispatchParams();
88*cdf0e10cSrcweir          DispatchParams(const ::comphelper::SequenceAsHashMap&             lArgs ,
89*cdf0e10cSrcweir                         const css::uno::Reference< css::uno::XInterface >& xOwner);
90*cdf0e10cSrcweir          DispatchParams(const DispatchParams& rCopy);
91*cdf0e10cSrcweir         ~DispatchParams();
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir          DispatchParams& operator=(const DispatchParams& rCopy);
94*cdf0e10cSrcweir          void forget();
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir     public:
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir         //---------------------------------------
99*cdf0e10cSrcweir         /** @short  can be set from outside and is provided to
100*cdf0e10cSrcweir                     our internal started operations.
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir             @descr  Normaly we use the normal status indicator
103*cdf0e10cSrcweir                     of the document windows to show a progress.
104*cdf0e10cSrcweir                     But in case we are used by any special UI,
105*cdf0e10cSrcweir                     it can provide its own status indicator object
106*cdf0e10cSrcweir                     to us - so we use it instead of the normal one.
107*cdf0e10cSrcweir          */
108*cdf0e10cSrcweir         css::uno::Reference< css::task::XStatusIndicator > m_xProgress;
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir         //---------------------------------------
111*cdf0e10cSrcweir         /** TODO document me */
112*cdf0e10cSrcweir         ::rtl::OUString m_sSavePath;
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir         //---------------------------------------
115*cdf0e10cSrcweir         /** @short  define the current cache entry, which should be used for current
116*cdf0e10cSrcweir                     backup or cleanUp operation ... which is may be done asynchronous */
117*cdf0e10cSrcweir         sal_Int32 m_nWorkingEntryID;
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir         //---------------------------------------
120*cdf0e10cSrcweir         /** @short  used for asyncoperations, to prevent us from dying.
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir             @descr  If our dispatch() method was forced to start the
123*cdf0e10cSrcweir                     internal operation asynchronous ... we send an event
124*cdf0e10cSrcweir                     to start and return immediatly. But we must be shure that
125*cdf0e10cSrcweir                     our instance live if the event callback reach us.
126*cdf0e10cSrcweir                     So we hold an uno reference to ourself.
127*cdf0e10cSrcweir          */
128*cdf0e10cSrcweir         css::uno::Reference< css::uno::XInterface > m_xHoldRefForAsyncOpAlive;
129*cdf0e10cSrcweir };
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir //_______________________________________________
132*cdf0e10cSrcweir /**
133*cdf0e10cSrcweir     implements the functionality of AutoSave and AutoRecovery
134*cdf0e10cSrcweir     of documents - including features of an EmergencySave in
135*cdf0e10cSrcweir     case a GPF occures.
136*cdf0e10cSrcweir  */
137*cdf0e10cSrcweir class AutoRecovery  : public  css::lang::XTypeProvider
138*cdf0e10cSrcweir                     , public  css::lang::XServiceInfo
139*cdf0e10cSrcweir                     , public  css::frame::XDispatch
140*cdf0e10cSrcweir                     , public  css::document::XEventListener         // => css.lang.XEventListener
141*cdf0e10cSrcweir                     , public  css::util::XChangesListener           // => css.lang.XEventListener
142*cdf0e10cSrcweir                     , public  css::util::XModifyListener            // => css.lang.XEventListener
143*cdf0e10cSrcweir                     // attention! Must be the first base class to guarentee right initialize lock ...
144*cdf0e10cSrcweir                     , private ThreadHelpBase
145*cdf0e10cSrcweir                     , public  ::cppu::OBroadcastHelper
146*cdf0e10cSrcweir                     , public  ::cppu::OPropertySetHelper            // => XPropertySet, XFastPropertySet, XMultiPropertySet
147*cdf0e10cSrcweir                     , public  ::cppu::OWeakObject
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir     //___________________________________________
150*cdf0e10cSrcweir     // types
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir     public:
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir         /** These values are used as flags and represent the current state of a document.
155*cdf0e10cSrcweir             Every state of the life time of a document has to be recognized here.
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir             @attention  Do not change (means reorganize) already used numbers.
158*cdf0e10cSrcweir                         There exists some code inside SVX, which uses the same numbers,
159*cdf0e10cSrcweir                         to analyze such document states.
160*cdf0e10cSrcweir                         Not the best design ... but may be it will be changed later .-)
161*cdf0e10cSrcweir         */
162*cdf0e10cSrcweir         enum EDocStates
163*cdf0e10cSrcweir         {
164*cdf0e10cSrcweir             /* TEMP STATES */
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir             /// default state, if a document was new created or loaded
167*cdf0e10cSrcweir             E_UNKNOWN = 0,
168*cdf0e10cSrcweir             /// modified against the original file
169*cdf0e10cSrcweir             E_MODIFIED = 1,
170*cdf0e10cSrcweir             /// an active document can be postponed to be saved later.
171*cdf0e10cSrcweir             E_POSTPONED = 2,
172*cdf0e10cSrcweir             /// was already handled during one AutoSave/Recovery session.
173*cdf0e10cSrcweir             E_HANDLED = 4,
174*cdf0e10cSrcweir             /** an action was started (saving/loading) ... Can be interesting later if the process may be was interrupted by an exception. */
175*cdf0e10cSrcweir             E_TRY_SAVE = 8,
176*cdf0e10cSrcweir             E_TRY_LOAD_BACKUP = 16,
177*cdf0e10cSrcweir             E_TRY_LOAD_ORIGINAL = 32,
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir             /* FINAL STATES */
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir             /// the Auto/Emergency saved document isnt useable any longer
182*cdf0e10cSrcweir             E_DAMAGED = 64,
183*cdf0e10cSrcweir             /// the Auto/Emergency saved document isnt realy up-to-date (some changes can be missing)
184*cdf0e10cSrcweir             E_INCOMPLETE = 128,
185*cdf0e10cSrcweir             /// the Auto/Emergency saved document was processed successfully
186*cdf0e10cSrcweir             E_SUCCEDED = 512
187*cdf0e10cSrcweir         };
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir         /** @short  indicates the results of a FAILURE_SAFE operation
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir             @descr  We must know, which reason was the real one in case
192*cdf0e10cSrcweir                     we couldnt copy a "failure document" to a user specified path.
193*cdf0e10cSrcweir                     We must know, if we can forget our cache entry or not.
194*cdf0e10cSrcweir          */
195*cdf0e10cSrcweir         enum EFailureSafeResult
196*cdf0e10cSrcweir         {
197*cdf0e10cSrcweir             E_COPIED,
198*cdf0e10cSrcweir             E_ORIGINAL_FILE_MISSING,
199*cdf0e10cSrcweir             E_WRONG_TARGET_PATH
200*cdf0e10cSrcweir         };
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir         // TODO document me
203*cdf0e10cSrcweir         enum ETimerType
204*cdf0e10cSrcweir         {
205*cdf0e10cSrcweir             /** the timer shouldnt be used next time */
206*cdf0e10cSrcweir             E_DONT_START_TIMER,
207*cdf0e10cSrcweir             /** timer (was/must be) started with normal AutoSaveTimeIntervall */
208*cdf0e10cSrcweir             E_NORMAL_AUTOSAVE_INTERVALL,
209*cdf0e10cSrcweir             /** timer must be started with special short time intervall,
210*cdf0e10cSrcweir                 to poll for an user idle period */
211*cdf0e10cSrcweir             E_POLL_FOR_USER_IDLE,
212*cdf0e10cSrcweir             /** timer mst be started with a very(!) short time intervall,
213*cdf0e10cSrcweir                 to poll for the end of an user action, which does not allow saving documents in general */
214*cdf0e10cSrcweir             E_POLL_TILL_AUTOSAVE_IS_ALLOWED,
215*cdf0e10cSrcweir             /** dont start the timer - but calls the same action then before immediatly again! */
216*cdf0e10cSrcweir             E_CALL_ME_BACK
217*cdf0e10cSrcweir         };
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir         // TODO document me ... flag field
220*cdf0e10cSrcweir         // Emergency_Save and Recovery overwrites Auto_Save!
221*cdf0e10cSrcweir         enum EJob
222*cdf0e10cSrcweir         {
223*cdf0e10cSrcweir             E_NO_JOB                    =   0,
224*cdf0e10cSrcweir             E_AUTO_SAVE                 =   1,
225*cdf0e10cSrcweir             E_EMERGENCY_SAVE            =   2,
226*cdf0e10cSrcweir             E_RECOVERY                  =   4,
227*cdf0e10cSrcweir             E_ENTRY_BACKUP              =   8,
228*cdf0e10cSrcweir             E_ENTRY_CLEANUP             =  16,
229*cdf0e10cSrcweir             E_PREPARE_EMERGENCY_SAVE    =  32,
230*cdf0e10cSrcweir             E_SESSION_SAVE              =  64,
231*cdf0e10cSrcweir             E_SESSION_RESTORE           = 128,
232*cdf0e10cSrcweir             E_DISABLE_AUTORECOVERY      = 256,
233*cdf0e10cSrcweir             E_SET_AUTOSAVE_STATE        = 512,
234*cdf0e10cSrcweir             E_SESSION_QUIET_QUIT        = 1024
235*cdf0e10cSrcweir         };
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir         //---------------------------------------
238*cdf0e10cSrcweir         /** @short  combine different informations about one office document. */
239*cdf0e10cSrcweir         struct TDocumentInfo
240*cdf0e10cSrcweir         {
241*cdf0e10cSrcweir             public:
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir                 //-------------------------------
244*cdf0e10cSrcweir                 TDocumentInfo()
245*cdf0e10cSrcweir 					: DocumentState   (E_UNKNOWN)
246*cdf0e10cSrcweir                     , UsedForSaving   (sal_False)
247*cdf0e10cSrcweir                     , ListenForModify (sal_False)
248*cdf0e10cSrcweir                     , IgnoreClosing   (sal_False)
249*cdf0e10cSrcweir                     , ID              (-1       )
250*cdf0e10cSrcweir                 {}
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir                 //-------------------------------
253*cdf0e10cSrcweir                 /** @short  points to the document. */
254*cdf0e10cSrcweir                 css::uno::Reference< css::frame::XModel > Document;
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir                 //-------------------------------
257*cdf0e10cSrcweir                 /** @short  knows, if the document is realy modified since the last autosave,
258*cdf0e10cSrcweir                             or  was postponed, because it was an active one etcpp...
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir                     @descr  Because we have no CHANGE TRACKING mechanism, based on office document,
261*cdf0e10cSrcweir                             we implements it by ourself. We listen for MODIFIED events
262*cdf0e10cSrcweir                             of each document and update this state flag here.
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir                             Further we postpone saving of active documents, e.g. if the user
265*cdf0e10cSrcweir                             works currently on it. We wait for an idle period then ...
266*cdf0e10cSrcweir                  */
267*cdf0e10cSrcweir                 sal_Int32 DocumentState;
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir                 //-------------------------------
270*cdf0e10cSrcweir                 /** Because our applications not ready for concurrent save requests at the same time,
271*cdf0e10cSrcweir                     we have supress our own AutoSave for the moment, a document will be already saved
272*cdf0e10cSrcweir                     by others.
273*cdf0e10cSrcweir                  */
274*cdf0e10cSrcweir                 sal_Bool UsedForSaving;
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir                 //-------------------------------
277*cdf0e10cSrcweir                 /** For every user action, which modifies a document (e.g. key input) we get
278*cdf0e10cSrcweir                     a notification as XModifyListener. That seams to be a "performance issue" .-)
279*cdf0e10cSrcweir                     So we decided to listen for such modify events only for the time in which the document
280*cdf0e10cSrcweir                     was stored as temp. file and was not modified again by the user.
281*cdf0e10cSrcweir                 */
282*cdf0e10cSrcweir                 sal_Bool ListenForModify;
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir                 //-------------------------------
285*cdf0e10cSrcweir                 /** For SessionSave we must close all open documents by ourself.
286*cdf0e10cSrcweir                     But because we are listen for documents events, we get some ...
287*cdf0e10cSrcweir                     and deregister these documents from our configuration.
288*cdf0e10cSrcweir                     That's why we mark these documents as "Closed by ourself" so we can
289*cdf0e10cSrcweir                     ignore these "OnUnload" or disposing() events .-)
290*cdf0e10cSrcweir                 */
291*cdf0e10cSrcweir                 sal_Bool IgnoreClosing;
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir                 //-------------------------------
294*cdf0e10cSrcweir                 /** TODO: document me */
295*cdf0e10cSrcweir                 ::rtl::OUString OrgURL;
296*cdf0e10cSrcweir                 ::rtl::OUString FactoryURL;
297*cdf0e10cSrcweir                 ::rtl::OUString TemplateURL;
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir                 ::rtl::OUString OldTempURL;
300*cdf0e10cSrcweir                 ::rtl::OUString NewTempURL;
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir                 ::rtl::OUString AppModule;      // e.g. com.sun.star.text.TextDocument - used to identify app module
303*cdf0e10cSrcweir                 ::rtl::OUString FactoryService; // the service to create a document of the module
304*cdf0e10cSrcweir                 ::rtl::OUString RealFilter;     // real filter, which was used at loading time
305*cdf0e10cSrcweir                 ::rtl::OUString DefaultFilter;  // supports saving of the default format without loosing data
306*cdf0e10cSrcweir                 ::rtl::OUString Extension;      // file extension of the default filter
307*cdf0e10cSrcweir                 ::rtl::OUString Title;          // can be used as "DisplayName" on every recovery UI!
308*cdf0e10cSrcweir                 ::com::sun::star::uno::Sequence< ::rtl::OUString >
309*cdf0e10cSrcweir                                 ViewNames;      // names of the view which were active at emergency-save time
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir                 sal_Int32 ID;
312*cdf0e10cSrcweir         };
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir         //---------------------------------------
315*cdf0e10cSrcweir         /** @short  used to know every currently open document. */
316*cdf0e10cSrcweir         typedef ::std::vector< TDocumentInfo > TDocumentList;
317*cdf0e10cSrcweir 
318*cdf0e10cSrcweir     //___________________________________________
319*cdf0e10cSrcweir     // member
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir     private:
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir         //---------------------------------------
324*cdf0e10cSrcweir         /** @short  the global uno service manager.
325*cdf0e10cSrcweir             @descr  Must be used to create own needed services.
326*cdf0e10cSrcweir          */
327*cdf0e10cSrcweir         css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir         //---------------------------------------
330*cdf0e10cSrcweir         /** @short  points to the underlying recovery configuration.
331*cdf0e10cSrcweir             @descr  This instance does not cache - it calls directly the
332*cdf0e10cSrcweir                     configuration API!
333*cdf0e10cSrcweir           */
334*cdf0e10cSrcweir         css::uno::Reference< css::container::XNameAccess > m_xRecoveryCFG;
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir         //---------------------------------------
337*cdf0e10cSrcweir         /** @short  points to the used configuration package or.openoffice.Setup
338*cdf0e10cSrcweir             @descr  This instance does not cache - it calls directly the
339*cdf0e10cSrcweir                     configuration API!
340*cdf0e10cSrcweir           */
341*cdf0e10cSrcweir         css::uno::Reference< css::container::XNameAccess > m_xModuleCFG;
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir         //---------------------------------------
344*cdf0e10cSrcweir         /** @short  holds the global event broadcaster alive,
345*cdf0e10cSrcweir                     where we listen for new created documents.
346*cdf0e10cSrcweir           */
347*cdf0e10cSrcweir         css::uno::Reference< css::document::XEventBroadcaster > m_xNewDocBroadcaster;
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir         //---------------------------------------
350*cdf0e10cSrcweir         /** @short  because we stop/restart listening sometimes, it's a good idea to know
351*cdf0e10cSrcweir                     if we already registered as listener .-)
352*cdf0e10cSrcweir         */
353*cdf0e10cSrcweir         sal_Bool m_bListenForDocEvents;
354*cdf0e10cSrcweir         sal_Bool m_bListenForConfigChanges;
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir         //---------------------------------------
357*cdf0e10cSrcweir         /** @short  specify the time intervall between two save actions.
358*cdf0e10cSrcweir             @descr  Time is measured in [min].
359*cdf0e10cSrcweir          */
360*cdf0e10cSrcweir         sal_Int32 m_nAutoSaveTimeIntervall;
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir         //---------------------------------------
363*cdf0e10cSrcweir         /** @short  for an asynchronous operation we must know, if there is
364*cdf0e10cSrcweir                     at least one running job (may be asynchronous!).
365*cdf0e10cSrcweir          */
366*cdf0e10cSrcweir         sal_Int32 m_eJob;
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir         //---------------------------------------
369*cdf0e10cSrcweir         /** @short  the timer, which is used to be informed about the next
370*cdf0e10cSrcweir                     saving time ...
371*cdf0e10cSrcweir          */
372*cdf0e10cSrcweir         Timer m_aTimer;
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir         //---------------------------------------
375*cdf0e10cSrcweir         /** @short  make our dispatch asynchronous ... if required to do so! */
376*cdf0e10cSrcweir         ::vcl::EventPoster m_aAsyncDispatcher;
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir         //---------------------------------------
379*cdf0e10cSrcweir         /** @see    DispatchParams
380*cdf0e10cSrcweir          */
381*cdf0e10cSrcweir         DispatchParams m_aDispatchParams;
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir         //---------------------------------------
384*cdf0e10cSrcweir         /** @short  indicates, which time period is currently used by the
385*cdf0e10cSrcweir                     internal timer.
386*cdf0e10cSrcweir          */
387*cdf0e10cSrcweir         ETimerType m_eTimerType;
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir         //---------------------------------------
390*cdf0e10cSrcweir         /** @short  this cache is used to hold all informations about
391*cdf0e10cSrcweir                     recovery/emergency save documents alive.
392*cdf0e10cSrcweir          */
393*cdf0e10cSrcweir         TDocumentList m_lDocCache;
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir         //---------------------------------------
396*cdf0e10cSrcweir         // TODO document me
397*cdf0e10cSrcweir         sal_Int32 m_nIdPool;
398*cdf0e10cSrcweir 
399*cdf0e10cSrcweir         //---------------------------------------
400*cdf0e10cSrcweir         /** @short  contains all status listener registered at this instance.
401*cdf0e10cSrcweir          */
402*cdf0e10cSrcweir         ListenerHash m_lListener;
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir         /** @descr  This member is used to prevent us against re-entrance problems.
405*cdf0e10cSrcweir                     A mutex cant help to prevent us from concurrent using of members
406*cdf0e10cSrcweir                     inside the same thread. But e.g. our internaly used stl structures
407*cdf0e10cSrcweir                     are not threadsafe ... and furthermore they cant be used at the same time
408*cdf0e10cSrcweir                     for iteration and add/remove requests!
409*cdf0e10cSrcweir                     So we have to detect such states and ... show a warning.
410*cdf0e10cSrcweir                     May be there will be a better solution next time ... (copying the cache temp.
411*cdf0e10cSrcweir                     bevor using).
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir                     And further it's not possible to use a simple boolean value here.
414*cdf0e10cSrcweir                     Because if more then one operation iterates over the same stl container ...
415*cdf0e10cSrcweir                     (only to modify it's elements but dont add new or removing existing ones!)
416*cdf0e10cSrcweir                     it should be possible doing so. But we must guarantee that the last operation reset
417*cdf0e10cSrcweir                     this lock ... not the first one ! So we use a "ref count" mechanism for that."
418*cdf0e10cSrcweir          */
419*cdf0e10cSrcweir         sal_Int32 m_nDocCacheLock;
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir         /** @descr  These members are used to check the minimum disc space, which must exists
422*cdf0e10cSrcweir                     to start the corresponding operation.
423*cdf0e10cSrcweir          */
424*cdf0e10cSrcweir         sal_Int32 m_nMinSpaceDocSave;
425*cdf0e10cSrcweir         sal_Int32 m_nMinSpaceConfigSave;
426*cdf0e10cSrcweir 
427*cdf0e10cSrcweir         //---------------------------------------
428*cdf0e10cSrcweir         /** @short  special debug option to make testing faster.
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir             @descr  We dont interpret the timer unit as [min] ...
431*cdf0e10cSrcweir                     we use [ms] instead of that. Further we dont
432*cdf0e10cSrcweir                     wait 10 s for user idle ...
433*cdf0e10cSrcweir          */
434*cdf0e10cSrcweir         #if OSL_DEBUG_LEVEL > 1
435*cdf0e10cSrcweir         sal_Bool m_dbg_bMakeItFaster;
436*cdf0e10cSrcweir         #endif
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir         //---------------------------------------
439*cdf0e10cSrcweir         // HACK ... TODO
440*cdf0e10cSrcweir         css::uno::Reference< css::task::XStatusIndicator > m_xExternalProgress;
441*cdf0e10cSrcweir 
442*cdf0e10cSrcweir     //___________________________________________
443*cdf0e10cSrcweir     // interface
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir     public:
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir                  AutoRecovery(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR);
448*cdf0e10cSrcweir         virtual ~AutoRecovery(                                                                   );
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir         // XInterface, XTypeProvider, XServiceInfo
451*cdf0e10cSrcweir         FWK_DECLARE_XINTERFACE
452*cdf0e10cSrcweir         FWK_DECLARE_XTYPEPROVIDER
453*cdf0e10cSrcweir         DECLARE_XSERVICEINFO
454*cdf0e10cSrcweir 
455*cdf0e10cSrcweir         //---------------------------------------
456*cdf0e10cSrcweir         // css.frame.XDispatch
457*cdf0e10cSrcweir         virtual void SAL_CALL dispatch(const css::util::URL&                                  aURL      ,
458*cdf0e10cSrcweir                                        const css::uno::Sequence< css::beans::PropertyValue >& lArguments)
459*cdf0e10cSrcweir             throw(css::uno::RuntimeException);
460*cdf0e10cSrcweir 
461*cdf0e10cSrcweir         virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener >& xListener,
462*cdf0e10cSrcweir                                                 const css::util::URL&                                     aURL     )
463*cdf0e10cSrcweir             throw(css::uno::RuntimeException);
464*cdf0e10cSrcweir 
465*cdf0e10cSrcweir         virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >& xListener,
466*cdf0e10cSrcweir                                                    const css::util::URL&                                     aURL     )
467*cdf0e10cSrcweir             throw(css::uno::RuntimeException);
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir         //---------------------------------------
470*cdf0e10cSrcweir         // css.document.XEventListener
471*cdf0e10cSrcweir         /** @short  informs about created/opened documents.
472*cdf0e10cSrcweir 
473*cdf0e10cSrcweir             @descr  Every new opened/created document will be saved internaly
474*cdf0e10cSrcweir                     so it can be checked if its modified. This modified state
475*cdf0e10cSrcweir                     is used later to decide, if it must be saved or not.
476*cdf0e10cSrcweir 
477*cdf0e10cSrcweir             @param  aEvent
478*cdf0e10cSrcweir                     points to the new created/opened document.
479*cdf0e10cSrcweir          */
480*cdf0e10cSrcweir         virtual void SAL_CALL notifyEvent(const css::document::EventObject& aEvent)
481*cdf0e10cSrcweir             throw(css::uno::RuntimeException);
482*cdf0e10cSrcweir 
483*cdf0e10cSrcweir         //---------------------------------------
484*cdf0e10cSrcweir         // css.util.XChangesListener
485*cdf0e10cSrcweir         virtual void SAL_CALL changesOccurred(const css::util::ChangesEvent& aEvent)
486*cdf0e10cSrcweir             throw(css::uno::RuntimeException);
487*cdf0e10cSrcweir 
488*cdf0e10cSrcweir         //---------------------------------------
489*cdf0e10cSrcweir         // css.util.XModifyListener
490*cdf0e10cSrcweir         virtual void SAL_CALL modified(const css::lang::EventObject& aEvent)
491*cdf0e10cSrcweir             throw(css::uno::RuntimeException);
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir         //---------------------------------------
494*cdf0e10cSrcweir         // css.lang.XEventListener
495*cdf0e10cSrcweir         using cppu::OPropertySetHelper::disposing;
496*cdf0e10cSrcweir         virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent)
497*cdf0e10cSrcweir             throw(css::uno::RuntimeException);
498*cdf0e10cSrcweir 
499*cdf0e10cSrcweir     //___________________________________________
500*cdf0e10cSrcweir     // helper
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir 	protected:
503*cdf0e10cSrcweir 
504*cdf0e10cSrcweir         //---------------------------------------
505*cdf0e10cSrcweir 		// OPropertySetHelper
506*cdf0e10cSrcweir 
507*cdf0e10cSrcweir 		virtual sal_Bool SAL_CALL convertFastPropertyValue(      css::uno::Any& aConvertedValue,
508*cdf0e10cSrcweir                                                                  css::uno::Any&	aOldValue      ,
509*cdf0e10cSrcweir                                                                  sal_Int32		nHandle        ,
510*cdf0e10cSrcweir                                                            const css::uno::Any&	aValue         )
511*cdf0e10cSrcweir             throw(css::lang::IllegalArgumentException);
512*cdf0e10cSrcweir 
513*cdf0e10cSrcweir 		virtual void SAL_CALL setFastPropertyValue_NoBroadcast(      sal_Int32      nHandle,
514*cdf0e10cSrcweir                                                                const css::uno::Any& aValue )
515*cdf0e10cSrcweir             throw(css::uno::Exception);
516*cdf0e10cSrcweir         using cppu::OPropertySetHelper::getFastPropertyValue;
517*cdf0e10cSrcweir 		virtual void SAL_CALL getFastPropertyValue(css::uno::Any& aValue ,
518*cdf0e10cSrcweir                                                    sal_Int32      nHandle) const;
519*cdf0e10cSrcweir 
520*cdf0e10cSrcweir 		virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir 		virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo()
523*cdf0e10cSrcweir             throw(css::uno::RuntimeException);
524*cdf0e10cSrcweir     //___________________________________________
525*cdf0e10cSrcweir     // helper
526*cdf0e10cSrcweir 
527*cdf0e10cSrcweir     private:
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir         //---------------------------------------
530*cdf0e10cSrcweir         /** @short  open the underlying configuration.
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir             @descr  This method must be called everytimes
533*cdf0e10cSrcweir                     a configuartion call is needed. Because
534*cdf0e10cSrcweir                     method works together with the member
535*cdf0e10cSrcweir                     m_xCFG, open it on demand and cache it
536*cdf0e10cSrcweir                     afterwards.
537*cdf0e10cSrcweir 
538*cdf0e10cSrcweir             @return [com.sun.star.container.XNameAccess]
539*cdf0e10cSrcweir                     the configuration object
540*cdf0e10cSrcweir 
541*cdf0e10cSrcweir             @throw  [com.sun.star.uno.RuntimeException]
542*cdf0e10cSrcweir                     if config could not be opened successfully!
543*cdf0e10cSrcweir 
544*cdf0e10cSrcweir             @threadsafe
545*cdf0e10cSrcweir           */
546*cdf0e10cSrcweir         css::uno::Reference< css::container::XNameAccess > implts_openConfig();
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir         //---------------------------------------
549*cdf0e10cSrcweir         /** @short  read the underlying configuration.
550*cdf0e10cSrcweir 
551*cdf0e10cSrcweir             @descr  After that we know the initial state - means:
552*cdf0e10cSrcweir                     - if AutoSave was enabled by the user
553*cdf0e10cSrcweir                     - which time intervall has to be used
554*cdf0e10cSrcweir                     - which recovery entries may already exists
555*cdf0e10cSrcweir 
556*cdf0e10cSrcweir             @throw  [com.sun.star.uno.RuntimeException]
557*cdf0e10cSrcweir                     if config could not be opened or readed successfully!
558*cdf0e10cSrcweir 
559*cdf0e10cSrcweir             @threadsafe
560*cdf0e10cSrcweir           */
561*cdf0e10cSrcweir         void implts_readConfig();
562*cdf0e10cSrcweir 
563*cdf0e10cSrcweir         //---------------------------------------
564*cdf0e10cSrcweir         /** @short  read the underlying configuration...
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir             @descr  ... but only keys related to the AutoSave mechanism.
567*cdf0e10cSrcweir                     Means: State and Timer intervall.
568*cdf0e10cSrcweir                     E.g. the recovery list isnt adressed here.
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir             @throw  [com.sun.star.uno.RuntimeException]
571*cdf0e10cSrcweir                     if config could not be opened or readed successfully!
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir             @threadsafe
574*cdf0e10cSrcweir           */
575*cdf0e10cSrcweir         void implts_readAutoSaveConfig();
576*cdf0e10cSrcweir 
577*cdf0e10cSrcweir         //---------------------------------------
578*cdf0e10cSrcweir         // TODO document me
579*cdf0e10cSrcweir         void implts_flushConfigItem(const AutoRecovery::TDocumentInfo& rInfo                ,
580*cdf0e10cSrcweir                                           sal_Bool                     bRemoveIt = sal_False);
581*cdf0e10cSrcweir 
582*cdf0e10cSrcweir         //---------------------------------------
583*cdf0e10cSrcweir         // TODO document me
584*cdf0e10cSrcweir         void implts_startListening();
585*cdf0e10cSrcweir         void implts_startModifyListeningOnDoc(AutoRecovery::TDocumentInfo& rInfo);
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir         //---------------------------------------
588*cdf0e10cSrcweir         // TODO document me
589*cdf0e10cSrcweir         void implts_stopListening();
590*cdf0e10cSrcweir         void implts_stopModifyListeningOnDoc(AutoRecovery::TDocumentInfo& rInfo);
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir         //---------------------------------------
593*cdf0e10cSrcweir         /** @short  stops and may be(!) restarts the timer.
594*cdf0e10cSrcweir 
595*cdf0e10cSrcweir             @descr  A running timer is stopped everytimes here.
596*cdf0e10cSrcweir                     But starting depends from the different internal
597*cdf0e10cSrcweir                     timer variables (e.g. AutoSaveEnabled, AutoSaveTimeIntervall,
598*cdf0e10cSrcweir                     TimerType etcpp.)
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir             @throw  [com.sun.star.uno.RuntimeException]
601*cdf0e10cSrcweir                     if timer could not be stopped or started!
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir             @threadsafe
604*cdf0e10cSrcweir          */
605*cdf0e10cSrcweir         void implts_updateTimer();
606*cdf0e10cSrcweir 
607*cdf0e10cSrcweir         //---------------------------------------
608*cdf0e10cSrcweir         /** @short  stop the timer.
609*cdf0e10cSrcweir 
610*cdf0e10cSrcweir             @descr  Double calls will be ignored - means we do
611*cdf0e10cSrcweir                     nothing here, if the timer is already disabled.
612*cdf0e10cSrcweir 
613*cdf0e10cSrcweir             @throw  [com.sun.star.uno.RuntimeException]
614*cdf0e10cSrcweir                     if timer could not be stopped!
615*cdf0e10cSrcweir 
616*cdf0e10cSrcweir             @threadsafe
617*cdf0e10cSrcweir          */
618*cdf0e10cSrcweir         void implts_stopTimer();
619*cdf0e10cSrcweir 
620*cdf0e10cSrcweir         //---------------------------------------
621*cdf0e10cSrcweir         /** @short  callback of our internal timer.
622*cdf0e10cSrcweir          */
623*cdf0e10cSrcweir         DECL_LINK(implts_timerExpired, void*);
624*cdf0e10cSrcweir 
625*cdf0e10cSrcweir         //---------------------------------------
626*cdf0e10cSrcweir         /** @short  makes our dispatch() method asynchronous!
627*cdf0e10cSrcweir          */
628*cdf0e10cSrcweir         DECL_LINK(implts_asyncDispatch, void*);
629*cdf0e10cSrcweir 
630*cdf0e10cSrcweir         //---------------------------------------
631*cdf0e10cSrcweir         /** @short  implements the dispatch real. */
632*cdf0e10cSrcweir         void implts_dispatch(const DispatchParams& aParams);
633*cdf0e10cSrcweir 
634*cdf0e10cSrcweir         //---------------------------------------
635*cdf0e10cSrcweir         /** @short  validate new detected document and add it into the internal
636*cdf0e10cSrcweir                     document list.
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir             @descr  This method should be called only, if its clear that a new
639*cdf0e10cSrcweir                     document was opened/created during office runtime.
640*cdf0e10cSrcweir                     This method checks, if its a top level document (means not an embedded one).
641*cdf0e10cSrcweir                     Only such top level documents can be recognized by this auto save mechanism.
642*cdf0e10cSrcweir 
643*cdf0e10cSrcweir             @param  xDocument
644*cdf0e10cSrcweir                     the new document, which should be checked and registered.
645*cdf0e10cSrcweir 
646*cdf0e10cSrcweir             @threadsafe
647*cdf0e10cSrcweir          */
648*cdf0e10cSrcweir         void implts_registerDocument(const css::uno::Reference< css::frame::XModel >& xDocument);
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir         //---------------------------------------
651*cdf0e10cSrcweir         /** @short  remove the specified document from our internal document list.
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir             @param  xDocument
654*cdf0e10cSrcweir                     the new document, which should be deregistered.
655*cdf0e10cSrcweir 
656*cdf0e10cSrcweir             @param  bStopListening
657*cdf0e10cSrcweir                     sal_False: must be used in case this method is called withion disposing() of the document,
658*cdf0e10cSrcweir                            where it make no sense to deregister our listener. The container dies ...
659*cdf0e10cSrcweir                     sal_True : must be used in case this method is used on "dergistration" of this document, where
660*cdf0e10cSrcweir                            we must deregister our listener .-)
661*cdf0e10cSrcweir 
662*cdf0e10cSrcweir             @threadsafe
663*cdf0e10cSrcweir          */
664*cdf0e10cSrcweir         void implts_deregisterDocument(const css::uno::Reference< css::frame::XModel >& xDocument                ,
665*cdf0e10cSrcweir                                              sal_Bool                                   bStopListening = sal_True);
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir         //---------------------------------------
668*cdf0e10cSrcweir         // TODO document me
669*cdf0e10cSrcweir         void implts_markDocumentModifiedAgainstLastBackup(const css::uno::Reference< css::frame::XModel >& xDocument);
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir         //---------------------------------------
672*cdf0e10cSrcweir         // TODO document me
673*cdf0e10cSrcweir         void implts_updateModifiedState(const css::uno::Reference< css::frame::XModel >& xDocument);
674*cdf0e10cSrcweir 
675*cdf0e10cSrcweir         //---------------------------------------
676*cdf0e10cSrcweir         // TODO document me
677*cdf0e10cSrcweir         void implts_updateDocumentUsedForSavingState(const css::uno::Reference< css::frame::XModel >& xDocument      ,
678*cdf0e10cSrcweir                                                            sal_Bool                                   bSaveInProgress);
679*cdf0e10cSrcweir 
680*cdf0e10cSrcweir         //---------------------------------------
681*cdf0e10cSrcweir         // TODO document me
682*cdf0e10cSrcweir         void implts_markDocumentAsSaved(const css::uno::Reference< css::frame::XModel >& xDocument);
683*cdf0e10cSrcweir 
684*cdf0e10cSrcweir         //---------------------------------------
685*cdf0e10cSrcweir         /** @short  search a document inside given list.
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir             @param  rList
688*cdf0e10cSrcweir                     reference to a vector, which can contain such
689*cdf0e10cSrcweir                     document.
690*cdf0e10cSrcweir 
691*cdf0e10cSrcweir             @param  xDocument
692*cdf0e10cSrcweir                     the document, which should be located inside the
693*cdf0e10cSrcweir                     given list.
694*cdf0e10cSrcweir 
695*cdf0e10cSrcweir             @return [TDocumentList::iterator]
696*cdf0e10cSrcweir                     which points to the located document.
697*cdf0e10cSrcweir                     If document does not exists - its set to
698*cdf0e10cSrcweir                     rList.end()!
699*cdf0e10cSrcweir          */
700*cdf0e10cSrcweir         static TDocumentList::iterator impl_searchDocument(      AutoRecovery::TDocumentList&               rList    ,
701*cdf0e10cSrcweir                                                            const css::uno::Reference< css::frame::XModel >& xDocument);
702*cdf0e10cSrcweir 
703*cdf0e10cSrcweir         //---------------------------------------
704*cdf0e10cSrcweir         /** TODO document me */
705*cdf0e10cSrcweir         void implts_changeAllDocVisibility(sal_Bool bVisible);
706*cdf0e10cSrcweir         void implts_prepareSessionShutdown();
707*cdf0e10cSrcweir 
708*cdf0e10cSrcweir         //---------------------------------------
709*cdf0e10cSrcweir         /** @short  save all current opened documents to a specific
710*cdf0e10cSrcweir                     backup directory.
711*cdf0e10cSrcweir 
712*cdf0e10cSrcweir             @descr  Only realy changed documents will be saved here.
713*cdf0e10cSrcweir 
714*cdf0e10cSrcweir                     Further this method returns a suggestion, if and how it should
715*cdf0e10cSrcweir                     be called again. May be some documents was not saved yet
716*cdf0e10cSrcweir                     and must wait for an user idle period ...
717*cdf0e10cSrcweir 
718*cdf0e10cSrcweir             @param  bAllowUserIdleLoop
719*cdf0e10cSrcweir                     Because this method is used for different uses cases, it must
720*cdf0e10cSrcweir                     know, which actions are allowed or not.
721*cdf0e10cSrcweir                     AUTO_SAVE =>
722*cdf0e10cSrcweir                                  If a document is the most active one, saving it
723*cdf0e10cSrcweir                                  will be postponed if there exists other unsaved
724*cdf0e10cSrcweir                                  documents. This feature was implemented, because
725*cdf0e10cSrcweir                                  we dont wish to disturb the user on it's work.
726*cdf0e10cSrcweir                                  ... bAllowUserIdleLoop should be set to sal_True
727*cdf0e10cSrcweir                     EMERGENCY_SAVE / SESSION_SAVE =>
728*cdf0e10cSrcweir                                  Here we must finish our work ASAP! It's not allowed
729*cdf0e10cSrcweir                                  to postpone any document.
730*cdf0e10cSrcweir                                  ... bAllowUserIdleLoop must(!) be set to sal_False
731*cdf0e10cSrcweir 
732*cdf0e10cSrcweir             @param  pParams
733*cdf0e10cSrcweir                     sometimes this method is required inside an external dispatch request.
734*cdf0e10cSrcweir                     The it contains some special environment variables, which overwrites
735*cdf0e10cSrcweir                     our normal environment.
736*cdf0e10cSrcweir                     AutoSave              => pParams == 0
737*cdf0e10cSrcweir                     SessionSave/CrashSave => pParams != 0
738*cdf0e10cSrcweir 
739*cdf0e10cSrcweir             @return A suggestion, how the timer (if its not already disabled!)
740*cdf0e10cSrcweir                     should be restarted to full fill the requirements.
741*cdf0e10cSrcweir 
742*cdf0e10cSrcweir             @threadsafe
743*cdf0e10cSrcweir          */
744*cdf0e10cSrcweir         AutoRecovery::ETimerType implts_saveDocs(      sal_Bool        bAllowUserIdleLoop,
745*cdf0e10cSrcweir                                                        sal_Bool        bRemoveLockFiles,
746*cdf0e10cSrcweir                                                  const DispatchParams* pParams        = 0);
747*cdf0e10cSrcweir 
748*cdf0e10cSrcweir         //---------------------------------------
749*cdf0e10cSrcweir         /** @short  save one of the current documents to a specific
750*cdf0e10cSrcweir                     backup directory.
751*cdf0e10cSrcweir 
752*cdf0e10cSrcweir             @descr  It:
753*cdf0e10cSrcweir                     - defines a new(!) unique temp file name
754*cdf0e10cSrcweir                     - save the new temp file
755*cdf0e10cSrcweir                     - remove the old temp file
756*cdf0e10cSrcweir                     - patch the given info struct
757*cdf0e10cSrcweir                     - and return errors.
758*cdf0e10cSrcweir 
759*cdf0e10cSrcweir                     It does not:
760*cdf0e10cSrcweir                     - patch the configuration.
761*cdf0e10cSrcweir 
762*cdf0e10cSrcweir                     Note further: It paches the info struct
763*cdf0e10cSrcweir                     more then ones. E.g. the new temp URL is set
764*cdf0e10cSrcweir                     before the file is saved. And the old URL is removed
765*cdf0e10cSrcweir                     only if removing oft he old file was successfully.
766*cdf0e10cSrcweir                     If this method returns without an exception - everything
767*cdf0e10cSrcweir                     was OK. Otherwhise the info struct can be analyzed to
768*cdf0e10cSrcweir                     get more information, e.g. when the problem occures.
769*cdf0e10cSrcweir 
770*cdf0e10cSrcweir             @param  sBackupPath
771*cdf0e10cSrcweir                     the base path for saving such temp files.
772*cdf0e10cSrcweir 
773*cdf0e10cSrcweir             @param  rInfo
774*cdf0e10cSrcweir                     points to an informations structure, where
775*cdf0e10cSrcweir                     e.g. the document, its modified state, the count
776*cdf0e10cSrcweir                     of autosave-retries etcpp. exists.
777*cdf0e10cSrcweir                     Its used also to return the new temp file name
778*cdf0e10cSrcweir                     and some other state values!
779*cdf0e10cSrcweir 
780*cdf0e10cSrcweir             @threadsafe
781*cdf0e10cSrcweir           */
782*cdf0e10cSrcweir         void implts_saveOneDoc(const ::rtl::OUString&                                    sBackupPath      ,
783*cdf0e10cSrcweir                                      AutoRecovery::TDocumentInfo&                        rInfo            ,
784*cdf0e10cSrcweir                                const css::uno::Reference< css::task::XStatusIndicator >& xExternalProgress);
785*cdf0e10cSrcweir 
786*cdf0e10cSrcweir         //---------------------------------------
787*cdf0e10cSrcweir         /** @short  recovery all documents, which was saved during
788*cdf0e10cSrcweir                     a crash before.
789*cdf0e10cSrcweir 
790*cdf0e10cSrcweir             @return A suggestion, how this method must be called back!
791*cdf0e10cSrcweir 
792*cdf0e10cSrcweir             @threadsafe
793*cdf0e10cSrcweir          */
794*cdf0e10cSrcweir         AutoRecovery::ETimerType implts_openDocs(const DispatchParams& aParams);
795*cdf0e10cSrcweir 
796*cdf0e10cSrcweir         //---------------------------------------
797*cdf0e10cSrcweir         // TODO document me
798*cdf0e10cSrcweir         void implts_openOneDoc(const ::rtl::OUString&               sURL       ,
799*cdf0e10cSrcweir                                      ::comphelper::MediaDescriptor& lDescriptor,
800*cdf0e10cSrcweir                                      AutoRecovery::TDocumentInfo&   rInfo      );
801*cdf0e10cSrcweir 
802*cdf0e10cSrcweir         //---------------------------------------
803*cdf0e10cSrcweir         // TODO document me
804*cdf0e10cSrcweir         void implts_generateNewTempURL(const ::rtl::OUString&               sBackupPath     ,
805*cdf0e10cSrcweir                                              ::comphelper::MediaDescriptor& rMediaDescriptor,
806*cdf0e10cSrcweir                                              AutoRecovery::TDocumentInfo&   rInfo           );
807*cdf0e10cSrcweir 
808*cdf0e10cSrcweir         //---------------------------------------
809*cdf0e10cSrcweir         /** @short  notifies all interested listener about the current state
810*cdf0e10cSrcweir                     of the currently running operation.
811*cdf0e10cSrcweir 
812*cdf0e10cSrcweir             @descr  We support different set's of functions. AUTO_SAVE, EMERGENCY_SAVE,
813*cdf0e10cSrcweir                     AUTO_RECOVERY, FAILURE_SAVE ... etcpp.
814*cdf0e10cSrcweir                     Listener can register itself for any type of supported
815*cdf0e10cSrcweir                     functionality ... but not for document URL's in special.
816*cdf0e10cSrcweir 
817*cdf0e10cSrcweir             @param  eJob
818*cdf0e10cSrcweir                     is used to know, which set of listener we must notify.
819*cdf0e10cSrcweir 
820*cdf0e10cSrcweir             @param  aEvent
821*cdf0e10cSrcweir                     describe the event more in detail.
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir             @threadsafe
824*cdf0e10cSrcweir           */
825*cdf0e10cSrcweir         void implts_informListener(      sal_Int32                      eJob  ,
826*cdf0e10cSrcweir                                    const css::frame::FeatureStateEvent& aEvent);
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir         //---------------------------------------
829*cdf0e10cSrcweir         /** short   create a feature event struct, which can be send
830*cdf0e10cSrcweir                     to any interested listener.
831*cdf0e10cSrcweir 
832*cdf0e10cSrcweir             @param  eJob
833*cdf0e10cSrcweir                     describe the current running operation
834*cdf0e10cSrcweir                     AUTOSAVE, EMERGENCYSAVE, RECOVERY
835*cdf0e10cSrcweir 
836*cdf0e10cSrcweir             @param  sEventType
837*cdf0e10cSrcweir                     describe the type of this event
838*cdf0e10cSrcweir                     START, STOP, UPDATE
839*cdf0e10cSrcweir 
840*cdf0e10cSrcweir             @param  pInfo
841*cdf0e10cSrcweir                     if sOperation is an update, this parameter must be different from NULL
842*cdf0e10cSrcweir                     and is used to send informations regarding the current handled document.
843*cdf0e10cSrcweir 
844*cdf0e10cSrcweir             @return [css::frame::FeatureStateEvent]
845*cdf0e10cSrcweir                     the event structure for sending.
846*cdf0e10cSrcweir          */
847*cdf0e10cSrcweir         static css::frame::FeatureStateEvent implst_createFeatureStateEvent(      sal_Int32                    eJob      ,
848*cdf0e10cSrcweir                                                                             const ::rtl::OUString&             sEventType,
849*cdf0e10cSrcweir                                                                                   AutoRecovery::TDocumentInfo* pInfo     );
850*cdf0e10cSrcweir 
851*cdf0e10cSrcweir         //---------------------------------------
852*cdf0e10cSrcweir 
853*cdf0e10cSrcweir         // TODO document me
854*cdf0e10cSrcweir         void implts_resetHandleStates(sal_Bool bLoadCache);
855*cdf0e10cSrcweir 
856*cdf0e10cSrcweir         //---------------------------------------
857*cdf0e10cSrcweir         // TODO document me
858*cdf0e10cSrcweir         void implts_specifyDefaultFilterAndExtension(AutoRecovery::TDocumentInfo& rInfo);
859*cdf0e10cSrcweir 
860*cdf0e10cSrcweir         //---------------------------------------
861*cdf0e10cSrcweir         // TODO document me
862*cdf0e10cSrcweir         void implts_specifyAppModuleAndFactory(AutoRecovery::TDocumentInfo& rInfo);
863*cdf0e10cSrcweir 
864*cdf0e10cSrcweir         /** retrieves the names of all active views of the given document
865*cdf0e10cSrcweir             @param rInfo
866*cdf0e10cSrcweir                 the document info, whose <code>Document</code> member must not be <NULL/>.
867*cdf0e10cSrcweir         */
868*cdf0e10cSrcweir         void implts_collectActiveViewNames( AutoRecovery::TDocumentInfo& rInfo );
869*cdf0e10cSrcweir 
870*cdf0e10cSrcweir         /** updates the configuration so that for all documents, their current view/names are stored
871*cdf0e10cSrcweir         */
872*cdf0e10cSrcweir         void implts_persistAllActiveViewNames();
873*cdf0e10cSrcweir 
874*cdf0e10cSrcweir         //---------------------------------------
875*cdf0e10cSrcweir         // TODO document me
876*cdf0e10cSrcweir         void implts_prepareEmergencySave();
877*cdf0e10cSrcweir 
878*cdf0e10cSrcweir         //---------------------------------------
879*cdf0e10cSrcweir         // TODO document me
880*cdf0e10cSrcweir         void implts_doEmergencySave(const DispatchParams& aParams);
881*cdf0e10cSrcweir 
882*cdf0e10cSrcweir         //---------------------------------------
883*cdf0e10cSrcweir         // TODO document me
884*cdf0e10cSrcweir         void implts_doRecovery(const DispatchParams& aParams);
885*cdf0e10cSrcweir 
886*cdf0e10cSrcweir         //---------------------------------------
887*cdf0e10cSrcweir         // TODO document me
888*cdf0e10cSrcweir         void implts_doSessionSave(const DispatchParams& aParams);
889*cdf0e10cSrcweir 
890*cdf0e10cSrcweir         //---------------------------------------
891*cdf0e10cSrcweir         // TODO document me
892*cdf0e10cSrcweir         void implts_doSessionQuietQuit(const DispatchParams& aParams);
893*cdf0e10cSrcweir 
894*cdf0e10cSrcweir         //---------------------------------------
895*cdf0e10cSrcweir         // TODO document me
896*cdf0e10cSrcweir         void implts_doSessionRestore(const DispatchParams& aParams);
897*cdf0e10cSrcweir 
898*cdf0e10cSrcweir         //---------------------------------------
899*cdf0e10cSrcweir         // TODO document me
900*cdf0e10cSrcweir         void implts_backupWorkingEntry(const DispatchParams& aParams);
901*cdf0e10cSrcweir 
902*cdf0e10cSrcweir         //---------------------------------------
903*cdf0e10cSrcweir         // TODO document me
904*cdf0e10cSrcweir         void implts_cleanUpWorkingEntry(const DispatchParams& aParams);
905*cdf0e10cSrcweir 
906*cdf0e10cSrcweir         //---------------------------------------
907*cdf0e10cSrcweir         /** try to make sure that all changed config items (not our used
908*cdf0e10cSrcweir             config access only) will be flushed back to disc.
909*cdf0e10cSrcweir 
910*cdf0e10cSrcweir             E.g. our svtools::ConfigItems() has to be flushed explicitly .-(
911*cdf0e10cSrcweir 
912*cdf0e10cSrcweir             Note: This method cant fail. Flushing of config entries is an
913*cdf0e10cSrcweir                   optional feature. Errors can be ignored.
914*cdf0e10cSrcweir          */
915*cdf0e10cSrcweir         void impl_flushALLConfigChanges();
916*cdf0e10cSrcweir 
917*cdf0e10cSrcweir         //---------------------------------------
918*cdf0e10cSrcweir         // TODO document me
919*cdf0e10cSrcweir         AutoRecovery::EFailureSafeResult implts_copyFile(const ::rtl::OUString& sSource    ,
920*cdf0e10cSrcweir                                                          const ::rtl::OUString& sTargetPath,
921*cdf0e10cSrcweir                                                          const ::rtl::OUString& sTargetName);
922*cdf0e10cSrcweir 
923*cdf0e10cSrcweir         //---------------------------------------
924*cdf0e10cSrcweir         /** @short  converts m_eJob into a job description, which
925*cdf0e10cSrcweir                     can be used to inform an outside listener
926*cdf0e10cSrcweir                     about the current running operation
927*cdf0e10cSrcweir 
928*cdf0e10cSrcweir             @param  eJob
929*cdf0e10cSrcweir                     describe the current running operation
930*cdf0e10cSrcweir                     AUTOSAVE, EMERGENCYSAVE, RECOVERY
931*cdf0e10cSrcweir 
932*cdf0e10cSrcweir             @return [string]
933*cdf0e10cSrcweir                     a suitable job description of form:
934*cdf0e10cSrcweir                         vnd.sun.star.autorecovery:/do...
935*cdf0e10cSrcweir          */
936*cdf0e10cSrcweir         static ::rtl::OUString implst_getJobDescription(sal_Int32 eJob);
937*cdf0e10cSrcweir 
938*cdf0e10cSrcweir         //---------------------------------------
939*cdf0e10cSrcweir         /** @short  mape the given URL to an internal int representation.
940*cdf0e10cSrcweir 
941*cdf0e10cSrcweir             @param  aURL
942*cdf0e10cSrcweir                     the url, which describe the next starting or may be already running
943*cdf0e10cSrcweir                     operation.
944*cdf0e10cSrcweir 
945*cdf0e10cSrcweir             @return [long]
946*cdf0e10cSrcweir                     the internal int representation
947*cdf0e10cSrcweir                     see enum EJob
948*cdf0e10cSrcweir          */
949*cdf0e10cSrcweir         static sal_Int32 implst_classifyJob(const css::util::URL& aURL);
950*cdf0e10cSrcweir 
951*cdf0e10cSrcweir         /// TODO
952*cdf0e10cSrcweir         void implts_verifyCacheAgainstDesktopDocumentList();
953*cdf0e10cSrcweir 
954*cdf0e10cSrcweir         /// TODO document me
955*cdf0e10cSrcweir         sal_Bool impl_enoughDiscSpace(sal_Int32 nRequiredSpace);
956*cdf0e10cSrcweir 
957*cdf0e10cSrcweir         /// TODO document me
958*cdf0e10cSrcweir         static void impl_showFullDiscError();
959*cdf0e10cSrcweir 
960*cdf0e10cSrcweir         //---------------------------------------
961*cdf0e10cSrcweir         /** @short  try to create/use a progress and set it inside the
962*cdf0e10cSrcweir                     environment.
963*cdf0e10cSrcweir 
964*cdf0e10cSrcweir             @descr  The problem behind: There exists different use case of this method.
965*cdf0e10cSrcweir                     a) An external progress is provided by our CrashSave or Recovery dialog.
966*cdf0e10cSrcweir                     b) We must create our own progress e.g. for an AutoSave
967*cdf0e10cSrcweir                     c) Sometimes our application filters dont use the progress
968*cdf0e10cSrcweir                        provided by the MediaDescriptor. They uses the Frame everytime to create
969*cdf0e10cSrcweir                        it's own progress. So we implemented a HACK for these and now we set
970*cdf0e10cSrcweir                        an InterceptedProgress there for the time WE use this frame for loading/storing documents .-)
971*cdf0e10cSrcweir 
972*cdf0e10cSrcweir             @param  xNewFrame
973*cdf0e10cSrcweir                     must be set only in case WE create a new frame (e.g. for loading documents
974*cdf0e10cSrcweir                     on session restore or recovery). Then search for a frame using rInfo.Document must
975*cdf0e10cSrcweir                     be supressed and xFrame must be preferred instead .-)
976*cdf0e10cSrcweir 
977*cdf0e10cSrcweir             @param  rInfo
978*cdf0e10cSrcweir                     used e.g. to find the frame corresponding to a document.
979*cdf0e10cSrcweir                     This frame must be used to create a new progress e.g. for an AutoSave.
980*cdf0e10cSrcweir 
981*cdf0e10cSrcweir             @param  rArgs
982*cdf0e10cSrcweir                     is used to set the new created progress as parameter on these set.
983*cdf0e10cSrcweir          */
984*cdf0e10cSrcweir         void impl_establishProgress(const AutoRecovery::TDocumentInfo&               rInfo    ,
985*cdf0e10cSrcweir                                           ::comphelper::MediaDescriptor&             rArgs    ,
986*cdf0e10cSrcweir                                     const css::uno::Reference< css::frame::XFrame >& xNewFrame);
987*cdf0e10cSrcweir 
988*cdf0e10cSrcweir         void impl_forgetProgress(const AutoRecovery::TDocumentInfo&               rInfo    ,
989*cdf0e10cSrcweir                                        ::comphelper::MediaDescriptor&             rArgs    ,
990*cdf0e10cSrcweir                                  const css::uno::Reference< css::frame::XFrame >& xNewFrame);
991*cdf0e10cSrcweir 
992*cdf0e10cSrcweir         //---------------------------------------
993*cdf0e10cSrcweir         /** try to remove the specified file from disc.
994*cdf0e10cSrcweir 
995*cdf0e10cSrcweir             Every URL supported by our UCB component can be used here.
996*cdf0e10cSrcweir             Further it doesnt matter if the file realy exists or not.
997*cdf0e10cSrcweir             Because removing a non exsistent file will have the same
998*cdf0e10cSrcweir             result at the end ... a non existing file .-)
999*cdf0e10cSrcweir 
1000*cdf0e10cSrcweir             On the other side removing of files from disc is an optional
1001*cdf0e10cSrcweir             feature. If we are not able doing so ... its not a real problem.
1002*cdf0e10cSrcweir             Ok - users disc place will be samller then ... but we should produce
1003*cdf0e10cSrcweir             a crash during crash save because we cant delete a temporary file only !
1004*cdf0e10cSrcweir 
1005*cdf0e10cSrcweir             @param  sURL
1006*cdf0e10cSrcweir                     the url of the file, which should be removed.
1007*cdf0e10cSrcweir          */
1008*cdf0e10cSrcweir         static void st_impl_removeFile(const ::rtl::OUString& sURL);
1009*cdf0e10cSrcweir 
1010*cdf0e10cSrcweir         //---------------------------------------
1011*cdf0e10cSrcweir         /** try to remove ".lock" file from disc if office will be terminated
1012*cdf0e10cSrcweir             not using the offical way .-)
1013*cdf0e10cSrcweir 
1014*cdf0e10cSrcweir             This method has to be handled "optional". So every error inside
1015*cdf0e10cSrcweir             has to be ignored ! This method CANT FAIL ... it can forget something only .-)
1016*cdf0e10cSrcweir          */
1017*cdf0e10cSrcweir         static void st_impl_removeLockFile();
1018*cdf0e10cSrcweir };
1019*cdf0e10cSrcweir 
1020*cdf0e10cSrcweir } // namespace framework
1021*cdf0e10cSrcweir 
1022*cdf0e10cSrcweir #endif // __FRAMEWORK_SERVICES_AUTORECOVERY_HXX_
1023