LibreOffice Module extensions (master) 1
admininvokationimpl.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
22#include <tools/debug.hxx>
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>
27#include <strings.hrc>
28#include <componentmodule.hxx>
29#include <utility>
30#include <vcl/stdtext.hxx>
31#include <vcl/weld.hxx>
32
33namespace abp
34{
35
36
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;
43
44 OAdminDialogInvokation::OAdminDialogInvokation(const Reference< XComponentContext >& _rxContext,
45 css::uno::Reference< css::beans::XPropertySet > _xDataSource,
46 weld::Window* _pMessageParent)
47 :m_xContext(_rxContext)
48 ,m_xDataSource(std::move(_xDataSource))
49 ,m_pMessageParent(_pMessageParent)
50 {
51 DBG_ASSERT(m_xContext.is(), "OAdminDialogInvokation::OAdminDialogInvokation: invalid service factory!");
52 DBG_ASSERT(m_xDataSource.is(), "OAdminDialogInvokation::OAdminDialogInvokation: invalid preferred name!");
53 assert(m_pMessageParent && "OAdminDialogInvokation::OAdminDialogInvokation: invalid message parent!");
54 }
55
56
58 {
59 if (!m_xContext.is())
60 return false;
61
62 try
63 {
64 // the service name of the administration dialog
65 static const char16_t s_sAdministrationServiceName[] = u"com.sun.star.sdb.DatasourceAdministrationDialog";
66 static constexpr OUStringLiteral s_sDataSourceTypeChangeDialog = u"com.sun.star.sdb.DataSourceTypeChangeDialog";
67
68 // the parameters for the call
70 {
71 {"ParentWindow", Any(m_pMessageParent->GetXWindow())},
72 {"Title", Any(compmodule::ModuleRes(RID_STR_ADMINDIALOGTITLE))},
73 {"InitialSelection", Any(m_xDataSource)}, // the name of the new data source
74 }));
75
76
77 // create the dialog
78 Reference< XExecutableDialog > xDialog;
79 {
80 // creating the dialog service is potentially expensive (if all the libraries invoked need to be loaded)
81 // so we display a wait cursor
83 Reference<XInterface> x = m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(s_sDataSourceTypeChangeDialog, aArguments, m_xContext);
84 xDialog.set( x, UNO_QUERY );
85
86 // just for a smoother UI: What the dialog does upon execution, is (amongst other things) creating
87 // the DriverManager service
88 // If this context has never been accessed before, this may be expensive (it includes loading of
89 // at least one library).
90 // As this wizard is intended to run on the first office start, it is very likely that the
91 // context needs to be freshly created
92 // Thus, we access the context here (within the WaitCursor), which means the user sees a waitcursor
93 // while his/her office blocks a few seconds...
94 DriverManager::create( m_xContext );
95 }
96
97 if (xDialog.is())
98 { // execute it
99 if (xDialog->execute())
100 return true;
101 }
102 else
103 ShowServiceNotAvailableError(m_pMessageParent, s_sAdministrationServiceName, true);
104 }
105 catch(const Exception&)
106 {
107 TOOLS_WARN_EXCEPTION("extensions.abpilot",
108 "caught an exception while executing the dialog!");
109 }
110 return false;
111 }
112
113
114} // namespace abp
115
116
117/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OAdminDialogInvokation(const css::uno::Reference< css::uno::XComponentContext > &_rxContext, css::uno::Reference< css::beans::XPropertySet > _xDataSource, weld::Window *_pMessageParent)
css::uno::Reference< css::beans::XPropertySet > m_xDataSource
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual css::uno::Reference< css::awt::XWindow > GetXWindow()=0
Reference< XDataSource > m_xDataSource
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
float u
float x
Reference< XComponentContext > m_xContext
Definition: filehandler.cxx:78
Sequence< PropertyValue > aArguments
@ Exception
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
OUString ModuleRes(TranslateId pId)
void VCL_DLLPUBLIC ShowServiceNotAvailableError(weld::Widget *pParent, std::u16string_view rServiceName, bool bError)