Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / dbaccess / source / ui / dlg / UserAdminDlg.cxx
bloba70db89f7c490a058d5b95ccf030fb857a45f3b3
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 <core_resource.hxx>
21 #include "adminpages.hxx"
22 #include "DbAdminImpl.hxx"
23 #include <strings.hrc>
24 #include "UserAdmin.hxx"
25 #include <UserAdminDlg.hxx>
27 #include <com/sun/star/sdbc/SQLException.hpp>
29 #include <connectivity/dbexception.hxx>
30 #include <connectivity/dbmetadata.hxx>
31 #include <connectivity/dbtools.hxx>
32 #include <comphelper/types.hxx>
33 #include <cppuhelper/exc_hlp.hxx>
34 #include <comphelper/diagnose_ex.hxx>
36 namespace dbaui
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::beans;
40 using namespace ::com::sun::star::sdbc;
42 // OUserAdminDlg
43 OUserAdminDlg::OUserAdminDlg(weld::Window* pParent,
44 SfxItemSet* pItems,
45 const Reference< XComponentContext >& rxORB,
46 const css::uno::Any& rDataSourceName,
47 const Reference< XConnection >& xConnection)
48 : SfxTabDialogController(pParent, u"dbaccess/ui/useradmindialog.ui"_ustr, u"UserAdminDialog"_ustr, pItems)
49 , m_pParent(pParent)
50 , m_pItemSet(pItems)
51 , m_xConnection(xConnection)
52 , m_bOwnConnection(!xConnection.is())
54 m_pImpl.reset(new ODbDataSourceAdministrationHelper(rxORB, m_xDialog.get(), pParent, this));
55 m_pImpl->setDataSourceOrName(rDataSourceName);
56 Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
57 m_pImpl->translateProperties(xDatasource, *pItems);
58 SetInputSet(pItems);
59 // propagate this set as our new input set and reset the example set
60 m_xExampleSet.reset(new SfxItemSet(*GetInputSetImpl()));
62 AddTabPage(u"settings"_ustr, OUserAdmin::Create, nullptr);
64 // remove the reset button - it's meaning is much too ambiguous in this dialog
65 RemoveResetButton();
68 OUserAdminDlg::~OUserAdminDlg()
70 if ( m_bOwnConnection )
72 try
74 ::comphelper::disposeComponent(m_xConnection);
76 catch(const Exception&)
81 SetInputSet(nullptr);
84 short OUserAdminDlg::run()
86 try
88 ::dbtools::DatabaseMetaData aMetaData( createConnection().first );
89 if ( !aMetaData.supportsUserAdministration( getORB() ) )
91 OUString sError(DBA_RES(STR_USERADMIN_NOT_AVAILABLE));
92 throw SQLException(sError, nullptr, u"S1000"_ustr, 0, Any());
95 catch(const SQLException&)
97 ::dbtools::showError(::dbtools::SQLExceptionInfo(::cppu::getCaughtException()), m_pParent->GetXWindow(), getORB());
98 return RET_CANCEL;
100 catch(const Exception&)
102 DBG_UNHANDLED_EXCEPTION("dbaccess");
104 short nRet = SfxTabDialogController::run();
105 if ( nRet == RET_OK )
106 m_pImpl->saveChanges(*GetOutputItemSet());
107 return nRet;
109 void OUserAdminDlg::PageCreated(const OUString& rId, SfxTabPage& _rPage)
111 // register ourself as modified listener
112 static_cast<OGenericAdministrationPage&>(_rPage).SetServiceFactory( m_pImpl->getORB() );
113 static_cast<OGenericAdministrationPage&>(_rPage).SetAdminDialog(this,this);
114 SfxTabDialogController::PageCreated(rId, _rPage);
116 const SfxItemSet* OUserAdminDlg::getOutputSet() const
118 return m_pItemSet;
120 SfxItemSet* OUserAdminDlg::getWriteOutputSet()
122 return m_pItemSet;
124 std::pair< Reference<XConnection>,bool> OUserAdminDlg::createConnection()
126 if ( !m_xConnection.is() )
128 m_xConnection = m_pImpl->createConnection().first;
129 m_bOwnConnection = m_xConnection.is();
131 return std::pair< Reference<XConnection>,bool> (m_xConnection,false);
133 Reference< XComponentContext > OUserAdminDlg::getORB() const
135 return m_pImpl->getORB();
137 Reference< XDriver > OUserAdminDlg::getDriver()
139 return m_pImpl->getDriver();
141 OUString OUserAdminDlg::getDatasourceType(const SfxItemSet& _rSet) const
143 return dbaui::ODbDataSourceAdministrationHelper::getDatasourceType(_rSet);
145 void OUserAdminDlg::clearPassword()
147 m_pImpl->clearPassword();
149 void OUserAdminDlg::setTitle(const OUString& _sTitle)
151 m_xDialog->set_title(_sTitle);
153 void OUserAdminDlg::enableConfirmSettings( bool ) {}
154 void OUserAdminDlg::saveDatasource()
156 PrepareLeaveCurrentPage();
158 } // namespace dbaui
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */