16d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
36d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
46d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
56d739b60SAndrew Rist  * distributed with this work for additional information
66d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
76d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
86d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
96d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
106d739b60SAndrew Rist  *
116d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
126d739b60SAndrew Rist  *
136d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
146d739b60SAndrew Rist  * software distributed under the License is distributed on an
156d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
166d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
176d739b60SAndrew Rist  * specific language governing permissions and limitations
186d739b60SAndrew Rist  * under the License.
196d739b60SAndrew Rist  *
206d739b60SAndrew Rist  *************************************************************/
216d739b60SAndrew Rist 
226d739b60SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //_________________________________________________________________________________________________________________
28cdf0e10cSrcweir //	my own includes
29cdf0e10cSrcweir //_________________________________________________________________________________________________________________
30cdf0e10cSrcweir #include <services/license.hxx>
31cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
32cdf0e10cSrcweir #include <macros/debug.hxx>
33cdf0e10cSrcweir #include <services.h>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir // local header for UI implementation
36cdf0e10cSrcweir #include "services/licensedlg.hxx"
37cdf0e10cSrcweir #include "classes/resource.hrc"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //_________________________________________________________________________________________________________________
40cdf0e10cSrcweir //	interface includes
41cdf0e10cSrcweir //_________________________________________________________________________________________________________________
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
44cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
45cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
46cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
47cdf0e10cSrcweir #include <com/sun/star/util/XChangesBatch.hpp>
48cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
49cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir 
52cdf0e10cSrcweir //_________________________________________________________________________________________________________________
53cdf0e10cSrcweir //	includes of other projects
54cdf0e10cSrcweir //_________________________________________________________________________________________________________________
55cdf0e10cSrcweir 
56cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
57cdf0e10cSrcweir #include <rtl/strbuf.hxx>
58cdf0e10cSrcweir #include <rtl/ustring.hxx>
59cdf0e10cSrcweir #include <rtl/string.hxx>
60cdf0e10cSrcweir #include <unotools/bootstrap.hxx>
61cdf0e10cSrcweir #include <osl/file.hxx>
62cdf0e10cSrcweir #include <svtools/xtextedt.hxx>
63cdf0e10cSrcweir #include <vcl/svapp.hxx>
64cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
65cdf0e10cSrcweir #include <tools/date.hxx>
66cdf0e10cSrcweir #include <tools/time.hxx>
67cdf0e10cSrcweir #include <tools/datetime.hxx>
68cdf0e10cSrcweir #include <osl/file.hxx>
69cdf0e10cSrcweir #include <osl/time.h>
70cdf0e10cSrcweir 
71cdf0e10cSrcweir //_________________________________________________________________________________________________________________
72cdf0e10cSrcweir //	namespace
73cdf0e10cSrcweir //_________________________________________________________________________________________________________________
74cdf0e10cSrcweir 
75cdf0e10cSrcweir namespace framework{
76cdf0e10cSrcweir using namespace utl;
77cdf0e10cSrcweir using namespace ::osl							;
78cdf0e10cSrcweir using namespace ::cppu							;
79cdf0e10cSrcweir using namespace ::com::sun::star::uno			;
80cdf0e10cSrcweir using namespace ::com::sun::star::beans			;
81cdf0e10cSrcweir using namespace ::com::sun::star::lang			;
82cdf0e10cSrcweir using namespace ::com::sun::star::util			;
83cdf0e10cSrcweir using namespace ::com::sun::star::frame 		;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir //_________________________________________________________________________________________________________________
86cdf0e10cSrcweir //	non exported const
87cdf0e10cSrcweir //_________________________________________________________________________________________________________________
88cdf0e10cSrcweir 
89cdf0e10cSrcweir // license file name
90cdf0e10cSrcweir static const char *szLicensePath = "/share/readme";
91cdf0e10cSrcweir #ifdef UNX
92cdf0e10cSrcweir static const char *szUNXLicenseName = "/LICENSE";
93cdf0e10cSrcweir static const char *szUNXLicenseExt = "";
94cdf0e10cSrcweir #elif defined(WNT) || defined(OS2)
95cdf0e10cSrcweir static const char *szWNTLicenseName = "/license";
96cdf0e10cSrcweir static const char *szWNTLicenseExt = ".txt";
97cdf0e10cSrcweir #endif
98cdf0e10cSrcweir 
99cdf0e10cSrcweir //_________________________________________________________________________________________________________________
100cdf0e10cSrcweir //	non exported definitions
101cdf0e10cSrcweir //_________________________________________________________________________________________________________________
102cdf0e10cSrcweir 
103cdf0e10cSrcweir //_________________________________________________________________________________________________________________
104cdf0e10cSrcweir //	declarations
105cdf0e10cSrcweir //_________________________________________________________________________________________________________________
106cdf0e10cSrcweir 
107cdf0e10cSrcweir //*****************************************************************************************************************
108cdf0e10cSrcweir //	constructor
109cdf0e10cSrcweir //*****************************************************************************************************************
License(const Reference<XMultiServiceFactory> & xFactory)110cdf0e10cSrcweir License::License( const Reference< XMultiServiceFactory >& xFactory )
111cdf0e10cSrcweir 		//	Init baseclasses first
112cdf0e10cSrcweir 		//	Attention:
113cdf0e10cSrcweir 		//		Don't change order of initialization!
114cdf0e10cSrcweir 		//      ThreadHelpBase is a struct with a mutex as member. We can't use a mutex as member, while
115cdf0e10cSrcweir 		//		we must garant right initialization and a valid value of this! First initialize
116cdf0e10cSrcweir 		//		baseclasses and then members. And we need the mutex for other baseclasses !!!
117cdf0e10cSrcweir         :   ThreadHelpBase  ( &Application::GetSolarMutex() )
118cdf0e10cSrcweir         ,   OWeakObject     (                               )
119cdf0e10cSrcweir 		// Init member
120cdf0e10cSrcweir         ,   m_xFactory      ( xFactory                      )
121cdf0e10cSrcweir         ,   m_bTerminate    ( sal_False                     )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir //*****************************************************************************************************************
126cdf0e10cSrcweir //	destructor
127cdf0e10cSrcweir //*****************************************************************************************************************
~License()128cdf0e10cSrcweir License::~License()
129cdf0e10cSrcweir {
130cdf0e10cSrcweir }
131cdf0e10cSrcweir 
132cdf0e10cSrcweir //*****************************************************************************************************************
133cdf0e10cSrcweir //	XInterface, XTypeProvider, XServiceInfo
134cdf0e10cSrcweir //*****************************************************************************************************************
135cdf0e10cSrcweir 
DEFINE_XINTERFACE_4(License,OWeakObject,DIRECT_INTERFACE (XTypeProvider),DIRECT_INTERFACE (XServiceInfo),DIRECT_INTERFACE (XJob),DIRECT_INTERFACE (XCloseable))136cdf0e10cSrcweir DEFINE_XINTERFACE_4					(	License						   ,
137cdf0e10cSrcweir 										OWeakObject					   ,
138cdf0e10cSrcweir 										DIRECT_INTERFACE(XTypeProvider ),
139cdf0e10cSrcweir 										DIRECT_INTERFACE(XServiceInfo  ),
140cdf0e10cSrcweir 										DIRECT_INTERFACE(XJob	       ),
141cdf0e10cSrcweir                                         DIRECT_INTERFACE(XCloseable    )
142cdf0e10cSrcweir 									)
143cdf0e10cSrcweir 
144cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_4				(	License	,
145cdf0e10cSrcweir 										XTypeProvider	,
146cdf0e10cSrcweir 										XServiceInfo	,
147cdf0e10cSrcweir 										XJob            ,
148cdf0e10cSrcweir                                         XCloseable
149cdf0e10cSrcweir 									)
150cdf0e10cSrcweir 
151cdf0e10cSrcweir DEFINE_XSERVICEINFO_MULTISERVICE	(	License,
152cdf0e10cSrcweir                                         OWeakObject                 ,
153cdf0e10cSrcweir 										SERVICENAME_LICENSE			,
154cdf0e10cSrcweir 										IMPLEMENTATIONNAME_LICENSE
155cdf0e10cSrcweir 									)
156cdf0e10cSrcweir 
157cdf0e10cSrcweir DEFINE_INIT_SERVICE                 (   License,
158cdf0e10cSrcweir                                         {
159cdf0e10cSrcweir                                         }
160cdf0e10cSrcweir                                     )
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 
163cdf0e10cSrcweir #if 0
164cdf0e10cSrcweir IMPL_STATIC_LINK_NOINSTANCE( License, Terminate, void*, EMPTYARG )
165cdf0e10cSrcweir {
166cdf0e10cSrcweir     /*
167cdf0e10cSrcweir     Reference< XMultiServiceFactory > xFactory = comphelper::getProcessServiceFactory();
168cdf0e10cSrcweir     Reference< XDesktop > xDesktop(xFactory->createInstance(
169cdf0e10cSrcweir         ::rtl::OUString::createFromAscii("com.sun.star.frame.Desktop")), UNO_QUERY);
170cdf0e10cSrcweir     if (xDesktop.is())
171cdf0e10cSrcweir         xDesktop->terminate();
172cdf0e10cSrcweir     */
173cdf0e10cSrcweir     /*
174cdf0e10cSrcweir     _exit(0);
175cdf0e10cSrcweir     */
176cdf0e10cSrcweir 	return 0;
177cdf0e10cSrcweir }
178cdf0e10cSrcweir #endif
179cdf0e10cSrcweir 
180cdf0e10cSrcweir static DateTime _oslDateTimeToDateTime(const oslDateTime& aDateTime)
181cdf0e10cSrcweir {
182cdf0e10cSrcweir     return DateTime(
183cdf0e10cSrcweir         Date(aDateTime.Day, aDateTime.Month, aDateTime.Year),
184cdf0e10cSrcweir         Time(aDateTime.Hours, aDateTime.Minutes, aDateTime.Seconds));
185cdf0e10cSrcweir }
186cdf0e10cSrcweir 
_makeDateTimeString(const DateTime & aDateTime,sal_Bool bUTC=sal_False)187cdf0e10cSrcweir static ::rtl::OUString _makeDateTimeString (const DateTime& aDateTime, sal_Bool bUTC = sal_False)
188cdf0e10cSrcweir {
189cdf0e10cSrcweir     ::rtl::OStringBuffer aDateTimeString;
190cdf0e10cSrcweir     aDateTimeString.append((sal_Int32)aDateTime.GetYear());
191cdf0e10cSrcweir     aDateTimeString.append("-");
192cdf0e10cSrcweir     if (aDateTime.GetMonth()<10) aDateTimeString.append("0");
193cdf0e10cSrcweir     aDateTimeString.append((sal_Int32)aDateTime.GetMonth());
194cdf0e10cSrcweir     aDateTimeString.append("-");
195cdf0e10cSrcweir     if (aDateTime.GetDay()<10) aDateTimeString.append("0");
196cdf0e10cSrcweir     aDateTimeString.append((sal_Int32)aDateTime.GetDay());
197cdf0e10cSrcweir     aDateTimeString.append("T");
198cdf0e10cSrcweir     if (aDateTime.GetHour()<10) aDateTimeString.append("0");
199cdf0e10cSrcweir     aDateTimeString.append((sal_Int32)aDateTime.GetHour());
200cdf0e10cSrcweir     aDateTimeString.append(":");
201cdf0e10cSrcweir     if (aDateTime.GetMin()<10) aDateTimeString.append("0");
202cdf0e10cSrcweir     aDateTimeString.append((sal_Int32)aDateTime.GetMin());
203cdf0e10cSrcweir     aDateTimeString.append(":");
204cdf0e10cSrcweir     if (aDateTime.GetSec()<10) aDateTimeString.append("0");
205cdf0e10cSrcweir     aDateTimeString.append((sal_Int32)aDateTime.GetSec());
206cdf0e10cSrcweir     if (bUTC) aDateTimeString.append("Z");
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     return OStringToOUString(aDateTimeString.makeStringAndClear(), RTL_TEXTENCODING_ASCII_US);
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
_parseDateTime(const::rtl::OUString & aString,DateTime & aDateTime)211cdf0e10cSrcweir static sal_Bool _parseDateTime(const ::rtl::OUString& aString, DateTime& aDateTime)
212cdf0e10cSrcweir {
213cdf0e10cSrcweir     // take apart a canonical literal xsd:dateTime string
214cdf0e10cSrcweir     //CCYY-MM-DDThh:mm:ss(Z)
215cdf0e10cSrcweir 
216cdf0e10cSrcweir     ::rtl::OUString aDateTimeString = aString.trim();
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     // check length
219cdf0e10cSrcweir     if (aDateTimeString.getLength() < 19 || aDateTimeString.getLength() > 20)
220cdf0e10cSrcweir         return sal_False;
221cdf0e10cSrcweir 
222cdf0e10cSrcweir     sal_Int32 nDateLength = 10;
223cdf0e10cSrcweir     sal_Int32 nTimeLength = 8;
224cdf0e10cSrcweir 
225cdf0e10cSrcweir     ::rtl::OUString aDateTimeSep = ::rtl::OUString::createFromAscii("T");
226cdf0e10cSrcweir     ::rtl::OUString aDateSep = ::rtl::OUString::createFromAscii("-");
227cdf0e10cSrcweir     ::rtl::OUString aTimeSep = ::rtl::OUString::createFromAscii(":");
228cdf0e10cSrcweir     ::rtl::OUString aUTCString = ::rtl::OUString::createFromAscii("Z");
229cdf0e10cSrcweir 
230cdf0e10cSrcweir     ::rtl::OUString aDateString = aDateTimeString.copy(0, nDateLength);
231cdf0e10cSrcweir     ::rtl::OUString aTimeString = aDateTimeString.copy(nDateLength+1, nTimeLength);
232cdf0e10cSrcweir 
233cdf0e10cSrcweir     sal_Int32 nIndex = 0;
234cdf0e10cSrcweir     sal_Int32 nYear = aDateString.getToken(0, '-', nIndex).toInt32();
235cdf0e10cSrcweir     sal_Int32 nMonth = aDateString.getToken(0, '-', nIndex).toInt32();
236cdf0e10cSrcweir     sal_Int32 nDay = aDateString.getToken(0, '-', nIndex).toInt32();
237cdf0e10cSrcweir     nIndex = 0;
238cdf0e10cSrcweir     sal_Int32 nHour = aTimeString.getToken(0, ':', nIndex).toInt32();
239cdf0e10cSrcweir     sal_Int32 nMinute = aTimeString.getToken(0, ':', nIndex).toInt32();
240cdf0e10cSrcweir     sal_Int32 nSecond = aTimeString.getToken(0, ':', nIndex).toInt32();
241cdf0e10cSrcweir 
242cdf0e10cSrcweir     Date tmpDate((sal_uInt16)nDay, (sal_uInt16)nMonth, (sal_uInt16)nYear);
243cdf0e10cSrcweir     Time tmpTime(nHour, nMinute, nSecond);
244cdf0e10cSrcweir     DateTime tmpDateTime(tmpDate, tmpTime);
245cdf0e10cSrcweir     if (aString.indexOf(aUTCString) < 0)
246cdf0e10cSrcweir         tmpDateTime.ConvertToUTC();
247cdf0e10cSrcweir 
248cdf0e10cSrcweir     aDateTime = tmpDateTime;
249cdf0e10cSrcweir     return sal_True;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir 
_getCurrentDateString()252cdf0e10cSrcweir static ::rtl::OUString _getCurrentDateString()
253cdf0e10cSrcweir {
254cdf0e10cSrcweir     ::rtl::OUString aString;
255cdf0e10cSrcweir     return _makeDateTimeString(DateTime());
256cdf0e10cSrcweir }
257cdf0e10cSrcweir 
258cdf0e10cSrcweir // execution of license check...
execute(const css::uno::Sequence<css::beans::NamedValue> &)259cdf0e10cSrcweir css::uno::Any SAL_CALL License::execute(const css::uno::Sequence< css::beans::NamedValue >& )
260cdf0e10cSrcweir     throw( css::lang::IllegalArgumentException, css::uno::Exception)
261cdf0e10cSrcweir {
262cdf0e10cSrcweir     // return value
263cdf0e10cSrcweir     Any aRet; aRet <<= sal_False;
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     try
266cdf0e10cSrcweir     {
267cdf0e10cSrcweir         ::rtl::OUString aBaseInstallPath;
268cdf0e10cSrcweir         Bootstrap::PathStatus aBaseLocateResult =
269cdf0e10cSrcweir             Bootstrap::locateBaseInstallation(aBaseInstallPath);
270cdf0e10cSrcweir         if (aBaseLocateResult != Bootstrap::PATH_EXISTS)
271cdf0e10cSrcweir         {
272cdf0e10cSrcweir             // base install noit found
273cdf0e10cSrcweir             // prepare termination
274cdf0e10cSrcweir             // m_bTerminate = sal_True;
275cdf0e10cSrcweir             // Application::PostUserEvent( STATIC_LINK( 0, License, Terminate ) );
276cdf0e10cSrcweir             aRet <<= sal_False;
277cdf0e10cSrcweir             return aRet;
278cdf0e10cSrcweir         }
279cdf0e10cSrcweir         // determine the filename of the license to show
280cdf0e10cSrcweir 	    ::rtl::OUString  aLangString;
281cdf0e10cSrcweir         ::com::sun::star::lang::Locale aLocale;
282cdf0e10cSrcweir         ::rtl::OString aMgrName = ::rtl::OString("fwe");
283cdf0e10cSrcweir         AllSettings aSettings(Application::GetSettings());
284cdf0e10cSrcweir         aLocale = aSettings.GetUILocale();
285*24c56ab9SHerbert Dürr         ResMgr* pResMgr = ResMgr::SearchCreateResMgr( aMgrName.getStr(), aLocale);
286cdf0e10cSrcweir 
287cdf0e10cSrcweir         aLangString = aLocale.Language;
288cdf0e10cSrcweir         if ( aLocale.Country.getLength() != 0 )
289cdf0e10cSrcweir         {
290cdf0e10cSrcweir             aLangString += ::rtl::OUString::createFromAscii("-");
291cdf0e10cSrcweir             aLangString += aLocale.Country;
292cdf0e10cSrcweir 	        if ( aLocale.Variant.getLength() != 0 )
293cdf0e10cSrcweir             {
294cdf0e10cSrcweir 	            aLangString += ::rtl::OUString::createFromAscii("-");
295cdf0e10cSrcweir 	            aLangString += aLocale.Variant;
296cdf0e10cSrcweir             }
297cdf0e10cSrcweir         }
298cdf0e10cSrcweir #if defined(WNT) || defined(OS2)
299cdf0e10cSrcweir         ::rtl::OUString aLicensePath =
300cdf0e10cSrcweir             aBaseInstallPath + ::rtl::OUString::createFromAscii(szLicensePath)
301cdf0e10cSrcweir             + ::rtl::OUString::createFromAscii(szWNTLicenseName)
302cdf0e10cSrcweir             + ::rtl::OUString::createFromAscii("_")
303cdf0e10cSrcweir             + aLangString
304cdf0e10cSrcweir             + ::rtl::OUString::createFromAscii(szWNTLicenseExt);
305cdf0e10cSrcweir #else
306cdf0e10cSrcweir         ::rtl::OUString aLicensePath =
307cdf0e10cSrcweir             aBaseInstallPath + ::rtl::OUString::createFromAscii(szLicensePath)
308cdf0e10cSrcweir             + ::rtl::OUString::createFromAscii(szUNXLicenseName)
309cdf0e10cSrcweir             + ::rtl::OUString::createFromAscii("_")
310cdf0e10cSrcweir             + aLangString
311cdf0e10cSrcweir             + ::rtl::OUString::createFromAscii(szUNXLicenseExt);
312cdf0e10cSrcweir #endif
313cdf0e10cSrcweir         // check if we need to show the license at all
314cdf0e10cSrcweir         // open org.openoffice.Setup/Office/ooLicenseAcceptDate
315cdf0e10cSrcweir         ::rtl::OUString sConfigSrvc = SERVICENAME_CFGPROVIDER;
316cdf0e10cSrcweir         ::rtl::OUString sAccessSrvc = ::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationUpdateAccess");
317cdf0e10cSrcweir         ::rtl::OUString sReadSrvc   = SERVICENAME_CFGREADACCESS;
318cdf0e10cSrcweir 
319cdf0e10cSrcweir         // get configuration provider
320cdf0e10cSrcweir         Reference< XMultiServiceFactory > theConfigProvider = Reference< XMultiServiceFactory >(
321cdf0e10cSrcweir         m_xFactory->createInstance(sConfigSrvc), UNO_QUERY_THROW);
322cdf0e10cSrcweir         Sequence< Any > theArgs(1);
323cdf0e10cSrcweir         NamedValue v;
324cdf0e10cSrcweir         v.Name = ::rtl::OUString::createFromAscii("NodePath");
325cdf0e10cSrcweir         v.Value <<= ::rtl::OUString::createFromAscii("org.openoffice.Setup/Office");
326cdf0e10cSrcweir         theArgs[0] <<= v;
327cdf0e10cSrcweir         Reference< XPropertySet > pset = Reference< XPropertySet >(
328cdf0e10cSrcweir             theConfigProvider->createInstanceWithArguments(sAccessSrvc, theArgs), UNO_QUERY_THROW);
329cdf0e10cSrcweir 
330cdf0e10cSrcweir         // if we find a date there, compare it to baseinstall license date
331cdf0e10cSrcweir         ::rtl::OUString aAcceptDate;
332cdf0e10cSrcweir         if (pset->getPropertyValue(::rtl::OUString::createFromAscii("ooLicenseAcceptDate")) >>= aAcceptDate)
333cdf0e10cSrcweir         {
334cdf0e10cSrcweir             // get LicenseFileDate from base install
335cdf0e10cSrcweir             ::rtl::OUString aLicenseURL = aLicensePath;
336cdf0e10cSrcweir             /*
337cdf0e10cSrcweir             if (FileBase::getFileURLFromSystemPath(aLicensePath, aLicenseURL) != FileBase::E_None)
338cdf0e10cSrcweir                 return makeAny(sal_False);
339cdf0e10cSrcweir                 */
340cdf0e10cSrcweir             DirectoryItem aDirItem;
341cdf0e10cSrcweir             if (DirectoryItem::get(aLicenseURL, aDirItem) != FileBase::E_None)
342cdf0e10cSrcweir                 return makeAny(sal_False);
343cdf0e10cSrcweir             FileStatus aStatus(FileStatusMask_All);
344cdf0e10cSrcweir             if (aDirItem.getFileStatus(aStatus) != FileBase::E_None)
345cdf0e10cSrcweir                 return makeAny(sal_False);
346cdf0e10cSrcweir             TimeValue aTimeVal = aStatus.getModifyTime();
347cdf0e10cSrcweir             oslDateTime aDateTimeVal;
348cdf0e10cSrcweir             if (!osl_getDateTimeFromTimeValue(&aTimeVal, &aDateTimeVal))
349cdf0e10cSrcweir                 return makeAny(sal_False);
350cdf0e10cSrcweir 
351cdf0e10cSrcweir             // compare dates
352cdf0e10cSrcweir             DateTime aLicenseDateTime = _oslDateTimeToDateTime(aDateTimeVal);
353cdf0e10cSrcweir             DateTime aAcceptDateTime;
354cdf0e10cSrcweir             if (!_parseDateTime(aAcceptDate, aAcceptDateTime))
355cdf0e10cSrcweir                 return makeAny(sal_False);
356cdf0e10cSrcweir 
357cdf0e10cSrcweir             if ( aAcceptDateTime > aLicenseDateTime )
358cdf0e10cSrcweir                 return makeAny(sal_True);
359cdf0e10cSrcweir         }
360cdf0e10cSrcweir         // prepare to show
361cdf0e10cSrcweir         // display license dialog
362cdf0e10cSrcweir         LicenseDialog* pDialog = new LicenseDialog(aLicensePath, pResMgr);
363cdf0e10cSrcweir         sal_Bool bAgreed = (pDialog->Execute() == 1);
364cdf0e10cSrcweir         delete pDialog;
365cdf0e10cSrcweir 
366cdf0e10cSrcweir         if (bAgreed) {
367cdf0e10cSrcweir 
368cdf0e10cSrcweir             // write org.openoffice.Setup/ooLicenseAcceptDate
369cdf0e10cSrcweir             aAcceptDate = _getCurrentDateString();
370cdf0e10cSrcweir             pset->setPropertyValue(::rtl::OUString::createFromAscii("ooLicenseAcceptDate"), makeAny(aAcceptDate));
371cdf0e10cSrcweir             Reference< XChangesBatch >(pset, UNO_QUERY_THROW)->commitChanges();
372cdf0e10cSrcweir 
373cdf0e10cSrcweir             // enable quickstarter
374cdf0e10cSrcweir             sal_Bool bQuickstart( sal_True );
375cdf0e10cSrcweir             sal_Bool bAutostart( sal_True );
376cdf0e10cSrcweir             Sequence< Any > aSeq( 2 );
377cdf0e10cSrcweir             aSeq[0] <<= bQuickstart;
378cdf0e10cSrcweir             aSeq[1] <<= bAutostart;
379cdf0e10cSrcweir 
380cdf0e10cSrcweir             Reference < XInitialization > xQuickstart( ::comphelper::getProcessServiceFactory()->createInstance(
381cdf0e10cSrcweir                 ::rtl::OUString::createFromAscii( "com.sun.star.office.Quickstart" )),UNO_QUERY );
382cdf0e10cSrcweir             if ( xQuickstart.is() )
383cdf0e10cSrcweir                 xQuickstart->initialize( aSeq );
384cdf0e10cSrcweir 
385cdf0e10cSrcweir             aRet <<= sal_True;
386cdf0e10cSrcweir         }
387cdf0e10cSrcweir         else
388cdf0e10cSrcweir         {
389cdf0e10cSrcweir             // license was not accepted
390cdf0e10cSrcweir             // prepare termination
391cdf0e10cSrcweir             // m_bTerminate = sal_True;
392cdf0e10cSrcweir             // Application::PostUserEvent( STATIC_LINK( 0, License, Terminate ) );
393cdf0e10cSrcweir             aRet <<= sal_False;
394cdf0e10cSrcweir         }
395cdf0e10cSrcweir     }
396cdf0e10cSrcweir     catch (RuntimeException&)
397cdf0e10cSrcweir     {
398cdf0e10cSrcweir         // license could not be verified
399cdf0e10cSrcweir         aRet <<= sal_False;
400cdf0e10cSrcweir     }
401cdf0e10cSrcweir     return aRet;
402cdf0e10cSrcweir }
403cdf0e10cSrcweir 
close(sal_Bool)404cdf0e10cSrcweir void SAL_CALL License::close(sal_Bool /*bDeliverOwnership*/) throw (css::util::CloseVetoException)
405cdf0e10cSrcweir {
406cdf0e10cSrcweir     if (!m_bTerminate)
407cdf0e10cSrcweir         throw CloseVetoException();
408cdf0e10cSrcweir }
addCloseListener(const css::uno::Reference<css::util::XCloseListener> &)409cdf0e10cSrcweir void SAL_CALL License::addCloseListener(const css::uno::Reference< css::util::XCloseListener >&)
410cdf0e10cSrcweir     throw (css::uno::RuntimeException)
411cdf0e10cSrcweir {
412cdf0e10cSrcweir }
removeCloseListener(const css::uno::Reference<css::util::XCloseListener> &)413cdf0e10cSrcweir void SAL_CALL License::removeCloseListener(const css::uno::Reference< css::util::XCloseListener >&)
414cdf0e10cSrcweir     throw (css::uno::RuntimeException)
415cdf0e10cSrcweir {
416cdf0e10cSrcweir }
417cdf0e10cSrcweir 
418cdf0e10cSrcweir 
419cdf0e10cSrcweir //************************************************************************
420cdf0e10cSrcweir //   License Dialog
421cdf0e10cSrcweir //************************************************************************
422cdf0e10cSrcweir 
LicenseDialog(const::rtl::OUString & aLicensePath,ResMgr * pResMgr)423cdf0e10cSrcweir LicenseDialog::LicenseDialog(const ::rtl::OUString & aLicensePath, ResMgr *pResMgr) :
424cdf0e10cSrcweir     ModalDialog(NULL, ResId(DLG_LICENSE, *pResMgr)),
425cdf0e10cSrcweir     aLicenseML(this, ResId(ML_LICENSE, *pResMgr)),
426cdf0e10cSrcweir     aInfo1FT(this, ResId(FT_INFO1, *pResMgr)),
427cdf0e10cSrcweir     aInfo2FT(this, ResId(FT_INFO2, *pResMgr)),
428cdf0e10cSrcweir     aInfo3FT(this, ResId(FT_INFO3, *pResMgr)),
429cdf0e10cSrcweir     aInfo2_1FT(this, ResId(FT_INFO2_1, *pResMgr)),
430cdf0e10cSrcweir     aInfo3_1FT(this, ResId(FT_INFO3_1, *pResMgr)),
431cdf0e10cSrcweir     aFixedLine(this, ResId(FL_DIVIDE, *pResMgr)),
432cdf0e10cSrcweir     aPBPageDown(this, ResId(PB_PAGEDOWN, *pResMgr)),
433cdf0e10cSrcweir     aPBDecline( this, ResId(PB_DECLINE, *pResMgr) ),
434cdf0e10cSrcweir     aPBAccept( this, ResId(PB_ACCEPT, *pResMgr) ),
435cdf0e10cSrcweir     aArrow(this, ResId(IMG_ARROW, *pResMgr)),
436cdf0e10cSrcweir     aStrAccept( ResId(LICENSE_ACCEPT, *pResMgr) ),
437cdf0e10cSrcweir     aStrNotAccept( ResId(LICENSE_NOTACCEPT, *pResMgr) ),
438cdf0e10cSrcweir     bEndReached(sal_False)
439cdf0e10cSrcweir {
440cdf0e10cSrcweir     FreeResource();
441cdf0e10cSrcweir 
442cdf0e10cSrcweir     aLicenseML.SetEndReachedHdl( LINK(this, LicenseDialog, EndReachedHdl) );
443cdf0e10cSrcweir     aLicenseML.SetScrolledHdl( LINK(this, LicenseDialog, ScrolledHdl) );
444cdf0e10cSrcweir 
445cdf0e10cSrcweir     aPBPageDown.SetClickHdl( LINK(this, LicenseDialog, PageDownHdl) );
446cdf0e10cSrcweir     aPBDecline.SetClickHdl( LINK(this, LicenseDialog, DeclineBtnHdl) );
447cdf0e10cSrcweir     aPBAccept.SetClickHdl( LINK(this, LicenseDialog, AcceptBtnHdl) );
448cdf0e10cSrcweir 
449cdf0e10cSrcweir     // We want a automatic repeating page down button
450cdf0e10cSrcweir     WinBits aStyle = aPBPageDown.GetStyle();
451cdf0e10cSrcweir     aStyle |= WB_REPEAT;
452cdf0e10cSrcweir     aPBPageDown.SetStyle( aStyle );
453cdf0e10cSrcweir 
454cdf0e10cSrcweir     String aText = aInfo2FT.GetText();
455cdf0e10cSrcweir     aText.SearchAndReplaceAll( UniString::CreateFromAscii("%PAGEDOWN"), aPBPageDown.GetText() );
456cdf0e10cSrcweir     aInfo2FT.SetText( aText );
457cdf0e10cSrcweir 
458cdf0e10cSrcweir     aPBDecline.SetText( aStrNotAccept );
459cdf0e10cSrcweir     aPBAccept.SetText( aStrAccept );
460cdf0e10cSrcweir 
461cdf0e10cSrcweir     aPBAccept.Disable();
462cdf0e10cSrcweir 
463cdf0e10cSrcweir     // load license text
464cdf0e10cSrcweir     File aLicenseFile(aLicensePath);
465cdf0e10cSrcweir     if ( aLicenseFile.open(OpenFlag_Read) == FileBase::E_None)
466cdf0e10cSrcweir     {
467cdf0e10cSrcweir         DirectoryItem d;
468cdf0e10cSrcweir         DirectoryItem::get(aLicensePath, d);
469cdf0e10cSrcweir         FileStatus fs(FileStatusMask_FileSize);
470cdf0e10cSrcweir         d.getFileStatus(fs);
471cdf0e10cSrcweir         sal_uInt64 nBytesRead = 0;
472cdf0e10cSrcweir         sal_uInt64 nPosition = 0;
473cdf0e10cSrcweir         sal_uInt32 nBytes = (sal_uInt32)fs.getFileSize();
474cdf0e10cSrcweir         sal_Char *pBuffer = new sal_Char[nBytes];
475cdf0e10cSrcweir         // FileBase RC r = FileBase::E_None;
476cdf0e10cSrcweir         while (aLicenseFile.read(pBuffer+nPosition, nBytes-nPosition, nBytesRead) == FileBase::E_None
477cdf0e10cSrcweir             && nPosition + nBytesRead < nBytes)
478cdf0e10cSrcweir         {
479cdf0e10cSrcweir             nPosition += nBytesRead;
480cdf0e10cSrcweir         }
481cdf0e10cSrcweir         ::rtl::OUString aLicenseString(pBuffer, nBytes, RTL_TEXTENCODING_UTF8,
482cdf0e10cSrcweir                 OSTRING_TO_OUSTRING_CVTFLAGS | RTL_TEXTTOUNICODE_FLAGS_GLOBAL_SIGNATURE);
483cdf0e10cSrcweir         delete[] pBuffer;
484cdf0e10cSrcweir         aLicenseML.SetText(aLicenseString);
485cdf0e10cSrcweir     }
486cdf0e10cSrcweir 
487cdf0e10cSrcweir }
488cdf0e10cSrcweir 
~LicenseDialog()489cdf0e10cSrcweir LicenseDialog::~LicenseDialog()
490cdf0e10cSrcweir {
491cdf0e10cSrcweir }
492cdf0e10cSrcweir 
IMPL_LINK(LicenseDialog,PageDownHdl,PushButton *,EMPTYARG)493cdf0e10cSrcweir IMPL_LINK( LicenseDialog, PageDownHdl, PushButton *, EMPTYARG )
494cdf0e10cSrcweir {
495cdf0e10cSrcweir     aLicenseML.ScrollDown( SCROLL_PAGEDOWN );
496cdf0e10cSrcweir     return 0;
497cdf0e10cSrcweir }
498cdf0e10cSrcweir 
IMPL_LINK(LicenseDialog,EndReachedHdl,LicenseView *,EMPTYARG)499cdf0e10cSrcweir IMPL_LINK( LicenseDialog, EndReachedHdl, LicenseView *, EMPTYARG )
500cdf0e10cSrcweir {
501cdf0e10cSrcweir     bEndReached = sal_True;
502cdf0e10cSrcweir 
503cdf0e10cSrcweir     EnableControls();
504cdf0e10cSrcweir 
505cdf0e10cSrcweir     return 0;
506cdf0e10cSrcweir }
507cdf0e10cSrcweir 
IMPL_LINK(LicenseDialog,ScrolledHdl,LicenseView *,EMPTYARG)508cdf0e10cSrcweir IMPL_LINK( LicenseDialog, ScrolledHdl, LicenseView *, EMPTYARG )
509cdf0e10cSrcweir {
510cdf0e10cSrcweir     EnableControls();
511cdf0e10cSrcweir 
512cdf0e10cSrcweir     return 0;
513cdf0e10cSrcweir }
514cdf0e10cSrcweir 
IMPL_LINK(LicenseDialog,DeclineBtnHdl,PushButton *,EMPTYARG)515cdf0e10cSrcweir IMPL_LINK( LicenseDialog, DeclineBtnHdl, PushButton *, EMPTYARG )
516cdf0e10cSrcweir {
517cdf0e10cSrcweir     EndDialog(0);
518cdf0e10cSrcweir     return 0;
519cdf0e10cSrcweir }
IMPL_LINK(LicenseDialog,AcceptBtnHdl,PushButton *,EMPTYARG)520cdf0e10cSrcweir IMPL_LINK( LicenseDialog, AcceptBtnHdl, PushButton *, EMPTYARG )
521cdf0e10cSrcweir {
522cdf0e10cSrcweir     EndDialog(1);
523cdf0e10cSrcweir     return 0;
524cdf0e10cSrcweir }
525cdf0e10cSrcweir 
526cdf0e10cSrcweir 
EnableControls()527cdf0e10cSrcweir void LicenseDialog::EnableControls()
528cdf0e10cSrcweir {
529cdf0e10cSrcweir     if( !bEndReached &&
530cdf0e10cSrcweir         ( aLicenseML.IsEndReached() || !aLicenseML.GetText().Len() ) )
531cdf0e10cSrcweir         bEndReached = sal_True;
532cdf0e10cSrcweir 
533cdf0e10cSrcweir     if ( bEndReached )
534cdf0e10cSrcweir     {
535cdf0e10cSrcweir         Point aPos( aInfo1FT.GetPosPixel().X(),
536cdf0e10cSrcweir                 aInfo3_1FT.GetPosPixel().Y() );
537cdf0e10cSrcweir         aArrow.SetPosPixel( aPos );
538cdf0e10cSrcweir         aPBAccept.Enable();
539cdf0e10cSrcweir     }
540cdf0e10cSrcweir     else
541cdf0e10cSrcweir     {
542cdf0e10cSrcweir         Point aPos( aInfo1FT.GetPosPixel().X(),
543cdf0e10cSrcweir                 aInfo2_1FT.GetPosPixel().Y() );
544cdf0e10cSrcweir         aArrow.SetPosPixel( aPos );
545cdf0e10cSrcweir         aPBAccept.Disable();
546cdf0e10cSrcweir     }
547cdf0e10cSrcweir 
548cdf0e10cSrcweir     if ( aLicenseML.IsEndReached() )
549cdf0e10cSrcweir         aPBPageDown.Disable();
550cdf0e10cSrcweir     else
551cdf0e10cSrcweir         aPBPageDown.Enable();
552cdf0e10cSrcweir 
553cdf0e10cSrcweir }
554cdf0e10cSrcweir 
555cdf0e10cSrcweir 
LicenseView(Window * pParent,const ResId & rResId)556cdf0e10cSrcweir LicenseView::LicenseView( Window* pParent, const ResId& rResId )
557cdf0e10cSrcweir     : MultiLineEdit( pParent, rResId )
558cdf0e10cSrcweir {
559cdf0e10cSrcweir     SetLeftMargin( 5 );
560cdf0e10cSrcweir 
561cdf0e10cSrcweir     mbEndReached = IsEndReached();
562cdf0e10cSrcweir 
563cdf0e10cSrcweir 	StartListening( *GetTextEngine() );
564cdf0e10cSrcweir }
565cdf0e10cSrcweir 
~LicenseView()566cdf0e10cSrcweir LicenseView::~LicenseView()
567cdf0e10cSrcweir {
568cdf0e10cSrcweir     maEndReachedHdl = Link();
569cdf0e10cSrcweir     maScrolledHdl   = Link();
570cdf0e10cSrcweir 
571cdf0e10cSrcweir     EndListeningAll();
572cdf0e10cSrcweir }
573cdf0e10cSrcweir 
ScrollDown(ScrollType eScroll)574cdf0e10cSrcweir void LicenseView::ScrollDown( ScrollType eScroll )
575cdf0e10cSrcweir {
576cdf0e10cSrcweir     ScrollBar*  pScroll = GetVScrollBar();
577cdf0e10cSrcweir 
578cdf0e10cSrcweir     if ( pScroll )
579cdf0e10cSrcweir         pScroll->DoScrollAction( eScroll );
580cdf0e10cSrcweir }
581cdf0e10cSrcweir 
IsEndReached() const582cdf0e10cSrcweir sal_Bool LicenseView::IsEndReached() const
583cdf0e10cSrcweir {
584cdf0e10cSrcweir     sal_Bool bEndReached;
585cdf0e10cSrcweir 
586cdf0e10cSrcweir     ExtTextView*    pView = GetTextView();
587cdf0e10cSrcweir     ExtTextEngine*  pEdit = GetTextEngine();
588cdf0e10cSrcweir     sal_uLong           nHeight = pEdit->GetTextHeight();
589cdf0e10cSrcweir     Size            aOutSize = pView->GetWindow()->GetOutputSizePixel();
590cdf0e10cSrcweir     Point           aBottom( 0, aOutSize.Height() );
591cdf0e10cSrcweir 
592cdf0e10cSrcweir     if ( (sal_uLong) pView->GetDocPos( aBottom ).Y() >= nHeight - 1 )
593cdf0e10cSrcweir         bEndReached = sal_True;
594cdf0e10cSrcweir     else
595cdf0e10cSrcweir         bEndReached = sal_False;
596cdf0e10cSrcweir 
597cdf0e10cSrcweir     return bEndReached;
598cdf0e10cSrcweir }
599cdf0e10cSrcweir 
Notify(SfxBroadcaster &,const SfxHint & rHint)600cdf0e10cSrcweir void LicenseView::Notify( SfxBroadcaster&, const SfxHint& rHint )
601cdf0e10cSrcweir {
602cdf0e10cSrcweir     if ( rHint.IsA( TYPE(TextHint) ) )
603cdf0e10cSrcweir     {
604cdf0e10cSrcweir         sal_Bool    bLastVal = EndReached();
605cdf0e10cSrcweir         sal_uLong   nId = ((const TextHint&)rHint).GetId();
606cdf0e10cSrcweir 
607cdf0e10cSrcweir         if ( nId == TEXT_HINT_PARAINSERTED )
608cdf0e10cSrcweir         {
609cdf0e10cSrcweir             if ( bLastVal )
610cdf0e10cSrcweir                 mbEndReached = IsEndReached();
611cdf0e10cSrcweir         }
612cdf0e10cSrcweir         else if ( nId == TEXT_HINT_VIEWSCROLLED )
613cdf0e10cSrcweir         {
614cdf0e10cSrcweir             if ( ! mbEndReached )
615cdf0e10cSrcweir                 mbEndReached = IsEndReached();
616cdf0e10cSrcweir             maScrolledHdl.Call( this );
617cdf0e10cSrcweir         }
618cdf0e10cSrcweir 
619cdf0e10cSrcweir         if ( EndReached() && !bLastVal )
620cdf0e10cSrcweir         {
621cdf0e10cSrcweir             maEndReachedHdl.Call( this );
622cdf0e10cSrcweir         }
623cdf0e10cSrcweir     }
624cdf0e10cSrcweir }
625cdf0e10cSrcweir 
626cdf0e10cSrcweir }		//	namespace framework
627cdf0e10cSrcweir 
628