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 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_desktop.hxx" 30 31 #include "oemjob.hxx" 32 #include <rtl/bootstrap.hxx> 33 #include <rtl/ustrbuf.hxx> 34 #include <osl/file.hxx> 35 #include <unotools/bootstrap.hxx> 36 #include <tools/config.hxx> 37 #include <com/sun/star/frame/XDesktop.hpp> 38 #include <com/sun/star/frame/XFrame.hpp> 39 #include <com/sun/star/frame/XModel.hpp> 40 #include <com/sun/star/util/XCloseable.hpp> 41 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 42 #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> 43 #include <com/sun/star/beans/NamedValue.hpp> 44 45 using namespace rtl; 46 using namespace ::com::sun::star::uno; 47 using namespace ::com::sun::star::lang; 48 using namespace ::com::sun::star::beans; 49 using namespace ::com::sun::star::ui::dialogs; 50 using namespace ::com::sun::star::frame; 51 using namespace ::com::sun::star::util; 52 53 namespace desktop{ 54 55 char const OEM_PRELOAD_SECTION[] = "Bootstrap"; 56 char const OEM_PRELOAD[] = "Preload"; 57 char const STR_TRUE[] = "1"; 58 char const STR_FALSE[] = "0"; 59 60 const char* OEMPreloadJob::interfaces[] = 61 { 62 "com.sun.star.task.XJob", 63 NULL, 64 }; 65 const char* OEMPreloadJob::implementationName = "com.sun.star.comp.desktop.OEMPreloadJob"; 66 const char* OEMPreloadJob::serviceName = "com.sun.star.office.OEMPreloadJob"; 67 68 OUString OEMPreloadJob::GetImplementationName() 69 { 70 return OUString( RTL_CONSTASCII_USTRINGPARAM( implementationName)); 71 } 72 73 Sequence< OUString > OEMPreloadJob::GetSupportedServiceNames() 74 { 75 sal_Int32 nSize = (sizeof( interfaces ) / sizeof( const char *)) - 1; 76 Sequence< OUString > aResult( nSize ); 77 78 for( sal_Int32 i = 0; i < nSize; i++ ) 79 aResult[i] = OUString::createFromAscii( interfaces[i] ); 80 return aResult; 81 } 82 83 Reference< XInterface > SAL_CALL OEMPreloadJob::CreateInstance( 84 const Reference< XMultiServiceFactory >& rSMgr ) 85 { 86 static osl::Mutex aMutex; 87 osl::MutexGuard guard( aMutex ); 88 return (XComponent*) ( new OEMPreloadJob( rSMgr ) ); 89 } 90 91 OEMPreloadJob::OEMPreloadJob( const Reference< XMultiServiceFactory >& xFactory ) : 92 m_aListeners( m_aMutex ), 93 m_xServiceManager( xFactory ) 94 { 95 } 96 97 OEMPreloadJob::~OEMPreloadJob() 98 { 99 } 100 101 // XComponent 102 void SAL_CALL OEMPreloadJob::dispose() throw ( RuntimeException ) 103 { 104 EventObject aObject; 105 aObject.Source = (XComponent*)this; 106 m_aListeners.disposeAndClear( aObject ); 107 } 108 109 void SAL_CALL OEMPreloadJob::addEventListener( const Reference< XEventListener > & aListener) throw ( RuntimeException ) 110 { 111 m_aListeners.addInterface( aListener ); 112 } 113 114 void SAL_CALL OEMPreloadJob::removeEventListener( const Reference< XEventListener > & aListener ) throw ( RuntimeException ) 115 { 116 m_aListeners.removeInterface( aListener ); 117 } 118 119 // XServiceInfo 120 ::rtl::OUString SAL_CALL OEMPreloadJob::getImplementationName() 121 throw ( RuntimeException ) 122 { 123 return OEMPreloadJob::GetImplementationName(); 124 } 125 126 sal_Bool SAL_CALL OEMPreloadJob::supportsService( const ::rtl::OUString& rServiceName ) 127 throw ( RuntimeException ) 128 { 129 sal_Int32 nSize = sizeof( interfaces ) / sizeof( const char *); 130 131 for( sal_Int32 i = 0; i < nSize; i++ ) 132 if ( rServiceName.equalsAscii( interfaces[i] )) 133 return sal_True; 134 return sal_False; 135 } 136 137 Sequence< ::rtl::OUString > SAL_CALL OEMPreloadJob::getSupportedServiceNames() 138 throw ( RuntimeException ) 139 { 140 return OEMPreloadJob::GetSupportedServiceNames(); 141 } 142 143 // XJob 144 Any SAL_CALL OEMPreloadJob::execute(const Sequence<NamedValue>&) 145 throw ( RuntimeException ) 146 { 147 sal_Bool bCont = sal_False; 148 // are we an OEM version at all? 149 if (checkOEMPreloadFlag()) 150 { 151 // create OEM preload service dialog 152 Reference <XExecutableDialog> xDialog( m_xServiceManager->createInstance( 153 OUString::createFromAscii("org.openoffice.comp.preload.OEMPreloadWizard")), 154 UNO_QUERY ); 155 if ( xDialog.is() ){ 156 // execute OEM preload dialog and check return value 157 if ( xDialog->execute() == ExecutableDialogResults::OK ) { 158 // user accepted. 159 // make sure the job does not get called again. 160 bCont = sal_True; 161 disableOEMPreloadFlag(); 162 } else { 163 // user declined... 164 // terminate. 165 /* 166 Reference< XDesktop > xDesktop( m_xServiceManager->createInstance( 167 OUString::createFromAscii("com.sun.star.frame.Desktop")), 168 UNO_QUERY ); 169 xDesktop->terminate(); 170 */ 171 /* 172 OUString aName; 173 OUString aEnvType; 174 Reference<XFrame> rFrame; 175 Reference<XModel> rModel; 176 Reference<XCloseable> rClose; 177 for (int i=0; i<args.getLength(); i++) 178 { 179 if (args[i].Name.equalsAscii("EnvType")) 180 args[i].Value >>= aEnvType; 181 else if (args[i].Name.equalsAscii("Frame")) { 182 args[i].Value >>= rFrame; 183 rClose = Reference<XCloseable>(rFrame, UNO_QUERY); 184 } 185 else if (args[i].Name.equalsAscii("Model")) { 186 args[i].Value >>= rModel; 187 rClose = Reference<XCloseable>(rModel, UNO_QUERY); 188 } 189 } 190 if (rClose.is()) rClose->close(sal_True); 191 */ 192 bCont = sal_False; 193 } 194 } 195 } else { 196 // don't try again 197 bCont = sal_True; 198 } 199 /* 200 NamedValue nv; 201 nv.Name = OUString::createFromAscii("Deactivate"); 202 nv.Value <<= bDeactivate; 203 Sequence<NamedValue> s(1); 204 s[0] = nv; 205 */ 206 Any r; 207 r <<= bCont; 208 return r; 209 } 210 211 212 static sal_Bool existsURL( OUString const& _sURL ) 213 { 214 using namespace osl; 215 DirectoryItem aDirItem; 216 217 if (_sURL.getLength() != 0) 218 return ( DirectoryItem::get( _sURL, aDirItem ) == DirectoryItem::E_None ); 219 220 return sal_False; 221 } 222 223 224 // locate soffice.ini/.rc file 225 static OUString locateIniFile() 226 { 227 OUString aUserDataPath; 228 OUString aSofficeIniFileURL; 229 230 // Retrieve the default file URL for the soffice.ini/rc 231 Bootstrap().getIniName( aSofficeIniFileURL ); 232 233 if ( utl::Bootstrap::locateUserData( aUserDataPath ) == utl::Bootstrap::PATH_EXISTS ) 234 { 235 const char CONFIG_DIR[] = "/config"; 236 237 sal_Int32 nIndex = aSofficeIniFileURL.lastIndexOf( '/'); 238 if ( nIndex > 0 ) 239 { 240 OUString aUserSofficeIniFileURL; 241 OUStringBuffer aBuffer( aUserDataPath ); 242 aBuffer.appendAscii( CONFIG_DIR ); 243 aBuffer.append( aSofficeIniFileURL.copy( nIndex )); 244 aUserSofficeIniFileURL = aBuffer.makeStringAndClear(); 245 246 if ( existsURL( aUserSofficeIniFileURL )) 247 return aUserSofficeIniFileURL; 248 } 249 } 250 // Fallback try to use the soffice.ini/rc from program folder 251 return aSofficeIniFileURL; 252 } 253 254 // check whether the OEMPreload flag was set in soffice.ini/.rc 255 sal_Bool OEMPreloadJob::checkOEMPreloadFlag() 256 { 257 OUString aSofficeIniFileURL; 258 aSofficeIniFileURL = locateIniFile(); 259 Config aConfig(aSofficeIniFileURL); 260 aConfig.SetGroup( OEM_PRELOAD_SECTION ); 261 ByteString sResult = aConfig.ReadKey( OEM_PRELOAD ); 262 if ( sResult == STR_TRUE ) 263 return sal_True; 264 else 265 return sal_False; 266 } 267 268 void OEMPreloadJob::disableOEMPreloadFlag() 269 { 270 OUString aSofficeIniFileURL = locateIniFile(); 271 if ( aSofficeIniFileURL.getLength() > 0 ) 272 { 273 Config aConfig(aSofficeIniFileURL); 274 aConfig.SetGroup( OEM_PRELOAD_SECTION ); 275 aConfig.WriteKey( OEM_PRELOAD, STR_FALSE ); 276 aConfig.Flush(); 277 } 278 } 279 280 } // namespace desktop 281