android: Update app-specific/MIME type icons
[LibreOffice.git] / filter / source / xsltdialog / xmlfilterdialogcomponent.cxx
blob5cf047d07e418a82e7545536ba566d9edbb239de
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 <comphelper/servicehelper.hxx>
21 #include <cppuhelper/factory.hxx>
22 #include <comphelper/compbase.hxx>
23 #include <com/sun/star/frame/Desktop.hpp>
24 #include <com/sun/star/frame/XTerminateListener.hpp>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/lang/XInitialization.hpp>
28 #include <com/sun/star/awt/XWindow.hpp>
29 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
30 #include <com/sun/star/beans/PropertyValue.hpp>
31 #include <vcl/svapp.hxx>
33 #include "xmlfiltersettingsdialog.hxx"
35 using namespace ::cppu;
36 using namespace ::osl;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::lang;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::registry;
41 using namespace ::com::sun::star::frame;
43 namespace {
46 class XMLFilterDialogComponent : public comphelper::WeakComponentImplHelper<
47 css::ui::dialogs::XExecutableDialog,
48 XServiceInfo,
49 XInitialization,
50 XTerminateListener>
52 public:
53 explicit XMLFilterDialogComponent( const Reference< XComponentContext >& rxContext );
55 protected:
56 // XTypeProvider
57 virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
59 // XServiceInfo
60 virtual OUString SAL_CALL getImplementationName() override;
61 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
62 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
64 // XExecutableDialog
65 virtual void SAL_CALL setTitle( const OUString& aTitle ) override;
66 virtual sal_Int16 SAL_CALL execute( ) override;
68 // XInitialization
69 virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) override;
71 // XTerminateListener
72 virtual void SAL_CALL queryTermination( const EventObject& Event ) override;
73 virtual void SAL_CALL notifyTermination( const EventObject& Event ) override;
74 virtual void SAL_CALL disposing( const EventObject& Source ) override;
76 /** Called in dispose method after the listeners were notified.
78 virtual void disposing(std::unique_lock<std::mutex>& rGuard) override;
80 private:
81 css::uno::Reference<css::awt::XWindow> mxParent; /// parent window
82 css::uno::Reference< XComponentContext > mxContext;
84 std::shared_ptr<XMLFilterSettingsDialog> mxDialog;
89 XMLFilterDialogComponent::XMLFilterDialogComponent(const css::uno::Reference< XComponentContext >& rxContext)
90 : mxContext(rxContext)
92 Reference< XDesktop2 > xDesktop = Desktop::create( rxContext );
93 Reference< XTerminateListener > xListener( this );
94 xDesktop->addTerminateListener( xListener );
97 OUString SAL_CALL XMLFilterDialogComponent::getImplementationName()
99 return "com.sun.star.comp.ui.XSLTFilterDialog";
102 Sequence< sal_Int8 > SAL_CALL XMLFilterDialogComponent::getImplementationId()
104 static const comphelper::UnoIdInit implId;
105 return implId.getSeq();
109 Sequence< OUString > SAL_CALL XMLFilterDialogComponent::getSupportedServiceNames()
111 return { "com.sun.star.ui.dialogs.XSLTFilterDialog" };
114 sal_Bool SAL_CALL XMLFilterDialogComponent::supportsService(const OUString& ServiceName)
116 return cppu::supportsService( this, ServiceName );
119 /** Called in dispose method after the listeners were notified.
121 void XMLFilterDialogComponent::disposing(std::unique_lock<std::mutex>& rGuard)
123 rGuard.unlock();
125 ::SolarMutexGuard aGuard;
127 if (mxDialog)
128 mxDialog->response(RET_CLOSE);
130 rGuard.lock();
134 // XTerminateListener
135 void SAL_CALL XMLFilterDialogComponent::queryTermination( const EventObject& /* Event */ )
137 ::SolarMutexGuard aGuard;
138 if (!mxDialog)
139 return;
140 mxDialog->present();
143 void SAL_CALL XMLFilterDialogComponent::notifyTermination( const EventObject& /* Event */ )
146 ::SolarMutexGuard aGuard;
147 if (mxDialog)
148 mxDialog->response(RET_CLOSE);
151 // we are going down, so dispose us!
152 dispose();
155 void SAL_CALL XMLFilterDialogComponent::disposing( const EventObject& /* Source */ )
159 void SAL_CALL XMLFilterDialogComponent::setTitle( const OUString& /* _rTitle */ )
163 sal_Int16 SAL_CALL XMLFilterDialogComponent::execute()
165 ::SolarMutexGuard aGuard;
167 bool bLaunch = false;
168 if (!mxDialog)
170 Reference< XComponent > xKeepAlive( this );
171 mxDialog = std::make_shared<XMLFilterSettingsDialog>(Application::GetFrameWeld(mxParent), mxContext);
172 bLaunch = true;
175 mxDialog->UpdateWindow();
177 if (!bLaunch)
179 mxDialog->present();
180 return 0;
183 weld::DialogController::runAsync(mxDialog, [this](sal_Int32)
185 mxDialog.reset();
188 return 0;
191 void SAL_CALL XMLFilterDialogComponent::initialize( const Sequence< Any >& aArguments )
193 for(const Any& rArgument : aArguments)
195 PropertyValue aProperty;
196 if(rArgument >>= aProperty)
198 if( aProperty.Name == "ParentWindow" )
200 aProperty.Value >>= mxParent;
207 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
208 filter_XSLTFilterDialog_get_implementation(
209 css::uno::XComponentContext* context, css::uno::Sequence<css::uno::Any> const&)
211 return cppu::acquire(new XMLFilterDialogComponent(context));
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */