LCOV - code coverage report
Current view: top level - extensions/source/abpilot - abpfinalpage.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 95 0.0 %
Date: 2014-11-03 Functions: 0 18 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             :  * 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 "abpfinalpage.hxx"
      21             : #include "addresssettings.hxx"
      22             : #include "abspilot.hxx"
      23             : #include <tools/urlobj.hxx>
      24             : #include <unotools/ucbhelper.hxx>
      25             : #include <unotools/pathoptions.hxx>
      26             : #include <svl/filenotation.hxx>
      27             : #include <sfx2/docfilt.hxx>
      28             : #include <vcl/msgbox.hxx>
      29             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      30             : 
      31             : 
      32             : namespace abp
      33             : {
      34             : 
      35             :     using namespace ::svt;
      36             :     using namespace ::utl;
      37             : 
      38           0 :     const SfxFilter* lcl_getBaseFilter()
      39             :     {
      40           0 :         const SfxFilter* pFilter = SfxFilter::GetFilterByName(OUString("StarOffice XML (Base)"));
      41             :         OSL_ENSURE(pFilter,"Filter: StarOffice XML (Base) could not be found!");
      42           0 :         return pFilter;
      43             :     }
      44             : 
      45             :     //= FinalPage
      46           0 :     FinalPage::FinalPage( OAddessBookSourcePilot* _pParent )
      47             :         : AddressBookSourcePage(_pParent, "DataSourcePage",
      48           0 :             "modules/sabpilot/ui/datasourcepage.ui")
      49             :     {
      50           0 :         get(m_pLocation, "location");
      51           0 :         get(m_pBrowse, "browse");
      52           0 :         get(m_pRegisterName, "available");
      53           0 :         get(m_pNameLabel, "nameft");
      54           0 :         get(m_pName, "name");
      55           0 :         get(m_pDuplicateNameError, "warning");
      56             :         m_pLocationController = new ::svx::DatabaseLocationInputController(_pParent->getORB(),
      57           0 :             *m_pLocation, *m_pBrowse);
      58             : 
      59           0 :         m_pName->SetModifyHdl( LINK(this, FinalPage, OnNameModified) );
      60           0 :         m_pLocation->SetModifyHdl( LINK(this, FinalPage, OnNameModified) );
      61           0 :         m_pRegisterName->SetClickHdl( LINK( this, FinalPage, OnRegister ) );
      62           0 :         m_pRegisterName->Check(true);
      63           0 :     }
      64             : 
      65           0 :     FinalPage::~FinalPage()
      66             :     {
      67           0 :         delete m_pLocationController;
      68           0 :     }
      69             : 
      70           0 :     bool FinalPage::isValidName() const
      71             :     {
      72           0 :         OUString sCurrentName(m_pName->GetText());
      73             : 
      74           0 :         if (sCurrentName.isEmpty())
      75             :             // the name must not be empty
      76           0 :             return false;
      77             : 
      78           0 :         if ( m_aInvalidDataSourceNames.find( sCurrentName ) != m_aInvalidDataSourceNames.end() )
      79             :             // there already is a data source with this name
      80           0 :             return false;
      81             : 
      82           0 :         return true;
      83             :     }
      84             : 
      85           0 :     void FinalPage::setFields()
      86             :     {
      87           0 :         AddressSettings& rSettings = getSettings();
      88             : 
      89           0 :         INetURLObject aURL( rSettings.sDataSourceName );
      90           0 :         if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
      91             :         {
      92           0 :             OUString sPath = SvtPathOptions().GetWorkPath();
      93           0 :             sPath += "/";
      94           0 :             sPath += rSettings.sDataSourceName;
      95             : 
      96           0 :             const SfxFilter* pFilter = lcl_getBaseFilter();
      97           0 :             if ( pFilter )
      98             :             {
      99           0 :                 OUString sExt = pFilter->GetDefaultExtension();
     100           0 :                 sPath += sExt.getToken(1,'*');
     101             :             }
     102             : 
     103           0 :             aURL.SetURL(sPath);
     104             :         }
     105             :         OSL_ENSURE( aURL.GetProtocol() != INET_PROT_NOT_VALID ,"No valid file name!");
     106           0 :         rSettings.sDataSourceName = aURL.GetMainURL( INetURLObject::NO_DECODE );
     107           0 :         m_pLocationController->setURL( rSettings.sDataSourceName );
     108           0 :         OUString sName = aURL.getName( );
     109           0 :         sal_Int32 nPos = sName.indexOf(aURL.GetExtension());
     110           0 :         if ( nPos != -1 )
     111             :         {
     112           0 :             sName = sName.replaceAt(nPos-1, 4, "");
     113             :         }
     114           0 :         m_pName->SetText(sName);
     115             : 
     116           0 :         OnRegister(m_pRegisterName);
     117           0 :     }
     118             : 
     119             : 
     120           0 :     void FinalPage::initializePage()
     121             :     {
     122           0 :         AddressBookSourcePage::initializePage();
     123             : 
     124           0 :         setFields();
     125           0 :     }
     126             : 
     127             : 
     128           0 :     bool FinalPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
     129             :     {
     130           0 :         if (!AddressBookSourcePage::commitPage(_eReason))
     131           0 :             return false;
     132             : 
     133           0 :         if  (   ( ::svt::WizardTypes::eTravelBackward != _eReason )
     134           0 :             &&  ( !m_pLocationController->prepareCommit() )
     135             :             )
     136           0 :             return false;
     137             : 
     138           0 :         AddressSettings& rSettings = getSettings();
     139           0 :         rSettings.sDataSourceName = m_pLocationController->getURL();
     140           0 :         rSettings.bRegisterDataSource = m_pRegisterName->IsChecked();
     141           0 :         if ( rSettings.bRegisterDataSource )
     142           0 :             rSettings.sRegisteredDataSourceName = m_pName->GetText();
     143             : 
     144           0 :         return true;
     145             :     }
     146             : 
     147             : 
     148           0 :     void FinalPage::ActivatePage()
     149             :     {
     150           0 :         AddressBookSourcePage::ActivatePage();
     151             : 
     152             :         // get the names of all data sources
     153           0 :         ODataSourceContext aContext( getORB() );
     154           0 :         aContext.getDataSourceNames( m_aInvalidDataSourceNames );
     155             : 
     156             :         // give the name edit the focus
     157           0 :         m_pLocation->GrabFocus();
     158             : 
     159             :         // default the finish button
     160           0 :         getDialog()->defaultButton( WZB_FINISH );
     161           0 :     }
     162             : 
     163             : 
     164           0 :     void FinalPage::DeactivatePage()
     165             :     {
     166           0 :         AddressBookSourcePage::DeactivatePage();
     167             : 
     168             :         // default the "next" button, again
     169           0 :         getDialog()->defaultButton( WZB_NEXT );
     170             :         // disable the finish button
     171           0 :         getDialog()->enableButtons( WZB_FINISH, false );
     172           0 :     }
     173             : 
     174             : 
     175           0 :     bool FinalPage::canAdvance() const
     176             :     {
     177           0 :         return false;
     178             :     }
     179             : 
     180             : 
     181           0 :     void FinalPage::implCheckName()
     182             :     {
     183           0 :         bool bValidName = isValidName();
     184           0 :         bool bEmptyName = m_pName->GetText().isEmpty();
     185           0 :         bool bEmptyLocation = m_pLocation->GetText().isEmpty();
     186             : 
     187             :         // enable or disable the finish button
     188           0 :         getDialog()->enableButtons( WZB_FINISH, !bEmptyLocation && (!m_pRegisterName->IsChecked() || bValidName) );
     189             : 
     190             :         // show the error message for an invalid name
     191           0 :         m_pDuplicateNameError->Show( !bValidName && !bEmptyName );
     192           0 :     }
     193             : 
     194             : 
     195           0 :     IMPL_LINK( FinalPage, OnNameModified, Edit*, /**/ )
     196             :     {
     197           0 :         implCheckName();
     198           0 :         return 0L;
     199             :     }
     200             : 
     201             : 
     202           0 :     IMPL_LINK_NOARG(FinalPage, OnRegister)
     203             :     {
     204           0 :         bool bEnable = m_pRegisterName->IsChecked();
     205           0 :         m_pNameLabel->Enable(bEnable);
     206           0 :         m_pName->Enable(bEnable);
     207           0 :         implCheckName();
     208           0 :         return 0L;
     209             :     }
     210             : 
     211           0 : }   // namespace abp
     212             : 
     213             : 
     214             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10