include/sfx2/strings.hrc     |    2 ++
 include/sfx2/viewfrm.hxx     |    1 +
 sfx2/source/view/viewfrm.cxx |   38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 41 insertions(+)

New commits:
commit c5d01b11db3c83cb4a89d3b388d78e20dd3990b5
Author:     Caolán McNamara <[email protected]>
AuthorDate: Wed Mar 23 13:03:30 2022 +0000
Commit:     Christian Lohmaier <[email protected]>
CommitDate: Thu Mar 31 15:37:55 2022 +0200

    add infobar to prompt to refresh to replace old format
    
    Change-Id: Id99cbf2b50a4ebf289dae6fc67e22e20afcda35b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131976
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <[email protected]>
    (cherry picked from commit bbd196ff82bda9f66b4ba32a412f10cefe6da60e)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132307
    Reviewed-by: Sophie Gautier <[email protected]>
    Reviewed-by: Christian Lohmaier <[email protected]>

diff --git a/include/sfx2/strings.hrc b/include/sfx2/strings.hrc
index 0967a31c1109..3972509c32b0 100644
--- a/include/sfx2/strings.hrc
+++ b/include/sfx2/strings.hrc
@@ -295,6 +295,8 @@
 #define STR_SIGNATURE_SHOW                      NC_("STR_SIGNATURE_SHOW", 
"Show Signatures")
 #define STR_TRACK_CHANGES_BUTTON                
NC_("STR_TRACK_CHANGES_BUTTON", "Show Toolbar")
 #define STR_TRACK_CHANGES_BUTTON_HIDE           
NC_("STR_TRACK_CHANGES_BUTTON_HIDE", "Hide Toolbar")
+#define STR_REFRESH_MASTER_PASSWORD             
NC_("STR_REFRESH_MASTER_PASSWORD", "The master password is stored in an 
outdated format, you should refresh it")
+#define STR_REFRESH_PASSWORD                    NC_("STR_REFRESH_PASSWORD", 
"Refresh Password")
 
 #define STR_CLOSE_PANE                          NC_("STR_CLOSE_PANE", "Close 
Pane")
 
diff --git a/include/sfx2/viewfrm.hxx b/include/sfx2/viewfrm.hxx
index 4585b722e487..ae38b1a88f4e 100644
--- a/include/sfx2/viewfrm.hxx
+++ b/include/sfx2/viewfrm.hxx
@@ -71,6 +71,7 @@ protected:
     DECL_LINK(SwitchReadOnlyHandler, weld::Button&, void);
     DECL_LINK(SignDocumentHandler, weld::Button&, void);
     DECL_LINK(HiddenTrackChangesHandler, weld::Button&, void);
+    DECL_DLLPRIVATE_LINK(RefreshMasterPasswordHdl, weld::Button&, void);
     SAL_DLLPRIVATE void KillDispatcher_Impl();
 
     virtual                 ~SfxViewFrame() override;
diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx
index cb5761301379..251234477315 100644
--- a/sfx2/source/view/viewfrm.cxx
+++ b/sfx2/source/view/viewfrm.cxx
@@ -33,6 +33,7 @@
 #include <com/sun/star/frame/XLoadable.hpp>
 #include <com/sun/star/frame/XLayoutManager.hpp>
 #include <com/sun/star/frame/XComponentLoader.hpp>
+#include <com/sun/star/task/PasswordContainer.hpp>
 #include <officecfg/Office/Common.hxx>
 #include <officecfg/Setup.hxx>
 #include <toolkit/helper/vclunohelper.hxx>
@@ -1478,6 +1479,22 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, 
const SfxHint& rHint )
                     batch->commit();
                 }
 
+                if (officecfg::Office::Common::Passwords::HasMaster::get() &&
+                    
officecfg::Office::Common::Passwords::StorageVersion::get() == 0)
+                {
+                    // master password stored in deprecated format
+                    VclPtr<SfxInfoBarWindow> pOldMasterPasswordInfoBar =
+                        AppendInfoBar("oldmasterpassword", "",
+                                      SfxResId(STR_REFRESH_MASTER_PASSWORD), 
InfobarType::DANGER, false);
+                    if (pOldMasterPasswordInfoBar)
+                    {
+                        weld::Button& rButton = 
pOldMasterPasswordInfoBar->addButton();
+                        rButton.set_label(SfxResId(STR_REFRESH_PASSWORD));
+                        rButton.connect_clicked(LINK(this,
+                                                   SfxViewFrame, 
RefreshMasterPasswordHdl));
+                    }
+                }
+
                 // read-only infobar if necessary
                 const SfxViewShell *pVSh;
                 const SfxShell *pFSh;
@@ -1672,6 +1689,27 @@ IMPL_LINK(SfxViewFrame, HiddenTrackChangesHandler, 
weld::Button&, rButton, void)
     }
 }
 
+IMPL_LINK_NOARG(SfxViewFrame, RefreshMasterPasswordHdl, weld::Button&, void)
+{
+    bool bChanged = false;
+    try
+    {
+        Reference< task::XPasswordContainer2 > xMasterPasswd(
+            
task::PasswordContainer::create(comphelper::getProcessComponentContext()));
+
+        css::uno::Reference<css::frame::XFrame> xFrame = 
GetFrame().GetFrameInterface();
+        css::uno::Reference<css::awt::XWindow> xContainerWindow = 
xFrame->getContainerWindow();
+
+        uno::Reference<task::XInteractionHandler> 
xTmpHandler(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(),
+                                                              
xContainerWindow));
+        bChanged = xMasterPasswd->changeMasterPassword(xTmpHandler);
+    }
+    catch (const Exception&)
+    {}
+    if (bChanged)
+        RemoveInfoBar(u"oldmasterpassword");
+}
+
 void SfxViewFrame::Construct_Impl( SfxObjectShell *pObjSh )
 {
     m_pImpl->bResizeInToOut = true;

Reply via email to