fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / ui / dlg / UserAdmin.cxx
blob5e9afea0f7ea4c67ad98c50c5ab48a413c460055
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 "UserAdmin.hxx"
21 #include "UITools.hxx"
22 #include "dbu_dlg.hrc"
23 #include <comphelper/types.hxx>
24 #include <comphelper/processfactory.hxx>
25 #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
26 #include <com/sun/star/sdbcx/XDataDefinitionSupplier.hpp>
27 #include <com/sun/star/sdbcx/XUsersSupplier.hpp>
28 #include <com/sun/star/sdbcx/XDrop.hpp>
29 #include <ucbhelper/interactionrequest.hxx>
30 #include <ucbhelper/simpleauthenticationrequest.hxx>
31 #include <com/sun/star/sdbcx/XDataDescriptorFactory.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/sdbcx/XUser.hpp>
34 #include <com/sun/star/sdbcx/XAppend.hpp>
35 #include "dbustrings.hrc"
36 #include <tools/debug.hxx>
37 #include "dbadmin.hxx"
38 #include "moduledbu.hxx"
39 #include <vcl/layout.hxx>
40 #include <sfx2/passwd.hxx>
42 using namespace ::com::sun::star::container;
43 using namespace ::com::sun::star::beans;
44 using namespace ::com::sun::star::sdbcx;
45 using namespace ::com::sun::star::sdbc;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::task;
48 using namespace dbaui;
49 using namespace ucbhelper;
50 using namespace comphelper;
52 class OPasswordDialog : public ModalDialog
54 VclPtr<VclFrame> m_pUser;
55 VclPtr<Edit> m_pEDOldPassword;
56 VclPtr<Edit> m_pEDPassword;
57 VclPtr<Edit> m_pEDPasswordRepeat;
58 VclPtr<OKButton> m_pOKBtn;
60 DECL_LINK( OKHdl_Impl, void * );
61 DECL_LINK( ModifiedHdl, Edit * );
63 public:
64 OPasswordDialog( vcl::Window* pParent,const OUString& _sUserName);
65 virtual ~OPasswordDialog() { disposeOnce(); }
66 virtual void dispose() SAL_OVERRIDE
68 m_pUser.clear();
69 m_pEDOldPassword.clear();
70 m_pEDPassword.clear();
71 m_pEDPasswordRepeat.clear();
72 m_pOKBtn.clear();
73 ModalDialog::dispose();
76 OUString GetOldPassword() const { return m_pEDOldPassword->GetText(); }
77 OUString GetNewPassword() const { return m_pEDPassword->GetText(); }
80 OPasswordDialog::OPasswordDialog(vcl::Window* _pParent,const OUString& _sUserName)
81 : ModalDialog(_pParent, "PasswordDialog", "dbaccess/ui/password.ui")
83 get(m_pUser, "userframe");
84 get(m_pEDOldPassword, "oldpassword");
85 get(m_pEDPassword, "newpassword");
86 get(m_pEDPasswordRepeat, "confirmpassword");
87 get(m_pOKBtn, "ok");
89 OUString sUser = m_pUser->get_label();
90 sUser = sUser.replaceFirst("$name$: $",_sUserName);
91 m_pUser->set_label(sUser);
92 m_pOKBtn->Disable();
94 m_pOKBtn->SetClickHdl( LINK( this, OPasswordDialog, OKHdl_Impl ) );
95 m_pEDOldPassword->SetModifyHdl( LINK( this, OPasswordDialog, ModifiedHdl ) );
98 IMPL_LINK_NOARG(OPasswordDialog, OKHdl_Impl)
100 if( m_pEDPassword->GetText() == m_pEDPasswordRepeat->GetText() )
101 EndDialog( RET_OK );
102 else
104 OUString aErrorMsg( ModuleRes( STR_ERROR_PASSWORDS_NOT_IDENTICAL));
105 ScopedVclPtrInstance< MessageDialog > aErrorBox(this, aErrorMsg);
106 aErrorBox->Execute();
107 m_pEDPassword->SetText( OUString() );
108 m_pEDPasswordRepeat->SetText( OUString() );
109 m_pEDPassword->GrabFocus();
111 return 0;
114 IMPL_LINK( OPasswordDialog, ModifiedHdl, Edit *, pEdit )
116 m_pOKBtn->Enable(!pEdit->GetText().isEmpty());
117 return 0;
120 // OUserAdmin
121 OUserAdmin::OUserAdmin(vcl::Window* pParent,const SfxItemSet& _rAttrSet)
122 : OGenericAdministrationPage( pParent, "UserAdminPage", "dbaccess/ui/useradminpage.ui", _rAttrSet)
123 , m_pUSER(0)
124 , m_pNEWUSER(0)
125 , m_pCHANGEPWD(0)
126 , m_pDELETEUSER(0)
127 ,m_TableCtrl(VclPtr<OTableGrantControl>::Create(get<VclAlignment>("table"), WB_TABSTOP))
129 m_TableCtrl->Show();
130 get(m_pUSER, "user");
131 get(m_pNEWUSER, "add");
132 get(m_pCHANGEPWD, "changepass");
133 get(m_pDELETEUSER, "delete");
135 m_pUSER->SetSelectHdl(LINK(this, OUserAdmin, ListDblClickHdl));
137 m_pNEWUSER->SetClickHdl(LINK(this, OUserAdmin, UserHdl));
138 m_pCHANGEPWD->SetClickHdl(LINK(this, OUserAdmin, UserHdl));
139 m_pDELETEUSER->SetClickHdl(LINK(this, OUserAdmin, UserHdl));
142 OUserAdmin::~OUserAdmin()
144 disposeOnce();
147 void OUserAdmin::dispose()
149 m_xConnection = NULL;
150 m_TableCtrl.disposeAndClear();
151 m_pUSER.clear();
152 m_pNEWUSER.clear();
153 m_pCHANGEPWD.clear();
154 m_pDELETEUSER.clear();
155 OGenericAdministrationPage::dispose();
158 void OUserAdmin::FillUserNames()
160 if(m_xConnection.is())
162 m_pUSER->Clear();
164 Reference<XDatabaseMetaData> xMetaData = m_xConnection->getMetaData();
166 if ( xMetaData.is() )
168 m_UserName = xMetaData->getUserName();
170 // first we need the users
171 if ( m_xUsers.is() )
173 m_pUSER->Clear();
175 m_aUserNames = m_xUsers->getElementNames();
176 const OUString* pBegin = m_aUserNames.getConstArray();
177 const OUString* pEnd = pBegin + m_aUserNames.getLength();
178 for(;pBegin != pEnd;++pBegin)
179 m_pUSER->InsertEntry(*pBegin);
181 m_pUSER->SelectEntryPos(0);
182 if(m_xUsers->hasByName(m_UserName))
184 Reference<XAuthorizable> xAuth;
185 m_xUsers->getByName(m_UserName) >>= xAuth;
186 m_TableCtrl->setGrantUser(xAuth);
189 m_TableCtrl->setUserName(GetUser());
190 m_TableCtrl->Init();
195 Reference<XAppend> xAppend(m_xUsers,UNO_QUERY);
196 m_pNEWUSER->Enable(xAppend.is());
197 Reference<XDrop> xDrop(m_xUsers,UNO_QUERY);
198 m_pDELETEUSER->Enable(xDrop.is());
200 m_pCHANGEPWD->Enable(m_xUsers.is());
201 m_TableCtrl->Enable(m_xUsers.is());
205 VclPtr<SfxTabPage> OUserAdmin::Create( vcl::Window* pParent, const SfxItemSet* _rAttrSet )
207 return VclPtr<OUserAdmin>::Create( pParent, *_rAttrSet );
210 IMPL_LINK( OUserAdmin, UserHdl, PushButton *, pButton )
214 if(pButton == m_pNEWUSER)
216 ScopedVclPtrInstance< SfxPasswordDialog > aPwdDlg(this);
217 aPwdDlg->ShowExtras(SfxShowExtras::ALL);
218 if(aPwdDlg->Execute())
220 Reference<XDataDescriptorFactory> xUserFactory(m_xUsers,UNO_QUERY);
221 Reference<XPropertySet> xNewUser = xUserFactory->createDataDescriptor();
222 if(xNewUser.is())
224 xNewUser->setPropertyValue(PROPERTY_NAME,makeAny(OUString(aPwdDlg->GetUser())));
225 xNewUser->setPropertyValue(PROPERTY_PASSWORD,makeAny(OUString(aPwdDlg->GetPassword())));
226 Reference<XAppend> xAppend(m_xUsers,UNO_QUERY);
227 if(xAppend.is())
228 xAppend->appendByDescriptor(xNewUser);
232 else if(pButton == m_pCHANGEPWD)
234 OUString sName = GetUser();
236 if(m_xUsers->hasByName(sName))
238 Reference<XUser> xUser;
239 m_xUsers->getByName(sName) >>= xUser;
240 if(xUser.is())
242 OUString sNewPassword,sOldPassword;
243 ScopedVclPtrInstance< OPasswordDialog > aDlg(this,sName);
244 if(aDlg->Execute() == RET_OK)
246 sNewPassword = aDlg->GetNewPassword();
247 sOldPassword = aDlg->GetOldPassword();
249 if(!sNewPassword.isEmpty())
250 xUser->changePassword(sOldPassword,sNewPassword);
255 else
256 {// delete user
257 if(m_xUsers.is() && m_xUsers->hasByName(GetUser()))
259 Reference<XDrop> xDrop(m_xUsers,UNO_QUERY);
260 if(xDrop.is())
262 ScopedVclPtrInstance< MessageDialog > aQry(this, ModuleRes(STR_QUERY_USERADMIN_DELETE_USER), VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
263 if(aQry->Execute() == RET_YES)
264 xDrop->dropByName(GetUser());
268 FillUserNames();
270 catch(const SQLException& e)
272 ::dbaui::showError(::dbtools::SQLExceptionInfo(e), this, m_xORB);
273 return 0;
275 catch(Exception& )
277 return 0;
280 return 0;
283 IMPL_LINK( OUserAdmin, ListDblClickHdl, ListBox *, /*pListBox*/ )
285 m_TableCtrl->setUserName(GetUser());
286 m_TableCtrl->UpdateTables();
287 m_TableCtrl->DeactivateCell();
288 m_TableCtrl->ActivateCell(m_TableCtrl->GetCurRow(),m_TableCtrl->GetCurColumnId());
289 return 0;
292 OUString OUserAdmin::GetUser()
294 return m_pUSER->GetSelectEntry();
297 void OUserAdmin::fillControls(::std::vector< ISaveValueWrapper* >& /*_rControlList*/)
301 void OUserAdmin::fillWindows(::std::vector< ISaveValueWrapper* >& /*_rControlList*/)
305 void OUserAdmin::implInitControls(const SfxItemSet& _rSet, bool _bSaveValue)
307 m_TableCtrl->setComponentContext(m_xORB);
310 if ( !m_xConnection.is() && m_pAdminDialog )
312 m_xConnection = m_pAdminDialog->createConnection().first;
313 Reference< XTablesSupplier > xTablesSup(m_xConnection,UNO_QUERY);
314 Reference<XUsersSupplier> xUsersSup(xTablesSup,UNO_QUERY);
315 if ( !xUsersSup.is() )
317 Reference< XDataDefinitionSupplier > xDriver(m_pAdminDialog->getDriver(),UNO_QUERY);
318 if ( xDriver.is() )
320 xUsersSup.set(xDriver->getDataDefinitionByConnection(m_xConnection),UNO_QUERY);
321 xTablesSup.set(xUsersSup,UNO_QUERY);
324 if ( xUsersSup.is() )
326 m_TableCtrl->setTablesSupplier(xTablesSup);
327 m_xUsers = xUsersSup->getUsers();
330 FillUserNames();
332 catch(const SQLException& e)
334 ::dbaui::showError(::dbtools::SQLExceptionInfo(e), this, m_xORB);
337 OGenericAdministrationPage::implInitControls(_rSet, _bSaveValue);
340 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */