LCOV - code coverage report
Current view: top level - libreoffice/cui/source/dialogs - hlmailtp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 116 0.9 %
Date: 2012-12-27 Functions: 2 20 10.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             : #include "hyperdlg.hrc"
      32             : 
      33             : using namespace ::rtl;
      34             : using namespace ::com::sun::star;
      35             : 
      36             : /*************************************************************************
      37             : |*
      38             : |* Contructor / Destructor
      39             : |*
      40             : |************************************************************************/
      41             : 
      42           0 : SvxHyperlinkMailTp::SvxHyperlinkMailTp ( Window *pParent, const SfxItemSet& rItemSet)
      43           0 : :   SvxHyperlinkTabPageBase ( pParent, CUI_RES( RID_SVXPAGE_HYPERLINK_MAIL ),
      44             :                               rItemSet ),
      45           0 :     maGrpMailNews   ( this, CUI_RES (GRP_MAILNEWS) ),
      46           0 :     maRbtMail       ( this, CUI_RES (RB_LINKTYP_MAIL) ),
      47           0 :     maRbtNews       ( this, CUI_RES (RB_LINKTYP_NEWS) ),
      48           0 :     maFtReceiver    ( this, CUI_RES (FT_RECEIVER) ),
      49             :     maCbbReceiver   ( this, INET_PROT_MAILTO ),
      50           0 :     maBtAdrBook     ( this, CUI_RES (BTN_ADRESSBOOK) ),
      51           0 :     maFtSubject     ( this, CUI_RES (FT_SUBJECT) ),
      52           0 :     maEdSubject     ( this, CUI_RES (ED_SUBJECT) )
      53             : {
      54             :     // Disable display of bitmap names.
      55           0 :     maBtAdrBook.EnableTextDisplay (sal_False);
      56             : 
      57           0 :     InitStdControls();
      58           0 :     FreeResource();
      59             : 
      60             :     // Init URL-Box (pos&size, Open-Handler)
      61           0 :     maCbbReceiver.SetPosSizePixel ( LogicToPixel( Point( COL_2, 25 ), MAP_APPFONT ),
      62           0 :                                     LogicToPixel( Size ( 176 - COL_DIFF, 60), MAP_APPFONT ) );
      63             : 
      64           0 :     maCbbReceiver.Show();
      65           0 :     maCbbReceiver.SetHelpId( HID_HYPERDLG_MAIL_PATH );
      66             : 
      67           0 :     SetExchangeSupport ();
      68             : 
      69             :     // set defaults
      70           0 :     maRbtMail.Check ();
      71             : 
      72             :     // overload handlers
      73           0 :     maRbtMail.SetClickHdl        ( LINK ( this, SvxHyperlinkMailTp, Click_SmartProtocol_Impl ) );
      74           0 :     maRbtNews.SetClickHdl        ( LINK ( this, SvxHyperlinkMailTp, Click_SmartProtocol_Impl ) );
      75           0 :     maBtAdrBook.SetClickHdl      ( LINK ( this, SvxHyperlinkMailTp, ClickAdrBookHdl_Impl ) );
      76           0 :     maCbbReceiver.SetModifyHdl   ( LINK ( this, SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl) );
      77             : 
      78           0 :     if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) )
      79           0 :         maBtAdrBook.Hide();
      80             : 
      81           0 :     maBtAdrBook.SetAccessibleRelationMemberOf( &maGrpMailNews );
      82           0 :     maBtAdrBook.SetAccessibleRelationLabeledBy( &maFtReceiver );
      83           0 : }
      84             : 
      85           0 : SvxHyperlinkMailTp::~SvxHyperlinkMailTp ()
      86             : {
      87           0 : }
      88             : 
      89             : /*************************************************************************
      90             : |*
      91             : |* Fill the all dialog-controls except controls in groupbox "more..."
      92             : |*
      93             : |************************************************************************/
      94             : 
      95           0 : void SvxHyperlinkMailTp::FillDlgFields ( String& aStrURL )
      96             : {
      97           0 :     const sal_Char sMailtoScheme[] = INET_MAILTO_SCHEME;
      98             : 
      99           0 :     INetURLObject aURL( aStrURL );
     100           0 :     String aStrScheme = GetSchemeFromURL( aStrURL );
     101             : 
     102             :     // set URL-field and additional controls
     103           0 :     String aStrURLc ( aStrURL );
     104             :     // set additional controls for EMail:
     105           0 :     if ( aStrScheme.SearchAscii( sMailtoScheme ) == 0 )
     106             :     {
     107             :         // Find mail-subject
     108           0 :         String aStrSubject, aStrTmp ( aStrURLc );
     109             : 
     110           0 :         const sal_Char sSubject[] = "subject";
     111           0 :         xub_StrLen nPos = aStrTmp.ToLowerAscii().SearchAscii( sSubject, 0 );
     112           0 :         nPos = aStrTmp.Search( sal_Unicode( '=' ), nPos );
     113             : 
     114           0 :         if ( nPos != STRING_NOTFOUND )
     115           0 :             aStrSubject = aStrURLc.Copy( nPos+1, aStrURLc.Len() );
     116             : 
     117           0 :         nPos = aStrURLc.Search ( sal_Unicode( '?' ), 0);
     118             : 
     119             :         aStrURLc = aStrURLc.Copy( 0, ( nPos == STRING_NOTFOUND ?
     120           0 :                                            aStrURLc.Len() : nPos ) );
     121             : 
     122           0 :         maEdSubject.SetText ( aStrSubject );
     123             :     }
     124             :     else
     125             :     {
     126           0 :         maEdSubject.SetText (aEmptyStr);
     127             :     }
     128             : 
     129           0 :     maCbbReceiver.SetText ( aStrURLc );
     130             : 
     131           0 :     SetScheme( aStrScheme );
     132           0 : }
     133             : 
     134             : /*************************************************************************
     135             : |*
     136             : |* retrieve and prepare data from dialog-fields
     137             : |*
     138             : |************************************************************************/
     139             : 
     140           0 : void SvxHyperlinkMailTp::GetCurentItemData ( String& aStrURL, String& aStrName,
     141             :                                              String& aStrIntName, String& aStrFrame,
     142             :                                              SvxLinkInsertMode& eMode )
     143             : {
     144           0 :     aStrURL = CreateAbsoluteURL();
     145           0 :     GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
     146           0 : }
     147             : 
     148           0 : String SvxHyperlinkMailTp::CreateAbsoluteURL() const
     149             : {
     150           0 :     String aStrURL = maCbbReceiver.GetText();
     151           0 :     INetURLObject aURL(aStrURL);
     152             : 
     153           0 :     if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
     154             :     {
     155           0 :         aURL.SetSmartProtocol( GetSmartProtocolFromButtons() );
     156           0 :         aURL.SetSmartURL(aStrURL);
     157             :     }
     158             : 
     159             :     // subject for EMail-url
     160           0 :     if( aURL.GetProtocol() == INET_PROT_MAILTO )
     161             :     {
     162           0 :         if ( maEdSubject.GetText() != aEmptyStr )
     163             :         {
     164           0 :             String aQuery = rtl::OUString("subject=");
     165           0 :             aQuery.Append( maEdSubject.GetText() );
     166           0 :             aURL.SetParam(aQuery);
     167             :         }
     168             :     }
     169             : 
     170           0 :     if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
     171           0 :         return aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
     172             :     else //#105788# always create a URL even if it is not valid
     173           0 :         return aStrURL;
     174             : }
     175             : 
     176             : /*************************************************************************
     177             : |*
     178             : |* static method to create Tabpage
     179             : |*
     180             : |************************************************************************/
     181             : 
     182           0 : IconChoicePage* SvxHyperlinkMailTp::Create( Window* pWindow, const SfxItemSet& rItemSet )
     183             : {
     184           0 :     return( new SvxHyperlinkMailTp( pWindow, rItemSet ) );
     185             : }
     186             : 
     187             : /*************************************************************************
     188             : |*
     189             : |* Set initial focus
     190             : |*
     191             : |************************************************************************/
     192             : 
     193           0 : void SvxHyperlinkMailTp::SetInitFocus()
     194             : {
     195           0 :     maCbbReceiver.GrabFocus();
     196           0 : }
     197             : 
     198             : /*************************************************************************
     199             : |************************************************************************/
     200             : 
     201           0 : void SvxHyperlinkMailTp::SetScheme( const String& aScheme )
     202             : {
     203             :     //if  aScheme is empty or unknown the default beaviour is like it where MAIL
     204           0 :     const sal_Char sNewsScheme[]   = INET_NEWS_SCHEME;
     205             : 
     206           0 :     sal_Bool bMail = aScheme.SearchAscii( sNewsScheme ) != 0;
     207             : 
     208             :     //update protocol button selection:
     209           0 :     maRbtMail.Check(bMail);
     210           0 :     maRbtNews.Check(!bMail);
     211             : 
     212             :     //update target:
     213           0 :     RemoveImproperProtocol(aScheme);
     214           0 :     maCbbReceiver.SetSmartProtocol( GetSmartProtocolFromButtons() );
     215             : 
     216             :     //show/hide  special fields for MAIL:
     217           0 :     maFtSubject.Enable(bMail);
     218           0 :     maEdSubject.Enable(bMail);
     219           0 : }
     220             : 
     221             : /*************************************************************************
     222             : |*
     223             : |* Remove protocol if it does not fit to the current button selection
     224             : |*
     225             : |************************************************************************/
     226             : 
     227           0 : void SvxHyperlinkMailTp::RemoveImproperProtocol(const String& aProperScheme)
     228             : {
     229           0 :     String aStrURL ( maCbbReceiver.GetText() );
     230           0 :     if ( aStrURL != aEmptyStr )
     231             :     {
     232           0 :         String aStrScheme = GetSchemeFromURL( aStrURL );
     233           0 :         if ( aStrScheme != aEmptyStr && aStrScheme != aProperScheme )
     234             :         {
     235           0 :             aStrURL.Erase ( 0, aStrScheme.Len() );
     236           0 :             maCbbReceiver.SetText ( aStrURL );
     237           0 :         }
     238           0 :     }
     239           0 : }
     240             : 
     241           0 : String SvxHyperlinkMailTp::GetSchemeFromButtons() const
     242             : {
     243           0 :     if( maRbtNews.IsChecked() )
     244           0 :         return rtl::OUString(INET_NEWS_SCHEME);
     245           0 :     return rtl::OUString(INET_MAILTO_SCHEME);
     246             : }
     247             : 
     248           0 : INetProtocol SvxHyperlinkMailTp::GetSmartProtocolFromButtons() const
     249             : {
     250           0 :     if( maRbtNews.IsChecked() )
     251             :     {
     252           0 :         return INET_PROT_NEWS;
     253             :     }
     254           0 :     return INET_PROT_MAILTO;
     255             : }
     256             : 
     257             : /*************************************************************************
     258             : |*
     259             : |* Click on radiobutton : Type EMail
     260             : |*
     261             : |************************************************************************/
     262             : 
     263           0 : IMPL_LINK_NOARG(SvxHyperlinkMailTp, Click_SmartProtocol_Impl)
     264             : {
     265           0 :     String aScheme = GetSchemeFromButtons();
     266           0 :     SetScheme( aScheme );
     267           0 :     return( 0L );
     268             : }
     269             : 
     270             : /*************************************************************************
     271             : |*
     272             : |* Contens of editfield "receiver" modified
     273             : |*
     274             : |************************************************************************/
     275             : 
     276           0 : IMPL_LINK_NOARG(SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl)
     277             : {
     278           0 :     String aScheme = GetSchemeFromURL( maCbbReceiver.GetText() );
     279           0 :     if(aScheme.Len()!=0)
     280           0 :         SetScheme( aScheme );
     281             : 
     282           0 :     return( 0L );
     283             : }
     284             : 
     285             : /*************************************************************************
     286             : |*
     287             : |* Click on imagebutton : addressbook
     288             : |*
     289             : |************************************************************************/
     290             : 
     291           0 : IMPL_LINK_NOARG(SvxHyperlinkMailTp, ClickAdrBookHdl_Impl)
     292             : {
     293           0 :     SfxViewFrame* pViewFrame = SfxViewFrame::Current();
     294           0 :     if( pViewFrame )
     295             :     {
     296           0 :         SfxItemPool &rPool = pViewFrame->GetPool();
     297           0 :         SfxRequest aReq(SID_VIEW_DATA_SOURCE_BROWSER, 0, rPool);
     298           0 :         pViewFrame->ExecuteSlot( aReq, sal_True );
     299             :     }
     300             : 
     301             : 
     302           0 :     return( 0L );
     303           3 : }
     304             : 
     305             : 
     306             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10