filter/source/pdf/impdialog.cxx |   73 ++++++++++++++++++++++++----------------
 filter/source/pdf/impdialog.hxx |    4 ++
 include/sfx2/passwd.hxx         |    6 +++
 sfx2/source/dialog/passwd.cxx   |   30 ++++++++++++----
 vcl/jsdialog/enabled.cxx        |    1 
 5 files changed, 78 insertions(+), 36 deletions(-)

New commits:
commit 7ebe5e19fb379c88b8e455693a23fd9036c1b517
Author:     NickWingate <nick.wing...@collabora.com>
AuthorDate: Wed Dec 28 17:27:31 2022 +0000
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Thu Jan 19 12:48:06 2023 +0000

    Make PDFExport Password Subdialog Async
    
    Dialog in File>Export As PDF>Security>Set Password
    Close subdialog when parent dialog is closed
    
    Signed-off-by: NickWingate <nick.wing...@collabora.com>
    Change-Id: I9db8459309f2806ed47f9f932e0bde246400b2dc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144854
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145759
    Tested-by: Jenkins
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>

diff --git a/filter/source/pdf/impdialog.cxx b/filter/source/pdf/impdialog.cxx
index 4a03de89fdef..2516342cde70 100644
--- a/filter/source/pdf/impdialog.cxx
+++ b/filter/source/pdf/impdialog.cxx
@@ -1171,6 +1171,10 @@ 
ImpPDFTabSecurityPage::ImpPDFTabSecurityPage(weld::Container* pPage, weld::Dialo
 
 ImpPDFTabSecurityPage::~ImpPDFTabSecurityPage()
 {
+    if (mpPasswordDialog)
+        mpPasswordDialog->response(RET_CANCEL);
+    if (mpUnsupportedMsgDialog)
+        mpUnsupportedMsgDialog->response(RET_CANCEL);
 }
 
 std::unique_ptr<SfxTabPage> ImpPDFTabSecurityPage::Create(weld::Container* 
pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet)
@@ -1261,40 +1265,51 @@ void ImpPDFTabSecurityPage::SetFilterConfigItem( const  
ImpPDFTabDialog* pParent
 
 IMPL_LINK_NOARG(ImpPDFTabSecurityPage, ClickmaPbSetPwdHdl, weld::Button&, void)
 {
-    SfxPasswordDialog aPwdDialog(m_xContainer.get(), &msUserPwdTitle);
-    aPwdDialog.SetMinLen(0);
-    aPwdDialog.ShowMinLengthText(false);
-    aPwdDialog.ShowExtras( SfxShowExtras::CONFIRM | SfxShowExtras::PASSWORD2 | 
SfxShowExtras::CONFIRM2 );
-    aPwdDialog.set_title(msStrSetPwd);
-    aPwdDialog.SetGroup2Text(msOwnerPwdTitle);
-    aPwdDialog.AllowAsciiOnly();
-    if (aPwdDialog.run() == RET_OK)  // OK issued get password and set it
-    {
-        OUString aUserPW(aPwdDialog.GetPassword());
-        OUString aOwnerPW(aPwdDialog.GetPassword2());
+    if(mpPasswordDialog)
+        mpPasswordDialog->response(RET_CANCEL);
 
-        mbHaveUserPassword = !aUserPW.isEmpty();
-        mbHaveOwnerPassword = !aOwnerPW.isEmpty();
+    mpPasswordDialog = std::make_shared<SfxPasswordDialog>(m_xContainer.get(), 
&msUserPwdTitle);
 
-        mxPreparedPasswords = vcl::PDFWriter::InitEncryption( aOwnerPW, 
aUserPW );
-        if (!mxPreparedPasswords.is()) {
-            OUString msg;
-            ErrorHandler::GetErrorString(ERRCODE_IO_NOTSUPPORTED, msg); 
//TODO: handle failure
-            std::unique_ptr<weld::MessageDialog>(
-                Application::CreateMessageDialog(
-                    GetFrameWeld(), VclMessageType::Error, VclButtonsType::Ok, 
msg))
-                ->run();
-            return;
-        }
+    mpPasswordDialog->SetMinLen(0);
+    mpPasswordDialog->ShowMinLengthText(false);
+    mpPasswordDialog->ShowExtras( SfxShowExtras::CONFIRM | 
SfxShowExtras::PASSWORD2 | SfxShowExtras::CONFIRM2 );
+    mpPasswordDialog->set_title(msStrSetPwd);
+    mpPasswordDialog->SetGroup2Text(msOwnerPwdTitle);
+    mpPasswordDialog->AllowAsciiOnly();
+
+    mpPasswordDialog->PreRun();
 
-        if( mbHaveOwnerPassword )
+    weld::DialogController::runAsync(mpPasswordDialog, [this](sal_Int32 
response){
+        if (response == RET_OK)
         {
-            maPreparedOwnerPassword = 
comphelper::OStorageHelper::CreatePackageEncryptionData( aOwnerPW );
+            OUString aUserPW(mpPasswordDialog->GetPassword());
+            OUString aOwnerPW(mpPasswordDialog->GetPassword2());
+
+            mbHaveUserPassword = !aUserPW.isEmpty();
+            mbHaveOwnerPassword = !aOwnerPW.isEmpty();
+
+            mxPreparedPasswords = vcl::PDFWriter::InitEncryption( aOwnerPW, 
aUserPW );
+            if (!mxPreparedPasswords.is())
+            {
+                OUString msg;
+                ErrorHandler::GetErrorString(ERRCODE_IO_NOTSUPPORTED, msg); 
//TODO: handle failure
+                mpUnsupportedMsgDialog = std::shared_ptr<weld::MessageDialog>(
+                Application::CreateMessageDialog(
+                    GetFrameWeld(), VclMessageType::Error, VclButtonsType::Ok, 
msg));
+
+                mpUnsupportedMsgDialog->runAsync(mpUnsupportedMsgDialog, 
[](sal_Int32){ });
+                return;
+            }
+
+            if( mbHaveOwnerPassword )
+                maPreparedOwnerPassword = 
comphelper::OStorageHelper::CreatePackageEncryptionData( aOwnerPW );
+            else
+                maPreparedOwnerPassword = Sequence< NamedValue >();
         }
-        else
-            maPreparedOwnerPassword = Sequence< NamedValue >();
-    }
-    enablePermissionControls();
+        if (response != RET_CANCEL)
+            enablePermissionControls();
+        mpPasswordDialog.reset();
+    });
 }
 
 void ImpPDFTabSecurityPage::enablePermissionControls()
diff --git a/filter/source/pdf/impdialog.hxx b/filter/source/pdf/impdialog.hxx
index d0d63bccc86b..dd2a9a3add98 100644
--- a/filter/source/pdf/impdialog.hxx
+++ b/filter/source/pdf/impdialog.hxx
@@ -20,6 +20,7 @@
 #pragma once
 
 #include <sfx2/tabdlg.hxx>
+#include <sfx2/passwd.hxx>
 #include <svx/AccessibilityCheckDialog.hxx>
 
 #include <vcl/pdfwriter.hxx>
@@ -346,6 +347,9 @@ class ImpPDFTabSecurityPage : public SfxTabPage
     std::unique_ptr<weld::CheckButton> mxCbEnableAccessibility;
     std::unique_ptr<weld::Label> mxPasswordTitle;
 
+    std::shared_ptr< SfxPasswordDialog > mpPasswordDialog;
+    std::shared_ptr< weld::MessageDialog > mpUnsupportedMsgDialog;
+
     DECL_LINK(ClickmaPbSetPwdHdl, weld::Button&, void);
 
     void                        enablePermissionControls();
diff --git a/include/sfx2/passwd.hxx b/include/sfx2/passwd.hxx
index 3302c370b3b2..17205a5d4933 100644
--- a/include/sfx2/passwd.hxx
+++ b/include/sfx2/passwd.hxx
@@ -64,6 +64,8 @@ private:
 
     std::unique_ptr<weld::Button> m_xOKBtn;
 
+    std::shared_ptr<weld::MessageDialog> m_xConfirmFailedDialog;
+
     OUString        maMinLenPwdStr;
     OUString        maMinLenPwdStr1;
     OUString        maEmptyPwdStr;
@@ -122,7 +124,11 @@ public:
     void AllowAsciiOnly();
     void ShowMinLengthText(bool bShow);
 
+    void PreRun();
+
     virtual short run() override;
+
+    ~SfxPasswordDialog();
 };
 
 #endif // INCLUDED_SFX2_PASSWD_HXX
diff --git a/sfx2/source/dialog/passwd.cxx b/sfx2/source/dialog/passwd.cxx
index 13822c4a94d4..51f3abd84c0c 100644
--- a/sfx2/source/dialog/passwd.cxx
+++ b/sfx2/source/dialog/passwd.cxx
@@ -74,12 +74,18 @@ IMPL_LINK_NOARG(SfxPasswordDialog, OKHdl, weld::Button&, 
void)
         bConfirmFailed = true;
     if ( bConfirmFailed )
     {
-        std::unique_ptr<weld::MessageDialog> 
xBox(Application::CreateMessageDialog(m_xDialog.get(),
-                                                                 
VclMessageType::Warning, VclButtonsType::Ok,
-                                                                 
SfxResId(STR_ERROR_WRONG_CONFIRM)));
-        xBox->run();
-        m_xConfirm1ED->set_text(OUString());
-        m_xConfirm1ED->grab_focus();
+        if (m_xConfirmFailedDialog)
+            m_xConfirmFailedDialog->response(RET_CANCEL);
+
+        m_xConfirmFailedDialog =
+            
std::shared_ptr<weld::MessageDialog>(Application::CreateMessageDialog(m_xDialog.get(),
+                                                    VclMessageType::Warning, 
VclButtonsType::Ok,
+                                                    
SfxResId(STR_ERROR_WRONG_CONFIRM)));
+        m_xConfirmFailedDialog->runAsync(m_xConfirmFailedDialog, 
[this](sal_uInt32 response){
+            m_xConfirm1ED->set_text(OUString());
+            m_xConfirm1ED->grab_focus();
+            m_xConfirmFailedDialog->response(response);
+         });
     }
     else
         m_xDialog->response(RET_OK);
@@ -165,7 +171,7 @@ void SfxPasswordDialog::AllowAsciiOnly()
     m_xOnlyAsciiFT->show();
 }
 
-short SfxPasswordDialog::run()
+void SfxPasswordDialog::PreRun()
 {
     m_xUserFT->hide();
     m_xUserED->hide();
@@ -202,8 +208,18 @@ short SfxPasswordDialog::run()
         m_xConfirm2FT->show();
         m_xConfirm2ED->show();
     }
+}
+
+short SfxPasswordDialog::run()
+{
+    PreRun();
 
     return GenericDialogController::run();
 }
 
+SfxPasswordDialog::~SfxPasswordDialog()
+{
+    if (m_xConfirmFailedDialog)
+        m_xConfirmFailedDialog->response(RET_CANCEL);
+}
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/jsdialog/enabled.cxx b/vcl/jsdialog/enabled.cxx
index d92d75e8210f..2dff20b7263d 100644
--- a/vcl/jsdialog/enabled.cxx
+++ b/vcl/jsdialog/enabled.cxx
@@ -86,6 +86,7 @@ bool isBuilderEnabled(std::u16string_view rUIFile, bool 
bMobile)
         || rUIFile == u"sfx/ui/documentpropertiesdialog.ui"
         || rUIFile == u"sfx/ui/editdurationdialog.ui"
         || rUIFile == u"sfx/ui/linefragment.ui"
+        || rUIFile == u"sfx/ui/password.ui"
         // svx
         || rUIFile == u"svx/ui/accessibilitycheckdialog.ui"
         || rUIFile == u"svx/ui/accessibilitycheckentry.ui"

Reply via email to