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