Update ooo320-m1
[ooovba.git] / desktop / unx / splash / unxsplash.cxx
blobca203349518d5bdc7b6650a3bed2305d463479ee
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile$
7 * $Revision: 7305 $
9 * last change: $Author: jholesovsky $ $Date: 2006-08-04 16:35:41 +0200 (Pá, 04 srp 2006) $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
34 ************************************************************************/
36 #include "unxsplash.hxx"
37 #include <stdio.h>
38 #ifndef _UTL_BOOTSTRAP_HXX
39 #include <unotools/bootstrap.hxx>
40 #endif
41 #ifndef _VOS_PROCESS_HXX_
42 #include <vos/process.hxx>
43 #endif
44 #ifndef _URLOBJ_HXX
45 #include <tools/urlobj.hxx>
46 #endif
47 #ifndef _STREAM_HXX
48 #include <tools/stream.hxx>
49 #endif
50 #ifndef _SFX_HRC
51 #include <sfx2/sfx.hrc>
52 #endif
54 #include <com/sun/star/registry/XRegistryKey.hpp>
55 #include <rtl/logfile.hxx>
56 #include <rtl/ustrbuf.hxx>
57 #include <rtl/math.hxx>
59 #define PIPE_ARG "-splash-pipe="
61 using namespace ::rtl;
62 using namespace ::com::sun::star::registry;
64 namespace desktop
67 UnxSplashScreen::UnxSplashScreen( const Reference< XMultiServiceFactory >& rSMgr )
68 : m_rFactory( rSMgr ),
69 m_pOutFd( NULL )
73 UnxSplashScreen::~UnxSplashScreen()
75 #if OSL_DEBUG_LEVEL > 1
76 fprintf( stderr, "UnxSplashScreen::~UnxSplashScreen()\n" );
77 #endif
79 if ( m_pOutFd )
81 fclose( m_pOutFd );
82 m_pOutFd = NULL;
86 void SAL_CALL UnxSplashScreen::start( const OUString& /*aText*/, sal_Int32 /*nRange*/ )
87 throw ( RuntimeException )
91 void SAL_CALL UnxSplashScreen::end()
92 throw ( RuntimeException )
94 #if OSL_DEBUG_LEVEL > 1
95 fprintf( stderr, "UnxSplashScreen::end()\n" );
96 #endif
98 fprintf( m_pOutFd, "end\n" );
99 fflush( m_pOutFd );
102 void SAL_CALL UnxSplashScreen::reset()
103 throw ( RuntimeException )
105 // TODO?
108 void SAL_CALL UnxSplashScreen::setText( const OUString& /*aText*/ )
109 throw ( RuntimeException )
111 // TODO?
114 void SAL_CALL UnxSplashScreen::setValue( sal_Int32 nValue )
115 throw ( RuntimeException )
117 if ( m_pOutFd )
119 fprintf( m_pOutFd, "%d%%\n", nValue );
120 fflush( m_pOutFd );
124 // XInitialize
125 void SAL_CALL
126 UnxSplashScreen::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any>& aArguments )
127 throw ( RuntimeException )
129 ::vos::OStartupInfo aInfo;
130 for ( sal_uInt32 i = 0; i < aInfo.getCommandArgCount(); i++ )
132 rtl::OUString aArg;
133 if ( aInfo.getCommandArg( i, aArg ) )
134 break;
135 if ( aArg.matchIgnoreAsciiCaseAsciiL( PIPE_ARG, sizeof( PIPE_ARG ) - 1, 0 ) )
137 OUString aNum = aArg.copy( sizeof( PIPE_ARG ) - 1 );
138 int fd = aNum.toInt32();
139 m_pOutFd = fdopen( fd, "w" );
140 #if OSL_DEBUG_LEVEL > 1
141 fprintf( stderr, "Got argument '-splash-pipe=%d ('%s') (%p)\n",
142 fd, (const sal_Char *)rtl::OUStringToOString( aNum, RTL_TEXTENCODING_UTF8 ),
143 m_pOutFd );
144 #endif
149 // get service instance...
150 UnxSplashScreen *UnxSplashScreen::m_pINSTANCE = NULL;
151 osl::Mutex UnxSplashScreen::m_aMutex;
153 Reference< XInterface > UnxSplashScreen::getInstance( const Reference< XMultiServiceFactory >& rSMgr )
155 if ( m_pINSTANCE == NULL )
157 osl::MutexGuard guard( m_aMutex );
158 if ( m_pINSTANCE == NULL )
159 return (XComponent*) new UnxSplashScreen( rSMgr );
162 return (XComponent*)NULL;
165 // static service info...
166 const char* UnxSplashScreen::interfaces[] =
168 "com.sun.star.task.XStartusIndicator",
169 "com.sun.star.lang.XInitialization",
170 NULL,
172 const sal_Char *UnxSplashScreen::serviceName = "com.sun.star.office.PipeSplashScreen";
173 const sal_Char *UnxSplashScreen::implementationName = "com.sun.star.office.comp.PipeSplashScreen";
174 const sal_Char *UnxSplashScreen::supportedServiceNames[] = { "com.sun.star.office.PipeSplashScreen", NULL };
176 OUString UnxSplashScreen::impl_getImplementationName()
178 return OUString::createFromAscii( implementationName );
181 Sequence<OUString> UnxSplashScreen::impl_getSupportedServiceNames()
183 Sequence<OUString> aSequence;
184 for ( int i = 0; supportedServiceNames[i] != NULL; i++ )
186 aSequence.realloc( i+1 );
187 aSequence[i] = OUString::createFromAscii( supportedServiceNames[i] );
189 return aSequence;