Update ooo320-m1
[ooovba.git] / desktop / source / so_comp / evaluation.cxx
blob3ecb2af318cc5c89d51ddfb432ada8213ca16bf3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: evaluation.cxx,v $
10 * $Revision: 1.10 $
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_desktop.hxx"
34 #include "evaluation.hxx"
35 #include <com/sun/star/beans/NamedValue.hpp>
36 #include <com/sun/star/registry/XRegistryKey.hpp>
37 #include <com/sun/star/util/Date.hpp>
38 #include <rtl/ustrbuf.hxx>
39 #include <uno/environment.h>
40 #include <cppuhelper/factory.hxx>
41 #include <unotools/configmgr.hxx>
42 #include <vcl/msgbox.hxx>
43 #include <tools/resmgr.hxx>
44 #include <tools/resid.hxx>
45 #include "../app/desktop.hrc"
48 using namespace rtl;
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::lang;
51 using namespace ::com::sun::star::beans;
52 using namespace ::com::sun::star::registry;
54 namespace desktop {
56 static SOEvaluation* pSOEval=0;
58 const char* SOEvaluation::interfaces[] =
60 "com.sun.star.beans.XExactName",
61 "com.sun.star.beans.XMaterialHolder",
62 "com.sun.star.lang.XComponent",
63 "com.sun.star.lang.XServiceInfo",
64 NULL,
67 const char* SOEvaluation::implementationName = "com.sun.star.comp.desktop.Evaluation";
68 const char* SOEvaluation::serviceName = "com.sun.star.office.Evaluation";
70 OUString SOEvaluation::GetImplementationName()
72 return OUString( RTL_CONSTASCII_USTRINGPARAM( implementationName));
75 Sequence< OUString > SOEvaluation::GetSupportedServiceNames()
77 sal_Int32 nSize = (sizeof( interfaces ) / sizeof( const char *)) - 1;
78 Sequence< OUString > aResult( nSize );
80 for( sal_Int32 i = 0; i < nSize; i++ )
81 aResult[i] = OUString::createFromAscii( interfaces[i] );
82 return aResult;
85 Reference< XInterface > SAL_CALL SOEvaluation::CreateInstance(
86 const Reference< XMultiServiceFactory >& rSMgr )
88 static osl::Mutex aMutex;
89 if ( pSOEval == 0 )
91 osl::MutexGuard guard( aMutex );
92 if ( pSOEval == 0 )
93 return (XComponent*) ( new SOEvaluation( rSMgr ) );
95 return (XComponent*)0;
98 SOEvaluation::SOEvaluation( const Reference< XMultiServiceFactory >& xFactory ) :
99 m_aListeners( m_aMutex ),
100 m_xServiceManager( xFactory )
104 SOEvaluation::~SOEvaluation()
108 // XComponent
109 void SAL_CALL SOEvaluation::dispose() throw ( RuntimeException )
111 EventObject aObject;
112 aObject.Source = (XComponent*)this;
113 m_aListeners.disposeAndClear( aObject );
116 void SAL_CALL SOEvaluation::addEventListener( const Reference< XEventListener > & aListener) throw ( RuntimeException )
118 m_aListeners.addInterface( aListener );
121 void SAL_CALL SOEvaluation::removeEventListener( const Reference< XEventListener > & aListener ) throw ( RuntimeException )
123 m_aListeners.removeInterface( aListener );
126 // XExactName
127 rtl::OUString SAL_CALL SOEvaluation::getExactName( const rtl::OUString& rApproximateName ) throw ( RuntimeException )
129 // get the tabreg service for an evaluation version
130 // without this service office shouldn't run at all
131 OUString aTitle = rApproximateName;
132 OUString aEval;
133 sal_Bool bExpired = sal_True;
134 Reference < XMaterialHolder > xHolder( m_xServiceManager->createInstance(
135 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.tab.tabreg" ) ) ), UNO_QUERY );
136 if ( xHolder.is() )
138 // get a sequence of strings for the defined locales
139 // a registered version doesn't provide data
140 bExpired = sal_False;
141 Any aData = xHolder->getMaterial();
142 Sequence < NamedValue > aSeq;
143 if ( aData >>= aSeq )
145 // this is an evaluation version, because it provides "material"
146 bExpired = sal_True;
147 for (int i=0; i<aSeq.getLength(); i++ )
149 NamedValue& rValue = aSeq[i];
150 if ( rValue.Name.equalsAscii("expired") )
151 rValue.Value >>= bExpired;
152 else if (rValue.Name.equalsAscii("title") )
153 rValue.Value >>= aEval;
155 // append eval string to title
156 aTitle += OUString::createFromAscii(" ") + aEval;
157 if ( bExpired )
158 throw RuntimeException();
162 return aTitle;
165 // XMaterialHolder
166 Any SAL_CALL SOEvaluation::getMaterial() throw( RuntimeException )
168 // Time bomb implementation. Return empty Any to do nothing or
169 // provide a com::sun::star::util::Date with the time bomb date.
170 Any a;
172 // change here to force recompile 00002
173 #ifdef TIMEBOMB
174 // Code for extracting/providing time bomb date!
175 int nDay = TIMEBOMB % 100;
176 int nMonth = ( TIMEBOMB % 10000 ) / 100;
177 int nYear = TIMEBOMB / 10000;
178 com::sun::star::util::Date aDate( nDay, nMonth, nYear );
179 a <<= aDate;
180 #endif
181 return a;
184 // XServiceInfo
185 ::rtl::OUString SAL_CALL SOEvaluation::getImplementationName()
186 throw ( RuntimeException )
188 return SOEvaluation::GetImplementationName();
191 sal_Bool SAL_CALL SOEvaluation::supportsService( const ::rtl::OUString& rServiceName )
192 throw ( RuntimeException )
194 sal_Int32 nSize = (sizeof( interfaces ) / sizeof( const char *))-1;
196 for( sal_Int32 i = 0; i < nSize; i++ )
197 if ( rServiceName.equalsAscii( interfaces[i] ))
198 return sal_True;
199 return sal_False;
202 Sequence< ::rtl::OUString > SAL_CALL SOEvaluation::getSupportedServiceNames()
203 throw ( RuntimeException )
205 return SOEvaluation::GetSupportedServiceNames();