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 
29 using 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("adressbook"))
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 
70 void 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 |************************************************************************/
112 void 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);
124 
125  if( aURL.GetProtocol() == INetProtocol::NotValid )
126  {
127  aURL.SetSmartProtocol( INetProtocol::Mailto );
128  aURL.SetSmartURL(aStrURL);
129  }
130 
131  // subject for EMail-url
132  if( aURL.GetProtocol() == INetProtocol::Mailto )
133  {
134  if (!m_xEdSubject->get_text().isEmpty())
135  {
136  OUString aQuery = "subject=" + m_xEdSubject->get_text();
137  aURL.SetParam(aQuery);
138  }
139  }
140 
141  if ( aURL.GetProtocol() != INetProtocol::NotValid )
143  else //#105788# always create a URL even if it is not valid
144  return aStrURL;
145 }
146 
147 /*************************************************************************
148 |*
149 |* static method to create Tabpage
150 |*
151 |************************************************************************/
152 
153 std::unique_ptr<IconChoicePage> SvxHyperlinkMailTp::Create(weld::Container* pWindow, SvxHpLinkDlg* pDlg, const SfxItemSet* pItemSet)
154 {
155  return std::make_unique<SvxHyperlinkMailTp>(pWindow, pDlg, pItemSet);
156 }
157 
158 /*************************************************************************
159 |*
160 |* Set initial focus
161 |*
162 |************************************************************************/
164 {
165  m_xCbbReceiver->grab_focus();
166 }
167 
168 /*************************************************************************
169 |************************************************************************/
170 void SvxHyperlinkMailTp::SetScheme(const OUString& rScheme)
171 {
172  //update target:
173  RemoveImproperProtocol(rScheme);
174  m_xCbbReceiver->SetSmartProtocol( INetProtocol::Mailto );
175 
176  //show/hide special fields for MAIL:
177  m_xBtAdrBook->set_sensitive(true);
178  m_xEdSubject->set_sensitive(true);
179 }
180 
181 /*************************************************************************
182 |*
183 |* Remove protocol if it does not fit to the current button selection
184 |*
185 |************************************************************************/
186 void SvxHyperlinkMailTp::RemoveImproperProtocol(const OUString& aProperScheme)
187 {
188  OUString aStrURL(m_xCbbReceiver->get_active_text());
189  if ( !aStrURL.isEmpty() )
190  {
191  OUString aStrScheme = GetSchemeFromURL( aStrURL );
192  if ( !aStrScheme.isEmpty() && aStrScheme != aProperScheme )
193  {
194  aStrURL = aStrURL.copy( aStrScheme.getLength() );
195  m_xCbbReceiver->set_entry_text(aStrURL);
196  }
197  }
198 }
199 
200 /*************************************************************************
201 |*
202 |* Contents of editfield "receiver" modified
203 |*
204 |************************************************************************/
205 IMPL_LINK_NOARG(SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl, weld::ComboBox&, void)
206 {
207  OUString aScheme = GetSchemeFromURL( m_xCbbReceiver->get_active_text() );
208  if(!aScheme.isEmpty())
209  SetScheme( aScheme );
210 }
211 
212 /*************************************************************************
213 |*
214 |* Click on imagebutton : addressbook
215 |*
216 |************************************************************************/
218 {
219  SfxViewFrame* pViewFrame = SfxViewFrame::Current();
220  if( pViewFrame )
221  {
222  SfxItemPool &rPool = pViewFrame->GetPool();
223  SfxRequest aReq(SID_VIEW_DATA_SOURCE_BROWSER, SfxCallMode::SLOT, rPool);
224  pViewFrame->ExecuteSlot( aReq, true );
225  }
226 }
227 
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SfxPoolItem * ExecuteSlot(SfxRequest &rReq, const SfxInterface *pIF=nullptr)
IMPL_STATIC_LINK_NOARG(SvxHyperlinkMailTp, ClickAdrBookHdl_Impl, weld::Button &, void)
Definition: hlmailtp.cxx:217
virtual void FillDlgFields(const OUString &rStrURL) override
Definition: hlmailtp.cxx:70
void RemoveImproperProtocol(const OUString &aProperScheme)
Definition: hlmailtp.cxx:186
IMPL_LINK_NOARG(SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl, weld::ComboBox &, void)
Definition: hlmailtp.cxx:205
static std::unique_ptr< IconChoicePage > Create(weld::Container *pWindow, SvxHpLinkDlg *pDlg, const SfxItemSet *pItemSet)
Definition: hlmailtp.cxx:153
OUString CreateAbsoluteURL() const
Definition: hlmailtp.cxx:120
std::unique_ptr< weld::Button > m_xBtAdrBook
Definition: hlmailtp.hxx:34
virtual ~SvxHyperlinkMailTp() override
Definition: hlmailtp.cxx:60
void GetDataFromCommonFields(OUString &aStrName, OUString &aStrIntName, OUString &aStrFrame, SvxLinkInsertMode &eMode)
Definition: hltpbase.cxx:430
std::unique_ptr< weld::Entry > m_xEdSubject
Definition: hlmailtp.hxx:36
SfxItemPool & GetPool() const
virtual void GetCurentItemData(OUString &rStrURL, OUString &aStrName, OUString &aStrIntName, OUString &aStrFrame, SvxLinkInsertMode &eMode) override
Definition: hlmailtp.cxx:112
void SetSmartProtocol(INetProtocol eTheSmartScheme)
SvxHyperlinkMailTp(weld::Container *pParent, SvxHpLinkDlg *pDlg, const SfxItemSet *pItemSet)
Definition: hlmailtp.cxx:36
SvxLinkInsertMode
#define INET_MAILTO_SCHEME
virtual void SetInitFocus() override
Definition: hlmailtp.cxx:163
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
void SetExchangeSupport()
Definition: iconcdlg.hxx:75
void SetScheme(const OUString &rScheme)
Definition: hlmailtp.cxx:170
static SfxViewFrame * Current()
INetProtocol GetProtocol() const
ComboBox-Control for URL's with History and Autocompletion.
Definition: hltpbase.hxx:36
std::unique_ptr< SvxHyperURLBox > m_xCbbReceiver
Definition: hlmailtp.hxx:33
sal_Int32 nPos
bool SetParam(OUString const &rTheQuery, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
Tabpage : Basisclass.
Definition: hltpbase.hxx:47
static OUString GetSchemeFromURL(const OUString &rStrURL)
Definition: hltpbase.cxx:397
bool SetSmartURL(OUString const &rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)