1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: shutdownicon.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
34 #include <shutdownicon.hxx>
36 #include <sfx2/app.hxx>
37 #include <vos/mutex.hxx>
38 #include <svtools/imagemgr.hxx>
39 // #include <cmdlineargs.hxx>
40 #include <com/sun/star/task/XInteractionHandler.hpp>
41 #include <com/sun/star/frame/XDispatchResultListener.hpp>
42 #include <com/sun/star/frame/XNotifyingDispatch.hpp>
43 #include <com/sun/star/frame/XFramesSupplier.hpp>
44 #include <com/sun/star/frame/XComponentLoader.hpp>
45 #include <com/sun/star/frame/XFrame.hpp>
46 #include <com/sun/star/util/XURLTransformer.hpp>
47 #include <com/sun/star/frame/XFramesSupplier.hpp>
48 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
49 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
50 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
51 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
52 #include <com/sun/star/ui/dialogs/ControlActions.hpp>
53 #include <com/sun/star/document/MacroExecMode.hpp>
54 #include <com/sun/star/document/UpdateDocMode.hpp>
55 #include <sfx2/filedlghelper.hxx>
56 #include <sfx2/fcontnr.hxx>
57 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
58 #include <comphelper/processfactory.hxx>
60 #include <cppuhelper/compbase1.hxx>
61 #include <sfx2/dispatch.hxx>
62 #include <comphelper/extract.hxx>
63 #include <tools/urlobj.hxx>
64 #include <osl/security.hxx>
65 #include <osl/file.hxx>
66 #include <rtl/bootstrap.hxx>
67 #include <tools/link.hxx>
68 #ifdef UNX // need symlink
73 #include "sfxresid.hxx"
75 using namespace ::com::sun::star::uno
;
76 using namespace ::com::sun::star::frame
;
77 using namespace ::com::sun::star::container
;
78 using namespace ::com::sun::star::io
;
79 using namespace ::com::sun::star::lang
;
80 using namespace ::com::sun::star::beans
;
81 using namespace ::com::sun::star::util
;
82 using namespace ::com::sun::star::ui::dialogs
;
83 using namespace ::vos
;
84 using namespace ::rtl
;
85 using namespace ::sfx2
;
87 #ifdef ENABLE_QUICKSTART_APPLET
88 # if !defined(WIN32) && !defined(QUARTZ)
89 extern "C" { static void SAL_CALL
thisModule() {} }
93 class SfxNotificationListener_Impl
: public cppu::WeakImplHelper1
< XDispatchResultListener
>
96 virtual void SAL_CALL
dispatchFinished( const DispatchResultEvent
& aEvent
) throw( RuntimeException
);
97 virtual void SAL_CALL
disposing( const EventObject
& aEvent
) throw( RuntimeException
);
100 void SAL_CALL
SfxNotificationListener_Impl::dispatchFinished( const DispatchResultEvent
& ) throw( RuntimeException
)
102 ShutdownIcon::LeaveModalMode();
105 void SAL_CALL
SfxNotificationListener_Impl::disposing( const EventObject
& ) throw( RuntimeException
)
109 SFX_IMPL_XSERVICEINFO( ShutdownIcon
, "com.sun.star.office.Quickstart", "com.sun.star.comp.desktop.QuickstartWrapper" ) \
110 SFX_IMPL_ONEINSTANCEFACTORY( ShutdownIcon
);
112 bool ShutdownIcon::bModalMode
= false;
113 ShutdownIcon
* ShutdownIcon::pShutdownIcon
= NULL
;
115 // To remove conditionals
117 static void disabled_initSystray() { }
118 static void disabled_deInitSystray() { }
120 #define DOSTRING( x ) #x
121 #define STRING( x ) DOSTRING( x )
123 bool ShutdownIcon::LoadModule( osl::Module
**pModule
,
124 oslGenericFunction
*pInit
,
125 oslGenericFunction
*pDeInit
)
129 OSL_ASSERT ( pInit
&& pDeInit
);
130 *pInit
= *pDeInit
= NULL
;
134 #ifdef ENABLE_QUICKSTART_APPLET
138 *pInit
= win32_init_sys_tray
;
139 *pDeInit
= win32_shutdown_sys_tray
;
142 # elif defined QUARTZ
143 *pInit
= aqua_init_systray
;
144 *pDeInit
= aqua_shutdown_systray
;
147 osl::Module
*pPlugin
;
148 pPlugin
= new osl::Module();
150 oslGenericFunction pTmpInit
= NULL
;
151 oslGenericFunction pTmpDeInit
= NULL
;
152 if ( pPlugin
->loadRelative( &thisModule
, OUString (RTL_CONSTASCII_USTRINGPARAM( STRING( PLUGIN_NAME
) ) ) ) )
154 pTmpInit
= pPlugin
->getFunctionSymbol(
155 OUString( RTL_CONSTASCII_USTRINGPARAM( "plugin_init_sys_tray" ) ) );
156 pTmpDeInit
= pPlugin
->getFunctionSymbol(
157 OUString( RTL_CONSTASCII_USTRINGPARAM( "plugin_shutdown_sys_tray" ) ) );
159 if ( !pTmpInit
|| !pTmpDeInit
)
168 *pDeInit
= pTmpDeInit
;
172 bool bRet
= pPlugin
!= NULL
;
177 #endif // ENABLE_QUICKSTART_APPLET
181 *pInit
= disabled_initSystray
;
183 *pDeInit
= disabled_deInitSystray
;
189 void ShutdownIcon::initSystray()
193 m_bInitialized
= true;
196 (void) LoadModule( &m_pPlugin
, &m_pInitSystray
, &m_pDeInitSystray
);
202 void ShutdownIcon::deInitSystray()
207 if (m_pDeInitSystray
)
213 m_bInitialized
= false;
217 ShutdownIcon::ShutdownIcon( Reference
< XMultiServiceFactory
> aSMgr
) :
218 ShutdownIconServiceBase( m_aMutex
),
220 m_bListenForTermination ( false ),
223 m_xServiceManager( aSMgr
),
225 m_pDeInitSystray( 0 ),
227 m_bInitialized( false )
231 ShutdownIcon::~ShutdownIcon()
234 //Bustage on dlclosing when: no qstarter, start writer, enable, close writer, choose disable/quit
235 //dlclose gets called and pulls .so from under hack-tower
241 // ---------------------------------------------------------------------------
243 void ShutdownIcon::OpenURL( const ::rtl::OUString
& aURL
, const ::rtl::OUString
& rTarget
, const Sequence
< PropertyValue
>& aArgs
)
245 if ( getInstance() && getInstance()->m_xDesktop
.is() )
247 Reference
< XDispatchProvider
> xDispatchProvider( getInstance()->m_xDesktop
, UNO_QUERY
);
248 if ( xDispatchProvider
.is() )
250 com::sun::star::util::URL aDispatchURL
;
251 aDispatchURL
.Complete
= aURL
;
253 Reference
< com::sun::star::util::XURLTransformer
> xURLTransformer(
254 ::comphelper::getProcessServiceFactory()->createInstance( OUString::createFromAscii("com.sun.star.util.URLTransformer") ),
255 com::sun::star::uno::UNO_QUERY
);
256 if ( xURLTransformer
.is() )
260 Reference
< com::sun::star::frame::XDispatch
> xDispatch
;
262 xURLTransformer
->parseStrict( aDispatchURL
);
263 xDispatch
= xDispatchProvider
->queryDispatch( aDispatchURL
, rTarget
, 0 );
264 if ( xDispatch
.is() )
265 xDispatch
->dispatch( aDispatchURL
, aArgs
);
267 catch ( com::sun::star::uno::RuntimeException
& )
271 catch ( com::sun::star::uno::Exception
& )
279 // ---------------------------------------------------------------------------
281 void ShutdownIcon::FileOpen()
283 if ( getInstance() && getInstance()->m_xDesktop
.is() )
285 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
287 getInstance()->StartFileDialog();
291 // ---------------------------------------------------------------------------
293 void ShutdownIcon::FromTemplate()
295 if ( getInstance() && getInstance()->m_xDesktop
.is() )
297 Reference
< ::com::sun::star::frame::XFramesSupplier
> xDesktop ( getInstance()->m_xDesktop
, UNO_QUERY
);
298 Reference
< ::com::sun::star::frame::XFrame
> xFrame( xDesktop
->getActiveFrame() );
300 xFrame
= Reference
< ::com::sun::star::frame::XFrame
>( xDesktop
, UNO_QUERY
);
303 aTargetURL
.Complete
= OUString( RTL_CONSTASCII_USTRINGPARAM( "slot:5500" ) );
304 Reference
< XURLTransformer
> xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY
);
305 xTrans
->parseStrict( aTargetURL
);
307 Reference
< ::com::sun::star::frame::XDispatchProvider
> xProv( xFrame
, UNO_QUERY
);
308 Reference
< ::com::sun::star::frame::XDispatch
> xDisp
;
311 if ( aTargetURL
.Protocol
.compareToAscii("slot:") == COMPARE_EQUAL
)
312 xDisp
= xProv
->queryDispatch( aTargetURL
, ::rtl::OUString(), 0 );
314 xDisp
= xProv
->queryDispatch( aTargetURL
, ::rtl::OUString::createFromAscii("_blank"), 0 );
318 Sequence
<PropertyValue
> aArgs(1);
319 PropertyValue
* pArg
= aArgs
.getArray();
320 pArg
[0].Name
= rtl::OUString::createFromAscii("Referer");
321 pArg
[0].Value
<<= ::rtl::OUString::createFromAscii("private:user");
322 Reference
< ::com::sun::star::frame::XNotifyingDispatch
> xNotifyer( xDisp
, UNO_QUERY
);
323 if ( xNotifyer
.is() )
326 xNotifyer
->dispatchWithNotification( aTargetURL
, aArgs
, new SfxNotificationListener_Impl() );
329 xDisp
->dispatch( aTargetURL
, aArgs
);
334 // ---------------------------------------------------------------------------
335 #include <tools/rcid.h>
336 OUString
ShutdownIcon::GetResString( int id
)
338 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
341 m_pResMgr
= SfxResId::GetResMgr();
342 ResId
aResId( id
, *m_pResMgr
);
343 aResId
.SetRT( RSC_STRING
);
344 if( !m_pResMgr
|| !m_pResMgr
->IsAvailable( aResId
) )
347 UniString
aRes( ResId(id
, *m_pResMgr
) );
348 return OUString( aRes
);
351 // ---------------------------------------------------------------------------
353 OUString
ShutdownIcon::GetUrlDescription( const OUString
& aUrl
)
355 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
357 return OUString( SvFileInformationManager::GetDescription( INetURLObject( aUrl
) ) );
360 // ---------------------------------------------------------------------------
362 void ShutdownIcon::StartFileDialog()
364 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
367 m_pFileDlg
= new FileDialogHelper( WB_OPEN
| SFXWB_MULTISELECTION
, String() );
368 m_pFileDlg
->StartExecuteModal( STATIC_LINK( this, ShutdownIcon
, DialogClosedHdl_Impl
) );
371 // ---------------------------------------------------------------------------
373 IMPL_STATIC_LINK( ShutdownIcon
, DialogClosedHdl_Impl
, FileDialogHelper
*, EMPTYARG
)
375 DBG_ASSERT( pThis
->m_pFileDlg
, "ShutdownIcon, DialogClosedHdl_Impl(): no file dialog" );
377 // use ctor for filling up filters automatically! #89169#
378 if ( ERRCODE_NONE
== pThis
->m_pFileDlg
->GetError() )
380 Reference
< XFilePicker
> xPicker
= pThis
->m_pFileDlg
->GetFilePicker();
388 Reference
< XFilePickerControlAccess
> xPickerControls ( xPicker
, UNO_QUERY
);
389 Reference
< XFilterManager
> xFilterManager ( xPicker
, UNO_QUERY
);
391 Sequence
< OUString
> sFiles
= xPicker
->getFiles();
392 int nFiles
= sFiles
.getLength();
395 Sequence
< PropertyValue
> aArgs(3);
397 Reference
< com::sun::star::task::XInteractionHandler
> xInteraction(
398 ::comphelper::getProcessServiceFactory()->createInstance( OUString::createFromAscii("com.sun.star.task.InteractionHandler") ),
399 com::sun::star::uno::UNO_QUERY
);
401 aArgs
[0].Name
= OUString::createFromAscii( "InteractionHandler" );
402 aArgs
[0].Value
<<= xInteraction
;
404 sal_Int16 nMacroExecMode
= ::com::sun::star::document::MacroExecMode::USE_CONFIG
;
405 aArgs
[1].Name
= OUString::createFromAscii( "MacroExecutionMode" );
406 aArgs
[1].Value
<<= nMacroExecMode
;
408 sal_Int16 nUpdateDoc
= ::com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG
;
409 aArgs
[2].Name
= OUString::createFromAscii( "UpdateDocMode" );
410 aArgs
[2].Value
<<= nUpdateDoc
;
412 // pb: #102643# use the filedlghelper to get the current filter name,
413 // because it removes the extensions before you get the filter name.
414 OUString
aFilterName( pThis
->m_pFileDlg
->GetCurrentFilter() );
416 if ( xPickerControls
.is() )
421 sal_Bool bReadOnly
= sal_False
;
424 xPickerControls
->getValue( ExtendedFilePickerElementIds::CHECKBOX_READONLY
, 0 ) >>= bReadOnly
;
426 // #95239#: Only set porperty if readonly is set to TRUE
430 aArgs
.realloc( ++nArgs
);
431 aArgs
[nArgs
-1].Name
= OUString::createFromAscii( "ReadOnly" );
432 aArgs
[nArgs
-1].Value
<<= bReadOnly
;
435 // Get version string
437 sal_Int32 iVersion
= -1;
439 xPickerControls
->getValue( ExtendedFilePickerElementIds::LISTBOX_VERSION
, ControlActions::GET_SELECTED_ITEM_INDEX
) >>= iVersion
;
443 sal_Int16 uVersion
= (sal_Int16
)iVersion
;
445 aArgs
.realloc( ++nArgs
);
446 aArgs
[nArgs
-1].Name
= OUString::createFromAscii( "Version" );
447 aArgs
[nArgs
-1].Value
<<= uVersion
;
450 // Retrieve the current filter
452 if ( !aFilterName
.getLength() )
453 xPickerControls
->getValue( CommonFilePickerElementIds::LISTBOX_FILTER
, ControlActions::GET_SELECTED_ITEM
) >>= aFilterName
;
458 // Convert UI filter name to internal filter name
460 if ( aFilterName
.getLength() )
462 const SfxFilter
* pFilter
= SFX_APP()->GetFilterMatcher().GetFilter4UIName( aFilterName
, 0, SFX_FILTER_NOTINFILEDLG
);
466 aFilterName
= pFilter
->GetFilterName();
468 if ( aFilterName
.getLength() )
470 aArgs
.realloc( ++nArgs
);
471 aArgs
[nArgs
-1].Name
= OUString::createFromAscii( "FilterName" );
472 aArgs
[nArgs
-1].Value
<<= aFilterName
;
478 OpenURL( sFiles
[0], OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ), aArgs
);
481 OUString aBaseDirURL
= sFiles
[0];
482 if ( aBaseDirURL
.getLength() > 0 && aBaseDirURL
[aBaseDirURL
.getLength()-1] != '/' )
483 aBaseDirURL
+= OUString::createFromAscii("/");
486 for ( iFiles
= 1; iFiles
< nFiles
; iFiles
++ )
488 OUString aURL
= aBaseDirURL
;
489 aURL
+= sFiles
[iFiles
];
490 OpenURL( aURL
, OUString( RTL_CONSTASCII_USTRINGPARAM( "_default" ) ), aArgs
);
501 // #103346 Destroy dialog to prevent problems with custom controls
502 delete pThis
->m_pFileDlg
;
503 pThis
->m_pFileDlg
= NULL
;
510 // ---------------------------------------------------------------------------
512 void ShutdownIcon::addTerminateListener()
514 ShutdownIcon
* pInst
= getInstance();
518 if (pInst
->m_bListenForTermination
)
521 Reference
< XDesktop
> xDesktop
= pInst
->m_xDesktop
;
522 if ( ! xDesktop
.is())
525 xDesktop
->addTerminateListener( pInst
);
526 pInst
->m_bListenForTermination
= true;
529 // ---------------------------------------------------------------------------
531 void ShutdownIcon::terminateDesktop()
533 ShutdownIcon
* pInst
= getInstance();
537 Reference
< XDesktop
> xDesktop
= pInst
->m_xDesktop
;
538 if ( ! xDesktop
.is())
541 // always remove ourselves as listener
542 xDesktop
->removeTerminateListener( pInst
);
543 pInst
->m_bListenForTermination
= true;
545 // terminate desktop only if no tasks exist
546 Reference
< XFramesSupplier
> xSupplier( xDesktop
, UNO_QUERY
);
547 if ( xSupplier
.is() )
549 Reference
< XIndexAccess
> xTasks ( xSupplier
->getFrames(), UNO_QUERY
);
552 if( xTasks
->getCount() < 1 )
553 xDesktop
->terminate();
557 // remove the instance pointer
558 ShutdownIcon::pShutdownIcon
= 0;
561 // ---------------------------------------------------------------------------
563 ShutdownIcon
* ShutdownIcon::getInstance()
565 OSL_ASSERT( pShutdownIcon
);
566 return pShutdownIcon
;
569 // ---------------------------------------------------------------------------
571 ShutdownIcon
* ShutdownIcon::createInstance()
574 return pShutdownIcon
;
576 ShutdownIcon
*pIcon
= NULL
;
578 Reference
< XMultiServiceFactory
> xSMgr( comphelper::getProcessServiceFactory() );
579 pIcon
= new ShutdownIcon( xSMgr
);
581 pShutdownIcon
= pIcon
;
586 return pShutdownIcon
;
589 void ShutdownIcon::init() throw( ::com::sun::star::uno::Exception
)
591 // access resource system and sfx only protected by solarmutex
592 vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
593 ResMgr
*pResMgr
= SfxResId::GetResMgr();
595 ::osl::ResettableMutexGuard
aGuard( m_aMutex
);
598 Reference
< XDesktop
> xDesktop( m_xServiceManager
->createInstance(
599 DEFINE_CONST_UNICODE( "com.sun.star.frame.Desktop" )),
602 m_xDesktop
= xDesktop
;
605 // ---------------------------------------------------------------------------
607 void SAL_CALL
ShutdownIcon::disposing()
609 m_xServiceManager
= Reference
< XMultiServiceFactory
>();
610 m_xDesktop
= Reference
< XDesktop
>();
613 // ---------------------------------------------------------------------------
616 void SAL_CALL
ShutdownIcon::disposing( const ::com::sun::star::lang::EventObject
& )
617 throw(::com::sun::star::uno::RuntimeException
)
621 // ---------------------------------------------------------------------------
623 // XTerminateListener
624 void SAL_CALL
ShutdownIcon::queryTermination( const ::com::sun::star::lang::EventObject
& )
625 throw(::com::sun::star::frame::TerminationVetoException
, ::com::sun::star::uno::RuntimeException
)
627 ::osl::ClearableMutexGuard
aGuard( m_aMutex
);
630 throw ::com::sun::star::frame::TerminationVetoException();
634 // ---------------------------------------------------------------------------
636 void SAL_CALL
ShutdownIcon::notifyTermination( const ::com::sun::star::lang::EventObject
& )
637 throw(::com::sun::star::uno::RuntimeException
)
642 // ---------------------------------------------------------------------------
644 void SAL_CALL
ShutdownIcon::initialize( const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& aArguments
)
645 throw( ::com::sun::star::uno::Exception
)
647 ::osl::ResettableMutexGuard
aGuard( m_aMutex
);
649 // third argument only sets veto, everything else will be ignored!
650 if (aArguments
.getLength() > 2)
652 sal_Bool bVeto
= sal_True
;
653 bVeto
= ::cppu::any2bool(aArguments
[2]);
658 if ( aArguments
.getLength() > 0 )
660 if ( !ShutdownIcon::pShutdownIcon
)
664 sal_Bool bQuickstart
= sal_False
;
665 bQuickstart
= ::cppu::any2bool( aArguments
[0] );
666 if( !bQuickstart
&& !GetAutostart() )
671 if ( !m_xDesktop
.is() )
674 /* Create a sub-classed instance - foo */
675 ShutdownIcon::pShutdownIcon
= this;
678 // above win32 starts the quickstart thread, but we have
679 // quickstart running only when -quickstart is specified
680 // on command line (next boot).
681 // so if -quickstart was not specified, we cannot issue
682 // quickstart veto on shutdown.
686 ShutdownIcon::getInstance()->SetVeto( true );
687 ShutdownIcon::getInstance()->addTerminateListener();
691 catch(const ::com::sun::star::lang::IllegalArgumentException
&)
696 if ( aArguments
.getLength() > 1 )
698 sal_Bool bAutostart
= sal_False
;
699 bAutostart
= ::cppu::any2bool( aArguments
[1] );
700 if (bAutostart
&& !GetAutostart())
701 SetAutostart( sal_True
);
702 if (!bAutostart
&& GetAutostart())
703 SetAutostart( sal_False
);
708 // -------------------------------
710 void ShutdownIcon::EnterModalMode()
715 // -------------------------------
717 void ShutdownIcon::LeaveModalMode()
723 // defined in shutdowniconw32.cxx
725 // defined in shutdowniconOs2.cxx
727 // defined in shutdowniconaqua.cxx
729 bool ShutdownIcon::IsQuickstarterInstalled()
731 #ifndef ENABLE_QUICKSTART_APPLET
733 #else // !ENABLE_QUICKSTART_APPLET
735 return LoadModule( NULL
, NULL
, NULL
);
737 #endif // !ENABLE_QUICKSTART_APPLET
741 // ---------------------------------------------------------------------------
743 #if defined (ENABLE_QUICKSTART_APPLET) && defined (UNX)
744 static OUString
getDotAutostart( bool bCreate
= false )
747 const char *pConfigHome
;
748 if( (pConfigHome
= getenv("XDG_CONFIG_HOME") ) )
749 aShortcut
= OStringToOUString( OString( pConfigHome
), RTL_TEXTENCODING_UTF8
);
753 osl::Security().getHomeDir( aHomeURL
);
754 ::osl::File::getSystemPathFromFileURL( aHomeURL
, aShortcut
);
755 aShortcut
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "/.config" ) );
757 aShortcut
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "/autostart" ) );
760 OUString aShortcutUrl
;
761 osl::File::getFileURLFromSystemPath( aShortcut
, aShortcutUrl
);
762 osl::Directory::createPath( aShortcutUrl
);
768 rtl::OUString
ShutdownIcon::getShortcutName()
770 #ifndef ENABLE_QUICKSTART_APPLET
774 OUString
aShortcutName( RTL_CONSTASCII_USTRINGPARAM( "StarOffice 6.0" ) );
775 ResMgr
* pMgr
= SfxResId::GetResMgr();
778 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
779 UniString
aRes( SfxResId( STR_QUICKSTART_LNKNAME
) );
780 aShortcutName
= OUString( aRes
);
783 aShortcutName
+= OUString( RTL_CONSTASCII_USTRINGPARAM( ".lnk" ) );
785 OUString
aShortcut(GetAutostartFolderNameW32());
786 aShortcut
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "\\" ) );
787 aShortcut
+= aShortcutName
;
789 OUString aShortcut
= getDotAutostart();
790 aShortcut
+= OUString( RTL_CONSTASCII_USTRINGPARAM( "/qstart.desktop" ) );
793 #endif // ENABLE_QUICKSTART_APPLET
796 bool ShutdownIcon::GetAutostart( )
799 return GetAutostartOs2( );
804 #ifdef ENABLE_QUICKSTART_APPLET
805 OUString
aShortcut( getShortcutName() );
806 OUString aShortcutUrl
;
807 osl::File::getFileURLFromSystemPath( aShortcut
, aShortcutUrl
);
808 osl::File
f( aShortcutUrl
);
809 osl::File::RC error
= f
.open( OpenFlag_Read
);
810 if( error
== osl::File::E_None
)
815 #endif // ENABLE_QUICKSTART_APPLET
820 void ShutdownIcon::SetAutostart( bool bActivate
)
822 #ifdef ENABLE_QUICKSTART_APPLET
823 OUString
aShortcut( getShortcutName() );
825 if( bActivate
&& IsQuickstarterInstalled() )
828 EnableAutostartW32( aShortcut
);
830 getDotAutostart( true );
832 OUString
aPath( RTL_CONSTASCII_USTRINGPARAM("${BRAND_BASE_DIR}/share/xdg/qstart.desktop" ) );
833 Bootstrap::expandMacros( aPath
);
835 OUString aDesktopFile
;
836 ::osl::File::getSystemPathFromFileURL( aPath
, aDesktopFile
);
838 OString aDesktopFileUnx
= OUStringToOString( aDesktopFile
,
839 osl_getThreadTextEncoding() );
840 OString aShortcutUnx
= OUStringToOString( aShortcut
,
841 osl_getThreadTextEncoding() );
842 if ((0 != symlink(aDesktopFileUnx
, aShortcutUnx
)) && (errno
== EEXIST
))
844 unlink(aShortcutUnx
);
845 symlink(aDesktopFileUnx
, aShortcutUnx
);
848 ShutdownIcon
*pIcon
= ShutdownIcon::createInstance();
850 pIcon
->initSystray();
855 OUString aShortcutUrl
;
856 ::osl::File::getFileURLFromSystemPath( aShortcut
, aShortcutUrl
);
857 ::osl::File::remove( aShortcutUrl
);
859 ShutdownIcon
*pIcon
= getInstance();
861 pIcon
->deInitSystray();
865 SetAutostartOs2( bActivate
);
867 (void)bActivate
; // unused variable
868 #endif // ENABLE_QUICKSTART_APPLET
871 static const ::sal_Int32 PROPHANDLE_TERMINATEVETOSTATE
= 0;
874 void SAL_CALL
ShutdownIcon::setFastPropertyValue( ::sal_Int32 nHandle
,
875 const ::com::sun::star::uno::Any
& aValue
)
876 throw (::com::sun::star::beans::UnknownPropertyException
,
877 ::com::sun::star::beans::PropertyVetoException
,
878 ::com::sun::star::lang::IllegalArgumentException
,
879 ::com::sun::star::lang::WrappedTargetException
,
880 ::com::sun::star::uno::RuntimeException
)
884 case PROPHANDLE_TERMINATEVETOSTATE
:
886 // use new value in case it's a valid information only
887 ::sal_Bool
bState( sal_False
);
888 if (! (aValue
>>= bState
))
892 if (m_bVeto
&& ! m_bListenForTermination
)
893 addTerminateListener();
898 throw ::com::sun::star::beans::UnknownPropertyException();
903 ::com::sun::star::uno::Any SAL_CALL
ShutdownIcon::getFastPropertyValue( ::sal_Int32 nHandle
)
904 throw (::com::sun::star::beans::UnknownPropertyException
,
905 ::com::sun::star::lang::WrappedTargetException
,
906 ::com::sun::star::uno::RuntimeException
)
908 ::com::sun::star::uno::Any aValue
;
911 case PROPHANDLE_TERMINATEVETOSTATE
:
913 bool bState
= (m_bListenForTermination
&& m_bVeto
);
919 throw ::com::sun::star::beans::UnknownPropertyException();