LCOV - code coverage report
Current view: top level - sc/source/ui/miscdlgs - sharedocdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 95 0.0 %
Date: 2012-08-25 Functions: 0 7 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 272 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 <osl/security.hxx>
      30                 :            : #include <svl/sharecontrolfile.hxx>
      31                 :            : #include <unotools/useroptions.hxx>
      32                 :            : 
      33                 :            : #include <docsh.hxx>
      34                 :            : 
      35                 :            : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
      36                 :            : #include <com/sun/star/document/XDocumentProperties.hpp>
      37                 :            : 
      38                 :            : 
      39                 :            : #include "sharedocdlg.hxx"
      40                 :            : #include "sharedocdlg.hrc"
      41                 :            : #include "scresid.hxx"
      42                 :            : #include "docsh.hxx"
      43                 :            : #include "viewdata.hxx"
      44                 :            : 
      45                 :            : 
      46                 :            : using namespace ::com::sun::star;
      47                 :            : 
      48                 :            : 
      49                 :            : //=============================================================================
      50                 :            : // class ScShareDocumentDlg
      51                 :            : //=============================================================================
      52                 :            : 
      53                 :          0 : ScShareDocumentDlg::ScShareDocumentDlg( Window* pParent, ScViewData* pViewData )
      54                 :            :     :ModalDialog( pParent, ScResId( RID_SCDLG_SHAREDOCUMENT ) )
      55                 :            :     ,maCbShare            ( this, ScResId( CB_SHARE ) )
      56                 :            :     ,maFtWarning          ( this, ScResId( FT_WARNING ) )
      57                 :            :     ,maFlUsers            ( this, ScResId( FL_USERS ) )
      58                 :            :     ,maFtUsers            ( this, ScResId( FT_USERS ) )
      59                 :            :     ,m_aLbUsersContainer(this, ScResId(LB_USERS))
      60                 :            :     ,maLbUsers(m_aLbUsersContainer)
      61                 :            :     ,maFlEnd              ( this, ScResId( FL_END ) )
      62                 :            :     ,maBtnHelp            ( this, ScResId( BTN_HELP ) )
      63                 :            :     ,maBtnOK              ( this, ScResId( BTN_OK ) )
      64                 :            :     ,maBtnCancel          ( this, ScResId( BTN_CANCEL ) )
      65                 :            :     ,maStrTitleName       ( ScResId( STR_TITLE_NAME ) )
      66                 :            :     ,maStrTitleAccessed   ( ScResId( STR_TITLE_ACCESSED ) )
      67                 :            :     ,maStrNoUserData      ( ScResId( STR_NO_USER_DATA ) )
      68                 :            :     ,maStrUnkownUser      ( ScResId( STR_UNKNOWN_USER ) )
      69                 :            :     ,maStrExclusiveAccess ( ScResId( STR_EXCLUSIVE_ACCESS ) )
      70                 :            :     ,mpViewData           ( pViewData )
      71 [ #  # ][ #  # ]:          0 :     ,mpDocShell           ( NULL )
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      72                 :            : {
      73                 :            :     OSL_ENSURE( mpViewData, "ScShareDocumentDlg CTOR: mpViewData is null!" );
      74         [ #  # ]:          0 :     mpDocShell = ( mpViewData ? mpViewData->GetDocShell() : NULL );
      75                 :            :     OSL_ENSURE( mpDocShell, "ScShareDocumentDlg CTOR: mpDocShell is null!" );
      76                 :            : 
      77         [ #  # ]:          0 :     FreeResource();
      78                 :            : 
      79 [ #  # ][ #  # ]:          0 :     bool bIsDocShared = ( mpDocShell ? mpDocShell->IsDocShared() : false );
                 [ #  # ]
      80         [ #  # ]:          0 :     maCbShare.Check( bIsDocShared );
      81         [ #  # ]:          0 :     maCbShare.SetToggleHdl( LINK( this, ScShareDocumentDlg, ToggleHandle ) );
      82         [ #  # ]:          0 :     maFtWarning.Enable( bIsDocShared );
      83                 :            : 
      84                 :          0 :     long nTabs[] = { 2, 10, 128 };
      85         [ #  # ]:          0 :     maLbUsers.SetTabs( nTabs );
      86                 :            : 
      87         [ #  # ]:          0 :     String aHeader( maStrTitleName );
      88         [ #  # ]:          0 :     aHeader += '\t';
      89         [ #  # ]:          0 :     aHeader += maStrTitleAccessed;
      90 [ #  # ][ #  # ]:          0 :     maLbUsers.InsertHeaderEntry( aHeader, HEADERBAR_APPEND, HIB_LEFT | HIB_LEFTIMAGE | HIB_VCENTER );
      91         [ #  # ]:          0 :     maLbUsers.SetSelectionMode( NO_SELECTION );
      92                 :            : 
      93 [ #  # ][ #  # ]:          0 :     UpdateView();
      94                 :          0 : }
      95                 :            : 
      96 [ #  # ][ #  # ]:          0 : ScShareDocumentDlg::~ScShareDocumentDlg()
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      97                 :            : {
      98         [ #  # ]:          0 : }
      99                 :            : 
     100                 :          0 : IMPL_LINK_NOARG(ScShareDocumentDlg, ToggleHandle)
     101                 :            : {
     102                 :          0 :     maFtWarning.Enable( maCbShare.IsChecked() );
     103                 :            : 
     104                 :          0 :     return 0;
     105                 :            : }
     106                 :            : 
     107                 :          0 : bool ScShareDocumentDlg::IsShareDocumentChecked() const
     108                 :            : {
     109                 :          0 :     return maCbShare.IsChecked();
     110                 :            : }
     111                 :            : 
     112                 :          0 : void ScShareDocumentDlg::UpdateView()
     113                 :            : {
     114         [ #  # ]:          0 :     if ( !mpDocShell )
     115                 :            :     {
     116                 :          0 :         return;
     117                 :            :     }
     118                 :            : 
     119         [ #  # ]:          0 :     if ( mpDocShell->IsDocShared() )
     120                 :            :     {
     121                 :            :         try
     122                 :            :         {
     123 [ #  # ][ #  # ]:          0 :             ::svt::ShareControlFile aControlFile( mpDocShell->GetSharedFileURL() );
     124         [ #  # ]:          0 :             uno::Sequence< uno::Sequence< ::rtl::OUString > > aUsersData = aControlFile.GetUsersData();
     125                 :          0 :             const uno::Sequence< ::rtl::OUString >* pUsersData = aUsersData.getConstArray();
     126                 :          0 :             sal_Int32 nLength = aUsersData.getLength();
     127                 :            : 
     128         [ #  # ]:          0 :             if ( nLength > 0 )
     129                 :            :             {
     130                 :          0 :                 sal_Int32 nUnknownUser = 1;
     131                 :            : 
     132         [ #  # ]:          0 :                 for ( sal_Int32 i = 0; i < nLength; ++i )
     133                 :            :                 {
     134         [ #  # ]:          0 :                     if ( pUsersData[i].getLength() > SHARED_EDITTIME_ID )
     135                 :            :                     {
     136         [ #  # ]:          0 :                         String aUser;
     137         [ #  # ]:          0 :                         if ( !pUsersData[i][SHARED_OOOUSERNAME_ID].isEmpty() )
     138                 :            :                         {
     139         [ #  # ]:          0 :                             aUser = pUsersData[i][SHARED_OOOUSERNAME_ID];
     140                 :            :                         }
     141         [ #  # ]:          0 :                         else if ( !pUsersData[i][SHARED_SYSUSERNAME_ID].isEmpty() )
     142                 :            :                         {
     143         [ #  # ]:          0 :                             aUser = pUsersData[i][SHARED_SYSUSERNAME_ID];
     144                 :            :                         }
     145                 :            :                         else
     146                 :            :                         {
     147         [ #  # ]:          0 :                             aUser = maStrUnkownUser;
     148         [ #  # ]:          0 :                             aUser += ' ';
     149 [ #  # ][ #  # ]:          0 :                             aUser += String::CreateFromInt32( nUnknownUser++ );
                 [ #  # ]
     150                 :            :                         }
     151                 :            : 
     152                 :            :                         // parse the edit time string of the format "DD.MM.YYYY hh:mm"
     153                 :          0 :                         ::rtl::OUString aDateTimeStr = pUsersData[i][SHARED_EDITTIME_ID];
     154                 :          0 :                         sal_Int32 nIndex = 0;
     155                 :          0 :                         ::rtl::OUString aDateStr = aDateTimeStr.getToken( 0, ' ', nIndex );
     156                 :          0 :                         ::rtl::OUString aTimeStr = aDateTimeStr.getToken( 0, ' ', nIndex );
     157                 :          0 :                         nIndex = 0;
     158                 :          0 :                         sal_uInt16 nDay = sal::static_int_cast< sal_uInt16 >( aDateStr.getToken( 0, '.', nIndex ).toInt32() );
     159                 :          0 :                         sal_uInt16 nMonth = sal::static_int_cast< sal_uInt16 >( aDateStr.getToken( 0, '.', nIndex ).toInt32() );
     160                 :          0 :                         sal_uInt16 nYear = sal::static_int_cast< sal_uInt16 >( aDateStr.getToken( 0, '.', nIndex ).toInt32() );
     161                 :          0 :                         nIndex = 0;
     162                 :          0 :                         sal_uInt16 nHours = sal::static_int_cast< sal_uInt16 >( aTimeStr.getToken( 0, ':', nIndex ).toInt32() );
     163                 :          0 :                         sal_uInt16 nMinutes = sal::static_int_cast< sal_uInt16 >( aTimeStr.getToken( 0, ':', nIndex ).toInt32() );
     164                 :          0 :                         Date aDate( nDay, nMonth, nYear );
     165         [ #  # ]:          0 :                         Time aTime( nHours, nMinutes );
     166         [ #  # ]:          0 :                         DateTime aDateTime( aDate, aTime );
     167                 :            : 
     168         [ #  # ]:          0 :                         String aString( aUser );
     169         [ #  # ]:          0 :                         aString += '\t';
     170 [ #  # ][ #  # ]:          0 :                         aString += ScGlobal::pLocaleData->getDate( aDateTime );
     171         [ #  # ]:          0 :                         aString += ' ';
     172 [ #  # ][ #  # ]:          0 :                         aString += ScGlobal::pLocaleData->getTime( aDateTime, false );
     173                 :            : 
     174 [ #  # ][ #  # ]:          0 :                         maLbUsers.InsertEntry( aString, NULL );
                 [ #  # ]
     175                 :            :                     }
     176                 :            :                 }
     177                 :            :             }
     178                 :            :             else
     179                 :            :             {
     180         [ #  # ]:          0 :                 maLbUsers.InsertEntry( maStrNoUserData, NULL );
     181 [ #  # ][ #  # ]:          0 :             }
     182                 :            :         }
     183         [ #  # ]:          0 :         catch ( uno::Exception& )
     184                 :            :         {
     185                 :            :             OSL_FAIL( "ScShareDocumentDlg::UpdateView(): caught exception\n" );
     186         [ #  # ]:          0 :             maLbUsers.Clear();
     187         [ #  # ]:          0 :             maLbUsers.InsertEntry( maStrNoUserData, NULL );
     188                 :            :         }
     189                 :            :     }
     190                 :            :     else
     191                 :            :     {
     192                 :            :         // get OOO user name
     193         [ #  # ]:          0 :         SvtUserOptions aUserOpt;
     194 [ #  # ][ #  # ]:          0 :         String aUser = aUserOpt.GetFirstName();
     195         [ #  # ]:          0 :         if ( aUser.Len() > 0 )
     196                 :            :         {
     197         [ #  # ]:          0 :             aUser += ' ';
     198                 :            :         }
     199 [ #  # ][ #  # ]:          0 :         aUser += String(aUserOpt.GetLastName());
         [ #  # ][ #  # ]
     200         [ #  # ]:          0 :         if ( aUser.Len() == 0 )
     201                 :            :         {
     202                 :            :             // get sys user name
     203                 :          0 :             ::rtl::OUString aUserName;
     204         [ #  # ]:          0 :             ::osl::Security aSecurity;
     205         [ #  # ]:          0 :             aSecurity.getUserName( aUserName );
     206 [ #  # ][ #  # ]:          0 :             aUser = aUserName;
     207                 :            :         }
     208         [ #  # ]:          0 :         if ( aUser.Len() == 0 )
     209                 :            :         {
     210                 :            :             // unknown user name
     211         [ #  # ]:          0 :             aUser = maStrUnkownUser;
     212                 :            :         }
     213         [ #  # ]:          0 :         aUser += ' ';
     214         [ #  # ]:          0 :         aUser += maStrExclusiveAccess;
     215         [ #  # ]:          0 :         String aString( aUser );
     216         [ #  # ]:          0 :         aString += '\t';
     217                 :            : 
     218 [ #  # ][ #  # ]:          0 :         uno::Reference<document::XDocumentPropertiesSupplier> xDPS(mpDocShell->GetModel(), uno::UNO_QUERY_THROW);
     219 [ #  # ][ #  # ]:          0 :         uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties();
     220                 :            : 
     221 [ #  # ][ #  # ]:          0 :         util::DateTime uDT(xDocProps->getModificationDate());
     222                 :          0 :         Date d(uDT.Day, uDT.Month, uDT.Year);
     223         [ #  # ]:          0 :         Time t(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds);
     224         [ #  # ]:          0 :         DateTime aDateTime(d,t);
     225                 :            : 
     226 [ #  # ][ #  # ]:          0 :         aString += ScGlobal::pLocaleData->getDate( aDateTime );
     227         [ #  # ]:          0 :         aString += ' ';
     228 [ #  # ][ #  # ]:          0 :         aString += ScGlobal::pLocaleData->getTime( aDateTime, false );
     229                 :            : 
     230 [ #  # ][ #  # ]:          0 :         maLbUsers.InsertEntry( aString, NULL );
         [ #  # ][ #  # ]
     231                 :            :     }
     232                 :            : }
     233                 :            : 
     234                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10