LCOV - code coverage report
Current view: top level - cui/source/dialogs - hlmailtp.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 115 0.0 %
Date: 2014-04-14 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             : #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 (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(const OUString& rStrURL)
      96             : {
      97           0 :     OUString aStrScheme = GetSchemeFromURL(rStrURL);
      98             : 
      99             :     // set URL-field and additional controls
     100           0 :     OUString aStrURLc (rStrURL);
     101             :     // set additional controls for EMail:
     102           0 :     if ( aStrScheme.startsWith( INET_MAILTO_SCHEME ) )
     103             :     {
     104             :         // Find mail-subject
     105           0 :         OUString aStrSubject, aStrTmp( aStrURLc );
     106             : 
     107           0 :         sal_Int32 nPos = aStrTmp.toAsciiLowerCase().indexOf( "subject" );
     108             : 
     109           0 :         if ( nPos != -1 )
     110           0 :             nPos = aStrTmp.indexOf( '=', nPos );
     111             : 
     112           0 :         if ( nPos != -1 )
     113           0 :             aStrSubject = aStrURLc.copy( nPos+1 );
     114             : 
     115           0 :         nPos = aStrURLc.indexOf( '?' );
     116             : 
     117           0 :         if ( nPos != -1 )
     118           0 :             aStrURLc = aStrURLc.copy( 0, nPos );
     119             : 
     120           0 :         maEdSubject.SetText ( aStrSubject );
     121             :     }
     122             :     else
     123             :     {
     124           0 :         maEdSubject.SetText (aEmptyStr);
     125             :     }
     126             : 
     127           0 :     maCbbReceiver.SetText ( aStrURLc );
     128             : 
     129           0 :     SetScheme( aStrScheme );
     130           0 : }
     131             : 
     132             : /*************************************************************************
     133             : |*
     134             : |* retrieve and prepare data from dialog-fields
     135             : |*
     136             : |************************************************************************/
     137             : 
     138           0 : void SvxHyperlinkMailTp::GetCurentItemData ( OUString& rStrURL, OUString& aStrName,
     139             :                                              OUString& aStrIntName, OUString& aStrFrame,
     140             :                                              SvxLinkInsertMode& eMode )
     141             : {
     142           0 :     rStrURL = CreateAbsoluteURL();
     143           0 :     GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
     144           0 : }
     145             : 
     146           0 : OUString SvxHyperlinkMailTp::CreateAbsoluteURL() const
     147             : {
     148           0 :     OUString aStrURL = maCbbReceiver.GetText();
     149           0 :     INetURLObject aURL(aStrURL);
     150             : 
     151           0 :     if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
     152             :     {
     153           0 :         aURL.SetSmartProtocol( GetSmartProtocolFromButtons() );
     154           0 :         aURL.SetSmartURL(aStrURL);
     155             :     }
     156             : 
     157             :     // subject for EMail-url
     158           0 :     if( aURL.GetProtocol() == INET_PROT_MAILTO )
     159             :     {
     160           0 :         if ( maEdSubject.GetText() != OUString(aEmptyStr) )
     161             :         {
     162           0 :             OUString aQuery("subject=");
     163           0 :             aQuery += maEdSubject.GetText();
     164           0 :             aURL.SetParam(aQuery);
     165             :         }
     166             :     }
     167             : 
     168           0 :     if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
     169           0 :         return aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
     170             :     else //#105788# always create a URL even if it is not valid
     171           0 :         return aStrURL;
     172             : }
     173             : 
     174             : /*************************************************************************
     175             : |*
     176             : |* static method to create Tabpage
     177             : |*
     178             : |************************************************************************/
     179             : 
     180           0 : IconChoicePage* SvxHyperlinkMailTp::Create( Window* pWindow, const SfxItemSet& rItemSet )
     181             : {
     182           0 :     return( new SvxHyperlinkMailTp( pWindow, rItemSet ) );
     183             : }
     184             : 
     185             : /*************************************************************************
     186             : |*
     187             : |* Set initial focus
     188             : |*
     189             : |************************************************************************/
     190             : 
     191           0 : void SvxHyperlinkMailTp::SetInitFocus()
     192             : {
     193           0 :     maCbbReceiver.GrabFocus();
     194           0 : }
     195             : 
     196             : /*************************************************************************
     197             : |************************************************************************/
     198             : 
     199           0 : void SvxHyperlinkMailTp::SetScheme(const OUString& rScheme)
     200             : {
     201             :     //if rScheme is empty or unknown the default beaviour is like it where MAIL
     202           0 :     const sal_Char sNewsScheme[]   = INET_NEWS_SCHEME;
     203             : 
     204           0 :     bool bMail = !rScheme.startsWith(sNewsScheme);
     205             : 
     206             :     //update protocol button selection:
     207           0 :     maRbtMail.Check(bMail);
     208           0 :     maRbtNews.Check(!bMail);
     209             : 
     210             :     //update target:
     211           0 :     RemoveImproperProtocol(rScheme);
     212           0 :     maCbbReceiver.SetSmartProtocol( GetSmartProtocolFromButtons() );
     213             : 
     214             :     //show/hide  special fields for MAIL:
     215           0 :     maFtSubject.Enable(bMail);
     216           0 :     maEdSubject.Enable(bMail);
     217           0 : }
     218             : 
     219             : /*************************************************************************
     220             : |*
     221             : |* Remove protocol if it does not fit to the current button selection
     222             : |*
     223             : |************************************************************************/
     224             : 
     225           0 : void SvxHyperlinkMailTp::RemoveImproperProtocol(const OUString& aProperScheme)
     226             : {
     227           0 :     OUString aStrURL ( maCbbReceiver.GetText() );
     228           0 :     if ( aStrURL != aEmptyStr )
     229             :     {
     230           0 :         OUString aStrScheme = GetSchemeFromURL( aStrURL );
     231           0 :         if ( aStrScheme != aEmptyStr && aStrScheme != aProperScheme )
     232             :         {
     233           0 :             aStrURL = aStrURL.copy( aStrScheme.getLength() );
     234           0 :             maCbbReceiver.SetText ( aStrURL );
     235           0 :         }
     236           0 :     }
     237           0 : }
     238             : 
     239           0 : OUString SvxHyperlinkMailTp::GetSchemeFromButtons() const
     240             : {
     241           0 :     if( maRbtNews.IsChecked() )
     242           0 :         return OUString(INET_NEWS_SCHEME);
     243           0 :     return OUString(INET_MAILTO_SCHEME);
     244             : }
     245             : 
     246           0 : INetProtocol SvxHyperlinkMailTp::GetSmartProtocolFromButtons() const
     247             : {
     248           0 :     if( maRbtNews.IsChecked() )
     249             :     {
     250           0 :         return INET_PROT_NEWS;
     251             :     }
     252           0 :     return INET_PROT_MAILTO;
     253             : }
     254             : 
     255             : /*************************************************************************
     256             : |*
     257             : |* Click on radiobutton : Type EMail
     258             : |*
     259             : |************************************************************************/
     260             : 
     261           0 : IMPL_LINK_NOARG(SvxHyperlinkMailTp, Click_SmartProtocol_Impl)
     262             : {
     263           0 :     OUString aScheme = GetSchemeFromButtons();
     264           0 :     SetScheme( aScheme );
     265           0 :     return( 0L );
     266             : }
     267             : 
     268             : /*************************************************************************
     269             : |*
     270             : |* Contens of editfield "receiver" modified
     271             : |*
     272             : |************************************************************************/
     273             : 
     274           0 : IMPL_LINK_NOARG(SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl)
     275             : {
     276           0 :     OUString aScheme = GetSchemeFromURL( maCbbReceiver.GetText() );
     277           0 :     if(!aScheme.isEmpty())
     278           0 :         SetScheme( aScheme );
     279             : 
     280           0 :     return( 0L );
     281             : }
     282             : 
     283             : /*************************************************************************
     284             : |*
     285             : |* Click on imagebutton : addressbook
     286             : |*
     287             : |************************************************************************/
     288             : 
     289           0 : IMPL_LINK_NOARG(SvxHyperlinkMailTp, ClickAdrBookHdl_Impl)
     290             : {
     291           0 :     SfxViewFrame* pViewFrame = SfxViewFrame::Current();
     292           0 :     if( pViewFrame )
     293             :     {
     294           0 :         SfxItemPool &rPool = pViewFrame->GetPool();
     295           0 :         SfxRequest aReq(SID_VIEW_DATA_SOURCE_BROWSER, 0, rPool);
     296           0 :         pViewFrame->ExecuteSlot( aReq, true );
     297             :     }
     298             : 
     299             : 
     300           0 :     return( 0L );
     301           0 : }
     302             : 
     303             : 
     304             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10