Use correct object
[LibreOffice.git] / cui / source / options / securityoptions.cxx
blob02fab4bfdeee511edb1fab1bfb5510df6e8c51bc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <securityoptions.hxx>
21 #include <unotools/securityoptions.hxx>
23 namespace
25 bool enableAndSet(SvtSecurityOptions::EOption eOption,
26 weld::CheckButton& rCheckBox, weld::Widget& rFixedImage)
28 bool bEnable = !SvtSecurityOptions::IsReadOnly(eOption);
29 rCheckBox.set_sensitive(bEnable);
30 rFixedImage.set_visible(!bEnable);
31 rCheckBox.set_active(SvtSecurityOptions::IsOptionSet(eOption));
32 return bEnable;
35 void CheckAndSave(SvtSecurityOptions::EOption _eOpt, const bool _bIsChecked, bool& _rModified)
37 if (!SvtSecurityOptions::IsReadOnly(_eOpt) && SvtSecurityOptions::IsOptionSet(_eOpt) != _bIsChecked)
39 SvtSecurityOptions::SetOption(_eOpt, _bIsChecked);
40 _rModified = true;
45 namespace svx
48 SecurityOptionsDialog::SecurityOptionsDialog(weld::Window* pParent)
49 : GenericDialogController(pParent, u"cui/ui/securityoptionsdialog.ui"_ustr, u"SecurityOptionsDialog"_ustr)
50 , m_xSaveOrSendDocsCB(m_xBuilder->weld_check_button(u"savesenddocs"_ustr))
51 , m_xSaveOrSendDocsImg(m_xBuilder->weld_widget(u"locksavesenddocs"_ustr))
52 , m_xSignDocsCB(m_xBuilder->weld_check_button(u"whensigning"_ustr))
53 , m_xSignDocsImg(m_xBuilder->weld_widget(u"lockwhensigning"_ustr))
54 , m_xPrintDocsCB(m_xBuilder->weld_check_button(u"whenprinting"_ustr))
55 , m_xPrintDocsImg(m_xBuilder->weld_widget(u"lockwhenprinting"_ustr))
56 , m_xCreatePdfCB(m_xBuilder->weld_check_button(u"whenpdf"_ustr))
57 , m_xCreatePdfImg(m_xBuilder->weld_widget(u"lockwhenpdf"_ustr))
58 , m_xRemovePersInfoCB(m_xBuilder->weld_check_button(u"removepersonal"_ustr))
59 , m_xRemovePersInfoImg(m_xBuilder->weld_widget(u"lockremovepersonal"_ustr))
60 , m_xRecommPasswdCB(m_xBuilder->weld_check_button(u"password"_ustr))
61 , m_xRecommPasswdImg(m_xBuilder->weld_widget(u"lockpassword"_ustr))
62 , m_xCtrlHyperlinkCB(m_xBuilder->weld_check_button(u"ctrlclick"_ustr))
63 , m_xCtrlHyperlinkImg(m_xBuilder->weld_widget(u"lockctrlclick"_ustr))
64 , m_xBlockUntrustedRefererLinksCB(m_xBuilder->weld_check_button(u"blockuntrusted"_ustr))
65 , m_xBlockUntrustedRefererLinksImg(m_xBuilder->weld_widget(u"lockblockuntrusted"_ustr))
66 , m_xDisableActiveContentCB(m_xBuilder->weld_check_button(u"disableactivecontent"_ustr))
67 , m_xDisableActiveContentImg(m_xBuilder->weld_widget(u"lockdisableactivecontent"_ustr))
68 , m_xRedlineinfoCB(m_xBuilder->weld_check_button(u"redlineinfo"_ustr))
69 , m_xRedlineinfoImg(m_xBuilder->weld_widget(u"lockredlineinfo"_ustr))
70 , m_xDocPropertiesCB(m_xBuilder->weld_check_button(u"docproperties"_ustr))
71 , m_xDocPropertiesImg(m_xBuilder->weld_widget(u"lockdocproperties"_ustr))
72 , m_xNoteAuthorCB(m_xBuilder->weld_check_button(u"noteauthor"_ustr))
73 , m_xNoteAuthorImg(m_xBuilder->weld_widget(u"locknoteauthor"_ustr))
74 , m_xDocumentVersionCB(m_xBuilder->weld_check_button(u"documentversion"_ustr))
75 , m_xDocumentVersionImg(m_xBuilder->weld_widget(u"lockdocumentversion"_ustr))
76 , m_xPrinterSettingsCB(m_xBuilder->weld_check_button(u"printersettings"_ustr))
77 , m_xPrinterSettingsImg(m_xBuilder->weld_widget(u"lockprintersettings"_ustr))
79 m_xRemovePersInfoCB->connect_toggled(LINK(this, SecurityOptionsDialog, ShowPersonalInfosToggle));
80 init();
83 IMPL_LINK_NOARG(SecurityOptionsDialog, ShowPersonalInfosToggle, weld::Toggleable&, void)
85 changeKeepSecurityInfosEnabled();
88 void SecurityOptionsDialog::init()
90 enableAndSet(SvtSecurityOptions::EOption::DocWarnSaveOrSend, *m_xSaveOrSendDocsCB,
91 *m_xSaveOrSendDocsImg);
92 enableAndSet(SvtSecurityOptions::EOption::DocWarnSigning, *m_xSignDocsCB,
93 *m_xSignDocsImg);
94 enableAndSet(SvtSecurityOptions::EOption::DocWarnPrint, *m_xPrintDocsCB,
95 *m_xPrintDocsImg);
96 enableAndSet(SvtSecurityOptions::EOption::DocWarnCreatePdf, *m_xCreatePdfCB,
97 *m_xCreatePdfImg);
98 enableAndSet(SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo, *m_xRemovePersInfoCB,
99 *m_xRemovePersInfoImg);
100 enableAndSet(SvtSecurityOptions::EOption::DocWarnKeepRedlineInfo, *m_xRedlineinfoCB,
101 *m_xRedlineinfoImg);
102 enableAndSet(SvtSecurityOptions::EOption::DocWarnKeepDocUserInfo, *m_xDocPropertiesCB,
103 *m_xDocPropertiesImg);
104 enableAndSet(SvtSecurityOptions::EOption::DocWarnKeepNoteAuthorDateInfo, *m_xNoteAuthorCB,
105 *m_xNoteAuthorImg);
106 enableAndSet(SvtSecurityOptions::EOption::DocWarnKeepDocVersionInfo, *m_xDocumentVersionCB,
107 *m_xDocumentVersionImg);
108 enableAndSet(SvtSecurityOptions::EOption::DocKeepPrinterSettings, *m_xPrinterSettingsCB,
109 *m_xPrinterSettingsImg);
110 enableAndSet(SvtSecurityOptions::EOption::DocWarnRecommendPassword, *m_xRecommPasswdCB,
111 *m_xRecommPasswdImg);
112 enableAndSet(SvtSecurityOptions::EOption::CtrlClickHyperlink, *m_xCtrlHyperlinkCB,
113 *m_xCtrlHyperlinkImg);
114 enableAndSet(SvtSecurityOptions::EOption::BlockUntrustedRefererLinks, *m_xBlockUntrustedRefererLinksCB,
115 *m_xBlockUntrustedRefererLinksImg);
116 enableAndSet(SvtSecurityOptions::EOption::DisableActiveContent,
117 *m_xDisableActiveContentCB, *m_xDisableActiveContentImg);
119 if (!SvtSecurityOptions::IsReadOnly(SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo))
120 changeKeepSecurityInfosEnabled();
123 bool SecurityOptionsDialog::SetSecurityOptions()
125 bool bModified = false;
126 CheckAndSave(SvtSecurityOptions::EOption::DocWarnSaveOrSend, IsSaveOrSendDocsChecked(), bModified);
127 CheckAndSave(SvtSecurityOptions::EOption::DocWarnSigning, IsSignDocsChecked(), bModified);
128 CheckAndSave(SvtSecurityOptions::EOption::DocWarnPrint, IsPrintDocsChecked(), bModified);
129 CheckAndSave(SvtSecurityOptions::EOption::DocWarnCreatePdf, IsCreatePdfChecked(), bModified);
130 CheckAndSave(SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo, IsRemovePersInfoChecked(), bModified);
131 CheckAndSave(SvtSecurityOptions::EOption::DocWarnKeepRedlineInfo, IsRemoveRedlineInfoChecked(), bModified);
132 CheckAndSave(SvtSecurityOptions::EOption::DocWarnKeepDocUserInfo, IsRemoveDocUserInfoChecked(), bModified);
133 CheckAndSave(SvtSecurityOptions::EOption::DocWarnKeepNoteAuthorDateInfo, IsRemoveNoteAuthorInfoChecked(), bModified);
134 CheckAndSave(SvtSecurityOptions::EOption::DocWarnKeepDocVersionInfo, IsRemoveDocVersionInfoChecked(), bModified);
135 CheckAndSave(SvtSecurityOptions::EOption::DocKeepPrinterSettings, IsKeepPrinterSettingsChecked(), bModified);
136 CheckAndSave(SvtSecurityOptions::EOption::DocWarnRecommendPassword, IsRecommPasswdChecked(), bModified);
137 CheckAndSave(SvtSecurityOptions::EOption::CtrlClickHyperlink, IsCtrlHyperlinkChecked(), bModified);
138 CheckAndSave(SvtSecurityOptions::EOption::BlockUntrustedRefererLinks, IsBlockUntrustedRefererLinksChecked(), bModified);
139 CheckAndSave(SvtSecurityOptions::EOption::DisableActiveContent, IsDisableActiveContentChecked(), bModified);
141 return bModified;
144 void SecurityOptionsDialog::changeKeepSecurityInfosEnabled()
146 bool bEnable = m_xRemovePersInfoCB->get_active();
147 m_xRedlineinfoCB->set_sensitive(bEnable);
148 m_xDocPropertiesCB->set_sensitive(bEnable);
149 m_xNoteAuthorCB->set_sensitive(bEnable);
150 m_xDocumentVersionCB->set_sensitive(bEnable);
151 m_xPrinterSettingsCB->set_sensitive(bEnable);
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */