Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / extensions / source / abpilot / admininvokationimpl.cxx
blob71c459a7b5dbd387a87fa834ad6638f70e363828
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 "admininvokationimpl.hxx"
21 #include <tools/debug.hxx>
22 #include <com/sun/star/beans/PropertyValue.hpp>
23 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
24 #include <com/sun/star/awt/XWindow.hpp>
25 #include <com/sun/star/sdbc/DriverManager.hpp>
26 #include <vcl/stdtext.hxx>
27 #include <toolkit/helper/vclunohelper.hxx>
28 #include "abpresid.hrc"
29 #include "componentmodule.hxx"
30 #include <vcl/waitobj.hxx>
33 namespace abp
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::awt;
41 using namespace ::com::sun::star::ui::dialogs;
42 using namespace ::com::sun::star::sdbc;
44 OAdminDialogInvokation::OAdminDialogInvokation(const Reference< XComponentContext >& _rxContext,
45 const css::uno::Reference< css::beans::XPropertySet >& _rxDataSource
46 , vcl::Window* _pMessageParent)
47 :m_xContext(_rxContext)
48 ,m_xDataSource(_rxDataSource)
49 ,m_pMessageParent(_pMessageParent)
51 DBG_ASSERT(m_xContext.is(), "OAdminDialogInvokation::OAdminDialogInvokation: invalid service factory!");
52 DBG_ASSERT(m_xDataSource.is(), "OAdminDialogInvokation::OAdminDialogInvokation: invalid preferred name!");
53 DBG_ASSERT(m_pMessageParent, "OAdminDialogInvokation::OAdminDialogInvokation: invalid message parent!");
57 bool OAdminDialogInvokation::invokeAdministration()
59 if (!m_xContext.is())
60 return false;
62 try
64 // the service name of the administration dialog
65 static const char s_sAdministrationServiceName[] = "com.sun.star.sdb.DatasourceAdministrationDialog";
66 static const char s_sDataSourceTypeChangeDialog[] = "com.sun.star.sdb.DataSourceTypeChangeDialog";
68 // the parameters for the call
69 Sequence< Any > aArguments(3);
70 Any* pArguments = aArguments.getArray();
72 // the parent window
73 Reference< XWindow > xDialogParent = VCLUnoHelper::GetInterface(m_pMessageParent);
74 *pArguments++ <<= PropertyValue("ParentWindow", -1, makeAny(xDialogParent), PropertyState_DIRECT_VALUE);
76 // the title of the dialog
77 OUString sAdminDialogTitle(ModuleRes(RID_STR_ADMINDIALOGTITLE));
78 *pArguments++ <<= PropertyValue("Title", -1, makeAny(sAdminDialogTitle), PropertyState_DIRECT_VALUE);
80 // the name of the new data source
81 *pArguments++ <<= PropertyValue("InitialSelection", -1, makeAny(m_xDataSource), PropertyState_DIRECT_VALUE);
83 // create the dialog
84 Reference< XExecutableDialog > xDialog;
86 // creating the dialog service is potentially expensive (if all the libraries invoked need to be loaded)
87 // so we display a wait cursor
88 WaitObject aWaitCursor(m_pMessageParent);
89 Reference<XInterface> x = m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(s_sDataSourceTypeChangeDialog, aArguments, m_xContext);
90 xDialog.set( x, UNO_QUERY );
92 // just for a smoother UI: What the dialog does upon execution, is (amongst other things) creating
93 // the DriverManager service
94 // If this context has never been accessed before, this may be expensive (it includes loading of
95 // at least one library).
96 // As this wizard is intended to run on the first office start, it is very likely that the
97 // context needs to be freshly created
98 // Thus, we access the context here (within the WaitCursor), which means the user sees a waitcursor
99 // while his/her office blocks a few seconds ....
100 DriverManager::create( m_xContext );
103 if (xDialog.is())
104 { // execute it
105 if (xDialog->execute())
106 return true;
108 else
109 ShowServiceNotAvailableError(m_pMessageParent, s_sAdministrationServiceName, true);
111 catch(const Exception&)
113 OSL_FAIL("OAdminDialogInvokation::invokeAdministration: caught an exception while executing the dialog!");
115 return false;
119 } // namespace abp
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */