1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hlinettp.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
37 #include <svtools/adrparse.hxx>
38 #include <svtools/pathoptions.hxx>
39 #include <svtools/useroptions.hxx>
41 #include "hlinettp.hxx"
42 #include "hyperdlg.hrc"
43 #include "hlmarkwn_def.hxx" //ADD CHINA001
45 #define STD_DOC_SUBPATH "internal"
46 #define STD_DOC_NAME "url_transfer.htm"
48 sal_Char __READONLY_DATA sAnonymous
[] = "anonymous";
49 sal_Char __READONLY_DATA sHTTPScheme
[] = INET_HTTP_SCHEME
;
50 sal_Char __READONLY_DATA sHTTPSScheme
[] = INET_HTTPS_SCHEME
;
51 sal_Char __READONLY_DATA sFTPScheme
[] = INET_FTP_SCHEME
;
52 sal_Char __READONLY_DATA sTelnetScheme
[] = INET_TELNET_SCHEME
;
54 /*************************************************************************
56 |* Contructor / Destructor
58 |************************************************************************/
60 SvxHyperlinkInternetTp::SvxHyperlinkInternetTp ( Window
*pParent
,
61 const SfxItemSet
& rItemSet
)
62 : SvxHyperlinkTabPageBase ( pParent
, SVX_RES( RID_SVXPAGE_HYPERLINK_INTERNET
),
64 maGrpLinkTyp ( this, SVX_RES (GRP_LINKTYPE
) ),
65 maRbtLinktypInternet ( this, SVX_RES (RB_LINKTYP_INTERNET
) ),
66 maRbtLinktypFTP ( this, SVX_RES (RB_LINKTYP_FTP
) ),
67 maRbtLinktypTelnet ( this, SVX_RES (RB_LINKTYP_TELNET
) ),
68 maFtTarget ( this, SVX_RES (FT_TARGET_HTML
) ),
69 maCbbTarget ( this, INET_PROT_HTTP
),
70 maFtLogin ( this, SVX_RES (FT_LOGIN
) ),
71 maEdLogin ( this, SVX_RES (ED_LOGIN
) ),
72 maFtPassword ( this, SVX_RES (FT_PASSWD
) ),
73 maEdPassword ( this, SVX_RES (ED_PASSWD
) ),
74 maCbAnonymous ( this, SVX_RES (CBX_ANONYMOUS
) ),
75 maBtBrowse ( this, SVX_RES (BTN_BROWSE
) ),
76 maBtTarget ( this, SVX_RES (BTN_TARGET
) ),
77 mbMarkWndOpen ( FALSE
)
79 // Set HC bitmaps and display display of bitmap names.
80 maBtBrowse
.SetModeImage( Image( SVX_RES( IMG_BROWSE_HC
) ), BMP_COLOR_HIGHCONTRAST
);
81 maBtBrowse
.EnableTextDisplay (FALSE
);
82 maBtTarget
.SetModeImage( Image( SVX_RES( IMG_TARGET_HC
) ), BMP_COLOR_HIGHCONTRAST
);
83 maBtTarget
.EnableTextDisplay (FALSE
);
88 // Init URL-Box (pos&size, Open-Handler)
89 maCbbTarget
.SetPosSizePixel ( LogicToPixel( Point( COL_2
, 25 ), MAP_APPFONT
),
90 LogicToPixel( Size ( 176 - COL_DIFF
, 60), MAP_APPFONT
) );
92 maCbbTarget
.SetHelpId( HID_HYPERDLG_INET_PATH
);
94 // Find Path to Std-Doc
95 String
aStrBasePaths( SvtPathOptions().GetTemplatePath() );
96 for( xub_StrLen n
= 0; n
< aStrBasePaths
.GetTokenCount(); n
++ )
98 INetURLObject
aURL( aStrBasePaths
.GetToken( n
) );
99 aURL
.Append( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( STD_DOC_SUBPATH
) ) );
100 aURL
.Append( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( STD_DOC_NAME
) ) );
101 if ( FileExists( aURL
) )
103 maStrStdDocURL
= aURL
.GetMainURL( INetURLObject::NO_DECODE
);
107 SetExchangeSupport ();
109 ///////////////////////////////////////
111 maRbtLinktypInternet
.Check ();
112 maFtLogin
.Show( FALSE
);
113 maFtPassword
.Show( FALSE
);
114 maEdLogin
.Show( FALSE
);
115 maEdPassword
.Show( FALSE
);
116 maCbAnonymous
.Show( FALSE
);
117 maBtTarget
.Enable( FALSE
);
118 maBtBrowse
.Enable( maStrStdDocURL
!= aEmptyStr
);
120 ///////////////////////////////////////
122 Link
aLink( LINK ( this, SvxHyperlinkInternetTp
, Click_SmartProtocol_Impl
) );
123 maRbtLinktypInternet
.SetClickHdl( aLink
);
124 maRbtLinktypFTP
.SetClickHdl ( aLink
);
125 maRbtLinktypTelnet
.SetClickHdl ( aLink
);
126 maCbAnonymous
.SetClickHdl ( LINK ( this, SvxHyperlinkInternetTp
, ClickAnonymousHdl_Impl
) );
127 maBtBrowse
.SetClickHdl ( LINK ( this, SvxHyperlinkInternetTp
, ClickBrowseHdl_Impl
) );
128 maBtTarget
.SetClickHdl ( LINK ( this, SvxHyperlinkInternetTp
, ClickTargetHdl_Impl
) );
129 maEdLogin
.SetModifyHdl ( LINK ( this, SvxHyperlinkInternetTp
, ModifiedLoginHdl_Impl
) );
130 maCbbTarget
.SetLoseFocusHdl ( LINK ( this, SvxHyperlinkInternetTp
, LostFocusTargetHdl_Impl
) );
131 maCbbTarget
.SetModifyHdl ( LINK ( this, SvxHyperlinkInternetTp
, ModifiedTargetHdl_Impl
) );
132 maTimer
.SetTimeoutHdl ( LINK ( this, SvxHyperlinkInternetTp
, TimeoutHdl_Impl
) );
135 SvxHyperlinkInternetTp::~SvxHyperlinkInternetTp ()
139 /*************************************************************************
141 |* Fill the all dialog-controls except controls in groupbox "more..."
143 |************************************************************************/
145 void SvxHyperlinkInternetTp::FillDlgFields ( String
& aStrURL
)
147 INetURLObject
aURL( aStrURL
);
148 String aStrScheme
= GetSchemeFromURL( aStrURL
);
150 // set additional controls for FTP: Username / Password
151 if ( aStrScheme
.SearchAscii( sFTPScheme
) == 0 )
153 if ( String(aURL
.GetUser()).ToLowerAscii().SearchAscii ( sAnonymous
) == 0 )
154 setAnonymousFTPUser();
156 setFTPUser(aURL
.GetUser(), aURL
.GetPass());
158 //do not show password and user in url
159 if(aURL
.GetUser().getLength()!=0 || aURL
.GetPass().getLength()!=0 )
160 aURL
.SetUserAndPass(aEmptyStr
,aEmptyStr
);
164 // Show the scheme, #72740
165 if ( aURL
.GetProtocol() != INET_PROT_NOT_VALID
)
166 maCbbTarget
.SetText( aURL
.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS
) );
168 maCbbTarget
.SetText( aStrURL
); // #77696#
170 SetScheme( aStrScheme
);
173 void SvxHyperlinkInternetTp::setAnonymousFTPUser()
175 maEdLogin
.SetText( UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM ( sAnonymous
) ) );
176 SvAddressParser
aAddress( SvtUserOptions().GetEmail() );
177 maEdPassword
.SetText( aAddress
.Count() ? aAddress
.GetEmailAddress(0) : String() );
179 maFtLogin
.Disable ();
180 maFtPassword
.Disable ();
181 maEdLogin
.Disable ();
182 maEdPassword
.Disable ();
183 maCbAnonymous
.Check();
186 void SvxHyperlinkInternetTp::setFTPUser(const String
& rUser
, const String
& rPassword
)
188 maEdLogin
.SetText ( rUser
);
189 maEdPassword
.SetText ( rPassword
);
192 maFtPassword
.Enable ();
194 maEdPassword
.Enable ();
195 maCbAnonymous
.Check(FALSE
);
198 /*************************************************************************
200 |* retrieve and prepare data from dialog-fields
202 |************************************************************************/
204 void SvxHyperlinkInternetTp::GetCurentItemData ( String
& aStrURL
, String
& aStrName
,
205 String
& aStrIntName
, String
& aStrFrame
,
206 SvxLinkInsertMode
& eMode
)
208 aStrURL
= CreateAbsoluteURL();
209 GetDataFromCommonFields( aStrName
, aStrIntName
, aStrFrame
, eMode
);
212 String
SvxHyperlinkInternetTp::CreateAbsoluteURL() const
214 String aStrURL
= maCbbTarget
.GetText();
215 String aScheme
= GetSchemeFromURL(aStrURL
);
217 INetURLObject
aURL(aStrURL
);
219 if( aURL
.GetProtocol() == INET_PROT_NOT_VALID
)
221 aURL
.SetSmartProtocol( GetSmartProtocolFromButtons() );
222 aURL
.SetSmartURL(aStrURL
);
225 // username and password for ftp-url
226 if( aURL
.GetProtocol() == INET_PROT_FTP
&& maEdLogin
.GetText().Len()!=0 )
227 aURL
.SetUserAndPass ( maEdLogin
.GetText(), maEdPassword
.GetText() );
229 if ( aURL
.GetProtocol() != INET_PROT_NOT_VALID
)
230 return aURL
.GetMainURL( INetURLObject::DECODE_WITH_CHARSET
);
231 else //#105788# always create a URL even if it is not valid
235 /*************************************************************************
237 |* static method to create Tabpage
239 |************************************************************************/
241 IconChoicePage
* SvxHyperlinkInternetTp::Create( Window
* pWindow
, const SfxItemSet
& rItemSet
)
243 return( new SvxHyperlinkInternetTp( pWindow
, rItemSet
) );
246 /*************************************************************************
250 |************************************************************************/
252 void SvxHyperlinkInternetTp::SetInitFocus()
254 maCbbTarget
.GrabFocus();
257 /*************************************************************************
259 |* Contens of editfield "Taregt" modified
261 |************************************************************************/
263 IMPL_LINK ( SvxHyperlinkInternetTp
, ModifiedTargetHdl_Impl
, void *, EMPTYARG
)
265 String aScheme
= GetSchemeFromURL( maCbbTarget
.GetText() );
267 SetScheme( aScheme
);
270 maTimer
.SetTimeout( 2500 );
276 /*************************************************************************
278 |* If target-field was modify, to browse the new doc afeter timeout
280 |************************************************************************/
282 IMPL_LINK ( SvxHyperlinkInternetTp
, TimeoutHdl_Impl
, Timer
*, EMPTYARG
)
288 /*************************************************************************
290 |* Contens of editfield "Login" modified
292 |************************************************************************/
294 IMPL_LINK ( SvxHyperlinkInternetTp
, ModifiedLoginHdl_Impl
, void *, EMPTYARG
)
296 String
aStrLogin ( maEdLogin
.GetText() );
297 if ( aStrLogin
.EqualsIgnoreCaseAscii( sAnonymous
) )
299 maCbAnonymous
.Check();
300 ClickAnonymousHdl_Impl(NULL
);
306 /*************************************************************************
307 |************************************************************************/
309 void SvxHyperlinkInternetTp::SetScheme( const String
& aScheme
)
311 //if aScheme is empty or unknown the default beaviour is like it where HTTP
313 BOOL bFTP
= aScheme
.SearchAscii( sFTPScheme
) == 0;
314 BOOL bTelnet
= FALSE
;
316 bTelnet
= aScheme
.SearchAscii( sTelnetScheme
) == 0;
317 BOOL bInternet
= !(bFTP
|| bTelnet
);
319 //update protocol button selection:
320 maRbtLinktypFTP
.Check(bFTP
);
321 maRbtLinktypTelnet
.Check(bTelnet
);
322 maRbtLinktypInternet
.Check(bInternet
);
325 RemoveImproperProtocol(aScheme
);
326 maCbbTarget
.SetSmartProtocol( GetSmartProtocolFromButtons() );
328 //show/hide special fields for FTP:
329 maFtLogin
.Show( bFTP
);
330 maFtPassword
.Show( bFTP
);
331 maEdLogin
.Show( bFTP
);
332 maEdPassword
.Show( bFTP
);
333 maCbAnonymous
.Show( bFTP
);
335 //update 'link target in document'-window and opening-button
336 if( aScheme
.SearchAscii( sHTTPScheme
) == 0 || aScheme
.Len() == 0 )
344 //disable for https, ftp and telnet
345 maBtTarget
.Disable();
351 /*************************************************************************
353 |* Remove protocol if it does not fit to the current button selection
355 |************************************************************************/
357 void SvxHyperlinkInternetTp::RemoveImproperProtocol(const String
& aProperScheme
)
359 String
aStrURL ( maCbbTarget
.GetText() );
360 if ( aStrURL
!= aEmptyStr
)
362 String aStrScheme
= GetSchemeFromURL( aStrURL
);
363 if ( aStrScheme
!= aEmptyStr
&& aStrScheme
!= aProperScheme
)
365 aStrURL
.Erase ( 0, aStrScheme
.Len() );
366 maCbbTarget
.SetText ( aStrURL
);
371 String
SvxHyperlinkInternetTp::GetSchemeFromButtons() const
373 if( maRbtLinktypFTP
.IsChecked() )
375 return String::CreateFromAscii( INET_FTP_SCHEME
);
377 else if( maRbtLinktypTelnet
.IsChecked() )
379 return String::CreateFromAscii( INET_TELNET_SCHEME
);
381 return String::CreateFromAscii( INET_HTTP_SCHEME
);
384 INetProtocol
SvxHyperlinkInternetTp::GetSmartProtocolFromButtons() const
386 if( maRbtLinktypFTP
.IsChecked() )
388 return INET_PROT_FTP
;
390 else if( maRbtLinktypTelnet
.IsChecked() )
392 return INET_PROT_TELNET
;
394 return INET_PROT_HTTP
;
397 /*************************************************************************
399 |* Click on Radiobutton : Internet, FTP or Telnet
401 |************************************************************************/
403 IMPL_LINK ( SvxHyperlinkInternetTp
, Click_SmartProtocol_Impl
, void*, EMPTYARG
)
405 String aScheme
= GetSchemeFromButtons();
406 SetScheme( aScheme
);
410 /*************************************************************************
412 |* Click on Checkbox : Anonymous user
414 |************************************************************************/
416 IMPL_LINK ( SvxHyperlinkInternetTp
, ClickAnonymousHdl_Impl
, void *, EMPTYARG
)
418 // disable login-editfields if checked
419 if ( maCbAnonymous
.IsChecked() )
421 if ( maEdLogin
.GetText().ToLowerAscii().SearchAscii ( sAnonymous
) == 0 )
423 maStrOldUser
= aEmptyStr
;
424 maStrOldPassword
= aEmptyStr
;
428 maStrOldUser
= maEdLogin
.GetText();
429 maStrOldPassword
= maEdPassword
.GetText();
432 setAnonymousFTPUser();
435 setFTPUser(maStrOldUser
, maStrOldPassword
);
440 /*************************************************************************
442 |* Combobox Target lost the focus
444 |************************************************************************/
446 IMPL_LINK ( SvxHyperlinkInternetTp
, LostFocusTargetHdl_Impl
, void *, EMPTYARG
)
452 /*************************************************************************
454 |* Click on imagebutton : Browse
456 |************************************************************************/
458 IMPL_LINK ( SvxHyperlinkInternetTp
, ClickBrowseHdl_Impl
, void *, EMPTYARG
)
460 /////////////////////////////////////////////////
461 // Open URL if available
463 SfxStringItem
aName( SID_FILE_NAME
, maStrStdDocURL
);
464 SfxStringItem
aRefererItem( SID_REFERER
, UniString::CreateFromAscii(
465 RTL_CONSTASCII_STRINGPARAM( "private:user" ) ) );
466 SfxBoolItem
aNewView( SID_OPEN_NEW_VIEW
, TRUE
);
467 SfxBoolItem
aSilent( SID_SILENT
, TRUE
);
468 SfxBoolItem
aReadOnly( SID_DOC_READONLY
, TRUE
);
470 SfxBoolItem
aBrowse( SID_BROWSE
, TRUE
);
472 const SfxPoolItem
*ppItems
[] = { &aName
, &aNewView
, &aSilent
, &aReadOnly
, &aRefererItem
, &aBrowse
, NULL
};
473 (((SvxHpLinkDlg
*)mpDialog
)->GetBindings())->Execute( SID_OPENDOC
, ppItems
, 0, SFX_CALLMODE_ASYNCHRON
| SFX_CALLMODE_RECORD
);
478 /*************************************************************************
480 |* Click on imagebutton : Target
482 |************************************************************************/
484 IMPL_LINK ( SvxHyperlinkInternetTp
, ClickTargetHdl_Impl
, void *, EMPTYARG
)
488 mbMarkWndOpen
= IsMarkWndVisible ();
493 void SvxHyperlinkInternetTp::RefreshMarkWindow()
495 if ( maRbtLinktypInternet
.IsChecked() && IsMarkWndVisible() )
498 String
aStrURL( CreateAbsoluteURL() );
499 if ( aStrURL
!= aEmptyStr
)
500 mpMarkWnd
->RefreshTree ( aStrURL
);
502 mpMarkWnd
->SetError( LERR_DOCNOTOPEN
);
508 /*************************************************************************
510 |* Get String from Bookmark-Wnd
512 |************************************************************************/
514 void SvxHyperlinkInternetTp::SetMarkStr ( String
& aStrMark
)
516 String
aStrURL ( maCbbTarget
.GetText() );
518 const sal_Unicode sUHash
= '#';
519 xub_StrLen nPos
= aStrURL
.SearchBackward( sUHash
);
521 if( nPos
!= STRING_NOTFOUND
)
522 aStrURL
.Erase ( nPos
);
527 maCbbTarget
.SetText ( aStrURL
);
530 /*************************************************************************
532 |* Enable Browse-Button in subject to the office is in onlinemode
534 |************************************************************************/
536 void SvxHyperlinkInternetTp::SetOnlineMode( BOOL
/*bEnable*/ )
538 // State of target-button in subject to the current url-string
539 // ( Can't display any targets in an document, if there is no
540 // valid url to a document )
541 String
aStrCurrentTarget( maCbbTarget
.GetText() );
542 aStrCurrentTarget
.EraseTrailingChars();
544 if( aStrCurrentTarget
== aEmptyStr
||
545 aStrCurrentTarget
.EqualsIgnoreCaseAscii( sHTTPScheme
) ||
546 aStrCurrentTarget
.EqualsIgnoreCaseAscii( sHTTPSScheme
) )
547 maBtTarget
.Enable( FALSE
);
549 maBtTarget
.Enable( TRUE
);