LibreOffice Module dbaccess (master) 1
UserAdminDlg.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
20#include <core_resource.hxx>
21#include "adminpages.hxx"
22#include "DbAdminImpl.hxx"
23#include <strings.hrc>
24#include "UserAdmin.hxx"
25#include <UserAdminDlg.hxx>
26
27#include <com/sun/star/sdbc/SQLException.hpp>
28
32#include <comphelper/types.hxx>
35
36namespace dbaui
37{
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::lang;
41 using namespace ::com::sun::star::sdbc;
42 using namespace ::com::sun::star::sdbcx;
43
44 // OUserAdminDlg
46 SfxItemSet* pItems,
48 const css::uno::Any& rDataSourceName,
49 const Reference< XConnection >& xConnection)
50 : SfxTabDialogController(pParent, "dbaccess/ui/useradmindialog.ui", "UserAdminDialog", pItems)
51 , m_pParent(pParent)
52 , m_pItemSet(pItems)
53 , m_xConnection(xConnection)
54 , m_bOwnConnection(!xConnection.is())
55 {
56 m_pImpl.reset(new ODbDataSourceAdministrationHelper(rxORB, m_xDialog.get(), pParent, this));
57 m_pImpl->setDataSourceOrName(rDataSourceName);
58 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
59 m_pImpl->translateProperties(xDatasource, *pItems);
60 SetInputSet(pItems);
61 // propagate this set as our new input set and reset the example set
63
64 AddTabPage("settings", OUserAdmin::Create, nullptr);
65
66 // remove the reset button - it's meaning is much too ambiguous in this dialog
68 }
69
71 {
72 if ( m_bOwnConnection )
73 {
74 try
75 {
76 ::comphelper::disposeComponent(m_xConnection);
77 }
78 catch(const Exception&)
79 {
80 }
81 }
82
83 SetInputSet(nullptr);
84 }
85
87 {
88 try
89 {
91 if ( !aMetaData.supportsUserAdministration( getORB() ) )
92 {
93 OUString sError(DBA_RES(STR_USERADMIN_NOT_AVAILABLE));
94 throw SQLException(sError, nullptr, "S1000", 0, Any());
95 }
96 }
97 catch(const SQLException&)
98 {
99 ::dbtools::showError(::dbtools::SQLExceptionInfo(::cppu::getCaughtException()), m_pParent->GetXWindow(), getORB());
100 return RET_CANCEL;
101 }
102 catch(const Exception&)
103 {
104 DBG_UNHANDLED_EXCEPTION("dbaccess");
105 }
106 short nRet = SfxTabDialogController::run();
107 if ( nRet == RET_OK )
108 m_pImpl->saveChanges(*GetOutputItemSet());
109 return nRet;
110 }
111 void OUserAdminDlg::PageCreated(const OUString& rId, SfxTabPage& _rPage)
112 {
113 // register ourself as modified listener
114 static_cast<OGenericAdministrationPage&>(_rPage).SetServiceFactory( m_pImpl->getORB() );
115 static_cast<OGenericAdministrationPage&>(_rPage).SetAdminDialog(this,this);
117 }
119 {
120 return m_pItemSet;
121 }
123 {
124 return m_pItemSet;
125 }
126 std::pair< Reference<XConnection>,bool> OUserAdminDlg::createConnection()
127 {
128 if ( !m_xConnection.is() )
129 {
130 m_xConnection = m_pImpl->createConnection().first;
132 }
133 return std::pair< Reference<XConnection>,bool> (m_xConnection,false);
134 }
136 {
137 return m_pImpl->getORB();
138 }
140 {
141 return m_pImpl->getDriver();
142 }
143 OUString OUserAdminDlg::getDatasourceType(const SfxItemSet& _rSet) const
144 {
146 }
148 {
149 m_pImpl->clearPassword();
150 }
151 void OUserAdminDlg::setTitle(const OUString& _sTitle)
152 {
153 m_xDialog->set_title(_sTitle);
154 }
157 {
159 }
160} // namespace dbaui
161
162/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
void AddTabPage(const OUString &rName, CreateTabPage pCreateFunc, GetTabPageRanges pRangesFunc)
void SetInputSet(const SfxItemSet *pInSet)
virtual short run() override
std::unique_ptr< SfxItemSet > m_xExampleSet
virtual void PageCreated(const OUString &rName, SfxTabPage &rPage)
const SfxItemSet * GetOutputItemSet() const
SfxItemSet * GetInputSetImpl()
static OUString getDatasourceType(const SfxItemSet &_rSet)
extracts the connection type from the given setThe connection type is determined by the value of the ...
OUserAdminDlg(weld::Window *pParent, SfxItemSet *pItems, const css::uno::Reference< css::uno::XComponentContext > &rxORB, const css::uno::Any &rDataSourceName, const css::uno::Reference< css::sdbc::XConnection > &rConnection)
virtual css::uno::Reference< css::uno::XComponentContext > getORB() const override
virtual void PageCreated(const OUString &rId, SfxTabPage &_rPage) override
virtual short run() override
virtual SfxItemSet * getWriteOutputSet() override
virtual void saveDatasource() override
virtual ~OUserAdminDlg() override
virtual std::pair< css::uno::Reference< css::sdbc::XConnection >, bool > createConnection() override
css::uno::Reference< css::sdbc::XConnection > m_xConnection
virtual void setTitle(const OUString &_sTitle) override
virtual OUString getDatasourceType(const SfxItemSet &_rSet) const override
virtual const SfxItemSet * getOutputSet() const override
virtual css::uno::Reference< css::sdbc::XDriver > getDriver() override
virtual void enableConfirmSettings(bool _bEnable) override
enables or disables the user's possibility to confirm the settings
weld::Window * m_pParent
virtual void clearPassword() override
SfxItemSet * m_pItemSet
std::unique_ptr< ODbDataSourceAdministrationHelper > m_pImpl
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rAttrSet)
Definition: UserAdmin.cxx:255
bool supportsUserAdministration(const css::uno::Reference< css::uno::XComponentContext > &_rContext) const
virtual css::uno::Reference< css::awt::XWindow > GetXWindow()=0
#define DBA_RES(id)
#define DBG_UNHANDLED_EXCEPTION(...)
@ Exception
constexpr OUStringLiteral first
Reference< XConnection > m_xConnection
Definition: objectnames.cxx:79
RET_OK
RET_CANCEL