1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sc.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir //----------------------------------------------------------------------------- 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <osl/security.hxx> 34*cdf0e10cSrcweir #include <svl/sharecontrolfile.hxx> 35*cdf0e10cSrcweir #include <unotools/useroptions.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include <docsh.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/document/XDocumentProperties.hpp> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #include "sharedocdlg.hxx" 44*cdf0e10cSrcweir #include "sharedocdlg.hrc" 45*cdf0e10cSrcweir #include "scresid.hxx" 46*cdf0e10cSrcweir #include "docsh.hxx" 47*cdf0e10cSrcweir #include "viewdata.hxx" 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir using namespace ::com::sun::star; 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir //============================================================================= 54*cdf0e10cSrcweir // class ScShareDocumentDlg 55*cdf0e10cSrcweir //============================================================================= 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir ScShareDocumentDlg::ScShareDocumentDlg( Window* pParent, ScViewData* pViewData ) 58*cdf0e10cSrcweir :ModalDialog( pParent, ScResId( RID_SCDLG_SHAREDOCUMENT ) ) 59*cdf0e10cSrcweir ,maCbShare ( this, ScResId( CB_SHARE ) ) 60*cdf0e10cSrcweir ,maFtWarning ( this, ScResId( FT_WARNING ) ) 61*cdf0e10cSrcweir ,maFlUsers ( this, ScResId( FL_USERS ) ) 62*cdf0e10cSrcweir ,maFtUsers ( this, ScResId( FT_USERS ) ) 63*cdf0e10cSrcweir ,maLbUsers ( this, ScResId( LB_USERS ) ) 64*cdf0e10cSrcweir ,maFlEnd ( this, ScResId( FL_END ) ) 65*cdf0e10cSrcweir ,maBtnHelp ( this, ScResId( BTN_HELP ) ) 66*cdf0e10cSrcweir ,maBtnOK ( this, ScResId( BTN_OK ) ) 67*cdf0e10cSrcweir ,maBtnCancel ( this, ScResId( BTN_CANCEL ) ) 68*cdf0e10cSrcweir ,maStrTitleName ( ScResId( STR_TITLE_NAME ) ) 69*cdf0e10cSrcweir ,maStrTitleAccessed ( ScResId( STR_TITLE_ACCESSED ) ) 70*cdf0e10cSrcweir ,maStrNoUserData ( ScResId( STR_NO_USER_DATA ) ) 71*cdf0e10cSrcweir ,maStrUnkownUser ( ScResId( STR_UNKNOWN_USER ) ) 72*cdf0e10cSrcweir ,maStrExclusiveAccess ( ScResId( STR_EXCLUSIVE_ACCESS ) ) 73*cdf0e10cSrcweir ,mpViewData ( pViewData ) 74*cdf0e10cSrcweir ,mpDocShell ( NULL ) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir DBG_ASSERT( mpViewData, "ScShareDocumentDlg CTOR: mpViewData is null!" ); 77*cdf0e10cSrcweir mpDocShell = ( mpViewData ? mpViewData->GetDocShell() : NULL ); 78*cdf0e10cSrcweir DBG_ASSERT( mpDocShell, "ScShareDocumentDlg CTOR: mpDocShell is null!" ); 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir FreeResource(); 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir bool bIsDocShared = ( mpDocShell ? mpDocShell->IsDocShared() : false ); 83*cdf0e10cSrcweir maCbShare.Check( bIsDocShared ); 84*cdf0e10cSrcweir maCbShare.SetToggleHdl( LINK( this, ScShareDocumentDlg, ToggleHandle ) ); 85*cdf0e10cSrcweir maFtWarning.Enable( bIsDocShared ); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir long nTabs[] = { 2, 10, 128 }; 88*cdf0e10cSrcweir maLbUsers.SetTabs( nTabs ); 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir String aHeader( maStrTitleName ); 91*cdf0e10cSrcweir aHeader += '\t'; 92*cdf0e10cSrcweir aHeader += maStrTitleAccessed; 93*cdf0e10cSrcweir maLbUsers.InsertHeaderEntry( aHeader, HEADERBAR_APPEND, HIB_LEFT | HIB_LEFTIMAGE | HIB_VCENTER ); 94*cdf0e10cSrcweir maLbUsers.SetSelectionMode( NO_SELECTION ); 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir UpdateView(); 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir ScShareDocumentDlg::~ScShareDocumentDlg() 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir } 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir IMPL_LINK( ScShareDocumentDlg, ToggleHandle, void*, EMPTYARG ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir maFtWarning.Enable( maCbShare.IsChecked() ); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir return 0; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir bool ScShareDocumentDlg::IsShareDocumentChecked() const 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir return maCbShare.IsChecked(); 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir void ScShareDocumentDlg::UpdateView() 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir if ( !mpDocShell ) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir return; 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir if ( mpDocShell->IsDocShared() ) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir try 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir ::svt::ShareControlFile aControlFile( mpDocShell->GetSharedFileURL() ); 127*cdf0e10cSrcweir uno::Sequence< uno::Sequence< ::rtl::OUString > > aUsersData = aControlFile.GetUsersData(); 128*cdf0e10cSrcweir const uno::Sequence< ::rtl::OUString >* pUsersData = aUsersData.getConstArray(); 129*cdf0e10cSrcweir sal_Int32 nLength = aUsersData.getLength(); 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir if ( nLength > 0 ) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir sal_Int32 nUnknownUser = 1; 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nLength; ++i ) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir if ( pUsersData[i].getLength() > SHARED_EDITTIME_ID ) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir String aUser; 140*cdf0e10cSrcweir if ( pUsersData[i][SHARED_OOOUSERNAME_ID].getLength() ) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir aUser = pUsersData[i][SHARED_OOOUSERNAME_ID]; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir else if ( pUsersData[i][SHARED_SYSUSERNAME_ID].getLength() ) 145*cdf0e10cSrcweir { 146*cdf0e10cSrcweir aUser = pUsersData[i][SHARED_SYSUSERNAME_ID]; 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir else 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir aUser = maStrUnkownUser; 151*cdf0e10cSrcweir aUser += ' '; 152*cdf0e10cSrcweir aUser += String::CreateFromInt32( nUnknownUser++ ); 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir // parse the edit time string of the format "DD.MM.YYYY hh:mm" 156*cdf0e10cSrcweir ::rtl::OUString aDateTimeStr = pUsersData[i][SHARED_EDITTIME_ID]; 157*cdf0e10cSrcweir sal_Int32 nIndex = 0; 158*cdf0e10cSrcweir ::rtl::OUString aDateStr = aDateTimeStr.getToken( 0, ' ', nIndex ); 159*cdf0e10cSrcweir ::rtl::OUString aTimeStr = aDateTimeStr.getToken( 0, ' ', nIndex ); 160*cdf0e10cSrcweir nIndex = 0; 161*cdf0e10cSrcweir sal_uInt16 nDay = sal::static_int_cast< sal_uInt16 >( aDateStr.getToken( 0, '.', nIndex ).toInt32() ); 162*cdf0e10cSrcweir sal_uInt16 nMonth = sal::static_int_cast< sal_uInt16 >( aDateStr.getToken( 0, '.', nIndex ).toInt32() ); 163*cdf0e10cSrcweir sal_uInt16 nYear = sal::static_int_cast< sal_uInt16 >( aDateStr.getToken( 0, '.', nIndex ).toInt32() ); 164*cdf0e10cSrcweir nIndex = 0; 165*cdf0e10cSrcweir sal_uInt16 nHours = sal::static_int_cast< sal_uInt16 >( aTimeStr.getToken( 0, ':', nIndex ).toInt32() ); 166*cdf0e10cSrcweir sal_uInt16 nMinutes = sal::static_int_cast< sal_uInt16 >( aTimeStr.getToken( 0, ':', nIndex ).toInt32() ); 167*cdf0e10cSrcweir Date aDate( nDay, nMonth, nYear ); 168*cdf0e10cSrcweir Time aTime( nHours, nMinutes ); 169*cdf0e10cSrcweir DateTime aDateTime( aDate, aTime ); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir String aString( aUser ); 172*cdf0e10cSrcweir aString += '\t'; 173*cdf0e10cSrcweir aString += ScGlobal::pLocaleData->getDate( aDateTime ); 174*cdf0e10cSrcweir aString += ' '; 175*cdf0e10cSrcweir aString += ScGlobal::pLocaleData->getTime( aDateTime, sal_False ); 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir maLbUsers.InsertEntry( aString, NULL ); 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir else 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir maLbUsers.InsertEntry( maStrNoUserData, NULL ); 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir catch ( uno::Exception& ) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir DBG_ERROR( "ScShareDocumentDlg::UpdateView(): caught exception\n" ); 189*cdf0e10cSrcweir maLbUsers.Clear(); 190*cdf0e10cSrcweir maLbUsers.InsertEntry( maStrNoUserData, NULL ); 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir else 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir // get OOO user name 196*cdf0e10cSrcweir SvtUserOptions aUserOpt; 197*cdf0e10cSrcweir String aUser = aUserOpt.GetFirstName(); 198*cdf0e10cSrcweir if ( aUser.Len() > 0 ) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir aUser += ' '; 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir aUser += String(aUserOpt.GetLastName()); 203*cdf0e10cSrcweir if ( aUser.Len() == 0 ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir // get sys user name 206*cdf0e10cSrcweir ::rtl::OUString aUserName; 207*cdf0e10cSrcweir ::osl::Security aSecurity; 208*cdf0e10cSrcweir aSecurity.getUserName( aUserName ); 209*cdf0e10cSrcweir aUser = aUserName; 210*cdf0e10cSrcweir } 211*cdf0e10cSrcweir if ( aUser.Len() == 0 ) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir // unknown user name 214*cdf0e10cSrcweir aUser = maStrUnkownUser; 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir aUser += ' '; 217*cdf0e10cSrcweir aUser += maStrExclusiveAccess; 218*cdf0e10cSrcweir String aString( aUser ); 219*cdf0e10cSrcweir aString += '\t'; 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir uno::Reference<document::XDocumentPropertiesSupplier> xDPS(mpDocShell->GetModel(), uno::UNO_QUERY_THROW); 222*cdf0e10cSrcweir uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties(); 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir util::DateTime uDT(xDocProps->getModificationDate()); 225*cdf0e10cSrcweir Date d(uDT.Day, uDT.Month, uDT.Year); 226*cdf0e10cSrcweir Time t(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds); 227*cdf0e10cSrcweir DateTime aDateTime(d,t); 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir aString += ScGlobal::pLocaleData->getDate( aDateTime ); 230*cdf0e10cSrcweir aString += ' '; 231*cdf0e10cSrcweir aString += ScGlobal::pLocaleData->getTime( aDateTime, sal_False ); 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir maLbUsers.InsertEntry( aString, NULL ); 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir } 236