1*2ee96f1cSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2ee96f1cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2ee96f1cSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2ee96f1cSAndrew Rist * distributed with this work for additional information 6*2ee96f1cSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2ee96f1cSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2ee96f1cSAndrew Rist * "License"); you may not use this file except in compliance 9*2ee96f1cSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*2ee96f1cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*2ee96f1cSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2ee96f1cSAndrew Rist * software distributed under the License is distributed on an 15*2ee96f1cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2ee96f1cSAndrew Rist * KIND, either express or implied. See the License for the 17*2ee96f1cSAndrew Rist * specific language governing permissions and limitations 18*2ee96f1cSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*2ee96f1cSAndrew Rist *************************************************************/ 21*2ee96f1cSAndrew Rist 22*2ee96f1cSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_cui.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 28cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp> 29cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp> 30cdf0e10cSrcweir #include <sfx2/request.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 33cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 34cdf0e10cSrcweir #include <unotools/pathoptions.hxx> 35cdf0e10cSrcweir #include <unotools/moduleoptions.hxx> 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include "hlmailtp.hxx" 38cdf0e10cSrcweir #include "hyperdlg.hrc" 39cdf0e10cSrcweir 40cdf0e10cSrcweir using namespace ::rtl; 41cdf0e10cSrcweir using namespace ::com::sun::star; 42cdf0e10cSrcweir 43cdf0e10cSrcweir /************************************************************************* 44cdf0e10cSrcweir |* 45cdf0e10cSrcweir |* Contructor / Destructor 46cdf0e10cSrcweir |* 47cdf0e10cSrcweir |************************************************************************/ 48cdf0e10cSrcweir 49cdf0e10cSrcweir SvxHyperlinkMailTp::SvxHyperlinkMailTp ( Window *pParent, const SfxItemSet& rItemSet) 50cdf0e10cSrcweir : SvxHyperlinkTabPageBase ( pParent, CUI_RES( RID_SVXPAGE_HYPERLINK_MAIL ), 51cdf0e10cSrcweir rItemSet ), 52cdf0e10cSrcweir maGrpMailNews ( this, CUI_RES (GRP_MAILNEWS) ), 53cdf0e10cSrcweir maRbtMail ( this, CUI_RES (RB_LINKTYP_MAIL) ), 54cdf0e10cSrcweir maRbtNews ( this, CUI_RES (RB_LINKTYP_NEWS) ), 55cdf0e10cSrcweir maFtReceiver ( this, CUI_RES (FT_RECEIVER) ), 56cdf0e10cSrcweir maCbbReceiver ( this, INET_PROT_MAILTO ), 57cdf0e10cSrcweir maBtAdrBook ( this, CUI_RES (BTN_ADRESSBOOK) ), 58cdf0e10cSrcweir maFtSubject ( this, CUI_RES (FT_SUBJECT) ), 59cdf0e10cSrcweir maEdSubject ( this, CUI_RES (ED_SUBJECT) ) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir // Set HC bitmaps and disable display of bitmap names. 62cdf0e10cSrcweir maBtAdrBook.SetModeImage( Image( CUI_RES( IMG_ADRESSBOOK_HC ) ), BMP_COLOR_HIGHCONTRAST ); 63cdf0e10cSrcweir maBtAdrBook.EnableTextDisplay (sal_False); 64cdf0e10cSrcweir 65cdf0e10cSrcweir InitStdControls(); 66cdf0e10cSrcweir FreeResource(); 67cdf0e10cSrcweir 68cdf0e10cSrcweir // Init URL-Box (pos&size, Open-Handler) 69cdf0e10cSrcweir maCbbReceiver.SetPosSizePixel ( LogicToPixel( Point( COL_2, 25 ), MAP_APPFONT ), 70cdf0e10cSrcweir LogicToPixel( Size ( 176 - COL_DIFF, 60), MAP_APPFONT ) ); 71cdf0e10cSrcweir 72cdf0e10cSrcweir maCbbReceiver.Show(); 73cdf0e10cSrcweir maCbbReceiver.SetHelpId( HID_HYPERDLG_MAIL_PATH ); 74cdf0e10cSrcweir 75cdf0e10cSrcweir SetExchangeSupport (); 76cdf0e10cSrcweir 77cdf0e10cSrcweir // set defaults 78cdf0e10cSrcweir maRbtMail.Check (); 79cdf0e10cSrcweir 80cdf0e10cSrcweir // overload handlers 81cdf0e10cSrcweir maRbtMail.SetClickHdl ( LINK ( this, SvxHyperlinkMailTp, Click_SmartProtocol_Impl ) ); 82cdf0e10cSrcweir maRbtNews.SetClickHdl ( LINK ( this, SvxHyperlinkMailTp, Click_SmartProtocol_Impl ) ); 83cdf0e10cSrcweir maBtAdrBook.SetClickHdl ( LINK ( this, SvxHyperlinkMailTp, ClickAdrBookHdl_Impl ) ); 84cdf0e10cSrcweir maCbbReceiver.SetModifyHdl ( LINK ( this, SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl) ); 85cdf0e10cSrcweir 86cdf0e10cSrcweir if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) ) 87cdf0e10cSrcweir maBtAdrBook.Hide(); 88cdf0e10cSrcweir 89cdf0e10cSrcweir maBtAdrBook.SetAccessibleRelationMemberOf( &maGrpMailNews ); 90cdf0e10cSrcweir maBtAdrBook.SetAccessibleRelationLabeledBy( &maFtReceiver ); 91cdf0e10cSrcweir } 92cdf0e10cSrcweir 93cdf0e10cSrcweir SvxHyperlinkMailTp::~SvxHyperlinkMailTp () 94cdf0e10cSrcweir { 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir /************************************************************************* 98cdf0e10cSrcweir |* 99cdf0e10cSrcweir |* Fill the all dialog-controls except controls in groupbox "more..." 100cdf0e10cSrcweir |* 101cdf0e10cSrcweir |************************************************************************/ 102cdf0e10cSrcweir 103cdf0e10cSrcweir void SvxHyperlinkMailTp::FillDlgFields ( String& aStrURL ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir const sal_Char sMailtoScheme[] = INET_MAILTO_SCHEME; 106cdf0e10cSrcweir 107cdf0e10cSrcweir INetURLObject aURL( aStrURL ); 108cdf0e10cSrcweir String aStrScheme = GetSchemeFromURL( aStrURL ); 109cdf0e10cSrcweir 110cdf0e10cSrcweir // set URL-field and additional controls 111cdf0e10cSrcweir String aStrURLc ( aStrURL ); 112cdf0e10cSrcweir // set additional controls for EMail: 113cdf0e10cSrcweir if ( aStrScheme.SearchAscii( sMailtoScheme ) == 0 ) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir // Find mail-subject 116cdf0e10cSrcweir String aStrSubject, aStrTmp ( aStrURLc ); 117cdf0e10cSrcweir 118cdf0e10cSrcweir const sal_Char sSubject[] = "subject"; 119cdf0e10cSrcweir xub_StrLen nPos = aStrTmp.ToLowerAscii().SearchAscii( sSubject, 0 ); 120cdf0e10cSrcweir nPos = aStrTmp.Search( sal_Unicode( '=' ), nPos ); 121cdf0e10cSrcweir 122cdf0e10cSrcweir if ( nPos != STRING_NOTFOUND ) 123cdf0e10cSrcweir aStrSubject = aStrURLc.Copy( nPos+1, aStrURLc.Len() ); 124cdf0e10cSrcweir 125cdf0e10cSrcweir nPos = aStrURLc.Search ( sal_Unicode( '?' ), 0); 126cdf0e10cSrcweir 127cdf0e10cSrcweir aStrURLc = aStrURLc.Copy( 0, ( nPos == STRING_NOTFOUND ? 128cdf0e10cSrcweir aStrURLc.Len() : nPos ) ); 129cdf0e10cSrcweir 130cdf0e10cSrcweir maEdSubject.SetText ( aStrSubject ); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir else 133cdf0e10cSrcweir { 134cdf0e10cSrcweir maEdSubject.SetText (aEmptyStr); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir maCbbReceiver.SetText ( aStrURLc ); 138cdf0e10cSrcweir 139cdf0e10cSrcweir SetScheme( aStrScheme ); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir /************************************************************************* 143cdf0e10cSrcweir |* 144cdf0e10cSrcweir |* retrieve and prepare data from dialog-fields 145cdf0e10cSrcweir |* 146cdf0e10cSrcweir |************************************************************************/ 147cdf0e10cSrcweir 148cdf0e10cSrcweir void SvxHyperlinkMailTp::GetCurentItemData ( String& aStrURL, String& aStrName, 149cdf0e10cSrcweir String& aStrIntName, String& aStrFrame, 150cdf0e10cSrcweir SvxLinkInsertMode& eMode ) 151cdf0e10cSrcweir { 152cdf0e10cSrcweir aStrURL = CreateAbsoluteURL(); 153cdf0e10cSrcweir GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode ); 154cdf0e10cSrcweir } 155cdf0e10cSrcweir 156cdf0e10cSrcweir String SvxHyperlinkMailTp::CreateAbsoluteURL() const 157cdf0e10cSrcweir { 158cdf0e10cSrcweir String aStrURL = maCbbReceiver.GetText(); 159cdf0e10cSrcweir INetURLObject aURL(aStrURL); 160cdf0e10cSrcweir 161cdf0e10cSrcweir if( aURL.GetProtocol() == INET_PROT_NOT_VALID ) 162cdf0e10cSrcweir { 163cdf0e10cSrcweir aURL.SetSmartProtocol( GetSmartProtocolFromButtons() ); 164cdf0e10cSrcweir aURL.SetSmartURL(aStrURL); 165cdf0e10cSrcweir } 166cdf0e10cSrcweir 167cdf0e10cSrcweir // subject for EMail-url 168cdf0e10cSrcweir if( aURL.GetProtocol() == INET_PROT_MAILTO ) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir if ( maEdSubject.GetText() != aEmptyStr ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir String aQuery = UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "subject=" ) ); 173cdf0e10cSrcweir aQuery.Append( maEdSubject.GetText() ); 174cdf0e10cSrcweir aURL.SetParam(aQuery); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir if ( aURL.GetProtocol() != INET_PROT_NOT_VALID ) 179cdf0e10cSrcweir return aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET ); 180cdf0e10cSrcweir else //#105788# always create a URL even if it is not valid 181cdf0e10cSrcweir return aStrURL; 182cdf0e10cSrcweir } 183cdf0e10cSrcweir 184cdf0e10cSrcweir /************************************************************************* 185cdf0e10cSrcweir |* 186cdf0e10cSrcweir |* static method to create Tabpage 187cdf0e10cSrcweir |* 188cdf0e10cSrcweir |************************************************************************/ 189cdf0e10cSrcweir 190cdf0e10cSrcweir IconChoicePage* SvxHyperlinkMailTp::Create( Window* pWindow, const SfxItemSet& rItemSet ) 191cdf0e10cSrcweir { 192cdf0e10cSrcweir return( new SvxHyperlinkMailTp( pWindow, rItemSet ) ); 193cdf0e10cSrcweir } 194cdf0e10cSrcweir 195cdf0e10cSrcweir /************************************************************************* 196cdf0e10cSrcweir |* 197cdf0e10cSrcweir |* Set initial focus 198cdf0e10cSrcweir |* 199cdf0e10cSrcweir |************************************************************************/ 200cdf0e10cSrcweir 201cdf0e10cSrcweir void SvxHyperlinkMailTp::SetInitFocus() 202cdf0e10cSrcweir { 203cdf0e10cSrcweir maCbbReceiver.GrabFocus(); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir /************************************************************************* 207cdf0e10cSrcweir |************************************************************************/ 208cdf0e10cSrcweir 209cdf0e10cSrcweir void SvxHyperlinkMailTp::SetScheme( const String& aScheme ) 210cdf0e10cSrcweir { 211cdf0e10cSrcweir //if aScheme is empty or unknown the default beaviour is like it where MAIL 212cdf0e10cSrcweir const sal_Char sNewsScheme[] = INET_NEWS_SCHEME; 213cdf0e10cSrcweir 214cdf0e10cSrcweir sal_Bool bMail = aScheme.SearchAscii( sNewsScheme ) != 0; 215cdf0e10cSrcweir 216cdf0e10cSrcweir //update protocol button selection: 217cdf0e10cSrcweir maRbtMail.Check(bMail); 218cdf0e10cSrcweir maRbtNews.Check(!bMail); 219cdf0e10cSrcweir 220cdf0e10cSrcweir //update target: 221cdf0e10cSrcweir RemoveImproperProtocol(aScheme); 222cdf0e10cSrcweir maCbbReceiver.SetSmartProtocol( GetSmartProtocolFromButtons() ); 223cdf0e10cSrcweir 224cdf0e10cSrcweir //show/hide special fields for MAIL: 225cdf0e10cSrcweir maFtSubject.Enable(bMail); 226cdf0e10cSrcweir maEdSubject.Enable(bMail); 227cdf0e10cSrcweir } 228cdf0e10cSrcweir 229cdf0e10cSrcweir /************************************************************************* 230cdf0e10cSrcweir |* 231cdf0e10cSrcweir |* Remove protocol if it does not fit to the current button selection 232cdf0e10cSrcweir |* 233cdf0e10cSrcweir |************************************************************************/ 234cdf0e10cSrcweir 235cdf0e10cSrcweir void SvxHyperlinkMailTp::RemoveImproperProtocol(const String& aProperScheme) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir String aStrURL ( maCbbReceiver.GetText() ); 238cdf0e10cSrcweir if ( aStrURL != aEmptyStr ) 239cdf0e10cSrcweir { 240cdf0e10cSrcweir String aStrScheme = GetSchemeFromURL( aStrURL ); 241cdf0e10cSrcweir if ( aStrScheme != aEmptyStr && aStrScheme != aProperScheme ) 242cdf0e10cSrcweir { 243cdf0e10cSrcweir aStrURL.Erase ( 0, aStrScheme.Len() ); 244cdf0e10cSrcweir maCbbReceiver.SetText ( aStrURL ); 245cdf0e10cSrcweir } 246cdf0e10cSrcweir } 247cdf0e10cSrcweir } 248cdf0e10cSrcweir 249cdf0e10cSrcweir String SvxHyperlinkMailTp::GetSchemeFromButtons() const 250cdf0e10cSrcweir { 251cdf0e10cSrcweir if( maRbtNews.IsChecked() ) 252cdf0e10cSrcweir { 253cdf0e10cSrcweir return String::CreateFromAscii( INET_NEWS_SCHEME ); 254cdf0e10cSrcweir } 255cdf0e10cSrcweir return String::CreateFromAscii( INET_MAILTO_SCHEME ); 256cdf0e10cSrcweir } 257cdf0e10cSrcweir 258cdf0e10cSrcweir INetProtocol SvxHyperlinkMailTp::GetSmartProtocolFromButtons() const 259cdf0e10cSrcweir { 260cdf0e10cSrcweir if( maRbtNews.IsChecked() ) 261cdf0e10cSrcweir { 262cdf0e10cSrcweir return INET_PROT_NEWS; 263cdf0e10cSrcweir } 264cdf0e10cSrcweir return INET_PROT_MAILTO; 265cdf0e10cSrcweir } 266cdf0e10cSrcweir 267cdf0e10cSrcweir /************************************************************************* 268cdf0e10cSrcweir |* 269cdf0e10cSrcweir |* Click on radiobutton : Type EMail 270cdf0e10cSrcweir |* 271cdf0e10cSrcweir |************************************************************************/ 272cdf0e10cSrcweir 273cdf0e10cSrcweir IMPL_LINK ( SvxHyperlinkMailTp, Click_SmartProtocol_Impl, void *, EMPTYARG ) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir String aScheme = GetSchemeFromButtons(); 276cdf0e10cSrcweir SetScheme( aScheme ); 277cdf0e10cSrcweir return( 0L ); 278cdf0e10cSrcweir } 279cdf0e10cSrcweir 280cdf0e10cSrcweir /************************************************************************* 281cdf0e10cSrcweir |* 282cdf0e10cSrcweir |* Contens of editfield "receiver" modified 283cdf0e10cSrcweir |* 284cdf0e10cSrcweir |************************************************************************/ 285cdf0e10cSrcweir 286cdf0e10cSrcweir IMPL_LINK ( SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl, void *, EMPTYARG ) 287cdf0e10cSrcweir { 288cdf0e10cSrcweir String aScheme = GetSchemeFromURL( maCbbReceiver.GetText() ); 289cdf0e10cSrcweir if(aScheme.Len()!=0) 290cdf0e10cSrcweir SetScheme( aScheme ); 291cdf0e10cSrcweir 292cdf0e10cSrcweir return( 0L ); 293cdf0e10cSrcweir } 294cdf0e10cSrcweir 295cdf0e10cSrcweir /************************************************************************* 296cdf0e10cSrcweir |* 297cdf0e10cSrcweir |* Click on imagebutton : addressbook 298cdf0e10cSrcweir |* 299cdf0e10cSrcweir |************************************************************************/ 300cdf0e10cSrcweir 301cdf0e10cSrcweir IMPL_LINK ( SvxHyperlinkMailTp, ClickAdrBookHdl_Impl, void *, EMPTYARG ) 302cdf0e10cSrcweir { 303cdf0e10cSrcweir SfxViewFrame* pViewFrame = SfxViewFrame::Current(); 304cdf0e10cSrcweir if( pViewFrame ) 305cdf0e10cSrcweir { 306cdf0e10cSrcweir SfxItemPool &rPool = pViewFrame->GetPool(); 307cdf0e10cSrcweir SfxRequest aReq(SID_VIEW_DATA_SOURCE_BROWSER, 0, rPool); 308cdf0e10cSrcweir pViewFrame->ExecuteSlot( aReq, sal_True ); 309cdf0e10cSrcweir } 310cdf0e10cSrcweir 311cdf0e10cSrcweir 312cdf0e10cSrcweir /* uno::Reference< frame::XDispatchProvider > xProv( pViewFrame->GetFrame().GetFrameInterface(), uno::UNO_QUERY ); 313cdf0e10cSrcweir if ( xProv.is() ) 314cdf0e10cSrcweir { 315cdf0e10cSrcweir !!! (pb) we need a new config item here 316cdf0e10cSrcweir SfxAppIniManagerProperty aProp; 317cdf0e10cSrcweir GetpApp()->Property( aProp ); 318cdf0e10cSrcweir if( !aProp.GetIniManager() ) 319cdf0e10cSrcweir return ( 0L ); 320cdf0e10cSrcweir 321cdf0e10cSrcweir String aAddressBook = aProp.GetIniManager()->Get( SFX_KEY_ADDRESSBOOK ); 322cdf0e10cSrcweir INetURLObject aObj; 323cdf0e10cSrcweir aObj.SetSmartProtocol( INET_PROT_FILE ); 324cdf0e10cSrcweir aObj.SetURL( aAddressBook.GetToken( 0, sal_Unicode( ';' ) ) ); 325cdf0e10cSrcweir 326cdf0e10cSrcweir String aMark( RTL_CONSTASCII_USTRINGPARAM( "db:Table;" ) ); 327cdf0e10cSrcweir aMark += aAddressBook.GetToken( 1, sal_Unicode( ';' ) ); 328cdf0e10cSrcweir aObj.SetMark( aMark ); 329cdf0e10cSrcweir 330cdf0e10cSrcweir util::URL aURL; 331cdf0e10cSrcweir aURL.Complete = ::rtl::OUString( aObj.GetMainURL( INetURLObject::NO_DECODE ) ); 332cdf0e10cSrcweir 333cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() ); 334cdf0e10cSrcweir if( xFactory.is() ) 335cdf0e10cSrcweir { 336cdf0e10cSrcweir uno::Reference< util::XURLTransformer > xTrans( xFactory->createInstance 337cdf0e10cSrcweir ( OUString::createFromAscii( "com.sun.star.util.URLTransformer" ) ), 338cdf0e10cSrcweir uno::UNO_QUERY); 339cdf0e10cSrcweir xTrans->parseStrict( aURL ); 340cdf0e10cSrcweir 341cdf0e10cSrcweir uno::Reference< frame::XDispatch > aDisp = xProv->queryDispatch( aURL, 342cdf0e10cSrcweir OUString::createFromAscii( "_beamer" ), 343cdf0e10cSrcweir frame::FrameSearchFlag::GLOBAL | 344cdf0e10cSrcweir frame::FrameSearchFlag::CREATE ); 345cdf0e10cSrcweir if ( aDisp.is() ) 346cdf0e10cSrcweir { 347cdf0e10cSrcweir uno::Sequence< beans::PropertyValue > aArgs(1); 348cdf0e10cSrcweir beans::PropertyValue* pArg = aArgs.getArray(); 349cdf0e10cSrcweir pArg[0].Name = DEFINE_CONST_UNICODE("Referer"); 350cdf0e10cSrcweir pArg[0].Value = uno::makeAny( OUString( DEFINE_CONST_UNICODE("private:user") ) ); 351cdf0e10cSrcweir aDisp->dispatch( aURL, aArgs ); 352cdf0e10cSrcweir } 353cdf0e10cSrcweir } 354cdf0e10cSrcweir } 355cdf0e10cSrcweir */ 356cdf0e10cSrcweir 357cdf0e10cSrcweir return( 0L ); 358cdf0e10cSrcweir } 359cdf0e10cSrcweir 360cdf0e10cSrcweir 361