android: Update app-specific/MIME type icons
[LibreOffice.git] / cui / source / dialogs / hldoctp.cxx
bloba1c1454b69deb786dc603a98035f9edca7b2e29f
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 <cuihyperdlg.hxx>
21 #include <osl/file.hxx>
22 #include <sfx2/filedlghelper.hxx>
23 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
25 #include <hldoctp.hxx>
26 #include <hlmarkwn_def.hxx>
28 char const sHash[] = "#";
30 /*************************************************************************
32 |* Constructor / Destructor
34 |************************************************************************/
36 SvxHyperlinkDocTp::SvxHyperlinkDocTp(weld::Container* pParent, SvxHpLinkDlg* pDlg, const SfxItemSet* pItemSet)
37 : SvxHyperlinkTabPageBase(pParent, pDlg, "cui/ui/hyperlinkdocpage.ui", "HyperlinkDocPage", pItemSet)
38 , m_xCbbPath(new SvxHyperURLBox(xBuilder->weld_combo_box("path")))
39 , m_xBtFileopen(xBuilder->weld_button("fileopen"))
40 , m_xEdTarget(xBuilder->weld_entry("target"))
41 , m_xFtFullURL(xBuilder->weld_label("url"))
42 , m_xBtBrowse(xBuilder->weld_button("browse"))
43 , m_bMarkWndOpen(false)
45 m_xCbbPath->SetSmartProtocol(INetProtocol::File);
47 InitStdControls();
49 m_xCbbPath->show();
50 m_xCbbPath->SetBaseURL(INET_FILE_SCHEME);
52 SetExchangeSupport();
54 // set handlers
55 m_xBtFileopen->connect_clicked( LINK ( this, SvxHyperlinkDocTp, ClickFileopenHdl_Impl ) );
56 m_xBtBrowse->connect_clicked( LINK ( this, SvxHyperlinkDocTp, ClickTargetHdl_Impl ) );
57 m_xCbbPath->connect_changed( LINK ( this, SvxHyperlinkDocTp, ModifiedPathHdl_Impl ) );
58 m_xEdTarget->connect_changed( LINK ( this, SvxHyperlinkDocTp, ModifiedTargetHdl_Impl ) );
60 m_xCbbPath->connect_focus_out( LINK ( this, SvxHyperlinkDocTp, LostFocusPathHdl_Impl ) );
62 maTimer.SetInvokeHandler ( LINK ( this, SvxHyperlinkDocTp, TimeoutHdl_Impl ) );
65 SvxHyperlinkDocTp::~SvxHyperlinkDocTp()
69 /*************************************************************************
71 |* Fill all dialog-controls except controls in groupbox "more..."
73 |************************************************************************/
74 void SvxHyperlinkDocTp::FillDlgFields(const OUString& rStrURL)
76 sal_Int32 nPos = rStrURL.indexOf(sHash);
77 // path
78 m_xCbbPath->set_entry_text( rStrURL.copy( 0, ( nPos == -1 ? rStrURL.getLength() : nPos ) ) );
80 // set target in document at editfield
81 OUString aStrMark;
82 if ( nPos != -1 && nPos < rStrURL.getLength()-1 )
83 aStrMark = rStrURL.copy( nPos+1 );
84 m_xEdTarget->set_text( aStrMark );
86 ModifiedPathHdl_Impl(*m_xCbbPath->getWidget());
89 /*************************************************************************
91 |* retrieve current url-string
93 |************************************************************************/
94 OUString SvxHyperlinkDocTp::GetCurrentURL () const
96 // get data from dialog-controls
97 OUString aStrURL;
98 OUString aStrPath( m_xCbbPath->get_active_text() );
99 OUString aStrMark( m_xEdTarget->get_text() );
101 if ( !aStrPath.isEmpty() )
103 INetURLObject aURL( aStrPath );
104 if ( aURL.GetProtocol() != INetProtocol::NotValid ) // maybe the path is already a valid
105 aStrURL = aStrPath; // hyperlink, then we can use this path directly
106 else
108 osl::FileBase::getFileURLFromSystemPath( aStrPath, aStrURL );
109 aStrURL = INetURLObject::decode(aStrURL, INetURLObject::DecodeMechanism::ToIUri, RTL_TEXTENCODING_UTF8);
112 //#105788# always create a URL even if it is not valid
113 if( aStrURL.isEmpty() )
114 aStrURL = aStrPath;
117 if( !aStrMark.isEmpty() )
119 aStrURL += sHash + aStrMark;
122 return aStrURL;
125 /*************************************************************************
127 |* retrieve and prepare data from dialog-fields
129 |************************************************************************/
130 void SvxHyperlinkDocTp::GetCurrentItemData ( OUString& rStrURL, OUString& aStrName,
131 OUString& aStrIntName, OUString& aStrFrame,
132 SvxLinkInsertMode& eMode )
134 // get data from standard-fields
135 rStrURL = GetCurrentURL();
137 if( rStrURL.equalsIgnoreAsciiCase( INET_FILE_SCHEME ) )
138 rStrURL.clear();
140 GetDataFromCommonFields( aStrName, aStrIntName, aStrFrame, eMode );
143 /*************************************************************************
145 |* static method to create Tabpage
147 |************************************************************************/
148 std::unique_ptr<IconChoicePage> SvxHyperlinkDocTp::Create(weld::Container* pWindow, SvxHpLinkDlg* pDlg, const SfxItemSet* pItemSet)
150 return std::make_unique<SvxHyperlinkDocTp>(pWindow, pDlg, pItemSet);
153 /*************************************************************************
155 |* Set initial focus
157 |************************************************************************/
158 void SvxHyperlinkDocTp::SetInitFocus()
160 m_xCbbPath->grab_focus();
163 /*************************************************************************
165 |* Click on imagebutton : fileopen
167 |************************************************************************/
168 IMPL_LINK_NOARG(SvxHyperlinkDocTp, ClickFileopenHdl_Impl, weld::Button&, void)
170 DisableClose( true );
171 // Open Fileopen-Dialog
172 sfx2::FileDialogHelper aDlg(
173 css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, FileDialogFlags::NONE,
174 mpDialog->getDialog() );
175 OUString aOldURL( GetCurrentURL() );
176 if( aOldURL.startsWithIgnoreAsciiCase( INET_FILE_SCHEME ) )
178 OUString aPath;
179 osl::FileBase::getSystemPathFromFileURL(aOldURL, aPath);
180 aDlg.SetDisplayFolder( aPath );
183 ErrCode nError = aDlg.Execute();
184 DisableClose( false );
186 if ( ERRCODE_NONE != nError )
187 return;
189 OUString aURL( aDlg.GetPath() );
190 OUString aPath;
192 osl::FileBase::getSystemPathFromFileURL(aURL, aPath);
194 m_xCbbPath->SetBaseURL( aURL );
195 m_xCbbPath->set_entry_text(aPath);
197 if ( aOldURL != GetCurrentURL() )
198 ModifiedPathHdl_Impl(*m_xCbbPath->getWidget());
201 /*************************************************************************
203 |* Click on imagebutton : target
205 |************************************************************************/
206 IMPL_LINK_NOARG(SvxHyperlinkDocTp, ClickTargetHdl_Impl, weld::Button&, void)
208 ShowMarkWnd();
210 if ( GetPathType ( maStrURL ) == EPathType::ExistsFile ||
211 maStrURL.isEmpty() ||
212 maStrURL.equalsIgnoreAsciiCase( INET_FILE_SCHEME ) ||
213 maStrURL.startsWith( sHash ) )
215 mxMarkWnd->SetError( LERR_NOERROR );
217 weld::WaitObject aWait(mpDialog->getDialog());
219 if ( maStrURL.equalsIgnoreAsciiCase( INET_FILE_SCHEME ) )
220 mxMarkWnd->RefreshTree ( "" );
221 else
222 mxMarkWnd->RefreshTree ( maStrURL );
224 else
225 mxMarkWnd->SetError( LERR_DOCNOTOPEN );
228 /*************************************************************************
230 |* Contents of combobox "Path" modified
232 |************************************************************************/
233 IMPL_LINK_NOARG(SvxHyperlinkDocTp, ModifiedPathHdl_Impl, weld::ComboBox&, void)
235 maStrURL = GetCurrentURL();
237 maTimer.SetTimeout( 2500 );
238 maTimer.Start();
240 m_xFtFullURL->set_label( maStrURL );
243 /*************************************************************************
245 |* If path-field was modify, to browse the new doc after timeout
247 |************************************************************************/
248 IMPL_LINK_NOARG(SvxHyperlinkDocTp, TimeoutHdl_Impl, Timer *, void)
250 if ( IsMarkWndVisible() && ( GetPathType( maStrURL )== EPathType::ExistsFile ||
251 maStrURL.isEmpty() ||
252 maStrURL.equalsIgnoreAsciiCase( INET_FILE_SCHEME ) ) )
254 weld::WaitObject aWait(mpDialog->getDialog());
256 if ( maStrURL.equalsIgnoreAsciiCase( INET_FILE_SCHEME ) )
257 mxMarkWnd->RefreshTree ( "" );
258 else
259 mxMarkWnd->RefreshTree ( maStrURL );
263 /*************************************************************************
265 |* Contents of editfield "Target" modified
267 |************************************************************************/
268 IMPL_LINK_NOARG(SvxHyperlinkDocTp, ModifiedTargetHdl_Impl, weld::Entry&, void)
270 maStrURL = GetCurrentURL();
272 if (IsMarkWndVisible())
273 mxMarkWnd->SelectEntry(m_xEdTarget->get_text());
275 m_xFtFullURL->set_label( maStrURL );
278 /*************************************************************************
280 |* editfield "Target" lost focus
282 |************************************************************************/
283 IMPL_LINK_NOARG(SvxHyperlinkDocTp, LostFocusPathHdl_Impl, weld::Widget&, void)
285 maStrURL = GetCurrentURL();
287 m_xFtFullURL->set_label( maStrURL );
290 /*************************************************************************
292 |* Get String from Bookmark-Wnd
294 |************************************************************************/
295 void SvxHyperlinkDocTp::SetMarkStr ( const OUString& aStrMark )
297 m_xEdTarget->set_text(aStrMark);
299 ModifiedTargetHdl_Impl ( *m_xEdTarget );
302 /*************************************************************************
304 |* retrieve kind of pathstr
306 |************************************************************************/
307 SvxHyperlinkDocTp::EPathType SvxHyperlinkDocTp::GetPathType ( std::u16string_view rStrPath )
309 INetURLObject aURL( rStrPath, INetProtocol::File );
311 if( aURL.HasError() )
312 return EPathType::Invalid;
313 else
314 return EPathType::ExistsFile;
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */