Kaydet (Commit) 44bf46c1 authored tarafından Caolán McNamara's avatar Caolán McNamara

weld MacroWarning

Change-Id: I9ec8ce9b0d5bb973f75606d850fb5961a85865cd
Reviewed-on: https://gerrit.libreoffice.org/51630Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 2333786a
......@@ -55,7 +55,6 @@
#include <vcl/dllapi.h>
#include <vcl/errcode.hxx>
#include <vcl/layout.hxx>
#include <vcl/msgbox.hxx>
#include <vcl/svapp.hxx>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
......
......@@ -1173,20 +1173,20 @@ UUIInteractionHelper::handleMacroConfirmRequest(
bool bApprove = false;
bool bShowSignatures = aSignInfo.getLength() > 0;
ScopedVclPtrInstance<MacroWarning> aWarning(
getParentProperty(), bShowSignatures );
vcl::Window* pWin = getParentProperty();
MacroWarning aWarning(pWin ? pWin->GetFrameWeld() : nullptr, bShowSignatures);
aWarning->SetDocumentURL( aDocumentURL );
aWarning.SetDocumentURL(aDocumentURL);
if ( aSignInfo.getLength() > 1 )
{
aWarning->SetStorage( xZipStorage, aDocumentVersion, aSignInfo );
aWarning.SetStorage(xZipStorage, aDocumentVersion, aSignInfo);
}
else if ( aSignInfo.getLength() == 1 )
{
aWarning->SetCertificate( aSignInfo[ 0 ].Signer );
aWarning.SetCertificate(aSignInfo[0].Signer);
}
bApprove = aWarning->Execute() == RET_OK;
bApprove = aWarning.run() == RET_OK;
if ( bApprove && xApprove.is() )
xApprove->select();
......
......@@ -23,10 +23,9 @@
#include <comphelper/sequence.hxx>
#include <comphelper/documentconstants.hxx>
#include <comphelper/processfactory.hxx>
#include <osl/file.h>
#include <sal/macros.h>
#include <vcl/fixed.hxx>
#include <vcl/msgbox.hxx>
#include <unotools/resmgr.hxx>
#include <com/sun/star/security/NoPasswordException.hpp>
using namespace ::com::sun::star::security;
......@@ -62,58 +61,37 @@ namespace
}
}
MacroWarning::MacroWarning( vcl::Window* _pParent, bool _bWithSignatures )
:ModalDialog ( _pParent, "MacroWarnMedium", "uui/ui/macrowarnmedium.ui" )
,mpInfos ( nullptr )
,mbSignedMode ( true )
,mbShowSignatures ( _bWithSignatures )
,mnActSecLevel ( 0 )
MacroWarning::MacroWarning(weld::Window* pParent, bool _bWithSignatures)
: MessageDialogController(pParent, "uui/ui/macrowarnmedium.ui", "MacroWarnMedium", "grid")
, mxGrid(m_xBuilder->weld_widget("grid"))
, mxSignsFI(m_xBuilder->weld_label("signsLabel"))
, mxViewSignsBtn(m_xBuilder->weld_button("viewSignsButton"))
, mxAlwaysTrustCB(m_xBuilder->weld_check_button("alwaysTrustCheckbutton"))
, mxEnableBtn(m_xBuilder->weld_button("ok"))
, mxDisableBtn(m_xBuilder->weld_button("cancel"))
, mpInfos ( nullptr )
, mbSignedMode ( true )
, mbShowSignatures ( _bWithSignatures )
, mnActSecLevel ( 0 )
{
get(mpSymbolImg, "symbolImage");
get(mpDocNameFI, "docNameLabel");
get(mpDescr1FI, "descr1Label");
get(mpDescr1aFI, "descr1aLabel");
get(mpSignsFI, "signsLabel");
get(mpViewSignsBtn, "viewSignsButton");
get(mpDescr2FI, "descr2Label");
get(mpAlwaysTrustCB, "alwaysTrustCheckbutton");
get(mpEnableBtn, "ok");
get(mpDisableBtn, "cancel");
m_xDialog->set_title(Translate::GetReadStringHook()(m_xDialog->get_title()));
InitControls();
mpDisableBtn->SetClickHdl( LINK( this, MacroWarning, DisableBtnHdl ) );
mpEnableBtn->SetClickHdl( LINK( this, MacroWarning, EnableBtnHdl ) );
mpDisableBtn->GrabFocus(); // Default button, but focus is on view button
}
MacroWarning::~MacroWarning()
{
disposeOnce();
}
void MacroWarning::dispose()
{
mpSymbolImg.clear();
mpDocNameFI.clear();
mpDescr1aFI.clear();
mpDescr1FI.clear();
mpSignsFI.clear();
mpViewSignsBtn.clear();
mpDescr2FI.clear();
mpAlwaysTrustCB.clear();
mpEnableBtn.clear();
mpDisableBtn.clear();
ModalDialog::dispose();
mxEnableBtn->connect_clicked(LINK(this, MacroWarning, EnableBtnHdl));
mxDisableBtn->grab_focus(); // Default button, but focus is on view button
}
void MacroWarning::SetDocumentURL( const OUString& rDocURL )
{
mpDocNameFI->SetText( rDocURL );
OUString aAbbreviatedPath;
osl_abbreviateSystemPath(rDocURL.pData, &aAbbreviatedPath.pData, 50, nullptr);
fprintf(stderr, "in %s, out %s\n", OUStringToOString(rDocURL, RTL_TEXTENCODING_UTF8).getStr(),
OUStringToOString(aAbbreviatedPath, RTL_TEXTENCODING_UTF8).getStr());
m_xDialog->set_primary_text(aAbbreviatedPath);
}
IMPL_LINK_NOARG(MacroWarning, ViewSignsBtnHdl, Button*, void)
IMPL_LINK_NOARG(MacroWarning, ViewSignsBtnHdl, weld::Button&, void)
{
DBG_ASSERT( mxCert.is(), "*MacroWarning::ViewSignsBtnHdl(): no certificate set!" );
......@@ -128,9 +106,9 @@ IMPL_LINK_NOARG(MacroWarning, ViewSignsBtnHdl, Button*, void)
}
}
IMPL_LINK_NOARG(MacroWarning, EnableBtnHdl, Button*, void)
IMPL_LINK_NOARG(MacroWarning, EnableBtnHdl, weld::Button&, void)
{
if( mbSignedMode && mpAlwaysTrustCB->IsChecked() )
if (mbSignedMode && mxAlwaysTrustCB->get_active())
{ // insert path into trusted path list
uno::Reference< security::XDocumentDigitalSignatures > xD(
security::DocumentDigitalSignatures::createWithVersion(comphelper::getProcessComponentContext(), maODFVersion));
......@@ -145,56 +123,32 @@ IMPL_LINK_NOARG(MacroWarning, EnableBtnHdl, Button*, void)
xD->addAuthorToTrustedSources( (*mpInfos)[ i ].Signer );
}
}
EndDialog( RET_OK );
}
IMPL_LINK_NOARG(MacroWarning, DisableBtnHdl, Button*, void)
{
EndDialog();
m_xDialog->response(RET_OK);
}
IMPL_LINK_NOARG(MacroWarning, AlwaysTrustCheckHdl, Button*, void)
IMPL_LINK_NOARG(MacroWarning, AlwaysTrustCheckHdl, weld::Button&, void)
{
bool bEnable = ( mnActSecLevel < 2 || mpAlwaysTrustCB->IsChecked() );
mpEnableBtn->Enable( bEnable );
mpDisableBtn->Enable( !mpAlwaysTrustCB->IsChecked() );
const bool bEnable = (mnActSecLevel < 2 || mxAlwaysTrustCB->get_active());
mxEnableBtn->set_sensitive(bEnable);
mxDisableBtn->set_sensitive(!mxAlwaysTrustCB->get_active());
}
void MacroWarning::InitControls()
{
// set warning image
Image aImg(GetStandardWarningBoxImage());
mpSymbolImg->SetImage( aImg );
mpSymbolImg->SetSizePixel( aImg.GetSizePixel() );
// set bold font and path ellipsis for docname fixedtext
vcl::Font aTmpFont = mpDocNameFI->GetControlFont();
aTmpFont.SetWeight( WEIGHT_BOLD );
mpDocNameFI->SetControlFont( aTmpFont );
WinBits nStyle = mpDocNameFI->GetStyle();
nStyle |= WB_PATHELLIPSIS;
mpDocNameFI->SetStyle( nStyle );
// show signature controls?
if( mbShowSignatures )
if (mbShowSignatures)
{
mpViewSignsBtn->SetClickHdl( LINK( this, MacroWarning, ViewSignsBtnHdl ) );
mpViewSignsBtn->Disable(); // default
mpAlwaysTrustCB->SetClickHdl( LINK( this, MacroWarning, AlwaysTrustCheckHdl ) );
mxViewSignsBtn->connect_clicked(LINK(this, MacroWarning, ViewSignsBtnHdl));
mxViewSignsBtn->set_sensitive(false); // default
mxAlwaysTrustCB->connect_clicked(LINK(this, MacroWarning, AlwaysTrustCheckHdl));
mnActSecLevel = SvtSecurityOptions().GetMacroSecurityLevel();
if ( mnActSecLevel >= 2 )
mpEnableBtn->Disable();
mxEnableBtn->set_sensitive(false);
}
else
{
mpDescr1FI->Hide();
mpDescr1aFI->Show();
mpSignsFI->Hide();
mpViewSignsBtn->Hide();
mpAlwaysTrustCB->Hide();
// move hint up to position of signer list
mpDescr2FI->SetPosPixel( mpSignsFI->GetPosPixel() );
mxGrid->hide();
}
}
......@@ -218,8 +172,8 @@ void MacroWarning::SetStorage( const css::uno::Reference < css::embed::XStorage
s += GetContentPart( rInfos[ i ].Signer->getSubjectName(), aCN_Id );
}
mpSignsFI->SetText( s );
mpViewSignsBtn->Enable();
mxSignsFI->set_label(s);
mxViewSignsBtn->set_sensitive(true);
}
}
......@@ -229,8 +183,8 @@ void MacroWarning::SetCertificate( const css::uno::Reference< css::security::XCe
if( mxCert.is() )
{
OUString s = GetContentPart( mxCert->getSubjectName(), "CN" );
mpSignsFI->SetText( s );
mpViewSignsBtn->Enable();
mxSignsFI->set_label(s);
mxViewSignsBtn->set_sensitive(true);
}
}
......
......@@ -20,11 +20,9 @@
#ifndef INCLUDED_UUI_SOURCE_SECMACROWARNINGS_HXX
#define INCLUDED_UUI_SOURCE_SECMACROWARNINGS_HXX
#include <vcl/dialog.hxx>
#include <unotools/securityoptions.hxx>
#include <vcl/button.hxx>
#include <vcl/fixed.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <unotools/securityoptions.hxx>
#include <vcl/weld.hxx>
namespace com {
namespace sun {
......@@ -33,41 +31,33 @@ namespace security {
class XCertificate; }
}}}
class MacroWarning : public ModalDialog
class MacroWarning : public weld::MessageDialogController
{
private:
std::unique_ptr<weld::Widget> mxGrid;
std::unique_ptr<weld::Label> mxSignsFI;
std::unique_ptr<weld::Button> mxViewSignsBtn;
std::unique_ptr<weld::CheckButton> mxAlwaysTrustCB;
std::unique_ptr<weld::Button> mxEnableBtn;
std::unique_ptr<weld::Button> mxDisableBtn;
css::uno::Reference< css::security::XCertificate > mxCert;
css::uno::Reference< css::embed::XStorage > mxStore;
OUString maODFVersion;
const css::uno::Sequence< css::security::DocumentSignatureInformation >* mpInfos;
VclPtr<FixedImage> mpSymbolImg;
VclPtr<FixedText> mpDocNameFI;
VclPtr<FixedText> mpDescr1FI;
VclPtr<FixedText> mpDescr1aFI;
VclPtr<FixedText> mpSignsFI;
VclPtr<PushButton> mpViewSignsBtn;
VclPtr<FixedText> mpDescr2FI;
VclPtr<CheckBox> mpAlwaysTrustCB;
VclPtr<PushButton> mpEnableBtn;
VclPtr<PushButton> mpDisableBtn;
const bool mbSignedMode; // mode of dialog (signed / unsigned macros)
const bool mbShowSignatures;
sal_Int32 mnActSecLevel;
DECL_LINK( ViewSignsBtnHdl, Button*, void );
DECL_LINK( EnableBtnHdl, Button*, void );
DECL_LINK( DisableBtnHdl, Button*, void );
DECL_LINK( AlwaysTrustCheckHdl, Button*, void );
DECL_LINK(ViewSignsBtnHdl, weld::Button&, void);
DECL_LINK(EnableBtnHdl, weld::Button&, void);
DECL_LINK(AlwaysTrustCheckHdl, weld::Button&, void);
void InitControls();
public:
MacroWarning( vcl::Window* pParent, bool _bShowSignatures );
virtual ~MacroWarning() override;
virtual void dispose() override;
MacroWarning(weld::Window* pParent, bool _bShowSignatures);
void SetDocumentURL( const OUString& rDocURL );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment