LCOV - code coverage report
Current view: top level - framework/source/services - license.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 245 0.4 %
Date: 2012-08-25 Functions: 1 44 2.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 554 0.0 %

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

Generated by: LCOV version 1.10