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