LibreOffice Module cui (master) 1
hlmailtp.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sfx2/request.hxx>
21
22#include <sfx2/viewfrm.hxx>
24
25#include <hlmailtp.hxx>
26
27#include <comphelper/lok.hxx>
28
29using namespace ::com::sun::star;
30
31/*************************************************************************
32|*
33|* Constructor / Destructor
34|*
35|************************************************************************/
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("addressbook"))
40 , m_xFtSubject(xBuilder->weld_label("subject_label"))
41 , m_xEdSubject(xBuilder->weld_entry("subject"))
42{
43 m_xCbbReceiver->SetSmartProtocol(INetProtocol::Mailto);
44
46
47 m_xCbbReceiver->show();
48
50
51 // set handlers
52 m_xBtAdrBook->connect_clicked( LINK ( this, SvxHyperlinkMailTp, ClickAdrBookHdl_Impl ) );
53 m_xCbbReceiver->connect_changed( LINK ( this, SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl) );
54
55 if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::EModule::DATABASE ) ||
57 m_xBtAdrBook->hide();
58}
59
61{
62}
63
64/*************************************************************************
65|*
66|* Fill the all dialog-controls except controls in groupbox "more..."
67|*
68|************************************************************************/
69
70void SvxHyperlinkMailTp::FillDlgFields(const OUString& rStrURL)
71{
72 OUString aStrScheme = GetSchemeFromURL(rStrURL);
73
74 // set URL-field and additional controls
75 OUString aStrURLc (rStrURL);
76 // set additional controls for EMail:
77 if ( aStrScheme.startsWith( INET_MAILTO_SCHEME ) )
78 {
79 // Find mail-subject
80 OUString aStrSubject, aStrTmp( aStrURLc );
81
82 sal_Int32 nPos = aStrTmp.toAsciiLowerCase().indexOf( "subject" );
83
84 if ( nPos != -1 )
85 nPos = aStrTmp.indexOf( '=', nPos );
86
87 if ( nPos != -1 )
88 aStrSubject = aStrURLc.copy( nPos+1 );
89
90 nPos = aStrURLc.indexOf( '?' );
91
92 if ( nPos != -1 )
93 aStrURLc = aStrURLc.copy( 0, nPos );
94
95 m_xEdSubject->set_text( aStrSubject );
96 }
97 else
98 {
99 m_xEdSubject->set_text("");
100 }
101
102 m_xCbbReceiver->set_entry_text(aStrURLc);
103
104 SetScheme( aStrScheme );
105}
106
107/*************************************************************************
108|*
109|* retrieve and prepare data from dialog-fields
110|*
111|************************************************************************/
112void SvxHyperlinkMailTp::GetCurentItemData ( OUString& rStrURL, OUString& aStrName,
113 OUString& aStrIntName, OUString& aStrFrame,
114 SvxLinkInsertMode& eMode )
115{
116 rStrURL = CreateAbsoluteURL();
117 GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
118}
119
121{
122 OUString aStrURL = m_xCbbReceiver->get_active_text();
123 INetURLObject aURL(aStrURL, INetProtocol::Mailto);
124
125 // subject for EMail-url
126 if( aURL.GetProtocol() == INetProtocol::Mailto )
127 {
128 if (!m_xEdSubject->get_text().isEmpty())
129 {
130 OUString aQuery = "subject=" + m_xEdSubject->get_text();
131 aURL.SetParam(aQuery);
132 }
133 }
134
135 if ( aURL.GetProtocol() != INetProtocol::NotValid )
137 else //#105788# always create a URL even if it is not valid
138 return aStrURL;
139}
140
141/*************************************************************************
142|*
143|* static method to create Tabpage
144|*
145|************************************************************************/
146
147std::unique_ptr<IconChoicePage> SvxHyperlinkMailTp::Create(weld::Container* pWindow, SvxHpLinkDlg* pDlg, const SfxItemSet* pItemSet)
148{
149 return std::make_unique<SvxHyperlinkMailTp>(pWindow, pDlg, pItemSet);
150}
151
152/*************************************************************************
153|*
154|* Set initial focus
155|*
156|************************************************************************/
158{
159 m_xCbbReceiver->grab_focus();
160}
161
162/*************************************************************************
163|************************************************************************/
164void SvxHyperlinkMailTp::SetScheme(std::u16string_view rScheme)
165{
166 //update target:
167 RemoveImproperProtocol(rScheme);
168 m_xCbbReceiver->SetSmartProtocol( INetProtocol::Mailto );
169
170 //show/hide special fields for MAIL:
171 m_xBtAdrBook->set_sensitive(true);
172 m_xEdSubject->set_sensitive(true);
173}
174
175/*************************************************************************
176|*
177|* Remove protocol if it does not fit to the current button selection
178|*
179|************************************************************************/
180void SvxHyperlinkMailTp::RemoveImproperProtocol(std::u16string_view aProperScheme)
181{
182 OUString aStrURL(m_xCbbReceiver->get_active_text());
183 if ( !aStrURL.isEmpty() )
184 {
185 OUString aStrScheme = GetSchemeFromURL( aStrURL );
186 if ( !aStrScheme.isEmpty() && aStrScheme != aProperScheme )
187 {
188 aStrURL = aStrURL.copy( aStrScheme.getLength() );
189 m_xCbbReceiver->set_entry_text(aStrURL);
190 }
191 }
192}
193
194/*************************************************************************
195|*
196|* Contents of editfield "receiver" modified
197|*
198|************************************************************************/
199IMPL_LINK_NOARG(SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl, weld::ComboBox&, void)
200{
201 OUString aScheme = GetSchemeFromURL( m_xCbbReceiver->get_active_text() );
202 if(!aScheme.isEmpty())
203 SetScheme( aScheme );
204}
205
206/*************************************************************************
207|*
208|* Click on imagebutton : addressbook
209|*
210|************************************************************************/
212{
213 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
214 if( pViewFrame )
215 {
216 SfxItemPool &rPool = pViewFrame->GetPool();
217 SfxRequest aReq(SID_VIEW_DATA_SOURCE_BROWSER, SfxCallMode::SLOT, rPool);
218 pViewFrame->ExecuteSlot( aReq, true );
219 }
220}
221
222/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetExchangeSupport()
Definition: iconcdlg.hxx:75
SfxItemPool & GetPool() const
const SfxPoolItem * ExecuteSlot(SfxRequest &rReq, const SfxInterface *pIF=nullptr)
static SfxViewFrame * Current()
ComboBox-Control for URL's with History and Autocompletion.
Definition: hltpbase.hxx:36
std::unique_ptr< SvxHyperURLBox > m_xCbbReceiver
Definition: hlmailtp.hxx:32
OUString CreateAbsoluteURL() const
Definition: hlmailtp.cxx:120
void SetScheme(std::u16string_view rScheme)
Definition: hlmailtp.cxx:164
SvxHyperlinkMailTp(weld::Container *pParent, SvxHpLinkDlg *pDlg, const SfxItemSet *pItemSet)
Definition: hlmailtp.cxx:36
std::unique_ptr< weld::Button > m_xBtAdrBook
Definition: hlmailtp.hxx:33
virtual void FillDlgFields(const OUString &rStrURL) override
Definition: hlmailtp.cxx:70
virtual void SetInitFocus() override
Definition: hlmailtp.cxx:157
static std::unique_ptr< IconChoicePage > Create(weld::Container *pWindow, SvxHpLinkDlg *pDlg, const SfxItemSet *pItemSet)
Definition: hlmailtp.cxx:147
std::unique_ptr< weld::Entry > m_xEdSubject
Definition: hlmailtp.hxx:35
virtual ~SvxHyperlinkMailTp() override
Definition: hlmailtp.cxx:60
void RemoveImproperProtocol(std::u16string_view aProperScheme)
Definition: hlmailtp.cxx:180
virtual void GetCurentItemData(OUString &rStrURL, OUString &aStrName, OUString &aStrIntName, OUString &aStrFrame, SvxLinkInsertMode &eMode) override
Definition: hlmailtp.cxx:112
Tabpage : Basisclass.
Definition: hltpbase.hxx:47
static OUString GetSchemeFromURL(const OUString &rStrURL)
Definition: hltpbase.cxx:389
void GetDataFromCommonFields(OUString &aStrName, OUString &aStrIntName, OUString &aStrFrame, SvxLinkInsertMode &eMode)
Definition: hltpbase.cxx:422
URL aURL
IMPL_STATIC_LINK_NOARG(SvxHyperlinkMailTp, ClickAdrBookHdl_Impl, weld::Button &, void)
Definition: hlmailtp.cxx:211
IMPL_LINK_NOARG(SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl, weld::ComboBox &, void)
Definition: hlmailtp.cxx:199
SvxLinkInsertMode
Mode eMode
sal_uInt16 nPos
constexpr OUStringLiteral INET_MAILTO_SCHEME