Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <dialmgr.hxx>
30 : : #include <cuires.hrc>
31 : : #include <sal/macros.h>
32 : : #include <com/sun/star/task/UrlRecord.hpp>
33 : : #include <com/sun/star/task/XPasswordContainer.hpp>
34 : : #include <com/sun/star/task/XMasterPasswordHandling.hpp>
35 : : #include "com/sun/star/task/XUrlContainer.hpp"
36 : : #include <comphelper/processfactory.hxx>
37 : : #include <comphelper/docpasswordrequest.hxx>
38 : : #include "webconninfo.hxx"
39 : : #include "webconninfo.hrc"
40 : :
41 : : using namespace ::com::sun::star;
42 : :
43 : : //........................................................................
44 : : namespace svx
45 : : {
46 : : //........................................................................
47 : :
48 : : // class PasswordTable ---------------------------------------------------
49 : :
50 : 0 : PasswordTable::PasswordTable(SvxSimpleTableContainer& rParent, WinBits nBits)
51 : 0 : : SvxSimpleTable(rParent, nBits | WB_NOINITIALSELECTION)
52 : : {
53 : 0 : }
54 : :
55 : 0 : void PasswordTable::InsertHeaderItem( sal_uInt16 nColumn, const String& rText, HeaderBarItemBits nBits )
56 : : {
57 : 0 : GetTheHeaderBar().InsertItem( nColumn, rText, 0, nBits );
58 : 0 : }
59 : :
60 : 0 : void PasswordTable::ResetTabs()
61 : : {
62 : 0 : SetTabs();
63 : 0 : }
64 : :
65 : 0 : void PasswordTable::Resort( bool bForced )
66 : : {
67 : 0 : sal_uInt16 nColumn = GetSelectedCol();
68 [ # # ][ # # ]: 0 : if ( 0 == nColumn || bForced ) // only the first column is sorted
69 : : {
70 : 0 : HeaderBarItemBits nBits = GetTheHeaderBar().GetItemBits(1);
71 : 0 : sal_Bool bUp = ( ( nBits & HIB_UPARROW ) == HIB_UPARROW );
72 : 0 : SvSortMode eMode = SortAscending;
73 : :
74 [ # # ]: 0 : if ( bUp )
75 : : {
76 : 0 : nBits &= ~HIB_UPARROW;
77 : 0 : nBits |= HIB_DOWNARROW;
78 : 0 : eMode = SortDescending;
79 : : }
80 : : else
81 : : {
82 : 0 : nBits &= ~HIB_DOWNARROW;
83 : 0 : nBits |= HIB_UPARROW;
84 : : }
85 : 0 : GetTheHeaderBar().SetItemBits( 1, nBits );
86 : 0 : SvTreeList* pListModel = GetModel();
87 : 0 : pListModel->SetSortMode( eMode );
88 : 0 : pListModel->Resort();
89 : : }
90 : 0 : }
91 : :
92 : : // class WebConnectionInfoDialog -----------------------------------------
93 : :
94 : : // -----------------------------------------------------------------------
95 : 0 : WebConnectionInfoDialog::WebConnectionInfoDialog( Window* pParent ) :
96 : 0 : ModalDialog( pParent, CUI_RES( RID_SVXDLG_WEBCONNECTION_INFO ) )
97 [ # # ]: 0 : ,m_aNeverShownFI ( this, CUI_RES( FI_NEVERSHOWN ) )
98 [ # # ]: 0 : ,m_aPasswordsLBContainer(this, CUI_RES( LB_PASSWORDS))
99 : : ,m_aPasswordsLB(m_aPasswordsLBContainer)
100 [ # # ]: 0 : ,m_aRemoveBtn ( this, CUI_RES( PB_REMOVE ) )
101 [ # # ]: 0 : ,m_aRemoveAllBtn ( this, CUI_RES( PB_REMOVEALL ) )
102 [ # # ]: 0 : ,m_aChangeBtn ( this, CUI_RES( PB_CHANGE ) )
103 [ # # ]: 0 : ,m_aButtonsFL ( this, CUI_RES( FL_BUTTONS ) )
104 [ # # ]: 0 : ,m_aCloseBtn ( this, CUI_RES( PB_CLOSE ) )
105 [ # # ]: 0 : ,m_aHelpBtn ( this, CUI_RES( PB_HELP ) )
106 [ # # ][ # # ]: 0 : ,m_nPos ( -1 )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
107 : : {
108 : : static long aStaticTabs[]= { 3, 0, 150, 250 };
109 [ # # ]: 0 : m_aPasswordsLB.SetTabs( aStaticTabs );
110 [ # # ]: 0 : m_aPasswordsLB.InsertHeaderItem( 1, CUI_RESSTR( STR_WEBSITE ),
111 [ # # ][ # # ]: 0 : HIB_LEFT | HIB_VCENTER | HIB_FIXEDPOS | HIB_CLICKABLE | HIB_UPARROW );
[ # # ][ # # ]
112 [ # # ]: 0 : m_aPasswordsLB.InsertHeaderItem( 2, CUI_RESSTR( STR_USERNAME ),
113 [ # # ][ # # ]: 0 : HIB_LEFT | HIB_VCENTER | HIB_FIXEDPOS );
[ # # ][ # # ]
114 [ # # ]: 0 : m_aPasswordsLB.ResetTabs();
115 : :
116 [ # # ]: 0 : FreeResource();
117 : :
118 [ # # ]: 0 : m_aPasswordsLB.SetHeaderBarClickHdl( LINK( this, WebConnectionInfoDialog, HeaderBarClickedHdl ) );
119 [ # # ]: 0 : m_aRemoveBtn.SetClickHdl( LINK( this, WebConnectionInfoDialog, RemovePasswordHdl ) );
120 [ # # ]: 0 : m_aRemoveAllBtn.SetClickHdl( LINK( this, WebConnectionInfoDialog, RemoveAllPasswordsHdl ) );
121 [ # # ]: 0 : m_aChangeBtn.SetClickHdl( LINK( this, WebConnectionInfoDialog, ChangePasswordHdl ) );
122 : :
123 : : // one button too small for its text?
124 : 0 : sal_Int32 i = 0;
125 : 0 : long nBtnTextWidth = 0;
126 : 0 : Window* pButtons[] = { &m_aRemoveBtn, &m_aRemoveAllBtn, &m_aChangeBtn };
127 : 0 : Window** pButton = pButtons;
128 : 0 : const sal_Int32 nBCount = SAL_N_ELEMENTS( pButtons );
129 [ # # ]: 0 : for ( ; i < nBCount; ++i, ++pButton )
130 : : {
131 [ # # ][ # # ]: 0 : long nTemp = (*pButton)->GetCtrlTextWidth( (*pButton)->GetText() );
[ # # ]
132 [ # # ]: 0 : if ( nTemp > nBtnTextWidth )
133 : 0 : nBtnTextWidth = nTemp;
134 : : }
135 : 0 : nBtnTextWidth = nBtnTextWidth * 115 / 100; // a little offset
136 [ # # ]: 0 : long nButtonWidth = m_aRemoveBtn.GetSizePixel().Width();
137 [ # # ]: 0 : if ( nBtnTextWidth > nButtonWidth )
138 : : {
139 : : // so make the buttons broader and its control in front of it smaller
140 : 0 : long nDelta = nBtnTextWidth - nButtonWidth;
141 : 0 : pButton = pButtons;
142 [ # # ]: 0 : for ( i = 0; i < nBCount; ++i, ++pButton )
143 : : {
144 [ # # ]: 0 : Point aNewPos = (*pButton)->GetPosPixel();
145 [ # # ]: 0 : if ( &m_aRemoveAllBtn == (*pButton) )
146 : 0 : aNewPos.X() += nDelta;
147 [ # # ]: 0 : else if ( &m_aChangeBtn == (*pButton) )
148 : 0 : aNewPos.X() -= nDelta;
149 [ # # ]: 0 : Size aNewSize = (*pButton)->GetSizePixel();
150 : 0 : aNewSize.Width() += nDelta;
151 [ # # ]: 0 : (*pButton)->SetPosSizePixel( aNewPos, aNewSize );
152 : : }
153 : : }
154 : :
155 [ # # ]: 0 : FillPasswordList();
156 : :
157 [ # # ]: 0 : m_aRemoveBtn.SetClickHdl( LINK( this, WebConnectionInfoDialog, RemovePasswordHdl ) );
158 [ # # ]: 0 : m_aRemoveAllBtn.SetClickHdl( LINK( this, WebConnectionInfoDialog, RemoveAllPasswordsHdl ) );
159 [ # # ]: 0 : m_aChangeBtn.SetClickHdl( LINK( this, WebConnectionInfoDialog, ChangePasswordHdl ) );
160 [ # # ]: 0 : m_aPasswordsLB.SetSelectHdl( LINK( this, WebConnectionInfoDialog, EntrySelectedHdl ) );
161 : :
162 [ # # ]: 0 : m_aRemoveBtn.Enable( sal_False );
163 [ # # ]: 0 : m_aChangeBtn.Enable( sal_False );
164 : :
165 [ # # ]: 0 : HeaderBarClickedHdl( NULL );
166 : 0 : }
167 : :
168 : : // -----------------------------------------------------------------------
169 [ # # ][ # # ]: 0 : WebConnectionInfoDialog::~WebConnectionInfoDialog()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
170 : : {
171 [ # # ]: 0 : }
172 : :
173 : : // -----------------------------------------------------------------------
174 : 0 : IMPL_LINK( WebConnectionInfoDialog, HeaderBarClickedHdl, SvxSimpleTable*, pTable )
175 : : {
176 : 0 : m_aPasswordsLB.Resort( NULL == pTable );
177 : 0 : return 0;
178 : : }
179 : :
180 : : // -----------------------------------------------------------------------
181 : 0 : void WebConnectionInfoDialog::FillPasswordList()
182 : : {
183 : : try
184 : : {
185 : : uno::Reference< task::XMasterPasswordHandling > xMasterPasswd(
186 [ # # ][ # # ]: 0 : comphelper::getProcessServiceFactory()->createInstance(
187 : 0 : rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.task.PasswordContainer" ) ) ),
188 [ # # ][ # # ]: 0 : uno::UNO_QUERY );
[ # # ]
189 : :
190 [ # # ][ # # ]: 0 : if ( xMasterPasswd.is() && xMasterPasswd->isPersistentStoringAllowed() )
[ # # ][ # # ]
[ # # ]
191 : : {
192 [ # # ]: 0 : uno::Reference< task::XPasswordContainer > xPasswdContainer( xMasterPasswd, uno::UNO_QUERY_THROW );
193 : : uno::Reference< task::XInteractionHandler > xInteractionHandler(
194 [ # # ][ # # ]: 0 : comphelper::getProcessServiceFactory()->createInstance(
195 : 0 : rtl::OUString( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.task.InteractionHandler" ) ) ),
196 [ # # ][ # # ]: 0 : uno::UNO_QUERY_THROW );
[ # # ]
197 : :
198 [ # # ][ # # ]: 0 : uno::Sequence< task::UrlRecord > aURLEntries = xPasswdContainer->getAllPersistent( xInteractionHandler );
199 : 0 : sal_Int32 nCount = 0;
200 [ # # ]: 0 : for ( sal_Int32 nURLInd = 0; nURLInd < aURLEntries.getLength(); nURLInd++ )
201 : : {
202 [ # # ][ # # ]: 0 : for ( sal_Int32 nUserInd = 0; nUserInd < aURLEntries[nURLInd].UserList.getLength(); nUserInd++ )
203 : : {
204 [ # # ]: 0 : ::rtl::OUString aUIEntry( aURLEntries[nURLInd].Url );
205 : 0 : aUIEntry += ::rtl::OUString::valueOf( (sal_Unicode)'\t' );
206 [ # # ][ # # ]: 0 : aUIEntry += aURLEntries[nURLInd].UserList[nUserInd].UserName;
207 [ # # ][ # # ]: 0 : SvLBoxEntry* pEntry = m_aPasswordsLB.InsertEntry( aUIEntry );
[ # # ]
208 : 0 : pEntry->SetUserData( (void*)(sal_IntPtr)(nCount++) );
209 : 0 : }
210 : : }
211 : :
212 : : // remember pos of first url container entry.
213 : 0 : m_nPos = nCount;
214 : :
215 : : uno::Reference< task::XUrlContainer > xUrlContainer(
216 [ # # ]: 0 : xPasswdContainer, uno::UNO_QUERY_THROW );
217 : :
218 : : uno::Sequence< rtl::OUString > aUrls
219 [ # # ][ # # ]: 0 : = xUrlContainer->getUrls( sal_True /* OnlyPersistent */ );
220 : :
221 [ # # ]: 0 : for ( sal_Int32 nURLIdx = 0; nURLIdx < aUrls.getLength(); nURLIdx++ )
222 : : {
223 [ # # ]: 0 : ::rtl::OUString aUIEntry( aUrls[ nURLIdx ] );
224 : 0 : aUIEntry += ::rtl::OUString::valueOf( (sal_Unicode)'\t' );
225 [ # # ]: 0 : aUIEntry += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "*" ) );
226 [ # # ][ # # ]: 0 : SvLBoxEntry* pEntry = m_aPasswordsLB.InsertEntry( aUIEntry );
[ # # ]
227 : 0 : pEntry->SetUserData( (void*)(sal_IntPtr)(nCount++) );
228 [ # # ][ # # ]: 0 : }
229 [ # # ]: 0 : }
230 : : }
231 : 0 : catch( uno::Exception& )
232 : : {}
233 : 0 : }
234 : :
235 : : // -----------------------------------------------------------------------
236 : 0 : IMPL_LINK_NOARG(WebConnectionInfoDialog, RemovePasswordHdl)
237 : : {
238 : : try
239 : : {
240 [ # # ]: 0 : SvLBoxEntry* pEntry = m_aPasswordsLB.GetCurEntry();
241 [ # # ]: 0 : if ( pEntry )
242 : : {
243 [ # # ][ # # ]: 0 : ::rtl::OUString aURL = m_aPasswordsLB.GetEntryText( pEntry, 0 );
[ # # ]
244 [ # # ][ # # ]: 0 : ::rtl::OUString aUserName = m_aPasswordsLB.GetEntryText( pEntry, 1 );
[ # # ]
245 : :
246 : : uno::Reference< task::XPasswordContainer > xPasswdContainer(
247 [ # # ][ # # ]: 0 : comphelper::getProcessServiceFactory()->createInstance(
248 : : rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
249 : 0 : "com.sun.star.task.PasswordContainer" ) ) ),
250 [ # # ][ # # ]: 0 : uno::UNO_QUERY_THROW );
[ # # ]
251 : :
252 : 0 : sal_Int32 nPos = (sal_Int32)(sal_IntPtr)pEntry->GetUserData();
253 [ # # ]: 0 : if ( nPos < m_nPos )
254 : : {
255 [ # # ][ # # ]: 0 : xPasswdContainer->removePersistent( aURL, aUserName );
256 : : }
257 : : else
258 : : {
259 : : uno::Reference< task::XUrlContainer > xUrlContainer(
260 [ # # ]: 0 : xPasswdContainer, uno::UNO_QUERY_THROW );
261 [ # # ][ # # ]: 0 : xUrlContainer->removeUrl( aURL );
262 : : }
263 [ # # ][ # # ]: 0 : m_aPasswordsLB.RemoveEntry( pEntry );
264 : : }
265 : : }
266 : 0 : catch( uno::Exception& )
267 : : {}
268 : :
269 : 0 : return 0;
270 : : }
271 : :
272 : : // -----------------------------------------------------------------------
273 : 0 : IMPL_LINK_NOARG(WebConnectionInfoDialog, RemoveAllPasswordsHdl)
274 : : {
275 : : try
276 : : {
277 : : uno::Reference< task::XPasswordContainer > xPasswdContainer(
278 [ # # ][ # # ]: 0 : comphelper::getProcessServiceFactory()->createInstance(
279 : : rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
280 : 0 : "com.sun.star.task.PasswordContainer" ) ) ),
281 [ # # ][ # # ]: 0 : uno::UNO_QUERY_THROW );
[ # # ]
282 : :
283 : : // should the master password be requested before?
284 [ # # ][ # # ]: 0 : xPasswdContainer->removeAllPersistent();
285 : :
286 : : uno::Reference< task::XUrlContainer > xUrlContainer(
287 [ # # ]: 0 : xPasswdContainer, uno::UNO_QUERY_THROW );
288 : : uno::Sequence< rtl::OUString > aUrls
289 [ # # ][ # # ]: 0 : = xUrlContainer->getUrls( sal_True /* OnlyPersistent */ );
290 [ # # ]: 0 : for ( sal_Int32 nURLIdx = 0; nURLIdx < aUrls.getLength(); nURLIdx++ )
291 [ # # ][ # # ]: 0 : xUrlContainer->removeUrl( aUrls[ nURLIdx ] );
[ # # ]
292 : :
293 [ # # ][ # # ]: 0 : m_aPasswordsLB.Clear();
[ # # ]
294 : : }
295 : 0 : catch( uno::Exception& )
296 : : {}
297 : :
298 : 0 : return 0;
299 : : }
300 : :
301 : : // -----------------------------------------------------------------------
302 : 0 : IMPL_LINK_NOARG(WebConnectionInfoDialog, ChangePasswordHdl)
303 : : {
304 : : try
305 : : {
306 [ # # ]: 0 : SvLBoxEntry* pEntry = m_aPasswordsLB.GetCurEntry();
307 [ # # ]: 0 : if ( pEntry )
308 : : {
309 [ # # ][ # # ]: 0 : ::rtl::OUString aURL = m_aPasswordsLB.GetEntryText( pEntry, 0 );
[ # # ]
310 [ # # ][ # # ]: 0 : ::rtl::OUString aUserName = m_aPasswordsLB.GetEntryText( pEntry, 1 );
[ # # ]
311 : :
312 : : ::comphelper::SimplePasswordRequest* pPasswordRequest
313 [ # # ]: 0 : = new ::comphelper::SimplePasswordRequest( task::PasswordRequestMode_PASSWORD_CREATE );
314 [ # # ]: 0 : uno::Reference< task::XInteractionRequest > rRequest( pPasswordRequest );
315 : :
316 : : uno::Reference< task::XInteractionHandler > xInteractionHandler(
317 [ # # ][ # # ]: 0 : comphelper::getProcessServiceFactory()->createInstance(
318 : : rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
319 : 0 : "com.sun.star.task.InteractionHandler" ) ) ),
320 [ # # ][ # # ]: 0 : uno::UNO_QUERY_THROW );
[ # # ]
321 [ # # ][ # # ]: 0 : xInteractionHandler->handle( rRequest );
322 : :
323 [ # # ][ # # ]: 0 : if ( pPasswordRequest->isPassword() )
324 : : {
325 [ # # ][ # # ]: 0 : String aNewPass = pPasswordRequest->getPassword();
326 [ # # ]: 0 : uno::Sequence< ::rtl::OUString > aPasswd( 1 );
327 [ # # ][ # # ]: 0 : aPasswd[0] = aNewPass;
328 : :
329 : : uno::Reference< task::XPasswordContainer > xPasswdContainer(
330 [ # # ][ # # ]: 0 : comphelper::getProcessServiceFactory()->createInstance(
331 : : rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
332 : 0 : "com.sun.star.task.PasswordContainer" ) ) ),
333 [ # # ][ # # ]: 0 : uno::UNO_QUERY_THROW );
[ # # ]
334 [ # # ]: 0 : xPasswdContainer->addPersistent(
335 [ # # ][ # # ]: 0 : aURL, aUserName, aPasswd, xInteractionHandler );
[ # # ]
336 [ # # ]: 0 : }
337 : : }
338 : : }
339 : 0 : catch( uno::Exception& )
340 : : {}
341 : :
342 : 0 : return 0;
343 : : }
344 : :
345 : : // -----------------------------------------------------------------------
346 : 0 : IMPL_LINK_NOARG(WebConnectionInfoDialog, EntrySelectedHdl)
347 : : {
348 : 0 : SvLBoxEntry* pEntry = m_aPasswordsLB.GetCurEntry();
349 [ # # ]: 0 : if ( !pEntry )
350 : : {
351 : 0 : m_aRemoveBtn.Enable( sal_False );
352 : 0 : m_aChangeBtn.Enable( sal_False );
353 : : }
354 : : else
355 : : {
356 : 0 : m_aRemoveBtn.Enable( sal_True );
357 : :
358 : : // url container entries (-> use system credentials) have
359 : : // no password
360 : 0 : sal_Int32 nPos = (sal_Int32)(sal_IntPtr)pEntry->GetUserData();
361 : 0 : m_aChangeBtn.Enable( nPos < m_nPos );
362 : : }
363 : :
364 : 0 : return 0;
365 : : }
366 : :
367 : : //........................................................................
368 : : } // namespace svx
369 : : //........................................................................
370 : :
371 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|