LCOV - code coverage report
Current view: top level - libreoffice/extensions/source/abpilot - abpfinalpage.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 85 0.0 %
Date: 2012-12-27 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 <comphelper/componentcontext.hxx>
      30             : #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
      31             : 
      32             : //.........................................................................
      33             : namespace abp
      34             : {
      35             : //.........................................................................
      36             :     using namespace ::svt;
      37             :     using namespace ::utl;
      38             : 
      39           0 :     const SfxFilter* lcl_getBaseFilter()
      40             :     {
      41           0 :         const SfxFilter* pFilter = SfxFilter::GetFilterByName(rtl::OUString("StarOffice XML (Base)"));
      42             :         OSL_ENSURE(pFilter,"Filter: StarOffice XML (Base) could not be found!");
      43           0 :         return pFilter;
      44             :     }
      45             :     //=====================================================================
      46             :     //= FinalPage
      47             :     //=====================================================================
      48             :     //---------------------------------------------------------------------
      49           0 :     FinalPage::FinalPage( OAddessBookSourcePilot* _pParent )
      50             :         :AddressBookSourcePage(_pParent, ModuleRes(RID_PAGE_FINAL))
      51             :         ,m_aExplanation         ( this, ModuleRes( FT_FINISH_EXPL ) )
      52             :         ,m_aLocationLabel       ( this, ModuleRes( FT_LOCATION ) )
      53             :         ,m_aLocation            ( this, ModuleRes( CBB_LOCATION ) )
      54             :         ,m_aBrowse              ( this, ModuleRes( PB_BROWSE ) )
      55             :         ,m_aRegisterName        ( this, ModuleRes( CB_REGISTER_DS ) )
      56             :         ,m_aNameLabel           ( this, ModuleRes( FT_NAME_EXPL ) )
      57             :         ,m_aName                ( this, ModuleRes( ET_DATASOURCENAME ) )
      58             :         ,m_aDuplicateNameError  ( this, ModuleRes( FT_DUPLICATENAME ) )
      59           0 :         ,m_aLocationController( ::comphelper::ComponentContext( _pParent->getORB() ), m_aLocation, m_aBrowse )
      60             :     {
      61           0 :         FreeResource();
      62             : 
      63           0 :         m_aName.SetModifyHdl( LINK(this, FinalPage, OnNameModified) );
      64           0 :         m_aLocation.SetModifyHdl( LINK(this, FinalPage, OnNameModified) );
      65           0 :         m_aRegisterName.SetClickHdl( LINK( this, FinalPage, OnRegister ) );
      66           0 :         m_aRegisterName.Check(sal_True);
      67           0 :     }
      68             : 
      69             :     //---------------------------------------------------------------------
      70           0 :     sal_Bool FinalPage::isValidName() const
      71             :     {
      72           0 :         ::rtl::OUString sCurrentName(m_aName.GetText());
      73             : 
      74           0 :         if (sCurrentName.isEmpty())
      75             :             // the name must not be empty
      76           0 :             return sal_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 sal_False;
      81             : 
      82           0 :         return sal_True;
      83             :     }
      84             : 
      85             :     //---------------------------------------------------------------------
      86           0 :     void FinalPage::setFields()
      87             :     {
      88           0 :         AddressSettings& rSettings = getSettings();
      89             : 
      90           0 :         INetURLObject aURL( rSettings.sDataSourceName );
      91           0 :         if( aURL.GetProtocol() == INET_PROT_NOT_VALID )
      92             :         {
      93           0 :             String sPath = SvtPathOptions().GetWorkPath();
      94           0 :             sPath += '/';
      95           0 :             sPath += String(rSettings.sDataSourceName);
      96             : 
      97           0 :             const SfxFilter* pFilter = lcl_getBaseFilter();
      98           0 :             if ( pFilter )
      99             :             {
     100           0 :                 String sExt = pFilter->GetDefaultExtension();
     101           0 :                 sPath += sExt.GetToken(1,'*');
     102             :             }
     103             : 
     104           0 :             aURL.SetURL(sPath);
     105             :         }
     106             :         OSL_ENSURE( aURL.GetProtocol() != INET_PROT_NOT_VALID ,"No valid file name!");
     107           0 :         rSettings.sDataSourceName = aURL.GetMainURL( INetURLObject::NO_DECODE );
     108           0 :         m_aLocationController.setURL( rSettings.sDataSourceName );
     109           0 :         String sName = aURL.getName( );
     110           0 :         xub_StrLen nPos = sName.Search(String(aURL.GetExtension()));
     111           0 :         if ( nPos != STRING_NOTFOUND )
     112             :         {
     113           0 :             sName.Erase(nPos-1,4);
     114             :         }
     115           0 :         m_aName.SetText(sName);
     116             : 
     117           0 :         OnRegister(&m_aRegisterName);
     118           0 :     }
     119             : 
     120             :     //---------------------------------------------------------------------
     121           0 :     void FinalPage::initializePage()
     122             :     {
     123           0 :         AddressBookSourcePage::initializePage();
     124             : 
     125           0 :         setFields();
     126           0 :     }
     127             : 
     128             :     //---------------------------------------------------------------------
     129           0 :     sal_Bool FinalPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
     130             :     {
     131           0 :         if (!AddressBookSourcePage::commitPage(_eReason))
     132           0 :             return sal_False;
     133             : 
     134           0 :         if  (   ( ::svt::WizardTypes::eTravelBackward != _eReason )
     135           0 :             &&  ( !m_aLocationController.prepareCommit() )
     136             :             )
     137           0 :             return sal_False;
     138             : 
     139           0 :         AddressSettings& rSettings = getSettings();
     140           0 :         rSettings.sDataSourceName = m_aLocationController.getURL();
     141           0 :         rSettings.bRegisterDataSource = m_aRegisterName.IsChecked();
     142           0 :         if ( rSettings.bRegisterDataSource )
     143           0 :             rSettings.sRegisteredDataSourceName = m_aName.GetText();
     144             : 
     145           0 :         return sal_True;
     146             :     }
     147             : 
     148             :     //---------------------------------------------------------------------
     149           0 :     void FinalPage::ActivatePage()
     150             :     {
     151           0 :         AddressBookSourcePage::ActivatePage();
     152             : 
     153             :         // get the names of all data sources
     154           0 :         ODataSourceContext aContext( getORB() );
     155           0 :         aContext.getDataSourceNames( m_aInvalidDataSourceNames );
     156             : 
     157             :         // give the name edit the focus
     158           0 :         m_aLocation.GrabFocus();
     159             : 
     160             :         // default the finish button
     161           0 :         getDialog()->defaultButton( WZB_FINISH );
     162           0 :     }
     163             : 
     164             :     //---------------------------------------------------------------------
     165           0 :     void FinalPage::DeactivatePage()
     166             :     {
     167           0 :         AddressBookSourcePage::DeactivatePage();
     168             : 
     169             :         // default the "next" button, again
     170           0 :         getDialog()->defaultButton( WZB_NEXT );
     171             :         // disable the finish button
     172           0 :         getDialog()->enableButtons( WZB_FINISH, sal_False );
     173           0 :     }
     174             : 
     175             :     //---------------------------------------------------------------------
     176           0 :     bool FinalPage::canAdvance() const
     177             :     {
     178           0 :         return false;
     179             :     }
     180             : 
     181             :     //---------------------------------------------------------------------
     182           0 :     void FinalPage::implCheckName()
     183             :     {
     184           0 :         sal_Bool bValidName = isValidName();
     185           0 :         sal_Bool bEmptyName = 0 == m_aName.GetText().Len();
     186           0 :         sal_Bool bEmptyLocation = 0 == m_aLocation.GetText().Len();
     187             : 
     188             :         // enable or disable the finish button
     189           0 :         getDialog()->enableButtons( WZB_FINISH, !bEmptyLocation && (!m_aRegisterName.IsChecked() || bValidName) );
     190             : 
     191             :         // show the error message for an invalid name
     192           0 :         m_aDuplicateNameError.Show( !bValidName && !bEmptyName );
     193           0 :     }
     194             : 
     195             :     //---------------------------------------------------------------------
     196           0 :     IMPL_LINK( FinalPage, OnNameModified, Edit*, /**/ )
     197             :     {
     198           0 :         implCheckName();
     199           0 :         return 0L;
     200             :     }
     201             : 
     202             :     // -----------------------------------------------------------------------------
     203           0 :     IMPL_LINK_NOARG(FinalPage, OnRegister)
     204             :     {
     205           0 :         sal_Bool bEnable = m_aRegisterName.IsChecked();
     206           0 :         m_aNameLabel.Enable(bEnable);
     207           0 :         m_aName.Enable(bEnable);
     208           0 :         implCheckName();
     209           0 :         return 0L;
     210             :     }
     211             : //.........................................................................
     212             : }   // namespace abp
     213             : //.........................................................................
     214             : 
     215             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10