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