bump product version to 6.4.0.3
[LibreOffice.git] / cui / source / dialogs / hlmailtp.cxx
blob4e2e111fcc9b80b8075a929420d2c5064e9e7cb6
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 <sfx2/request.hxx>
22 #include <sfx2/viewfrm.hxx>
23 #include <unotools/moduleoptions.hxx>
25 #include <hlmailtp.hxx>
27 #include <comphelper/lok.hxx>
29 using namespace ::com::sun::star;
31 /*************************************************************************
33 |* Constructor / Destructor
35 |************************************************************************/
36 SvxHyperlinkMailTp::SvxHyperlinkMailTp(weld::Container* pParent, SvxHpLinkDlg* pDlg, const SfxItemSet* pItemSet)
37 : SvxHyperlinkTabPageBase(pParent, pDlg, "cui/ui/hyperlinkmailpage.ui", "HyperlinkMailPage", pItemSet)
38 , m_xCbbReceiver(new SvxHyperURLBox(xBuilder->weld_combo_box("receiver")))
39 , m_xBtAdrBook(xBuilder->weld_button("adressbook"))
40 , m_xFtSubject(xBuilder->weld_label("subject_label"))
41 , m_xEdSubject(xBuilder->weld_entry("subject"))
43 m_xCbbReceiver->SetSmartProtocol(INetProtocol::Mailto);
45 InitStdControls();
47 m_xCbbReceiver->show();
49 SetExchangeSupport ();
51 // set handlers
52 m_xBtAdrBook->connect_clicked( LINK ( this, SvxHyperlinkMailTp, ClickAdrBookHdl_Impl ) );
53 m_xCbbReceiver->connect_changed( LINK ( this, SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl) );
55 if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::EModule::DATABASE ) ||
56 comphelper::LibreOfficeKit::isActive() )
57 m_xBtAdrBook->hide();
60 SvxHyperlinkMailTp::~SvxHyperlinkMailTp()
64 /*************************************************************************
66 |* Fill the all dialog-controls except controls in groupbox "more..."
68 |************************************************************************/
70 void SvxHyperlinkMailTp::FillDlgFields(const OUString& rStrURL)
72 OUString aStrScheme = GetSchemeFromURL(rStrURL);
74 // set URL-field and additional controls
75 OUString aStrURLc (rStrURL);
76 // set additional controls for EMail:
77 if ( aStrScheme.startsWith( INET_MAILTO_SCHEME ) )
79 // Find mail-subject
80 OUString aStrSubject, aStrTmp( aStrURLc );
82 sal_Int32 nPos = aStrTmp.toAsciiLowerCase().indexOf( "subject" );
84 if ( nPos != -1 )
85 nPos = aStrTmp.indexOf( '=', nPos );
87 if ( nPos != -1 )
88 aStrSubject = aStrURLc.copy( nPos+1 );
90 nPos = aStrURLc.indexOf( '?' );
92 if ( nPos != -1 )
93 aStrURLc = aStrURLc.copy( 0, nPos );
95 m_xEdSubject->set_text( aStrSubject );
97 else
99 m_xEdSubject->set_text("");
102 m_xCbbReceiver->set_entry_text(aStrURLc);
104 SetScheme( aStrScheme );
107 /*************************************************************************
109 |* retrieve and prepare data from dialog-fields
111 |************************************************************************/
112 void SvxHyperlinkMailTp::GetCurentItemData ( OUString& rStrURL, OUString& aStrName,
113 OUString& aStrIntName, OUString& aStrFrame,
114 SvxLinkInsertMode& eMode )
116 rStrURL = CreateAbsoluteURL();
117 GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
120 OUString SvxHyperlinkMailTp::CreateAbsoluteURL() const
122 OUString aStrURL = m_xCbbReceiver->get_active_text();
123 INetURLObject aURL(aStrURL);
125 if( aURL.GetProtocol() == INetProtocol::NotValid )
127 aURL.SetSmartProtocol( INetProtocol::Mailto );
128 aURL.SetSmartURL(aStrURL);
131 // subject for EMail-url
132 if( aURL.GetProtocol() == INetProtocol::Mailto )
134 if (!m_xEdSubject->get_text().isEmpty())
136 OUString aQuery = "subject=" + m_xEdSubject->get_text();
137 aURL.SetParam(aQuery);
141 if ( aURL.GetProtocol() != INetProtocol::NotValid )
142 return aURL.GetMainURL( INetURLObject::DecodeMechanism::WithCharset );
143 else //#105788# always create a URL even if it is not valid
144 return aStrURL;
147 /*************************************************************************
149 |* static method to create Tabpage
151 |************************************************************************/
153 std::unique_ptr<IconChoicePage> SvxHyperlinkMailTp::Create(weld::Container* pWindow, SvxHpLinkDlg* pDlg, const SfxItemSet* pItemSet)
155 return std::make_unique<SvxHyperlinkMailTp>(pWindow, pDlg, pItemSet);
158 /*************************************************************************
160 |* Set initial focus
162 |************************************************************************/
163 void SvxHyperlinkMailTp::SetInitFocus()
165 m_xCbbReceiver->grab_focus();
168 /*************************************************************************
169 |************************************************************************/
170 void SvxHyperlinkMailTp::SetScheme(const OUString& rScheme)
172 //update target:
173 RemoveImproperProtocol(rScheme);
174 m_xCbbReceiver->SetSmartProtocol( INetProtocol::Mailto );
176 //show/hide special fields for MAIL:
177 m_xBtAdrBook->set_sensitive(true);
178 m_xEdSubject->set_sensitive(true);
181 /*************************************************************************
183 |* Remove protocol if it does not fit to the current button selection
185 |************************************************************************/
186 void SvxHyperlinkMailTp::RemoveImproperProtocol(const OUString& aProperScheme)
188 OUString aStrURL(m_xCbbReceiver->get_active_text());
189 if ( !aStrURL.isEmpty() )
191 OUString aStrScheme = GetSchemeFromURL( aStrURL );
192 if ( !aStrScheme.isEmpty() && aStrScheme != aProperScheme )
194 aStrURL = aStrURL.copy( aStrScheme.getLength() );
195 m_xCbbReceiver->set_entry_text(aStrURL);
200 /*************************************************************************
202 |* Contents of editfield "receiver" modified
204 |************************************************************************/
205 IMPL_LINK_NOARG(SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl, weld::ComboBox&, void)
207 OUString aScheme = GetSchemeFromURL( m_xCbbReceiver->get_active_text() );
208 if(!aScheme.isEmpty())
209 SetScheme( aScheme );
212 /*************************************************************************
214 |* Click on imagebutton : addressbook
216 |************************************************************************/
217 IMPL_STATIC_LINK_NOARG(SvxHyperlinkMailTp, ClickAdrBookHdl_Impl, weld::Button&, void)
219 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
220 if( pViewFrame )
222 SfxItemPool &rPool = pViewFrame->GetPool();
223 SfxRequest aReq(SID_VIEW_DATA_SOURCE_BROWSER, SfxCallMode::SLOT, rPool);
224 pViewFrame->ExecuteSlot( aReq, true );
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */