From 947ad25207a52d8d245a977430244cce38734b65 Mon Sep 17 00:00:00 2001 From: Heiko Tietze Date: Wed, 3 Aug 2022 16:56:18 +0200 Subject: Resolves tdf#149944 - UI issues with Base's User Administration dialog Buttons for add, delete user and change password moved into a menu Change-Id: Ibddda5269f0a8a9219538833b1f871b041dd5341 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/137754 Tested-by: Jenkins Reviewed-by: Heiko Tietze --- dbaccess/inc/strings.hrc | 3 + dbaccess/source/ui/dlg/UserAdmin.cxx | 160 +++++++++++++++++----------------- dbaccess/source/ui/dlg/UserAdmin.hxx | 6 +- dbaccess/uiconfig/ui/useradminpage.ui | 112 +++++++++--------------- 4 files changed, 128 insertions(+), 153 deletions(-) (limited to 'dbaccess') diff --git a/dbaccess/inc/strings.hrc b/dbaccess/inc/strings.hrc index ea57f4ebd240..f8370a1832b0 100644 --- a/dbaccess/inc/strings.hrc +++ b/dbaccess/inc/strings.hrc @@ -420,6 +420,9 @@ #define STR_EXCEPTION_INFO NC_("STR_EXCEPTION_INFO", "Information") #define STR_EXCEPTION_DETAILS NC_("STR_EXCEPTION_DETAILS", "Details") +#define STR_ADD_USER NC_("STR_ADD_USER", "Add User") +#define STR_DELETE_USER NC_("STR_DELETE_USER", "Delete User") +#define STR_CHANGE_PASSWORD NC_("STR_CHANGE_PASSWORD", "Change Password") #define STR_QUERY_USERADMIN_DELETE_USER NC_("STR_QUERY_USERADMIN_DELETE_USER", "Do you really want to delete the user?") #define STR_USERADMIN_NOT_AVAILABLE NC_("STR_USERADMIN_NOT_AVAILABLE", "The database does not support user administration." ) #define STR_ERROR_PASSWORDS_NOT_IDENTICAL NC_("STR_ERROR_PASSWORDS_NOT_IDENTICAL", "The passwords do not match. Please enter the password again.") diff --git a/dbaccess/source/ui/dlg/UserAdmin.cxx b/dbaccess/source/ui/dlg/UserAdmin.cxx index b601c49391fc..d7396dc4970f 100644 --- a/dbaccess/source/ui/dlg/UserAdmin.cxx +++ b/dbaccess/source/ui/dlg/UserAdmin.cxx @@ -49,6 +49,10 @@ using namespace comphelper; namespace { +#define MNI_ACTION_ADD_USER "add" +#define MNI_ACTION_DEL_USER "delete" +#define MNI_ACTION_CHANGE_PASSWORD "password" + class OPasswordDialog : public weld::GenericDialogController { std::unique_ptr m_xUser; @@ -111,20 +115,87 @@ IMPL_LINK(OPasswordDialog, ModifiedHdl, weld::Entry&, rEdit, void) // OUserAdmin OUserAdmin::OUserAdmin(weld::Container* pPage, weld::DialogController* pController,const SfxItemSet& _rAttrSet) : OGenericAdministrationPage(pPage, pController, "dbaccess/ui/useradminpage.ui", "UserAdminPage", _rAttrSet) + , mxActionBar(m_xBuilder->weld_menu_button("action_menu")) , m_xUSER(m_xBuilder->weld_combo_box("user")) - , m_xNEWUSER(m_xBuilder->weld_button("add")) - , m_xCHANGEPWD(m_xBuilder->weld_button("changepass")) - , m_xDELETEUSER(m_xBuilder->weld_button("delete")) , m_xTable(m_xBuilder->weld_container("table")) , m_xTableCtrlParent(m_xTable->CreateChildFrame()) , m_xTableCtrl(VclPtr::Create(m_xTableCtrlParent)) { + mxActionBar->append_item(MNI_ACTION_ADD_USER, DBA_RES(STR_ADD_USER)); + mxActionBar->append_item(MNI_ACTION_DEL_USER, DBA_RES(STR_DELETE_USER)); + mxActionBar->append_item(MNI_ACTION_CHANGE_PASSWORD, DBA_RES(STR_CHANGE_PASSWORD)); + mxActionBar->connect_selected(LINK(this,OUserAdmin,MenuSelectHdl)); + m_xTableCtrl->Show(); m_xUSER->connect_changed(LINK(this, OUserAdmin, ListDblClickHdl)); - m_xNEWUSER->connect_clicked(LINK(this, OUserAdmin, UserHdl)); - m_xCHANGEPWD->connect_clicked(LINK(this, OUserAdmin, UserHdl)); - m_xDELETEUSER->connect_clicked(LINK(this, OUserAdmin, UserHdl)); +} + +IMPL_LINK(OUserAdmin, MenuSelectHdl, const OString&, rIdent, void) +{ + try + { + if (rIdent == MNI_ACTION_ADD_USER) { + SfxPasswordDialog aPwdDlg(GetFrameWeld()); + aPwdDlg.ShowExtras(SfxShowExtras::ALL); + if (aPwdDlg.run()) + { + Reference xUserFactory(m_xUsers,UNO_QUERY); + Reference xNewUser = xUserFactory->createDataDescriptor(); + if(xNewUser.is()) + { + xNewUser->setPropertyValue(PROPERTY_NAME,Any(aPwdDlg.GetUser())); + xNewUser->setPropertyValue(PROPERTY_PASSWORD,Any(aPwdDlg.GetPassword())); + Reference xAppend(m_xUsers,UNO_QUERY); + if(xAppend.is()) + xAppend->appendByDescriptor(xNewUser); + } + } + } + else if (rIdent == MNI_ACTION_DEL_USER) { + if (m_xUsers.is() && m_xUsers->hasByName(GetUser())) + { + Reference xDrop(m_xUsers,UNO_QUERY); + if(xDrop.is()) + { + std::unique_ptr xQry(Application::CreateMessageDialog(GetFrameWeld(), + VclMessageType::Question, VclButtonsType::YesNo, + DBA_RES(STR_QUERY_USERADMIN_DELETE_USER))); + if (xQry->run() == RET_YES) + xDrop->dropByName(GetUser()); + } + } + } + else if (rIdent == MNI_ACTION_CHANGE_PASSWORD) { + OUString sName = GetUser(); + if(m_xUsers->hasByName(sName)) + { + Reference xUser; + m_xUsers->getByName(sName) >>= xUser; + if(xUser.is()) + { + OPasswordDialog aDlg(GetFrameWeld(), sName); + if (aDlg.run() == RET_OK) + { + OUString sNewPassword,sOldPassword; + sNewPassword = aDlg.GetNewPassword(); + sOldPassword = aDlg.GetOldPassword(); + + if(!sNewPassword.isEmpty()) + xUser->changePassword(sOldPassword,sNewPassword); + } + } + } + } + FillUserNames(); + } + catch(const SQLException& e) + { + ::dbtools::showError(::dbtools::SQLExceptionInfo(e), GetDialogController()->getDialog()->GetXWindow(), m_xORB); + } + catch(Exception& ) + { + } } OUserAdmin::~OUserAdmin() @@ -173,11 +244,11 @@ void OUserAdmin::FillUserNames() } Reference xAppend(m_xUsers,UNO_QUERY); - m_xNEWUSER->set_sensitive(xAppend.is()); + mxActionBar->set_item_sensitive(MNI_ACTION_ADD_USER, xAppend.is()); Reference xDrop(m_xUsers,UNO_QUERY); - m_xDELETEUSER->set_sensitive(xDrop.is()); + mxActionBar->set_item_sensitive(MNI_ACTION_DEL_USER, xDrop.is()); + mxActionBar->set_item_sensitive(MNI_ACTION_CHANGE_PASSWORD, m_xUsers.is()); - m_xCHANGEPWD->set_sensitive(m_xUsers.is()); m_xTableCtrl->Enable(m_xUsers.is()); } @@ -186,77 +257,6 @@ std::unique_ptr OUserAdmin::Create( weld::Container* pPage, weld::Di return std::make_unique( pPage, pController, *_rAttrSet ); } -IMPL_LINK(OUserAdmin, UserHdl, weld::Button&, rButton, void) -{ - try - { - if (&rButton == m_xNEWUSER.get()) - { - SfxPasswordDialog aPwdDlg(GetFrameWeld()); - aPwdDlg.ShowExtras(SfxShowExtras::ALL); - if (aPwdDlg.run()) - { - Reference xUserFactory(m_xUsers,UNO_QUERY); - Reference xNewUser = xUserFactory->createDataDescriptor(); - if(xNewUser.is()) - { - xNewUser->setPropertyValue(PROPERTY_NAME,Any(aPwdDlg.GetUser())); - xNewUser->setPropertyValue(PROPERTY_PASSWORD,Any(aPwdDlg.GetPassword())); - Reference xAppend(m_xUsers,UNO_QUERY); - if(xAppend.is()) - xAppend->appendByDescriptor(xNewUser); - } - } - } - else if (&rButton == m_xCHANGEPWD.get()) - { - OUString sName = GetUser(); - - if(m_xUsers->hasByName(sName)) - { - Reference xUser; - m_xUsers->getByName(sName) >>= xUser; - if(xUser.is()) - { - OPasswordDialog aDlg(GetFrameWeld(), sName); - if (aDlg.run() == RET_OK) - { - OUString sNewPassword,sOldPassword; - sNewPassword = aDlg.GetNewPassword(); - sOldPassword = aDlg.GetOldPassword(); - - if(!sNewPassword.isEmpty()) - xUser->changePassword(sOldPassword,sNewPassword); - } - } - } - } - else - {// delete user - if(m_xUsers.is() && m_xUsers->hasByName(GetUser())) - { - Reference xDrop(m_xUsers,UNO_QUERY); - if(xDrop.is()) - { - std::unique_ptr xQry(Application::CreateMessageDialog(GetFrameWeld(), - VclMessageType::Question, VclButtonsType::YesNo, - DBA_RES(STR_QUERY_USERADMIN_DELETE_USER))); - if (xQry->run() == RET_YES) - xDrop->dropByName(GetUser()); - } - } - } - FillUserNames(); - } - catch(const SQLException& e) - { - ::dbtools::showError(::dbtools::SQLExceptionInfo(e), GetDialogController()->getDialog()->GetXWindow(), m_xORB); - } - catch(Exception& ) - { - } -} - IMPL_LINK_NOARG(OUserAdmin, ListDblClickHdl, weld::ComboBox&, void) { m_xTableCtrl->setUserName(GetUser()); diff --git a/dbaccess/source/ui/dlg/UserAdmin.hxx b/dbaccess/source/ui/dlg/UserAdmin.hxx index e9c2a13e7876..045d8c39806f 100644 --- a/dbaccess/source/ui/dlg/UserAdmin.hxx +++ b/dbaccess/source/ui/dlg/UserAdmin.hxx @@ -32,10 +32,8 @@ namespace dbaui class OUserAdmin final : public OGenericAdministrationPage { + std::unique_ptr mxActionBar; std::unique_ptr m_xUSER; - std::unique_ptr m_xNEWUSER; - std::unique_ptr m_xCHANGEPWD; - std::unique_ptr m_xDELETEUSER; std::unique_ptr m_xTable; css::uno::Reference m_xTableCtrlParent; VclPtr m_xTableCtrl; // show the grant rights of one user @@ -48,7 +46,7 @@ class OUserAdmin final : public OGenericAdministrationPage // methods DECL_LINK(ListDblClickHdl, weld::ComboBox&, void); - DECL_LINK(UserHdl, weld::Button&, void); + DECL_LINK(MenuSelectHdl, const OString&, void); void FillUserNames(); diff --git a/dbaccess/uiconfig/ui/useradminpage.ui b/dbaccess/uiconfig/ui/useradminpage.ui index 4d649ea90af9..e76349a49b90 100644 --- a/dbaccess/uiconfig/ui/useradminpage.ui +++ b/dbaccess/uiconfig/ui/useradminpage.ui @@ -1,44 +1,50 @@ - + + + True + False + True - False + False True True - 6 + 6 vertical 12 True - False + False + 6 + 6 + 6 True - 0 - none + 0 + none True - False + False + 6 True vertical 6 - 6 True - False + False True 12 True - False + False start - True Us_er: - True + True 0 @@ -50,7 +56,7 @@ True - False + False True @@ -59,54 +65,19 @@ 1 - - - False - True - 0 - - - - - True - False - True - 6 - - - _Add User... - True - True - True - True - - - False - True - 0 - - - - - Change _Password... - True - True - True - True - - - False - True - 1 - - - - _Delete User... + + _Manage + True True - True - True - True + True + False + True + end + menu + + + False @@ -118,7 +89,7 @@ False True - 1 + 0 @@ -126,7 +97,7 @@ True - False + False User Selection @@ -143,20 +114,23 @@ True - False + False + 6 + 6 + 6 True True - 0 - none + 0 + none + 150 + True + False + 6 True True - True - 150 - False vertical - 6 @@ -165,7 +139,7 @@ True - False + False Access Rights for Selected User -- cgit