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