diff options
author | Katarina Behrens <Katarina.Behrens@cib.de> | 2017-05-29 15:53:19 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2017-06-01 02:14:12 +0200 |
commit | bd8b8ccd3110a9f6fa7fb4f2aec3275f7b650052 (patch) | |
tree | 38f5aaf6e535e548aa0bfdb26b63dd034945015e /sfx2 | |
parent | ddcd9c3a6e78131d511e91f832ab33c41d41916d (diff) |
tdf#105566: Add/remove infobar when the signature status changes
this time without stack overflow. Updating existing infobar needs
some work still
This patch is partially based on work of samuel_m
Change-Id: I2c44c14e27cf85a1014b01e5588b7b53990033b9
Reviewed-on: https://gerrit.libreoffice.org/38148
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
(cherry picked from commit e744e9f4492d3013742fcdb6254cd76528870e9d)
Reviewed-on: https://gerrit.libreoffice.org/38255
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/dialog/infobar.cxx | 5 | ||||
-rw-r--r-- | sfx2/source/doc/objserv.cxx | 60 | ||||
-rw-r--r-- | sfx2/source/view/viewfrm.cxx | 50 |
3 files changed, 79 insertions, 36 deletions
diff --git a/sfx2/source/dialog/infobar.cxx b/sfx2/source/dialog/infobar.cxx index 69b4df48df69..b093718f4e86 100644 --- a/sfx2/source/dialog/infobar.cxx +++ b/sfx2/source/dialog/infobar.cxx @@ -359,6 +359,11 @@ VclPtr<SfxInfoBarWindow> SfxInfoBarContainerWindow::getInfoBar(const OUString& s return nullptr; } +bool SfxInfoBarContainerWindow::hasInfoBarWithID( const OUString &sId ) +{ + return ( getInfoBar( sId ) != nullptr ); +} + void SfxInfoBarContainerWindow::removeInfoBar(VclPtr<SfxInfoBarWindow> const & pInfoBar) { // Remove diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index 6e1f008627df..edebf6a3cae5 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -64,6 +64,7 @@ #include <unotools/saveopt.hxx> #include <svtools/asynclink.hxx> #include <comphelper/documentconstants.hxx> +#include <tools/link.hxx> #include <sfx2/app.hxx> #include <sfx2/signaturestate.hxx> @@ -90,6 +91,7 @@ #include <sfx2/msgpool.hxx> #include <sfx2/objface.hxx> #include <sfx2/checkin.hxx> +#include <sfx2/infobar.hxx> #include "app.hrc" #include <com/sun/star/document/XDocumentSubStorageSupplier.hpp> @@ -1033,6 +1035,60 @@ void SfxObjectShell::GetState_Impl(SfxItemSet &rSet) } case SID_SIGNATURE: { + SfxViewFrame *pFrame = SfxViewFrame::Current(); + if ( pFrame ) + { + SignatureState eState = GetDocumentSignatureState(); + InfoBarType aInfoBarType(InfoBarType::Info); + OUString sMessage(""); + + switch (eState) + { + 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; + } + + // new info bar + if ( !pFrame->HasInfoBarWithID("signature") ) + { + + if (!sMessage.isEmpty()) + { + auto pInfoBar = pFrame->AppendInfoBar("signature", sMessage, aInfoBarType); + if (pInfoBar == nullptr) + return; + VclPtrInstance<PushButton> xBtn(&(pFrame->GetWindow())); + xBtn->SetText(SfxResId(STR_SIGNATURE_SHOW)); + xBtn->SetSizePixel(xBtn->GetOptimalSize()); + xBtn->SetClickHdl(LINK(this, SfxObjectShell, SignDocumentHandler)); + pInfoBar->addButton(xBtn); + } + } + else // signature info bar exists already + { + if (eState == SignatureState::NOSIGNATURES ) + pFrame->RemoveInfoBar("signature"); + //FIXME: Update existing info bar + } + + } + rSet.Put( SfxUInt16Item( SID_SIGNATURE, static_cast<sal_uInt16>(GetDocumentSignatureState()) ) ); break; } @@ -1049,6 +1105,10 @@ void SfxObjectShell::GetState_Impl(SfxItemSet &rSet) } } +IMPL_LINK_NOARG(SfxObjectShell, SignDocumentHandler, Button*, void) +{ + GetDispatcher()->Execute(SID_SIGNATURE); +} void SfxObjectShell::ExecProps_Impl(SfxRequest &rReq) { diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index 6b7f5ea63076..aafff1ff21b6 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<PushButton> 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() && @@ -3054,4 +3018,18 @@ void SfxViewFrame::RemoveInfoBar( const OUString& sId ) } } +bool SfxViewFrame::HasInfoBarWithID( const OUString& sId ) +{ + const sal_uInt16 nId = SfxInfoBarContainerChild::GetChildWindowId(); + + SfxChildWindow* pChild = GetChildWindow(nId); + if (pChild) + { + SfxInfoBarContainerWindow* pInfoBarContainer = static_cast<SfxInfoBarContainerWindow*>(pChild->GetWindow()); + return pInfoBarContainer->hasInfoBarWithID(sId); + } + + return false; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |