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