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 "adminpages.hxx"
21 #include "DbAdminImpl.hxx"
22 #include "dbu_dlg.hrc"
23 #include "DriverSettings.hxx"
24 #include "dsitems.hxx"
25 #include "propertysetitem.hxx"
26 #include "UITools.hxx"
27 #include "UserAdmin.hxx"
28 #include "UserAdminDlg.hxx"
30 #include <comphelper/processfactory.hxx>
31 #include <connectivity/dbmetadata.hxx>
32 #include <cppuhelper/exc_hlp.hxx>
33 #include <svl/eitem.hxx>
34 #include <svl/intitem.hxx>
35 #include <svl/stritem.hxx>
36 #include <tools/diagnose_ex.h>
37 #include <vcl/msgbox.hxx>
38 #include <vcl/stdtext.hxx>
42 using namespace ::com::sun::star::uno
;
43 using namespace ::com::sun::star::beans
;
44 using namespace ::com::sun::star::lang
;
45 using namespace ::com::sun::star::sdbc
;
46 using namespace ::com::sun::star::sdbcx
;
49 OUserAdminDlg::OUserAdminDlg(vcl::Window
* _pParent
51 ,const Reference
< XComponentContext
>& _rxORB
52 ,const ::com::sun::star::uno::Any
& _aDataSourceName
53 ,const Reference
< XConnection
>& _xConnection
)
54 : SfxTabDialog(_pParent
, "UserAdminDialog", "dbaccess/ui/useradmindialog.ui", _pItems
)
56 , m_xConnection(_xConnection
)
57 , m_bOwnConnection(!_xConnection
.is())
59 m_pImpl
.reset(new ODbDataSourceAdministrationHelper(_rxORB
,_pParent
,this));
60 m_pImpl
->setDataSourceOrName(_aDataSourceName
);
61 Reference
< XPropertySet
> xDatasource
= m_pImpl
->getCurrentDataSource();
62 m_pImpl
->translateProperties(xDatasource
, *_pItems
);
64 // propagate this set as our new input set and reset the example set
66 pExampleSet
= new SfxItemSet(*GetInputSetImpl());
68 AddTabPage("settings", OUserAdmin::Create
, 0);
70 // remove the reset button - it's meaning is much too ambiguous in this dialog
74 OUserAdminDlg::~OUserAdminDlg()
79 void OUserAdminDlg::dispose()
81 if ( m_bOwnConnection
)
85 ::comphelper::disposeComponent(m_xConnection
);
87 catch(const Exception
&)
94 SfxTabDialog::dispose();
97 short OUserAdminDlg::Execute()
101 ::dbtools::DatabaseMetaData
aMetaData( createConnection().first
);
102 if ( !aMetaData
.supportsUserAdministration( getORB() ) )
104 OUString
sError(ModuleRes(STR_USERADMIN_NOT_AVAILABLE
));
105 throw SQLException(sError
,NULL
,OUString("S1000") ,0,Any());
108 catch(const SQLException
&)
110 ::dbaui::showError( ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() ), GetParent(), getORB() );
113 catch(const Exception
&)
115 DBG_UNHANDLED_EXCEPTION();
117 short nRet
= SfxTabDialog::Execute();
118 if ( nRet
== RET_OK
)
119 m_pImpl
->saveChanges(*GetOutputItemSet());
122 void OUserAdminDlg::PageCreated(sal_uInt16 _nId
, SfxTabPage
& _rPage
)
124 // register ourself as modified listener
125 static_cast<OGenericAdministrationPage
&>(_rPage
).SetServiceFactory( m_pImpl
->getORB() );
126 static_cast<OGenericAdministrationPage
&>(_rPage
).SetAdminDialog(this,this);
128 vcl::Window
*pWin
= GetViewWindow();
132 SfxTabDialog::PageCreated(_nId
, _rPage
);
134 const SfxItemSet
* OUserAdminDlg::getOutputSet() const
138 SfxItemSet
* OUserAdminDlg::getWriteOutputSet()
142 ::std::pair
< Reference
<XConnection
>,sal_Bool
> OUserAdminDlg::createConnection()
144 if ( !m_xConnection
.is() )
146 m_xConnection
= m_pImpl
->createConnection().first
;
147 m_bOwnConnection
= m_xConnection
.is();
149 return ::std::pair
< Reference
<XConnection
>,sal_Bool
> (m_xConnection
,sal_False
);
151 Reference
< XComponentContext
> OUserAdminDlg::getORB() const
153 return m_pImpl
->getORB();
155 Reference
< XDriver
> OUserAdminDlg::getDriver()
157 return m_pImpl
->getDriver();
159 OUString
OUserAdminDlg::getDatasourceType(const SfxItemSet
& _rSet
) const
161 return dbaui::ODbDataSourceAdministrationHelper::getDatasourceType(_rSet
);
163 void OUserAdminDlg::clearPassword()
165 m_pImpl
->clearPassword();
167 void OUserAdminDlg::setTitle(const OUString
& _sTitle
)
171 void OUserAdminDlg::enableConfirmSettings( bool _bEnable
)
175 bool OUserAdminDlg::saveDatasource()
177 return PrepareLeaveCurrentPage();
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */