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