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