LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/dbui - mmdocselectpage.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 82 0.0 %
Date: 2012-12-27 Functions: 0 10 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 <unotools/pathoptions.hxx>
      21             : #include <sfx2/filedlghelper.hxx>
      22             : #include <sfx2/new.hxx>
      23             : #include <sfx2/docfilt.hxx>
      24             : #include <sfx2/fcontnr.hxx>
      25             : #include <sfx2/docfac.hxx>
      26             : #include <vcl/msgbox.hxx>
      27             : #include <view.hxx>
      28             : #include <docsh.hxx>
      29             : #include <mmdocselectpage.hxx>
      30             : #include <mailmergewizard.hxx>
      31             : #include <shellio.hxx>
      32             : #include <swabstdlg.hxx>
      33             : #include <mmconfigitem.hxx>
      34             : 
      35             : #include <dbui.hrc>
      36             : #include <mmdocselectpage.hrc>
      37             : 
      38             : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
      39             : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
      40             : #include <com/sun/star/ui/dialogs/XFilterManager.hpp>
      41             : 
      42             : using namespace ::com::sun::star::ui::dialogs;
      43             : using namespace ::com::sun::star;
      44             : using namespace ::com::sun::star::uno;
      45             : using namespace svt;
      46             : 
      47           0 : SwMailMergeDocSelectPage::SwMailMergeDocSelectPage( SwMailMergeWizard* _pParent ) :
      48             :     svt::OWizardPage(_pParent, SW_RES(DLG_MM_DOCSELECT_PAGE)),
      49             : #ifdef MSC
      50             : #pragma warning (disable : 4355)
      51             : #endif
      52             :     m_aHeaderFI(this,          SW_RES(  FI_HEADER           ) ),
      53             :     m_aHowToFT          (this, SW_RES( FT_HOWTO )),
      54             :     m_aCurrentDocRB     (this, SW_RES( RB_CURRENTDOC )),
      55             :     m_aNewDocRB         (this, SW_RES( RB_NEWDOC )),
      56             :     m_aLoadDocRB        (this, SW_RES( RB_LOADDOC )),
      57             :     m_aLoadTemplateRB   (this, SW_RES( RB_LOADTEMPLATE )),
      58             :     m_aRecentDocRB      (this, SW_RES( RB_RECENTDOC )),
      59             :     m_aBrowseDocPB      (this, SW_RES( PB_LOADDOC )),
      60             :     m_aBrowseTemplatePB (this, SW_RES( PB_BROWSETEMPLATE )),
      61             :     m_aRecentDocLB      (this, SW_RES( LB_RECENTDOC )),
      62             : #ifdef MSC
      63             : #pragma warning (default : 4355)
      64             : #endif
      65           0 :     m_pWizard(_pParent)
      66             : {
      67           0 :     FreeResource();
      68             : 
      69           0 :     m_aCurrentDocRB.Check();
      70           0 :     DocSelectHdl(&m_aNewDocRB);
      71             : 
      72           0 :     Link aDocSelectLink = LINK(this, SwMailMergeDocSelectPage, DocSelectHdl);
      73           0 :     m_aCurrentDocRB.SetClickHdl(aDocSelectLink);
      74           0 :     m_aNewDocRB.SetClickHdl(aDocSelectLink);
      75           0 :     m_aLoadDocRB.SetClickHdl(aDocSelectLink);
      76           0 :     m_aLoadTemplateRB.SetClickHdl(aDocSelectLink);
      77           0 :     m_aRecentDocRB.SetClickHdl(aDocSelectLink);
      78             : 
      79           0 :     Link aFileSelectHdl = LINK(this, SwMailMergeDocSelectPage, FileSelectHdl);
      80           0 :     m_aBrowseDocPB.SetClickHdl(aFileSelectHdl);
      81           0 :     m_aBrowseTemplatePB.SetClickHdl(aFileSelectHdl);
      82             : 
      83             :     const uno::Sequence< ::rtl::OUString >& rDocs =
      84           0 :                             m_pWizard->GetConfigItem().GetSavedDocuments();
      85           0 :     for(sal_Int32 nDoc = 0; nDoc < rDocs.getLength(); ++nDoc)
      86             :     {
      87             :         //insert in reverse order
      88           0 :         m_aRecentDocLB.InsertEntry(rDocs[nDoc], 0);
      89             :     }
      90           0 :     m_aRecentDocLB.SelectEntryPos(0);
      91           0 :     if(!rDocs.getLength())
      92             :     {
      93           0 :         m_aRecentDocRB.Enable(sal_False);
      94             :     }
      95           0 : }
      96             : 
      97           0 : SwMailMergeDocSelectPage::~SwMailMergeDocSelectPage()
      98             : {
      99           0 : }
     100             : 
     101           0 : IMPL_LINK(SwMailMergeDocSelectPage, DocSelectHdl, RadioButton*, pButton)
     102             : {
     103           0 :     m_aRecentDocLB.Enable(&m_aRecentDocRB == pButton);
     104             : 
     105           0 :     m_pWizard->UpdateRoadmap();
     106           0 :     m_pWizard->enableButtons(WZB_NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
     107             : 
     108           0 :     return 0;
     109             : }
     110             : 
     111           0 : IMPL_LINK(SwMailMergeDocSelectPage, FileSelectHdl, PushButton*, pButton)
     112             : {
     113           0 :     bool bTemplate = &m_aBrowseTemplatePB == pButton;
     114             : 
     115           0 :     if(bTemplate)
     116             :     {
     117           0 :         m_aLoadTemplateRB.Check();
     118           0 :         SfxNewFileDialog* pNewFileDlg = new SfxNewFileDialog(this, 0);
     119           0 :         sal_uInt16 nRet = pNewFileDlg->Execute();
     120           0 :         if(RET_TEMPLATE_LOAD == nRet)
     121           0 :             bTemplate = false;
     122           0 :         else if(RET_CANCEL != nRet)
     123           0 :             m_sLoadTemplateName = pNewFileDlg->GetTemplateFileName();
     124           0 :         delete pNewFileDlg;
     125             :     }
     126             :     else
     127           0 :         m_aLoadDocRB.Check();
     128             : 
     129           0 :     if(!bTemplate)
     130             :     {
     131           0 :         sfx2::FileDialogHelper aDlgHelper( TemplateDescription::FILEOPEN_SIMPLE, 0 );
     132           0 :         Reference < XFilePicker > xFP = aDlgHelper.GetFilePicker();
     133             : 
     134           0 :         xFP->setDisplayDirectory( SvtPathOptions().GetWorkPath() );
     135             : 
     136           0 :         SfxObjectFactory &rFact = m_pWizard->GetSwView()->GetDocShell()->GetFactory();
     137           0 :         SfxFilterMatcher aMatcher( rtl::OUString::createFromAscii(rFact.GetShortName()) );
     138           0 :         SfxFilterMatcherIter aIter( aMatcher );
     139           0 :         Reference<XFilterManager> xFltMgr(xFP, UNO_QUERY);
     140           0 :         const SfxFilter* pFlt = aIter.First();
     141           0 :         while( pFlt )
     142             :         {
     143           0 :             if( pFlt && pFlt->IsAllowedAsTemplate() )
     144             :             {
     145           0 :                 const String sWild = pFlt->GetWildcard().getGlob();
     146           0 :                 xFltMgr->appendFilter( pFlt->GetUIName(), sWild );
     147             : 
     148             :                 // #i40125
     149           0 :                 if(pFlt->GetFilterFlags() & SFX_FILTER_DEFAULT)
     150           0 :                     xFltMgr->setCurrentFilter( pFlt->GetUIName() ) ;
     151             :             }
     152             : 
     153             : 
     154           0 :             pFlt = aIter.Next();
     155             :         }
     156             : 
     157           0 :         if( ERRCODE_NONE == aDlgHelper.Execute() )
     158             :         {
     159           0 :             m_sLoadFileName = xFP->getFiles().getConstArray()[0];
     160           0 :         }
     161             :     }
     162           0 :     m_pWizard->UpdateRoadmap();
     163           0 :     m_pWizard->enableButtons(WZB_NEXT, m_pWizard->isStateEnabled(MM_OUTPUTTYPETPAGE));
     164             : 
     165           0 :     return 0;
     166             : }
     167             : 
     168           0 : sal_Bool SwMailMergeDocSelectPage::commitPage( ::svt::WizardTypes::CommitPageReason _eReason )
     169             : {
     170           0 :     sal_Bool bReturn = sal_False;
     171           0 :     bool bNext = _eReason == ::svt::WizardTypes::eTravelForward;
     172           0 :     if(bNext || _eReason == ::svt::WizardTypes::eValidate )
     173             :     {
     174           0 :         ::rtl::OUString sReloadDocument;
     175           0 :         bReturn = m_aCurrentDocRB.IsChecked() ||
     176           0 :                 m_aNewDocRB.IsChecked() ||
     177           0 :                 (!(sReloadDocument = m_sLoadFileName).isEmpty() && m_aLoadDocRB.IsChecked() )||
     178           0 :                 (!(sReloadDocument = m_sLoadTemplateName).isEmpty() && m_aLoadTemplateRB.IsChecked())||
     179           0 :                 (m_aRecentDocRB.IsChecked() && !(sReloadDocument = m_aRecentDocLB.GetSelectEntry()).isEmpty());
     180           0 :         if( _eReason == ::svt::WizardTypes::eValidate )
     181           0 :             m_pWizard->SetDocumentLoad(!m_aCurrentDocRB.IsChecked());
     182             : 
     183           0 :         if(bNext && !m_aCurrentDocRB.IsChecked())
     184             :         {
     185           0 :             if(!sReloadDocument.isEmpty())
     186           0 :                 m_pWizard->SetReloadDocument( sReloadDocument );
     187           0 :             m_pWizard->SetRestartPage(MM_OUTPUTTYPETPAGE);
     188           0 :             m_pWizard->EndDialog(RET_LOAD_DOC);
     189           0 :         }
     190             :     }
     191           0 :     return bReturn;
     192           0 : }
     193             : 
     194             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10