LCOV - code coverage report
Current view: top level - cui/source/options - tsaurls.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 65 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 13 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : 
      10             : #include <officecfg/Office/Common.hxx>
      11             : #include <svx/svxdlg.hxx>
      12             : #include <cuires.hrc>
      13             : 
      14             : #include "tsaurls.hxx"
      15             : 
      16             : #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
      17             : 
      18             : using namespace ::com::sun::star;
      19             : 
      20           0 : TSAURLsDialog::TSAURLsDialog(vcl::Window* pParent)
      21           0 :     : ModalDialog(pParent, "TSAURLDialog", "cui/ui/tsaurldialog.ui")
      22             : {
      23           0 :     get(m_pAddBtn, "add");
      24           0 :     get(m_pDeleteBtn, "delete");
      25           0 :     get(m_pOKBtn, "ok");
      26           0 :     get(m_pURLListBox, "urls");
      27             : 
      28           0 :     m_pURLListBox->SetDropDownLineCount(8);
      29           0 :     m_pURLListBox->set_width_request(m_pURLListBox->approximate_char_width() * 32);
      30           0 :     m_pOKBtn->Disable();
      31             : 
      32           0 :     m_pAddBtn->SetClickHdl( LINK( this, TSAURLsDialog, AddHdl_Impl ) );
      33           0 :     m_pDeleteBtn->SetClickHdl( LINK( this, TSAURLsDialog, DeleteHdl_Impl ) );
      34           0 :     m_pOKBtn->SetClickHdl( LINK( this, TSAURLsDialog, OKHdl_Impl ) );
      35             : 
      36             :     try
      37             :     {
      38           0 :         css::uno::Sequence<OUString> aUserSetTSAURLs(officecfg::Office::Common::Security::Scripting::TSAURLs::get());
      39             : 
      40           0 :         for (auto i = aUserSetTSAURLs.begin(); i != aUserSetTSAURLs.end(); ++i)
      41             :         {
      42           0 :             AddTSAURL(*i);
      43           0 :         }
      44             :     }
      45           0 :     catch (const uno::Exception &e)
      46             :     {
      47             :         SAL_WARN("cui.options", "TSAURLsDialog::TSAURLsDialog(): caught exception" << e.Message);
      48             :     }
      49           0 : }
      50             : 
      51           0 : IMPL_LINK_NOARG(TSAURLsDialog, OKHdl_Impl)
      52             : {
      53           0 :     std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
      54             : 
      55           0 :     css::uno::Sequence<OUString> aNewValue(m_aURLs.size());
      56           0 :     size_t n(0);
      57             : 
      58           0 :     for (auto i = m_aURLs.cbegin(); i != m_aURLs.cend(); ++i)
      59           0 :         aNewValue[n++] = *i;
      60           0 :     officecfg::Office::Common::Security::Scripting::TSAURLs::set(aNewValue, batch);
      61           0 :     batch->commit();
      62             : 
      63           0 :     EndDialog(RET_OK);
      64             : 
      65           0 :     return 0;
      66             : }
      67             : 
      68           0 : TSAURLsDialog::~TSAURLsDialog()
      69             : {
      70           0 :     disposeOnce();
      71           0 : }
      72             : 
      73           0 : void TSAURLsDialog::dispose()
      74             : {
      75           0 :     m_pAddBtn.clear();
      76           0 :     m_pDeleteBtn.clear();
      77           0 :     m_pOKBtn.clear();
      78           0 :     m_pURLListBox.clear();
      79             : 
      80           0 :     ModalDialog::dispose();
      81           0 : }
      82             : 
      83           0 : void TSAURLsDialog::AddTSAURL(const OUString& rURL)
      84             : {
      85           0 :     m_aURLs.insert(rURL);
      86             : 
      87           0 :     m_pURLListBox->SetUpdateMode(false);
      88           0 :     m_pURLListBox->Clear();
      89             : 
      90           0 :     for (auto i = m_aURLs.cbegin(); i != m_aURLs.cend(); ++i)
      91             :     {
      92           0 :         m_pURLListBox->InsertEntry(*i);
      93             :     }
      94             : 
      95           0 :     m_pURLListBox->SetUpdateMode(true);
      96           0 : }
      97             : 
      98           0 : IMPL_LINK_NOARG(TSAURLsDialog, AddHdl_Impl)
      99             : {
     100           0 :     OUString aURL;
     101           0 :     OUString aDesc( get<FixedText>("enteraurl")->GetText() );
     102             : 
     103           0 :     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     104           0 :     boost::scoped_ptr<AbstractSvxNameDialog> pDlg(pFact->CreateSvxNameDialog( m_pAddBtn, aURL, aDesc));
     105             : 
     106           0 :     if ( pDlg->Execute() == RET_OK )
     107             :     {
     108           0 :         pDlg->GetName( aURL );
     109             : 
     110           0 :         AddTSAURL(aURL);
     111           0 :         m_pOKBtn->Enable();
     112             :     }
     113             : 
     114           0 :     return 0;
     115             : }
     116             : 
     117           0 : IMPL_LINK_NOARG(TSAURLsDialog, DeleteHdl_Impl)
     118             : {
     119           0 :     sal_Int32 nSel = m_pURLListBox->GetSelectEntryPos();
     120             : 
     121           0 :     if (nSel == LISTBOX_ENTRY_NOTFOUND)
     122           0 :         return 0;
     123             : 
     124           0 :     m_aURLs.erase(m_pURLListBox->GetEntry(nSel));
     125           0 :     m_pURLListBox->RemoveEntry(nSel);
     126           0 :     m_pOKBtn->Enable();
     127             : 
     128           0 :     return 0;
     129           0 : }
     130             : 
     131             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11