LCOV - code coverage report
Current view: top level - cui/source/dialogs - hlinettp.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 194 0.0 %
Date: 2014-04-11 Functions: 0 32 0.0 %
Legend: Lines: hit not hit

          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 <unotools/pathoptions.hxx>
      21             : #include <unotools/useroptions.hxx>
      22             : #include <svl/adrparse.hxx>
      23             : 
      24             : #include "hlinettp.hxx"
      25             : #include "hyperdlg.hrc"
      26             : #include "hlmarkwn_def.hxx"
      27             : 
      28             : sal_Char const sAnonymous[]    = "anonymous";
      29             : sal_Char const sHTTPScheme[]   = INET_HTTP_SCHEME;
      30             : sal_Char const sFTPScheme[]    = INET_FTP_SCHEME;
      31             : 
      32             : /*************************************************************************
      33             : |*
      34             : |* Constructor / Destructor
      35             : |*
      36             : |************************************************************************/
      37             : 
      38           0 : SvxHyperlinkInternetTp::SvxHyperlinkInternetTp ( Window *pParent,
      39             :                                                  const SfxItemSet& rItemSet)
      40           0 : :   SvxHyperlinkTabPageBase ( pParent, CUI_RES( RID_SVXPAGE_HYPERLINK_INTERNET ),
      41             :                               rItemSet ) ,
      42           0 :     maGrpLinkTyp           ( this, CUI_RES (GRP_LINKTYPE) ),
      43           0 :     maRbtLinktypInternet    ( this, CUI_RES (RB_LINKTYP_INTERNET) ),
      44           0 :     maRbtLinktypFTP         ( this, CUI_RES (RB_LINKTYP_FTP) ),
      45           0 :     maFtTarget              ( this, CUI_RES (FT_TARGET_HTML) ),
      46             :     maCbbTarget             ( this, INET_PROT_HTTP ),
      47           0 :     maBtBrowse              ( this, CUI_RES (BTN_BROWSE) ),
      48           0 :     maFtLogin               ( this, CUI_RES (FT_LOGIN) ),
      49           0 :     maEdLogin               ( this, CUI_RES (ED_LOGIN) ),
      50           0 :     maFtPassword            ( this, CUI_RES (FT_PASSWD) ),
      51           0 :     maEdPassword            ( this, CUI_RES (ED_PASSWD) ),
      52           0 :     maCbAnonymous           ( this, CUI_RES (CBX_ANONYMOUS) ),
      53           0 :     mbMarkWndOpen           ( sal_False )
      54             : {
      55             :     // Disable display of bitmap names.
      56           0 :     maBtBrowse.EnableTextDisplay (false);
      57             : 
      58           0 :     InitStdControls();
      59           0 :     FreeResource();
      60             : 
      61             :     // Init URL-Box (pos&size, Open-Handler)
      62           0 :     maCbbTarget.SetPosSizePixel ( LogicToPixel( Point( COL_2, 25 ), MAP_APPFONT ),
      63           0 :                                   LogicToPixel( Size ( 176 - COL_DIFF, 60), MAP_APPFONT ) );
      64           0 :     maCbbTarget.Show();
      65           0 :     maCbbTarget.SetHelpId( HID_HYPERDLG_INET_PATH );
      66             : 
      67           0 :     SetExchangeSupport ();
      68             : 
      69             : 
      70             :     // set defaults
      71           0 :     maRbtLinktypInternet.Check ();
      72           0 :     maFtLogin.Show( false );
      73           0 :     maFtPassword.Show( false );
      74           0 :     maEdLogin.Show( false );
      75           0 :     maEdPassword.Show( false );
      76           0 :     maCbAnonymous.Show( false );
      77           0 :     maBtBrowse.Enable( true );
      78             : 
      79             : 
      80             :     // overload handlers
      81           0 :     Link aLink( LINK ( this, SvxHyperlinkInternetTp, Click_SmartProtocol_Impl ) );
      82           0 :     maRbtLinktypInternet.SetClickHdl( aLink );
      83           0 :     maRbtLinktypFTP.SetClickHdl     ( aLink );
      84           0 :     maCbAnonymous.SetClickHdl       ( LINK ( this, SvxHyperlinkInternetTp, ClickAnonymousHdl_Impl ) );
      85           0 :     maBtBrowse.SetClickHdl          ( LINK ( this, SvxHyperlinkInternetTp, ClickBrowseHdl_Impl ) );
      86           0 :     maEdLogin.SetModifyHdl          ( LINK ( this, SvxHyperlinkInternetTp, ModifiedLoginHdl_Impl ) );
      87           0 :     maCbbTarget.SetLoseFocusHdl     ( LINK ( this, SvxHyperlinkInternetTp, LostFocusTargetHdl_Impl ) );
      88           0 :     maCbbTarget.SetModifyHdl        ( LINK ( this, SvxHyperlinkInternetTp, ModifiedTargetHdl_Impl ) );
      89           0 :     maTimer.SetTimeoutHdl           ( LINK ( this, SvxHyperlinkInternetTp, TimeoutHdl_Impl ) );
      90             : 
      91           0 :     maFtTarget.SetAccessibleRelationMemberOf( &maGrpLinkTyp );
      92           0 :     maCbbTarget.SetAccessibleRelationMemberOf( &maGrpLinkTyp );
      93           0 :     maBtBrowse.SetAccessibleRelationMemberOf( &maGrpLinkTyp );
      94           0 :     maBtBrowse.SetAccessibleRelationLabeledBy( &maFtTarget );
      95           0 : }
      96             : 
      97           0 : SvxHyperlinkInternetTp::~SvxHyperlinkInternetTp ()
      98             : {
      99           0 : }
     100             : 
     101             : /*************************************************************************
     102             : |*
     103             : |* Fill the all dialog-controls except controls in groupbox "more..."
     104             : |*
     105             : |************************************************************************/
     106             : 
     107           0 : void SvxHyperlinkInternetTp::FillDlgFields(const OUString& rStrURL)
     108             : {
     109           0 :     INetURLObject aURL(rStrURL);
     110           0 :     OUString aStrScheme(GetSchemeFromURL(rStrURL));
     111             : 
     112             :     // set additional controls for FTP: Username / Password
     113           0 :     if (aStrScheme.startsWith(sFTPScheme))
     114             :     {
     115           0 :         if ( aURL.GetUser().toAsciiLowerCase().startsWith( sAnonymous ) )
     116           0 :             setAnonymousFTPUser();
     117             :         else
     118           0 :             setFTPUser(aURL.GetUser(), aURL.GetPass());
     119             : 
     120             :         //do not show password and user in url
     121           0 :         if(!aURL.GetUser().isEmpty() || !aURL.GetPass().isEmpty() )
     122           0 :             aURL.SetUserAndPass(aEmptyStr,aEmptyStr);
     123             :     }
     124             : 
     125             :     // set URL-field
     126             :     // Show the scheme, #72740
     127           0 :     if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
     128           0 :         maCbbTarget.SetText( aURL.GetMainURL( INetURLObject::DECODE_UNAMBIGUOUS ) );
     129             :     else
     130           0 :         maCbbTarget.SetText(rStrURL); // #77696#
     131             : 
     132           0 :     SetScheme(aStrScheme);
     133           0 : }
     134             : 
     135           0 : void SvxHyperlinkInternetTp::setAnonymousFTPUser()
     136             : {
     137           0 :     maEdLogin.SetText(OUString(sAnonymous));
     138           0 :     SvAddressParser aAddress( SvtUserOptions().GetEmail() );
     139           0 :     maEdPassword.SetText( aAddress.Count() ? aAddress.GetEmailAddress(0) : OUString() );
     140             : 
     141           0 :     maFtLogin.Disable ();
     142           0 :     maFtPassword.Disable ();
     143           0 :     maEdLogin.Disable ();
     144           0 :     maEdPassword.Disable ();
     145           0 :     maCbAnonymous.Check();
     146           0 : }
     147             : 
     148           0 : void SvxHyperlinkInternetTp::setFTPUser(const OUString& rUser, const OUString& rPassword)
     149             : {
     150           0 :     maEdLogin.SetText ( rUser );
     151           0 :     maEdPassword.SetText ( rPassword );
     152             : 
     153           0 :     maFtLogin.Enable ();
     154           0 :     maFtPassword.Enable ();
     155           0 :     maEdLogin.Enable ();
     156           0 :     maEdPassword.Enable ();
     157           0 :     maCbAnonymous.Check(false);
     158           0 : }
     159             : 
     160             : /*************************************************************************
     161             : |*
     162             : |* retrieve and prepare data from dialog-fields
     163             : |*
     164             : |************************************************************************/
     165             : 
     166           0 : void SvxHyperlinkInternetTp::GetCurentItemData ( OUString& rStrURL, OUString& aStrName,
     167             :                                                  OUString& aStrIntName, OUString& aStrFrame,
     168             :                                                  SvxLinkInsertMode& eMode )
     169             : {
     170           0 :     rStrURL = CreateAbsoluteURL();
     171           0 :     GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
     172           0 : }
     173             : 
     174           0 : OUString SvxHyperlinkInternetTp::CreateAbsoluteURL() const
     175             : {
     176             :     // erase leading and trailing whitespaces
     177           0 :     OUString aStrURL( maCbbTarget.GetText().trim() );
     178             : 
     179           0 :     INetURLObject aURL(aStrURL);
     180             : 
     181           0 :     if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
     182             :     {
     183           0 :         aURL.SetSmartProtocol( GetSmartProtocolFromButtons() );
     184           0 :         aURL.SetSmartURL(aStrURL);
     185             :     }
     186             : 
     187             :     // username and password for ftp-url
     188           0 :     if( aURL.GetProtocol() == INET_PROT_FTP && !maEdLogin.GetText().isEmpty() )
     189           0 :         aURL.SetUserAndPass ( maEdLogin.GetText(), maEdPassword.GetText() );
     190             : 
     191           0 :     if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
     192           0 :         return aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
     193             :     else //#105788# always create a URL even if it is not valid
     194           0 :         return aStrURL;
     195             : }
     196             : 
     197             : /*************************************************************************
     198             : |*
     199             : |* static method to create Tabpage
     200             : |*
     201             : |************************************************************************/
     202             : 
     203           0 : IconChoicePage* SvxHyperlinkInternetTp::Create( Window* pWindow, const SfxItemSet& rItemSet )
     204             : {
     205           0 :     return( new SvxHyperlinkInternetTp( pWindow, rItemSet ) );
     206             : }
     207             : 
     208             : /*************************************************************************
     209             : |*
     210             : |* Set initial focus
     211             : |*
     212             : |************************************************************************/
     213             : 
     214           0 : void SvxHyperlinkInternetTp::SetInitFocus()
     215             : {
     216           0 :     maCbbTarget.GrabFocus();
     217           0 : }
     218             : 
     219             : /*************************************************************************
     220             : |*
     221             : |* Contents of editfield "Target" modified
     222             : |*
     223             : |************************************************************************/
     224             : 
     225           0 : IMPL_LINK_NOARG(SvxHyperlinkInternetTp, ModifiedTargetHdl_Impl)
     226             : {
     227           0 :     OUString aScheme = GetSchemeFromURL( maCbbTarget.GetText() );
     228           0 :     if( !aScheme.isEmpty() )
     229           0 :         SetScheme( aScheme );
     230             : 
     231             :     // start timer
     232           0 :     maTimer.SetTimeout( 2500 );
     233           0 :     maTimer.Start();
     234             : 
     235           0 :     return( 0L );
     236             : }
     237             : 
     238             : /*************************************************************************
     239             : |*
     240             : |* If target-field was modify, to browse the new doc after timeout
     241             : |*
     242             : |************************************************************************/
     243             : 
     244           0 : IMPL_LINK_NOARG(SvxHyperlinkInternetTp, TimeoutHdl_Impl)
     245             : {
     246           0 :     RefreshMarkWindow();
     247           0 :     return( 0L );
     248             : }
     249             : 
     250             : /*************************************************************************
     251             : |*
     252             : |* Contents of editfield "Login" modified
     253             : |*
     254             : |************************************************************************/
     255             : 
     256           0 : IMPL_LINK_NOARG(SvxHyperlinkInternetTp, ModifiedLoginHdl_Impl)
     257             : {
     258           0 :     OUString aStrLogin ( maEdLogin.GetText() );
     259           0 :     if ( aStrLogin.equalsIgnoreAsciiCase( sAnonymous ) )
     260             :     {
     261           0 :         maCbAnonymous.Check();
     262           0 :         ClickAnonymousHdl_Impl(NULL);
     263             :     }
     264             : 
     265           0 :     return( 0L );
     266             : }
     267             : 
     268             : /*************************************************************************
     269             : |************************************************************************/
     270             : 
     271           0 : void SvxHyperlinkInternetTp::SetScheme(const OUString& rScheme)
     272             : {
     273             :     //if rScheme is empty or unknown the default beaviour is like it where HTTP
     274           0 :     sal_Bool bFTP = rScheme.startsWith(sFTPScheme);
     275           0 :     sal_Bool bInternet = !(bFTP);
     276             : 
     277             :     //update protocol button selection:
     278           0 :     maRbtLinktypFTP.Check(bFTP);
     279           0 :     maRbtLinktypInternet.Check(bInternet);
     280             : 
     281             :     //update target:
     282           0 :     RemoveImproperProtocol(rScheme);
     283           0 :     maCbbTarget.SetSmartProtocol( GetSmartProtocolFromButtons() );
     284             : 
     285             :     //show/hide  special fields for FTP:
     286           0 :     maFtLogin.Show( bFTP );
     287           0 :     maFtPassword.Show( bFTP );
     288           0 :     maEdLogin.Show( bFTP );
     289           0 :     maEdPassword.Show( bFTP );
     290           0 :     maCbAnonymous.Show( bFTP );
     291             : 
     292             :     //update 'link target in document'-window and opening-button
     293           0 :     if (rScheme.startsWith(sHTTPScheme) || rScheme.isEmpty())
     294             :     {
     295           0 :         if ( mbMarkWndOpen )
     296           0 :             ShowMarkWnd ();
     297             :     }
     298             :     else
     299             :     {
     300             :         //disable for https and ftp
     301           0 :         if ( mbMarkWndOpen )
     302           0 :             HideMarkWnd ();
     303             :     }
     304           0 : }
     305             : 
     306             : /*************************************************************************
     307             : |*
     308             : |* Remove protocol if it does not fit to the current button selection
     309             : |*
     310             : |************************************************************************/
     311             : 
     312           0 : void SvxHyperlinkInternetTp::RemoveImproperProtocol(const OUString& aProperScheme)
     313             : {
     314           0 :     OUString aStrURL ( maCbbTarget.GetText() );
     315           0 :     if ( aStrURL != aEmptyStr )
     316             :     {
     317           0 :         OUString aStrScheme(GetSchemeFromURL(aStrURL));
     318           0 :         if ( !aStrScheme.isEmpty() && aStrScheme != aProperScheme )
     319             :         {
     320           0 :             aStrURL = aStrURL.copy( aStrScheme.getLength() );
     321           0 :             maCbbTarget.SetText ( aStrURL );
     322           0 :         }
     323           0 :     }
     324           0 : }
     325             : 
     326           0 : OUString SvxHyperlinkInternetTp::GetSchemeFromButtons() const
     327             : {
     328           0 :     if( maRbtLinktypFTP.IsChecked() )
     329           0 :         return OUString(INET_FTP_SCHEME);
     330           0 :     return OUString(INET_HTTP_SCHEME);
     331             : }
     332             : 
     333           0 : INetProtocol SvxHyperlinkInternetTp::GetSmartProtocolFromButtons() const
     334             : {
     335           0 :     if( maRbtLinktypFTP.IsChecked() )
     336             :     {
     337           0 :         return INET_PROT_FTP;
     338             :     }
     339           0 :     return INET_PROT_HTTP;
     340             : }
     341             : 
     342             : /*************************************************************************
     343             : |*
     344             : |* Click on Radiobutton : Internet or FTP
     345             : |*
     346             : |************************************************************************/
     347             : 
     348           0 : IMPL_LINK_NOARG(SvxHyperlinkInternetTp, Click_SmartProtocol_Impl)
     349             : {
     350           0 :     OUString aScheme = GetSchemeFromButtons();
     351           0 :     SetScheme(aScheme);
     352           0 :     return( 0L );
     353             : }
     354             : 
     355             : /*************************************************************************
     356             : |*
     357             : |* Click on Checkbox : Anonymous user
     358             : |*
     359             : |************************************************************************/
     360             : 
     361           0 : IMPL_LINK_NOARG(SvxHyperlinkInternetTp, ClickAnonymousHdl_Impl)
     362             : {
     363             :     // disable login-editfields if checked
     364           0 :     if ( maCbAnonymous.IsChecked() )
     365             :     {
     366           0 :         if ( maEdLogin.GetText().toAsciiLowerCase().startsWith( sAnonymous ) )
     367             :         {
     368           0 :             maStrOldUser = aEmptyStr;
     369           0 :             maStrOldPassword = aEmptyStr;
     370             :         }
     371             :         else
     372             :         {
     373           0 :             maStrOldUser = maEdLogin.GetText();
     374           0 :             maStrOldPassword = maEdPassword.GetText();
     375             :         }
     376             : 
     377           0 :         setAnonymousFTPUser();
     378             :     }
     379             :     else
     380           0 :         setFTPUser(maStrOldUser, maStrOldPassword);
     381             : 
     382           0 :     return( 0L );
     383             : }
     384             : 
     385             : /*************************************************************************
     386             : |*
     387             : |* Combobox Target lost the focus
     388             : |*
     389             : |************************************************************************/
     390             : 
     391           0 : IMPL_LINK_NOARG(SvxHyperlinkInternetTp, LostFocusTargetHdl_Impl)
     392             : {
     393           0 :     RefreshMarkWindow();
     394           0 :     return (0L);
     395             : }
     396             : 
     397             : /*************************************************************************
     398             : |*
     399             : |* Click on imagebutton : Browse
     400             : |*
     401             : |************************************************************************/
     402             : 
     403           0 : IMPL_LINK_NOARG(SvxHyperlinkInternetTp, ClickBrowseHdl_Impl)
     404             : {
     405             : 
     406             :     // Open URL if available
     407             : 
     408           0 :     SfxStringItem aName( SID_FILE_NAME, OUString("http://") );
     409           0 :     SfxStringItem aRefererItem( SID_REFERER, OUString("private:user") );
     410           0 :     SfxBoolItem aNewView( SID_OPEN_NEW_VIEW, true );
     411           0 :     SfxBoolItem aSilent( SID_SILENT, true );
     412           0 :     SfxBoolItem aReadOnly( SID_DOC_READONLY, true );
     413             : 
     414           0 :     SfxBoolItem aBrowse( SID_BROWSE, true );
     415             : 
     416           0 :     const SfxPoolItem *ppItems[] = { &aName, &aNewView, &aSilent, &aReadOnly, &aRefererItem, &aBrowse, NULL };
     417           0 :     (((SvxHpLinkDlg*)mpDialog)->GetBindings())->Execute( SID_OPENDOC, ppItems, 0, SFX_CALLMODE_ASYNCHRON | SFX_CALLMODE_RECORD );
     418             : 
     419           0 :     return( 0L );
     420             : }
     421             : 
     422           0 : void SvxHyperlinkInternetTp::RefreshMarkWindow()
     423             : {
     424           0 :     if ( maRbtLinktypInternet.IsChecked() && IsMarkWndVisible() )
     425             :     {
     426           0 :         EnterWait();
     427           0 :         OUString aStrURL( CreateAbsoluteURL() );
     428           0 :         if ( aStrURL != aEmptyStr )
     429           0 :             mpMarkWnd->RefreshTree ( aStrURL );
     430             :         else
     431           0 :             mpMarkWnd->SetError( LERR_DOCNOTOPEN );
     432           0 :         LeaveWait();
     433             :     }
     434             : 
     435           0 : }
     436             : 
     437             : /*************************************************************************
     438             : |*
     439             : |* Get String from Bookmark-Wnd
     440             : |*
     441             : |************************************************************************/
     442             : 
     443           0 : void SvxHyperlinkInternetTp::SetMarkStr ( const OUString& aStrMark )
     444             : {
     445           0 :     OUString aStrURL ( maCbbTarget.GetText() );
     446             : 
     447           0 :     const sal_Unicode sUHash = '#';
     448           0 :     sal_Int32 nPos = aStrURL.lastIndexOf( sUHash );
     449             : 
     450           0 :     if( nPos != -1 )
     451           0 :         aStrURL = aStrURL.copy(0, nPos);
     452             : 
     453           0 :     aStrURL += OUString(sUHash) + aStrMark;
     454             : 
     455           0 :     maCbbTarget.SetText ( aStrURL );
     456           0 : }
     457             : 
     458             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10