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 <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 <comphelper/propertysequence.hxx>
27 #include <vcl/stdtext.hxx>
28 #include <toolkit/helper/vclunohelper.hxx>
29 #include <strings.hrc>
30 #include <componentmodule.hxx>
31 #include <vcl/weld.hxx>
32 #include <vcl/waitobj.hxx>
33 #include <osl/diagnose.h>
40 using namespace ::com::sun::star::uno
;
41 using namespace ::com::sun::star::lang
;
42 using namespace ::com::sun::star::beans
;
43 using namespace ::com::sun::star::awt
;
44 using namespace ::com::sun::star::ui::dialogs
;
45 using namespace ::com::sun::star::sdbc
;
47 OAdminDialogInvokation::OAdminDialogInvokation(const Reference
< XComponentContext
>& _rxContext
,
48 const css::uno::Reference
< css::beans::XPropertySet
>& _rxDataSource
49 , vcl::Window
* _pMessageParent
)
50 :m_xContext(_rxContext
)
51 ,m_xDataSource(_rxDataSource
)
52 ,m_pMessageParent(_pMessageParent
)
54 DBG_ASSERT(m_xContext
.is(), "OAdminDialogInvokation::OAdminDialogInvokation: invalid service factory!");
55 DBG_ASSERT(m_xDataSource
.is(), "OAdminDialogInvokation::OAdminDialogInvokation: invalid preferred name!");
56 assert(m_pMessageParent
&& "OAdminDialogInvokation::OAdminDialogInvokation: invalid message parent!");
60 bool OAdminDialogInvokation::invokeAdministration()
67 // the service name of the administration dialog
68 static const char s_sAdministrationServiceName
[] = "com.sun.star.sdb.DatasourceAdministrationDialog";
69 static const char s_sDataSourceTypeChangeDialog
[] = "com.sun.star.sdb.DataSourceTypeChangeDialog";
71 // the parameters for the call
72 Sequence
<Any
> aArguments(comphelper::InitAnyPropertySequence(
74 {"ParentWindow", Any(VCLUnoHelper::GetInterface(m_pMessageParent
))},
75 {"Title", Any(compmodule::ModuleRes(RID_STR_ADMINDIALOGTITLE
))},
76 {"InitialSelection", Any(m_xDataSource
)}, // the name of the new data source
81 Reference
< XExecutableDialog
> xDialog
;
83 // creating the dialog service is potentially expensive (if all the libraries invoked need to be loaded)
84 // so we display a wait cursor
85 WaitObject
aWaitCursor(m_pMessageParent
);
86 Reference
<XInterface
> x
= m_xContext
->getServiceManager()->createInstanceWithArgumentsAndContext(s_sDataSourceTypeChangeDialog
, aArguments
, m_xContext
);
87 xDialog
.set( x
, UNO_QUERY
);
89 // just for a smoother UI: What the dialog does upon execution, is (amongst other things) creating
90 // the DriverManager service
91 // If this context has never been accessed before, this may be expensive (it includes loading of
92 // at least one library).
93 // As this wizard is intended to run on the first office start, it is very likely that the
94 // context needs to be freshly created
95 // Thus, we access the context here (within the WaitCursor), which means the user sees a waitcursor
96 // while his/her office blocks a few seconds ....
97 DriverManager::create( m_xContext
);
102 if (xDialog
->execute())
106 ShowServiceNotAvailableError(m_pMessageParent
->GetFrameWeld(), s_sAdministrationServiceName
, true);
108 catch(const Exception
&)
110 OSL_FAIL("OAdminDialogInvokation::invokeAdministration: caught an exception while executing the dialog!");
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */