1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_extensions.hxx" 30 #include "admininvokationimpl.hxx" 31 #include <tools/debug.hxx> 32 #include <com/sun/star/beans/PropertyValue.hpp> 33 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> 34 #include <com/sun/star/awt/XWindow.hpp> 35 #include <vcl/stdtext.hxx> 36 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_ 37 #include <toolkit/unohlp.hxx> 38 #endif 39 #ifndef EXTENSIONS_ABPRESID_HRC 40 #include "abpresid.hrc" 41 #endif 42 #include "componentmodule.hxx" 43 #include <vcl/waitobj.hxx> 44 45 46 //......................................................................... 47 namespace abp 48 { 49 //......................................................................... 50 51 using namespace ::com::sun::star::uno; 52 using namespace ::com::sun::star::lang; 53 using namespace ::com::sun::star::beans; 54 using namespace ::com::sun::star::awt; 55 using namespace ::com::sun::star::ui::dialogs; 56 57 //===================================================================== 58 //= OAdminDialogInvokation 59 //===================================================================== 60 //--------------------------------------------------------------------- 61 OAdminDialogInvokation::OAdminDialogInvokation(const Reference< XMultiServiceFactory >& _rxORB 62 , const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > _xDataSource 63 , Window* _pMessageParent) 64 :m_xORB(_rxORB) 65 ,m_xDataSource(_xDataSource) 66 ,m_pMessageParent(_pMessageParent) 67 { 68 DBG_ASSERT(m_xORB.is(), "OAdminDialogInvokation::OAdminDialogInvokation: invalid service factory!"); 69 DBG_ASSERT(m_xDataSource.is(), "OAdminDialogInvokation::OAdminDialogInvokation: invalid preferred name!"); 70 DBG_ASSERT(m_pMessageParent, "OAdminDialogInvokation::OAdminDialogInvokation: invalid message parent!"); 71 } 72 73 //--------------------------------------------------------------------- 74 sal_Bool OAdminDialogInvokation::invokeAdministration( sal_Bool _bFixedType ) 75 { 76 if (!m_xORB.is()) 77 return sal_False; 78 79 try 80 { 81 // the service name of the administration dialog 82 const static ::rtl::OUString s_sAdministrationServiceName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.DatasourceAdministrationDialog")); 83 const static ::rtl::OUString s_sDataSourceTypeChangeDialog = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.DataSourceTypeChangeDialog")); 84 85 // the parameters for the call 86 Sequence< Any > aArguments(3); 87 Any* pArguments = aArguments.getArray(); 88 89 // the parent window 90 Reference< XWindow > xDialogParent = VCLUnoHelper::GetInterface(m_pMessageParent); 91 *pArguments++ <<= PropertyValue(::rtl::OUString::createFromAscii("ParentWindow"), -1, makeAny(xDialogParent), PropertyState_DIRECT_VALUE); 92 93 // the title of the dialog 94 String sAdminDialogTitle(ModuleRes(RID_STR_ADMINDIALOGTITLE)); 95 *pArguments++ <<= PropertyValue(::rtl::OUString::createFromAscii("Title"), -1, makeAny(::rtl::OUString(sAdminDialogTitle)), PropertyState_DIRECT_VALUE); 96 97 // the name of the new data source 98 *pArguments++ <<= PropertyValue(::rtl::OUString::createFromAscii("InitialSelection"), -1, makeAny(m_xDataSource), PropertyState_DIRECT_VALUE); 99 100 // create the dialog 101 Reference< XExecutableDialog > xDialog; 102 { 103 // creating the dialog service is potentially expensive (if all the libraries invoked need to be loaded) 104 // so we display a wait cursor 105 WaitObject aWaitCursor(m_pMessageParent); 106 xDialog = Reference< XExecutableDialog >( m_xORB->createInstanceWithArguments( _bFixedType ? s_sAdministrationServiceName : s_sDataSourceTypeChangeDialog, aArguments ), UNO_QUERY ); 107 108 // just for a smoother UI: What the dialog does upon execution, is (amongst other things) creating 109 // the DriverManager service 110 // If this context has never been accessed before, this may be expensive (it includes loading of 111 // at least one library). 112 // As this wizard is intended to run on the first office start, it is very likely that the 113 // context needs to be freshly created 114 // Thus, we access the context here (within the WaitCursor), which means the user sees a waitcursor 115 // while his/her office blocks a few seconds .... 116 m_xORB->createInstance( ::rtl::OUString::createFromAscii( "com.sun.star.sdbc.DriverManager" ) ); 117 } 118 119 if (xDialog.is()) 120 { // execute it 121 if (xDialog->execute()) 122 return sal_True; 123 } 124 else 125 ShowServiceNotAvailableError(m_pMessageParent, s_sAdministrationServiceName, sal_True); 126 } 127 catch(const Exception&) 128 { 129 DBG_ERROR("OAdminDialogInvokation::invokeAdministration: caught an exception while executing the dialog!"); 130 } 131 return sal_False; 132 } 133 134 //......................................................................... 135 } // namespace abp 136 //......................................................................... 137 138