1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <comphelper/diagnose_ex.hxx>
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>
26 #include <comphelper/propertysequence.hxx>
27 #include <strings.hrc>
28 #include <componentmodule.hxx>
30 #include <vcl/stdtext.hxx>
31 #include <vcl/weld.hxx>
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 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
)
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!");
57 bool OAdminDialogInvokation::invokeAdministration()
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";
68 // the parameters for the call
69 Sequence
<Any
> aArguments(comphelper::InitAnyPropertySequence(
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
78 Reference
< XExecutableDialog
> xDialog
;
80 // creating the dialog service is potentially expensive (if all the libraries invoked need to be loaded)
81 // so we display a wait cursor
82 weld::WaitObject
aWaitCursor(m_pMessageParent
);
83 Reference
<XInterface
> x
= m_xContext
->getServiceManager()->createInstanceWithArgumentsAndContext(s_sDataSourceTypeChangeDialog
, aArguments
, m_xContext
);
84 xDialog
.set( x
, UNO_QUERY
);
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
);
99 if (xDialog
->execute())
103 ShowServiceNotAvailableError(m_pMessageParent
, s_sAdministrationServiceName
, true);
105 catch(const Exception
&)
107 TOOLS_WARN_EXCEPTION("extensions.abpilot",
108 "caught an exception while executing the dialog!");
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */