LCOV - code coverage report
Current view: top level - cui/source/dialogs - hlmailtp.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 99 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 17 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             : |* Constructor / 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_pCbbReceiver, "receiver");
      45           0 :     m_pCbbReceiver->SetSmartProtocol(INetProtocol::Mailto);
      46           0 :     get(m_pBtAdrBook, "adressbook");
      47           0 :     m_pBtAdrBook->SetModeImage(Image(CUI_RES(RID_SVXBMP_ADRESSBOOK)));
      48           0 :     get(m_pFtSubject, "subject_label");
      49           0 :     get(m_pEdSubject, "subject");
      50             : 
      51             :     // Disable display of bitmap names.
      52           0 :     m_pBtAdrBook->EnableTextDisplay (false);
      53             : 
      54           0 :     InitStdControls();
      55             : 
      56           0 :     m_pCbbReceiver->Show();
      57           0 :     m_pCbbReceiver->SetHelpId( HID_HYPERDLG_MAIL_PATH );
      58             : 
      59           0 :     SetExchangeSupport ();
      60             : 
      61             :     // set handlers
      62           0 :     m_pBtAdrBook->SetClickHdl      ( LINK ( this, SvxHyperlinkMailTp, ClickAdrBookHdl_Impl ) );
      63           0 :     m_pCbbReceiver->SetModifyHdl   ( LINK ( this, SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl) );
      64             : 
      65           0 :     if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::EModule::DATABASE ) )
      66           0 :         m_pBtAdrBook->Hide();
      67           0 : }
      68             : 
      69           0 : SvxHyperlinkMailTp::~SvxHyperlinkMailTp()
      70             : {
      71           0 :     disposeOnce();
      72           0 : }
      73             : 
      74           0 : void SvxHyperlinkMailTp::dispose()
      75             : {
      76           0 :     m_pCbbReceiver.clear();
      77           0 :     m_pBtAdrBook.clear();
      78           0 :     m_pFtSubject.clear();
      79           0 :     m_pEdSubject.clear();
      80           0 :     SvxHyperlinkTabPageBase::dispose();
      81           0 : }
      82             : 
      83             : /*************************************************************************
      84             : |*
      85             : |* Fill the all dialog-controls except controls in groupbox "more..."
      86             : |*
      87             : |************************************************************************/
      88             : 
      89           0 : void SvxHyperlinkMailTp::FillDlgFields(const OUString& rStrURL)
      90             : {
      91           0 :     OUString aStrScheme = GetSchemeFromURL(rStrURL);
      92             : 
      93             :     // set URL-field and additional controls
      94           0 :     OUString aStrURLc (rStrURL);
      95             :     // set additional controls for EMail:
      96           0 :     if ( aStrScheme.startsWith( INET_MAILTO_SCHEME ) )
      97             :     {
      98             :         // Find mail-subject
      99           0 :         OUString aStrSubject, aStrTmp( aStrURLc );
     100             : 
     101           0 :         sal_Int32 nPos = aStrTmp.toAsciiLowerCase().indexOf( "subject" );
     102             : 
     103           0 :         if ( nPos != -1 )
     104           0 :             nPos = aStrTmp.indexOf( '=', nPos );
     105             : 
     106           0 :         if ( nPos != -1 )
     107           0 :             aStrSubject = aStrURLc.copy( nPos+1 );
     108             : 
     109           0 :         nPos = aStrURLc.indexOf( '?' );
     110             : 
     111           0 :         if ( nPos != -1 )
     112           0 :             aStrURLc = aStrURLc.copy( 0, nPos );
     113             : 
     114           0 :         m_pEdSubject->SetText ( aStrSubject );
     115             :     }
     116             :     else
     117             :     {
     118           0 :         m_pEdSubject->SetText (aEmptyStr);
     119             :     }
     120             : 
     121           0 :     m_pCbbReceiver->SetText ( aStrURLc );
     122             : 
     123           0 :     SetScheme( aStrScheme );
     124           0 : }
     125             : 
     126             : /*************************************************************************
     127             : |*
     128             : |* retrieve and prepare data from dialog-fields
     129             : |*
     130             : |************************************************************************/
     131             : 
     132           0 : void SvxHyperlinkMailTp::GetCurentItemData ( OUString& rStrURL, OUString& aStrName,
     133             :                                              OUString& aStrIntName, OUString& aStrFrame,
     134             :                                              SvxLinkInsertMode& eMode )
     135             : {
     136           0 :     rStrURL = CreateAbsoluteURL();
     137           0 :     GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
     138           0 : }
     139             : 
     140           0 : OUString SvxHyperlinkMailTp::CreateAbsoluteURL() const
     141             : {
     142           0 :     OUString aStrURL = m_pCbbReceiver->GetText();
     143           0 :     INetURLObject aURL(aStrURL);
     144             : 
     145           0 :     if( aURL.GetProtocol() == INetProtocol::NotValid )
     146             :     {
     147           0 :         aURL.SetSmartProtocol( INetProtocol::Mailto );
     148           0 :         aURL.SetSmartURL(aStrURL);
     149             :     }
     150             : 
     151             :     // subject for EMail-url
     152           0 :     if( aURL.GetProtocol() == INetProtocol::Mailto )
     153             :     {
     154           0 :         if ( m_pEdSubject->GetText() != OUString(aEmptyStr) )
     155             :         {
     156           0 :             OUString aQuery("subject=");
     157           0 :             aQuery += m_pEdSubject->GetText();
     158           0 :             aURL.SetParam(aQuery);
     159             :         }
     160             :     }
     161             : 
     162           0 :     if ( aURL.GetProtocol() != INetProtocol::NotValid )
     163           0 :         return aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
     164             :     else //#105788# always create a URL even if it is not valid
     165           0 :         return aStrURL;
     166             : }
     167             : 
     168             : /*************************************************************************
     169             : |*
     170             : |* static method to create Tabpage
     171             : |*
     172             : |************************************************************************/
     173             : 
     174           0 : VclPtr<IconChoicePage> SvxHyperlinkMailTp::Create( vcl::Window* pWindow, IconChoiceDialog* pDlg, const SfxItemSet& rItemSet )
     175             : {
     176           0 :     return VclPtr<SvxHyperlinkMailTp>::Create( pWindow, pDlg, rItemSet );
     177             : }
     178             : 
     179             : /*************************************************************************
     180             : |*
     181             : |* Set initial focus
     182             : |*
     183             : |************************************************************************/
     184             : 
     185           0 : void SvxHyperlinkMailTp::SetInitFocus()
     186             : {
     187           0 :     m_pCbbReceiver->GrabFocus();
     188           0 : }
     189             : 
     190             : /*************************************************************************
     191             : |************************************************************************/
     192             : 
     193           0 : void SvxHyperlinkMailTp::SetScheme(const OUString& rScheme)
     194             : {
     195           0 :     const bool bMail = true;
     196             : 
     197             :     //update target:
     198           0 :     RemoveImproperProtocol(rScheme);
     199           0 :     m_pCbbReceiver->SetSmartProtocol( INetProtocol::Mailto );
     200             : 
     201             :     //show/hide  special fields for MAIL:
     202           0 :     m_pBtAdrBook->Enable(bMail);
     203           0 :     m_pEdSubject->Enable(bMail);
     204           0 : }
     205             : 
     206             : /*************************************************************************
     207             : |*
     208             : |* Remove protocol if it does not fit to the current button selection
     209             : |*
     210             : |************************************************************************/
     211             : 
     212           0 : void SvxHyperlinkMailTp::RemoveImproperProtocol(const OUString& aProperScheme)
     213             : {
     214           0 :     OUString aStrURL ( m_pCbbReceiver->GetText() );
     215           0 :     if ( aStrURL != aEmptyStr )
     216             :     {
     217           0 :         OUString aStrScheme = GetSchemeFromURL( aStrURL );
     218           0 :         if ( aStrScheme != aEmptyStr && aStrScheme != aProperScheme )
     219             :         {
     220           0 :             aStrURL = aStrURL.copy( aStrScheme.getLength() );
     221           0 :             m_pCbbReceiver->SetText ( aStrURL );
     222           0 :         }
     223           0 :     }
     224           0 : }
     225             : 
     226             : /*************************************************************************
     227             : |*
     228             : |* Contens of editfield "receiver" modified
     229             : |*
     230             : |************************************************************************/
     231             : 
     232           0 : IMPL_LINK_NOARG(SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl)
     233             : {
     234           0 :     OUString aScheme = GetSchemeFromURL( m_pCbbReceiver->GetText() );
     235           0 :     if(!aScheme.isEmpty())
     236           0 :         SetScheme( aScheme );
     237             : 
     238           0 :     return 0L;
     239             : }
     240             : 
     241             : /*************************************************************************
     242             : |*
     243             : |* Click on imagebutton : addressbook
     244             : |*
     245             : |************************************************************************/
     246             : 
     247           0 : IMPL_STATIC_LINK_NOARG(SvxHyperlinkMailTp, ClickAdrBookHdl_Impl)
     248             : {
     249           0 :     SfxViewFrame* pViewFrame = SfxViewFrame::Current();
     250           0 :     if( pViewFrame )
     251             :     {
     252           0 :         SfxItemPool &rPool = pViewFrame->GetPool();
     253           0 :         SfxRequest aReq(SID_VIEW_DATA_SOURCE_BROWSER, SfxCallMode::SLOT, rPool);
     254           0 :         pViewFrame->ExecuteSlot( aReq, true );
     255             :     }
     256             : 
     257             : 
     258           0 :     return 0L;
     259           0 : }
     260             : 
     261             : 
     262             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11