LCOV - code coverage report
Current view: top level - cui/source/dialogs - hlmailtp.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 111 0.0 %
Date: 2014-11-03 Functions: 0 20 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 <com/sun/star/frame/XDispatchProvider.hpp>
      21             : #include <com/sun/star/util/XURLTransformer.hpp>
      22             : #include <com/sun/star/frame/FrameSearchFlag.hpp>
      23             : #include <sfx2/request.hxx>
      24             : 
      25             : #include <comphelper/processfactory.hxx>
      26             : #include <sfx2/viewfrm.hxx>
      27             : #include <unotools/pathoptions.hxx>
      28             : #include <unotools/moduleoptions.hxx>
      29             : 
      30             : #include "hlmailtp.hxx"
      31             : 
      32             : using namespace ::com::sun::star;
      33             : 
      34             : /*************************************************************************
      35             : |*
      36             : |* Contructor / Destructor
      37             : |*
      38             : |************************************************************************/
      39             : 
      40           0 : SvxHyperlinkMailTp::SvxHyperlinkMailTp ( vcl::Window *pParent, IconChoiceDialog* pDlg, const SfxItemSet& rItemSet)
      41             : :   SvxHyperlinkTabPageBase ( pParent, pDlg, "HyperlinkMailPage", "cui/ui/hyperlinkmailpage.ui",
      42           0 :                               rItemSet )
      43             : {
      44           0 :     get(m_pRbtMail, "linktyp_mail");
      45           0 :     get(m_pRbtNews, "linktyp_news");
      46           0 :     get(m_pCbbReceiver, "receiver");
      47           0 :     m_pCbbReceiver->SetSmartProtocol(INET_PROT_MAILTO);
      48           0 :     get(m_pBtAdrBook, "adressbook");
      49           0 :     m_pBtAdrBook->SetModeImage(Image(CUI_RES(RID_SVXBMP_ADRESSBOOK)));
      50           0 :     get(m_pFtSubject, "subject_label");
      51           0 :     get(m_pEdSubject, "subject");
      52             : 
      53             :     // Disable display of bitmap names.
      54           0 :     m_pBtAdrBook->EnableTextDisplay (false);
      55             : 
      56           0 :     InitStdControls();
      57             : 
      58           0 :     m_pCbbReceiver->Show();
      59           0 :     m_pCbbReceiver->SetHelpId( HID_HYPERDLG_MAIL_PATH );
      60             : 
      61           0 :     SetExchangeSupport ();
      62             : 
      63             :     // set defaults
      64           0 :     m_pRbtMail->Check ();
      65             : 
      66             :     // overload handlers
      67           0 :     m_pRbtMail->SetClickHdl        ( LINK ( this, SvxHyperlinkMailTp, Click_SmartProtocol_Impl ) );
      68           0 :     m_pRbtNews->SetClickHdl        ( LINK ( this, SvxHyperlinkMailTp, Click_SmartProtocol_Impl ) );
      69           0 :     m_pBtAdrBook->SetClickHdl      ( LINK ( this, SvxHyperlinkMailTp, ClickAdrBookHdl_Impl ) );
      70           0 :     m_pCbbReceiver->SetModifyHdl   ( LINK ( this, SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl) );
      71             : 
      72           0 :     if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) )
      73           0 :         m_pBtAdrBook->Hide();
      74           0 : }
      75             : 
      76           0 : SvxHyperlinkMailTp::~SvxHyperlinkMailTp ()
      77             : {
      78           0 : }
      79             : 
      80             : /*************************************************************************
      81             : |*
      82             : |* Fill the all dialog-controls except controls in groupbox "more..."
      83             : |*
      84             : |************************************************************************/
      85             : 
      86           0 : void SvxHyperlinkMailTp::FillDlgFields(const OUString& rStrURL)
      87             : {
      88           0 :     OUString aStrScheme = GetSchemeFromURL(rStrURL);
      89             : 
      90             :     // set URL-field and additional controls
      91           0 :     OUString aStrURLc (rStrURL);
      92             :     // set additional controls for EMail:
      93           0 :     if ( aStrScheme.startsWith( INET_MAILTO_SCHEME ) )
      94             :     {
      95             :         // Find mail-subject
      96           0 :         OUString aStrSubject, aStrTmp( aStrURLc );
      97             : 
      98           0 :         sal_Int32 nPos = aStrTmp.toAsciiLowerCase().indexOf( "subject" );
      99             : 
     100           0 :         if ( nPos != -1 )
     101           0 :             nPos = aStrTmp.indexOf( '=', nPos );
     102             : 
     103           0 :         if ( nPos != -1 )
     104           0 :             aStrSubject = aStrURLc.copy( nPos+1 );
     105             : 
     106           0 :         nPos = aStrURLc.indexOf( '?' );
     107             : 
     108           0 :         if ( nPos != -1 )
     109           0 :             aStrURLc = aStrURLc.copy( 0, nPos );
     110             : 
     111           0 :         m_pEdSubject->SetText ( aStrSubject );
     112             :     }
     113             :     else
     114             :     {
     115           0 :         m_pEdSubject->SetText (aEmptyStr);
     116             :     }
     117             : 
     118           0 :     m_pCbbReceiver->SetText ( aStrURLc );
     119             : 
     120           0 :     SetScheme( aStrScheme );
     121           0 : }
     122             : 
     123             : /*************************************************************************
     124             : |*
     125             : |* retrieve and prepare data from dialog-fields
     126             : |*
     127             : |************************************************************************/
     128             : 
     129           0 : void SvxHyperlinkMailTp::GetCurentItemData ( OUString& rStrURL, OUString& aStrName,
     130             :                                              OUString& aStrIntName, OUString& aStrFrame,
     131             :                                              SvxLinkInsertMode& eMode )
     132             : {
     133           0 :     rStrURL = CreateAbsoluteURL();
     134           0 :     GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
     135           0 : }
     136             : 
     137           0 : OUString SvxHyperlinkMailTp::CreateAbsoluteURL() const
     138             : {
     139           0 :     OUString aStrURL = m_pCbbReceiver->GetText();
     140           0 :     INetURLObject aURL(aStrURL);
     141             : 
     142           0 :     if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
     143             :     {
     144           0 :         aURL.SetSmartProtocol( GetSmartProtocolFromButtons() );
     145           0 :         aURL.SetSmartURL(aStrURL);
     146             :     }
     147             : 
     148             :     // subject for EMail-url
     149           0 :     if( aURL.GetProtocol() == INET_PROT_MAILTO )
     150             :     {
     151           0 :         if ( m_pEdSubject->GetText() != OUString(aEmptyStr) )
     152             :         {
     153           0 :             OUString aQuery("subject=");
     154           0 :             aQuery += m_pEdSubject->GetText();
     155           0 :             aURL.SetParam(aQuery);
     156             :         }
     157             :     }
     158             : 
     159           0 :     if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
     160           0 :         return aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
     161             :     else //#105788# always create a URL even if it is not valid
     162           0 :         return aStrURL;
     163             : }
     164             : 
     165             : /*************************************************************************
     166             : |*
     167             : |* static method to create Tabpage
     168             : |*
     169             : |************************************************************************/
     170             : 
     171           0 : IconChoicePage* SvxHyperlinkMailTp::Create( vcl::Window* pWindow, IconChoiceDialog* pDlg, const SfxItemSet& rItemSet )
     172             : {
     173           0 :     return( new SvxHyperlinkMailTp( pWindow, pDlg, rItemSet ) );
     174             : }
     175             : 
     176             : /*************************************************************************
     177             : |*
     178             : |* Set initial focus
     179             : |*
     180             : |************************************************************************/
     181             : 
     182           0 : void SvxHyperlinkMailTp::SetInitFocus()
     183             : {
     184           0 :     m_pCbbReceiver->GrabFocus();
     185           0 : }
     186             : 
     187             : /*************************************************************************
     188             : |************************************************************************/
     189             : 
     190           0 : void SvxHyperlinkMailTp::SetScheme(const OUString& rScheme)
     191             : {
     192             :     //if rScheme is empty or unknown the default beaviour is like it where MAIL
     193           0 :     const sal_Char sNewsScheme[]   = INET_NEWS_SCHEME;
     194             : 
     195           0 :     bool bMail = !rScheme.startsWith(sNewsScheme);
     196             : 
     197             :     //update protocol button selection:
     198           0 :     m_pRbtMail->Check(bMail);
     199           0 :     m_pRbtNews->Check(!bMail);
     200             : 
     201             :     //update target:
     202           0 :     RemoveImproperProtocol(rScheme);
     203           0 :     m_pCbbReceiver->SetSmartProtocol( GetSmartProtocolFromButtons() );
     204             : 
     205             :     //show/hide  special fields for MAIL:
     206           0 :     m_pBtAdrBook->Enable(bMail);
     207           0 :     m_pEdSubject->Enable(bMail);
     208           0 : }
     209             : 
     210             : /*************************************************************************
     211             : |*
     212             : |* Remove protocol if it does not fit to the current button selection
     213             : |*
     214             : |************************************************************************/
     215             : 
     216           0 : void SvxHyperlinkMailTp::RemoveImproperProtocol(const OUString& aProperScheme)
     217             : {
     218           0 :     OUString aStrURL ( m_pCbbReceiver->GetText() );
     219           0 :     if ( aStrURL != aEmptyStr )
     220             :     {
     221           0 :         OUString aStrScheme = GetSchemeFromURL( aStrURL );
     222           0 :         if ( aStrScheme != aEmptyStr && aStrScheme != aProperScheme )
     223             :         {
     224           0 :             aStrURL = aStrURL.copy( aStrScheme.getLength() );
     225           0 :             m_pCbbReceiver->SetText ( aStrURL );
     226           0 :         }
     227           0 :     }
     228           0 : }
     229             : 
     230           0 : OUString SvxHyperlinkMailTp::GetSchemeFromButtons() const
     231             : {
     232           0 :     if( m_pRbtNews->IsChecked() )
     233           0 :         return OUString(INET_NEWS_SCHEME);
     234           0 :     return OUString(INET_MAILTO_SCHEME);
     235             : }
     236             : 
     237           0 : INetProtocol SvxHyperlinkMailTp::GetSmartProtocolFromButtons() const
     238             : {
     239           0 :     if( m_pRbtNews->IsChecked() )
     240             :     {
     241           0 :         return INET_PROT_NEWS;
     242             :     }
     243           0 :     return INET_PROT_MAILTO;
     244             : }
     245             : 
     246             : /*************************************************************************
     247             : |*
     248             : |* Click on radiobutton : Type EMail
     249             : |*
     250             : |************************************************************************/
     251             : 
     252           0 : IMPL_LINK_NOARG(SvxHyperlinkMailTp, Click_SmartProtocol_Impl)
     253             : {
     254           0 :     OUString aScheme = GetSchemeFromButtons();
     255           0 :     SetScheme( aScheme );
     256           0 :     return( 0L );
     257             : }
     258             : 
     259             : /*************************************************************************
     260             : |*
     261             : |* Contens of editfield "receiver" modified
     262             : |*
     263             : |************************************************************************/
     264             : 
     265           0 : IMPL_LINK_NOARG(SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl)
     266             : {
     267           0 :     OUString aScheme = GetSchemeFromURL( m_pCbbReceiver->GetText() );
     268           0 :     if(!aScheme.isEmpty())
     269           0 :         SetScheme( aScheme );
     270             : 
     271           0 :     return( 0L );
     272             : }
     273             : 
     274             : /*************************************************************************
     275             : |*
     276             : |* Click on imagebutton : addressbook
     277             : |*
     278             : |************************************************************************/
     279             : 
     280           0 : IMPL_LINK_NOARG(SvxHyperlinkMailTp, ClickAdrBookHdl_Impl)
     281             : {
     282           0 :     SfxViewFrame* pViewFrame = SfxViewFrame::Current();
     283           0 :     if( pViewFrame )
     284             :     {
     285           0 :         SfxItemPool &rPool = pViewFrame->GetPool();
     286           0 :         SfxRequest aReq(SID_VIEW_DATA_SOURCE_BROWSER, SfxCallMode::SLOT, rPool);
     287           0 :         pViewFrame->ExecuteSlot( aReq, true );
     288             :     }
     289             : 
     290             : 
     291           0 :     return( 0L );
     292           0 : }
     293             : 
     294             : 
     295             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10