android: Update app-specific/MIME type icons
[LibreOffice.git] / cui / source / dialogs / hlmailtp.cxx
blob2d25bed91747fc47a619f19b77273afdb48ee6a0
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("addressbook"))
40 , m_xEdSubject(xBuilder->weld_entry("subject"))
42 m_xCbbReceiver->SetSmartProtocol(INetProtocol::Mailto);
44 InitStdControls();
46 m_xCbbReceiver->show();
48 SetExchangeSupport ();
50 // set handlers
51 m_xBtAdrBook->connect_clicked( LINK ( this, SvxHyperlinkMailTp, ClickAdrBookHdl_Impl ) );
52 m_xCbbReceiver->connect_changed( LINK ( this, SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl) );
54 if ( !SvtModuleOptions().IsModuleInstalled( SvtModuleOptions::EModule::DATABASE ) ||
55 comphelper::LibreOfficeKit::isActive() )
56 m_xBtAdrBook->hide();
59 SvxHyperlinkMailTp::~SvxHyperlinkMailTp()
63 /*************************************************************************
65 |* Fill the all dialog-controls except controls in groupbox "more..."
67 |************************************************************************/
69 void SvxHyperlinkMailTp::FillDlgFields(const OUString& rStrURL)
71 OUString aStrScheme = GetSchemeFromURL(rStrURL);
73 // set URL-field and additional controls
74 OUString aStrURLc (rStrURL);
75 // set additional controls for EMail:
76 if ( aStrScheme.startsWith( INET_MAILTO_SCHEME ) )
78 // Find mail-subject
79 OUString aStrSubject, aStrTmp( aStrURLc );
81 sal_Int32 nPos = aStrTmp.toAsciiLowerCase().indexOf( "subject" );
83 if ( nPos != -1 )
84 nPos = aStrTmp.indexOf( '=', nPos );
86 if ( nPos != -1 )
87 aStrSubject = aStrURLc.copy( nPos+1 );
89 nPos = aStrURLc.indexOf( '?' );
91 if ( nPos != -1 )
92 aStrURLc = aStrURLc.copy( 0, nPos );
94 m_xEdSubject->set_text( aStrSubject );
96 else
98 m_xEdSubject->set_text("");
101 m_xCbbReceiver->set_entry_text(aStrURLc);
103 SetScheme( aStrScheme );
106 /*************************************************************************
108 |* retrieve and prepare data from dialog-fields
110 |************************************************************************/
111 void SvxHyperlinkMailTp::GetCurrentItemData ( OUString& rStrURL, OUString& aStrName,
112 OUString& aStrIntName, OUString& aStrFrame,
113 SvxLinkInsertMode& eMode )
115 rStrURL = CreateAbsoluteURL();
116 GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
119 OUString SvxHyperlinkMailTp::CreateAbsoluteURL() const
121 OUString aStrURL = m_xCbbReceiver->get_active_text();
122 INetURLObject aURL(aStrURL, INetProtocol::Mailto);
124 // subject for EMail-url
125 if( aURL.GetProtocol() == INetProtocol::Mailto )
127 if (!m_xEdSubject->get_text().isEmpty())
129 OUString aQuery = "subject=" + m_xEdSubject->get_text();
130 aURL.SetParam(aQuery);
134 if ( aURL.GetProtocol() != INetProtocol::NotValid )
135 return aURL.GetMainURL( INetURLObject::DecodeMechanism::WithCharset );
136 else //#105788# always create a URL even if it is not valid
137 return aStrURL;
140 /*************************************************************************
142 |* static method to create Tabpage
144 |************************************************************************/
146 std::unique_ptr<IconChoicePage> SvxHyperlinkMailTp::Create(weld::Container* pWindow, SvxHpLinkDlg* pDlg, const SfxItemSet* pItemSet)
148 return std::make_unique<SvxHyperlinkMailTp>(pWindow, pDlg, pItemSet);
151 /*************************************************************************
153 |* Set initial focus
155 |************************************************************************/
156 void SvxHyperlinkMailTp::SetInitFocus()
158 m_xCbbReceiver->grab_focus();
161 /*************************************************************************
162 |************************************************************************/
163 void SvxHyperlinkMailTp::SetScheme(std::u16string_view rScheme)
165 //update target:
166 RemoveImproperProtocol(rScheme);
167 m_xCbbReceiver->SetSmartProtocol( INetProtocol::Mailto );
169 //show/hide special fields for MAIL:
170 m_xBtAdrBook->set_sensitive(true);
171 m_xEdSubject->set_sensitive(true);
174 /*************************************************************************
176 |* Remove protocol if it does not fit to the current button selection
178 |************************************************************************/
179 void SvxHyperlinkMailTp::RemoveImproperProtocol(std::u16string_view aProperScheme)
181 OUString aStrURL(m_xCbbReceiver->get_active_text());
182 if ( !aStrURL.isEmpty() )
184 OUString aStrScheme = GetSchemeFromURL( aStrURL );
185 if ( !aStrScheme.isEmpty() && aStrScheme != aProperScheme )
187 aStrURL = aStrURL.copy( aStrScheme.getLength() );
188 m_xCbbReceiver->set_entry_text(aStrURL);
193 /*************************************************************************
195 |* Contents of editfield "receiver" modified
197 |************************************************************************/
198 IMPL_LINK_NOARG(SvxHyperlinkMailTp, ModifiedReceiverHdl_Impl, weld::ComboBox&, void)
200 OUString aScheme = GetSchemeFromURL( m_xCbbReceiver->get_active_text() );
201 if(!aScheme.isEmpty())
202 SetScheme( aScheme );
205 /*************************************************************************
207 |* Click on imagebutton : addressbook
209 |************************************************************************/
210 IMPL_STATIC_LINK_NOARG(SvxHyperlinkMailTp, ClickAdrBookHdl_Impl, weld::Button&, void)
212 if (SfxViewFrame* pViewFrame = SfxViewFrame::Current())
214 SfxItemPool &rPool = pViewFrame->GetPool();
215 SfxRequest aReq(SID_VIEW_DATA_SOURCE_BROWSER, SfxCallMode::SLOT, rPool);
216 pViewFrame->ExecuteSlot( aReq, true );
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */