Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / dbaccess / source / ext / macromigration / macromigrationwizard.cxx
blob78b51f5b8e8e91e88f00ae3a86c184e5a2794c51
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 "dbmm_module.hxx"
21 #include "dbmm_global.hrc"
22 #include "macromigrationdialog.hxx"
23 #include "macromigrationwizard.hxx"
25 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
26 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
27 #include <com/sun/star/frame/XStorable.hpp>
29 #include <svtools/genericunodialog.hxx>
31 namespace dbmm
34 using ::com::sun::star::uno::Reference;
35 using ::com::sun::star::uno::XInterface;
36 using ::com::sun::star::uno::UNO_QUERY;
37 using ::com::sun::star::uno::UNO_QUERY_THROW;
38 using ::com::sun::star::uno::Exception;
39 using ::com::sun::star::uno::RuntimeException;
40 using ::com::sun::star::uno::Any;
41 using ::com::sun::star::uno::XComponentContext;
42 using ::com::sun::star::uno::Sequence;
43 using ::com::sun::star::beans::XPropertySetInfo;
44 using ::com::sun::star::beans::Property;
45 using ::com::sun::star::ucb::AlreadyInitializedException;
46 using ::com::sun::star::sdb::XOfficeDatabaseDocument;
47 using ::com::sun::star::lang::IllegalArgumentException;
48 using ::com::sun::star::frame::XStorable;
50 // MacroMigrationDialogService
51 class MacroMigrationDialogService;
52 typedef ::svt::OGenericUnoDialog MacroMigrationDialogService_Base;
53 typedef ::comphelper::OPropertyArrayUsageHelper< MacroMigrationDialogService > MacroMigrationDialogService_PBase;
55 class MacroMigrationDialogService
56 :public MacroMigrationDialogService_Base
57 ,public MacroMigrationDialogService_PBase
58 ,public MacroMigrationModuleClient
60 public:
61 explicit MacroMigrationDialogService( const Reference< XComponentContext >& _rxContext );
63 // XTypeProvider
64 virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw(RuntimeException, std::exception) override;
66 // XServiceInfo
67 virtual OUString SAL_CALL getImplementationName() throw(RuntimeException, std::exception) override;
68 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException, std::exception) override;
70 // XInitialization
71 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw(css::uno::Exception, css::uno::RuntimeException, std::exception) override;
73 // XPropertySet
74 virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo() throw(RuntimeException, std::exception) override;
75 virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() override;
77 // OPropertyArrayUsageHelper
78 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const override;
80 // helper for factories
81 static Reference< XInterface > SAL_CALL Create( const Reference< XComponentContext >& _rxContext );
82 static OUString SAL_CALL getImplementationName_static() throw(RuntimeException);
83 static Sequence< OUString > SAL_CALL getSupportedServiceNames_static() throw(RuntimeException);
85 protected:
86 virtual ~MacroMigrationDialogService();
88 protected:
89 virtual VclPtr<Dialog> createDialog( vcl::Window* _pParent ) override;
90 virtual void destroyDialog() override;
92 private:
93 Reference<XComponentContext> m_aContext;
94 Reference< XOfficeDatabaseDocument > m_xDocument;
97 // MacroMigrationDialogService
98 MacroMigrationDialogService::MacroMigrationDialogService( const Reference< XComponentContext >& _rxContext )
99 :MacroMigrationDialogService_Base( _rxContext )
100 ,m_aContext( _rxContext )
102 m_bNeedInitialization = true;
105 MacroMigrationDialogService::~MacroMigrationDialogService()
107 // we do this here cause the base class' call to destroyDialog won't reach us anymore: we're within an dtor,
108 // so this virtual-method-call the base class does not work, we're already dead then...
109 if ( m_pDialog )
111 ::osl::MutexGuard aGuard( m_aMutex );
112 if ( m_pDialog )
113 destroyDialog();
117 Reference< XInterface > SAL_CALL MacroMigrationDialogService::Create( const Reference< XComponentContext >& _rxContext )
119 return *(new MacroMigrationDialogService( _rxContext ) );
122 VclPtr<Dialog> MacroMigrationDialogService::createDialog( vcl::Window* _pParent )
124 return VclPtr<MacroMigrationDialog>::Create( _pParent, m_aContext, m_xDocument );
127 void MacroMigrationDialogService::destroyDialog()
129 MacroMigrationDialogService_Base::destroyDialog();
132 Sequence< sal_Int8 > SAL_CALL MacroMigrationDialogService::getImplementationId() throw(RuntimeException, std::exception)
134 return css::uno::Sequence<sal_Int8>();
137 OUString SAL_CALL MacroMigrationDialogService::getImplementationName_static() throw(RuntimeException)
139 return OUString( "com.sun.star.comp.dbaccess.macromigration.MacroMigrationDialogService" );
142 Sequence< OUString > SAL_CALL MacroMigrationDialogService::getSupportedServiceNames_static() throw(RuntimeException)
144 Sequence< OUString > aServices { "com.sun.star.sdb.application.MacroMigrationWizard" };
145 return aServices;
148 OUString SAL_CALL MacroMigrationDialogService::getImplementationName() throw(RuntimeException, std::exception)
150 return getImplementationName_static();
153 Sequence< OUString > SAL_CALL MacroMigrationDialogService::getSupportedServiceNames() throw(RuntimeException, std::exception)
155 return getSupportedServiceNames_static();
158 void SAL_CALL MacroMigrationDialogService::initialize( const Sequence< Any >& _rArguments ) throw(Exception, RuntimeException, std::exception)
160 ::osl::MutexGuard aGuard( m_aMutex );
161 if ( m_bInitialized )
162 throw AlreadyInitializedException( OUString(), *this );
164 if ( _rArguments.getLength() != 1 )
165 throw IllegalArgumentException(
166 OUString(MacroMigrationResId(STR_INVALID_NUMBER_ARGS)),
167 *this,
171 m_xDocument.set( _rArguments[0], UNO_QUERY );
172 if ( !m_xDocument.is() )
173 throw IllegalArgumentException(
174 OUString(MacroMigrationResId(STR_NO_DATABASE)),
175 *this,
179 Reference< XStorable > xDocStor( m_xDocument, UNO_QUERY_THROW );
180 if ( xDocStor->isReadonly() )
181 throw IllegalArgumentException(
182 OUString(MacroMigrationResId(STR_NOT_READONLY)),
183 *this,
187 m_bInitialized = true;
190 Reference< XPropertySetInfo > SAL_CALL MacroMigrationDialogService::getPropertySetInfo() throw(RuntimeException, std::exception)
192 return createPropertySetInfo( getInfoHelper() );
195 ::cppu::IPropertyArrayHelper& SAL_CALL MacroMigrationDialogService::getInfoHelper()
197 return *getArrayHelper();
200 ::cppu::IPropertyArrayHelper* MacroMigrationDialogService::createArrayHelper( ) const
202 Sequence< Property > aProps;
203 describeProperties( aProps );
204 return new ::cppu::OPropertyArrayHelper( aProps );
207 void createRegistryInfo_MacroMigrationDialogService()
209 static OAutoRegistration< MacroMigrationDialogService > aAutoRegistration;
212 } // namespace dbmm
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */