1cdf0e10cSrcweir /************************************************************************* 2cdf0e10cSrcweir * 3cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4cdf0e10cSrcweir * 5cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6cdf0e10cSrcweir * 7cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8cdf0e10cSrcweir * 9cdf0e10cSrcweir * This file is part of OpenOffice.org. 10cdf0e10cSrcweir * 11cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14cdf0e10cSrcweir * 15cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20cdf0e10cSrcweir * 21cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25cdf0e10cSrcweir * 26cdf0e10cSrcweir ************************************************************************/ 27cdf0e10cSrcweir 28cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29cdf0e10cSrcweir #include "precompiled_sfx2.hxx" 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <shutdownicon.hxx> 32cdf0e10cSrcweir #include <app.hrc> 33cdf0e10cSrcweir #include <sfx2/app.hxx> 34cdf0e10cSrcweir #include <vos/mutex.hxx> 35cdf0e10cSrcweir #include <svtools/imagemgr.hxx> 36cdf0e10cSrcweir #include <svtools/miscopt.hxx> 37cdf0e10cSrcweir // #include <cmdlineargs.hxx> 38cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp> 39cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchResultListener.hpp> 40cdf0e10cSrcweir #include <com/sun/star/frame/XNotifyingDispatch.hpp> 41cdf0e10cSrcweir #include <com/sun/star/frame/XFramesSupplier.hpp> 42cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp> 43cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 44cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp> 45cdf0e10cSrcweir #include <com/sun/star/frame/XFramesSupplier.hpp> 46cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp> 47cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilterManager.hpp> 48cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> 49cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp> 50cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ControlActions.hpp> 51cdf0e10cSrcweir #include <com/sun/star/document/MacroExecMode.hpp> 52cdf0e10cSrcweir #include <com/sun/star/document/UpdateDocMode.hpp> 53cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx> 54cdf0e10cSrcweir #include <sfx2/fcontnr.hxx> 55cdf0e10cSrcweir #ifndef _UNOTOOLS_PROCESSFACTORY_HXX 56cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 57cdf0e10cSrcweir #endif 58cdf0e10cSrcweir #include <cppuhelper/compbase1.hxx> 59cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 60cdf0e10cSrcweir #include <comphelper/extract.hxx> 61cdf0e10cSrcweir #include <tools/urlobj.hxx> 62cdf0e10cSrcweir #include <osl/security.hxx> 63cdf0e10cSrcweir #include <osl/file.hxx> 64cdf0e10cSrcweir #include <rtl/bootstrap.hxx> 65cdf0e10cSrcweir #include <tools/link.hxx> 66cdf0e10cSrcweir #ifdef UNX // need symlink 67cdf0e10cSrcweir #include <unistd.h> 68cdf0e10cSrcweir #include <errno.h> 69cdf0e10cSrcweir #endif 70cdf0e10cSrcweir #include <vcl/timer.hxx> 71cdf0e10cSrcweir 72cdf0e10cSrcweir #include "sfx2/sfxresid.hxx" 73cdf0e10cSrcweir 74cdf0e10cSrcweir using namespace ::com::sun::star::uno; 75cdf0e10cSrcweir using namespace ::com::sun::star::frame; 76cdf0e10cSrcweir using namespace ::com::sun::star::container; 77cdf0e10cSrcweir using namespace ::com::sun::star::io; 78cdf0e10cSrcweir using namespace ::com::sun::star::lang; 79cdf0e10cSrcweir using namespace ::com::sun::star::beans; 80cdf0e10cSrcweir using namespace ::com::sun::star::util; 81cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs; 82cdf0e10cSrcweir using namespace ::vos; 83cdf0e10cSrcweir #ifdef WNT 84cdf0e10cSrcweir using ::rtl::OUString; 85cdf0e10cSrcweir #else 86cdf0e10cSrcweir using namespace ::rtl; 87cdf0e10cSrcweir #endif 88cdf0e10cSrcweir using namespace ::sfx2; 89cdf0e10cSrcweir 90cdf0e10cSrcweir #ifdef ENABLE_QUICKSTART_APPLET 91cdf0e10cSrcweir # if !defined(WIN32) && !defined(QUARTZ) 92cdf0e10cSrcweir extern "C" { static void SAL_CALL thisModule() {} } 93cdf0e10cSrcweir # endif 94cdf0e10cSrcweir #endif 95cdf0e10cSrcweir 96cdf0e10cSrcweir #if defined(UNX) && defined(ENABLE_SYSTRAY_GTK) 97*ac203367SPedro Giffuni #define PLUGIN_NAME libqstart_gtk.so 98cdf0e10cSrcweir #endif 99cdf0e10cSrcweir 100cdf0e10cSrcweir class SfxNotificationListener_Impl : public cppu::WeakImplHelper1< XDispatchResultListener > 101cdf0e10cSrcweir { 102cdf0e10cSrcweir public: 103cdf0e10cSrcweir virtual void SAL_CALL dispatchFinished( const DispatchResultEvent& aEvent ) throw( RuntimeException ); 104cdf0e10cSrcweir virtual void SAL_CALL disposing( const EventObject& aEvent ) throw( RuntimeException ); 105cdf0e10cSrcweir }; 106cdf0e10cSrcweir 107cdf0e10cSrcweir void SAL_CALL SfxNotificationListener_Impl::dispatchFinished( const DispatchResultEvent& ) throw( RuntimeException ) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir ShutdownIcon::LeaveModalMode(); 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir void SAL_CALL SfxNotificationListener_Impl::disposing( const EventObject& ) throw( RuntimeException ) 113cdf0e10cSrcweir { 114cdf0e10cSrcweir } 115cdf0e10cSrcweir 116cdf0e10cSrcweir SFX_IMPL_XSERVICEINFO( ShutdownIcon, "com.sun.star.office.Quickstart", "com.sun.star.comp.desktop.QuickstartWrapper" ) \ 117cdf0e10cSrcweir SFX_IMPL_ONEINSTANCEFACTORY( ShutdownIcon ); 118cdf0e10cSrcweir 119cdf0e10cSrcweir bool ShutdownIcon::bModalMode = false; 120cdf0e10cSrcweir ShutdownIcon* ShutdownIcon::pShutdownIcon = NULL; 121cdf0e10cSrcweir 122cdf0e10cSrcweir // To remove conditionals 123cdf0e10cSrcweir extern "C" { 124cdf0e10cSrcweir static void disabled_initSystray() { } 125cdf0e10cSrcweir static void disabled_deInitSystray() { } 126cdf0e10cSrcweir } 127cdf0e10cSrcweir #define DOSTRING( x ) #x 128cdf0e10cSrcweir #define STRING( x ) DOSTRING( x ) 129cdf0e10cSrcweir 130cdf0e10cSrcweir bool ShutdownIcon::LoadModule( osl::Module **pModule, 131cdf0e10cSrcweir oslGenericFunction *pInit, 132cdf0e10cSrcweir oslGenericFunction *pDeInit ) 133cdf0e10cSrcweir { 134cdf0e10cSrcweir if ( pModule ) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir OSL_ASSERT ( pInit && pDeInit ); 137cdf0e10cSrcweir *pInit = *pDeInit = NULL; 138cdf0e10cSrcweir *pModule = NULL; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir #ifdef ENABLE_QUICKSTART_APPLET 142cdf0e10cSrcweir # ifdef WIN32 143cdf0e10cSrcweir if ( pModule ) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir *pInit = win32_init_sys_tray; 146cdf0e10cSrcweir *pDeInit = win32_shutdown_sys_tray; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir return true; 149cdf0e10cSrcweir # elif defined QUARTZ 150cdf0e10cSrcweir *pInit = aqua_init_systray; 151cdf0e10cSrcweir *pDeInit = aqua_shutdown_systray; 152cdf0e10cSrcweir return true; 153cdf0e10cSrcweir # else // UNX 154cdf0e10cSrcweir osl::Module *pPlugin; 155cdf0e10cSrcweir pPlugin = new osl::Module(); 156cdf0e10cSrcweir 157cdf0e10cSrcweir oslGenericFunction pTmpInit = NULL; 158cdf0e10cSrcweir oslGenericFunction pTmpDeInit = NULL; 159*ac203367SPedro Giffuni if ( pPlugin->loadRelative( &thisModule, OUString( RTL_CONSTASCII_USTRINGPARAM( STRING( PLUGIN_NAME ) ) ) ) ) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir pTmpInit = pPlugin->getFunctionSymbol( 162cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( "plugin_init_sys_tray" ) ) ); 163cdf0e10cSrcweir pTmpDeInit = pPlugin->getFunctionSymbol( 164cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( "plugin_shutdown_sys_tray" ) ) ); 165cdf0e10cSrcweir } 166cdf0e10cSrcweir if ( !pTmpInit || !pTmpDeInit ) 167cdf0e10cSrcweir { 168cdf0e10cSrcweir delete pPlugin; 169cdf0e10cSrcweir pPlugin = NULL; 170cdf0e10cSrcweir } 171cdf0e10cSrcweir if ( pModule ) 172cdf0e10cSrcweir { 173cdf0e10cSrcweir *pModule = pPlugin; 174cdf0e10cSrcweir *pInit = pTmpInit; 175cdf0e10cSrcweir *pDeInit = pTmpDeInit; 176cdf0e10cSrcweir } 177cdf0e10cSrcweir else 178cdf0e10cSrcweir { 179cdf0e10cSrcweir bool bRet = pPlugin != NULL; 180cdf0e10cSrcweir delete pPlugin; 181cdf0e10cSrcweir return bRet; 182cdf0e10cSrcweir } 183cdf0e10cSrcweir # endif // UNX 184cdf0e10cSrcweir #endif // ENABLE_QUICKSTART_APPLET 185cdf0e10cSrcweir if ( pModule ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir if ( !*pInit ) 188cdf0e10cSrcweir *pInit = disabled_initSystray; 189cdf0e10cSrcweir if ( !*pDeInit ) 190cdf0e10cSrcweir *pDeInit = disabled_deInitSystray; 191cdf0e10cSrcweir } 192cdf0e10cSrcweir 193cdf0e10cSrcweir return true; 194cdf0e10cSrcweir } 195cdf0e10cSrcweir 196cdf0e10cSrcweir class IdleUnloader : Timer 197cdf0e10cSrcweir { 198cdf0e10cSrcweir ::osl::Module *m_pModule; 199cdf0e10cSrcweir public: 200cdf0e10cSrcweir IdleUnloader (::osl::Module **pModule) : 201cdf0e10cSrcweir m_pModule (*pModule) 202cdf0e10cSrcweir { 203cdf0e10cSrcweir *pModule = NULL; 204cdf0e10cSrcweir Start(); 205cdf0e10cSrcweir } 206cdf0e10cSrcweir virtual void Timeout() 207cdf0e10cSrcweir { 208cdf0e10cSrcweir delete m_pModule; 209cdf0e10cSrcweir delete this; 210cdf0e10cSrcweir } 211cdf0e10cSrcweir }; 212cdf0e10cSrcweir 213cdf0e10cSrcweir void ShutdownIcon::initSystray() 214cdf0e10cSrcweir { 215cdf0e10cSrcweir if (m_bInitialized) 216cdf0e10cSrcweir return; 217cdf0e10cSrcweir m_bInitialized = true; 218cdf0e10cSrcweir 219cdf0e10cSrcweir (void) LoadModule( &m_pPlugin, &m_pInitSystray, &m_pDeInitSystray ); 220cdf0e10cSrcweir m_bVeto = true; 221cdf0e10cSrcweir m_pInitSystray(); 222cdf0e10cSrcweir } 223cdf0e10cSrcweir 224cdf0e10cSrcweir void ShutdownIcon::deInitSystray() 225cdf0e10cSrcweir { 226cdf0e10cSrcweir if (!m_bInitialized) 227cdf0e10cSrcweir return; 228cdf0e10cSrcweir 229cdf0e10cSrcweir if (m_pDeInitSystray) 230cdf0e10cSrcweir m_pDeInitSystray(); 231cdf0e10cSrcweir 232cdf0e10cSrcweir m_bVeto = false; 233cdf0e10cSrcweir m_pInitSystray = 0; 234cdf0e10cSrcweir m_pDeInitSystray = 0; 235cdf0e10cSrcweir new IdleUnloader (&m_pPlugin); 236cdf0e10cSrcweir 237cdf0e10cSrcweir delete m_pFileDlg; 238cdf0e10cSrcweir m_pFileDlg = NULL; 239cdf0e10cSrcweir m_bInitialized = false; 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242cdf0e10cSrcweir 243cdf0e10cSrcweir ShutdownIcon::ShutdownIcon( Reference< XMultiServiceFactory > aSMgr ) : 244cdf0e10cSrcweir ShutdownIconServiceBase( m_aMutex ), 245cdf0e10cSrcweir m_bVeto ( false ), 246cdf0e10cSrcweir m_bListenForTermination ( false ), 247cdf0e10cSrcweir m_bSystemDialogs( false ), 248cdf0e10cSrcweir m_pResMgr( NULL ), 249cdf0e10cSrcweir m_pFileDlg( NULL ), 250cdf0e10cSrcweir m_xServiceManager( aSMgr ), 251cdf0e10cSrcweir m_pInitSystray( 0 ), 252cdf0e10cSrcweir m_pDeInitSystray( 0 ), 253cdf0e10cSrcweir m_pPlugin( 0 ), 254cdf0e10cSrcweir m_bInitialized( false ) 255cdf0e10cSrcweir { 256cdf0e10cSrcweir m_bSystemDialogs = SvtMiscOptions().UseSystemFileDialog(); 257cdf0e10cSrcweir } 258cdf0e10cSrcweir 259cdf0e10cSrcweir ShutdownIcon::~ShutdownIcon() 260cdf0e10cSrcweir { 261cdf0e10cSrcweir deInitSystray(); 262cdf0e10cSrcweir new IdleUnloader (&m_pPlugin); 263cdf0e10cSrcweir } 264cdf0e10cSrcweir 265cdf0e10cSrcweir // --------------------------------------------------------------------------- 266cdf0e10cSrcweir 267cdf0e10cSrcweir void ShutdownIcon::OpenURL( const ::rtl::OUString& aURL, const ::rtl::OUString& rTarget, const Sequence< PropertyValue >& aArgs ) 268cdf0e10cSrcweir { 269cdf0e10cSrcweir if ( getInstance() && getInstance()->m_xDesktop.is() ) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir Reference < XDispatchProvider > xDispatchProvider( getInstance()->m_xDesktop, UNO_QUERY ); 272cdf0e10cSrcweir if ( xDispatchProvider.is() ) 273cdf0e10cSrcweir { 274cdf0e10cSrcweir com::sun::star::util::URL aDispatchURL; 275cdf0e10cSrcweir aDispatchURL.Complete = aURL; 276cdf0e10cSrcweir 277cdf0e10cSrcweir Reference < com::sun::star::util::XURLTransformer > xURLTransformer( 278cdf0e10cSrcweir ::comphelper::getProcessServiceFactory()->createInstance( OUString::createFromAscii("com.sun.star.util.URLTransformer") ), 279cdf0e10cSrcweir com::sun::star::uno::UNO_QUERY ); 280cdf0e10cSrcweir if ( xURLTransformer.is() ) 281cdf0e10cSrcweir { 282cdf0e10cSrcweir try 283cdf0e10cSrcweir { 284cdf0e10cSrcweir Reference< com::sun::star::frame::XDispatch > xDispatch; 285cdf0e10cSrcweir 286cdf0e10cSrcweir xURLTransformer->parseStrict( aDispatchURL ); 287cdf0e10cSrcweir xDispatch = xDispatchProvider->queryDispatch( aDispatchURL, rTarget, 0 ); 288cdf0e10cSrcweir if ( xDispatch.is() ) 289cdf0e10cSrcweir xDispatch->dispatch( aDispatchURL, aArgs ); 290cdf0e10cSrcweir } 291cdf0e10cSrcweir catch ( com::sun::star::uno::RuntimeException& ) 292cdf0e10cSrcweir { 293cdf0e10cSrcweir throw; 294cdf0e10cSrcweir } 295cdf0e10cSrcweir catch ( com::sun::star::uno::Exception& ) 296cdf0e10cSrcweir { 297cdf0e10cSrcweir } 298cdf0e10cSrcweir } 299cdf0e10cSrcweir } 300cdf0e10cSrcweir } 301cdf0e10cSrcweir } 302cdf0e10cSrcweir 303cdf0e10cSrcweir // --------------------------------------------------------------------------- 304cdf0e10cSrcweir 305cdf0e10cSrcweir void ShutdownIcon::FileOpen() 306cdf0e10cSrcweir { 307cdf0e10cSrcweir if ( getInstance() && getInstance()->m_xDesktop.is() ) 308cdf0e10cSrcweir { 309cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 310cdf0e10cSrcweir EnterModalMode(); 311cdf0e10cSrcweir getInstance()->StartFileDialog(); 312cdf0e10cSrcweir } 313cdf0e10cSrcweir } 314cdf0e10cSrcweir 315cdf0e10cSrcweir // --------------------------------------------------------------------------- 316cdf0e10cSrcweir 317cdf0e10cSrcweir void ShutdownIcon::FromTemplate() 318cdf0e10cSrcweir { 319cdf0e10cSrcweir if ( getInstance() && getInstance()->m_xDesktop.is() ) 320cdf0e10cSrcweir { 321cdf0e10cSrcweir Reference < ::com::sun::star::frame::XFramesSupplier > xDesktop ( getInstance()->m_xDesktop, UNO_QUERY); 322cdf0e10cSrcweir Reference < ::com::sun::star::frame::XFrame > xFrame( xDesktop->getActiveFrame() ); 323cdf0e10cSrcweir if ( !xFrame.is() ) 324cdf0e10cSrcweir xFrame = Reference < ::com::sun::star::frame::XFrame >( xDesktop, UNO_QUERY ); 325cdf0e10cSrcweir 326cdf0e10cSrcweir URL aTargetURL; 327cdf0e10cSrcweir aTargetURL.Complete = OUString( RTL_CONSTASCII_USTRINGPARAM( "slot:5500" ) ); 328cdf0e10cSrcweir Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY ); 329cdf0e10cSrcweir xTrans->parseStrict( aTargetURL ); 330cdf0e10cSrcweir 331cdf0e10cSrcweir Reference < ::com::sun::star::frame::XDispatchProvider > xProv( xFrame, UNO_QUERY ); 332cdf0e10cSrcweir Reference < ::com::sun::star::frame::XDispatch > xDisp; 333cdf0e10cSrcweir if ( xProv.is() ) 334cdf0e10cSrcweir { 335cdf0e10cSrcweir if ( aTargetURL.Protocol.compareToAscii("slot:") == COMPARE_EQUAL ) 336cdf0e10cSrcweir xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString(), 0 ); 337cdf0e10cSrcweir else 338cdf0e10cSrcweir xDisp = xProv->queryDispatch( aTargetURL, ::rtl::OUString::createFromAscii("_blank"), 0 ); 339cdf0e10cSrcweir } 340cdf0e10cSrcweir if ( xDisp.is() ) 341cdf0e10cSrcweir { 342cdf0e10cSrcweir Sequence<PropertyValue> aArgs(1); 343cdf0e10cSrcweir PropertyValue* pArg = aArgs.getArray(); 344cdf0e10cSrcweir pArg[0].Name = rtl::OUString::createFromAscii("Referer"); 345cdf0e10cSrcweir pArg[0].Value <<= ::rtl::OUString::createFromAscii("private:user"); 346cdf0e10cSrcweir Reference< ::com::sun::star::frame::XNotifyingDispatch > xNotifyer( xDisp, UNO_QUERY ); 347cdf0e10cSrcweir if ( xNotifyer.is() ) 348cdf0e10cSrcweir { 349cdf0e10cSrcweir EnterModalMode(); 350cdf0e10cSrcweir xNotifyer->dispatchWithNotification( aTargetURL, aArgs, new SfxNotificationListener_Impl() ); 351cdf0e10cSrcweir } 352cdf0e10cSrcweir else 353cdf0e10cSrcweir xDisp->dispatch( aTargetURL, aArgs ); 354cdf0e10cSrcweir } 355cdf0e10cSrcweir } 356cdf0e10cSrcweir } 357cdf0e10cSrcweir 358cdf0e10cSrcweir // --------------------------------------------------------------------------- 359cdf0e10cSrcweir #include <tools/rcid.h> 360cdf0e10cSrcweir OUString ShutdownIcon::GetResString( int id ) 361cdf0e10cSrcweir { 362cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 363cdf0e10cSrcweir 364cdf0e10cSrcweir if( ! m_pResMgr ) 365cdf0e10cSrcweir m_pResMgr = SfxResId::GetResMgr(); 366cdf0e10cSrcweir ResId aResId( id, *m_pResMgr ); 367cdf0e10cSrcweir aResId.SetRT( RSC_STRING ); 368cdf0e10cSrcweir if( !m_pResMgr || !m_pResMgr->IsAvailable( aResId ) ) 369cdf0e10cSrcweir return OUString(); 370cdf0e10cSrcweir 371cdf0e10cSrcweir UniString aRes( ResId(id, *m_pResMgr) ); 372cdf0e10cSrcweir return OUString( aRes ); 373cdf0e10cSrcweir } 374cdf0e10cSrcweir 375cdf0e10cSrcweir // --------------------------------------------------------------------------- 376cdf0e10cSrcweir 377cdf0e10cSrcweir OUString ShutdownIcon::GetUrlDescription( const OUString& aUrl ) 378cdf0e10cSrcweir { 379cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 380cdf0e10cSrcweir 381cdf0e10cSrcweir return OUString( SvFileInformationManager::GetDescription( INetURLObject( aUrl ) ) ); 382cdf0e10cSrcweir } 383cdf0e10cSrcweir 384cdf0e10cSrcweir // --------------------------------------------------------------------------- 385cdf0e10cSrcweir 386cdf0e10cSrcweir void ShutdownIcon::StartFileDialog() 387cdf0e10cSrcweir { 388cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 389cdf0e10cSrcweir 390cdf0e10cSrcweir bool bDirty = ( m_bSystemDialogs != static_cast<bool>(SvtMiscOptions().UseSystemFileDialog()) ); 391cdf0e10cSrcweir 392cdf0e10cSrcweir if ( m_pFileDlg && bDirty ) 393cdf0e10cSrcweir { 394cdf0e10cSrcweir // Destroy instance as changing the system file dialog setting 395cdf0e10cSrcweir // forces us to create a new FileDialogHelper instance! 396cdf0e10cSrcweir delete m_pFileDlg; 397cdf0e10cSrcweir m_pFileDlg = NULL; 398cdf0e10cSrcweir } 399cdf0e10cSrcweir 400cdf0e10cSrcweir if ( !m_pFileDlg ) 401cdf0e10cSrcweir m_pFileDlg = new FileDialogHelper( WB_OPEN | SFXWB_MULTISELECTION, String() ); 402cdf0e10cSrcweir m_pFileDlg->StartExecuteModal( STATIC_LINK( this, ShutdownIcon, DialogClosedHdl_Impl ) ); 403cdf0e10cSrcweir } 404cdf0e10cSrcweir 405cdf0e10cSrcweir // --------------------------------------------------------------------------- 406cdf0e10cSrcweir 407cdf0e10cSrcweir IMPL_STATIC_LINK( ShutdownIcon, DialogClosedHdl_Impl, FileDialogHelper*, EMPTYARG ) 408cdf0e10cSrcweir { 409cdf0e10cSrcweir DBG_ASSERT( pThis->m_pFileDlg, "ShutdownIcon, DialogClosedHdl_Impl(): no file dialog" ); 410cdf0e10cSrcweir 411cdf0e10cSrcweir // use ctor for filling up filters automatically! #89169# 412cdf0e10cSrcweir if ( ERRCODE_NONE == pThis->m_pFileDlg->GetError() ) 413cdf0e10cSrcweir { 414cdf0e10cSrcweir Reference< XFilePicker > xPicker = pThis->m_pFileDlg->GetFilePicker(); 415cdf0e10cSrcweir 416cdf0e10cSrcweir try 417cdf0e10cSrcweir { 418cdf0e10cSrcweir 419cdf0e10cSrcweir if ( xPicker.is() ) 420cdf0e10cSrcweir { 421cdf0e10cSrcweir 422cdf0e10cSrcweir Reference < XFilePickerControlAccess > xPickerControls ( xPicker, UNO_QUERY ); 423cdf0e10cSrcweir Reference < XFilterManager > xFilterManager ( xPicker, UNO_QUERY ); 424cdf0e10cSrcweir 425cdf0e10cSrcweir Sequence< OUString > sFiles = xPicker->getFiles(); 426cdf0e10cSrcweir int nFiles = sFiles.getLength(); 427cdf0e10cSrcweir 428cdf0e10cSrcweir int nArgs=3; 429cdf0e10cSrcweir Sequence< PropertyValue > aArgs(3); 430cdf0e10cSrcweir 431cdf0e10cSrcweir Reference < com::sun::star::task::XInteractionHandler > xInteraction( 432cdf0e10cSrcweir ::comphelper::getProcessServiceFactory()->createInstance( OUString::createFromAscii("com.sun.star.task.InteractionHandler") ), 433cdf0e10cSrcweir com::sun::star::uno::UNO_QUERY ); 434cdf0e10cSrcweir 435cdf0e10cSrcweir aArgs[0].Name = OUString::createFromAscii( "InteractionHandler" ); 436cdf0e10cSrcweir aArgs[0].Value <<= xInteraction; 437cdf0e10cSrcweir 438cdf0e10cSrcweir sal_Int16 nMacroExecMode = ::com::sun::star::document::MacroExecMode::USE_CONFIG; 439cdf0e10cSrcweir aArgs[1].Name = OUString::createFromAscii( "MacroExecutionMode" ); 440cdf0e10cSrcweir aArgs[1].Value <<= nMacroExecMode; 441cdf0e10cSrcweir 442cdf0e10cSrcweir sal_Int16 nUpdateDoc = ::com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG; 443cdf0e10cSrcweir aArgs[2].Name = OUString::createFromAscii( "UpdateDocMode" ); 444cdf0e10cSrcweir aArgs[2].Value <<= nUpdateDoc; 445cdf0e10cSrcweir 446cdf0e10cSrcweir // pb: #102643# use the filedlghelper to get the current filter name, 447cdf0e10cSrcweir // because it removes the extensions before you get the filter name. 448cdf0e10cSrcweir OUString aFilterName( pThis->m_pFileDlg->GetCurrentFilter() ); 449cdf0e10cSrcweir 450cdf0e10cSrcweir if ( xPickerControls.is() ) 451cdf0e10cSrcweir { 452cdf0e10cSrcweir 453cdf0e10cSrcweir // Set readonly flag 454cdf0e10cSrcweir 455cdf0e10cSrcweir sal_Bool bReadOnly = sal_False; 456cdf0e10cSrcweir 457cdf0e10cSrcweir 458cdf0e10cSrcweir xPickerControls->getValue( ExtendedFilePickerElementIds::CHECKBOX_READONLY, 0 ) >>= bReadOnly; 459cdf0e10cSrcweir 460cdf0e10cSrcweir // #95239#: Only set porperty if readonly is set to TRUE 461cdf0e10cSrcweir 462cdf0e10cSrcweir if ( bReadOnly ) 463cdf0e10cSrcweir { 464cdf0e10cSrcweir aArgs.realloc( ++nArgs ); 465cdf0e10cSrcweir aArgs[nArgs-1].Name = OUString::createFromAscii( "ReadOnly" ); 466cdf0e10cSrcweir aArgs[nArgs-1].Value <<= bReadOnly; 467cdf0e10cSrcweir } 468cdf0e10cSrcweir 469cdf0e10cSrcweir // Get version string 470cdf0e10cSrcweir 471cdf0e10cSrcweir sal_Int32 iVersion = -1; 472cdf0e10cSrcweir 473cdf0e10cSrcweir xPickerControls->getValue( ExtendedFilePickerElementIds::LISTBOX_VERSION, ControlActions::GET_SELECTED_ITEM_INDEX ) >>= iVersion; 474cdf0e10cSrcweir 475cdf0e10cSrcweir if ( iVersion >= 0 ) 476cdf0e10cSrcweir { 477cdf0e10cSrcweir sal_Int16 uVersion = (sal_Int16)iVersion; 478cdf0e10cSrcweir 479cdf0e10cSrcweir aArgs.realloc( ++nArgs ); 480cdf0e10cSrcweir aArgs[nArgs-1].Name = OUString::createFromAscii( "Version" ); 481cdf0e10cSrcweir aArgs[nArgs-1].Value <<= uVersion; 482cdf0e10cSrcweir } 483cdf0e10cSrcweir 484cdf0e10cSrcweir // Retrieve the current filter 485cdf0e10cSrcweir 486cdf0e10cSrcweir if ( !aFilterName.getLength() ) 487cdf0e10cSrcweir xPickerControls->getValue( CommonFilePickerElementIds::LISTBOX_FILTER, ControlActions::GET_SELECTED_ITEM ) >>= aFilterName; 488cdf0e10cSrcweir 489cdf0e10cSrcweir } 490cdf0e10cSrcweir 491cdf0e10cSrcweir 492cdf0e10cSrcweir // Convert UI filter name to internal filter name 493cdf0e10cSrcweir 494cdf0e10cSrcweir if ( aFilterName.getLength() ) 495cdf0e10cSrcweir { 496cdf0e10cSrcweir const SfxFilter* pFilter = SFX_APP()->GetFilterMatcher().GetFilter4UIName( aFilterName, 0, SFX_FILTER_NOTINFILEDLG ); 497cdf0e10cSrcweir 498cdf0e10cSrcweir if ( pFilter ) 499cdf0e10cSrcweir { 500cdf0e10cSrcweir aFilterName = pFilter->GetFilterName(); 501cdf0e10cSrcweir 502cdf0e10cSrcweir if ( aFilterName.getLength() ) 503cdf0e10cSrcweir { 504cdf0e10cSrcweir aArgs.realloc( ++nArgs ); 505cdf0e10cSrcweir aArgs[nArgs-1].Name = OUString::createFromAscii( "FilterName" ); 506cdf0e10cSrcweir aArgs[nArgs-1].Value <<= aFilterName; 507cdf0e10cSrcweir } 508cdf0e10cSrcweir } 509cdf0e10cSrcweir } 510cdf0e10cSrcweir 511cdf0e10cSrcweir if ( 1 == nFiles ) 512cdf0e10cSrcweir OpenURL( sFiles[0], OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ), aArgs ); 513cdf0e10cSrcweir else 514cdf0e10cSrcweir { 515cdf0e10cSrcweir OUString aBaseDirURL = sFiles[0]; 516cdf0e10cSrcweir if ( aBaseDirURL.getLength() > 0 && aBaseDirURL[aBaseDirURL.getLength()-1] != '/' ) 517cdf0e10cSrcweir aBaseDirURL += OUString::createFromAscii("/"); 518cdf0e10cSrcweir 519cdf0e10cSrcweir int iFiles; 520cdf0e10cSrcweir for ( iFiles = 1; iFiles < nFiles; iFiles++ ) 521cdf0e10cSrcweir { 522cdf0e10cSrcweir OUString aURL = aBaseDirURL; 523cdf0e10cSrcweir aURL += sFiles[iFiles]; 524cdf0e10cSrcweir OpenURL( aURL, OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ), aArgs ); 525cdf0e10cSrcweir } 526cdf0e10cSrcweir } 527cdf0e10cSrcweir } 528cdf0e10cSrcweir } 529cdf0e10cSrcweir catch ( ... ) 530cdf0e10cSrcweir { 531cdf0e10cSrcweir } 532cdf0e10cSrcweir } 533cdf0e10cSrcweir 534cdf0e10cSrcweir #ifdef WNT 535cdf0e10cSrcweir // #103346 Destroy dialog to prevent problems with custom controls 536cdf0e10cSrcweir // This fix is dependent on the dialog settings. Destroying the dialog here will 537cdf0e10cSrcweir // crash the non-native dialog implementation! Therefore make this dependent on 538cdf0e10cSrcweir // the settings. 539cdf0e10cSrcweir if ( SvtMiscOptions().UseSystemFileDialog() ) 540cdf0e10cSrcweir { 541cdf0e10cSrcweir delete pThis->m_pFileDlg; 542cdf0e10cSrcweir pThis->m_pFileDlg = NULL; 543cdf0e10cSrcweir } 544cdf0e10cSrcweir #endif 545cdf0e10cSrcweir 546cdf0e10cSrcweir LeaveModalMode(); 547cdf0e10cSrcweir return 0; 548cdf0e10cSrcweir } 549cdf0e10cSrcweir 550cdf0e10cSrcweir // --------------------------------------------------------------------------- 551cdf0e10cSrcweir 552cdf0e10cSrcweir void ShutdownIcon::addTerminateListener() 553cdf0e10cSrcweir { 554cdf0e10cSrcweir ShutdownIcon* pInst = getInstance(); 555cdf0e10cSrcweir if ( ! pInst) 556cdf0e10cSrcweir return; 557cdf0e10cSrcweir 558cdf0e10cSrcweir if (pInst->m_bListenForTermination) 559cdf0e10cSrcweir return; 560cdf0e10cSrcweir 561cdf0e10cSrcweir Reference< XDesktop > xDesktop = pInst->m_xDesktop; 562cdf0e10cSrcweir if ( ! xDesktop.is()) 563cdf0e10cSrcweir return; 564cdf0e10cSrcweir 565cdf0e10cSrcweir xDesktop->addTerminateListener( pInst ); 566cdf0e10cSrcweir pInst->m_bListenForTermination = true; 567cdf0e10cSrcweir } 568cdf0e10cSrcweir 569cdf0e10cSrcweir // --------------------------------------------------------------------------- 570cdf0e10cSrcweir 571cdf0e10cSrcweir void ShutdownIcon::terminateDesktop() 572cdf0e10cSrcweir { 573cdf0e10cSrcweir ShutdownIcon* pInst = getInstance(); 574cdf0e10cSrcweir if ( ! pInst) 575cdf0e10cSrcweir return; 576cdf0e10cSrcweir 577cdf0e10cSrcweir Reference< XDesktop > xDesktop = pInst->m_xDesktop; 578cdf0e10cSrcweir if ( ! xDesktop.is()) 579cdf0e10cSrcweir return; 580cdf0e10cSrcweir 581cdf0e10cSrcweir // always remove ourselves as listener 582cdf0e10cSrcweir xDesktop->removeTerminateListener( pInst ); 583cdf0e10cSrcweir pInst->m_bListenForTermination = true; 584cdf0e10cSrcweir 585cdf0e10cSrcweir // terminate desktop only if no tasks exist 586cdf0e10cSrcweir Reference< XFramesSupplier > xSupplier( xDesktop, UNO_QUERY ); 587cdf0e10cSrcweir if ( xSupplier.is() ) 588cdf0e10cSrcweir { 589cdf0e10cSrcweir Reference< XIndexAccess > xTasks ( xSupplier->getFrames(), UNO_QUERY ); 590cdf0e10cSrcweir if( xTasks.is() ) 591cdf0e10cSrcweir { 592cdf0e10cSrcweir if( xTasks->getCount() < 1 ) 593cdf0e10cSrcweir xDesktop->terminate(); 594cdf0e10cSrcweir } 595cdf0e10cSrcweir } 596cdf0e10cSrcweir 597cdf0e10cSrcweir // remove the instance pointer 598cdf0e10cSrcweir ShutdownIcon::pShutdownIcon = 0; 599cdf0e10cSrcweir } 600cdf0e10cSrcweir 601cdf0e10cSrcweir // --------------------------------------------------------------------------- 602cdf0e10cSrcweir 603cdf0e10cSrcweir ShutdownIcon* ShutdownIcon::getInstance() 604cdf0e10cSrcweir { 605cdf0e10cSrcweir OSL_ASSERT( pShutdownIcon ); 606cdf0e10cSrcweir return pShutdownIcon; 607cdf0e10cSrcweir } 608cdf0e10cSrcweir 609cdf0e10cSrcweir // --------------------------------------------------------------------------- 610cdf0e10cSrcweir 611cdf0e10cSrcweir ShutdownIcon* ShutdownIcon::createInstance() 612cdf0e10cSrcweir { 613cdf0e10cSrcweir if (pShutdownIcon) 614cdf0e10cSrcweir return pShutdownIcon; 615cdf0e10cSrcweir 616cdf0e10cSrcweir ShutdownIcon *pIcon = NULL; 617cdf0e10cSrcweir try { 618cdf0e10cSrcweir Reference< XMultiServiceFactory > xSMgr( comphelper::getProcessServiceFactory() ); 619cdf0e10cSrcweir pIcon = new ShutdownIcon( xSMgr ); 620cdf0e10cSrcweir pIcon->init (); 621cdf0e10cSrcweir pShutdownIcon = pIcon; 622cdf0e10cSrcweir } catch (...) { 623cdf0e10cSrcweir delete pIcon; 624cdf0e10cSrcweir } 625cdf0e10cSrcweir 626cdf0e10cSrcweir return pShutdownIcon; 627cdf0e10cSrcweir } 628cdf0e10cSrcweir 629cdf0e10cSrcweir void ShutdownIcon::init() throw( ::com::sun::star::uno::Exception ) 630cdf0e10cSrcweir { 631cdf0e10cSrcweir // access resource system and sfx only protected by solarmutex 632cdf0e10cSrcweir vos::OGuard aSolarGuard( Application::GetSolarMutex() ); 633cdf0e10cSrcweir ResMgr *pResMgr = SfxResId::GetResMgr(); 634cdf0e10cSrcweir 635cdf0e10cSrcweir ::osl::ResettableMutexGuard aGuard( m_aMutex ); 636cdf0e10cSrcweir m_pResMgr = pResMgr; 637cdf0e10cSrcweir aGuard.clear(); 638cdf0e10cSrcweir Reference < XDesktop > xDesktop( m_xServiceManager->createInstance( 639cdf0e10cSrcweir DEFINE_CONST_UNICODE( "com.sun.star.frame.Desktop" )), 640cdf0e10cSrcweir UNO_QUERY ); 641cdf0e10cSrcweir aGuard.reset(); 642cdf0e10cSrcweir m_xDesktop = xDesktop; 643cdf0e10cSrcweir } 644cdf0e10cSrcweir 645cdf0e10cSrcweir // --------------------------------------------------------------------------- 646cdf0e10cSrcweir 647cdf0e10cSrcweir void SAL_CALL ShutdownIcon::disposing() 648cdf0e10cSrcweir { 649cdf0e10cSrcweir m_xServiceManager = Reference< XMultiServiceFactory >(); 650cdf0e10cSrcweir m_xDesktop = Reference< XDesktop >(); 651cdf0e10cSrcweir } 652cdf0e10cSrcweir 653cdf0e10cSrcweir // --------------------------------------------------------------------------- 654cdf0e10cSrcweir 655cdf0e10cSrcweir // XEventListener 656cdf0e10cSrcweir void SAL_CALL ShutdownIcon::disposing( const ::com::sun::star::lang::EventObject& ) 657cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 658cdf0e10cSrcweir { 659cdf0e10cSrcweir } 660cdf0e10cSrcweir 661cdf0e10cSrcweir // --------------------------------------------------------------------------- 662cdf0e10cSrcweir 663cdf0e10cSrcweir // XTerminateListener 664cdf0e10cSrcweir void SAL_CALL ShutdownIcon::queryTermination( const ::com::sun::star::lang::EventObject& ) 665cdf0e10cSrcweir throw(::com::sun::star::frame::TerminationVetoException, ::com::sun::star::uno::RuntimeException) 666cdf0e10cSrcweir { 667cdf0e10cSrcweir ::osl::ClearableMutexGuard aGuard( m_aMutex ); 668cdf0e10cSrcweir 669cdf0e10cSrcweir if ( m_bVeto ) 670cdf0e10cSrcweir throw ::com::sun::star::frame::TerminationVetoException(); 671cdf0e10cSrcweir } 672cdf0e10cSrcweir 673cdf0e10cSrcweir 674cdf0e10cSrcweir // --------------------------------------------------------------------------- 675cdf0e10cSrcweir 676cdf0e10cSrcweir void SAL_CALL ShutdownIcon::notifyTermination( const ::com::sun::star::lang::EventObject& ) 677cdf0e10cSrcweir throw(::com::sun::star::uno::RuntimeException) 678cdf0e10cSrcweir { 679cdf0e10cSrcweir } 680cdf0e10cSrcweir 681cdf0e10cSrcweir 682cdf0e10cSrcweir // --------------------------------------------------------------------------- 683cdf0e10cSrcweir 684cdf0e10cSrcweir void SAL_CALL ShutdownIcon::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any>& aArguments ) 685cdf0e10cSrcweir throw( ::com::sun::star::uno::Exception ) 686cdf0e10cSrcweir { 687cdf0e10cSrcweir ::osl::ResettableMutexGuard aGuard( m_aMutex ); 688cdf0e10cSrcweir 689cdf0e10cSrcweir // third argument only sets veto, everything else will be ignored! 690cdf0e10cSrcweir if (aArguments.getLength() > 2) 691cdf0e10cSrcweir { 692cdf0e10cSrcweir sal_Bool bVeto = sal_True; 693cdf0e10cSrcweir bVeto = ::cppu::any2bool(aArguments[2]); 694cdf0e10cSrcweir m_bVeto = bVeto; 695cdf0e10cSrcweir return; 696cdf0e10cSrcweir } 697cdf0e10cSrcweir 698cdf0e10cSrcweir if ( aArguments.getLength() > 0 ) 699cdf0e10cSrcweir { 700cdf0e10cSrcweir if ( !ShutdownIcon::pShutdownIcon ) 701cdf0e10cSrcweir { 702cdf0e10cSrcweir try 703cdf0e10cSrcweir { 704cdf0e10cSrcweir sal_Bool bQuickstart = sal_False; 705cdf0e10cSrcweir bQuickstart = ::cppu::any2bool( aArguments[0] ); 706cdf0e10cSrcweir if( !bQuickstart && !GetAutostart() ) 707cdf0e10cSrcweir return; 708cdf0e10cSrcweir aGuard.clear(); 709cdf0e10cSrcweir init (); 710cdf0e10cSrcweir aGuard.reset(); 711cdf0e10cSrcweir if ( !m_xDesktop.is() ) 712cdf0e10cSrcweir return; 713cdf0e10cSrcweir 714cdf0e10cSrcweir /* Create a sub-classed instance - foo */ 715cdf0e10cSrcweir ShutdownIcon::pShutdownIcon = this; 716cdf0e10cSrcweir initSystray(); 717cdf0e10cSrcweir #ifdef OS2 718cdf0e10cSrcweir // above win32 starts the quickstart thread, but we have 719cdf0e10cSrcweir // quickstart running only when -quickstart is specified 720cdf0e10cSrcweir // on command line (next boot). 721cdf0e10cSrcweir // so if -quickstart was not specified, we cannot issue 722cdf0e10cSrcweir // quickstart veto on shutdown. 723cdf0e10cSrcweir if (bQuickstart) 724cdf0e10cSrcweir { 725cdf0e10cSrcweir // disable shutdown 726cdf0e10cSrcweir ShutdownIcon::getInstance()->SetVeto( true ); 727cdf0e10cSrcweir ShutdownIcon::getInstance()->addTerminateListener(); 728cdf0e10cSrcweir } 729cdf0e10cSrcweir #endif 730cdf0e10cSrcweir } 731cdf0e10cSrcweir catch(const ::com::sun::star::lang::IllegalArgumentException&) 732cdf0e10cSrcweir { 733cdf0e10cSrcweir } 734cdf0e10cSrcweir } 735cdf0e10cSrcweir } 736cdf0e10cSrcweir if ( aArguments.getLength() > 1 ) 737cdf0e10cSrcweir { 738cdf0e10cSrcweir sal_Bool bAutostart = sal_False; 739cdf0e10cSrcweir bAutostart = ::cppu::any2bool( aArguments[1] ); 740cdf0e10cSrcweir if (bAutostart && !GetAutostart()) 741cdf0e10cSrcweir SetAutostart( sal_True ); 742cdf0e10cSrcweir if (!bAutostart && GetAutostart()) 743cdf0e10cSrcweir SetAutostart( sal_False ); 744cdf0e10cSrcweir } 745cdf0e10cSrcweir 746cdf0e10cSrcweir } 747cdf0e10cSrcweir 748cdf0e10cSrcweir // ------------------------------- 749cdf0e10cSrcweir 750cdf0e10cSrcweir void ShutdownIcon::EnterModalMode() 751cdf0e10cSrcweir { 752cdf0e10cSrcweir bModalMode = sal_True; 753cdf0e10cSrcweir } 754cdf0e10cSrcweir 755cdf0e10cSrcweir // ------------------------------- 756cdf0e10cSrcweir 757cdf0e10cSrcweir void ShutdownIcon::LeaveModalMode() 758cdf0e10cSrcweir { 759cdf0e10cSrcweir bModalMode = sal_False; 760cdf0e10cSrcweir } 761cdf0e10cSrcweir 762cdf0e10cSrcweir #ifdef WNT 763cdf0e10cSrcweir // defined in shutdowniconw32.cxx 764cdf0e10cSrcweir #elif defined(OS2) 765cdf0e10cSrcweir // defined in shutdowniconOs2.cxx 766cdf0e10cSrcweir #elif defined QUARTZ 767cdf0e10cSrcweir // defined in shutdowniconaqua.cxx 768cdf0e10cSrcweir #else 769cdf0e10cSrcweir bool ShutdownIcon::IsQuickstarterInstalled() 770cdf0e10cSrcweir { 771cdf0e10cSrcweir #ifndef ENABLE_QUICKSTART_APPLET 772cdf0e10cSrcweir return false; 773cdf0e10cSrcweir #else // !ENABLE_QUICKSTART_APPLET 774cdf0e10cSrcweir #ifdef UNX 775cdf0e10cSrcweir return LoadModule( NULL, NULL, NULL); 776cdf0e10cSrcweir #endif // UNX 777cdf0e10cSrcweir #endif // !ENABLE_QUICKSTART_APPLET 778cdf0e10cSrcweir } 779cdf0e10cSrcweir #endif // !WNT 780cdf0e10cSrcweir 781cdf0e10cSrcweir // --------------------------------------------------------------------------- 782cdf0e10cSrcweir 783cdf0e10cSrcweir #if defined (ENABLE_QUICKSTART_APPLET) && defined (UNX) 784cdf0e10cSrcweir static OUString getDotAutostart( bool bCreate = false ) 785cdf0e10cSrcweir { 786cdf0e10cSrcweir OUString aShortcut; 787cdf0e10cSrcweir const char *pConfigHome; 788cdf0e10cSrcweir if( (pConfigHome = getenv("XDG_CONFIG_HOME") ) ) 789cdf0e10cSrcweir aShortcut = OStringToOUString( OString( pConfigHome ), RTL_TEXTENCODING_UTF8 ); 790cdf0e10cSrcweir else 791cdf0e10cSrcweir { 792cdf0e10cSrcweir OUString aHomeURL; 793cdf0e10cSrcweir osl::Security().getHomeDir( aHomeURL ); 794cdf0e10cSrcweir ::osl::File::getSystemPathFromFileURL( aHomeURL, aShortcut ); 795cdf0e10cSrcweir aShortcut += OUString( RTL_CONSTASCII_USTRINGPARAM( "/.config" ) ); 796cdf0e10cSrcweir } 797cdf0e10cSrcweir aShortcut += OUString( RTL_CONSTASCII_USTRINGPARAM( "/autostart" ) ); 798cdf0e10cSrcweir if (bCreate) 799cdf0e10cSrcweir { 800cdf0e10cSrcweir OUString aShortcutUrl; 801cdf0e10cSrcweir osl::File::getFileURLFromSystemPath( aShortcut, aShortcutUrl ); 802cdf0e10cSrcweir osl::Directory::createPath( aShortcutUrl ); 803cdf0e10cSrcweir } 804cdf0e10cSrcweir return aShortcut; 805cdf0e10cSrcweir } 806cdf0e10cSrcweir #endif 807cdf0e10cSrcweir 808cdf0e10cSrcweir rtl::OUString ShutdownIcon::getShortcutName() 809cdf0e10cSrcweir { 810cdf0e10cSrcweir #ifndef ENABLE_QUICKSTART_APPLET 811cdf0e10cSrcweir return OUString(); 812cdf0e10cSrcweir #else 813cdf0e10cSrcweir 814cdf0e10cSrcweir OUString aShortcutName( RTL_CONSTASCII_USTRINGPARAM( "StarOffice 6.0" ) ); 815cdf0e10cSrcweir ResMgr* pMgr = SfxResId::GetResMgr(); 816cdf0e10cSrcweir if( pMgr ) 817cdf0e10cSrcweir { 818cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 819cdf0e10cSrcweir UniString aRes( SfxResId( STR_QUICKSTART_LNKNAME ) ); 820cdf0e10cSrcweir aShortcutName = OUString( aRes ); 821cdf0e10cSrcweir } 822cdf0e10cSrcweir #ifdef WNT 823cdf0e10cSrcweir aShortcutName += OUString( RTL_CONSTASCII_USTRINGPARAM( ".lnk" ) ); 824cdf0e10cSrcweir 825cdf0e10cSrcweir OUString aShortcut(GetAutostartFolderNameW32()); 826cdf0e10cSrcweir aShortcut += OUString( RTL_CONSTASCII_USTRINGPARAM( "\\" ) ); 827cdf0e10cSrcweir aShortcut += aShortcutName; 828cdf0e10cSrcweir #else // UNX 829cdf0e10cSrcweir OUString aShortcut = getDotAutostart(); 830cdf0e10cSrcweir aShortcut += OUString( RTL_CONSTASCII_USTRINGPARAM( "/qstart.desktop" ) ); 831cdf0e10cSrcweir #endif // UNX 832cdf0e10cSrcweir return aShortcut; 833cdf0e10cSrcweir #endif // ENABLE_QUICKSTART_APPLET 834cdf0e10cSrcweir } 835cdf0e10cSrcweir 836cdf0e10cSrcweir bool ShutdownIcon::GetAutostart( ) 837cdf0e10cSrcweir { 838cdf0e10cSrcweir #if defined(OS2) 839cdf0e10cSrcweir return GetAutostartOs2( ); 840cdf0e10cSrcweir #elif defined QUARTZ 841cdf0e10cSrcweir return true; 842cdf0e10cSrcweir #else 843cdf0e10cSrcweir bool bRet = false; 844cdf0e10cSrcweir #ifdef ENABLE_QUICKSTART_APPLET 845cdf0e10cSrcweir OUString aShortcut( getShortcutName() ); 846cdf0e10cSrcweir OUString aShortcutUrl; 847cdf0e10cSrcweir osl::File::getFileURLFromSystemPath( aShortcut, aShortcutUrl ); 848cdf0e10cSrcweir osl::File f( aShortcutUrl ); 849cdf0e10cSrcweir osl::File::RC error = f.open( OpenFlag_Read ); 850cdf0e10cSrcweir if( error == osl::File::E_None ) 851cdf0e10cSrcweir { 852cdf0e10cSrcweir f.close(); 853cdf0e10cSrcweir bRet = true; 854cdf0e10cSrcweir } 855cdf0e10cSrcweir #endif // ENABLE_QUICKSTART_APPLET 856cdf0e10cSrcweir return bRet; 857cdf0e10cSrcweir #endif 858cdf0e10cSrcweir } 859cdf0e10cSrcweir 860cdf0e10cSrcweir void ShutdownIcon::SetAutostart( bool bActivate ) 861cdf0e10cSrcweir { 862cdf0e10cSrcweir #ifdef ENABLE_QUICKSTART_APPLET 863cdf0e10cSrcweir OUString aShortcut( getShortcutName() ); 864cdf0e10cSrcweir 865cdf0e10cSrcweir if( bActivate && IsQuickstarterInstalled() ) 866cdf0e10cSrcweir { 867cdf0e10cSrcweir #ifdef WNT 868cdf0e10cSrcweir EnableAutostartW32( aShortcut ); 869cdf0e10cSrcweir #else // UNX 870cdf0e10cSrcweir getDotAutostart( true ); 871cdf0e10cSrcweir 872cdf0e10cSrcweir OUString aPath( RTL_CONSTASCII_USTRINGPARAM("${BRAND_BASE_DIR}/share/xdg/qstart.desktop" ) ); 873cdf0e10cSrcweir Bootstrap::expandMacros( aPath ); 874cdf0e10cSrcweir 875cdf0e10cSrcweir OUString aDesktopFile; 876cdf0e10cSrcweir ::osl::File::getSystemPathFromFileURL( aPath, aDesktopFile ); 877cdf0e10cSrcweir 878cdf0e10cSrcweir OString aDesktopFileUnx = OUStringToOString( aDesktopFile, 879cdf0e10cSrcweir osl_getThreadTextEncoding() ); 880cdf0e10cSrcweir OString aShortcutUnx = OUStringToOString( aShortcut, 881cdf0e10cSrcweir osl_getThreadTextEncoding() ); 882cdf0e10cSrcweir if ((0 != symlink(aDesktopFileUnx, aShortcutUnx)) && (errno == EEXIST)) 883cdf0e10cSrcweir { 884cdf0e10cSrcweir unlink(aShortcutUnx); 885cdf0e10cSrcweir symlink(aDesktopFileUnx, aShortcutUnx); 886cdf0e10cSrcweir } 887cdf0e10cSrcweir 888cdf0e10cSrcweir ShutdownIcon *pIcon = ShutdownIcon::createInstance(); 889cdf0e10cSrcweir if( pIcon ) 890cdf0e10cSrcweir pIcon->initSystray(); 891cdf0e10cSrcweir #endif // UNX 892cdf0e10cSrcweir } 893cdf0e10cSrcweir else 894cdf0e10cSrcweir { 895cdf0e10cSrcweir OUString aShortcutUrl; 896cdf0e10cSrcweir ::osl::File::getFileURLFromSystemPath( aShortcut, aShortcutUrl ); 897cdf0e10cSrcweir ::osl::File::remove( aShortcutUrl ); 898cdf0e10cSrcweir #ifdef UNX 899cdf0e10cSrcweir if (pShutdownIcon) 900cdf0e10cSrcweir { 901cdf0e10cSrcweir ShutdownIcon *pIcon = getInstance(); 902cdf0e10cSrcweir pIcon->deInitSystray(); 903cdf0e10cSrcweir } 904cdf0e10cSrcweir #endif 905cdf0e10cSrcweir } 906cdf0e10cSrcweir #elif defined OS2 907cdf0e10cSrcweir SetAutostartOs2( bActivate ); 908cdf0e10cSrcweir #else 909cdf0e10cSrcweir (void)bActivate; // unused variable 910cdf0e10cSrcweir #endif // ENABLE_QUICKSTART_APPLET 911cdf0e10cSrcweir } 912cdf0e10cSrcweir 913cdf0e10cSrcweir static const ::sal_Int32 PROPHANDLE_TERMINATEVETOSTATE = 0; 914cdf0e10cSrcweir 915cdf0e10cSrcweir // XFastPropertySet 916cdf0e10cSrcweir void SAL_CALL ShutdownIcon::setFastPropertyValue( ::sal_Int32 nHandle, 917cdf0e10cSrcweir const ::com::sun::star::uno::Any& aValue ) 918cdf0e10cSrcweir throw (::com::sun::star::beans::UnknownPropertyException, 919cdf0e10cSrcweir ::com::sun::star::beans::PropertyVetoException, 920cdf0e10cSrcweir ::com::sun::star::lang::IllegalArgumentException, 921cdf0e10cSrcweir ::com::sun::star::lang::WrappedTargetException, 922cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException) 923cdf0e10cSrcweir { 924cdf0e10cSrcweir switch(nHandle) 925cdf0e10cSrcweir { 926cdf0e10cSrcweir case PROPHANDLE_TERMINATEVETOSTATE : 927cdf0e10cSrcweir { 928cdf0e10cSrcweir // use new value in case it's a valid information only 929cdf0e10cSrcweir ::sal_Bool bState( sal_False ); 930cdf0e10cSrcweir if (! (aValue >>= bState)) 931cdf0e10cSrcweir return; 932cdf0e10cSrcweir 933cdf0e10cSrcweir m_bVeto = bState; 934cdf0e10cSrcweir if (m_bVeto && ! m_bListenForTermination) 935cdf0e10cSrcweir addTerminateListener(); 936cdf0e10cSrcweir } 937cdf0e10cSrcweir break; 938cdf0e10cSrcweir 939cdf0e10cSrcweir default : 940cdf0e10cSrcweir throw ::com::sun::star::beans::UnknownPropertyException(); 941cdf0e10cSrcweir } 942cdf0e10cSrcweir } 943cdf0e10cSrcweir 944cdf0e10cSrcweir // XFastPropertySet 945cdf0e10cSrcweir ::com::sun::star::uno::Any SAL_CALL ShutdownIcon::getFastPropertyValue( ::sal_Int32 nHandle ) 946cdf0e10cSrcweir throw (::com::sun::star::beans::UnknownPropertyException, 947cdf0e10cSrcweir ::com::sun::star::lang::WrappedTargetException, 948cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException) 949cdf0e10cSrcweir { 950cdf0e10cSrcweir ::com::sun::star::uno::Any aValue; 951cdf0e10cSrcweir switch(nHandle) 952cdf0e10cSrcweir { 953cdf0e10cSrcweir case PROPHANDLE_TERMINATEVETOSTATE : 954cdf0e10cSrcweir { 955cdf0e10cSrcweir bool bState = (m_bListenForTermination && m_bVeto); 956cdf0e10cSrcweir aValue <<= bState; 957cdf0e10cSrcweir } 958cdf0e10cSrcweir break; 959cdf0e10cSrcweir 960cdf0e10cSrcweir default : 961cdf0e10cSrcweir throw ::com::sun::star::beans::UnknownPropertyException(); 962cdf0e10cSrcweir } 963cdf0e10cSrcweir 964cdf0e10cSrcweir return aValue; 965cdf0e10cSrcweir } 966