LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/miscdlgs - sharedocdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 96 1.0 %
Date: 2012-12-27 Functions: 2 9 22.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <osl/security.hxx>
      21             : #include <svl/sharecontrolfile.hxx>
      22             : #include <unotools/useroptions.hxx>
      23             : 
      24             : #include <docsh.hxx>
      25             : 
      26             : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
      27             : #include <com/sun/star/document/XDocumentProperties.hpp>
      28             : 
      29             : 
      30             : #include "sharedocdlg.hxx"
      31             : #include "sharedocdlg.hrc"
      32             : #include "scresid.hxx"
      33             : #include "docsh.hxx"
      34             : #include "viewdata.hxx"
      35             : 
      36             : 
      37             : using namespace ::com::sun::star;
      38             : 
      39             : 
      40             : //=============================================================================
      41             : // class ScShareDocumentDlg
      42             : //=============================================================================
      43             : 
      44           0 : ScShareDocumentDlg::ScShareDocumentDlg( Window* pParent, ScViewData* pViewData )
      45             :     :ModalDialog( pParent, ScResId( RID_SCDLG_SHAREDOCUMENT ) )
      46             :     ,maCbShare            ( this, ScResId( CB_SHARE ) )
      47             :     ,maFtWarning          ( this, ScResId( FT_WARNING ) )
      48             :     ,maFlUsers            ( this, ScResId( FL_USERS ) )
      49             :     ,maFtUsers            ( this, ScResId( FT_USERS ) )
      50             :     ,m_aLbUsersContainer(this, ScResId(LB_USERS))
      51             :     ,maLbUsers(m_aLbUsersContainer)
      52             :     ,maFlEnd              ( this, ScResId( FL_END ) )
      53             :     ,maBtnHelp            ( this, ScResId( BTN_HELP ) )
      54             :     ,maBtnOK              ( this, ScResId( BTN_OK ) )
      55             :     ,maBtnCancel          ( this, ScResId( BTN_CANCEL ) )
      56             :     ,maStrTitleName       ( ScResId( STR_TITLE_NAME ) )
      57             :     ,maStrTitleAccessed   ( ScResId( STR_TITLE_ACCESSED ) )
      58             :     ,maStrNoUserData      ( ScResId( STR_NO_USER_DATA ) )
      59             :     ,maStrUnkownUser      ( ScResId( STR_UNKNOWN_USER ) )
      60             :     ,maStrExclusiveAccess ( ScResId( STR_EXCLUSIVE_ACCESS ) )
      61             :     ,mpViewData           ( pViewData )
      62           0 :     ,mpDocShell           ( NULL )
      63             : {
      64             :     OSL_ENSURE( mpViewData, "ScShareDocumentDlg CTOR: mpViewData is null!" );
      65           0 :     mpDocShell = ( mpViewData ? mpViewData->GetDocShell() : NULL );
      66             :     OSL_ENSURE( mpDocShell, "ScShareDocumentDlg CTOR: mpDocShell is null!" );
      67             : 
      68           0 :     FreeResource();
      69             : 
      70           0 :     bool bIsDocShared = ( mpDocShell ? mpDocShell->IsDocShared() : false );
      71           0 :     maCbShare.Check( bIsDocShared );
      72           0 :     maCbShare.SetToggleHdl( LINK( this, ScShareDocumentDlg, ToggleHandle ) );
      73           0 :     maFtWarning.Enable( bIsDocShared );
      74             : 
      75           0 :     long nTabs[] = { 2, 10, 128 };
      76           0 :     maLbUsers.SetTabs( nTabs );
      77             : 
      78           0 :     String aHeader( maStrTitleName );
      79           0 :     aHeader += '\t';
      80           0 :     aHeader += maStrTitleAccessed;
      81           0 :     maLbUsers.InsertHeaderEntry( aHeader, HEADERBAR_APPEND, HIB_LEFT | HIB_LEFTIMAGE | HIB_VCENTER );
      82           0 :     maLbUsers.SetSelectionMode( NO_SELECTION );
      83             : 
      84           0 :     UpdateView();
      85           0 : }
      86             : 
      87           0 : ScShareDocumentDlg::~ScShareDocumentDlg()
      88             : {
      89           0 : }
      90             : 
      91           0 : IMPL_LINK_NOARG(ScShareDocumentDlg, ToggleHandle)
      92             : {
      93           0 :     maFtWarning.Enable( maCbShare.IsChecked() );
      94             : 
      95           0 :     return 0;
      96             : }
      97             : 
      98           0 : bool ScShareDocumentDlg::IsShareDocumentChecked() const
      99             : {
     100           0 :     return maCbShare.IsChecked();
     101             : }
     102             : 
     103           0 : void ScShareDocumentDlg::UpdateView()
     104             : {
     105           0 :     if ( !mpDocShell )
     106             :     {
     107           0 :         return;
     108             :     }
     109             : 
     110           0 :     if ( mpDocShell->IsDocShared() )
     111             :     {
     112             :         try
     113             :         {
     114           0 :             ::svt::ShareControlFile aControlFile( mpDocShell->GetSharedFileURL() );
     115           0 :             uno::Sequence< uno::Sequence< ::rtl::OUString > > aUsersData = aControlFile.GetUsersData();
     116           0 :             const uno::Sequence< ::rtl::OUString >* pUsersData = aUsersData.getConstArray();
     117           0 :             sal_Int32 nLength = aUsersData.getLength();
     118             : 
     119           0 :             if ( nLength > 0 )
     120             :             {
     121           0 :                 sal_Int32 nUnknownUser = 1;
     122             : 
     123           0 :                 for ( sal_Int32 i = 0; i < nLength; ++i )
     124             :                 {
     125           0 :                     if ( pUsersData[i].getLength() > SHARED_EDITTIME_ID )
     126             :                     {
     127           0 :                         String aUser;
     128           0 :                         if ( !pUsersData[i][SHARED_OOOUSERNAME_ID].isEmpty() )
     129             :                         {
     130           0 :                             aUser = pUsersData[i][SHARED_OOOUSERNAME_ID];
     131             :                         }
     132           0 :                         else if ( !pUsersData[i][SHARED_SYSUSERNAME_ID].isEmpty() )
     133             :                         {
     134           0 :                             aUser = pUsersData[i][SHARED_SYSUSERNAME_ID];
     135             :                         }
     136             :                         else
     137             :                         {
     138           0 :                             aUser = maStrUnkownUser;
     139           0 :                             aUser += ' ';
     140           0 :                             aUser += String::CreateFromInt32( nUnknownUser++ );
     141             :                         }
     142             : 
     143             :                         // parse the edit time string of the format "DD.MM.YYYY hh:mm"
     144           0 :                         ::rtl::OUString aDateTimeStr = pUsersData[i][SHARED_EDITTIME_ID];
     145           0 :                         sal_Int32 nIndex = 0;
     146           0 :                         ::rtl::OUString aDateStr = aDateTimeStr.getToken( 0, ' ', nIndex );
     147           0 :                         ::rtl::OUString aTimeStr = aDateTimeStr.getToken( 0, ' ', nIndex );
     148           0 :                         nIndex = 0;
     149           0 :                         sal_uInt16 nDay = sal::static_int_cast< sal_uInt16 >( aDateStr.getToken( 0, '.', nIndex ).toInt32() );
     150           0 :                         sal_uInt16 nMonth = sal::static_int_cast< sal_uInt16 >( aDateStr.getToken( 0, '.', nIndex ).toInt32() );
     151           0 :                         sal_uInt16 nYear = sal::static_int_cast< sal_uInt16 >( aDateStr.getToken( 0, '.', nIndex ).toInt32() );
     152           0 :                         nIndex = 0;
     153           0 :                         sal_uInt16 nHours = sal::static_int_cast< sal_uInt16 >( aTimeStr.getToken( 0, ':', nIndex ).toInt32() );
     154           0 :                         sal_uInt16 nMinutes = sal::static_int_cast< sal_uInt16 >( aTimeStr.getToken( 0, ':', nIndex ).toInt32() );
     155           0 :                         Date aDate( nDay, nMonth, nYear );
     156           0 :                         Time aTime( nHours, nMinutes );
     157           0 :                         DateTime aDateTime( aDate, aTime );
     158             : 
     159           0 :                         String aString( aUser );
     160           0 :                         aString += '\t';
     161           0 :                         aString += ScGlobal::pLocaleData->getDate( aDateTime );
     162           0 :                         aString += ' ';
     163           0 :                         aString += ScGlobal::pLocaleData->getTime( aDateTime, false );
     164             : 
     165           0 :                         maLbUsers.InsertEntry( aString, NULL );
     166             :                     }
     167             :                 }
     168             :             }
     169             :             else
     170             :             {
     171           0 :                 maLbUsers.InsertEntry( maStrNoUserData, NULL );
     172           0 :             }
     173             :         }
     174           0 :         catch ( uno::Exception& )
     175             :         {
     176             :             OSL_FAIL( "ScShareDocumentDlg::UpdateView(): caught exception\n" );
     177           0 :             maLbUsers.Clear();
     178           0 :             maLbUsers.InsertEntry( maStrNoUserData, NULL );
     179             :         }
     180             :     }
     181             :     else
     182             :     {
     183             :         // get OOO user name
     184           0 :         SvtUserOptions aUserOpt;
     185           0 :         String aUser = aUserOpt.GetFirstName();
     186           0 :         if ( aUser.Len() > 0 )
     187             :         {
     188           0 :             aUser += ' ';
     189             :         }
     190           0 :         aUser += String(aUserOpt.GetLastName());
     191           0 :         if ( aUser.Len() == 0 )
     192             :         {
     193             :             // get sys user name
     194           0 :             ::rtl::OUString aUserName;
     195           0 :             ::osl::Security aSecurity;
     196           0 :             aSecurity.getUserName( aUserName );
     197           0 :             aUser = aUserName;
     198             :         }
     199           0 :         if ( aUser.Len() == 0 )
     200             :         {
     201             :             // unknown user name
     202           0 :             aUser = maStrUnkownUser;
     203             :         }
     204           0 :         aUser += ' ';
     205           0 :         aUser += maStrExclusiveAccess;
     206           0 :         String aString( aUser );
     207           0 :         aString += '\t';
     208             : 
     209           0 :         uno::Reference<document::XDocumentPropertiesSupplier> xDPS(mpDocShell->GetModel(), uno::UNO_QUERY_THROW);
     210           0 :         uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties();
     211             : 
     212           0 :         util::DateTime uDT(xDocProps->getModificationDate());
     213           0 :         Date d(uDT.Day, uDT.Month, uDT.Year);
     214           0 :         Time t(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
     215           0 :         DateTime aDateTime(d,t);
     216             : 
     217           0 :         aString += ScGlobal::pLocaleData->getDate( aDateTime );
     218           0 :         aString += ' ';
     219           0 :         aString += ScGlobal::pLocaleData->getTime( aDateTime, false );
     220             : 
     221           0 :         maLbUsers.InsertEntry( aString, NULL );
     222             :     }
     223          15 : }
     224             : 
     225             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10