1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbaccess.hxx"
26 
27 #include "dbmm_module.hxx"
28 #include "dbmm_global.hrc"
29 #include "macromigrationdialog.hxx"
30 
31 /** === begin UNO includes === **/
32 #include <com/sun/star/ucb/AlreadyInitializedException.hpp>
33 #include <com/sun/star/sdb/XOfficeDatabaseDocument.hpp>
34 #include <com/sun/star/frame/XStorable.hpp>
35 /** === end UNO includes === **/
36 
37 #include <comphelper/componentcontext.hxx>
38 #include <svtools/genericunodialog.hxx>
39 
40 //........................................................................
41 namespace dbmm
42 {
43 //........................................................................
44 
45 	/** === begin UNO using === **/
46 	using ::com::sun::star::uno::Reference;
47 	using ::com::sun::star::uno::XInterface;
48 	using ::com::sun::star::uno::UNO_QUERY;
49 	using ::com::sun::star::uno::UNO_QUERY_THROW;
50 	using ::com::sun::star::uno::UNO_SET_THROW;
51 	using ::com::sun::star::uno::Exception;
52 	using ::com::sun::star::uno::RuntimeException;
53 	using ::com::sun::star::uno::Any;
54 	using ::com::sun::star::uno::makeAny;
55     using ::com::sun::star::uno::XComponentContext;
56     using ::com::sun::star::uno::Sequence;
57     using ::com::sun::star::beans::XPropertySetInfo;
58     using ::com::sun::star::beans::Property;
59     using ::com::sun::star::ucb::AlreadyInitializedException;
60     using ::com::sun::star::sdb::XOfficeDatabaseDocument;
61     using ::com::sun::star::lang::IllegalArgumentException;
62     using ::com::sun::star::frame::XStorable;
63 	/** === end UNO using === **/
64 
65 	//====================================================================
66 	//= MacroMigrationDialogService
67 	//====================================================================
68     class MacroMigrationDialogService;
69     typedef ::svt::OGenericUnoDialog                                                MacroMigrationDialogService_Base;
70     typedef ::comphelper::OPropertyArrayUsageHelper< MacroMigrationDialogService >  MacroMigrationDialogService_PBase;
71 
72     class MacroMigrationDialogService
73                 :public MacroMigrationDialogService_Base
74                 ,public MacroMigrationDialogService_PBase
75                 ,public MacroMigrationModuleClient
76     {
77     public:
78         MacroMigrationDialogService( const Reference< XComponentContext >& _rxContext );
79 
80         // XTypeProvider
81 		virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() throw(RuntimeException);
82 
83 		// XServiceInfo
84 		virtual ::rtl::OUString SAL_CALL getImplementationName() throw(RuntimeException);
85         virtual Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw(RuntimeException);
86 
87         // XInitialization
88 		virtual void SAL_CALL initialize( const com::sun::star::uno::Sequence< com::sun::star::uno::Any >& aArguments ) throw(com::sun::star::uno::Exception, com::sun::star::uno::RuntimeException);
89 
90 	    // XPropertySet
91 	    virtual Reference< XPropertySetInfo >  SAL_CALL getPropertySetInfo() throw(RuntimeException);
92 	    virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();
93 
94 	    // OPropertyArrayUsageHelper
95 	    virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
96 
97         // helper for factories
98         static Reference< XInterface > SAL_CALL Create( const Reference< XComponentContext >& _rxContext );
99 		static ::rtl::OUString SAL_CALL getImplementationName_static() throw(RuntimeException);
100         static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static() throw(RuntimeException);
101 
102     protected:
103         ~MacroMigrationDialogService();
104 
105     protected:
106 		virtual Dialog*	createDialog( Window* _pParent );
107 	    virtual void destroyDialog();
108 
109     private:
110         ::comphelper::ComponentContext          m_aContext;
111         Reference< XOfficeDatabaseDocument >    m_xDocument;
112     };
113 
114 	//====================================================================
115 	//= MacroMigrationDialogService
116 	//====================================================================
117 	//--------------------------------------------------------------------
MacroMigrationDialogService(const Reference<XComponentContext> & _rxContext)118     MacroMigrationDialogService::MacroMigrationDialogService( const Reference< XComponentContext >& _rxContext )
119         :MacroMigrationDialogService_Base( _rxContext )
120         ,m_aContext( _rxContext )
121     {
122         m_bNeedInitialization = true;
123     }
124 
125     //--------------------------------------------------------------------
~MacroMigrationDialogService()126     MacroMigrationDialogService::~MacroMigrationDialogService()
127     {
128         // we do this here cause the base class' call to destroyDialog won't reach us anymore : we're within an dtor,
129         // so this virtual-method-call the base class does does not work, we're already dead then ...
130         if ( m_pDialog )
131         {
132             ::osl::MutexGuard aGuard( m_aMutex );
133             if ( m_pDialog )
134                 destroyDialog();
135         }
136     }
137 
138     //--------------------------------------------------------------------
Create(const Reference<XComponentContext> & _rxContext)139     Reference< XInterface > SAL_CALL MacroMigrationDialogService::Create( const Reference< XComponentContext >& _rxContext )
140     {
141         return *(new MacroMigrationDialogService( _rxContext ) );
142     }
143 
144     //--------------------------------------------------------------------
createDialog(Window * _pParent)145 	Dialog*	MacroMigrationDialogService::createDialog( Window* _pParent )
146     {
147         return new MacroMigrationDialog( _pParent, m_aContext, m_xDocument );
148     }
149 
150     //--------------------------------------------------------------------
destroyDialog()151     void MacroMigrationDialogService::destroyDialog()
152     {
153 	    MacroMigrationDialogService_Base::destroyDialog();
154     }
155 
156     //--------------------------------------------------------------------
getImplementationId()157     Sequence< sal_Int8 > SAL_CALL MacroMigrationDialogService::getImplementationId() throw(RuntimeException)
158     {
159         static ::cppu::OImplementationId* pId = NULL;
160         if ( !pId )
161         {
162             ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
163             if ( !pId )
164             {
165                 static ::cppu::OImplementationId aId;
166                 pId = &aId;
167             }
168         }
169         return pId->getImplementationId();
170     }
171 
172     //--------------------------------------------------------------------
getImplementationName_static()173     ::rtl::OUString SAL_CALL MacroMigrationDialogService::getImplementationName_static() throw(RuntimeException)
174     {
175         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.dbaccess.macromigration.MacroMigrationDialogService" ) );
176     }
177 
178     //--------------------------------------------------------------------
getSupportedServiceNames_static()179     Sequence< ::rtl::OUString > SAL_CALL MacroMigrationDialogService::getSupportedServiceNames_static() throw(RuntimeException)
180     {
181         Sequence< ::rtl::OUString > aServices(1);
182         aServices[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sdb.application.MacroMigrationWizard" ) );
183         return aServices;
184     }
185 
186     //--------------------------------------------------------------------
getImplementationName()187     ::rtl::OUString SAL_CALL MacroMigrationDialogService::getImplementationName() throw(RuntimeException)
188     {
189         return getImplementationName_static();
190     }
191 
192     //--------------------------------------------------------------------
getSupportedServiceNames()193     Sequence< ::rtl::OUString > SAL_CALL MacroMigrationDialogService::getSupportedServiceNames() throw(RuntimeException)
194     {
195         return getSupportedServiceNames_static();
196     }
197 
198     //--------------------------------------------------------------------
initialize(const Sequence<Any> & _rArguments)199     void SAL_CALL MacroMigrationDialogService::initialize( const Sequence< Any >& _rArguments ) throw(Exception, RuntimeException)
200     {
201         ::osl::MutexGuard aGuard( m_aMutex );
202         if ( m_bInitialized )
203             throw AlreadyInitializedException( ::rtl::OUString(), *this );
204 
205         if ( _rArguments.getLength() != 1 )
206             throw IllegalArgumentException(
207                 String(MacroMigrationResId(STR_INVALID_NUMBER_ARGS)),
208                 *this,
209                 1
210             );
211 
212         m_xDocument.set( _rArguments[0], UNO_QUERY );
213         if ( !m_xDocument.is() )
214             throw IllegalArgumentException(
215                 String(MacroMigrationResId(STR_NO_DATABASE)),
216                 *this,
217                 1
218             );
219 
220         Reference< XStorable > xDocStor( m_xDocument, UNO_QUERY_THROW );
221         if ( xDocStor->isReadonly() )
222             throw IllegalArgumentException(
223                 String(MacroMigrationResId(STR_NOT_READONLY)),
224                 *this,
225                 1
226             );
227 
228         m_bInitialized = true;
229     }
230 
231     //--------------------------------------------------------------------
getPropertySetInfo()232 	Reference< XPropertySetInfo > SAL_CALL MacroMigrationDialogService::getPropertySetInfo() throw(RuntimeException)
233     {
234 	    return createPropertySetInfo( getInfoHelper() );
235     }
236 
237     //--------------------------------------------------------------------
getInfoHelper()238 	::cppu::IPropertyArrayHelper& SAL_CALL MacroMigrationDialogService::getInfoHelper()
239     {
240     	return *const_cast< MacroMigrationDialogService* >( this )->getArrayHelper();
241     }
242 
243     //--------------------------------------------------------------------
createArrayHelper() const244 	::cppu::IPropertyArrayHelper* MacroMigrationDialogService::createArrayHelper( ) const
245     {
246 	    Sequence< Property > aProps;
247 	    describeProperties( aProps );
248 	    return new ::cppu::OPropertyArrayHelper( aProps );
249     }
250 
251     //--------------------------------------------------------------------
createRegistryInfo_MacroMigrationDialogService()252     void createRegistryInfo_MacroMigrationDialogService()
253     {
254         static OAutoRegistration< MacroMigrationDialogService > aAutoRegistration;
255     }
256 
257 //........................................................................
258 } // namespace dbmm
259 //........................................................................
260