From d8faf3bf9a82e8f49340b5020ec4ee931cc2f3f4 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Fri, 7 Apr 2017 09:48:42 +0200 Subject: Related tdf#105566 Update Infobar when signature status changes gpg4libre Change-Id: I8f29cf16905c79d19d46662b087f4fd8778c8147 Reviewed-on: https://gerrit.libreoffice.org/36251 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt --- sfx2/Library_sfx.mk | 1 + sfx2/inc/view/signaturehelper.hxx | 32 +++++++++++++++++ sfx2/source/doc/objserv.cxx | 6 ++++ sfx2/source/view/signaturehelper.cxx | 67 ++++++++++++++++++++++++++++++++++++ sfx2/source/view/viewfrm.cxx | 36 ------------------- 5 files changed, 106 insertions(+), 36 deletions(-) create mode 100644 sfx2/inc/view/signaturehelper.hxx create mode 100644 sfx2/source/view/signaturehelper.cxx (limited to 'sfx2') diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk index f0a5a52c0cc2..2e51f1b6e21a 100644 --- a/sfx2/Library_sfx.mk +++ b/sfx2/Library_sfx.mk @@ -300,6 +300,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\ sfx2/source/view/ipclient \ sfx2/source/view/lokhelper \ sfx2/source/view/printer \ + sfx2/source/view/signaturehelper \ sfx2/source/view/sfxbasecontroller \ sfx2/source/view/userinputinterception \ sfx2/source/view/viewfac \ diff --git a/sfx2/inc/view/signaturehelper.hxx b/sfx2/inc/view/signaturehelper.hxx new file mode 100644 index 000000000000..e8dc089ba876 --- /dev/null +++ b/sfx2/inc/view/signaturehelper.hxx @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#ifndef INCLUDED_SFX2_SIGNATUREHELPER_HXX +#define INCLUDED_SFX2_SIGNATUREHELPER_HXX + +#include + +class SfxViewFrame; + +class SignatureHelper +{ +public: + SignatureHelper(SfxViewFrame* rViewFrame); + /** + * Show the appropriate infobar according to the current signature status + */ + void updateInfoBarState(SignatureState signatureState); +private: + SfxViewFrame* mrViewFrame; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ + diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index c2bdb2e5281a..d5058863a183 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -90,6 +90,7 @@ #include #include #include +#include "view/signaturehelper.hxx" #include "app.hrc" #include @@ -1036,6 +1037,11 @@ void SfxObjectShell::GetState_Impl(SfxItemSet &rSet) } case SID_SIGNATURE: { + SfxViewFrame *pFrame = SfxViewFrame::GetFirst( this ); + if ( pFrame ) + { + SignatureHelper(pFrame).updateInfoBarState(GetDocumentSignatureState()); + } rSet.Put( SfxUInt16Item( SID_SIGNATURE, static_cast(GetDocumentSignatureState()) ) ); break; } diff --git a/sfx2/source/view/signaturehelper.cxx b/sfx2/source/view/signaturehelper.cxx new file mode 100644 index 000000000000..d5b01fd5805c --- /dev/null +++ b/sfx2/source/view/signaturehelper.cxx @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "view/signaturehelper.hxx" + +#include +#include +#include +#include +#include +#include + + +SignatureHelper::SignatureHelper(SfxViewFrame* rViewFrame) +{ + mrViewFrame = rViewFrame; +} + +void SignatureHelper::updateInfoBarState(SignatureState nSignatureState) +{ + InfoBarType aInfoBarType(InfoBarType::Info); + OUString sMessage(""); + + switch (nSignatureState) + { + case SignatureState::BROKEN: + sMessage = SfxResId(STR_SIGNATURE_BROKEN); + aInfoBarType = InfoBarType::Danger; + break; + case SignatureState::NOTVALIDATED: + sMessage = SfxResId(STR_SIGNATURE_NOTVALIDATED); + aInfoBarType = InfoBarType::Warning; + break; + case SignatureState::PARTIAL_OK: + sMessage = SfxResId(STR_SIGNATURE_PARTIAL_OK); + aInfoBarType = InfoBarType::Warning; + break; + case SignatureState::OK: + sMessage = SfxResId(STR_SIGNATURE_OK); + aInfoBarType = InfoBarType::Info; + break; + default: + break; + } + + mrViewFrame->RemoveInfoBar("signature"); + if (!sMessage.isEmpty()) + { + auto pInfoBar = mrViewFrame->AppendInfoBar("signature", sMessage, aInfoBarType); + if (pInfoBar == nullptr) + return; + VclPtrInstance xBtn(&(mrViewFrame->GetWindow())); + xBtn->SetText(SfxResId(STR_SIGNATURE_SHOW)); + xBtn->SetSizePixel(xBtn->GetOptimalSize()); + xBtn->SetCommandHandler(".uno:Signature", false); // false = No status listener, else we get in an infinite loop + pInfoBar->addButton(xBtn); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ + diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index 6127ce8ab611..289bae55fb27 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -1138,42 +1138,6 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) rBind.Invalidate( SID_RELOAD ); rBind.Invalidate( SID_EDITDOC ); - SignatureState nSignatureState = GetObjectShell()->GetDocumentSignatureState(); - InfoBarType aInfoBarType(InfoBarType::Info); - OUString sMessage; - - switch (nSignatureState) - { - case SignatureState::BROKEN: - sMessage = SfxResId(STR_SIGNATURE_BROKEN); - aInfoBarType = InfoBarType::Danger; - break; - case SignatureState::NOTVALIDATED: - sMessage = SfxResId(STR_SIGNATURE_NOTVALIDATED); - aInfoBarType = InfoBarType::Warning; - break; - case SignatureState::PARTIAL_OK: - sMessage = SfxResId(STR_SIGNATURE_PARTIAL_OK); - aInfoBarType = InfoBarType::Warning; - break; - case SignatureState::OK: - sMessage = SfxResId(STR_SIGNATURE_OK); - aInfoBarType = InfoBarType::Info; - break; - default: - break; - } - - if (!sMessage.isEmpty()) - { - auto pInfoBar = AppendInfoBar("signature", sMessage, aInfoBarType); - VclPtrInstance xBtn(&GetWindow()); - xBtn->SetText(SfxResId(STR_SIGNATURE_SHOW)); - xBtn->SetSizePixel(xBtn->GetOptimalSize()); - xBtn->SetClickHdl(LINK(this, SfxViewFrame, SignDocumentHandler)); - pInfoBar->addButton(xBtn); - } - const SfxViewShell *pVSh; const SfxShell *pFSh; if ( m_xObjSh->IsOriginallyReadOnlyMedium() && -- cgit