Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / filter / source / xsltdialog / xmlfiltertabpagexslt.cxx
blobca879c93a4fae355b6cf7adf3f8a0d3037cace4f
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 <com/sun/star/ui/dialogs/TemplateDescription.hpp>
21 #include <sfx2/filedlghelper.hxx>
22 #include <unotools/localfilehelper.hxx>
23 #include <unotools/pathoptions.hxx>
24 #include <osl/file.hxx>
25 #include <svl/urihelper.hxx>
26 #include <vcl/svapp.hxx>
28 #include "xmlfiltertabpagexslt.hxx"
29 #include "xmlfiltersettingsdialog.hxx"
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::lang;
34 XMLFilterTabPageXSLT::XMLFilterTabPageXSLT(weld::Widget* pPage, weld::Dialog* pDialog)
35 : sInstPath( "$(prog)/" )
36 , m_pDialog(pDialog)
37 , m_xBuilder(Application::CreateBuilder(pPage, "filter/ui/xmlfiltertabpagetransformation.ui"))
38 , m_xContainer(m_xBuilder->weld_widget("XmlFilterTabPageTransformation"))
39 , m_xEDDocType(m_xBuilder->weld_entry("doc"))
40 , m_xEDExportXSLT(new URLBox(m_xBuilder->weld_combo_box("xsltexport")))
41 , m_xPBExprotXSLT(m_xBuilder->weld_button("browseexport"))
42 , m_xEDImportXSLT(new URLBox(m_xBuilder->weld_combo_box("xsltimport")))
43 , m_xPBImportXSLT(m_xBuilder->weld_button("browseimport"))
44 , m_xEDImportTemplate(new URLBox(m_xBuilder->weld_combo_box("tempimport")))
45 , m_xPBImportTemplate(m_xBuilder->weld_button("browsetemp"))
46 , m_xCBNeedsXSLT2(m_xBuilder->weld_check_button("filtercb"))
48 SvtPathOptions aOptions;
49 sInstPath = aOptions.SubstituteVariable( sInstPath );
51 m_xPBExprotXSLT->connect_clicked( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) );
52 m_xPBImportXSLT->connect_clicked( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) );
53 m_xPBImportTemplate->connect_clicked( LINK ( this, XMLFilterTabPageXSLT, ClickBrowseHdl_Impl ) );
56 XMLFilterTabPageXSLT::~XMLFilterTabPageXSLT()
60 void XMLFilterTabPageXSLT::FillInfo( filter_info_impl* pInfo )
62 if( pInfo )
64 pInfo->maDocType = m_xEDDocType->get_text();
65 pInfo->maExportXSLT = GetURL(*m_xEDExportXSLT);
66 pInfo->maImportXSLT = GetURL(*m_xEDImportXSLT);
67 pInfo->maImportTemplate = GetURL(*m_xEDImportTemplate);
68 pInfo->mbNeedsXSLT2 = m_xCBNeedsXSLT2->get_active();
72 void XMLFilterTabPageXSLT::SetInfo(const filter_info_impl* pInfo)
74 if( pInfo )
76 m_xEDDocType->set_text( pInfo->maDocType );
78 SetURL( *m_xEDExportXSLT, pInfo->maExportXSLT );
79 SetURL( *m_xEDImportXSLT, pInfo->maImportXSLT );
80 SetURL( *m_xEDImportTemplate, pInfo->maImportTemplate );
81 m_xCBNeedsXSLT2->set_active(pInfo->mbNeedsXSLT2);
85 void XMLFilterTabPageXSLT::SetURL( URLBox& rURLBox, const OUString& rURL )
87 OUString aPath;
89 if( rURL.matchIgnoreAsciiCase( "file://" ) )
91 osl::FileBase::getSystemPathFromFileURL( rURL, aPath );
93 rURLBox.SetBaseURL( rURL );
94 rURLBox.set_entry_text( aPath );
96 else if( rURL.matchIgnoreAsciiCase( "http://" ) ||
97 rURL.matchIgnoreAsciiCase( "https://" ) ||
98 rURL.matchIgnoreAsciiCase( "ftp://" ) )
100 rURLBox.SetBaseURL( rURL );
101 rURLBox.set_entry_text( rURL );
103 else if( !rURL.isEmpty() )
105 OUString aURL = URIHelper::SmartRel2Abs( INetURLObject(sInstPath), rURL, Link<OUString *, bool>(), false );
106 osl::FileBase::getSystemPathFromFileURL( aURL, aPath );
108 rURLBox.SetBaseURL( aURL );
109 rURLBox.set_entry_text( aPath );
111 else
113 rURLBox.SetBaseURL( sInstPath );
114 rURLBox.set_entry_text( "" );
118 OUString XMLFilterTabPageXSLT::GetURL(const URLBox& rURLBox)
120 OUString aURL;
121 OUString aStrPath(rURLBox.get_active_text());
122 if( aStrPath.matchIgnoreAsciiCase( "http://" ) ||
123 aStrPath.matchIgnoreAsciiCase( "https://" ) ||
124 aStrPath.matchIgnoreAsciiCase( "ftp://" ) )
126 return aStrPath;
128 else
130 osl::FileBase::getFileURLFromSystemPath( aStrPath, aURL );
133 return aURL;
136 IMPL_LINK ( XMLFilterTabPageXSLT, ClickBrowseHdl_Impl, weld::Button&, rButton, void )
138 URLBox* pURLBox;
140 if( &rButton == m_xPBExprotXSLT.get() )
142 pURLBox = m_xEDExportXSLT.get();
144 else if( &rButton == m_xPBImportXSLT.get() )
146 pURLBox = m_xEDImportXSLT.get();
148 else
150 pURLBox = m_xEDImportTemplate.get();
153 // Open Fileopen-Dialog
154 ::sfx2::FileDialogHelper aDlg(css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE,
155 FileDialogFlags::NONE, m_pDialog);
157 aDlg.SetDisplayDirectory(GetURL(*pURLBox));
159 if (aDlg.Execute() == ERRCODE_NONE)
161 OUString aURL(aDlg.GetPath());
162 SetURL(*pURLBox, aURL);
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */