LCOV - code coverage report
Current view: top level - extensions/source/abpilot - abpfinalpage.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 85 0.0 %
Date: 2014-04-14 Functions: 0 14 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             : 
      47             : 
      48           0 :     FinalPage::FinalPage( OAddessBookSourcePilot* _pParent )
      49             :         :AddressBookSourcePage(_pParent, ModuleRes(RID_PAGE_FINAL))
      50             :         ,m_aExplanation         ( this, ModuleRes( FT_FINISH_EXPL ) )
      51             :         ,m_aLocationLabel       ( this, ModuleRes( FT_LOCATION ) )
      52             :         ,m_aLocation            ( this, ModuleRes( CBB_LOCATION ) )
      53             :         ,m_aBrowse              ( this, ModuleRes( PB_BROWSE ) )
      54             :         ,m_aRegisterName        ( this, ModuleRes( CB_REGISTER_DS ) )
      55             :         ,m_aNameLabel           ( this, ModuleRes( FT_NAME_EXPL ) )
      56             :         ,m_aName                ( this, ModuleRes( ET_DATASOURCENAME ) )
      57             :         ,m_aDuplicateNameError  ( this, ModuleRes( FT_DUPLICATENAME ) )
      58           0 :         ,m_aLocationController( _pParent->getORB(), m_aLocation, m_aBrowse )
      59             :     {
      60           0 :         FreeResource();
      61             : 
      62           0 :         m_aName.SetModifyHdl( LINK(this, FinalPage, OnNameModified) );
      63           0 :         m_aLocation.SetModifyHdl( LINK(this, FinalPage, OnNameModified) );
      64           0 :         m_aRegisterName.SetClickHdl( LINK( this, FinalPage, OnRegister ) );
      65           0 :         m_aRegisterName.Check(true);
      66           0 :     }
      67             : 
      68             : 
      69           0 :     sal_Bool FinalPage::isValidName() const
      70             :     {
      71           0 :         OUString sCurrentName(m_aName.GetText());
      72             : 
      73           0 :         if (sCurrentName.isEmpty())
      74             :             // the name must not be empty
      75           0 :             return sal_False;
      76             : 
      77           0 :         if ( m_aInvalidDataSourceNames.find( sCurrentName ) != m_aInvalidDataSourceNames.end() )
      78             :             // there already is a data source with this name
      79           0 :             return sal_False;
      80             : 
      81           0 :         return sal_True;
      82             :     }
      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_aLocationController.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_aName.SetText(sName);
     115             : 
     116           0 :         OnRegister(&m_aRegisterName);
     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_aLocationController.prepareCommit() )
     135             :             )
     136           0 :             return false;
     137             : 
     138           0 :         AddressSettings& rSettings = getSettings();
     139           0 :         rSettings.sDataSourceName = m_aLocationController.getURL();
     140           0 :         rSettings.bRegisterDataSource = m_aRegisterName.IsChecked();
     141           0 :         if ( rSettings.bRegisterDataSource )
     142           0 :             rSettings.sRegisteredDataSourceName = m_aName.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_aLocation.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 :         sal_Bool bValidName = isValidName();
     184           0 :         sal_Bool bEmptyName = m_aName.GetText().isEmpty();
     185           0 :         sal_Bool bEmptyLocation = m_aLocation.GetText().isEmpty();
     186             : 
     187             :         // enable or disable the finish button
     188           0 :         getDialog()->enableButtons( WZB_FINISH, !bEmptyLocation && (!m_aRegisterName.IsChecked() || bValidName) );
     189             : 
     190             :         // show the error message for an invalid name
     191           0 :         m_aDuplicateNameError.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 :         sal_Bool bEnable = m_aRegisterName.IsChecked();
     205           0 :         m_aNameLabel.Enable(bEnable);
     206           0 :         m_aName.Enable(bEnable);
     207           0 :         implCheckName();
     208           0 :         return 0L;
     209             :     }
     210             : 
     211             : }   // namespace abp
     212             : 
     213             : 
     214             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10