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