LibreOffice Module cui (master)  1
optinet2.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <sal/config.h>
21 
22 #include <string_view>
23 
24 #include <officecfg/Inet.hxx>
25 #include <officecfg/Office/Common.hxx>
26 #include <officecfg/Office/Security.hxx>
27 #include <vcl/weld.hxx>
28 #include <sfx2/filedlghelper.hxx>
29 #include <vcl/svapp.hxx>
31 #include <com/sun/star/uno/Sequence.hxx>
32 #include <tools/diagnose_ex.h>
33 
34 #include <dialmgr.hxx>
35 #include "optinet2.hxx"
36 #include <strings.hrc>
37 
38 #include <com/sun/star/security/DocumentDigitalSignatures.hpp>
39 #include <com/sun/star/task/InteractionHandler.hpp>
40 
41 #include <sal/types.h>
42 #include <sal/log.hxx>
43 #include <rtl/ustring.hxx>
44 #include <osl/file.hxx>
45 #include <com/sun/star/configuration/theDefaultProvider.hpp>
46 #include <com/sun/star/beans/NamedValue.hpp>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <com/sun/star/beans/XPropertyState.hpp>
49 #include <com/sun/star/util/XChangesBatch.hpp>
51 #include <comphelper/string.hxx>
52 
53 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
54 #include <com/sun/star/task/PasswordContainer.hpp>
55 #include <com/sun/star/task/XPasswordContainer2.hpp>
56 #include "securityoptions.hxx"
57 #include "webconninfo.hxx"
58 #include "certpath.hxx"
59 #include "tsaurls.hxx"
60 
62 
63 using namespace ::com::sun::star;
64 using namespace ::com::sun::star::uno;
65 using namespace ::sfx2;
66 
67 namespace {
68 
69 bool isValidPort(OUString const & value) {
71  return false;
72  }
73  auto const n = value.toUInt64();
74  if (n > 65535) {
75  return false;
76  }
77  if (n != 0) {
78  return true;
79  }
80  // Overflow in OUString::toUInt64 returns 0, so need to check value contains only zeroes:
81  return std::u16string_view(value).find_first_not_of(u'0') == std::u16string_view::npos;
82 }
83 
84 }
85 
86 IMPL_LINK(SvxProxyTabPage, PortChangedHdl, weld::Entry&, rEdit, void)
87 {
88  if (!isValidPort(rEdit.get_text()))
89  {
90  std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(GetFrameWeld(),
91  VclMessageType::Warning, VclButtonsType::Ok,
92  CuiResId( RID_SVXSTR_OPT_PROXYPORTS)));
93  xErrorBox->run();
94  }
95 }
96 
97 const char g_aProxyModePN[] = "ooInetProxyType";
98 const char g_aHttpProxyPN[] = "ooInetHTTPProxyName";
99 const char g_aHttpPortPN[] = "ooInetHTTPProxyPort";
100 const char g_aHttpsProxyPN[] = "ooInetHTTPSProxyName";
101 const char g_aHttpsPortPN[] = "ooInetHTTPSProxyPort";
102 const char g_aFtpProxyPN[] = "ooInetFTPProxyName";
103 const char g_aFtpPortPN[] = "ooInetFTPProxyPort";
104 const char g_aNoProxyDescPN[] = "ooInetNoProxy";
105 
106 IMPL_STATIC_LINK(SvxProxyTabPage, NumberOnlyTextFilterHdl, OUString&, rTest, bool)
107 {
108  OUStringBuffer sAllowed;
109  for (sal_Int32 i = 0, nLen = rTest.getLength(); i < nLen; ++i)
110  {
111  if (rTest[i] >= '0' && rTest[i] <= '9')
112  sAllowed.append(rTest[i]);
113  }
114  rTest = sAllowed.makeStringAndClear();
115  return true;
116 }
117 
118 IMPL_STATIC_LINK(SvxProxyTabPage, NoSpaceTextFilterHdl, OUString&, rTest, bool)
119 {
120  rTest = rTest.replaceAll(" ", "");
121  return true;
122 }
123 
124 /********************************************************************/
125 /* */
126 /* SvxProxyTabPage */
127 /* */
128 /********************************************************************/
130  : SfxTabPage(pPage, pController, "cui/ui/optproxypage.ui", "OptProxyPage", &rSet)
131  , m_xProxyModeLB(m_xBuilder->weld_combo_box("proxymode"))
132  , m_xHttpProxyFT(m_xBuilder->weld_label("httpft"))
133  , m_xHttpProxyED(m_xBuilder->weld_entry("http"))
134  , m_xHttpPortFT(m_xBuilder->weld_label("httpportft"))
135  , m_xHttpPortED(m_xBuilder->weld_entry("httpport"))
136  , m_xHttpsProxyFT(m_xBuilder->weld_label("httpsft"))
137  , m_xHttpsProxyED(m_xBuilder->weld_entry("https"))
138  , m_xHttpsPortFT(m_xBuilder->weld_label("httpsportft"))
139  , m_xHttpsPortED(m_xBuilder->weld_entry("httpsport"))
140  , m_xFtpProxyFT(m_xBuilder->weld_label("ftpft"))
141  , m_xFtpProxyED(m_xBuilder->weld_entry("ftp"))
142  , m_xFtpPortFT(m_xBuilder->weld_label("ftpportft"))
143  , m_xFtpPortED(m_xBuilder->weld_entry("ftpport"))
144  , m_xNoProxyForFT(m_xBuilder->weld_label("noproxyft"))
145  , m_xNoProxyForED(m_xBuilder->weld_entry("noproxy"))
146  , m_xNoProxyDescFT(m_xBuilder->weld_label("noproxydesc"))
147 {
148  m_xHttpProxyED->connect_insert_text(LINK(this, SvxProxyTabPage, NoSpaceTextFilterHdl));
149  m_xHttpPortED->connect_insert_text(LINK(this, SvxProxyTabPage, NumberOnlyTextFilterHdl));
150  m_xHttpPortED->connect_changed(LINK(this, SvxProxyTabPage, PortChangedHdl));
151  m_xHttpsProxyED->connect_insert_text(LINK(this, SvxProxyTabPage, NoSpaceTextFilterHdl));
152  m_xHttpsPortED->connect_insert_text(LINK(this, SvxProxyTabPage, NumberOnlyTextFilterHdl));
153  m_xHttpsPortED->connect_changed(LINK(this, SvxProxyTabPage, PortChangedHdl));
154  m_xFtpProxyED->connect_insert_text(LINK(this, SvxProxyTabPage, NoSpaceTextFilterHdl));
155  m_xFtpPortED->connect_insert_text(LINK(this, SvxProxyTabPage, NumberOnlyTextFilterHdl));
156  m_xFtpPortED->connect_changed(LINK(this, SvxProxyTabPage, PortChangedHdl));
157 
158  Link<weld::Widget&,void> aLink = LINK( this, SvxProxyTabPage, LoseFocusHdl_Impl );
159  m_xHttpPortED->connect_focus_out( aLink );
160  m_xHttpsPortED->connect_focus_out( aLink );
161  m_xFtpPortED->connect_focus_out( aLink );
162 
163  m_xProxyModeLB->connect_changed(LINK( this, SvxProxyTabPage, ProxyHdl_Impl ));
164 
165  Reference< css::lang::XMultiServiceFactory >
166  xConfigurationProvider(
167  configuration::theDefaultProvider::get(
169 
170  beans::NamedValue aProperty;
171  aProperty.Name = "nodepath";
172  aProperty.Value <<= OUString( "org.openoffice.Inet/Settings" );
173 
174  Sequence< Any > aArgumentList( 1 );
175  aArgumentList[0] <<= aProperty;
176 
177  m_xConfigurationUpdateAccess = xConfigurationProvider->createInstanceWithArguments(
178  "com.sun.star.configuration.ConfigurationUpdateAccess",
179  aArgumentList );
180 }
181 
183 {
184 }
185 
186 std::unique_ptr<SfxTabPage> SvxProxyTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet )
187 {
188  return std::make_unique<SvxProxyTabPage>(pPage, pController, *rAttrSet);
189 }
190 
192 {
193  sal_Int32 nIntValue = 0;
194 
195  std::optional<sal_Int32> x(officecfg::Inet::Settings::ooInetProxyType::get());
196  if (x)
197  {
198  nIntValue = *x;
199  m_xProxyModeLB->set_active(nIntValue);
200  }
201 
202  m_xHttpProxyED->set_text( officecfg::Inet::Settings::ooInetHTTPProxyName::get() );
203  x = officecfg::Inet::Settings::ooInetHTTPProxyPort::get();
204  if (x)
205  {
206  nIntValue = *x;
207  m_xHttpPortED->set_text( OUString::number( nIntValue ));
208  }
209 
210  m_xHttpsProxyED->set_text( officecfg::Inet::Settings::ooInetHTTPSProxyName::get() );
211  x = officecfg::Inet::Settings::ooInetHTTPSProxyPort::get();
212  if (x)
213  {
214  nIntValue = *x;
215  m_xHttpsPortED->set_text( OUString::number( nIntValue ));
216  }
217 
218  m_xFtpProxyED->set_text( officecfg::Inet::Settings::ooInetFTPProxyName::get() );
219  x = officecfg::Inet::Settings::ooInetFTPProxyPort::get();
220  if (x)
221  {
222  nIntValue = *x;
223  m_xFtpPortED->set_text( OUString::number( nIntValue ));
224  }
225 
226  m_xNoProxyForED->set_text( officecfg::Inet::Settings::ooInetNoProxy::get() );
227 }
228 
230 {
231  try
232  {
233  Reference< beans::XPropertyState > xPropertyState(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
234 
235  sal_Int32 nIntValue = 0;
236  OUString aStringValue;
237 
238  if( xPropertyState->getPropertyDefault(g_aHttpProxyPN) >>= aStringValue )
239  {
240  m_xHttpProxyED->set_text( aStringValue );
241  }
242 
243  if( xPropertyState->getPropertyDefault(g_aHttpPortPN) >>= nIntValue )
244  {
245  m_xHttpPortED->set_text( OUString::number( nIntValue ));
246  }
247 
248  if( xPropertyState->getPropertyDefault(g_aHttpsProxyPN) >>= aStringValue )
249  {
250  m_xHttpsProxyED->set_text( aStringValue );
251  }
252 
253  if( xPropertyState->getPropertyDefault(g_aHttpsPortPN) >>= nIntValue )
254  {
255  m_xHttpsPortED->set_text( OUString::number( nIntValue ));
256  }
257 
258  if( xPropertyState->getPropertyDefault(g_aFtpProxyPN) >>= aStringValue )
259  {
260  m_xFtpProxyED->set_text( aStringValue );
261  }
262 
263  if( xPropertyState->getPropertyDefault(g_aFtpPortPN) >>= nIntValue )
264  {
265  m_xFtpPortED->set_text( OUString::number( nIntValue ));
266  }
267 
268  if( xPropertyState->getPropertyDefault(g_aNoProxyDescPN) >>= aStringValue )
269  {
270  m_xNoProxyForED->set_text( aStringValue );
271  }
272  }
273  catch (const beans::UnknownPropertyException &)
274  {
275  SAL_WARN("cui.options", "SvxProxyTabPage::ReadConfigDefaults_Impl: UnknownPropertyException caught" );
276  }
277  catch (const css::lang::WrappedTargetException &) {
278  SAL_WARN("cui.options", "SvxProxyTabPage::ReadConfigDefaults_Impl: WrappedTargetException caught" );
279  }
280  catch (const RuntimeException &)
281  {
282  SAL_WARN("cui.options", "SvxProxyTabPage::ReadConfigDefaults_Impl: RuntimeException caught" );
283  }
284 }
285 
287 {
288  try
289  {
290  Reference< beans::XPropertyState > xPropertyState(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
291 
292  xPropertyState->setPropertyToDefault(g_aProxyModePN);
293  xPropertyState->setPropertyToDefault(g_aHttpProxyPN);
294  xPropertyState->setPropertyToDefault(g_aHttpPortPN);
295  xPropertyState->setPropertyToDefault(g_aHttpsProxyPN);
296  xPropertyState->setPropertyToDefault(g_aHttpsPortPN);
297  xPropertyState->setPropertyToDefault(g_aFtpProxyPN);
298  xPropertyState->setPropertyToDefault(g_aFtpPortPN);
299  xPropertyState->setPropertyToDefault(g_aNoProxyDescPN);
300 
301  Reference< util::XChangesBatch > xChangesBatch(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
302  xChangesBatch->commitChanges();
303  }
304  catch (const beans::UnknownPropertyException &)
305  {
306  SAL_WARN("cui.options", "SvxProxyTabPage::RestoreConfigDefaults_Impl: UnknownPropertyException caught" );
307  }
308  catch (const css::lang::WrappedTargetException &) {
309  SAL_WARN("cui.options", "SvxProxyTabPage::RestoreConfigDefaults_Impl: WrappedTargetException caught" );
310  }
311  catch (const RuntimeException &)
312  {
313  SAL_WARN("cui.options", "SvxProxyTabPage::RestoreConfigDefaults_Impl: RuntimeException caught" );
314  }
315 }
316 
318 {
320 
321  m_xProxyModeLB->save_value();
322  m_xHttpProxyED->save_value();
323  m_xHttpPortED->save_value();
324  m_xHttpsProxyED->save_value();
325  m_xHttpsPortED->save_value();
326  m_xFtpProxyED->save_value();
327  m_xFtpPortED->save_value();
328  m_xNoProxyForED->save_value();
329 
331 }
332 
334 {
335  bool bModified = false;
336 
337  try {
338  Reference< beans::XPropertySet > xPropertySet(m_xConfigurationUpdateAccess, UNO_QUERY_THROW );
339 
340  sal_Int32 nSelPos = m_xProxyModeLB->get_active();
341  if(m_xProxyModeLB->get_value_changed_from_saved())
342  {
343  if( nSelPos == 1 )
344  {
346  return true;
347  }
348 
349  xPropertySet->setPropertyValue(g_aProxyModePN, Any(nSelPos));
350  bModified = true;
351  }
352 
353  if(m_xHttpProxyED->get_value_changed_from_saved())
354  {
355  xPropertySet->setPropertyValue( g_aHttpProxyPN, Any(m_xHttpProxyED->get_text()));
356  bModified = true;
357  }
358 
359  if ( m_xHttpPortED->get_value_changed_from_saved())
360  {
361  xPropertySet->setPropertyValue( g_aHttpPortPN, Any(m_xHttpPortED->get_text().toInt32()));
362  bModified = true;
363  }
364 
365  if( m_xHttpsProxyED->get_value_changed_from_saved() )
366  {
367  xPropertySet->setPropertyValue( g_aHttpsProxyPN, Any(m_xHttpsProxyED->get_text()) );
368  bModified = true;
369  }
370 
371  if ( m_xHttpsPortED->get_value_changed_from_saved() )
372  {
373  xPropertySet->setPropertyValue( g_aHttpsPortPN, Any(m_xHttpsPortED->get_text().toInt32()) );
374  bModified = true;
375  }
376 
377  if( m_xFtpProxyED->get_value_changed_from_saved())
378  {
379  xPropertySet->setPropertyValue( g_aFtpProxyPN, Any(m_xFtpProxyED->get_text()) );
380  bModified = true;
381  }
382 
383  if ( m_xFtpPortED->get_value_changed_from_saved() )
384  {
385  xPropertySet->setPropertyValue( g_aFtpPortPN, Any(m_xFtpPortED->get_text().toInt32()));
386  bModified = true;
387  }
388 
389  if ( m_xNoProxyForED->get_value_changed_from_saved() )
390  {
391  xPropertySet->setPropertyValue( g_aNoProxyDescPN, Any( m_xNoProxyForED->get_text()));
392  bModified = true;
393  }
394 
395  Reference< util::XChangesBatch > xChangesBatch(m_xConfigurationUpdateAccess, UNO_QUERY_THROW);
396  xChangesBatch->commitChanges();
397  }
398  catch (const css::lang::IllegalArgumentException &) {
399  SAL_WARN("cui.options", "SvxProxyTabPage::FillItemSet: IllegalArgumentException caught" );
400  }
401  catch (const beans::UnknownPropertyException &) {
402  SAL_WARN("cui.options", "SvxProxyTabPage::FillItemSet: UnknownPropertyException caught" );
403  }
404  catch (const beans::PropertyVetoException &) {
405  SAL_WARN("cui.options", "SvxProxyTabPage::FillItemSet: PropertyVetoException caught" );
406  }
407  catch (const css::lang::WrappedTargetException &) {
408  SAL_WARN("cui.options", "SvxProxyTabPage::FillItemSet: WrappedTargetException caught" );
409  }
410  catch (const RuntimeException &) {
411  SAL_WARN("cui.options", "SvxProxyTabPage::FillItemSet: RuntimeException caught" );
412  }
413 
414  return bModified;
415 }
416 
418 {
419  m_xProxyModeLB->set_sensitive(!officecfg::Inet::Settings::ooInetNoProxy::isReadOnly());
420 
421  const bool bManualConfig = m_xProxyModeLB->get_active() == 2;
422 
423  const bool bHTTPProxyNameEnabled = bManualConfig && !officecfg::Inet::Settings::ooInetHTTPProxyName::isReadOnly();
424  const bool bHTTPProxyPortEnabled = bManualConfig && !officecfg::Inet::Settings::ooInetHTTPProxyPort::isReadOnly();
425  m_xHttpProxyFT->set_sensitive(bHTTPProxyNameEnabled);
426  m_xHttpProxyED->set_sensitive(bHTTPProxyNameEnabled);
427  m_xHttpPortFT->set_sensitive(bHTTPProxyPortEnabled);
428  m_xHttpPortED->set_sensitive(bHTTPProxyPortEnabled);
429 
430  const bool bHTTPSProxyNameEnabled = bManualConfig && !officecfg::Inet::Settings::ooInetHTTPSProxyName::isReadOnly();
431  const bool bHTTPSProxyPortEnabled = bManualConfig && !officecfg::Inet::Settings::ooInetHTTPSProxyPort::isReadOnly();
432  m_xHttpsProxyFT->set_sensitive(bHTTPSProxyNameEnabled);
433  m_xHttpsProxyED->set_sensitive(bHTTPSProxyNameEnabled);
434  m_xHttpsPortFT->set_sensitive(bHTTPSProxyPortEnabled);
435  m_xHttpsPortED->set_sensitive(bHTTPSProxyPortEnabled);
436 
437  const bool bFTPProxyNameEnabled = bManualConfig && !officecfg::Inet::Settings::ooInetFTPProxyName::isReadOnly();
438  const bool bFTPProxyPortEnabled = bManualConfig && !officecfg::Inet::Settings::ooInetFTPProxyPort::isReadOnly();
439  m_xFtpProxyFT->set_sensitive(bFTPProxyNameEnabled);
440  m_xFtpProxyED->set_sensitive(bFTPProxyNameEnabled);
441  m_xFtpPortFT->set_sensitive(bFTPProxyPortEnabled);
442  m_xFtpPortED->set_sensitive(bFTPProxyPortEnabled);
443 
444  const bool bInetNoProxyEnabled = bManualConfig && !officecfg::Inet::Settings::ooInetNoProxy::isReadOnly();
445  m_xNoProxyForFT->set_sensitive(bInetNoProxyEnabled);
446  m_xNoProxyForED->set_sensitive(bInetNoProxyEnabled);
447  m_xNoProxyDescFT->set_sensitive(bInetNoProxyEnabled);
448 }
449 
450 IMPL_LINK(SvxProxyTabPage, ProxyHdl_Impl, weld::ComboBox&, rBox, void)
451 {
452  sal_Int32 nPos = rBox.get_active();
453 
454  // Restore original system values
455  if( nPos == 1 )
456  {
457  ReadConfigDefaults_Impl();
458  }
459 
460  EnableControls_Impl();
461 }
462 
463 IMPL_STATIC_LINK(SvxProxyTabPage, LoseFocusHdl_Impl, weld::Widget&, rControl, void)
464 {
465  weld::Entry* pEdit = dynamic_cast<weld::Entry*>(&rControl);
466  if (pEdit && !isValidPort(pEdit->get_text()))
467  pEdit->set_text(OUString('0'));
468 }
469 
470 /********************************************************************/
471 /* */
472 /* SvxSecurityTabPage */
473 /* */
474 /********************************************************************/
476  : SfxTabPage(pPage, pController, "cui/ui/optsecuritypage.ui", "OptSecurityPage", &rSet)
477  , mpSecOptions(new SvtSecurityOptions)
478  , m_xSecurityOptionsPB(m_xBuilder->weld_button("options"))
479  , m_xSavePasswordsCB(m_xBuilder->weld_check_button("savepassword"))
480  , m_xShowConnectionsPB(m_xBuilder->weld_button("connections"))
481  , m_xMasterPasswordCB(m_xBuilder->weld_check_button("usemasterpassword"))
482  , m_xMasterPasswordFT(m_xBuilder->weld_label("masterpasswordtext"))
483  , m_xMasterPasswordPB(m_xBuilder->weld_button("masterpassword"))
484  , m_xMacroSecFrame(m_xBuilder->weld_container("macrosecurity"))
485  , m_xMacroSecPB(m_xBuilder->weld_button("macro"))
486  , m_xCertFrame(m_xBuilder->weld_container("certificatepath"))
487  , m_xCertPathPB(m_xBuilder->weld_button("cert"))
488  , m_xTSAURLsFrame(m_xBuilder->weld_container("tsaurls"))
489  , m_xTSAURLsPB(m_xBuilder->weld_button("tsas"))
490  , m_xNoPasswordSaveFT(m_xBuilder->weld_label("nopasswordsave"))
491 {
492  //fdo#65595, we need height-for-width support here, but for now we can
493  //bodge it
494  Size aPrefSize(m_xSavePasswordsCB->get_preferred_size());
495  int nMaxWidth = m_xSavePasswordsCB->get_approximate_digit_width() * 40;
496  if (aPrefSize.Width() > nMaxWidth)
497  {
498  m_xSavePasswordsCB->set_label_line_wrap(true);
499  m_xSavePasswordsCB->set_size_request(nMaxWidth, -1);
500  }
501 
503 
504  InitControls();
505 
506  m_xSecurityOptionsPB->connect_clicked( LINK( this, SvxSecurityTabPage, SecurityOptionsHdl ) );
507  m_xSavePasswordsCB->connect_clicked( LINK( this, SvxSecurityTabPage, SavePasswordHdl ) );
508  m_xMasterPasswordPB->connect_clicked( LINK( this, SvxSecurityTabPage, MasterPasswordHdl ) );
509  m_xMasterPasswordCB->connect_clicked( LINK( this, SvxSecurityTabPage, MasterPasswordCBHdl ) );
510  m_xShowConnectionsPB->connect_clicked( LINK( this, SvxSecurityTabPage, ShowPasswordsHdl ) );
511  m_xMacroSecPB->connect_clicked( LINK( this, SvxSecurityTabPage, MacroSecPBHdl ) );
512  m_xCertPathPB->connect_clicked( LINK( this, SvxSecurityTabPage, CertPathPBHdl ) );
513  m_xTSAURLsPB->connect_clicked( LINK( this, SvxSecurityTabPage, TSAURLsPBHdl ) );
514 
515  ActivatePage( rSet );
516 }
517 
519 {
520 }
521 
522 IMPL_LINK_NOARG(SvxSecurityTabPage, SecurityOptionsHdl, weld::Button&, void)
523 {
524  if (!m_xSecOptDlg)
525  m_xSecOptDlg.reset(new svx::SecurityOptionsDialog(GetFrameWeld(), mpSecOptions.get()));
526  m_xSecOptDlg->run();
527 }
528 
530 {
531  try
532  {
533  Reference< task::XPasswordContainer2 > xMasterPasswd(
534  task::PasswordContainer::create(comphelper::getProcessComponentContext()));
535 
536  if ( m_xSavePasswordsCB->get_active() )
537  {
538  bool bOldValue = xMasterPasswd->allowPersistentStoring( true );
539  xMasterPasswd->removeMasterPassword();
540 
541  uno::Reference<task::XInteractionHandler> xTmpHandler(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(),
542  GetDialogController()->getDialog()->GetXWindow()));
543 
544  if ( xMasterPasswd->changeMasterPassword(xTmpHandler) )
545  {
546  m_xMasterPasswordPB->set_sensitive(true);
547  m_xMasterPasswordCB->set_active(true);
548  m_xMasterPasswordCB->set_sensitive(true);
549  m_xMasterPasswordFT->set_sensitive(true);
550  m_xShowConnectionsPB->set_sensitive(true);
551  }
552  else
553  {
554  xMasterPasswd->allowPersistentStoring( bOldValue );
555  m_xSavePasswordsCB->set_active( false );
556  }
557  }
558  else
559  {
560  std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(GetFrameWeld(),
561  VclMessageType::Question, VclButtonsType::YesNo,
562  m_sPasswordStoringDeactivateStr));
563  xQueryBox->set_default_response(RET_NO);
564 
565  sal_uInt16 nRet = xQueryBox->run();
566 
567  if( RET_YES == nRet )
568  {
569  xMasterPasswd->allowPersistentStoring( false );
570  m_xMasterPasswordCB->set_active(true);
571  m_xMasterPasswordPB->set_sensitive( false );
572  m_xMasterPasswordCB->set_sensitive( false );
573  m_xMasterPasswordFT->set_sensitive( false );
574  m_xShowConnectionsPB->set_sensitive( false );
575  }
576  else
577  {
578  m_xSavePasswordsCB->set_active(true);
579  m_xMasterPasswordPB->set_sensitive(true);
580  m_xShowConnectionsPB->set_sensitive(true);
581  }
582  }
583  }
584  catch (const Exception&)
585  {
586  m_xSavePasswordsCB->set_active( !m_xSavePasswordsCB->get_active() );
587  }
588 }
589 
591 {
592  try
593  {
594  Reference< task::XPasswordContainer2 > xMasterPasswd(
595  task::PasswordContainer::create(comphelper::getProcessComponentContext()));
596 
597  if ( xMasterPasswd->isPersistentStoringAllowed() )
598  {
599  uno::Reference<task::XInteractionHandler> xTmpHandler(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(),
600  GetDialogController()->getDialog()->GetXWindow()));
601  xMasterPasswd->changeMasterPassword(xTmpHandler);
602  }
603  }
604  catch (const Exception&)
605  {}
606 }
607 
608 IMPL_LINK_NOARG(SvxSecurityTabPage, MasterPasswordCBHdl, weld::Button&, void)
609 {
610  try
611  {
612  Reference< task::XPasswordContainer2 > xMasterPasswd(
613  task::PasswordContainer::create(comphelper::getProcessComponentContext()));
614 
615  uno::Reference<task::XInteractionHandler> xTmpHandler(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(),
616  GetDialogController()->getDialog()->GetXWindow()));
617 
618  if ( m_xMasterPasswordCB->get_active() )
619  {
620  if (xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->changeMasterPassword(xTmpHandler))
621  {
622  m_xMasterPasswordPB->set_sensitive(true);
623  m_xMasterPasswordFT->set_sensitive(true);
624  }
625  else
626  {
627  m_xMasterPasswordCB->set_active( false );
628  m_xMasterPasswordPB->set_sensitive(true);
629  m_xMasterPasswordFT->set_sensitive(true);
630  }
631  }
632  else
633  {
634  if ( xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->useDefaultMasterPassword(xTmpHandler) )
635  {
636  m_xMasterPasswordPB->set_sensitive( false );
637  m_xMasterPasswordFT->set_sensitive( false );
638  }
639  else
640  {
641  m_xMasterPasswordCB->set_active(true);
642  m_xMasterPasswordPB->set_sensitive(true);
643  m_xShowConnectionsPB->set_sensitive(true);
644  }
645  }
646  }
647  catch (const Exception&)
648  {
649  m_xSavePasswordsCB->set_active( !m_xSavePasswordsCB->get_active() );
650  }
651 }
652 
654 {
655  try
656  {
657  Reference< task::XPasswordContainer2 > xMasterPasswd(
658  task::PasswordContainer::create(comphelper::getProcessComponentContext()));
659 
660  uno::Reference<task::XInteractionHandler> xTmpHandler(task::InteractionHandler::createWithParent(comphelper::getProcessComponentContext(),
661  GetDialogController()->getDialog()->GetXWindow()));
662 
663  if ( xMasterPasswd->isPersistentStoringAllowed() && xMasterPasswd->authorizateWithMasterPassword(xTmpHandler) )
664  {
666  aDlg.run();
667  }
668  }
669  catch (const Exception&)
670  {}
671 }
672 
674 {
675  if (!mpCertPathDlg)
676  mpCertPathDlg.reset(new CertPathDialog(GetFrameWeld()));
677  mpCertPathDlg->Init();
678 
679  if (mpCertPathDlg->run() == RET_OK && !mpCertPathDlg->isActiveServicePath())
680  {
681  SolarMutexGuard aGuard;
683  GetDialogController()->response(RET_OK);
684  }
685 }
686 
688 {
689  // Unlike the mpCertPathDlg, we *don't* keep the same dialog object around between
690  // invocations. Seems clearer to my little brain that way.
691  TSAURLsDialog aTSAURLsDlg(GetFrameWeld());
692  aTSAURLsDlg.run();
693 }
694 
696 {
697  try
698  {
699  Reference< security::XDocumentDigitalSignatures > xD(
700  security::DocumentDigitalSignatures::createDefault(comphelper::getProcessComponentContext() ) );
701  xD->setParentWindow(GetDialogController()->getDialog()->GetXWindow());
702  xD->manageTrustedSources();
703  }
704  catch (const Exception&)
705  {
706  TOOLS_WARN_EXCEPTION( "cui.options", "");
707  }
708 }
709 
711 {
712 #ifndef UNX
713  m_xCertFrame->hide();
714 #endif
715 
716  m_xMasterPasswordPB->set_sensitive( false );
717  m_xMasterPasswordCB->set_sensitive( false );
718  m_xMasterPasswordCB->set_active(true);
719  m_xMasterPasswordFT->set_sensitive( false );
720  m_xShowConnectionsPB->set_sensitive( false );
721 
722  // initialize the password saving checkbox
723  try
724  {
725  Reference< task::XPasswordContainer2 > xMasterPasswd(
726  task::PasswordContainer::create(comphelper::getProcessComponentContext()));
727 
728  if ( xMasterPasswd->isPersistentStoringAllowed() )
729  {
730  m_xMasterPasswordCB->set_sensitive(true);
731  m_xShowConnectionsPB->set_sensitive(true);
732  m_xSavePasswordsCB->set_active(true);
733 
734  if ( xMasterPasswd->isDefaultMasterPasswordUsed() )
735  m_xMasterPasswordCB->set_active( false );
736  else
737  {
738  m_xMasterPasswordPB->set_sensitive(true);
739  m_xMasterPasswordCB->set_active(true);
740  m_xMasterPasswordFT->set_sensitive(true);
741  }
742  }
743  }
744  catch (const Exception&)
745  {
746  m_xSavePasswordsCB->set_sensitive( false );
747  }
748 }
749 
750 std::unique_ptr<SfxTabPage> SvxSecurityTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet )
751 {
752  return std::make_unique<SvxSecurityTabPage>(pPage, pController, *rAttrSet);
753 }
754 
756 {
757 }
758 
760 {
761  if( _pSet )
762  FillItemSet( _pSet );
763  return DeactivateRC::LeavePage;
764 }
765 
766 namespace
767 {
768  bool CheckAndSave( SvtSecurityOptions& _rOpt, SvtSecurityOptions::EOption _eOpt, const bool _bIsChecked, bool& _rModified )
769  {
770  bool bModified = false;
771  if ( _rOpt.IsOptionEnabled( _eOpt ) )
772  {
773  bModified = _rOpt.IsOptionSet( _eOpt ) != _bIsChecked;
774  if ( bModified )
775  {
776  _rOpt.SetOption( _eOpt, _bIsChecked );
777  _rModified = true;
778  }
779  }
780 
781  return bModified;
782  }
783 }
784 
786 {
787  bool bModified = false;
788 
789  if (m_xSecOptDlg)
790  {
791  CheckAndSave( *mpSecOptions, SvtSecurityOptions::EOption::DocWarnSaveOrSend, m_xSecOptDlg->IsSaveOrSendDocsChecked(), bModified );
792  CheckAndSave( *mpSecOptions, SvtSecurityOptions::EOption::DocWarnSigning, m_xSecOptDlg->IsSignDocsChecked(), bModified );
793  CheckAndSave( *mpSecOptions, SvtSecurityOptions::EOption::DocWarnPrint, m_xSecOptDlg->IsPrintDocsChecked(), bModified );
794  CheckAndSave( *mpSecOptions, SvtSecurityOptions::EOption::DocWarnCreatePdf, m_xSecOptDlg->IsCreatePdfChecked(), bModified );
795  CheckAndSave( *mpSecOptions, SvtSecurityOptions::EOption::DocWarnRemovePersonalInfo, m_xSecOptDlg->IsRemovePersInfoChecked(), bModified );
796  CheckAndSave( *mpSecOptions, SvtSecurityOptions::EOption::DocWarnRecommendPassword, m_xSecOptDlg->IsRecommPasswdChecked(), bModified );
797  CheckAndSave( *mpSecOptions, SvtSecurityOptions::EOption::CtrlClickHyperlink, m_xSecOptDlg->IsCtrlHyperlinkChecked(), bModified );
798  CheckAndSave( *mpSecOptions, SvtSecurityOptions::EOption::BlockUntrustedRefererLinks, m_xSecOptDlg->IsBlockUntrustedRefererLinksChecked(), bModified );
799  }
800 
801  return bModified;
802 }
803 
804 /*--------------------------------------------------------------------*/
805 
807 {
808 }
809 
811 {
813  sProgram(officecfg::Office::Common::ExternalMailer::Program::get()),
814  bROProgram(
815  officecfg::Office::Common::ExternalMailer::Program::isReadOnly()),
816  bHideContent(
817  officecfg::Office::Security::HiddenContent::RemoveHiddenContent::get()),
819  officecfg::Office::Security::HiddenContent::RemoveHiddenContent::isReadOnly())
820  {}
821 
822  OUString sProgram;
826 };
827 
829  : SfxTabPage( pPage, pController, "cui/ui/optemailpage.ui", "OptEmailPage", &rSet)
830  , pImpl(new SvxEMailTabPage_Impl)
831  , m_xMailContainer(m_xBuilder->weld_container("program"))
832  , m_xMailerURLFI(m_xBuilder->weld_image("lockemail"))
833  , m_xMailerURLED(m_xBuilder->weld_entry("url"))
834  , m_xMailerURLPB(m_xBuilder->weld_button("browse"))
835  , m_xSuppressHiddenContainer(m_xBuilder->weld_container("suppressHiddenCont"))
836  , m_xSuppressHiddenFI(m_xBuilder->weld_image("lockSuppressHidden"))
837  , m_xSuppressHidden(m_xBuilder->weld_check_button("suppressHidden"))
838  , m_xDefaultFilterFT(m_xBuilder->weld_label("browsetitle"))
839 {
841  m_xMailerURLPB->connect_clicked( LINK( this, SvxEMailTabPage, FileDialogHdl_Impl ) );
842 }
843 
844 /* -------------------------------------------------------------------------*/
845 
847 {
848 }
849 
850 /* -------------------------------------------------------------------------*/
851 
852 std::unique_ptr<SfxTabPage> SvxEMailTabPage::Create( weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rAttrSet )
853 {
854  return std::make_unique<SvxEMailTabPage>(pPage, pController, *rAttrSet);
855 }
856 
857 /* -------------------------------------------------------------------------*/
858 
860 {
861  std::shared_ptr<comphelper::ConfigurationChanges> batch(
863  if (!pImpl->bROProgram && m_xMailerURLED->get_value_changed_from_saved())
864  {
865  pImpl->sProgram = m_xMailerURLED->get_text();
866  officecfg::Office::Common::ExternalMailer::Program::set(
867  pImpl->sProgram, batch);
868  }
869  if (!pImpl->bROHideContent
870  && pImpl->bHideContent != m_xSuppressHidden->get_active())
871  {
872  pImpl->bHideContent = m_xSuppressHidden->get_active();
873  officecfg::Office::Security::HiddenContent::RemoveHiddenContent::set(
874  pImpl->bHideContent, batch);
875  }
876  batch->commit();
877  return false;
878 }
879 
880 /* -------------------------------------------------------------------------*/
881 
883 {
884  m_xMailerURLED->set_sensitive(true);
885  m_xMailerURLPB->set_sensitive(true);
886 
887  if (pImpl->bROProgram)
888  m_xMailerURLFI->show();
889 
890  m_xMailerURLED->set_text(pImpl->sProgram);
891  m_xMailerURLED->save_value();
892 
893  m_xMailContainer->set_sensitive(!pImpl->bROProgram);
894 
895  if (pImpl->bROHideContent)
896  m_xSuppressHiddenFI->show();
897 
898  m_xSuppressHidden->set_active(pImpl->bHideContent);
899 
900  m_xSuppressHiddenContainer->set_sensitive(!pImpl->bROHideContent);
901 }
902 
903 /* -------------------------------------------------------------------------*/
904 
905 IMPL_LINK_NOARG(SvxEMailTabPage, FileDialogHdl_Impl, weld::Button&, void)
906 {
907  if (pImpl->bROProgram)
908  return;
909 
910  FileDialogHelper aHelper(css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE, FileDialogFlags::NONE, GetFrameWeld());
911  OUString sPath = m_xMailerURLED->get_text();
912  if ( sPath.isEmpty() )
913  sPath = "/usr/bin";
914 
915  OUString sUrl;
916  osl::FileBase::getFileURLFromSystemPath(sPath, sUrl);
917  aHelper.SetDisplayDirectory(sUrl);
918  aHelper.AddFilter( m_sDefaultFilterName, "*");
919 
920  if ( ERRCODE_NONE == aHelper.Execute() )
921  {
922  sUrl = aHelper.GetPath();
923  if (osl::FileBase::getSystemPathFromFileURL(sUrl, sPath)
924  != osl::FileBase::E_None)
925  {
926  sPath.clear();
927  }
928  m_xMailerURLED->set_text(sPath);
929  }
930 }
931 
932 
933 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< weld::Entry > m_xMailerURLED
Definition: optinet2.hxx:141
bool IsOptionSet(EOption eOption) const
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
std::unique_ptr< weld::Label > m_xNoPasswordSaveFT
Definition: optinet2.hxx:107
std::unique_ptr< weld::Button > m_xSecurityOptionsPB
Definition: optinet2.hxx:89
std::unique_ptr< weld::Label > m_xHttpProxyFT
Definition: optinet2.hxx:35
virtual ~SvxEMailTabPage() override
Definition: optinet2.cxx:846
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: optinet2.cxx:759
void ReadConfigData_Impl()
Definition: optinet2.cxx:191
std::unique_ptr< weld::Label > m_xNoProxyForFT
Definition: optinet2.hxx:50
std::unique_ptr< weld::Label > m_xMasterPasswordFT
Definition: optinet2.hxx:95
std::unique_ptr< weld::Entry > m_xFtpPortED
Definition: optinet2.hxx:48
std::unique_ptr< weld::CheckButton > m_xSuppressHidden
Definition: optinet2.hxx:145
std::unique_ptr< SvtSecurityOptions > mpSecOptions
Definition: optinet2.hxx:82
std::unique_ptr< weld::Button > m_xMacroSecPB
Definition: optinet2.hxx:99
SvxEMailTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: optinet2.cxx:828
std::unique_ptr< weld::Entry > m_xHttpProxyED
Definition: optinet2.hxx:36
const char g_aProxyModePN[]
Definition: optinet2.cxx:97
const char g_aFtpPortPN[]
Definition: optinet2.cxx:103
sal_Int64 n
std::unique_ptr< weld::Button > m_xMasterPasswordPB
Definition: optinet2.hxx:96
std::unique_ptr< weld::Entry > m_xFtpProxyED
Definition: optinet2.hxx:46
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: optinet2.cxx:755
std::unique_ptr< weld::Image > m_xMailerURLFI
Definition: optinet2.hxx:140
std::unique_ptr< weld::Button > m_xCertPathPB
Definition: optinet2.hxx:102
virtual void Reset(const SfxItemSet *rSet) override
Definition: optinet2.cxx:882
float x
std::unique_ptr< weld::Image > m_xSuppressHiddenFI
Definition: optinet2.hxx:144
std::unique_ptr< weld::Label > m_xDefaultFilterFT
Definition: optinet2.hxx:146
virtual void set_text(const OUString &rText)=0
std::unique_ptr< SvxEMailTabPage_Impl > pImpl
Definition: optinet2.hxx:137
std::unique_ptr< weld::Label > m_xNoProxyDescFT
Definition: optinet2.hxx:52
std::unique_ptr< weld::ComboBox > m_xProxyModeLB
Definition: optinet2.hxx:33
RET_NO
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rAttrSet)
Definition: optinet2.cxx:750
RET_YES
void EnableControls_Impl()
Definition: optinet2.cxx:417
std::unique_ptr< weld::Label > m_xFtpProxyFT
Definition: optinet2.hxx:45
std::unique_ptr< weld::Button > m_xShowConnectionsPB
Definition: optinet2.hxx:92
std::unique_ptr< weld::CheckButton > m_xMasterPasswordCB
Definition: optinet2.hxx:94
void SetOption(EOption eOption, bool bValue)
std::unique_ptr< weld::Entry > m_xNoProxyForED
Definition: optinet2.hxx:51
static std::shared_ptr< ConfigurationChanges > create(css::uno::Reference< css::uno::XComponentContext > const &context=comphelper::getProcessComponentContext())
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rAttrSet)
Definition: optinet2.cxx:186
bool isdigitAsciiString(const OString &rString)
std::unique_ptr< weld::Button > m_xTSAURLsPB
Definition: optinet2.hxx:105
const char g_aHttpPortPN[]
Definition: optinet2.cxx:99
std::unique_ptr< weld::Label > m_xHttpsProxyFT
Definition: optinet2.hxx:40
SVT_DLLPUBLIC bool executeRestartDialog(css::uno::Reference< css::uno::XComponentContext > const &context, weld::Window *parent, RestartReason reason)
const char g_aFtpProxyPN[]
Definition: optinet2.cxx:102
#define TOOLS_WARN_EXCEPTION(area, stream)
const char g_aNoProxyDescPN[]
Definition: optinet2.cxx:104
css::uno::Reference< css::uno::XInterface > m_xConfigurationUpdateAccess
Definition: optinet2.hxx:54
SvxProxyTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: optinet2.cxx:129
void ReadConfigDefaults_Impl()
Definition: optinet2.cxx:229
int i
std::unique_ptr< weld::CheckButton > m_xSavePasswordsCB
Definition: optinet2.hxx:91
virtual ~SvxProxyTabPage() override
Definition: optinet2.cxx:182
const char g_aHttpsProxyPN[]
Definition: optinet2.cxx:100
std::unique_ptr< weld::Entry > m_xHttpsPortED
Definition: optinet2.hxx:43
Any aHelper
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: optinet2.cxx:785
const char g_aHttpsPortPN[]
Definition: optinet2.cxx:101
OUString CuiResId(const char *pKey)
Definition: cuiresmgr.cxx:23
virtual OUString get_text() const =0
std::unique_ptr< weld::Container > m_xCertFrame
Definition: optinet2.hxx:101
IMPL_LINK_NOARG(SvxSecurityTabPage, SecurityOptionsHdl, weld::Button &, void)
Definition: optinet2.cxx:522
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: optinet2.cxx:859
std::unique_ptr< weld::Entry > m_xHttpsProxyED
Definition: optinet2.hxx:41
OUString m_sDefaultFilterName
Definition: optinet2.hxx:135
std::unique_ptr< weld::Container > m_xSuppressHiddenContainer
Definition: optinet2.hxx:143
bool IsOptionEnabled(EOption eOption) const
weld::Entry & rEdit
#define ERRCODE_NONE
SvxSecurityTabPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: optinet2.cxx:475
std::unique_ptr< weld::Label > m_xHttpsPortFT
Definition: optinet2.hxx:42
OUString m_sPasswordStoringDeactivateStr
Definition: optinet2.hxx:87
RET_OK
std::unique_ptr< weld::Label > m_xHttpPortFT
Definition: optinet2.hxx:37
IMPL_STATIC_LINK(SvxProxyTabPage, NumberOnlyTextFilterHdl, OUString &, rTest, bool)
Definition: optinet2.cxx:106
std::unique_ptr< weld::Button > m_xMailerURLPB
Definition: optinet2.hxx:142
virtual short run()
Reference< XComponentContext > getProcessComponentContext()
std::unique_ptr< weld::Entry > m_xHttpPortED
Definition: optinet2.hxx:38
virtual void Reset(const SfxItemSet *rSet) override
Definition: optinet2.cxx:317
DeactivateRC
std::unique_ptr< svx::SecurityOptionsDialog > m_xSecOptDlg
Definition: optinet2.hxx:83
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rAttrSet)
Definition: optinet2.cxx:852
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: optinet2.cxx:333
#define SAL_WARN(area, stream)
virtual void Reset(const SfxItemSet *rSet) override
Definition: optinet2.cxx:806
virtual ~SvxSecurityTabPage() override
Definition: optinet2.cxx:518
std::unique_ptr< weld::Label > m_xFtpPortFT
Definition: optinet2.hxx:47
std::unique_ptr< weld::Container > m_xMailContainer
Definition: optinet2.hxx:139
void RestoreConfigDefaults_Impl()
Definition: optinet2.cxx:286
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
sal_uInt16 nPos
const char g_aHttpProxyPN[]
Definition: optinet2.cxx:98
IMPL_LINK(SvxProxyTabPage, PortChangedHdl, weld::Entry &, rEdit, void)
Definition: optinet2.cxx:86
RESTART_REASON_ADDING_PATH