1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/pathoptions.hxx>
23 #include <osl/file.hxx>
24 #include <svl/urihelper.hxx>
25 #include <vcl/svapp.hxx>
27 #include "xmlfiltercommon.hxx"
28 #include "xmlfiltertabpagexslt.hxx"
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::lang
;
33 XMLFilterTabPageXSLT::XMLFilterTabPageXSLT(weld::Widget
* pPage
, weld::Dialog
* pDialog
)
34 : sInstPath( "$(prog)/" )
36 , m_xBuilder(Application::CreateBuilder(pPage
, "filter/ui/xmlfiltertabpagetransformation.ui"))
37 , m_xContainer(m_xBuilder
->weld_widget("XmlFilterTabPageTransformation"))
38 , m_xEDDocType(m_xBuilder
->weld_entry("doc"))
39 , m_xEDExportXSLT(new SvtURLBox(m_xBuilder
->weld_combo_box("xsltexport")))
40 , m_xPBExprotXSLT(m_xBuilder
->weld_button("browseexport"))
41 , m_xEDImportXSLT(new SvtURLBox(m_xBuilder
->weld_combo_box("xsltimport")))
42 , m_xPBImportXSLT(m_xBuilder
->weld_button("browseimport"))
43 , m_xEDImportTemplate(new SvtURLBox(m_xBuilder
->weld_combo_box("tempimport")))
44 , m_xPBImportTemplate(m_xBuilder
->weld_button("browsetemp"))
45 , m_xCBNeedsXSLT2(m_xBuilder
->weld_check_button("filtercb"))
47 SvtPathOptions aOptions
;
48 sInstPath
= aOptions
.SubstituteVariable( sInstPath
);
50 m_xPBExprotXSLT
->connect_clicked( LINK ( this, XMLFilterTabPageXSLT
, ClickBrowseHdl_Impl
) );
51 m_xPBImportXSLT
->connect_clicked( LINK ( this, XMLFilterTabPageXSLT
, ClickBrowseHdl_Impl
) );
52 m_xPBImportTemplate
->connect_clicked( LINK ( this, XMLFilterTabPageXSLT
, ClickBrowseHdl_Impl
) );
55 XMLFilterTabPageXSLT::~XMLFilterTabPageXSLT()
59 void XMLFilterTabPageXSLT::FillInfo( filter_info_impl
* pInfo
)
63 pInfo
->maDocType
= m_xEDDocType
->get_text();
64 pInfo
->maExportXSLT
= GetURL(*m_xEDExportXSLT
);
65 pInfo
->maImportXSLT
= GetURL(*m_xEDImportXSLT
);
66 pInfo
->maImportTemplate
= GetURL(*m_xEDImportTemplate
);
67 pInfo
->mbNeedsXSLT2
= m_xCBNeedsXSLT2
->get_active();
71 void XMLFilterTabPageXSLT::SetInfo(const filter_info_impl
* pInfo
)
75 m_xEDDocType
->set_text( pInfo
->maDocType
);
77 SetURL( *m_xEDExportXSLT
, pInfo
->maExportXSLT
);
78 SetURL( *m_xEDImportXSLT
, pInfo
->maImportXSLT
);
79 SetURL( *m_xEDImportTemplate
, pInfo
->maImportTemplate
);
80 m_xCBNeedsXSLT2
->set_active(pInfo
->mbNeedsXSLT2
);
84 void XMLFilterTabPageXSLT::SetURL( SvtURLBox
& rURLBox
, const OUString
& rURL
)
88 if( rURL
.matchIgnoreAsciiCase( "file://" ) )
90 osl::FileBase::getSystemPathFromFileURL( rURL
, aPath
);
92 rURLBox
.SetBaseURL( rURL
);
93 rURLBox
.set_entry_text( aPath
);
95 else if( rURL
.matchIgnoreAsciiCase( "http://" ) ||
96 rURL
.matchIgnoreAsciiCase( "https://" ) ||
97 rURL
.matchIgnoreAsciiCase( "ftp://" ) )
99 rURLBox
.SetBaseURL( rURL
);
100 rURLBox
.set_entry_text( rURL
);
102 else if( !rURL
.isEmpty() )
104 OUString aURL
= URIHelper::SmartRel2Abs( INetURLObject(sInstPath
), rURL
, Link
<OUString
*, bool>(), false );
105 osl::FileBase::getSystemPathFromFileURL( aURL
, aPath
);
107 rURLBox
.SetBaseURL( aURL
);
108 rURLBox
.set_entry_text( aPath
);
112 rURLBox
.SetBaseURL( sInstPath
);
113 rURLBox
.set_entry_text( "" );
117 OUString
XMLFilterTabPageXSLT::GetURL(const SvtURLBox
& rURLBox
)
120 OUString
aStrPath(rURLBox
.get_active_text());
121 if( aStrPath
.matchIgnoreAsciiCase( "http://" ) ||
122 aStrPath
.matchIgnoreAsciiCase( "https://" ) ||
123 aStrPath
.matchIgnoreAsciiCase( "ftp://" ) )
129 osl::FileBase::getFileURLFromSystemPath( aStrPath
, aURL
);
135 IMPL_LINK ( XMLFilterTabPageXSLT
, ClickBrowseHdl_Impl
, weld::Button
&, rButton
, void )
139 if( &rButton
== m_xPBExprotXSLT
.get() )
141 pURLBox
= m_xEDExportXSLT
.get();
143 else if( &rButton
== m_xPBImportXSLT
.get() )
145 pURLBox
= m_xEDImportXSLT
.get();
149 pURLBox
= m_xEDImportTemplate
.get();
152 // Open Fileopen-Dialog
153 ::sfx2::FileDialogHelper
aDlg(css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE
,
154 FileDialogFlags::NONE
, m_pDialog
);
156 aDlg
.SetDisplayDirectory(GetURL(*pURLBox
));
158 if (aDlg
.Execute() == ERRCODE_NONE
)
160 OUString
aURL(aDlg
.GetPath());
161 SetURL(*pURLBox
, aURL
);
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */