From da9aa49f360c1351f5b5ce8bcf4a9df2db8c4f15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Thu, 22 Mar 2018 09:32:51 +0000 Subject: [PATCH] weld PasswordToOpenModifyDialog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I42ebbd1c94a54fb1d4c755fbcc6758c93614bc33 Reviewed-on: https://gerrit.libreoffice.org/51729 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- cui/source/dialogs/passwdomdlg.cxx | 158 +++++++++------------------ cui/source/factory/dlgfact.cxx | 21 ++-- cui/source/factory/dlgfact.hxx | 12 +- cui/source/inc/passwdomdlg.hxx | 30 +++-- cui/uiconfig/ui/password.ui | 49 ++++----- include/vcl/abstdlg.hxx | 8 +- uui/source/iahndl-authentication.cxx | 12 +- 7 files changed, 128 insertions(+), 162 deletions(-) diff --git a/cui/source/dialogs/passwdomdlg.cxx b/cui/source/dialogs/passwdomdlg.cxx index fab6b3caa6cc..a5efbd0d6428 100644 --- a/cui/source/dialogs/passwdomdlg.cxx +++ b/cui/source/dialogs/passwdomdlg.cxx @@ -17,163 +17,111 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include #include - #include #include -#include -#include -#include -#include -#include -#include - -struct PasswordToOpenModifyDialog_Impl +IMPL_LINK_NOARG(PasswordToOpenModifyDialog, OkBtnClickHdl, weld::Button&, void) { - VclPtr m_pParent; - - VclPtr m_pPasswdToOpenED; - VclPtr m_pReenterPasswdToOpenED; - VclPtr m_pOptionsExpander; - VclPtr m_pOk; - VclPtr m_pOpenReadonlyCB; - VclPtr m_pPasswdToModifyED; - VclPtr m_pReenterPasswdToModifyED; - - OUString m_aOneMismatch; - OUString m_aTwoMismatch; - OUString m_aInvalidStateForOkButton; - OUString m_aInvalidStateForOkButton_v2; - - bool m_bIsPasswordToModify; - - - DECL_LINK( OkBtnClickHdl, Button*, void ); - - PasswordToOpenModifyDialog_Impl( PasswordToOpenModifyDialog * pParent, - sal_uInt16 nMaxPasswdLen, bool bIsPasswordToModify ); -}; - -PasswordToOpenModifyDialog_Impl::PasswordToOpenModifyDialog_Impl( - PasswordToOpenModifyDialog * pParent, - sal_uInt16 nMaxPasswdLen, - bool bIsPasswordToModify ) - : m_pParent( pParent ) - , m_aOneMismatch( CuiResId( RID_SVXSTR_ONE_PASSWORD_MISMATCH ) ) - , m_aTwoMismatch( CuiResId( RID_SVXSTR_TWO_PASSWORDS_MISMATCH ) ) - , m_aInvalidStateForOkButton( CuiResId( RID_SVXSTR_INVALID_STATE_FOR_OK_BUTTON ) ) - , m_aInvalidStateForOkButton_v2( CuiResId( RID_SVXSTR_INVALID_STATE_FOR_OK_BUTTON_V2 ) ) - , m_bIsPasswordToModify( bIsPasswordToModify ) -{ - pParent->get(m_pPasswdToOpenED, "newpassEntry"); - pParent->get(m_pReenterPasswdToOpenED, "confirmpassEntry"); - pParent->get(m_pOk, "ok"); - pParent->get(m_pOpenReadonlyCB, "readonly"); - pParent->get(m_pPasswdToModifyED, "newpassroEntry"); - pParent->get(m_pReenterPasswdToModifyED, "confirmropassEntry"); - pParent->get(m_pOptionsExpander, "expander"); - - m_pOk->SetClickHdl( LINK( this, PasswordToOpenModifyDialog_Impl, OkBtnClickHdl ) ); - - if (nMaxPasswdLen) - { - m_pPasswdToOpenED->SetMaxTextLen( nMaxPasswdLen ); - m_pReenterPasswdToOpenED->SetMaxTextLen( nMaxPasswdLen ); - m_pPasswdToModifyED->SetMaxTextLen( nMaxPasswdLen ); - m_pReenterPasswdToModifyED->SetMaxTextLen( nMaxPasswdLen ); - } - - m_pPasswdToOpenED->GrabFocus(); - - m_pOptionsExpander->Enable(bIsPasswordToModify); - if (!bIsPasswordToModify) - m_pOptionsExpander->Hide(); -} - -IMPL_LINK(PasswordToOpenModifyDialog_Impl, OkBtnClickHdl, Button *, pButton, void) -{ - bool bInvalidState = !m_pOpenReadonlyCB->IsChecked() && - m_pPasswdToOpenED->GetText().isEmpty() && - m_pPasswdToModifyED->GetText().isEmpty(); + bool bInvalidState = !m_xOpenReadonlyCB->get_active() && + m_xPasswdToOpenED->get_text().isEmpty() && + m_xPasswdToModifyED->get_text().isEmpty(); if (bInvalidState) { - std::unique_ptr xErrorBox(Application::CreateMessageDialog(pButton->GetFrameWeld(), + std::unique_ptr xErrorBox(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Warning, VclButtonsType::Ok, m_bIsPasswordToModify? m_aInvalidStateForOkButton : m_aInvalidStateForOkButton_v2)); xErrorBox->run(); } else // check for mismatched passwords... { - const bool bToOpenMatch = m_pPasswdToOpenED->GetText() == m_pReenterPasswdToOpenED->GetText(); - const bool bToModifyMatch = m_pPasswdToModifyED->GetText() == m_pReenterPasswdToModifyED->GetText(); + const bool bToOpenMatch = m_xPasswdToOpenED->get_text() == m_xReenterPasswdToOpenED->get_text(); + const bool bToModifyMatch = m_xPasswdToModifyED->get_text() == m_xReenterPasswdToModifyED->get_text(); const int nMismatch = (bToOpenMatch? 0 : 1) + (bToModifyMatch? 0 : 1); if (nMismatch > 0) { - std::unique_ptr xErrorBox(Application::CreateMessageDialog(pButton->GetFrameWeld(), + std::unique_ptr xErrorBox(Application::CreateMessageDialog(m_xDialog.get(), VclMessageType::Warning, VclButtonsType::Ok, nMismatch == 1 ? m_aOneMismatch : m_aTwoMismatch)); xErrorBox->run(); - Edit* pEdit = !bToOpenMatch ? m_pPasswdToOpenED.get() : m_pPasswdToModifyED.get(); - Edit* pRepeatEdit = !bToOpenMatch? m_pReenterPasswdToOpenED.get() : m_pReenterPasswdToModifyED.get(); + weld::Entry* pEdit = !bToOpenMatch ? m_xPasswdToOpenED.get() : m_xPasswdToModifyED.get(); + weld::Entry* pRepeatEdit = !bToOpenMatch? m_xReenterPasswdToOpenED.get() : m_xReenterPasswdToModifyED.get(); if (nMismatch == 1) { - pEdit->SetText( "" ); - pRepeatEdit->SetText( "" ); + pEdit->set_text( "" ); + pRepeatEdit->set_text( "" ); } else if (nMismatch == 2) { - m_pPasswdToOpenED->SetText( "" ); - m_pReenterPasswdToOpenED->SetText( "" ); - m_pPasswdToModifyED->SetText( "" ); - m_pReenterPasswdToModifyED->SetText( "" ); + m_xPasswdToOpenED->set_text( "" ); + m_xReenterPasswdToOpenED->set_text( "" ); + m_xPasswdToModifyED->set_text( "" ); + m_xReenterPasswdToModifyED->set_text( "" ); } - pEdit->GrabFocus(); + pEdit->grab_focus(); } else { - m_pParent->EndDialog( RET_OK ); + m_xDialog->response(RET_OK); } } } -PasswordToOpenModifyDialog::PasswordToOpenModifyDialog( - vcl::Window * pParent, - sal_uInt16 nMaxPasswdLen, bool bIsPasswordToModify) - : SfxModalDialog( pParent, "PasswordDialog", "cui/ui/password.ui" ) +PasswordToOpenModifyDialog::PasswordToOpenModifyDialog(weld::Window * pParent, sal_uInt16 nMaxPasswdLen, bool bIsPasswordToModify) + : GenericDialogController(pParent, "cui/ui/password.ui", "PasswordDialog") + , m_xPasswdToOpenED(m_xBuilder->weld_entry("newpassEntry")) + , m_xReenterPasswdToOpenED(m_xBuilder->weld_entry("confirmpassEntry")) + , m_xOptionsExpander(m_xBuilder->weld_expander("expander")) + , m_xOk(m_xBuilder->weld_button("ok")) + , m_xOpenReadonlyCB(m_xBuilder->weld_check_button("readonly")) + , m_xPasswdToModifyED(m_xBuilder->weld_entry("newpassroEntry")) + , m_xReenterPasswdToModifyED(m_xBuilder->weld_entry("confirmropassEntry")) + , m_aOneMismatch( CuiResId( RID_SVXSTR_ONE_PASSWORD_MISMATCH ) ) + , m_aTwoMismatch( CuiResId( RID_SVXSTR_TWO_PASSWORDS_MISMATCH ) ) + , m_aInvalidStateForOkButton( CuiResId( RID_SVXSTR_INVALID_STATE_FOR_OK_BUTTON ) ) + , m_aInvalidStateForOkButton_v2( CuiResId( RID_SVXSTR_INVALID_STATE_FOR_OK_BUTTON_V2 ) ) + , m_bIsPasswordToModify( bIsPasswordToModify ) { - m_pImpl.reset(new PasswordToOpenModifyDialog_Impl(this, - nMaxPasswdLen, bIsPasswordToModify ) ); -} + m_xOk->connect_clicked(LINK(this, PasswordToOpenModifyDialog, OkBtnClickHdl)); + if (nMaxPasswdLen) + { + m_xPasswdToOpenED->set_max_length( nMaxPasswdLen ); + m_xReenterPasswdToOpenED->set_max_length( nMaxPasswdLen ); + m_xPasswdToModifyED->set_max_length( nMaxPasswdLen ); + m_xReenterPasswdToModifyED->set_max_length( nMaxPasswdLen ); + } -PasswordToOpenModifyDialog::~PasswordToOpenModifyDialog() -{ - disposeOnce(); + m_xPasswdToOpenED->grab_focus(); + + m_xOptionsExpander->set_sensitive(bIsPasswordToModify); + if (!bIsPasswordToModify) + m_xOptionsExpander->hide(); } OUString PasswordToOpenModifyDialog::GetPasswordToOpen() const { const bool bPasswdOk = - !m_pImpl->m_pPasswdToOpenED->GetText().isEmpty() && - m_pImpl->m_pPasswdToOpenED->GetText() == m_pImpl->m_pReenterPasswdToOpenED->GetText(); - return bPasswdOk ? m_pImpl->m_pPasswdToOpenED->GetText() : OUString(); + !m_xPasswdToOpenED->get_text().isEmpty() && + m_xPasswdToOpenED->get_text() == m_xReenterPasswdToOpenED->get_text(); + return bPasswdOk ? m_xPasswdToOpenED->get_text() : OUString(); } OUString PasswordToOpenModifyDialog::GetPasswordToModify() const { const bool bPasswdOk = - !m_pImpl->m_pPasswdToModifyED->GetText().isEmpty() && - m_pImpl->m_pPasswdToModifyED->GetText() == m_pImpl->m_pReenterPasswdToModifyED->GetText(); - return bPasswdOk ? m_pImpl->m_pPasswdToModifyED->GetText() : OUString(); + !m_xPasswdToModifyED->get_text().isEmpty() && + m_xPasswdToModifyED->get_text() == m_xReenterPasswdToModifyED->get_text(); + return bPasswdOk ? m_xPasswdToModifyED->get_text() : OUString(); } bool PasswordToOpenModifyDialog::IsRecommendToOpenReadonly() const { - return m_pImpl->m_pOpenReadonlyCB->IsChecked(); + return m_xOpenReadonlyCB->get_active(); } diff --git a/cui/source/factory/dlgfact.cxx b/cui/source/factory/dlgfact.cxx index f8ed8b406591..b6b81359c9a0 100644 --- a/cui/source/factory/dlgfact.cxx +++ b/cui/source/factory/dlgfact.cxx @@ -143,7 +143,12 @@ IMPL_ABSTDLG_BASE(AbstractInsertObjectDialog_Impl); IMPL_ABSTDLG_BASE(AbstractLinksDialog_Impl); IMPL_ABSTDLG_BASE(AbstractSpellDialog_Impl); IMPL_ABSTDLG_BASE(AbstractSvxPostItDialog_Impl); -IMPL_ABSTDLG_BASE(AbstractPasswordToOpenModifyDialog_Impl); + +short AbstractPasswordToOpenModifyDialog_Impl::Execute() +{ + return m_xDlg->run(); +} + IMPL_ABSTDLG_BASE(AbstractScreenshotAnnotationDlg_Impl); @@ -785,15 +790,17 @@ vcl::Window * AbstractSvxPostItDialog_Impl::GetWindow() OUString AbstractPasswordToOpenModifyDialog_Impl::GetPasswordToOpen() const { - return pDlg->GetPasswordToOpen(); + return m_xDlg->GetPasswordToOpen(); } + OUString AbstractPasswordToOpenModifyDialog_Impl::GetPasswordToModify() const { - return pDlg->GetPasswordToModify(); + return m_xDlg->GetPasswordToModify(); } + bool AbstractPasswordToOpenModifyDialog_Impl::IsRecommendToOpenReadonly() const { - return pDlg->IsRecommendToOpenReadonly(); + return m_xDlg->IsRecommendToOpenReadonly(); } // Create dialogs with simplest interface @@ -1515,11 +1522,9 @@ VclPtr AbstractDialogFactory_Impl::CreateSvxInsRowColDl } VclPtr AbstractDialogFactory_Impl::CreatePasswordToOpenModifyDialog( - vcl::Window * pParent, - sal_uInt16 nMaxPasswdLen, bool bIsPasswordToModify ) + weld::Window * pParent, sal_uInt16 nMaxPasswdLen, bool bIsPasswordToModify) { - VclPtrInstance pDlg( pParent, nMaxPasswdLen, bIsPasswordToModify ); - return VclPtr::Create( pDlg ); + return VclPtr::Create(new PasswordToOpenModifyDialog(pParent, nMaxPasswdLen, bIsPasswordToModify)); } VclPtr AbstractDialogFactory_Impl::CreateScreenshotAnnotationDlg( diff --git a/cui/source/factory/dlgfact.hxx b/cui/source/factory/dlgfact.hxx index 7d74cb2d9dd9..346d80311d9e 100644 --- a/cui/source/factory/dlgfact.hxx +++ b/cui/source/factory/dlgfact.hxx @@ -458,8 +458,14 @@ private: class PasswordToOpenModifyDialog; class AbstractPasswordToOpenModifyDialog_Impl : public AbstractPasswordToOpenModifyDialog { - DECL_ABSTDLG_BASE( AbstractPasswordToOpenModifyDialog_Impl, PasswordToOpenModifyDialog ) - +protected: + std::unique_ptr m_xDlg; +public: + explicit AbstractPasswordToOpenModifyDialog_Impl(PasswordToOpenModifyDialog* p) + : m_xDlg(p) + { + } + virtual short Execute() override; virtual OUString GetPasswordToOpen() const override; virtual OUString GetPasswordToModify() const override; virtual bool IsRecommendToOpenReadonly() const override; @@ -648,7 +654,7 @@ public: virtual VclPtr CreateSvxInsRowColDlg(weld::Window* pParent, bool bCol, const OString& rHelpId) override; - virtual VclPtr CreatePasswordToOpenModifyDialog(vcl::Window * pParent, sal_uInt16 nMaxPasswdLen, bool bIsPasswordToModify) override; + virtual VclPtr CreatePasswordToOpenModifyDialog(weld::Window * pParent, sal_uInt16 nMaxPasswdLen, bool bIsPasswordToModify) override; virtual VclPtr CreateScreenshotAnnotationDlg(vcl::Window * pParent, Dialog& rParentDialog) override; }; diff --git a/cui/source/inc/passwdomdlg.hxx b/cui/source/inc/passwdomdlg.hxx index 529b67fb06ed..2d56f3b480ce 100644 --- a/cui/source/inc/passwdomdlg.hxx +++ b/cui/source/inc/passwdomdlg.hxx @@ -19,26 +19,37 @@ #ifndef INCLUDED_CUI_SOURCE_INC_PASSWDOMDLG_HXX #define INCLUDED_CUI_SOURCE_INC_PASSWDOMDLG_HXX - -#include - +#include #include -struct PasswordToOpenModifyDialog_Impl; - -class PasswordToOpenModifyDialog : public SfxModalDialog +class PasswordToOpenModifyDialog : public weld::GenericDialogController { - std::unique_ptr< PasswordToOpenModifyDialog_Impl > m_pImpl; + std::unique_ptr m_xPasswdToOpenED; + std::unique_ptr m_xReenterPasswdToOpenED; + std::unique_ptr m_xOptionsExpander; + std::unique_ptr m_xOk; + std::unique_ptr m_xOpenReadonlyCB; + std::unique_ptr m_xPasswdToModifyED; + std::unique_ptr m_xReenterPasswdToModifyED; + + OUString m_aOneMismatch; + OUString m_aTwoMismatch; + OUString m_aInvalidStateForOkButton; + OUString m_aInvalidStateForOkButton_v2; + + bool m_bIsPasswordToModify; + + + DECL_LINK(OkBtnClickHdl, weld::Button&, void); PasswordToOpenModifyDialog( const PasswordToOpenModifyDialog & ) = delete; PasswordToOpenModifyDialog & operator = ( const PasswordToOpenModifyDialog & ) = delete; public: - PasswordToOpenModifyDialog( vcl::Window * pParent, + PasswordToOpenModifyDialog(weld::Window* pParent, sal_uInt16 nMaxPasswdLen /* 0 -> no max len enforced */, bool bIsPasswordToModify ); - virtual ~PasswordToOpenModifyDialog() override; // AbstractPasswordToOpenModifyDialog OUString GetPasswordToOpen() const; @@ -46,7 +57,6 @@ public: bool IsRecommendToOpenReadonly() const; }; - #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cui/uiconfig/ui/password.ui b/cui/uiconfig/ui/password.ui index c738242b5076..7f529182a5f9 100644 --- a/cui/uiconfig/ui/password.ui +++ b/cui/uiconfig/ui/password.ui @@ -1,11 +1,14 @@ - + False 6 Set Password + True + 0 + 0 normal @@ -86,32 +89,28 @@ True False - 0 Confirm password True confirmpassEntry + 0 0 2 - 1 - 1 True False - 0 _Enter password to open True newpassEntry + 0 0 0 - 1 - 1 @@ -120,12 +119,13 @@ True True False + True + 50 + password 0 1 - 1 - 1 @@ -134,28 +134,26 @@ True True False + True + password 0 3 - 1 - 1 True False - 0 Note: After a password has been set, the document will only open with the password. Should you lose the password, there will be no way to recover the document. Please also note that this password is case-sensitive. True 60 + 0 0 4 - 1 - 1 @@ -192,24 +190,20 @@ 0 0 - 1 - 1 True False - 0 Enter password to allow editing True newpassroEntry + 0 0 1 - 1 - 1 @@ -218,28 +212,26 @@ True True False + True + password 0 2 - 1 - 1 True False - 0 Confirm password True confirmropassEntry + 0 0 3 - 1 - 1 @@ -248,12 +240,12 @@ True True False + True + password 0 4 - 1 - 1 @@ -284,8 +276,6 @@ 0 5 - 1 - 1 @@ -322,6 +312,9 @@ ok cancel + + + diff --git a/include/vcl/abstdlg.hxx b/include/vcl/abstdlg.hxx index af676785b295..29eeaaf71147 100644 --- a/include/vcl/abstdlg.hxx +++ b/include/vcl/abstdlg.hxx @@ -31,7 +31,11 @@ namespace vcl { class Window; } class Dialog; class Bitmap; -namespace weld { class DialogController; } +namespace weld +{ + class DialogController; + class Window; +} /** * Some things multiple-inherit from VclAbstractDialog and OutputDevice, @@ -120,7 +124,7 @@ public: virtual VclPtr CreateVclDialog(vcl::Window* pParent, sal_uInt32 nId) = 0; // creates instance of PasswordToOpenModifyDialog from cui - virtual VclPtr CreatePasswordToOpenModifyDialog( vcl::Window * pParent, sal_uInt16 nMaxPasswdLen, bool bIsPasswordToModify ) = 0; + virtual VclPtr CreatePasswordToOpenModifyDialog(weld::Window * pParent, sal_uInt16 nMaxPasswdLen, bool bIsPasswordToModify) = 0; // creates instance of ScreenshotAnnotationDlg from cui virtual VclPtr CreateScreenshotAnnotationDlg( diff --git a/uui/source/iahndl-authentication.cxx b/uui/source/iahndl-authentication.cxx index 2351cdbc395d..2e88d43191db 100644 --- a/uui/source/iahndl-authentication.cxx +++ b/uui/source/iahndl-authentication.cxx @@ -500,7 +500,7 @@ handleMasterPasswordRequest_( void executePasswordDialog( - vcl::Window * pParent, + weld::Window * pParent, LoginErrorInfo & rInfo, task::PasswordRequestMode nMode, const OUString& aDocName, @@ -517,7 +517,7 @@ executePasswordDialog( { if (bIsSimplePasswordRequest) { - std::unique_ptr xDialog(new PasswordDialog(pParent ? pParent->GetFrameWeld() : nullptr, nMode, + std::unique_ptr xDialog(new PasswordDialog(pParent, nMode, aResLocale, aDocName, bIsPasswordToModify, bIsSimplePasswordRequest)); xDialog->SetMinLen(0); @@ -540,7 +540,7 @@ executePasswordDialog( } else // enter password or reenter password { - std::unique_ptr xDialog(new PasswordDialog(pParent ? pParent->GetFrameWeld() : nullptr, nMode, + std::unique_ptr xDialog(new PasswordDialog(pParent, nMode, aResLocale, aDocName, bIsPasswordToModify, bIsSimplePasswordRequest)); xDialog->SetMinLen(0); @@ -558,7 +558,7 @@ executePasswordDialog( void handlePasswordRequest_( - vcl::Window * pParent, + weld::Window * pParent, task::PasswordRequestMode nMode, uno::Sequence< uno::Reference< task::XInteractionContinuation > > const & rContinuations, @@ -723,7 +723,7 @@ UUIInteractionHelper::handlePasswordRequest( if (bDoHandleRequest) { - handlePasswordRequest_( pParent, nMode, rContinuations, + handlePasswordRequest_( pParent ? pParent->GetFrameWeld() : nullptr, nMode, rContinuations, aDocumentName, bMSCryptoMode, bIsPasswordToModify ); return true; } @@ -731,7 +731,7 @@ UUIInteractionHelper::handlePasswordRequest( task::PasswordRequest aPasswordRequest; if( aAnyRequest >>= aPasswordRequest ) { - handlePasswordRequest_(getParentProperty(), + handlePasswordRequest_(pParent ? pParent->GetFrameWeld() : nullptr, aPasswordRequest.Mode, rRequest->getContinuations(), OUString(),