1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_folders.h>
22 #include <shutdownicon.hxx>
24 #include <sfx2/app.hxx>
25 #include <osl/mutex.hxx>
26 #include <svtools/imagemgr.hxx>
27 #include <svtools/miscopt.hxx>
28 #include <com/sun/star/task/InteractionHandler.hpp>
29 #include <com/sun/star/frame/Desktop.hpp>
30 #include <com/sun/star/frame/XDispatchResultListener.hpp>
31 #include <com/sun/star/frame/XNotifyingDispatch.hpp>
32 #include <com/sun/star/frame/XFramesSupplier.hpp>
33 #include <com/sun/star/frame/XComponentLoader.hpp>
34 #include <com/sun/star/frame/XFrame.hpp>
35 #include <com/sun/star/util/URLTransformer.hpp>
36 #include <com/sun/star/util/XURLTransformer.hpp>
37 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
38 #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
39 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
40 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
41 #include <com/sun/star/ui/dialogs/CommonFilePickerElementIds.hpp>
42 #include <com/sun/star/ui/dialogs/ControlActions.hpp>
43 #include <com/sun/star/document/MacroExecMode.hpp>
44 #include <com/sun/star/document/UpdateDocMode.hpp>
45 #include <sfx2/filedlghelper.hxx>
46 #include <sfx2/fcontnr.hxx>
47 #include <comphelper/processfactory.hxx>
48 #include <cppuhelper/compbase1.hxx>
49 #include <sfx2/dispatch.hxx>
50 #include <comphelper/extract.hxx>
51 #include <tools/urlobj.hxx>
52 #include <osl/security.hxx>
53 #include <osl/file.hxx>
54 #include <rtl/bootstrap.hxx>
55 #include <rtl/ustrbuf.hxx>
56 #ifdef UNX // need symlink
60 #include <vcl/timer.hxx>
62 #include <sfx2/sfxresid.hxx>
64 using namespace ::com::sun::star
;
65 using namespace ::com::sun::star::uno
;
66 using namespace ::com::sun::star::frame
;
67 using namespace ::com::sun::star::container
;
68 using namespace ::com::sun::star::io
;
69 using namespace ::com::sun::star::lang
;
70 using namespace ::com::sun::star::beans
;
71 using namespace ::com::sun::star::util
;
72 using namespace ::com::sun::star::ui::dialogs
;
75 using namespace ::rtl
;
77 using namespace ::sfx2
;
79 #ifdef ENABLE_QUICKSTART_APPLET
80 # if !defined(WIN32) && !defined(MACOSX)
81 extern "C" { static void SAL_CALL
thisModule() {} }
85 #if defined(UNX) && defined(ENABLE_SYSTRAY_GTK) && !defined(PLUGIN_NAME)
86 #define PLUGIN_NAME "libqstart_gtklo.so"
89 class SfxNotificationListener_Impl
: public cppu::WeakImplHelper1
< XDispatchResultListener
>
92 virtual void SAL_CALL
dispatchFinished( const DispatchResultEvent
& aEvent
) throw( RuntimeException
);
93 virtual void SAL_CALL
disposing( const EventObject
& aEvent
) throw( RuntimeException
);
96 void SAL_CALL
SfxNotificationListener_Impl::dispatchFinished( const DispatchResultEvent
& ) throw( RuntimeException
)
98 ShutdownIcon::LeaveModalMode();
101 void SAL_CALL
SfxNotificationListener_Impl::disposing( const EventObject
& ) throw( RuntimeException
)
105 SFX_IMPL_XSERVICEINFO_CTX( ShutdownIcon
, "com.sun.star.office.Quickstart", "com.sun.star.comp.desktop.QuickstartWrapper" ) \
106 SFX_IMPL_ONEINSTANCEFACTORY( ShutdownIcon
);
108 bool ShutdownIcon::bModalMode
= false;
109 ShutdownIcon
* ShutdownIcon::pShutdownIcon
= NULL
;
111 #if !defined( ENABLE_QUICKSTART_APPLET ) || defined( UNX )
112 // To remove conditionals
114 static void disabled_initSystray() { }
115 static void disabled_deInitSystray() { }
119 bool ShutdownIcon::LoadModule( osl::Module
**pModule
,
120 oslGenericFunction
*pInit
,
121 oslGenericFunction
*pDeInit
)
125 OSL_ASSERT ( pInit
&& pDeInit
);
126 *pInit
= *pDeInit
= NULL
;
130 #ifdef ENABLE_QUICKSTART_APPLET
134 *pInit
= win32_init_sys_tray
;
135 *pDeInit
= win32_shutdown_sys_tray
;
138 # elif defined MACOSX
139 *pInit
= aqua_init_systray
;
140 *pDeInit
= aqua_shutdown_systray
;
143 osl::Module
*pPlugin
;
144 pPlugin
= new osl::Module();
146 oslGenericFunction pTmpInit
= NULL
;
147 oslGenericFunction pTmpDeInit
= NULL
;
149 #define DOSTRING( x ) #x
150 #define STRING( x ) DOSTRING( x )
152 if ( pPlugin
->loadRelative( &thisModule
, OUString (STRING( PLUGIN_NAME
) ) ) )
154 pTmpInit
= pPlugin
->getFunctionSymbol(
155 OUString( "plugin_init_sys_tray" ) );
156 pTmpDeInit
= pPlugin
->getFunctionSymbol(
157 OUString( "plugin_shutdown_sys_tray" ) );
159 if ( !pTmpInit
|| !pTmpDeInit
)
168 *pDeInit
= pTmpDeInit
;
172 bool bRet
= pPlugin
!= NULL
;
177 #endif // ENABLE_QUICKSTART_APPLET
179 #if !defined( ENABLE_QUICKSTART_APPLET ) || defined( UNX )
180 // Avoid unreachable code. In the ENABLE_QUICKSTART_APPLET && !UNX
181 // case, we have already returned.
185 *pInit
= disabled_initSystray
;
187 *pDeInit
= disabled_deInitSystray
;
191 #endif // !ENABLE_QUICKSTART_APPLET || UNX
194 // These two timeouts are necessary to avoid there being
195 // plugin frames still on the stack, after unloading that
196 // code, causing a crash during disabling / termination.
197 class IdleUnloader
: Timer
199 ::osl::Module
*m_pModule
;
201 IdleUnloader (::osl::Module
**pModule
) :
207 virtual void Timeout()
214 class IdleTerminate
: Timer
216 Reference
< XDesktop2
> m_xDesktop
;
218 IdleTerminate (Reference
< XDesktop2
> xDesktop
)
220 m_xDesktop
= xDesktop
;
223 virtual void Timeout()
225 m_xDesktop
->terminate();
230 void ShutdownIcon::initSystray()
234 m_bInitialized
= true;
236 (void) LoadModule( &m_pPlugin
, &m_pInitSystray
, &m_pDeInitSystray
);
241 void ShutdownIcon::deInitSystray()
246 if (m_pDeInitSystray
)
251 m_pDeInitSystray
= 0;
252 new IdleUnloader (&m_pPlugin
);
256 m_bInitialized
= false;
260 ShutdownIcon::ShutdownIcon( const Reference
< XComponentContext
> & rxContext
) :
261 ShutdownIconServiceBase( m_aMutex
),
263 m_bListenForTermination ( false ),
264 m_bSystemDialogs( false ),
267 m_xContext( rxContext
),
269 m_pDeInitSystray( 0 ),
271 m_bInitialized( false )
273 m_bSystemDialogs
= SvtMiscOptions().UseSystemFileDialog();
276 ShutdownIcon::~ShutdownIcon()
279 new IdleUnloader (&m_pPlugin
);
282 // ---------------------------------------------------------------------------
284 void ShutdownIcon::OpenURL( const OUString
& aURL
, const OUString
& rTarget
, const Sequence
< PropertyValue
>& aArgs
)
286 if ( getInstance() && getInstance()->m_xDesktop
.is() )
288 Reference
< XDispatchProvider
> xDispatchProvider( getInstance()->m_xDesktop
, UNO_QUERY
);
289 if ( xDispatchProvider
.is() )
291 com::sun::star::util::URL aDispatchURL
;
292 aDispatchURL
.Complete
= aURL
;
294 Reference
< util::XURLTransformer
> xURLTransformer( util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
297 Reference
< com::sun::star::frame::XDispatch
> xDispatch
;
299 xURLTransformer
->parseStrict( aDispatchURL
);
300 xDispatch
= xDispatchProvider
->queryDispatch( aDispatchURL
, rTarget
, 0 );
301 if ( xDispatch
.is() )
302 xDispatch
->dispatch( aDispatchURL
, aArgs
);
304 catch ( com::sun::star::uno::RuntimeException
& )
308 catch ( com::sun::star::uno::Exception
& )
315 // ---------------------------------------------------------------------------
317 void ShutdownIcon::FileOpen()
319 if ( getInstance() && getInstance()->m_xDesktop
.is() )
321 ::SolarMutexGuard aGuard
;
323 getInstance()->StartFileDialog();
327 // ---------------------------------------------------------------------------
329 void ShutdownIcon::FromTemplate()
331 if ( getInstance() && getInstance()->m_xDesktop
.is() )
333 Reference
< ::com::sun::star::frame::XFramesSupplier
> xDesktop ( getInstance()->m_xDesktop
, UNO_QUERY
);
334 Reference
< ::com::sun::star::frame::XFrame
> xFrame( xDesktop
->getActiveFrame() );
336 xFrame
= Reference
< ::com::sun::star::frame::XFrame
>( xDesktop
, UNO_QUERY
);
339 aTargetURL
.Complete
= "slot:5500";
340 Reference
< util::XURLTransformer
> xTrans( util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
341 xTrans
->parseStrict( aTargetURL
);
343 Reference
< ::com::sun::star::frame::XDispatchProvider
> xProv( xFrame
, UNO_QUERY
);
344 Reference
< ::com::sun::star::frame::XDispatch
> xDisp
;
347 if (aTargetURL
.Protocol
== "slot:")
348 xDisp
= xProv
->queryDispatch( aTargetURL
, OUString(), 0 );
350 xDisp
= xProv
->queryDispatch( aTargetURL
, OUString("_blank"), 0 );
354 Sequence
<PropertyValue
> aArgs(1);
355 PropertyValue
* pArg
= aArgs
.getArray();
356 pArg
[0].Name
= "Referer";
357 pArg
[0].Value
<<= OUString("private:user");
358 Reference
< ::com::sun::star::frame::XNotifyingDispatch
> xNotifyer( xDisp
, UNO_QUERY
);
359 if ( xNotifyer
.is() )
362 xNotifyer
->dispatchWithNotification( aTargetURL
, aArgs
, new SfxNotificationListener_Impl() );
365 xDisp
->dispatch( aTargetURL
, aArgs
);
370 // ---------------------------------------------------------------------------
371 #include <tools/rcid.h>
372 OUString
ShutdownIcon::GetResString( int id
)
374 ::SolarMutexGuard aGuard
;
377 m_pResMgr
= SfxResId::GetResMgr();
378 ResId
aResId( id
, *m_pResMgr
);
379 aResId
.SetRT( RSC_STRING
);
380 if( !m_pResMgr
|| !m_pResMgr
->IsAvailable( aResId
) )
383 return ResId(id
, *m_pResMgr
).toString();
386 // ---------------------------------------------------------------------------
388 OUString
ShutdownIcon::GetUrlDescription( const OUString
& aUrl
)
390 ::SolarMutexGuard aGuard
;
392 return OUString( SvFileInformationManager::GetDescription( INetURLObject( aUrl
) ) );
395 // ---------------------------------------------------------------------------
397 void ShutdownIcon::StartFileDialog()
399 ::SolarMutexGuard aGuard
;
401 bool bDirty
= ( m_bSystemDialogs
!= static_cast<bool>(SvtMiscOptions().UseSystemFileDialog()) );
403 if ( m_pFileDlg
&& bDirty
)
405 // Destroy instance as changing the system file dialog setting
406 // forces us to create a new FileDialogHelper instance!
412 m_pFileDlg
= new FileDialogHelper(
413 ui::dialogs::TemplateDescription::FILEOPEN_READONLY_VERSION
,
414 SFXWB_MULTISELECTION
, OUString() );
415 m_pFileDlg
->StartExecuteModal( STATIC_LINK( this, ShutdownIcon
, DialogClosedHdl_Impl
) );
418 // ---------------------------------------------------------------------------
420 IMPL_STATIC_LINK( ShutdownIcon
, DialogClosedHdl_Impl
, FileDialogHelper
*, EMPTYARG
)
422 DBG_ASSERT( pThis
->m_pFileDlg
, "ShutdownIcon, DialogClosedHdl_Impl(): no file dialog" );
424 // use constructor for filling up filters automatically!
425 if ( ERRCODE_NONE
== pThis
->m_pFileDlg
->GetError() )
427 Reference
< XFilePicker
> xPicker
= pThis
->m_pFileDlg
->GetFilePicker();
435 Reference
< XFilePickerControlAccess
> xPickerControls ( xPicker
, UNO_QUERY
);
436 Reference
< XFilterManager
> xFilterManager ( xPicker
, UNO_QUERY
);
438 Sequence
< OUString
> sFiles
= xPicker
->getFiles();
439 int nFiles
= sFiles
.getLength();
442 Sequence
< PropertyValue
> aArgs(3);
444 Reference
< com::sun::star::task::XInteractionHandler2
> xInteraction(
445 task::InteractionHandler::createWithParent(::comphelper::getProcessComponentContext(), 0) );
447 aArgs
[0].Name
= "InteractionHandler";
448 aArgs
[0].Value
<<= xInteraction
;
450 sal_Int16 nMacroExecMode
= ::com::sun::star::document::MacroExecMode::USE_CONFIG
;
451 aArgs
[1].Name
= "MacroExecutionMode";
452 aArgs
[1].Value
<<= nMacroExecMode
;
454 sal_Int16 nUpdateDoc
= ::com::sun::star::document::UpdateDocMode::ACCORDING_TO_CONFIG
;
455 aArgs
[2].Name
= "UpdateDocMode";
456 aArgs
[2].Value
<<= nUpdateDoc
;
458 // use the filedlghelper to get the current filter name,
459 // because it removes the extensions before you get the filter name.
460 OUString
aFilterName( pThis
->m_pFileDlg
->GetCurrentFilter() );
462 if ( xPickerControls
.is() )
467 sal_Bool bReadOnly
= sal_False
;
470 xPickerControls
->getValue( ExtendedFilePickerElementIds::CHECKBOX_READONLY
, 0 ) >>= bReadOnly
;
472 // Only set porperty if readonly is set to TRUE
476 aArgs
.realloc( ++nArgs
);
477 aArgs
[nArgs
-1].Name
= "ReadOnly";
478 aArgs
[nArgs
-1].Value
<<= bReadOnly
;
481 // Get version string
483 sal_Int32 iVersion
= -1;
485 xPickerControls
->getValue( ExtendedFilePickerElementIds::LISTBOX_VERSION
, ControlActions::GET_SELECTED_ITEM_INDEX
) >>= iVersion
;
489 sal_Int16 uVersion
= (sal_Int16
)iVersion
;
491 aArgs
.realloc( ++nArgs
);
492 aArgs
[nArgs
-1].Name
= "Version";
493 aArgs
[nArgs
-1].Value
<<= uVersion
;
496 // Retrieve the current filter
498 if ( aFilterName
.isEmpty() )
499 xPickerControls
->getValue( CommonFilePickerElementIds::LISTBOX_FILTER
, ControlActions::GET_SELECTED_ITEM
) >>= aFilterName
;
504 // Convert UI filter name to internal filter name
506 if ( !aFilterName
.isEmpty() )
508 const SfxFilter
* pFilter
= SFX_APP()->GetFilterMatcher().GetFilter4UIName( aFilterName
, 0, SFX_FILTER_NOTINFILEDLG
);
512 aFilterName
= pFilter
->GetFilterName();
514 if ( !aFilterName
.isEmpty() )
516 aArgs
.realloc( ++nArgs
);
517 aArgs
[nArgs
-1].Name
= "FilterName";
518 aArgs
[nArgs
-1].Value
<<= aFilterName
;
524 OpenURL( sFiles
[0], OUString( "_default" ), aArgs
);
527 OUString aBaseDirURL
= sFiles
[0];
528 if ( !aBaseDirURL
.isEmpty() && !aBaseDirURL
.endsWith("/") )
532 for ( iFiles
= 1; iFiles
< nFiles
; iFiles
++ )
534 OUString aURL
= aBaseDirURL
;
535 aURL
+= sFiles
[iFiles
];
536 OpenURL( aURL
, OUString( "_default" ), aArgs
);
547 // Destroy dialog to prevent problems with custom controls
548 // This fix is dependent on the dialog settings. Destroying the dialog here will
549 // crash the non-native dialog implementation! Therefore make this dependent on
551 if ( SvtMiscOptions().UseSystemFileDialog() )
553 delete pThis
->m_pFileDlg
;
554 pThis
->m_pFileDlg
= NULL
;
562 // ---------------------------------------------------------------------------
564 void ShutdownIcon::addTerminateListener()
566 ShutdownIcon
* pInst
= getInstance();
570 if (pInst
->m_bListenForTermination
)
573 Reference
< XDesktop2
> xDesktop
= pInst
->m_xDesktop
;
574 if ( ! xDesktop
.is())
577 xDesktop
->addTerminateListener( pInst
);
578 pInst
->m_bListenForTermination
= true;
581 // ---------------------------------------------------------------------------
583 void ShutdownIcon::terminateDesktop()
585 ShutdownIcon
* pInst
= getInstance();
589 Reference
< XDesktop2
> xDesktop
= pInst
->m_xDesktop
;
590 if ( ! xDesktop
.is())
593 // always remove ourselves as listener
594 pInst
->m_bListenForTermination
= true;
595 xDesktop
->removeTerminateListener( pInst
);
597 // terminate desktop only if no tasks exist
598 Reference
< XIndexAccess
> xTasks ( xDesktop
->getFrames(), UNO_QUERY
);
599 if( xTasks
.is() && xTasks
->getCount() < 1 )
600 new IdleTerminate( xDesktop
);
602 // remove the instance pointer
603 ShutdownIcon::pShutdownIcon
= 0;
606 // ---------------------------------------------------------------------------
608 ShutdownIcon
* ShutdownIcon::getInstance()
610 OSL_ASSERT( pShutdownIcon
);
611 return pShutdownIcon
;
614 // ---------------------------------------------------------------------------
616 ShutdownIcon
* ShutdownIcon::createInstance()
619 return pShutdownIcon
;
621 ShutdownIcon
*pIcon
= NULL
;
623 pIcon
= new ShutdownIcon( comphelper::getProcessComponentContext() );
625 pShutdownIcon
= pIcon
;
630 return pShutdownIcon
;
633 void ShutdownIcon::init() throw( ::com::sun::star::uno::Exception
)
635 // access resource system and sfx only protected by solarmutex
636 ::SolarMutexGuard aSolarGuard
;
637 ResMgr
*pResMgr
= SfxResId::GetResMgr();
639 ::osl::ResettableMutexGuard
aGuard( m_aMutex
);
642 Reference
< XDesktop2
> xDesktop
= Desktop::create( m_xContext
);
644 m_xDesktop
= xDesktop
;
647 // ---------------------------------------------------------------------------
649 void SAL_CALL
ShutdownIcon::disposing()
655 // ---------------------------------------------------------------------------
658 void SAL_CALL
ShutdownIcon::disposing( const ::com::sun::star::lang::EventObject
& )
659 throw(::com::sun::star::uno::RuntimeException
)
663 // ---------------------------------------------------------------------------
665 // XTerminateListener
666 void SAL_CALL
ShutdownIcon::queryTermination( const ::com::sun::star::lang::EventObject
& )
667 throw(::com::sun::star::frame::TerminationVetoException
, ::com::sun::star::uno::RuntimeException
)
669 SAL_INFO("sfx.appl", "ShutdownIcon::queryTermination: veto is " << m_bVeto
);
670 ::osl::ClearableMutexGuard
aGuard( m_aMutex
);
673 throw ::com::sun::star::frame::TerminationVetoException();
677 // ---------------------------------------------------------------------------
679 void SAL_CALL
ShutdownIcon::notifyTermination( const ::com::sun::star::lang::EventObject
& )
680 throw(::com::sun::star::uno::RuntimeException
)
685 // ---------------------------------------------------------------------------
687 void SAL_CALL
ShutdownIcon::initialize( const ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
>& aArguments
)
688 throw( ::com::sun::star::uno::Exception
)
690 ::osl::ResettableMutexGuard
aGuard( m_aMutex
);
692 // third argument only sets veto, everything else will be ignored!
693 if (aArguments
.getLength() > 2)
695 sal_Bool bVeto
= sal_True
;
696 bVeto
= ::cppu::any2bool(aArguments
[2]);
701 if ( aArguments
.getLength() > 0 )
703 if ( !ShutdownIcon::pShutdownIcon
)
707 sal_Bool bQuickstart
= sal_False
;
708 bQuickstart
= ::cppu::any2bool( aArguments
[0] );
709 if( !bQuickstart
&& !GetAutostart() )
714 if ( !m_xDesktop
.is() )
717 /* Create a sub-classed instance - foo */
718 ShutdownIcon::pShutdownIcon
= this;
721 catch(const ::com::sun::star::lang::IllegalArgumentException
&)
726 if ( aArguments
.getLength() > 1 )
728 sal_Bool bAutostart
= sal_False
;
729 bAutostart
= ::cppu::any2bool( aArguments
[1] );
730 if (bAutostart
&& !GetAutostart())
731 SetAutostart( sal_True
);
732 if (!bAutostart
&& GetAutostart())
733 SetAutostart( sal_False
);
738 // -------------------------------
740 void ShutdownIcon::EnterModalMode()
742 bModalMode
= sal_True
;
745 // -------------------------------
747 void ShutdownIcon::LeaveModalMode()
749 bModalMode
= sal_False
;
753 // defined in shutdowniconw32.cxx
755 // defined in shutdowniconaqua.cxx
757 bool ShutdownIcon::IsQuickstarterInstalled()
759 #ifndef ENABLE_QUICKSTART_APPLET
761 #else // !ENABLE_QUICKSTART_APPLET
763 return LoadModule( NULL
, NULL
, NULL
);
765 #endif // !ENABLE_QUICKSTART_APPLET
769 // ---------------------------------------------------------------------------
771 #if defined (ENABLE_QUICKSTART_APPLET) && defined (UNX)
773 * Return the XDG autostart directory.
774 * http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html
775 * Available in Unix and with Quickstart enabled.
776 * @param bCreate Create the directory if it does not exist yet.
777 * @return OUString containing the autostart directory path.
779 static OUString
getAutostartDir( bool bCreate
= false )
782 const char *pConfigHome
;
783 if( (pConfigHome
= getenv("XDG_CONFIG_HOME") ) )
784 aShortcut
= OStringToOUString( OString( pConfigHome
),
785 RTL_TEXTENCODING_UTF8
);
789 osl::Security().getHomeDir( aHomeURL
);
790 ::osl::File::getSystemPathFromFileURL( aHomeURL
, aShortcut
);
791 aShortcut
+= "/.config";
793 aShortcut
+= "/autostart";
796 OUString aShortcutUrl
;
797 osl::File::getFileURLFromSystemPath( aShortcut
, aShortcutUrl
);
798 osl::Directory::createPath( aShortcutUrl
);
804 OUString
ShutdownIcon::getShortcutName()
806 #ifndef ENABLE_QUICKSTART_APPLET
810 OUString
aShortcutName( "StarOffice 6.0" );
811 ResMgr
* pMgr
= SfxResId::GetResMgr();
814 ::SolarMutexGuard aGuard
;
815 aShortcutName
= SFX2_RESSTR(STR_QUICKSTART_LNKNAME
);
818 aShortcutName
+= ".lnk";
820 OUString
aShortcut(GetAutostartFolderNameW32());
822 aShortcut
+= aShortcutName
;
824 OUString aShortcut
= getAutostartDir();
825 aShortcut
+= "/qstart.desktop";
828 #endif // ENABLE_QUICKSTART_APPLET
831 bool ShutdownIcon::GetAutostart( )
837 #ifdef ENABLE_QUICKSTART_APPLET
838 OUString
aShortcut( getShortcutName() );
839 OUString aShortcutUrl
;
840 osl::File::getFileURLFromSystemPath( aShortcut
, aShortcutUrl
);
841 osl::File
f( aShortcutUrl
);
842 osl::File::RC error
= f
.open( osl_File_OpenFlag_Read
);
843 if( error
== osl::File::E_None
)
848 #endif // ENABLE_QUICKSTART_APPLET
853 void ShutdownIcon::SetAutostart( bool bActivate
)
855 #ifdef ENABLE_QUICKSTART_APPLET
856 OUString
aShortcut( getShortcutName() );
858 if( bActivate
&& IsQuickstarterInstalled() )
861 EnableAutostartW32( aShortcut
);
863 getAutostartDir( true );
865 OUString
aPath( "${BRAND_BASE_DIR}/" LIBO_SHARE_FOLDER
"/xdg/qstart.desktop" );
866 Bootstrap::expandMacros( aPath
);
868 OUString aDesktopFile
;
869 ::osl::File::getSystemPathFromFileURL( aPath
, aDesktopFile
);
871 OString aDesktopFileUnx
= OUStringToOString( aDesktopFile
,
872 osl_getThreadTextEncoding() );
873 OString aShortcutUnx
= OUStringToOString( aShortcut
,
874 osl_getThreadTextEncoding() );
875 if ((0 != symlink(aDesktopFileUnx
.getStr(), aShortcutUnx
.getStr())) && (errno
== EEXIST
))
877 unlink(aShortcutUnx
.getStr());
878 int ret
= symlink(aDesktopFileUnx
.getStr(), aShortcutUnx
.getStr());
879 (void)ret
; //deliberately ignore return value, it's non-critical if it fails
882 ShutdownIcon
*pIcon
= ShutdownIcon::createInstance();
884 pIcon
->initSystray();
889 OUString aShortcutUrl
;
890 ::osl::File::getFileURLFromSystemPath( aShortcut
, aShortcutUrl
);
891 ::osl::File::remove( aShortcutUrl
);
895 ShutdownIcon
*pIcon
= getInstance();
896 pIcon
->deInitSystray();
901 (void)bActivate
; // unused variable
902 #endif // ENABLE_QUICKSTART_APPLET
905 static const ::sal_Int32 PROPHANDLE_TERMINATEVETOSTATE
= 0;
908 void SAL_CALL
ShutdownIcon::setFastPropertyValue( ::sal_Int32 nHandle
,
909 const ::com::sun::star::uno::Any
& aValue
)
910 throw (::com::sun::star::beans::UnknownPropertyException
,
911 ::com::sun::star::beans::PropertyVetoException
,
912 ::com::sun::star::lang::IllegalArgumentException
,
913 ::com::sun::star::lang::WrappedTargetException
,
914 ::com::sun::star::uno::RuntimeException
)
918 case PROPHANDLE_TERMINATEVETOSTATE
:
920 // use new value in case it's a valid information only
921 ::sal_Bool
bState( sal_False
);
922 if (! (aValue
>>= bState
))
926 if (m_bVeto
&& ! m_bListenForTermination
)
927 addTerminateListener();
932 throw ::com::sun::star::beans::UnknownPropertyException();
937 ::com::sun::star::uno::Any SAL_CALL
ShutdownIcon::getFastPropertyValue( ::sal_Int32 nHandle
)
938 throw (::com::sun::star::beans::UnknownPropertyException
,
939 ::com::sun::star::lang::WrappedTargetException
,
940 ::com::sun::star::uno::RuntimeException
)
942 ::com::sun::star::uno::Any aValue
;
945 case PROPHANDLE_TERMINATEVETOSTATE
:
947 bool bState
= (m_bListenForTermination
&& m_bVeto
);
953 throw ::com::sun::star::beans::UnknownPropertyException();
959 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */