1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_desktop.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "evaluation.hxx" 32*cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/util/Date.hpp> 35*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 36*cdf0e10cSrcweir #include <uno/environment.h> 37*cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 38*cdf0e10cSrcweir #include <unotools/configmgr.hxx> 39*cdf0e10cSrcweir #include <vcl/msgbox.hxx> 40*cdf0e10cSrcweir #include <tools/resmgr.hxx> 41*cdf0e10cSrcweir #include <tools/resid.hxx> 42*cdf0e10cSrcweir #include "../app/desktop.hrc" 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir using namespace rtl; 46*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 47*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 48*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 49*cdf0e10cSrcweir using namespace ::com::sun::star::registry; 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir namespace desktop { 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir static SOEvaluation* pSOEval=0; 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir const char* SOEvaluation::interfaces[] = 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir "com.sun.star.beans.XExactName", 58*cdf0e10cSrcweir "com.sun.star.beans.XMaterialHolder", 59*cdf0e10cSrcweir "com.sun.star.lang.XComponent", 60*cdf0e10cSrcweir "com.sun.star.lang.XServiceInfo", 61*cdf0e10cSrcweir NULL, 62*cdf0e10cSrcweir }; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir const char* SOEvaluation::implementationName = "com.sun.star.comp.desktop.Evaluation"; 65*cdf0e10cSrcweir const char* SOEvaluation::serviceName = "com.sun.star.office.Evaluation"; 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir OUString SOEvaluation::GetImplementationName() 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir return OUString( RTL_CONSTASCII_USTRINGPARAM( implementationName)); 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir 72*cdf0e10cSrcweir Sequence< OUString > SOEvaluation::GetSupportedServiceNames() 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir sal_Int32 nSize = (sizeof( interfaces ) / sizeof( const char *)) - 1; 75*cdf0e10cSrcweir Sequence< OUString > aResult( nSize ); 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir for( sal_Int32 i = 0; i < nSize; i++ ) 78*cdf0e10cSrcweir aResult[i] = OUString::createFromAscii( interfaces[i] ); 79*cdf0e10cSrcweir return aResult; 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir Reference< XInterface > SAL_CALL SOEvaluation::CreateInstance( 83*cdf0e10cSrcweir const Reference< XMultiServiceFactory >& rSMgr ) 84*cdf0e10cSrcweir { 85*cdf0e10cSrcweir static osl::Mutex aMutex; 86*cdf0e10cSrcweir if ( pSOEval == 0 ) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir osl::MutexGuard guard( aMutex ); 89*cdf0e10cSrcweir if ( pSOEval == 0 ) 90*cdf0e10cSrcweir return (XComponent*) ( new SOEvaluation( rSMgr ) ); 91*cdf0e10cSrcweir } 92*cdf0e10cSrcweir return (XComponent*)0; 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir SOEvaluation::SOEvaluation( const Reference< XMultiServiceFactory >& xFactory ) : 96*cdf0e10cSrcweir m_aListeners( m_aMutex ), 97*cdf0e10cSrcweir m_xServiceManager( xFactory ) 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir SOEvaluation::~SOEvaluation() 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir } 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir // XComponent 106*cdf0e10cSrcweir void SAL_CALL SOEvaluation::dispose() throw ( RuntimeException ) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir EventObject aObject; 109*cdf0e10cSrcweir aObject.Source = (XComponent*)this; 110*cdf0e10cSrcweir m_aListeners.disposeAndClear( aObject ); 111*cdf0e10cSrcweir } 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir void SAL_CALL SOEvaluation::addEventListener( const Reference< XEventListener > & aListener) throw ( RuntimeException ) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir m_aListeners.addInterface( aListener ); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir void SAL_CALL SOEvaluation::removeEventListener( const Reference< XEventListener > & aListener ) throw ( RuntimeException ) 119*cdf0e10cSrcweir { 120*cdf0e10cSrcweir m_aListeners.removeInterface( aListener ); 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir // XExactName 124*cdf0e10cSrcweir rtl::OUString SAL_CALL SOEvaluation::getExactName( const rtl::OUString& rApproximateName ) throw ( RuntimeException ) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir // get the tabreg service for an evaluation version 127*cdf0e10cSrcweir // without this service office shouldn't run at all 128*cdf0e10cSrcweir OUString aTitle = rApproximateName; 129*cdf0e10cSrcweir OUString aEval; 130*cdf0e10cSrcweir sal_Bool bExpired = sal_True; 131*cdf0e10cSrcweir Reference < XMaterialHolder > xHolder( m_xServiceManager->createInstance( 132*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.tab.tabreg" ) ) ), UNO_QUERY ); 133*cdf0e10cSrcweir if ( xHolder.is() ) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir // get a sequence of strings for the defined locales 136*cdf0e10cSrcweir // a registered version doesn't provide data 137*cdf0e10cSrcweir bExpired = sal_False; 138*cdf0e10cSrcweir Any aData = xHolder->getMaterial(); 139*cdf0e10cSrcweir Sequence < NamedValue > aSeq; 140*cdf0e10cSrcweir if ( aData >>= aSeq ) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir // this is an evaluation version, because it provides "material" 143*cdf0e10cSrcweir bExpired = sal_True; 144*cdf0e10cSrcweir for (int i=0; i<aSeq.getLength(); i++ ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir NamedValue& rValue = aSeq[i]; 147*cdf0e10cSrcweir if ( rValue.Name.equalsAscii("expired") ) 148*cdf0e10cSrcweir rValue.Value >>= bExpired; 149*cdf0e10cSrcweir else if (rValue.Name.equalsAscii("title") ) 150*cdf0e10cSrcweir rValue.Value >>= aEval; 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir // append eval string to title 153*cdf0e10cSrcweir aTitle += OUString::createFromAscii(" ") + aEval; 154*cdf0e10cSrcweir if ( bExpired ) 155*cdf0e10cSrcweir throw RuntimeException(); 156*cdf0e10cSrcweir } 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir return aTitle; 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir // XMaterialHolder 163*cdf0e10cSrcweir Any SAL_CALL SOEvaluation::getMaterial() throw( RuntimeException ) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir // Time bomb implementation. Return empty Any to do nothing or 166*cdf0e10cSrcweir // provide a com::sun::star::util::Date with the time bomb date. 167*cdf0e10cSrcweir Any a; 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir // change here to force recompile 00002 170*cdf0e10cSrcweir #ifdef TIMEBOMB 171*cdf0e10cSrcweir // Code for extracting/providing time bomb date! 172*cdf0e10cSrcweir int nDay = TIMEBOMB % 100; 173*cdf0e10cSrcweir int nMonth = ( TIMEBOMB % 10000 ) / 100; 174*cdf0e10cSrcweir int nYear = TIMEBOMB / 10000; 175*cdf0e10cSrcweir com::sun::star::util::Date aDate( nDay, nMonth, nYear ); 176*cdf0e10cSrcweir a <<= aDate; 177*cdf0e10cSrcweir #endif 178*cdf0e10cSrcweir return a; 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir // XServiceInfo 182*cdf0e10cSrcweir ::rtl::OUString SAL_CALL SOEvaluation::getImplementationName() 183*cdf0e10cSrcweir throw ( RuntimeException ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir return SOEvaluation::GetImplementationName(); 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir sal_Bool SAL_CALL SOEvaluation::supportsService( const ::rtl::OUString& rServiceName ) 189*cdf0e10cSrcweir throw ( RuntimeException ) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir sal_Int32 nSize = (sizeof( interfaces ) / sizeof( const char *))-1; 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir for( sal_Int32 i = 0; i < nSize; i++ ) 194*cdf0e10cSrcweir if ( rServiceName.equalsAscii( interfaces[i] )) 195*cdf0e10cSrcweir return sal_True; 196*cdf0e10cSrcweir return sal_False; 197*cdf0e10cSrcweir } 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL SOEvaluation::getSupportedServiceNames() 200*cdf0e10cSrcweir throw ( RuntimeException ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir return SOEvaluation::GetSupportedServiceNames(); 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir } 206