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_xEdSubject(xBuilder->weld_entry("subject"))
41{
42 m_xCbbReceiver->SetSmartProtocol(INetProtocol::Mailto);
43
45
46 m_xCbbReceiver->show();
47
49
50 // set handlers
51 m_xBtAdrBook->connect_clicked( LINK ( this, SvxHyperlinkMailTp, ClickAdrBookHdl_Impl ) );
52 m_xCbbReceiver->connect_changed( LINK ( this, SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl) );
53
54 if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::EModule::DATABASE ) ||
56 m_xBtAdrBook->hide();
57}
58
60{
61}
62
63/*************************************************************************
64|*
65|* Fill the all dialog-controls except controls in groupbox "more..."
66|*
67|************************************************************************/
68
69void SvxHyperlinkMailTp::FillDlgFields(const OUString& rStrURL)
70{
71 OUString aStrScheme = GetSchemeFromURL(rStrURL);
72
73 // set URL-field and additional controls
74 OUString aStrURLc (rStrURL);
75 // set additional controls for EMail:
76 if ( aStrScheme.startsWith( INET_MAILTO_SCHEME ) )
77 {
78 // Find mail-subject
79 OUString aStrSubject, aStrTmp( aStrURLc );
80
81 sal_Int32 nPos = aStrTmp.toAsciiLowerCase().indexOf( "subject" );
82
83 if ( nPos != -1 )
84 nPos = aStrTmp.indexOf( '=', nPos );
85
86 if ( nPos != -1 )
87 aStrSubject = aStrURLc.copy( nPos+1 );
88
89 nPos = aStrURLc.indexOf( '?' );
90
91 if ( nPos != -1 )
92 aStrURLc = aStrURLc.copy( 0, nPos );
93
94 m_xEdSubject->set_text( aStrSubject );
95 }
96 else
97 {
98 m_xEdSubject->set_text("");
99 }
100
101 m_xCbbReceiver->set_entry_text(aStrURLc);
102
103 SetScheme( aStrScheme );
104}
105
106/*************************************************************************
107|*
108|* retrieve and prepare data from dialog-fields
109|*
110|************************************************************************/
111void SvxHyperlinkMailTp::GetCurrentItemData ( OUString& rStrURL, OUString& aStrName,
112 OUString& aStrIntName, OUString& aStrFrame,
113 SvxLinkInsertMode& eMode )
114{
115 rStrURL = CreateAbsoluteURL();
116 GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
117}
118
120{
121 OUString aStrURL = m_xCbbReceiver->get_active_text();
122 INetURLObject aURL(aStrURL, INetProtocol::Mailto);
123
124 // subject for EMail-url
125 if( aURL.GetProtocol() == INetProtocol::Mailto )
126 {
127 if (!m_xEdSubject->get_text().isEmpty())
128 {
129 OUString aQuery = "subject=" + m_xEdSubject->get_text();
130 aURL.SetParam(aQuery);
131 }
132 }
133
134 if ( aURL.GetProtocol() != INetProtocol::NotValid )
136 else //#105788# always create a URL even if it is not valid
137 return aStrURL;
138}
139
140/*************************************************************************
141|*
142|* static method to create Tabpage
143|*
144|************************************************************************/
145
146std::unique_ptr<IconChoicePage> SvxHyperlinkMailTp::Create(weld::Container* pWindow, SvxHpLinkDlg* pDlg, const SfxItemSet* pItemSet)
147{
148 return std::make_unique<SvxHyperlinkMailTp>(pWindow, pDlg, pItemSet);
149}
150
151/*************************************************************************
152|*
153|* Set initial focus
154|*
155|************************************************************************/
157{
158 m_xCbbReceiver->grab_focus();
159}
160
161/*************************************************************************
162|************************************************************************/
163void SvxHyperlinkMailTp::SetScheme(std::u16string_view rScheme)
164{
165 //update target:
166 RemoveImproperProtocol(rScheme);
167 m_xCbbReceiver->SetSmartProtocol( INetProtocol::Mailto );
168
169 //show/hide special fields for MAIL:
170 m_xBtAdrBook->set_sensitive(true);
171 m_xEdSubject->set_sensitive(true);
172}
173
174/*************************************************************************
175|*
176|* Remove protocol if it does not fit to the current button selection
177|*
178|************************************************************************/
179void SvxHyperlinkMailTp::RemoveImproperProtocol(std::u16string_view aProperScheme)
180{
181 OUString aStrURL(m_xCbbReceiver->get_active_text());
182 if ( !aStrURL.isEmpty() )
183 {
184 OUString aStrScheme = GetSchemeFromURL( aStrURL );
185 if ( !aStrScheme.isEmpty() && aStrScheme != aProperScheme )
186 {
187 aStrURL = aStrURL.copy( aStrScheme.getLength() );
188 m_xCbbReceiver->set_entry_text(aStrURL);
189 }
190 }
191}
192
193/*************************************************************************
194|*
195|* Contents of editfield "receiver" modified
196|*
197|************************************************************************/
198IMPL_LINK_NOARG(SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl, weld::ComboBox&, void)
199{
200 OUString aScheme = GetSchemeFromURL( m_xCbbReceiver->get_active_text() );
201 if(!aScheme.isEmpty())
202 SetScheme( aScheme );
203}
204
205/*************************************************************************
206|*
207|* Click on imagebutton : addressbook
208|*
209|************************************************************************/
211{
212 if (SfxViewFrame* pViewFrame = SfxViewFrame::Current())
213 {
214 SfxItemPool &rPool = pViewFrame->GetPool();
215 SfxRequest aReq(SID_VIEW_DATA_SOURCE_BROWSER, SfxCallMode::SLOT, rPool);
216 pViewFrame->ExecuteSlot( aReq, true );
217 }
218}
219
220/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetExchangeSupport()
Definition: iconcdlg.hxx:60
static SAL_WARN_UNUSED_RESULT 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:119
void SetScheme(std::u16string_view rScheme)
Definition: hlmailtp.cxx:163
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:69
virtual void SetInitFocus() override
Definition: hlmailtp.cxx:156
static std::unique_ptr< IconChoicePage > Create(weld::Container *pWindow, SvxHpLinkDlg *pDlg, const SfxItemSet *pItemSet)
Definition: hlmailtp.cxx:146
std::unique_ptr< weld::Entry > m_xEdSubject
Definition: hlmailtp.hxx:34
virtual ~SvxHyperlinkMailTp() override
Definition: hlmailtp.cxx:59
virtual void GetCurrentItemData(OUString &rStrURL, OUString &aStrName, OUString &aStrIntName, OUString &aStrFrame, SvxLinkInsertMode &eMode) override
Definition: hlmailtp.cxx:111
void RemoveImproperProtocol(std::u16string_view aProperScheme)
Definition: hlmailtp.cxx:179
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:210
IMPL_LINK_NOARG(SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl, weld::ComboBox &, void)
Definition: hlmailtp.cxx:198
SvxLinkInsertMode
Mode eMode
sal_uInt16 nPos
constexpr OUStringLiteral INET_MAILTO_SCHEME