1*2722ceddSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*2722ceddSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*2722ceddSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*2722ceddSAndrew Rist * distributed with this work for additional information
6*2722ceddSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*2722ceddSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*2722ceddSAndrew Rist * "License"); you may not use this file except in compliance
9*2722ceddSAndrew Rist * with the License. You may obtain a copy of the License at
10*2722ceddSAndrew Rist *
11*2722ceddSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*2722ceddSAndrew Rist *
13*2722ceddSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*2722ceddSAndrew Rist * software distributed under the License is distributed on an
15*2722ceddSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2722ceddSAndrew Rist * KIND, either express or implied. See the License for the
17*2722ceddSAndrew Rist * specific language governing permissions and limitations
18*2722ceddSAndrew Rist * under the License.
19*2722ceddSAndrew Rist *
20*2722ceddSAndrew Rist *************************************************************/
21*2722ceddSAndrew Rist
22*2722ceddSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_desktop.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "evaluation.hxx"
28cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
29cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp>
30cdf0e10cSrcweir #include <com/sun/star/util/Date.hpp>
31cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
32cdf0e10cSrcweir #include <uno/environment.h>
33cdf0e10cSrcweir #include <cppuhelper/factory.hxx>
34cdf0e10cSrcweir #include <unotools/configmgr.hxx>
35cdf0e10cSrcweir #include <vcl/msgbox.hxx>
36cdf0e10cSrcweir #include <tools/resmgr.hxx>
37cdf0e10cSrcweir #include <tools/resid.hxx>
38cdf0e10cSrcweir #include "../app/desktop.hrc"
39cdf0e10cSrcweir
40cdf0e10cSrcweir
41cdf0e10cSrcweir using namespace rtl;
42cdf0e10cSrcweir using namespace ::com::sun::star::uno;
43cdf0e10cSrcweir using namespace ::com::sun::star::lang;
44cdf0e10cSrcweir using namespace ::com::sun::star::beans;
45cdf0e10cSrcweir using namespace ::com::sun::star::registry;
46cdf0e10cSrcweir
47cdf0e10cSrcweir namespace desktop {
48cdf0e10cSrcweir
49cdf0e10cSrcweir static SOEvaluation* pSOEval=0;
50cdf0e10cSrcweir
51cdf0e10cSrcweir const char* SOEvaluation::interfaces[] =
52cdf0e10cSrcweir {
53cdf0e10cSrcweir "com.sun.star.beans.XExactName",
54cdf0e10cSrcweir "com.sun.star.beans.XMaterialHolder",
55cdf0e10cSrcweir "com.sun.star.lang.XComponent",
56cdf0e10cSrcweir "com.sun.star.lang.XServiceInfo",
57cdf0e10cSrcweir NULL,
58cdf0e10cSrcweir };
59cdf0e10cSrcweir
60cdf0e10cSrcweir const char* SOEvaluation::implementationName = "com.sun.star.comp.desktop.Evaluation";
61cdf0e10cSrcweir const char* SOEvaluation::serviceName = "com.sun.star.office.Evaluation";
62cdf0e10cSrcweir
GetImplementationName()63cdf0e10cSrcweir OUString SOEvaluation::GetImplementationName()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir return OUString( RTL_CONSTASCII_USTRINGPARAM( implementationName));
66cdf0e10cSrcweir }
67cdf0e10cSrcweir
GetSupportedServiceNames()68cdf0e10cSrcweir Sequence< OUString > SOEvaluation::GetSupportedServiceNames()
69cdf0e10cSrcweir {
70cdf0e10cSrcweir sal_Int32 nSize = (sizeof( interfaces ) / sizeof( const char *)) - 1;
71cdf0e10cSrcweir Sequence< OUString > aResult( nSize );
72cdf0e10cSrcweir
73cdf0e10cSrcweir for( sal_Int32 i = 0; i < nSize; i++ )
74cdf0e10cSrcweir aResult[i] = OUString::createFromAscii( interfaces[i] );
75cdf0e10cSrcweir return aResult;
76cdf0e10cSrcweir }
77cdf0e10cSrcweir
CreateInstance(const Reference<XMultiServiceFactory> & rSMgr)78cdf0e10cSrcweir Reference< XInterface > SAL_CALL SOEvaluation::CreateInstance(
79cdf0e10cSrcweir const Reference< XMultiServiceFactory >& rSMgr )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir static osl::Mutex aMutex;
82cdf0e10cSrcweir if ( pSOEval == 0 )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir osl::MutexGuard guard( aMutex );
85cdf0e10cSrcweir if ( pSOEval == 0 )
86cdf0e10cSrcweir return (XComponent*) ( new SOEvaluation( rSMgr ) );
87cdf0e10cSrcweir }
88cdf0e10cSrcweir return (XComponent*)0;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir
SOEvaluation(const Reference<XMultiServiceFactory> & xFactory)91cdf0e10cSrcweir SOEvaluation::SOEvaluation( const Reference< XMultiServiceFactory >& xFactory ) :
92cdf0e10cSrcweir m_aListeners( m_aMutex ),
93cdf0e10cSrcweir m_xServiceManager( xFactory )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir }
96cdf0e10cSrcweir
~SOEvaluation()97cdf0e10cSrcweir SOEvaluation::~SOEvaluation()
98cdf0e10cSrcweir {
99cdf0e10cSrcweir }
100cdf0e10cSrcweir
101cdf0e10cSrcweir // XComponent
dispose()102cdf0e10cSrcweir void SAL_CALL SOEvaluation::dispose() throw ( RuntimeException )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir EventObject aObject;
105cdf0e10cSrcweir aObject.Source = (XComponent*)this;
106cdf0e10cSrcweir m_aListeners.disposeAndClear( aObject );
107cdf0e10cSrcweir }
108cdf0e10cSrcweir
addEventListener(const Reference<XEventListener> & aListener)109cdf0e10cSrcweir void SAL_CALL SOEvaluation::addEventListener( const Reference< XEventListener > & aListener) throw ( RuntimeException )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir m_aListeners.addInterface( aListener );
112cdf0e10cSrcweir }
113cdf0e10cSrcweir
removeEventListener(const Reference<XEventListener> & aListener)114cdf0e10cSrcweir void SAL_CALL SOEvaluation::removeEventListener( const Reference< XEventListener > & aListener ) throw ( RuntimeException )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir m_aListeners.removeInterface( aListener );
117cdf0e10cSrcweir }
118cdf0e10cSrcweir
119cdf0e10cSrcweir // XExactName
getExactName(const rtl::OUString & rApproximateName)120cdf0e10cSrcweir rtl::OUString SAL_CALL SOEvaluation::getExactName( const rtl::OUString& rApproximateName ) throw ( RuntimeException )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir // get the tabreg service for an evaluation version
123cdf0e10cSrcweir // without this service office shouldn't run at all
124cdf0e10cSrcweir OUString aTitle = rApproximateName;
125cdf0e10cSrcweir OUString aEval;
126cdf0e10cSrcweir sal_Bool bExpired = sal_True;
127cdf0e10cSrcweir Reference < XMaterialHolder > xHolder( m_xServiceManager->createInstance(
128cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.tab.tabreg" ) ) ), UNO_QUERY );
129cdf0e10cSrcweir if ( xHolder.is() )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir // get a sequence of strings for the defined locales
132cdf0e10cSrcweir // a registered version doesn't provide data
133cdf0e10cSrcweir bExpired = sal_False;
134cdf0e10cSrcweir Any aData = xHolder->getMaterial();
135cdf0e10cSrcweir Sequence < NamedValue > aSeq;
136cdf0e10cSrcweir if ( aData >>= aSeq )
137cdf0e10cSrcweir {
138cdf0e10cSrcweir // this is an evaluation version, because it provides "material"
139cdf0e10cSrcweir bExpired = sal_True;
140cdf0e10cSrcweir for (int i=0; i<aSeq.getLength(); i++ )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir NamedValue& rValue = aSeq[i];
143cdf0e10cSrcweir if ( rValue.Name.equalsAscii("expired") )
144cdf0e10cSrcweir rValue.Value >>= bExpired;
145cdf0e10cSrcweir else if (rValue.Name.equalsAscii("title") )
146cdf0e10cSrcweir rValue.Value >>= aEval;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir // append eval string to title
149cdf0e10cSrcweir aTitle += OUString::createFromAscii(" ") + aEval;
150cdf0e10cSrcweir if ( bExpired )
151cdf0e10cSrcweir throw RuntimeException();
152cdf0e10cSrcweir }
153cdf0e10cSrcweir }
154cdf0e10cSrcweir
155cdf0e10cSrcweir return aTitle;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir
158cdf0e10cSrcweir // XMaterialHolder
getMaterial()159cdf0e10cSrcweir Any SAL_CALL SOEvaluation::getMaterial() throw( RuntimeException )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir // Time bomb implementation. Return empty Any to do nothing or
162cdf0e10cSrcweir // provide a com::sun::star::util::Date with the time bomb date.
163cdf0e10cSrcweir Any a;
164cdf0e10cSrcweir
165cdf0e10cSrcweir // change here to force recompile 00002
166cdf0e10cSrcweir #ifdef TIMEBOMB
167cdf0e10cSrcweir // Code for extracting/providing time bomb date!
168cdf0e10cSrcweir int nDay = TIMEBOMB % 100;
169cdf0e10cSrcweir int nMonth = ( TIMEBOMB % 10000 ) / 100;
170cdf0e10cSrcweir int nYear = TIMEBOMB / 10000;
171cdf0e10cSrcweir com::sun::star::util::Date aDate( nDay, nMonth, nYear );
172cdf0e10cSrcweir a <<= aDate;
173cdf0e10cSrcweir #endif
174cdf0e10cSrcweir return a;
175cdf0e10cSrcweir }
176cdf0e10cSrcweir
177cdf0e10cSrcweir // XServiceInfo
getImplementationName()178cdf0e10cSrcweir ::rtl::OUString SAL_CALL SOEvaluation::getImplementationName()
179cdf0e10cSrcweir throw ( RuntimeException )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir return SOEvaluation::GetImplementationName();
182cdf0e10cSrcweir }
183cdf0e10cSrcweir
supportsService(const::rtl::OUString & rServiceName)184cdf0e10cSrcweir sal_Bool SAL_CALL SOEvaluation::supportsService( const ::rtl::OUString& rServiceName )
185cdf0e10cSrcweir throw ( RuntimeException )
186cdf0e10cSrcweir {
187cdf0e10cSrcweir sal_Int32 nSize = (sizeof( interfaces ) / sizeof( const char *))-1;
188cdf0e10cSrcweir
189cdf0e10cSrcweir for( sal_Int32 i = 0; i < nSize; i++ )
190cdf0e10cSrcweir if ( rServiceName.equalsAscii( interfaces[i] ))
191cdf0e10cSrcweir return sal_True;
192cdf0e10cSrcweir return sal_False;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir
getSupportedServiceNames()195cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL SOEvaluation::getSupportedServiceNames()
196cdf0e10cSrcweir throw ( RuntimeException )
197cdf0e10cSrcweir {
198cdf0e10cSrcweir return SOEvaluation::GetSupportedServiceNames();
199cdf0e10cSrcweir }
200cdf0e10cSrcweir
201cdf0e10cSrcweir }
202