1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <osl/security.hxx>
21 #include <svl/sharecontrolfile.hxx>
22 #include <unotools/useroptions.hxx>
26 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
27 #include <com/sun/star/document/XDocumentProperties.hpp>
30 #include "sharedocdlg.hxx"
31 #include "scresid.hxx"
33 #include "viewdata.hxx"
36 using namespace ::com::sun::star
;
38 class ScShareTable
: public SvxSimpleTable
41 OUString m_sWidestAccessString
;
43 ScShareTable(SvxSimpleTableContainer
& rParent
)
44 : SvxSimpleTable(rParent
)
46 Date
aDate(22, 12, 2000);
48 DateTime
aDateTime(aDate
, aTime
);
49 m_sWidestAccessString
+= ScGlobal::pLocaleData
->getDate(aDateTime
);
50 m_sWidestAccessString
+= OUString(' ');
51 m_sWidestAccessString
+= ScGlobal::pLocaleData
->getTime(aDateTime
, false);
55 SvxSimpleTable::Resize();
56 if (isInitialLayout(this))
61 HeaderBar
&rBar
= GetTheHeaderBar();
62 if (rBar
.GetItemCount() < 2)
65 long nAccessedWidth
= 12 +
66 std::max(rBar
.GetTextWidth(rBar
.GetItemText(2)),
67 GetTextWidth(m_sWidestAccessString
));
68 long nWebSiteWidth
= std::max(
69 12 + rBar
.GetTextWidth(rBar
.GetItemText(1)),
70 GetSizePixel().Width() - nAccessedWidth
);
71 long aStaticTabs
[]= { 2, 0, 0 };
72 aStaticTabs
[2] = nWebSiteWidth
;
73 SvxSimpleTable::SetTabs(aStaticTabs
, MAP_PIXEL
);
77 //=============================================================================
78 // class ScShareDocumentDlg
79 //=============================================================================
81 ScShareDocumentDlg::ScShareDocumentDlg( Window
* pParent
, ScViewData
* pViewData
)
82 : ModalDialog(pParent
, "ShareDocumentDialog", "modules/scalc/ui/sharedocumentdlg.ui")
83 , mpViewData(pViewData
)
86 OSL_ENSURE( mpViewData
, "ScShareDocumentDlg CTOR: mpViewData is null!" );
87 mpDocShell
= ( mpViewData
? mpViewData
->GetDocShell() : NULL
);
88 OSL_ENSURE( mpDocShell
, "ScShareDocumentDlg CTOR: mpDocShell is null!" );
90 get(m_pCbShare
, "share");
91 get(m_pFtWarning
, "warning");
93 SvxSimpleTableContainer
*pCtrl
= get
<SvxSimpleTableContainer
>("users");
94 pCtrl
->set_height_request(pCtrl
->GetTextHeight()*9);
95 m_pLbUsers
= new ScShareTable(*pCtrl
);
97 m_aStrNoUserData
= get
<FixedText
>("nouserdata")->GetText();
98 m_aStrUnknownUser
= get
<FixedText
>("unknownuser")->GetText();
99 m_aStrExclusiveAccess
= get
<FixedText
>("exclusive")->GetText();
101 bool bIsDocShared
= ( mpDocShell
? mpDocShell
->IsDocShared() : false );
102 m_pCbShare
->Check( bIsDocShared
);
103 m_pCbShare
->SetToggleHdl( LINK( this, ScShareDocumentDlg
, ToggleHandle
) );
104 m_pFtWarning
->Enable( bIsDocShared
);
106 long nTabs
[] = { 2, 0, 0 };
107 m_pLbUsers
->SetTabs( nTabs
);
109 String
aHeader(get
<FixedText
>("name")->GetText());
111 aHeader
+= get
<FixedText
>("accessed")->GetText();
112 m_pLbUsers
->InsertHeaderEntry( aHeader
, HEADERBAR_APPEND
, HIB_LEFT
| HIB_LEFTIMAGE
| HIB_VCENTER
);
113 m_pLbUsers
->SetSelectionMode( NO_SELECTION
);
118 ScShareDocumentDlg::~ScShareDocumentDlg()
123 IMPL_LINK_NOARG(ScShareDocumentDlg
, ToggleHandle
)
125 m_pFtWarning
->Enable( m_pCbShare
->IsChecked() );
130 bool ScShareDocumentDlg::IsShareDocumentChecked() const
132 return m_pCbShare
->IsChecked();
135 void ScShareDocumentDlg::UpdateView()
142 if ( mpDocShell
->IsDocShared() )
146 ::svt::ShareControlFile
aControlFile( mpDocShell
->GetSharedFileURL() );
147 uno::Sequence
< uno::Sequence
< OUString
> > aUsersData
= aControlFile
.GetUsersData();
148 const uno::Sequence
< OUString
>* pUsersData
= aUsersData
.getConstArray();
149 sal_Int32 nLength
= aUsersData
.getLength();
153 sal_Int32 nUnknownUser
= 1;
155 for ( sal_Int32 i
= 0; i
< nLength
; ++i
)
157 if ( pUsersData
[i
].getLength() > SHARED_EDITTIME_ID
)
160 if ( !pUsersData
[i
][SHARED_OOOUSERNAME_ID
].isEmpty() )
162 aUser
= pUsersData
[i
][SHARED_OOOUSERNAME_ID
];
164 else if ( !pUsersData
[i
][SHARED_SYSUSERNAME_ID
].isEmpty() )
166 aUser
= pUsersData
[i
][SHARED_SYSUSERNAME_ID
];
170 aUser
= OUString(m_aStrUnknownUser
) + " " + OUString::number( nUnknownUser
++ );
173 // parse the edit time string of the format "DD.MM.YYYY hh:mm"
174 OUString aDateTimeStr
= pUsersData
[i
][SHARED_EDITTIME_ID
];
175 sal_Int32 nIndex
= 0;
176 OUString aDateStr
= aDateTimeStr
.getToken( 0, ' ', nIndex
);
177 OUString aTimeStr
= aDateTimeStr
.getToken( 0, ' ', nIndex
);
179 sal_uInt16 nDay
= sal::static_int_cast
< sal_uInt16
>( aDateStr
.getToken( 0, '.', nIndex
).toInt32() );
180 sal_uInt16 nMonth
= sal::static_int_cast
< sal_uInt16
>( aDateStr
.getToken( 0, '.', nIndex
).toInt32() );
181 sal_uInt16 nYear
= sal::static_int_cast
< sal_uInt16
>( aDateStr
.getToken( 0, '.', nIndex
).toInt32() );
183 sal_uInt16 nHours
= sal::static_int_cast
< sal_uInt16
>( aTimeStr
.getToken( 0, ':', nIndex
).toInt32() );
184 sal_uInt16 nMinutes
= sal::static_int_cast
< sal_uInt16
>( aTimeStr
.getToken( 0, ':', nIndex
).toInt32() );
185 Date
aDate( nDay
, nMonth
, nYear
);
186 Time
aTime( nHours
, nMinutes
);
187 DateTime
aDateTime( aDate
, aTime
);
189 String
aString( aUser
);
191 aString
+= ScGlobal::pLocaleData
->getDate( aDateTime
);
193 aString
+= ScGlobal::pLocaleData
->getTime( aDateTime
, false );
195 m_pLbUsers
->InsertEntry( aString
, NULL
);
201 m_pLbUsers
->InsertEntry( m_aStrNoUserData
, NULL
);
204 catch ( uno::Exception
& )
206 OSL_FAIL( "ScShareDocumentDlg::UpdateView(): caught exception\n" );
208 m_pLbUsers
->InsertEntry( m_aStrNoUserData
, NULL
);
214 SvtUserOptions aUserOpt
;
215 String aUser
= aUserOpt
.GetFirstName();
216 if ( aUser
.Len() > 0 )
220 aUser
+= String(aUserOpt
.GetLastName());
221 if ( aUser
.Len() == 0 )
225 ::osl::Security aSecurity
;
226 aSecurity
.getUserName( aUserName
);
229 if ( aUser
.Len() == 0 )
232 aUser
= m_aStrUnknownUser
;
235 aUser
+= m_aStrExclusiveAccess
;
236 String
aString( aUser
);
239 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(mpDocShell
->GetModel(), uno::UNO_QUERY_THROW
);
240 uno::Reference
<document::XDocumentProperties
> xDocProps
= xDPS
->getDocumentProperties();
242 util::DateTime
uDT(xDocProps
->getModificationDate());
243 Date
d(uDT
.Day
, uDT
.Month
, uDT
.Year
);
244 Time
t(uDT
.Hours
, uDT
.Minutes
, uDT
.Seconds
, uDT
.NanoSeconds
);
245 DateTime
aDateTime(d
,t
);
247 aString
+= ScGlobal::pLocaleData
->getDate( aDateTime
);
249 aString
+= ScGlobal::pLocaleData
->getTime( aDateTime
, false );
251 m_pLbUsers
->InsertEntry( aString
, NULL
);
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */