xref: /aoo41x/main/desktop/inc/app.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _DESKTOP_APP_HXX_
29 #define _DESKTOP_APP_HXX_
30 
31 // stl includes first
32 #include <map>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #include <vcl/svapp.hxx>
35 #ifndef _VCL_TIMER_HXX_
36 #include <vcl/timer.hxx>
37 #endif
38 #include <tools/resmgr.hxx>
39 #include <unotools/bootstrap.hxx>
40 #include <com/sun/star/lang/XInitialization.hpp>
41 #include <com/sun/star/task/XStatusIndicator.hpp>
42 #include <com/sun/star/uno/Reference.h>
43 #include <osl/mutex.hxx>
44 
45 using namespace com::sun::star::task;
46 using namespace com::sun::star::uno;
47 using namespace com::sun::star::lang;
48 using namespace rtl;
49 
50 #define DESKTOP_SAVETASKS_MOD 0x1
51 #define DESKTOP_SAVETASKS_UNMOD 0x2
52 #define DESKTOP_SAVETASKS_ALL 0x3
53 
54 namespace desktop
55 {
56 
57 /*--------------------------------------------------------------------
58 	Description:	Application-class
59  --------------------------------------------------------------------*/
60 class CommandLineArgs;
61 class Lockfile;
62 class AcceptorMap : public std::map< OUString, Reference<XInitialization> > {};
63 struct ConvertData;
64 class Desktop : public Application
65 {
66     friend class UserInstall;
67 
68     void doShutdown();
69 
70 	public:
71 		enum BootstrapError
72 		{
73 			BE_OK,
74 			BE_UNO_SERVICEMANAGER,
75 			BE_UNO_SERVICE_CONFIG_MISSING,
76 			BE_PATHINFO_MISSING,
77             BE_USERINSTALL_FAILED,
78             BE_LANGUAGE_MISSING,
79             BE_USERINSTALL_NOTENOUGHDISKSPACE,
80             BE_USERINSTALL_NOWRITEACCESS,
81             BE_OFFICECONFIG_BROKEN
82 		};
83         enum BootstrapStatus
84         {
85             BS_OK,
86             BS_TERMINATE
87         };
88 
89 								Desktop();
90 								~Desktop();
91 		virtual void			Main( );
92 		virtual void			Init();
93 		virtual void			DeInit();
94 		virtual sal_Bool			QueryExit();
95 		virtual sal_uInt16			Exception(sal_uInt16 nError);
96 		virtual void			SystemSettingsChanging( AllSettings& rSettings, Window* pFrame );
97 		virtual void			AppEvent( const ApplicationEvent& rAppEvent );
98 
99 		DECL_LINK(          OpenClients_Impl, void* );
100 
101 		static void				OpenClients();
102 		static void				OpenDefault();
103 
104 		DECL_LINK( EnableAcceptors_Impl, void*);
105 
106 		static void				HandleAppEvent( const ApplicationEvent& rAppEvent );
107 		static ResMgr*			GetDesktopResManager();
108 		static CommandLineArgs* GetCommandLineArgs();
109 
110 		void					HandleBootstrapErrors( BootstrapError );
111 		void					SetBootstrapError( BootstrapError nError )
112 		{
113 			if ( m_aBootstrapError == BE_OK )
114 				m_aBootstrapError = nError;
115 		}
116         BootstrapError          GetBootstrapError() const
117         {
118             return m_aBootstrapError;
119         }
120 
121         void					SetBootstrapStatus( BootstrapStatus nStatus )
122 		{
123             m_aBootstrapStatus = nStatus;
124 		}
125         BootstrapStatus          GetBootstrapStatus() const
126         {
127             return m_aBootstrapStatus;
128         }
129 
130 		static sal_Bool         CheckOEM();
131         static sal_Bool         isCrashReporterEnabled();
132 
133         // first-start (ever) & license relate methods
134         static rtl::OUString    GetLicensePath();
135         static sal_Bool         LicenseNeedsAcceptance();
136         static sal_Bool         IsFirstStartWizardNeeded();
137         static sal_Bool         CheckExtensionDependencies();
138 
139         static void             DoRestartActionsIfNecessary( sal_Bool bQuickStart );
140         static void             SetRestartState();
141 
142         void                    SynchronizeExtensionRepositories();
143         void                    SetSplashScreenText( const ::rtl::OUString& rText );
144         void                    SetSplashScreenProgress( sal_Int32 );
145 
146 	private:
147 		// Bootstrap methods
148 		::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > CreateApplicationServiceManager();
149 
150 		void					RegisterServices( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSMgr );
151 		void					DeregisterServices();
152 
153 		void					DestroyApplicationServiceManager( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSMgr );
154 
155 		void					CreateTemporaryDirectory();
156 		void					RemoveTemporaryDirectory();
157 
158 		sal_Bool				InitializeInstallation( const rtl::OUString& rAppFilename );
159 		sal_Bool				InitializeConfiguration();
160         void                    FlushConfiguration();
161 		sal_Bool				InitializeQuickstartMode( com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rSMgr );
162 
163 		void					HandleBootstrapPathErrors( ::utl::Bootstrap::Status, const ::rtl::OUString& aMsg );
164 		void					StartSetup( const ::rtl::OUString& aParameters );
165 
166 		// Get a resource message string securely e.g. if resource cannot be retrieved return aFaultBackMsg
167 		::rtl::OUString			GetMsgString( sal_uInt16 nId, const ::rtl::OUString& aFaultBackMsg );
168 
169 		// Create a error message depending on bootstrap failure code and an optional file url
170 		::rtl::OUString			CreateErrorMsgString( utl::Bootstrap::FailureCode nFailureCode,
171 													  const ::rtl::OUString& aFileURL );
172 
173 		static void             PreloadModuleData( CommandLineArgs* );
174         static void             PreloadConfigurationData();
175 
176         Reference<XStatusIndicator> m_rSplashScreen;
177         void                    OpenSplashScreen();
178         void                    CloseSplashScreen();
179 
180     	void					EnableOleAutomation();
181 								DECL_LINK( ImplInitFilterHdl, ConvertData* );
182 		DECL_LINK(			AsyncInitFirstRun, void* );
183 		/** checks if the office is run the first time
184 			<p>If so, <method>DoFirstRunInitializations</method> is called (asynchronously and delayed) and the
185 			respective flag in the configuration is reset.</p>
186 		*/
187 		void					CheckFirstRun( );
188 
189 		/// does initializations which are necessary for the first run of the office
190 		void					DoFirstRunInitializations();
191 
192 		static sal_Bool			SaveTasks();
193         static sal_Bool         _bTasksSaved;
194 
195         static void             retrieveCrashReporterState();
196         static sal_Bool         isUIOnSessionShutdownAllowed();
197 
198         // on-demand acceptors
199 		static void							createAcceptor(const OUString& aDescription);
200 		static void							enableAcceptors();
201 		static void							destroyAcceptor(const OUString& aDescription);
202 
203 		sal_Bool						m_bMinimized;
204 		sal_Bool						m_bInvisible;
205 		bool                            m_bServicesRegistered;
206 		sal_uInt16							m_nAppEvents;
207 		BootstrapError					m_aBootstrapError;
208         BootstrapStatus                 m_aBootstrapStatus;
209 
210 		Lockfile *m_pLockfile;
211         Timer    m_firstRunTimer;
212 
213 		static ResMgr*					pResMgr;
214         static sal_Bool                 bSuppressOpenDefault;
215 };
216 
217 }
218 
219 #endif // _DESKTOP_APP_HXX_
220