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 = VclPtr<ScShareTable>::Create(*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, HeaderBarItemBits::LEFT | HeaderBarItemBits::LEFTIMAGE | HeaderBarItemBits::VCENTER );
104 0 : m_pLbUsers->SetSelectionMode( NO_SELECTION );
105 :
106 0 : UpdateView();
107 0 : }
108 :
109 0 : ScShareDocumentDlg::~ScShareDocumentDlg()
110 : {
111 0 : disposeOnce();
112 0 : }
113 :
114 0 : void ScShareDocumentDlg::dispose()
115 : {
116 0 : m_pLbUsers.disposeAndClear();
117 0 : m_pCbShare.clear();
118 0 : m_pFtWarning.clear();
119 0 : ModalDialog::dispose();
120 0 : }
121 :
122 0 : IMPL_LINK_NOARG(ScShareDocumentDlg, ToggleHandle)
123 : {
124 0 : m_pFtWarning->Enable( m_pCbShare->IsChecked() );
125 :
126 0 : return 0;
127 : }
128 :
129 0 : bool ScShareDocumentDlg::IsShareDocumentChecked() const
130 : {
131 0 : return m_pCbShare->IsChecked();
132 : }
133 :
134 0 : void ScShareDocumentDlg::UpdateView()
135 : {
136 0 : if ( !mpDocShell )
137 : {
138 0 : return;
139 : }
140 :
141 0 : if ( mpDocShell->IsDocShared() )
142 : {
143 : try
144 : {
145 0 : ::svt::ShareControlFile aControlFile( mpDocShell->GetSharedFileURL() );
146 0 : std::vector<LockFileEntry> aUsersData = aControlFile.GetUsersData();
147 0 : sal_Int32 nLength = aUsersData.size();
148 :
149 0 : if ( nLength > 0 )
150 : {
151 0 : sal_Int32 nUnknownUser = 1;
152 :
153 0 : for ( sal_Int32 i = 0; i < nLength; ++i )
154 : {
155 0 : if ( !aUsersData[i][LockFileComponent::EDITTIME].isEmpty() )
156 : {
157 0 : OUString aUser;
158 0 : if ( !aUsersData[i][LockFileComponent::OOOUSERNAME].isEmpty() )
159 : {
160 0 : aUser = aUsersData[i][LockFileComponent::OOOUSERNAME];
161 : }
162 0 : else if ( !aUsersData[i][LockFileComponent::SYSUSERNAME].isEmpty() )
163 : {
164 0 : aUser = aUsersData[i][LockFileComponent::SYSUSERNAME];
165 : }
166 : else
167 : {
168 0 : aUser = m_aStrUnknownUser + " " + OUString::number( nUnknownUser++ );
169 : }
170 :
171 : // parse the edit time string of the format "DD.MM.YYYY hh:mm"
172 0 : OUString aDateTimeStr = aUsersData[i][LockFileComponent::EDITTIME];
173 0 : sal_Int32 nIndex = 0;
174 0 : OUString aDateStr = aDateTimeStr.getToken( 0, ' ', nIndex );
175 0 : OUString aTimeStr = aDateTimeStr.getToken( 0, ' ', nIndex );
176 0 : nIndex = 0;
177 0 : sal_uInt16 nDay = sal::static_int_cast< sal_uInt16 >( aDateStr.getToken( 0, '.', nIndex ).toInt32() );
178 0 : sal_uInt16 nMonth = sal::static_int_cast< sal_uInt16 >( aDateStr.getToken( 0, '.', nIndex ).toInt32() );
179 0 : sal_uInt16 nYear = sal::static_int_cast< sal_uInt16 >( aDateStr.getToken( 0, '.', nIndex ).toInt32() );
180 0 : nIndex = 0;
181 0 : sal_uInt16 nHours = sal::static_int_cast< sal_uInt16 >( aTimeStr.getToken( 0, ':', nIndex ).toInt32() );
182 0 : sal_uInt16 nMinutes = sal::static_int_cast< sal_uInt16 >( aTimeStr.getToken( 0, ':', nIndex ).toInt32() );
183 0 : Date aDate( nDay, nMonth, nYear );
184 0 : tools::Time aTime( nHours, nMinutes );
185 0 : DateTime aDateTime( aDate, aTime );
186 :
187 0 : OUString aString( aUser );
188 0 : aString += "\t";
189 0 : aString += formatTime(aDateTime, *ScGlobal::pLocaleData);
190 :
191 0 : m_pLbUsers->InsertEntry( aString, NULL );
192 : }
193 : }
194 : }
195 : else
196 : {
197 0 : m_pLbUsers->InsertEntry( m_aStrNoUserData, NULL );
198 0 : }
199 : }
200 0 : catch ( uno::Exception& )
201 : {
202 : OSL_FAIL( "ScShareDocumentDlg::UpdateView(): caught exception\n" );
203 0 : m_pLbUsers->Clear();
204 0 : m_pLbUsers->InsertEntry( m_aStrNoUserData, NULL );
205 : }
206 : }
207 : else
208 : {
209 : // get OOO user name
210 0 : SvtUserOptions aUserOpt;
211 0 : OUString aUser = aUserOpt.GetFirstName();
212 0 : if ( !aUser.isEmpty() )
213 : {
214 0 : aUser += " ";
215 : }
216 0 : aUser += aUserOpt.GetLastName();
217 0 : if ( aUser.isEmpty() )
218 : {
219 : // get sys user name
220 0 : OUString aUserName;
221 0 : ::osl::Security aSecurity;
222 0 : aSecurity.getUserName( aUserName );
223 0 : aUser = aUserName;
224 : }
225 0 : if ( aUser.isEmpty() )
226 : {
227 : // unknown user name
228 0 : aUser = m_aStrUnknownUser;
229 : }
230 0 : aUser += " ";
231 0 : aUser += m_aStrExclusiveAccess;
232 0 : OUString aString = aUser + "\t";
233 :
234 0 : uno::Reference<document::XDocumentPropertiesSupplier> xDPS(mpDocShell->GetModel(), uno::UNO_QUERY_THROW);
235 0 : uno::Reference<document::XDocumentProperties> xDocProps = xDPS->getDocumentProperties();
236 :
237 0 : util::DateTime uDT(xDocProps->getModificationDate());
238 0 : DateTime aDateTime(uDT);
239 :
240 0 : aString += formatTime(aDateTime, *ScGlobal::pLocaleData);
241 0 : aString += " ";
242 0 : aString += ScGlobal::pLocaleData->getTime( aDateTime, false );
243 :
244 0 : m_pLbUsers->InsertEntry( aString, NULL );
245 : }
246 156 : }
247 :
248 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|