Update ooo320-m1
[ooovba.git] / svx / source / cui / hlmailtp.cxx
blob283d9d243a4c3f79ee52434224f1ad7b9342188f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: hlmailtp.cxx,v $
10 * $Revision: 1.23 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
36 #endif
37 #include <com/sun/star/frame/XDispatchProvider.hpp>
38 #include <com/sun/star/util/XURLTransformer.hpp>
39 #include <com/sun/star/frame/FrameSearchFlag.hpp>
40 #include <sfx2/request.hxx>
42 #include <comphelper/processfactory.hxx>
43 #include <sfx2/viewfrm.hxx>
44 #include <svtools/pathoptions.hxx>
45 #include <svtools/moduleoptions.hxx>
47 #include "hlmailtp.hxx"
48 #include "hyperdlg.hrc"
50 using namespace ::rtl;
51 using namespace ::com::sun::star;
53 /*************************************************************************
55 |* Contructor / Destructor
57 |************************************************************************/
59 SvxHyperlinkMailTp::SvxHyperlinkMailTp ( Window *pParent, const SfxItemSet& rItemSet)
60 : SvxHyperlinkTabPageBase ( pParent, SVX_RES( RID_SVXPAGE_HYPERLINK_MAIL ),
61 rItemSet ),
62 maGrpMailNews ( this, SVX_RES (GRP_MAILNEWS) ),
63 maRbtMail ( this, SVX_RES (RB_LINKTYP_MAIL) ),
64 maRbtNews ( this, SVX_RES (RB_LINKTYP_NEWS) ),
65 maFtReceiver ( this, SVX_RES (FT_RECEIVER) ),
66 maCbbReceiver ( this, INET_PROT_MAILTO ),
67 maBtAdrBook ( this, SVX_RES (BTN_ADRESSBOOK) ),
68 maFtSubject ( this, SVX_RES (FT_SUBJECT) ),
69 maEdSubject ( this, SVX_RES (ED_SUBJECT) )
71 // Set HC bitmaps and disable display of bitmap names.
72 maBtAdrBook.SetModeImage( Image( SVX_RES( IMG_ADRESSBOOK_HC ) ), BMP_COLOR_HIGHCONTRAST );
73 maBtAdrBook.EnableTextDisplay (FALSE);
75 InitStdControls();
76 FreeResource();
78 // Init URL-Box (pos&size, Open-Handler)
79 maCbbReceiver.SetPosSizePixel ( LogicToPixel( Point( COL_2, 25 ), MAP_APPFONT ),
80 LogicToPixel( Size ( 176 - COL_DIFF, 60), MAP_APPFONT ) );
82 maCbbReceiver.Show();
83 maCbbReceiver.SetHelpId( HID_HYPERDLG_MAIL_PATH );
85 SetExchangeSupport ();
87 // set defaults
88 maRbtMail.Check ();
90 // overload handlers
91 maRbtMail.SetClickHdl ( LINK ( this, SvxHyperlinkMailTp, Click_SmartProtocol_Impl ) );
92 maRbtNews.SetClickHdl ( LINK ( this, SvxHyperlinkMailTp, Click_SmartProtocol_Impl ) );
93 maBtAdrBook.SetClickHdl ( LINK ( this, SvxHyperlinkMailTp, ClickAdrBookHdl_Impl ) );
94 maCbbReceiver.SetModifyHdl ( LINK ( this, SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl) );
96 if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::E_SDATABASE ) )
97 maBtAdrBook.Hide();
100 SvxHyperlinkMailTp::~SvxHyperlinkMailTp ()
104 /*************************************************************************
106 |* Fill the all dialog-controls except controls in groupbox "more..."
108 |************************************************************************/
110 void SvxHyperlinkMailTp::FillDlgFields ( String& aStrURL )
112 const sal_Char sMailtoScheme[] = INET_MAILTO_SCHEME;
114 INetURLObject aURL( aStrURL );
115 String aStrScheme = GetSchemeFromURL( aStrURL );
117 // set URL-field and additional controls
118 String aStrURLc ( aStrURL );
119 // set additional controls for EMail:
120 if ( aStrScheme.SearchAscii( sMailtoScheme ) == 0 )
122 // Find mail-subject
123 String aStrSubject, aStrTmp ( aStrURLc );
125 const sal_Char sSubject[] = "subject";
126 xub_StrLen nPos = aStrTmp.ToLowerAscii().SearchAscii( sSubject, 0 );
127 nPos = aStrTmp.Search( sal_Unicode( '=' ), nPos );
129 if ( nPos != STRING_NOTFOUND )
130 aStrSubject = aStrURLc.Copy( nPos+1, aStrURLc.Len() );
132 nPos = aStrURLc.Search ( sal_Unicode( '?' ), 0);
134 aStrURLc = aStrURLc.Copy( 0, ( nPos == STRING_NOTFOUND ?
135 aStrURLc.Len() : nPos ) );
137 maEdSubject.SetText ( aStrSubject );
139 else
141 maEdSubject.SetText (aEmptyStr);
144 maCbbReceiver.SetText ( aStrURLc );
146 SetScheme( aStrScheme );
149 /*************************************************************************
151 |* retrieve and prepare data from dialog-fields
153 |************************************************************************/
155 void SvxHyperlinkMailTp::GetCurentItemData ( String& aStrURL, String& aStrName,
156 String& aStrIntName, String& aStrFrame,
157 SvxLinkInsertMode& eMode )
159 aStrURL = CreateAbsoluteURL();
160 GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
163 String SvxHyperlinkMailTp::CreateAbsoluteURL() const
165 String aStrURL = maCbbReceiver.GetText();
166 INetURLObject aURL(aStrURL);
168 if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
170 aURL.SetSmartProtocol( GetSmartProtocolFromButtons() );
171 aURL.SetSmartURL(aStrURL);
174 // subject for EMail-url
175 if( aURL.GetProtocol() == INET_PROT_MAILTO )
177 if ( maEdSubject.GetText() != aEmptyStr )
179 String aQuery = UniString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "subject=" ) );
180 aQuery.Append( maEdSubject.GetText() );
181 aURL.SetParam(aQuery);
185 if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
186 return aURL.GetMainURL( INetURLObject::DECODE_WITH_CHARSET );
187 else //#105788# always create a URL even if it is not valid
188 return aStrURL;
191 /*************************************************************************
193 |* static method to create Tabpage
195 |************************************************************************/
197 IconChoicePage* SvxHyperlinkMailTp::Create( Window* pWindow, const SfxItemSet& rItemSet )
199 return( new SvxHyperlinkMailTp( pWindow, rItemSet ) );
202 /*************************************************************************
204 |* Set initial focus
206 |************************************************************************/
208 void SvxHyperlinkMailTp::SetInitFocus()
210 maCbbReceiver.GrabFocus();
213 /*************************************************************************
214 |************************************************************************/
216 void SvxHyperlinkMailTp::SetScheme( const String& aScheme )
218 //if aScheme is empty or unknown the default beaviour is like it where MAIL
219 const sal_Char sNewsScheme[] = INET_NEWS_SCHEME;
221 BOOL bMail = aScheme.SearchAscii( sNewsScheme ) != 0;
223 //update protocol button selection:
224 maRbtMail.Check(bMail);
225 maRbtNews.Check(!bMail);
227 //update target:
228 RemoveImproperProtocol(aScheme);
229 maCbbReceiver.SetSmartProtocol( GetSmartProtocolFromButtons() );
231 //show/hide special fields for MAIL:
232 maFtSubject.Enable(bMail);
233 maEdSubject.Enable(bMail);
236 /*************************************************************************
238 |* Remove protocol if it does not fit to the current button selection
240 |************************************************************************/
242 void SvxHyperlinkMailTp::RemoveImproperProtocol(const String& aProperScheme)
244 String aStrURL ( maCbbReceiver.GetText() );
245 if ( aStrURL != aEmptyStr )
247 String aStrScheme = GetSchemeFromURL( aStrURL );
248 if ( aStrScheme != aEmptyStr && aStrScheme != aProperScheme )
250 aStrURL.Erase ( 0, aStrScheme.Len() );
251 maCbbReceiver.SetText ( aStrURL );
256 String SvxHyperlinkMailTp::GetSchemeFromButtons() const
258 if( maRbtNews.IsChecked() )
260 return String::CreateFromAscii( INET_NEWS_SCHEME );
262 return String::CreateFromAscii( INET_MAILTO_SCHEME );
265 INetProtocol SvxHyperlinkMailTp::GetSmartProtocolFromButtons() const
267 if( maRbtNews.IsChecked() )
269 return INET_PROT_NEWS;
271 return INET_PROT_MAILTO;
274 /*************************************************************************
276 |* Click on radiobutton : Type EMail
278 |************************************************************************/
280 IMPL_LINK ( SvxHyperlinkMailTp, Click_SmartProtocol_Impl, void *, EMPTYARG )
282 String aScheme = GetSchemeFromButtons();
283 SetScheme( aScheme );
284 return( 0L );
287 /*************************************************************************
289 |* Contens of editfield "receiver" modified
291 |************************************************************************/
293 IMPL_LINK ( SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl, void *, EMPTYARG )
295 String aScheme = GetSchemeFromURL( maCbbReceiver.GetText() );
296 if(aScheme.Len()!=0)
297 SetScheme( aScheme );
299 return( 0L );
302 /*************************************************************************
304 |* Click on imagebutton : addressbook
306 |************************************************************************/
308 IMPL_LINK ( SvxHyperlinkMailTp, ClickAdrBookHdl_Impl, void *, EMPTYARG )
310 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
311 if( pViewFrame )
313 SfxItemPool &rPool = pViewFrame->GetPool();
314 SfxRequest aReq(SID_VIEW_DATA_SOURCE_BROWSER, 0, rPool);
315 pViewFrame->ExecuteSlot( aReq, sal_True );
319 /* uno::Reference< frame::XDispatchProvider > xProv( pViewFrame->GetFrame()->GetFrameInterface(), uno::UNO_QUERY );
320 if ( xProv.is() )
322 !!! (pb) we need a new config item here
323 SfxAppIniManagerProperty aProp;
324 GetpApp()->Property( aProp );
325 if( !aProp.GetIniManager() )
326 return ( 0L );
328 String aAddressBook = aProp.GetIniManager()->Get( SFX_KEY_ADDRESSBOOK );
329 INetURLObject aObj;
330 aObj.SetSmartProtocol( INET_PROT_FILE );
331 aObj.SetURL( aAddressBook.GetToken( 0, sal_Unicode( ';' ) ) );
333 String aMark( RTL_CONSTASCII_USTRINGPARAM( "db:Table;" ) );
334 aMark += aAddressBook.GetToken( 1, sal_Unicode( ';' ) );
335 aObj.SetMark( aMark );
337 util::URL aURL;
338 aURL.Complete = ::rtl::OUString( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
340 uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() );
341 if( xFactory.is() )
343 uno::Reference< util::XURLTransformer > xTrans( xFactory->createInstance
344 ( OUString::createFromAscii( "com.sun.star.util.URLTransformer" ) ),
345 uno::UNO_QUERY);
346 xTrans->parseStrict( aURL );
348 uno::Reference< frame::XDispatch > aDisp = xProv->queryDispatch( aURL,
349 OUString::createFromAscii( "_beamer" ),
350 frame::FrameSearchFlag::GLOBAL |
351 frame::FrameSearchFlag::CREATE );
352 if ( aDisp.is() )
354 uno::Sequence< beans::PropertyValue > aArgs(1);
355 beans::PropertyValue* pArg = aArgs.getArray();
356 pArg[0].Name = DEFINE_CONST_UNICODE("Referer");
357 pArg[0].Value = uno::makeAny( OUString( DEFINE_CONST_UNICODE("private:user") ) );
358 aDisp->dispatch( aURL, aArgs );
364 return( 0L );