/* -*- 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/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
// check if supplied password was correct if (aPasswordHash.getLength() == 1 && aPasswordHash[0] == 1)
{ // dummy RedlinePassword from OOXML import: get real password info // from the grab-bag to verify the password const css::uno::Sequence< css::beans::PropertyValue > aDocumentProtection =
pCurDocShell->GetDocumentProtectionFromGrabBag();
bRes = // password is ok, if there is no DocumentProtection in the GrabBag, // i.e. the dummy RedlinePassword imported from an OpenDocument file
!aDocumentProtection.hasElements() || // verify password with the password info imported from OOXML
::comphelper::DocPasswordHelper::IsModifyPasswordCorrect( rPassword,
::comphelper::DocPasswordHelper::ConvertPasswordInfo ( aDocumentProtection ) );
} else
{
uno::Sequence< sal_Int8 > aNewPasswd( aPasswordHash );
SvPasswordHelper::GetHashPassword( aNewPasswd, rPassword );
bRes = SvPasswordHelper::CompareHashPassword( aPasswordHash, rPassword );
}
std::unique_ptr<weld::CheckButton> m_xOpenReadonlyCB;
std::unique_ptr<weld::CheckButton> m_xRecordChangesCB; // for record changes
std::unique_ptr<weld::Button> m_xProtectPB; // for record changes
std::unique_ptr<weld::Button> m_xUnProtectPB; // for record changes
m_xProtectPB->set_sensitive(!bIsReadonly);
m_xUnProtectPB->set_sensitive(!bIsReadonly); // set the right text if (bProtection)
{
bProtect = false;
bUnProtect = true;
}
m_bOrigPasswordIsConfirmed = true; // default case if no password is set
uno::Sequence< sal_Int8 > aPasswordHash; // check if password is available if (pCurDocShell->GetProtectionHash( aPasswordHash ) &&
aPasswordHash.hasElements())
m_bOrigPasswordIsConfirmed = false; // password found, needs to be confirmed later on
} else
{ // A Calc document that is shared will have 'm_eRedlingMode == RL_NONE' // In shared documents change recording and protection must be disabled, // similar to documents that do not support change recording at all.
m_xRecordChangesCB->set_active(false);
m_xRecordChangesCB->set_sensitive(false);
m_xProtectPB->set_sensitive(false);
m_xUnProtectPB->set_sensitive(false);
}
IMPL_LINK_NOARG(SfxSecurityPage_Impl, RecordChangesCBToggleHdl, weld::Toggleable&, void)
{ // when change recording gets disabled protection must be disabled as well if (m_xRecordChangesCB->get_active()) // the new check state is already present, thus the '!' return;
constbool bNeedPassword = !m_bOrigPasswordIsConfirmed
&& m_xUnProtectPB->get_visible(); // tdf#128230 Require password if the Unprotect button is visible if (!bAlreadyDone && bNeedPassword)
{
OUString aPasswordText;
// dialog canceled or no password provided if (!lcl_GetPassword( m_rMyTabPage.GetFrameWeld(), false, aPasswordText ))
bAlreadyDone = true;
// ask for password and if dialog is canceled or no password provided return if (lcl_IsPasswordCorrect(m_rMyTabPage.GetFrameWeld(), aPasswordText))
m_bOrigPasswordIsConfirmed = true; else
bAlreadyDone = true;
}
if (bAlreadyDone)
m_xRecordChangesCB->set_active(true); // restore original state else
{ // remember required values to change protection and change recording in // FillItemSet_Impl later on if password was correct.
m_bNewPasswordIsValid = true;
m_aNewPassword.clear();
m_xProtectPB->show();
m_xUnProtectPB->hide();
}
}
IMPL_LINK_NOARG(SfxSecurityPage_Impl, ChangeProtectionPBHdl, weld::Button&, void)
{ if (m_eRedlingMode == RL_NONE) return;
// the push button text is always the opposite of the current state. Thus: constbool bCurrentProtection = m_xUnProtectPB->get_visible();
// ask user for password (if still necessary)
OUString aPasswordText; bool bNewProtection = !bCurrentProtection; constbool bNeedPassword = bNewProtection || !m_bOrigPasswordIsConfirmed; if (bNeedPassword)
{ // ask for password and if dialog is canceled or no password provided return if (!lcl_GetPassword(m_rMyTabPage.GetFrameWeld(), bNewProtection, aPasswordText)) return;
// provided password still needs to be checked? if (!bNewProtection && !m_bOrigPasswordIsConfirmed)
{ if (lcl_IsPasswordCorrect(m_rMyTabPage.GetFrameWeld(), aPasswordText))
m_bOrigPasswordIsConfirmed = true; else return;
}
}
DBG_ASSERT( m_bOrigPasswordIsConfirmed, "ooops... this should not have happened!" );
// remember required values to change protection and change recording in // FillItemSet_Impl later on if password was correct.
m_bNewPasswordIsValid = true;
m_aNewPassword = bNewProtection? aPasswordText : OUString();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.