LCOV - code coverage report
Current view: top level - sc/source/ui/miscdlgs - sharedocdlg.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 121 0.0 %
Date: 2014-04-14 Functions: 0 14 0.0 %
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 <sfx2/dialoghelper.hxx>
      22             : #include <svl/sharecontrolfile.hxx>
      23             : #include <unotools/useroptions.hxx>
      24             : 
      25             : #include <docsh.hxx>
      26             : 
      27             : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
      28             : #include <com/sun/star/document/XDocumentProperties.hpp>
      29             : 
      30             : 
      31             : #include "sharedocdlg.hxx"
      32             : #include "scresid.hxx"
      33             : #include "viewdata.hxx"
      34             : 
      35             : 
      36             : using namespace ::com::sun::star;
      37             : 
      38           0 : class ScShareTable : public SvSimpleTable
      39             : {
      40             : private:
      41             :     OUString m_sWidestAccessString;
      42             : public:
      43           0 :     ScShareTable(SvSimpleTableContainer& rParent)
      44           0 :         : SvSimpleTable(rParent)
      45             :     {
      46           0 :         m_sWidestAccessString = getWidestTime(*ScGlobal::pLocaleData);
      47           0 :     }
      48           0 :     virtual void Resize() SAL_OVERRIDE
      49             :     {
      50           0 :         SvSimpleTable::Resize();
      51           0 :         if (isInitialLayout(this))
      52           0 :             setColWidths();
      53           0 :     }
      54           0 :     void setColWidths()
      55             :     {
      56           0 :         HeaderBar &rBar = GetTheHeaderBar();
      57           0 :         if (rBar.GetItemCount() < 2)
      58           0 :             return;
      59             : 
      60           0 :         long nAccessedWidth = 12 +
      61           0 :             std::max(rBar.GetTextWidth(rBar.GetItemText(2)),
      62           0 :             GetTextWidth(m_sWidestAccessString));
      63             :         long nWebSiteWidth = std::max(
      64           0 :             12 + rBar.GetTextWidth(rBar.GetItemText(1)),
      65           0 :             GetSizePixel().Width() - nAccessedWidth);
      66           0 :         long aStaticTabs[]= { 2, 0, 0 };
      67           0 :         aStaticTabs[2] = nWebSiteWidth;
      68           0 :         SvSimpleTable::SetTabs(aStaticTabs, MAP_PIXEL);
      69             :     }
      70             : };
      71             : 
      72             : 
      73             : // class ScShareDocumentDlg
      74             : 
      75             : 
      76           0 : ScShareDocumentDlg::ScShareDocumentDlg( Window* pParent, ScViewData* pViewData )
      77             :     : ModalDialog(pParent, "ShareDocumentDialog", "modules/scalc/ui/sharedocumentdlg.ui")
      78             :     , mpViewData(pViewData)
      79           0 :     , mpDocShell(NULL)
      80             : {
      81             :     OSL_ENSURE( mpViewData, "ScShareDocumentDlg CTOR: mpViewData is null!" );
      82           0 :     mpDocShell = ( mpViewData ? mpViewData->GetDocShell() : NULL );
      83             :     OSL_ENSURE( mpDocShell, "ScShareDocumentDlg CTOR: mpDocShell is null!" );
      84             : 
      85           0 :     get(m_pCbShare, "share");
      86           0 :     get(m_pFtWarning, "warning");
      87             : 
      88           0 :     SvSimpleTableContainer *pCtrl = get<SvSimpleTableContainer>("users");
      89           0 :     pCtrl->set_height_request(pCtrl->GetTextHeight()*9);
      90           0 :     m_pLbUsers = new ScShareTable(*pCtrl);
      91             : 
      92           0 :     m_aStrNoUserData = get<FixedText>("nouserdata")->GetText();
      93           0 :     m_aStrUnknownUser = get<FixedText>("unknownuser")->GetText();
      94           0 :     m_aStrExclusiveAccess = get<FixedText>("exclusive")->GetText();
      95             : 
      96           0 :     bool bIsDocShared = ( mpDocShell ? mpDocShell->IsDocShared() : false );
      97           0 :     m_pCbShare->Check( bIsDocShared );
      98           0 :     m_pCbShare->SetToggleHdl( LINK( this, ScShareDocumentDlg, ToggleHandle ) );
      99           0 :     m_pFtWarning->Enable( bIsDocShared );
     100             : 
     101           0 :     long nTabs[] = { 2, 0, 0 };
     102           0 :     m_pLbUsers->SetTabs( nTabs );
     103             : 
     104           0 :     OUString aHeader(get<FixedText>("name")->GetText());
     105           0 :     aHeader += "\t";
     106           0 :     aHeader += get<FixedText>("accessed")->GetText();
     107           0 :     m_pLbUsers->InsertHeaderEntry( aHeader, HEADERBAR_APPEND, HIB_LEFT | HIB_LEFTIMAGE | HIB_VCENTER );
     108           0 :     m_pLbUsers->SetSelectionMode( NO_SELECTION );
     109             : 
     110           0 :     UpdateView();
     111           0 : }
     112             : 
     113           0 : ScShareDocumentDlg::~ScShareDocumentDlg()
     114             : {
     115           0 :     delete m_pLbUsers;
     116           0 : }
     117             : 
     118           0 : IMPL_LINK_NOARG(ScShareDocumentDlg, ToggleHandle)
     119             : {
     120           0 :     m_pFtWarning->Enable( m_pCbShare->IsChecked() );
     121             : 
     122           0 :     return 0;
     123             : }
     124             : 
     125           0 : bool ScShareDocumentDlg::IsShareDocumentChecked() const
     126             : {
     127           0 :     return m_pCbShare->IsChecked();
     128             : }
     129             : 
     130           0 : void ScShareDocumentDlg::UpdateView()
     131             : {
     132           0 :     if ( !mpDocShell )
     133             :     {
     134           0 :         return;
     135             :     }
     136             : 
     137           0 :     if ( mpDocShell->IsDocShared() )
     138             :     {
     139             :         try
     140             :         {
     141           0 :             ::svt::ShareControlFile aControlFile( mpDocShell->GetSharedFileURL() );
     142           0 :             uno::Sequence< uno::Sequence< OUString > > aUsersData = aControlFile.GetUsersData();
     143           0 :             const uno::Sequence< OUString >* pUsersData = aUsersData.getConstArray();
     144           0 :             sal_Int32 nLength = aUsersData.getLength();
     145             : 
     146           0 :             if ( nLength > 0 )
     147             :             {
     148           0 :                 sal_Int32 nUnknownUser = 1;
     149             : 
     150           0 :                 for ( sal_Int32 i = 0; i < nLength; ++i )
     151             :                 {
     152           0 :                     if ( pUsersData[i].getLength() > SHARED_EDITTIME_ID )
     153             :                     {
     154           0 :                         OUString aUser;
     155           0 :                         if ( !pUsersData[i][SHARED_OOOUSERNAME_ID].isEmpty() )
     156             :                         {
     157           0 :                             aUser = pUsersData[i][SHARED_OOOUSERNAME_ID];
     158             :                         }
     159           0 :                         else if ( !pUsersData[i][SHARED_SYSUSERNAME_ID].isEmpty() )
     160             :                         {
     161           0 :                             aUser = pUsersData[i][SHARED_SYSUSERNAME_ID];
     162             :                         }
     163             :                         else
     164             :                         {
     165           0 :                             aUser = OUString(m_aStrUnknownUser) + " " + OUString::number( nUnknownUser++ );
     166             :                         }
     167             : 
     168             :                         // parse the edit time string of the format "DD.MM.YYYY hh:mm"
     169           0 :                         OUString aDateTimeStr = pUsersData[i][SHARED_EDITTIME_ID];
     170           0 :                         sal_Int32 nIndex = 0;
     171           0 :                         OUString aDateStr = aDateTimeStr.getToken( 0, ' ', nIndex );
     172           0 :                         OUString aTimeStr = aDateTimeStr.getToken( 0, ' ', nIndex );
     173           0 :                         nIndex = 0;
     174           0 :                         sal_uInt16 nDay = sal::static_int_cast< sal_uInt16 >( aDateStr.getToken( 0, '.', nIndex ).toInt32() );
     175           0 :                         sal_uInt16 nMonth = sal::static_int_cast< sal_uInt16 >( aDateStr.getToken( 0, '.', nIndex ).toInt32() );
     176           0 :                         sal_uInt16 nYear = sal::static_int_cast< sal_uInt16 >( aDateStr.getToken( 0, '.', nIndex ).toInt32() );
     177           0 :                         nIndex = 0;
     178           0 :                         sal_uInt16 nHours = sal::static_int_cast< sal_uInt16 >( aTimeStr.getToken( 0, ':', nIndex ).toInt32() );
     179           0 :                         sal_uInt16 nMinutes = sal::static_int_cast< sal_uInt16 >( aTimeStr.getToken( 0, ':', nIndex ).toInt32() );
     180           0 :                         Date aDate( nDay, nMonth, nYear );
     181           0 :                         Time aTime( nHours, nMinutes );
     182           0 :                         DateTime aDateTime( aDate, aTime );
     183             : 
     184           0 :                         OUString aString( aUser );
     185           0 :                         aString += "\t";
     186           0 :                         aString += formatTime(aDateTime, *ScGlobal::pLocaleData);
     187             : 
     188           0 :                         m_pLbUsers->InsertEntry( aString, NULL );
     189             :                     }
     190             :                 }
     191             :             }
     192             :             else
     193             :             {
     194           0 :                 m_pLbUsers->InsertEntry( m_aStrNoUserData, NULL );
     195           0 :             }
     196             :         }
     197           0 :         catch ( uno::Exception& )
     198             :         {
     199             :             OSL_FAIL( "ScShareDocumentDlg::UpdateView(): caught exception\n" );
     200           0 :             m_pLbUsers->Clear();
     201           0 :             m_pLbUsers->InsertEntry( m_aStrNoUserData, NULL );
     202             :         }
     203             :     }
     204             :     else
     205             :     {
     206             :         // get OOO user name
     207           0 :         SvtUserOptions aUserOpt;
     208           0 :         OUString aUser = aUserOpt.GetFirstName();
     209           0 :         if ( !aUser.isEmpty() )
     210             :         {
     211           0 :             aUser += " ";
     212             :         }
     213           0 :         aUser += aUserOpt.GetLastName();
     214           0 :         if ( aUser.isEmpty() )
     215             :         {
     216             :             // get sys user name
     217           0 :             OUString aUserName;
     218           0 :             ::osl::Security aSecurity;
     219           0 :             aSecurity.getUserName( aUserName );
     220           0 :             aUser = aUserName;
     221             :         }
     222           0 :         if ( aUser.isEmpty() )
     223             :         {
     224             :             // unknown user name
     225           0 :             aUser = m_aStrUnknownUser;
     226             :         }
     227           0 :         aUser += " ";
     228           0 :         aUser += m_aStrExclusiveAccess;
     229           0 :         OUString aString = aUser + "\t";
     230             : 
     231           0 :         uno::Reference<document::XDocumentPropertiesSupplier> xDPS(mpDocShell->GetModel(), uno::UNO_QUERY_THROW);
     232           0 :         uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties();
     233             : 
     234           0 :         util::DateTime uDT(xDocProps->getModificationDate());
     235           0 :         Date d(uDT.Day, uDT.Month, uDT.Year);
     236           0 :         Time t(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.NanoSeconds);
     237           0 :         DateTime aDateTime(d,t);
     238             : 
     239           0 :         aString += formatTime(aDateTime, *ScGlobal::pLocaleData);
     240           0 :         aString += " ";
     241           0 :         aString += ScGlobal::pLocaleData->getTime( aDateTime, false );
     242             : 
     243           0 :         m_pLbUsers->InsertEntry( aString, NULL );
     244             :     }
     245           0 : }
     246             : 
     247             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10