bump product version to 6.3.0.0.beta1
[LibreOffice.git] / cui / source / dialogs / hlmailtp.cxx
blobdda7b82b45654c37634a3f8ff039c8854b562c01
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/util/XURLTransformer.hpp>
21 #include <sfx2/request.hxx>
23 #include <sfx2/viewfrm.hxx>
24 #include <unotools/pathoptions.hxx>
25 #include <unotools/moduleoptions.hxx>
27 #include <hlmailtp.hxx>
28 #include <bitmaps.hlst>
30 #include <comphelper/lok.hxx>
32 using namespace ::com::sun::star;
34 /*************************************************************************
36 |* Constructor / Destructor
38 |************************************************************************/
40 SvxHyperlinkMailTp::SvxHyperlinkMailTp ( vcl::Window *pParent, IconChoiceDialog* pDlg, const SfxItemSet* pItemSet)
41 : SvxHyperlinkTabPageBase ( pParent, pDlg, "HyperlinkMailPage", "cui/ui/hyperlinkmailpage.ui",
42 pItemSet )
44 get(m_pCbbReceiver, "receiver");
45 m_pCbbReceiver->SetSmartProtocol(INetProtocol::Mailto);
46 get(m_pBtAdrBook, "adressbook");
47 m_pBtAdrBook->SetModeImage(Image(StockImage::Yes, RID_SVXBMP_ADRESSBOOK));
48 get(m_pFtSubject, "subject_label");
49 get(m_pEdSubject, "subject");
51 // Disable display of bitmap names.
52 m_pBtAdrBook->EnableTextDisplay (false);
54 InitStdControls();
56 m_pCbbReceiver->Show();
58 SetExchangeSupport ();
60 // set handlers
61 m_pBtAdrBook->SetClickHdl ( LINK ( this, SvxHyperlinkMailTp, ClickAdrBookHdl_Impl ) );
62 m_pCbbReceiver->SetModifyHdl ( LINK ( this, SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl) );
64 if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::EModule::DATABASE ) ||
65 comphelper::LibreOfficeKit::isActive() )
66 m_pBtAdrBook->Hide();
69 SvxHyperlinkMailTp::~SvxHyperlinkMailTp()
71 disposeOnce();
74 void SvxHyperlinkMailTp::dispose()
76 m_pCbbReceiver.clear();
77 m_pBtAdrBook.clear();
78 m_pFtSubject.clear();
79 m_pEdSubject.clear();
80 SvxHyperlinkTabPageBase::dispose();
83 /*************************************************************************
85 |* Fill the all dialog-controls except controls in groupbox "more..."
87 |************************************************************************/
89 void SvxHyperlinkMailTp::FillDlgFields(const OUString& rStrURL)
91 OUString aStrScheme = GetSchemeFromURL(rStrURL);
93 // set URL-field and additional controls
94 OUString aStrURLc (rStrURL);
95 // set additional controls for EMail:
96 if ( aStrScheme.startsWith( INET_MAILTO_SCHEME ) )
98 // Find mail-subject
99 OUString aStrSubject, aStrTmp( aStrURLc );
101 sal_Int32 nPos = aStrTmp.toAsciiLowerCase().indexOf( "subject" );
103 if ( nPos != -1 )
104 nPos = aStrTmp.indexOf( '=', nPos );
106 if ( nPos != -1 )
107 aStrSubject = aStrURLc.copy( nPos+1 );
109 nPos = aStrURLc.indexOf( '?' );
111 if ( nPos != -1 )
112 aStrURLc = aStrURLc.copy( 0, nPos );
114 m_pEdSubject->SetText ( aStrSubject );
116 else
118 m_pEdSubject->SetText ("");
121 m_pCbbReceiver->SetText ( aStrURLc );
123 SetScheme( aStrScheme );
126 /*************************************************************************
128 |* retrieve and prepare data from dialog-fields
130 |************************************************************************/
132 void SvxHyperlinkMailTp::GetCurentItemData ( OUString& rStrURL, OUString& aStrName,
133 OUString& aStrIntName, OUString& aStrFrame,
134 SvxLinkInsertMode& eMode )
136 rStrURL = CreateAbsoluteURL();
137 GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
140 OUString SvxHyperlinkMailTp::CreateAbsoluteURL() const
142 OUString aStrURL = m_pCbbReceiver->GetText();
143 INetURLObject aURL(aStrURL);
145 if( aURL.GetProtocol() == INetProtocol::NotValid )
147 aURL.SetSmartProtocol( INetProtocol::Mailto );
148 aURL.SetSmartURL(aStrURL);
151 // subject for EMail-url
152 if( aURL.GetProtocol() == INetProtocol::Mailto )
154 if ( !m_pEdSubject->GetText().isEmpty() )
156 OUString aQuery = "subject=" + m_pEdSubject->GetText();
157 aURL.SetParam(aQuery);
161 if ( aURL.GetProtocol() != INetProtocol::NotValid )
162 return aURL.GetMainURL( INetURLObject::DecodeMechanism::WithCharset );
163 else //#105788# always create a URL even if it is not valid
164 return aStrURL;
167 /*************************************************************************
169 |* static method to create Tabpage
171 |************************************************************************/
173 VclPtr<IconChoicePage> SvxHyperlinkMailTp::Create( vcl::Window* pWindow, IconChoiceDialog* pDlg, const SfxItemSet* pItemSet )
175 return VclPtr<SvxHyperlinkMailTp>::Create( pWindow, pDlg, pItemSet );
178 /*************************************************************************
180 |* Set initial focus
182 |************************************************************************/
184 void SvxHyperlinkMailTp::SetInitFocus()
186 m_pCbbReceiver->GrabFocus();
189 /*************************************************************************
190 |************************************************************************/
192 void SvxHyperlinkMailTp::SetScheme(const OUString& rScheme)
194 //update target:
195 RemoveImproperProtocol(rScheme);
196 m_pCbbReceiver->SetSmartProtocol( INetProtocol::Mailto );
198 //show/hide special fields for MAIL:
199 m_pBtAdrBook->Enable();
200 m_pEdSubject->Enable();
203 /*************************************************************************
205 |* Remove protocol if it does not fit to the current button selection
207 |************************************************************************/
209 void SvxHyperlinkMailTp::RemoveImproperProtocol(const OUString& aProperScheme)
211 OUString aStrURL ( m_pCbbReceiver->GetText() );
212 if ( !aStrURL.isEmpty() )
214 OUString aStrScheme = GetSchemeFromURL( aStrURL );
215 if ( !aStrScheme.isEmpty() && aStrScheme != aProperScheme )
217 aStrURL = aStrURL.copy( aStrScheme.getLength() );
218 m_pCbbReceiver->SetText ( aStrURL );
223 /*************************************************************************
225 |* Contents of editfield "receiver" modified
227 |************************************************************************/
229 IMPL_LINK_NOARG(SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl, Edit&, void)
231 OUString aScheme = GetSchemeFromURL( m_pCbbReceiver->GetText() );
232 if(!aScheme.isEmpty())
233 SetScheme( aScheme );
236 /*************************************************************************
238 |* Click on imagebutton : addressbook
240 |************************************************************************/
242 IMPL_STATIC_LINK_NOARG(SvxHyperlinkMailTp, ClickAdrBookHdl_Impl, Button*, void)
244 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
245 if( pViewFrame )
247 SfxItemPool &rPool = pViewFrame->GetPool();
248 SfxRequest aReq(SID_VIEW_DATA_SOURCE_BROWSER, SfxCallMode::SLOT, rPool);
249 pViewFrame->ExecuteSlot( aReq, true );
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */