Line data Source code
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 "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"
29 :
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>
39 :
40 : namespace dbaui
41 : {
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;
47 :
48 : // OUserAdminDlg
49 0 : OUserAdminDlg::OUserAdminDlg(Window* _pParent
50 : , SfxItemSet* _pItems
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)
55 : , m_pItemSet(_pItems)
56 : , m_xConnection(_xConnection)
57 0 : , m_bOwnConnection(!_xConnection.is())
58 : {
59 0 : m_pImpl.reset(new ODbDataSourceAdministrationHelper(_rxORB,_pParent,this));
60 0 : m_pImpl->setDataSourceOrName(_aDataSourceName);
61 0 : Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
62 0 : m_pImpl->translateProperties(xDatasource, *_pItems);
63 0 : SetInputSet(_pItems);
64 : // propagate this set as our new input set and reset the example set
65 0 : delete pExampleSet;
66 0 : pExampleSet = new SfxItemSet(*GetInputSetImpl());
67 :
68 0 : AddTabPage("settings", OUserAdmin::Create, 0);
69 :
70 : // remove the reset button - it's meaning is much too ambiguous in this dialog
71 0 : RemoveResetButton();
72 0 : }
73 :
74 0 : OUserAdminDlg::~OUserAdminDlg()
75 : {
76 0 : if ( m_bOwnConnection )
77 : {
78 : try
79 : {
80 0 : ::comphelper::disposeComponent(m_xConnection);
81 : }
82 0 : catch(const Exception&)
83 : {
84 : }
85 : }
86 :
87 0 : SetInputSet(NULL);
88 0 : DELETEZ(pExampleSet);
89 :
90 0 : }
91 0 : short OUserAdminDlg::Execute()
92 : {
93 : try
94 : {
95 0 : ::dbtools::DatabaseMetaData aMetaData( createConnection().first );
96 0 : if ( !aMetaData.supportsUserAdministration( getORB() ) )
97 : {
98 0 : OUString sError(ModuleRes(STR_USERADMIN_NOT_AVAILABLE));
99 0 : throw SQLException(sError,NULL,OUString("S1000") ,0,Any());
100 0 : }
101 : }
102 0 : catch(const SQLException&)
103 : {
104 0 : ::dbaui::showError( ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() ), GetParent(), getORB() );
105 0 : return RET_CANCEL;
106 : }
107 0 : catch(const Exception&)
108 : {
109 : DBG_UNHANDLED_EXCEPTION();
110 : }
111 0 : short nRet = SfxTabDialog::Execute();
112 0 : if ( nRet == RET_OK )
113 0 : m_pImpl->saveChanges(*GetOutputItemSet());
114 0 : return nRet;
115 : }
116 0 : void OUserAdminDlg::PageCreated(sal_uInt16 _nId, SfxTabPage& _rPage)
117 : {
118 : // register ourself as modified listener
119 0 : static_cast<OGenericAdministrationPage&>(_rPage).SetServiceFactory( m_pImpl->getORB() );
120 0 : static_cast<OGenericAdministrationPage&>(_rPage).SetAdminDialog(this,this);
121 :
122 0 : AdjustLayout();
123 0 : Window *pWin = GetViewWindow();
124 0 : if(pWin)
125 0 : pWin->Invalidate();
126 :
127 0 : SfxTabDialog::PageCreated(_nId, _rPage);
128 0 : }
129 0 : const SfxItemSet* OUserAdminDlg::getOutputSet() const
130 : {
131 0 : return m_pItemSet;
132 : }
133 0 : SfxItemSet* OUserAdminDlg::getWriteOutputSet()
134 : {
135 0 : return m_pItemSet;
136 : }
137 0 : ::std::pair< Reference<XConnection>,sal_Bool> OUserAdminDlg::createConnection()
138 : {
139 0 : if ( !m_xConnection.is() )
140 : {
141 0 : m_xConnection = m_pImpl->createConnection().first;
142 0 : m_bOwnConnection = m_xConnection.is();
143 : }
144 0 : return ::std::pair< Reference<XConnection>,sal_Bool> (m_xConnection,sal_False);
145 : }
146 0 : Reference< XComponentContext > OUserAdminDlg::getORB() const
147 : {
148 0 : return m_pImpl->getORB();
149 : }
150 0 : Reference< XDriver > OUserAdminDlg::getDriver()
151 : {
152 0 : return m_pImpl->getDriver();
153 : }
154 0 : OUString OUserAdminDlg::getDatasourceType(const SfxItemSet& _rSet) const
155 : {
156 0 : return m_pImpl->getDatasourceType(_rSet);
157 : }
158 0 : void OUserAdminDlg::clearPassword()
159 : {
160 0 : m_pImpl->clearPassword();
161 0 : }
162 0 : void OUserAdminDlg::setTitle(const OUString& _sTitle)
163 : {
164 0 : SetText(_sTitle);
165 0 : }
166 0 : void OUserAdminDlg::enableConfirmSettings( bool _bEnable )
167 : {
168 : (void)_bEnable;
169 0 : }
170 0 : sal_Bool OUserAdminDlg::saveDatasource()
171 : {
172 0 : return PrepareLeaveCurrentPage();
173 : }
174 0 : } // namespace dbaui
175 :
176 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|