1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "adminpages.hxx"
32*cdf0e10cSrcweir #include "DbAdminImpl.hxx"
33*cdf0e10cSrcweir #include "dbu_dlg.hrc"
34*cdf0e10cSrcweir #include "DriverSettings.hxx"
35*cdf0e10cSrcweir #include "dsitems.hxx"
36*cdf0e10cSrcweir #include "propertysetitem.hxx"
37*cdf0e10cSrcweir #include "UITools.hxx"
38*cdf0e10cSrcweir #include "UserAdmin.hxx"
39*cdf0e10cSrcweir #include "UserAdminDlg.hrc"
40*cdf0e10cSrcweir #include "UserAdminDlg.hxx"
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #include <comphelper/componentcontext.hxx>
43*cdf0e10cSrcweir #include <connectivity/dbmetadata.hxx>
44*cdf0e10cSrcweir #include <cppuhelper/exc_hlp.hxx>
45*cdf0e10cSrcweir #include <svl/eitem.hxx>
46*cdf0e10cSrcweir #include <svl/intitem.hxx>
47*cdf0e10cSrcweir #include <svl/stritem.hxx>
48*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
49*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
50*cdf0e10cSrcweir #include <vcl/stdtext.hxx>
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir //.........................................................................
53*cdf0e10cSrcweir namespace dbaui
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir //.........................................................................
56*cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
57*cdf0e10cSrcweir 	using namespace ::com::sun::star::beans;
58*cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
59*cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbc;
60*cdf0e10cSrcweir 	using namespace ::com::sun::star::sdbcx;
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir 	//========================================================================
63*cdf0e10cSrcweir 	//= OUserAdminDlg
64*cdf0e10cSrcweir DBG_NAME(OUserAdminDlg)
65*cdf0e10cSrcweir //========================================================================
66*cdf0e10cSrcweir 	OUserAdminDlg::OUserAdminDlg(Window* _pParent
67*cdf0e10cSrcweir 											, SfxItemSet* _pItems
68*cdf0e10cSrcweir 											,const Reference< XMultiServiceFactory >& _rxORB
69*cdf0e10cSrcweir 											,const ::com::sun::star::uno::Any& _aDataSourceName
70*cdf0e10cSrcweir 											,const Reference< XConnection >& _xConnection)
71*cdf0e10cSrcweir 		:SfxTabDialog(_pParent, ModuleRes(DLG_DATABASE_USERADMIN), _pItems)
72*cdf0e10cSrcweir 		,m_pItemSet(_pItems)
73*cdf0e10cSrcweir 		,m_xConnection(_xConnection)
74*cdf0e10cSrcweir 		,m_bOwnConnection(!_xConnection.is())
75*cdf0e10cSrcweir 	{
76*cdf0e10cSrcweir         DBG_CTOR(OUserAdminDlg,NULL);
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 		m_pImpl = ::std::auto_ptr<ODbDataSourceAdministrationHelper>(new ODbDataSourceAdministrationHelper(_rxORB,_pParent,this));
79*cdf0e10cSrcweir 		m_pImpl->setDataSourceOrName(_aDataSourceName);
80*cdf0e10cSrcweir 		Reference< XPropertySet > xDatasource = m_pImpl->getCurrentDataSource();
81*cdf0e10cSrcweir 		m_pImpl->translateProperties(xDatasource, *_pItems);
82*cdf0e10cSrcweir 		SetInputSet(_pItems);
83*cdf0e10cSrcweir 		// propagate this set as our new input set and reset the example set
84*cdf0e10cSrcweir 		delete pExampleSet;
85*cdf0e10cSrcweir 		pExampleSet = new SfxItemSet(*GetInputSetImpl());
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 		AddTabPage(TAB_PAGE_USERADMIN, String(ModuleRes(STR_PAGETITLE_USERADMIN)), OUserAdmin::Create,0, sal_False, 1);
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir 		// remove the reset button - it's meaning is much too ambiguous in this dialog
90*cdf0e10cSrcweir 		RemoveResetButton();
91*cdf0e10cSrcweir 		FreeResource();
92*cdf0e10cSrcweir 	}
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir 	// -----------------------------------------------------------------------
95*cdf0e10cSrcweir 	OUserAdminDlg::~OUserAdminDlg()
96*cdf0e10cSrcweir 	{
97*cdf0e10cSrcweir 		if ( m_bOwnConnection )
98*cdf0e10cSrcweir 			try
99*cdf0e10cSrcweir 			{
100*cdf0e10cSrcweir 				::comphelper::disposeComponent(m_xConnection);
101*cdf0e10cSrcweir 			}
102*cdf0e10cSrcweir 			catch(Exception){}
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 		SetInputSet(NULL);
105*cdf0e10cSrcweir 		DELETEZ(pExampleSet);
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir         DBG_DTOR(OUserAdminDlg,NULL);
108*cdf0e10cSrcweir     }
109*cdf0e10cSrcweir 	// -----------------------------------------------------------------------
110*cdf0e10cSrcweir 	short OUserAdminDlg::Execute()
111*cdf0e10cSrcweir 	{
112*cdf0e10cSrcweir 		try
113*cdf0e10cSrcweir 		{
114*cdf0e10cSrcweir             ::dbtools::DatabaseMetaData aMetaData( createConnection().first );
115*cdf0e10cSrcweir             if ( !aMetaData.supportsUserAdministration( ::comphelper::ComponentContext( getORB() ) ) )
116*cdf0e10cSrcweir 			{
117*cdf0e10cSrcweir 				String sError(ModuleRes(STR_USERADMIN_NOT_AVAILABLE));
118*cdf0e10cSrcweir 				throw SQLException(sError,NULL,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("S1000")) ,0,Any());
119*cdf0e10cSrcweir 			}
120*cdf0e10cSrcweir 		}
121*cdf0e10cSrcweir 		catch(const SQLException& e)
122*cdf0e10cSrcweir 		{
123*cdf0e10cSrcweir             ::dbaui::showError( ::dbtools::SQLExceptionInfo( ::cppu::getCaughtException() ), GetParent(), getORB() );
124*cdf0e10cSrcweir 			return RET_CANCEL;
125*cdf0e10cSrcweir 		}
126*cdf0e10cSrcweir         catch( const Exception& )
127*cdf0e10cSrcweir         {
128*cdf0e10cSrcweir             DBG_UNHANDLED_EXCEPTION();
129*cdf0e10cSrcweir         }
130*cdf0e10cSrcweir 		short nRet = SfxTabDialog::Execute();
131*cdf0e10cSrcweir 		if ( nRet == RET_OK )
132*cdf0e10cSrcweir 			m_pImpl->saveChanges(*GetOutputItemSet());
133*cdf0e10cSrcweir 		return nRet;
134*cdf0e10cSrcweir 	}
135*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
136*cdf0e10cSrcweir 	void OUserAdminDlg::PageCreated(sal_uInt16 _nId, SfxTabPage& _rPage)
137*cdf0e10cSrcweir 	{
138*cdf0e10cSrcweir 		// register ourself as modified listener
139*cdf0e10cSrcweir 		static_cast<OGenericAdministrationPage&>(_rPage).SetServiceFactory(m_pImpl->getORB());
140*cdf0e10cSrcweir 		static_cast<OGenericAdministrationPage&>(_rPage).SetAdminDialog(this,this);
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 		AdjustLayout();
143*cdf0e10cSrcweir 		Window *pWin = GetViewWindow();
144*cdf0e10cSrcweir 		if(pWin)
145*cdf0e10cSrcweir 			pWin->Invalidate();
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 		SfxTabDialog::PageCreated(_nId, _rPage);
148*cdf0e10cSrcweir 	}
149*cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
150*cdf0e10cSrcweir 	const SfxItemSet* OUserAdminDlg::getOutputSet() const
151*cdf0e10cSrcweir 	{
152*cdf0e10cSrcweir 		return m_pItemSet;
153*cdf0e10cSrcweir 	}
154*cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
155*cdf0e10cSrcweir 	SfxItemSet* OUserAdminDlg::getWriteOutputSet()
156*cdf0e10cSrcweir 	{
157*cdf0e10cSrcweir 		return m_pItemSet;
158*cdf0e10cSrcweir 	}
159*cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
160*cdf0e10cSrcweir 	::std::pair< Reference<XConnection>,sal_Bool> OUserAdminDlg::createConnection()
161*cdf0e10cSrcweir 	{
162*cdf0e10cSrcweir 		if ( !m_xConnection.is() )
163*cdf0e10cSrcweir 		{
164*cdf0e10cSrcweir 			m_xConnection = m_pImpl->createConnection().first;
165*cdf0e10cSrcweir 			m_bOwnConnection = m_xConnection.is();
166*cdf0e10cSrcweir 		}
167*cdf0e10cSrcweir 		return ::std::pair< Reference<XConnection>,sal_Bool> (m_xConnection,sal_False);
168*cdf0e10cSrcweir 	}
169*cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
170*cdf0e10cSrcweir 	Reference< XMultiServiceFactory > OUserAdminDlg::getORB() const
171*cdf0e10cSrcweir 	{
172*cdf0e10cSrcweir 		return m_pImpl->getORB();
173*cdf0e10cSrcweir 	}
174*cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
175*cdf0e10cSrcweir 	Reference< XDriver > OUserAdminDlg::getDriver()
176*cdf0e10cSrcweir 	{
177*cdf0e10cSrcweir 		return m_pImpl->getDriver();
178*cdf0e10cSrcweir 	}
179*cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
180*cdf0e10cSrcweir 	::rtl::OUString	OUserAdminDlg::getDatasourceType(const SfxItemSet& _rSet) const
181*cdf0e10cSrcweir 	{
182*cdf0e10cSrcweir 		return m_pImpl->getDatasourceType(_rSet);
183*cdf0e10cSrcweir 	}
184*cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
185*cdf0e10cSrcweir 	void OUserAdminDlg::clearPassword()
186*cdf0e10cSrcweir 	{
187*cdf0e10cSrcweir 		m_pImpl->clearPassword();
188*cdf0e10cSrcweir 	}
189*cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
190*cdf0e10cSrcweir 	void OUserAdminDlg::setTitle(const ::rtl::OUString& _sTitle)
191*cdf0e10cSrcweir 	{
192*cdf0e10cSrcweir 		SetText(_sTitle);
193*cdf0e10cSrcweir 	}
194*cdf0e10cSrcweir     //-------------------------------------------------------------------------
195*cdf0e10cSrcweir     void OUserAdminDlg::enableConfirmSettings( bool _bEnable )
196*cdf0e10cSrcweir     {
197*cdf0e10cSrcweir         (void)_bEnable;
198*cdf0e10cSrcweir     }
199*cdf0e10cSrcweir 	//-------------------------------------------------------------------------
200*cdf0e10cSrcweir 	sal_Bool OUserAdminDlg::saveDatasource()
201*cdf0e10cSrcweir 	{
202*cdf0e10cSrcweir 		return PrepareLeaveCurrentPage();
203*cdf0e10cSrcweir 	}
204*cdf0e10cSrcweir //.........................................................................
205*cdf0e10cSrcweir }	// namespace dbaui
206*cdf0e10cSrcweir //.........................................................................
207