24#include <sfx2/sfxsids.hrc>
38#include <sfx2/strings.hrc>
46 enum RedliningMode { RL_NONE, RL_WRITER, RL_CALC };
57 bRet = SfxItemState::DEFAULT <=
nState;
65 bool QueryRecordChangesProtectionState( RedliningMode _eMode,
bool& _rValue )
68 if (_eMode != RL_NONE)
71 bRet = QueryState( nSlot, _rValue );
77 bool QueryRecordChangesState( RedliningMode _eMode,
bool& _rValue )
80 if (_eMode != RL_NONE)
83 bRet = QueryState( nSlot, _rValue );
116 uno::Sequence< sal_Int8 > aPasswordHash;
120 if (aPasswordHash.getLength() == 1 && aPasswordHash[0] == 1)
124 const css::uno::Sequence< css::beans::PropertyValue > aDocumentProtection =
129 !aDocumentProtection.hasElements() ||
136 uno::Sequence< sal_Int8 > aNewPasswd( aPasswordHash );
144 VclMessageType::Info, VclButtonsType::Ok,
145 SfxResId(RID_SVXSTR_INCORRECT_PASSWORD)));
180 : m_rMyTabPage(rTabPage)
181 , m_eRedlingMode(RL_NONE)
182 , m_bOrigPasswordIsConfirmed(false)
183 , m_bNewPasswordIsValid(false)
184 , m_aEndRedliningWarning(
SfxResId(RID_SVXSTR_END_REDLINING_WARNING))
185 , m_bEndRedliningWarningDone(false)
186 , m_xOpenReadonlyCB(rTabPage.GetBuilder().weld_check_button(
"readonly"))
187 , m_xRecordChangesCB(rTabPage.GetBuilder().weld_check_button(
"recordchanges"))
188 , m_xProtectPB(rTabPage.GetBuilder().weld_button(
"protect"))
189 , m_xUnProtectPB(rTabPage.GetBuilder().weld_button(
"unprotect"))
201 bool bModified =
false;
204 if (pCurDocShell && !pCurDocShell->
IsReadOnly())
212 DBG_ASSERT( bDoRecordChanges || !bDoChangeProtection,
"no change recording should imply no change protection" );
213 DBG_ASSERT( bDoChangeProtection || !bDoRecordChanges,
"no change protection should imply no change recording" );
214 DBG_ASSERT( !bDoChangeProtection || !
m_aNewPassword.isEmpty(),
"change protection should imply password length is > 0" );
215 DBG_ASSERT( bDoChangeProtection ||
m_aNewPassword.isEmpty(),
"no change protection should imply password length is 0" );
228 DBG_ASSERT( !bDoChangeProtection || bDoRecordChanges,
229 "change protection requires record changes to be active!" );
264 bool bIsHTMLDoc =
false;
265 bool bProtect =
true, bUnProtect =
false;
271 if (SfxItemState::DEFAULT <= pDisp->QueryState( SID_HTML_MODE, pItem ))
273 sal_uInt16 nMode = pItem->
GetValue();
278 bool bIsReadonly = pCurDocShell->
IsReadOnly();
288 if (QueryRecordChangesState( RL_WRITER, bRecordChanges ) && !bIsHTMLDoc)
290 else if (QueryRecordChangesState( RL_CALC, bRecordChanges ))
297 bool bProtection(
false);
313 uno::Sequence< sal_Int8 > aPasswordHash;
316 aPasswordHash.hasElements())
338 if (m_xRecordChangesCB->get_active())
341 bool bAlreadyDone =
false;
342 if (!m_bEndRedliningWarningDone)
345 VclMessageType::Warning, VclButtonsType::YesNo,
346 m_aEndRedliningWarning));
347 xWarn->set_default_response(
RET_NO);
351 m_bEndRedliningWarningDone =
true;
354 const bool bNeedPassword = !m_bOrigPasswordIsConfirmed
355 && m_xUnProtectPB->get_visible();
356 if (!bAlreadyDone && bNeedPassword)
358 OUString aPasswordText;
361 if (!
lcl_GetPassword( m_rMyTabPage.GetFrameWeld(),
false, aPasswordText ))
366 m_bOrigPasswordIsConfirmed =
true;
372 m_xRecordChangesCB->set_active(
true);
377 m_bNewPasswordIsValid =
true;
378 m_aNewPassword.clear();
379 m_xProtectPB->show();
380 m_xUnProtectPB->hide();
386 if (m_eRedlingMode == RL_NONE)
390 const bool bCurrentProtection = m_xUnProtectPB->get_visible();
393 OUString aPasswordText;
394 bool bNewProtection = !bCurrentProtection;
395 const bool bNeedPassword = bNewProtection || !m_bOrigPasswordIsConfirmed;
399 if (!
lcl_GetPassword(m_rMyTabPage.GetFrameWeld(), bNewProtection, aPasswordText))
403 if (!bNewProtection && !m_bOrigPasswordIsConfirmed)
406 m_bOrigPasswordIsConfirmed =
true;
411 DBG_ASSERT( m_bOrigPasswordIsConfirmed,
"ooops... this should not have happened!" );
415 m_bNewPasswordIsValid =
true;
416 m_aNewPassword = bNewProtection? aPasswordText : OUString();
418 m_xRecordChangesCB->set_active(bNewProtection);
420 m_xUnProtectPB->set_visible(bNewProtection);
421 m_xProtectPB->set_visible(!bNewProtection);
426 return std::make_unique<SfxSecurityPage>(pPage, pController, *rItemSet);
430 :
SfxTabPage(pPage, pController,
"sfx/ui/securityinfopage.ui",
"SecurityInfoPage", &rItemSet)
437 bool bModified =
false;
440 bModified =
m_pImpl->FillItemSet_Impl();
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, const ILibreOfficeKitNotifier *pNotifier=nullptr)
sal_uInt16 GetValue() const
SfxItemState QueryState(sal_uInt16 nSID, const SfxPoolItem *&rpState)
virtual bool HasChangeRecordProtection() const
virtual bool GetProtectionHash(css::uno::Sequence< sal_Int8 > &rPasswordHash)
virtual bool IsChangeRecording() const
bool IsSecurityOptOpenReadOnly() const
virtual void SetProtectionPassword(const OUString &rPassword)
virtual void SetChangeRecording(bool bActivate, bool bLockAllViews=false)
static SAL_WARN_UNUSED_RESULT SfxObjectShell * Current()
css::uno::Sequence< css::beans::PropertyValue > GetDocumentProtectionFromGrabBag() const
Gets grab-bagged password info to unprotect change tracking with verification.
void SetSecurityOptOpenReadOnly(bool bOpenReadOnly)
OUString GetPassword() const
virtual short run() override
void SetMinLen(sal_uInt16 Len)
void ShowExtras(SfxShowExtras nExtras)
virtual bool FillItemSet(SfxItemSet *) override
SfxSecurityPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &)
virtual void Reset(const SfxItemSet *) override
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *)
std::unique_ptr< SfxSecurityPage_Impl > m_pImpl
SfxDispatcher * GetDispatcher() const
This method returns a pointer to the <SfxDispatcher>, when the SfxShell is currently <UI-active> or a...
One SfxViewShell more or less represents one edit window for a document, there can be multiple ones f...
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
static SVL_DLLPUBLIC void GetHashPassword(css::uno::Sequence< sal_Int8 > &rPassHash, const char *pPass, sal_uInt32 nLen)
static SVL_DLLPUBLIC bool CompareHashPassword(const css::uno::Sequence< sal_Int8 > &rOldPassHash, std::u16string_view sNewPass)
static bool IsModifyPasswordCorrect(std::u16string_view aPassword, const css::uno::Sequence< css::beans::PropertyValue > &aInfo)
static css::uno::Sequence< css::beans::PropertyValue > ConvertPasswordInfo(const css::uno::Sequence< css::beans::PropertyValue > &aInfo)
#define DBG_ASSERT(sCon, aError)
#define LINK(Instance, Class, Member)
static bool lcl_GetPassword(weld::Window *pParent, bool bProtect, OUString &rPassword)
static bool lcl_IsPasswordCorrect(weld::Window *pParent, std::u16string_view rPassword)
IMPL_LINK_NOARG(SfxSecurityPage_Impl, RecordChangesCBToggleHdl, weld::Toggleable &, void)
OUString SfxResId(TranslateId aId)
DECL_LINK(RecordChangesCBToggleHdl, weld::Toggleable &, void)
std::unique_ptr< weld::CheckButton > m_xOpenReadonlyCB
bool m_bNewPasswordIsValid
DECL_LINK(ChangeProtectionPBHdl, weld::Button &, void)
SfxSecurityPage & m_rMyTabPage
std::unique_ptr< weld::CheckButton > m_xRecordChangesCB
bool m_bEndRedliningWarningDone
SfxSecurityPage_Impl(SfxSecurityPage &rDlg)
std::unique_ptr< weld::Button > m_xProtectPB
bool m_bOrigPasswordIsConfirmed
OUString m_aEndRedliningWarning
RedliningMode m_eRedlingMode
std::unique_ptr< weld::Button > m_xUnProtectPB