xref: /AOO41X/main/desktop/inc/app.hxx (revision 8809db7a87f97847b57a57f4cd2b0104b2b83182)
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_OFFICECONFIG_BROKEN
78         };
79         enum BootstrapStatus
80         {
81             BS_OK,
82             BS_TERMINATE
83         };
84 
85                                 Desktop();
86                                 ~Desktop();
87         virtual void            Main( );
88         virtual void            Init();
89         virtual void            DeInit();
90         virtual sal_Bool            QueryExit();
91         virtual sal_uInt16          Exception(sal_uInt16 nError);
92         virtual void            SystemSettingsChanging( AllSettings& rSettings, Window* pFrame );
93         virtual void            AppEvent( const ApplicationEvent& rAppEvent );
94 
95         DECL_LINK(          OpenClients_Impl, void* );
96 
97         static void             OpenClients();
98         static void             OpenDefault();
99 
100         DECL_LINK( EnableAcceptors_Impl, void*);
101 
102         static void             HandleAppEvent( const ApplicationEvent& rAppEvent );
103         static ResMgr*          GetDesktopResManager();
104         static CommandLineArgs* GetCommandLineArgs();
105 
106         void                    HandleBootstrapErrors( BootstrapError );
107         void                    SetBootstrapError( BootstrapError nError )
108         {
109             if ( m_aBootstrapError == BE_OK )
110                 m_aBootstrapError = nError;
111         }
112         BootstrapError          GetBootstrapError() const
113         {
114             return m_aBootstrapError;
115         }
116 
117         void                    SetBootstrapStatus( BootstrapStatus nStatus )
118         {
119             m_aBootstrapStatus = nStatus;
120         }
121         BootstrapStatus          GetBootstrapStatus() const
122         {
123             return m_aBootstrapStatus;
124         }
125 
126         static sal_Bool         CheckOEM();
127         static sal_Bool         isCrashReporterEnabled();
128 
129         // first-start (ever) & license relate methods
130         static rtl::OUString    GetLicensePath();
131         static sal_Bool         LicenseNeedsAcceptance();
132         static sal_Bool         IsFirstStartWizardNeeded();
133         static sal_Bool         CheckExtensionDependencies();
134 
135         static void             DoRestartActionsIfNecessary( sal_Bool bQuickStart );
136         static void             SetRestartState();
137 
138         void                    SynchronizeExtensionRepositories();
139         void                    SetSplashScreenText( const ::rtl::OUString& rText );
140         void                    SetSplashScreenProgress( sal_Int32 );
141 
142     private:
143         // Bootstrap methods
144         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > CreateApplicationServiceManager();
145 
146         void                    RegisterServices( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSMgr );
147         void                    DeregisterServices();
148 
149         void                    DestroyApplicationServiceManager( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xSMgr );
150 
151         void                    CreateTemporaryDirectory();
152         void                    RemoveTemporaryDirectory();
153 
154         sal_Bool                InitializeInstallation( const rtl::OUString& rAppFilename );
155         sal_Bool                InitializeConfiguration();
156         void                    FlushConfiguration();
157         sal_Bool                InitializeQuickstartMode( com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rSMgr );
158 
159         void                    HandleBootstrapPathErrors( ::utl::Bootstrap::Status, const ::rtl::OUString& aMsg );
160         void                    StartSetup( const ::rtl::OUString& aParameters );
161 
162         // Get a resource message string securely e.g. if resource cannot be retrieved return aFaultBackMsg
163         ::rtl::OUString         GetMsgString( sal_uInt16 nId, const ::rtl::OUString& aFaultBackMsg );
164 
165         // Create a error message depending on bootstrap failure code and an optional file url
166         ::rtl::OUString         CreateErrorMsgString( utl::Bootstrap::FailureCode nFailureCode,
167                                                       const ::rtl::OUString& aFileURL );
168 
169         static void             PreloadModuleData( CommandLineArgs* );
170         static void             PreloadConfigurationData();
171 
172         Reference<XStatusIndicator> m_rSplashScreen;
173         void                    OpenSplashScreen();
174         void                    CloseSplashScreen();
175 
176         void                    EnableOleAutomation();
177                                 DECL_LINK( ImplInitFilterHdl, ConvertData* );
178         DECL_LINK(          AsyncInitFirstRun, void* );
179         /** checks if the office is run the first time
180             <p>If so, <method>DoFirstRunInitializations</method> is called (asynchronously and delayed) and the
181             respective flag in the configuration is reset.</p>
182         */
183         void                    CheckFirstRun( );
184 
185         /// does initializations which are necessary for the first run of the office
186         void                    DoFirstRunInitializations();
187 
188         static sal_Bool         SaveTasks();
189         static sal_Bool         _bTasksSaved;
190 
191         static void             retrieveCrashReporterState();
192         static sal_Bool         isUIOnSessionShutdownAllowed();
193 
194         // on-demand acceptors
195         static void                         createAcceptor(const OUString& aDescription);
196         static void                         enableAcceptors();
197         static void                         destroyAcceptor(const OUString& aDescription);
198 
199         sal_Bool                        m_bMinimized;
200         sal_Bool                        m_bInvisible;
201         bool                            m_bServicesRegistered;
202         sal_uInt16                          m_nAppEvents;
203         BootstrapError                  m_aBootstrapError;
204         BootstrapStatus                 m_aBootstrapStatus;
205 
206         Lockfile *m_pLockfile;
207         Timer    m_firstRunTimer;
208 
209         static ResMgr*                  pResMgr;
210         static sal_Bool                 bSuppressOpenDefault;
211 };
212 
213 }
214 
215 #endif // _DESKTOP_APP_HXX_
216