1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include <unotools/pathoptions.hxx>
#include <unotools/useroptions.hxx>
#include <svl/adrparse.hxx>
#include "hlinettp.hxx"
#include "hyperdlg.hrc"
#include "hlmarkwn_def.hxx"
sal_Char const sAnonymous[] = "anonymous";
sal_Char const sHTTPScheme[] = INET_HTTP_SCHEME;
sal_Char const sHTTPSScheme[] = INET_HTTPS_SCHEME;
sal_Char const sFTPScheme[] = INET_FTP_SCHEME;
/*************************************************************************
|*
|* Constructor / Destructor
|*
|************************************************************************/
SvxHyperlinkInternetTp::SvxHyperlinkInternetTp ( Window *pParent,
const SfxItemSet& rItemSet)
: SvxHyperlinkTabPageBase ( pParent, CUI_RES( RID_SVXPAGE_HYPERLINK_INTERNET ),
rItemSet ) ,
maGrpLinkTyp ( this, CUI_RES (GRP_LINKTYPE) ),
maRbtLinktypInternet ( this, CUI_RES (RB_LINKTYP_INTERNET) ),
maRbtLinktypFTP ( this, CUI_RES (RB_LINKTYP_FTP) ),
maFtTarget ( this, CUI_RES (FT_TARGET_HTML) ),
maCbbTarget ( this, INET_PROT_HTTP ),
maBtBrowse ( this, CUI_RES (BTN_BROWSE) ),
maFtLogin ( this, CUI_RES (FT_LOGIN) ),
maEdLogin ( this, CUI_RES (ED_LOGIN) ),
maBtTarget ( this, CUI_RES (BTN_TARGET) ),
maFtPassword ( this, CUI_RES (FT_PASSWD) ),
maEdPassword ( this, CUI_RES (ED_PASSWD) ),
maCbAnonymous ( this, CUI_RES (CBX_ANONYMOUS) ),
mbMarkWndOpen ( sal_False )
{
// Disable display of bitmap names.
maBtBrowse.EnableTextDisplay (sal_False);
maBtTarget.EnableTextDisplay (sal_False);
InitStdControls();
FreeResource();
// Init URL-Box (pos&size, Open-Handler)
maCbbTarget.SetPosSizePixel ( LogicToPixel( Point( COL_2, 25 ), MAP_APPFONT ),
LogicToPixel( Size ( 176 - COL_DIFF, 60), MAP_APPFONT ) );
maCbbTarget.Show();
maCbbTarget.SetHelpId( HID_HYPERDLG_INET_PATH );
SetExchangeSupport ();
///////////////////////////////////////
// set defaults
maRbtLinktypInternet.Check ();
maFtLogin.Show( sal_False );
maFtPassword.Show( sal_False );
maEdLogin.Show( sal_False );
maEdPassword.Show( sal_False );
maCbAnonymous.Show( sal_False );
maBtTarget.Enable( sal_False );
maBtBrowse.Enable( sal_True );
///////////////////////////////////////
// overload handlers
Link aLink( LINK ( this, SvxHyperlinkInternetTp, Click_SmartProtocol_Impl ) );
maRbtLinktypInternet.SetClickHdl( aLink );
maRbtLinktypFTP.SetClickHdl ( aLink );
maCbAnonymous.SetClickHdl ( LINK ( this, SvxHyperlinkInternetTp, ClickAnonymousHdl_Impl ) );
maBtBrowse.SetClickHdl ( LINK ( this, SvxHyperlinkInternetTp, ClickBrowseHdl_Impl ) );
maBtTarget.SetClickHdl ( LINK ( this, SvxHyperlinkInternetTp, ClickTargetHdl_Impl ) );
maEdLogin.SetModifyHdl ( LINK ( this, SvxHyperlinkInternetTp, ModifiedLoginHdl_Impl ) );
maCbbTarget.SetLoseFocusHdl ( LINK ( this, SvxHyperlinkInternetTp, LostFocusTargetHdl_Impl ) );
maCbbTarget.SetModifyHdl ( LINK ( this, SvxHyperlinkInternetTp, ModifiedTargetHdl_Impl ) );
maTimer.SetTimeoutHdl ( LINK ( this, SvxHyperlinkInternetTp, TimeoutHdl_Impl ) );
maFtTarget.SetAccessibleRelationMemberOf( &maGrpLinkTyp );
maCbbTarget.SetAccessibleRelationMemberOf( &maGrpLinkTyp );
maBtTarget.SetAccessibleRelationMemberOf( &maGrpLinkTyp );
maBtTarget.SetAccessibleRelationLabeledBy( &maFtTarget );
maBtBrowse.SetAccessibleRelationMemberOf( &maGrpLinkTyp );
maBtBrowse.SetAccessibleRelationLabeledBy( &maFtTarget );
}
SvxHyperlinkInternetTp::~SvxHyperlinkInternetTp ()
{
}
/*************************************************************************
|*
|* Fill the all dialog-controls except controls in groupbox "more..."
|*
|************************************************************************/
void SvxHyperlinkInternetTp::FillDlgFields ( String& aStrURL )
{
INetURLObject aURL( aStrURL );
String aStrScheme = GetSchemeFromURL( aStrURL );
// set additional controls for FTP: Username / Password
if ( aStrScheme.SearchAscii( sFTPScheme ) == 0 )
{
if ( String(aURL.GetUser()).ToLowerAscii().SearchAscii ( sAnonymous ) == 0 )
setAnonymousFTPUser();
else
setFTPUser(aURL.GetUser(), aURL.GetPass());
//do not show password and user in url
if(aURL.GetUser().getLength()!=0 || aURL.GetPass().getLength()!=0 )
aURL.SetUserAndPass(aEmptyStr,aEmptyStr);
}
// set URL-field
// Show the scheme, #72740
if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
maCbbTarget.SetText( aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) );
else
maCbbTarget.SetText( aStrURL ); // #77696#
SetScheme( aStrScheme );
}
void SvxHyperlinkInternetTp::setAnonymousFTPUser()
{
maEdLogin.SetText( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM ( sAnonymous ) ) );
SvAddressParser aAddress( SvtUserOptions().GetEmail() );
maEdPassword.SetText( aAddress.Count() ? aAddress.GetEmailAddress(0) : String() );
maFtLogin.Disable ();
maFtPassword.Disable ();
maEdLogin.Disable ();
maEdPassword.Disable ();
maCbAnonymous.Check();
}
void SvxHyperlinkInternetTp::setFTPUser(const String& rUser, const String& rPassword)
{
maEdLogin.SetText ( rUser );
maEdPassword.SetText ( rPassword );
maFtLogin.Enable ();
maFtPassword.Enable ();
maEdLogin.Enable ();
maEdPassword.Enable ();
maCbAnonymous.Check(sal_False);
}
/*************************************************************************
|*
|* retrieve and prepare data from dialog-fields
|*
|************************************************************************/
void SvxHyperlinkInternetTp::GetCurentItemData ( String& aStrURL, String& aStrName,
String& aStrIntName, String& aStrFrame,
SvxLinkInsertMode& eMode )
{
aStrURL = CreateAbsoluteURL();
GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
}
String SvxHyperlinkInternetTp::CreateAbsoluteURL() const
{
String aStrURL = maCbbTarget.GetText();
String aScheme = GetSchemeFromURL(aStrURL);
INetURLObject aURL(aStrURL);
if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
{
aURL.SetSmartProtocol( GetSmartProtocolFromButtons() );
aURL.SetSmartURL(aStrURL);
}
// username and password for ftp-url
if( aURL.GetProtocol() == INET_PROT_FTP && maEdLogin.GetText().Len()!=0 )
aURL.SetUserAndPass ( maEdLogin.GetText(), maEdPassword.GetText() );
if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
return aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
else //#105788# always create a URL even if it is not valid
return aStrURL;
}
/*************************************************************************
|*
|* static method to create Tabpage
|*
|************************************************************************/
IconChoicePage* SvxHyperlinkInternetTp::Create( Window* pWindow, const SfxItemSet& rItemSet )
{
return( new SvxHyperlinkInternetTp( pWindow, rItemSet ) );
}
/*************************************************************************
|*
|* Set initial focus
|*
|************************************************************************/
void SvxHyperlinkInternetTp::SetInitFocus()
{
maCbbTarget.GrabFocus();
}
/*************************************************************************
|*
|* Contents of editfield "Target" modified
|*
|************************************************************************/
IMPL_LINK ( SvxHyperlinkInternetTp, ModifiedTargetHdl_Impl, void *, EMPTYARG )
{
String aScheme = GetSchemeFromURL( maCbbTarget.GetText() );
if(aScheme.Len()!=0)
SetScheme( aScheme );
// start timer
maTimer.SetTimeout( 2500 );
maTimer.Start();
return( 0L );
}
/*************************************************************************
|*
|* If target-field was modify, to browse the new doc after timeout
|*
|************************************************************************/
IMPL_LINK ( SvxHyperlinkInternetTp, TimeoutHdl_Impl, Timer *, EMPTYARG )
{
RefreshMarkWindow();
return( 0L );
}
/*************************************************************************
|*
|* Contents of editfield "Login" modified
|*
|************************************************************************/
IMPL_LINK ( SvxHyperlinkInternetTp, ModifiedLoginHdl_Impl, void *, EMPTYARG )
{
String aStrLogin ( maEdLogin.GetText() );
if ( aStrLogin.EqualsIgnoreCaseAscii( sAnonymous ) )
{
maCbAnonymous.Check();
ClickAnonymousHdl_Impl(NULL);
}
return( 0L );
}
/*************************************************************************
|************************************************************************/
void SvxHyperlinkInternetTp::SetScheme( const String& aScheme )
{
//if aScheme is empty or unknown the default beaviour is like it where HTTP
sal_Bool bFTP = aScheme.SearchAscii( sFTPScheme ) == 0;
sal_Bool bInternet = !(bFTP);
//update protocol button selection:
maRbtLinktypFTP.Check(bFTP);
maRbtLinktypInternet.Check(bInternet);
//update target:
RemoveImproperProtocol(aScheme);
maCbbTarget.SetSmartProtocol( GetSmartProtocolFromButtons() );
//show/hide special fields for FTP:
maFtLogin.Show( bFTP );
maFtPassword.Show( bFTP );
maEdLogin.Show( bFTP );
maEdPassword.Show( bFTP );
maCbAnonymous.Show( bFTP );
//update 'link target in document'-window and opening-button
if( aScheme.SearchAscii( sHTTPScheme ) == 0 || aScheme.Len() == 0 )
{
maBtTarget.Enable();
if ( mbMarkWndOpen )
ShowMarkWnd ();
}
else
{
//disable for https and ftp
maBtTarget.Disable();
if ( mbMarkWndOpen )
HideMarkWnd ();
}
}
/*************************************************************************
|*
|* Remove protocol if it does not fit to the current button selection
|*
|************************************************************************/
void SvxHyperlinkInternetTp::RemoveImproperProtocol(const String& aProperScheme)
{
String aStrURL ( maCbbTarget.GetText() );
if ( aStrURL != aEmptyStr )
{
String aStrScheme = GetSchemeFromURL( aStrURL );
if ( aStrScheme != aEmptyStr && aStrScheme != aProperScheme )
{
aStrURL.Erase ( 0, aStrScheme.Len() );
maCbbTarget.SetText ( aStrURL );
}
}
}
String SvxHyperlinkInternetTp::GetSchemeFromButtons() const
{
if( maRbtLinktypFTP.IsChecked() )
{
return String::CreateFromAscii( INET_FTP_SCHEME );
}
return String::CreateFromAscii( INET_HTTP_SCHEME );
}
INetProtocol SvxHyperlinkInternetTp::GetSmartProtocolFromButtons() const
{
if( maRbtLinktypFTP.IsChecked() )
{
return INET_PROT_FTP;
}
return INET_PROT_HTTP;
}
/*************************************************************************
|*
|* Click on Radiobutton : Internet or FTP
|*
|************************************************************************/
IMPL_LINK ( SvxHyperlinkInternetTp, Click_SmartProtocol_Impl, void*, EMPTYARG )
{
String aScheme = GetSchemeFromButtons();
SetScheme( aScheme );
return( 0L );
}
/*************************************************************************
|*
|* Click on Checkbox : Anonymous user
|*
|************************************************************************/
IMPL_LINK ( SvxHyperlinkInternetTp, ClickAnonymousHdl_Impl, void *, EMPTYARG )
{
// disable login-editfields if checked
if ( maCbAnonymous.IsChecked() )
{
if ( maEdLogin.GetText().ToLowerAscii().SearchAscii ( sAnonymous ) == 0 )
{
maStrOldUser = aEmptyStr;
maStrOldPassword = aEmptyStr;
}
else
{
maStrOldUser = maEdLogin.GetText();
maStrOldPassword = maEdPassword.GetText();
}
setAnonymousFTPUser();
}
else
setFTPUser(maStrOldUser, maStrOldPassword);
return( 0L );
}
/*************************************************************************
|*
|* Combobox Target lost the focus
|*
|************************************************************************/
IMPL_LINK ( SvxHyperlinkInternetTp, LostFocusTargetHdl_Impl, void *, EMPTYARG )
{
RefreshMarkWindow();
return (0L);
}
/*************************************************************************
|*
|* Click on imagebutton : Browse
|*
|************************************************************************/
IMPL_LINK ( SvxHyperlinkInternetTp, ClickBrowseHdl_Impl, void *, EMPTYARG )
{
/////////////////////////////////////////////////
// Open URL if available
SfxStringItem aName( SID_FILE_NAME, UniString::CreateFromAscii(
RTL_CONSTASCII_STRINGPARAM( "http://" ) ) );
SfxStringItem aRefererItem( SID_REFERER, UniString::CreateFromAscii(
RTL_CONSTASCII_STRINGPARAM( "private:user" ) ) );
SfxBoolItem aNewView( SID_OPEN_NEW_VIEW, sal_True );
SfxBoolItem aSilent( SID_SILENT, sal_True );
SfxBoolItem aReadOnly( SID_DOC_READONLY, sal_True );
SfxBoolItem aBrowse( SID_BROWSE, sal_True );
const SfxPoolItem *ppItems[] = { &aName, &aNewView, &aSilent, &aReadOnly, &aRefererItem, &aBrowse, NULL };
(((SvxHpLinkDlg*)mpDialog)->GetBindings())->Execute( SID_OPENDOC, ppItems, 0, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD );
return( 0L );
}
/*************************************************************************
|*
|* Click on imagebutton : Target
|*
|************************************************************************/
IMPL_LINK ( SvxHyperlinkInternetTp, ClickTargetHdl_Impl, void *, EMPTYARG )
{
RefreshMarkWindow();
ShowMarkWnd ();
mbMarkWndOpen = IsMarkWndVisible ();
return( 0L );
}
void SvxHyperlinkInternetTp::RefreshMarkWindow()
{
if ( maRbtLinktypInternet.IsChecked() && IsMarkWndVisible() )
{
EnterWait();
String aStrURL( CreateAbsoluteURL() );
if ( aStrURL != aEmptyStr )
mpMarkWnd->RefreshTree ( aStrURL );
else
mpMarkWnd->SetError( LERR_DOCNOTOPEN );
LeaveWait();
}
}
/*************************************************************************
|*
|* Get String from Bookmark-Wnd
|*
|************************************************************************/
void SvxHyperlinkInternetTp::SetMarkStr ( String& aStrMark )
{
String aStrURL ( maCbbTarget.GetText() );
const sal_Unicode sUHash = '#';
xub_StrLen nPos = aStrURL.SearchBackward( sUHash );
if( nPos != STRING_NOTFOUND )
aStrURL.Erase ( nPos );
aStrURL += sUHash;
aStrURL += aStrMark;
maCbbTarget.SetText ( aStrURL );
}
/*************************************************************************
|*
|* Enable Browse-Button in subject to the office is in onlinemode
|*
|************************************************************************/
void SvxHyperlinkInternetTp::SetOnlineMode( sal_Bool /*bEnable*/ )
{
// State of target-button in subject to the current url-string
// ( Can't display any targets in an document, if there is no
// valid url to a document )
String aStrCurrentTarget( maCbbTarget.GetText() );
aStrCurrentTarget.EraseTrailingChars();
if( aStrCurrentTarget == aEmptyStr ||
aStrCurrentTarget.EqualsIgnoreCaseAscii( sHTTPScheme ) ||
aStrCurrentTarget.EqualsIgnoreCaseAscii( sHTTPSScheme ) )
maBtTarget.Enable( sal_False );
else
maBtTarget.Enable( sal_True );
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|