LCOV - code coverage report
Current view: top level - sw/source/ui/dbui - mailmergewizard.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 121 0.0 %
Date: 2014-04-14 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             :  * 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 <mailmergewizard.hxx>
      21             : #include <mmdocselectpage.hxx>
      22             : #include <mmoutputtypepage.hxx>
      23             : #include <mmaddressblockpage.hxx>
      24             : #include <mmpreparemergepage.hxx>
      25             : #include <mmmergepage.hxx>
      26             : #include <mmgreetingspage.hxx>
      27             : #include <mmoutputpage.hxx>
      28             : #include <mmlayoutpage.hxx>
      29             : #include <mmconfigitem.hxx>
      30             : #include <swabstdlg.hxx>
      31             : #include <dbui.hrc>
      32             : #include <view.hxx>
      33             : #include <dbmgr.hxx>
      34             : #include <sfx2/viewfrm.hxx>
      35             : #include <wrtsh.hxx>
      36             : #include "vcl/msgbox.hxx"
      37             : 
      38             : #include <helpid.h>
      39             : #include <mailmergewizard.hrc>
      40             : 
      41             : using namespace svt;
      42             : using namespace ::com::sun::star;
      43             : 
      44           0 : SwMailMergeWizard::SwMailMergeWizard(SwView& rView, SwMailMergeConfigItem& rItem) :
      45           0 :         RoadmapWizard(&rView.GetViewFrame()->GetWindow(),
      46             :                         SW_RES(DLG_MAILMERGEWIZARD),
      47             :                         WZB_NEXT|WZB_PREVIOUS|WZB_FINISH|WZB_CANCEL|WZB_HELP),
      48             :         m_pSwView(&rView),
      49             :         m_bDocumentLoad( false ),
      50             :         m_rConfigItem(rItem),
      51             :         m_sStarting(        SW_RES( ST_STARTING      )),
      52             :         m_sDocumentType(    SW_RES( ST_DOCUMETNTYPE   )),
      53             :         m_sAddressBlock(    SW_RES( ST_ADDRESSBLOCK   )),
      54             :         m_sAddressList(     SW_RES( ST_ADDRESSLIST )),
      55             :         m_sGreetingsLine(   SW_RES( ST_GREETINGSLINE   )),
      56             :         m_sLayout(          SW_RES( ST_LAYOUT        )),
      57             :         m_sPrepareMerge(    SW_RES( ST_PREPAREMERGE )),
      58             :         m_sMerge(           SW_RES( ST_MERGE        )),
      59             :         m_sOutput(          SW_RES( ST_OUTPUT       )),
      60             :         m_sFinish(          SW_RES( ST_FINISH       )),
      61           0 :         m_nRestartPage( MM_DOCUMENTSELECTPAGE )
      62             : {
      63           0 :     FreeResource();
      64           0 :     ShowButtonFixedLine(true);
      65           0 :     defaultButton(WZB_NEXT);
      66           0 :     enableButtons(WZB_FINISH, false);
      67             : 
      68           0 :     m_pFinish->SetText(m_sFinish);
      69           0 :     m_pNextPage->SetHelpId(HID_MM_NEXT_PAGE);
      70           0 :     m_pPrevPage->SetHelpId(HID_MM_PREV_PAGE);
      71             : 
      72             :     //#i51949# no output type page visible if e-Mail is not supported
      73           0 :     if(rItem.IsMailAvailable())
      74             :         declarePath(
      75             :             0,
      76             :             MM_DOCUMENTSELECTPAGE,
      77             :             MM_OUTPUTTYPETPAGE,
      78             :             MM_ADDRESSBLOCKPAGE,
      79             :             MM_GREETINGSPAGE,
      80             :             MM_LAYOUTPAGE,
      81             :             MM_PREPAREMERGEPAGE,
      82             :             MM_MERGEPAGE,
      83             :             MM_OUTPUTPAGE,
      84             :             WZS_INVALID_STATE
      85           0 :         );
      86             :     else
      87             :         declarePath(
      88             :             0,
      89             :             MM_DOCUMENTSELECTPAGE,
      90             :             MM_ADDRESSBLOCKPAGE,
      91             :             MM_GREETINGSPAGE,
      92             :             MM_LAYOUTPAGE,
      93             :             MM_PREPAREMERGEPAGE,
      94             :             MM_MERGEPAGE,
      95             :             MM_OUTPUTPAGE,
      96             :             WZS_INVALID_STATE
      97           0 :         );
      98             : 
      99           0 :     ActivatePage();
     100           0 :     UpdateRoadmap();
     101           0 : }
     102             : 
     103           0 : SwMailMergeWizard::~SwMailMergeWizard()
     104             : {
     105           0 : }
     106             : 
     107           0 : OWizardPage*    SwMailMergeWizard::createPage(WizardState _nState)
     108             : {
     109           0 :     OWizardPage* pRet = 0;
     110           0 :     switch(_nState)
     111             :     {
     112           0 :         case MM_DOCUMENTSELECTPAGE : pRet = new SwMailMergeDocSelectPage(this);     break;
     113           0 :         case MM_OUTPUTTYPETPAGE : pRet = new SwMailMergeOutputTypePage(this);       break;
     114           0 :         case MM_ADDRESSBLOCKPAGE  : pRet = new SwMailMergeAddressBlockPage(this);     break;
     115           0 :         case MM_GREETINGSPAGE     : pRet = new SwMailMergeGreetingsPage(this);      break;
     116           0 :         case MM_LAYOUTPAGE        : pRet = new SwMailMergeLayoutPage(this);     break;
     117           0 :         case MM_PREPAREMERGEPAGE  : pRet = new SwMailMergePrepareMergePage(this);   break;
     118           0 :         case MM_MERGEPAGE         : pRet = new SwMailMergeMergePage(this);          break;
     119           0 :         case MM_OUTPUTPAGE       :  pRet = new SwMailMergeOutputPage(this);         break;
     120             :     }
     121             :     OSL_ENSURE(pRet, "no page created in ::createPage");
     122           0 :     return pRet;
     123             : }
     124             : 
     125           0 : void SwMailMergeWizard::enterState( WizardState _nState )
     126             : {
     127           0 :     ::svt::RoadmapWizard::enterState( _nState );
     128             : /*
     129             : 
     130             :     entering a page after the layoutpage requires the insertion
     131             :     of greeting and address block - if not yet done
     132             :     entering the merge or output page requires to create the output document
     133             : */
     134           0 :     if(_nState > MM_LAYOUTPAGE && m_rConfigItem.GetSourceView() &&
     135           0 :             ((m_rConfigItem.IsAddressBlock() && !m_rConfigItem.IsAddressInserted()) ||
     136           0 :              (m_rConfigItem.IsGreetingLine(sal_False) && !m_rConfigItem.IsGreetingInserted() )))
     137             :     {
     138             :         SwMailMergeLayoutPage::InsertAddressAndGreeting(m_rConfigItem.GetSourceView(),
     139           0 :                                 m_rConfigItem, Point(-1, -1), true);
     140             :     }
     141           0 :     if(_nState >= MM_MERGEPAGE && !m_rConfigItem.GetTargetView())
     142             :     {
     143           0 :         CreateTargetDocument();
     144           0 :         m_nRestartPage = _nState;
     145           0 :         EndDialog(RET_TARGET_CREATED);
     146           0 :         return;
     147             :     }
     148           0 :     else if(_nState < MM_MERGEPAGE && m_rConfigItem.GetTargetView())
     149             :     {
     150             :         //close the dialog, remove the target view, show the source view
     151           0 :         m_nRestartPage = _nState;
     152             :         //set ResultSet back to start
     153           0 :         m_rConfigItem.MoveResultSet(1);
     154           0 :         EndDialog(RET_REMOVE_TARGET);
     155           0 :         return;
     156             :     }
     157           0 :     bool bEnablePrev = true;
     158           0 :     bool bEnableNext = true;
     159           0 :     switch(_nState)
     160             :     {
     161             :         case MM_DOCUMENTSELECTPAGE :
     162           0 :             bEnablePrev = false;
     163           0 :         break;
     164             :         case MM_ADDRESSBLOCKPAGE  :
     165           0 :             bEnableNext = m_rConfigItem.GetResultSet().is();
     166           0 :         break;
     167             :         case MM_OUTPUTPAGE       :
     168           0 :             bEnableNext = false;
     169           0 :         break;
     170             :     }
     171           0 :     enableButtons( WZB_PREVIOUS, bEnablePrev);
     172           0 :     enableButtons( WZB_NEXT, bEnableNext);
     173             : 
     174           0 :     UpdateRoadmap();
     175             : }
     176             : 
     177           0 : OUString SwMailMergeWizard::getStateDisplayName( WizardState _nState ) const
     178             : {
     179           0 :     switch(_nState)
     180             :     {
     181             :         case MM_DOCUMENTSELECTPAGE:
     182           0 :             return m_sStarting;
     183             :         case MM_OUTPUTTYPETPAGE:
     184           0 :             return m_sDocumentType;
     185             :         case MM_ADDRESSBLOCKPAGE:
     186           0 :             return m_rConfigItem.IsOutputToLetter() ?
     187           0 :                    m_sAddressBlock : m_sAddressList;
     188             :         case MM_GREETINGSPAGE:
     189           0 :             return m_sGreetingsLine;
     190             :         case MM_LAYOUTPAGE:
     191           0 :             return m_sLayout;
     192             :         case MM_PREPAREMERGEPAGE:
     193           0 :             return m_sPrepareMerge;
     194             :         case MM_MERGEPAGE:
     195           0 :             return m_sMerge;
     196             :         case MM_OUTPUTPAGE:
     197           0 :             return m_sOutput;
     198             :     }
     199           0 :     return OUString();
     200             : }
     201             : /*----------------------------------------------------------------------
     202             :     enables/disables pages in the roadmap depending on the current
     203             :     page and state
     204             :   -----------------------------------------------------------------------*/
     205           0 : void SwMailMergeWizard::UpdateRoadmap()
     206             : {
     207             : /*
     208             :     MM_DOCUMENTSELECTPAGE       > inactive after the layoutpage
     209             :     MM_OUTPUTTYPETPAGE :        > inactive after the layoutpage
     210             :     MM_ADDRESSBLOCKPAGE         > inactive after the layoutpage
     211             :     MM_GREETINGSPAGE            > inactive after the layoutpage
     212             :     MM_LAYOUTPAGE               >   inactive after the layoutpage
     213             :                                     inactive if address block and greeting are switched off
     214             :                                     or are already inserted into the source document
     215             :     MM_PREPAREMERGEPAGE         > only active if address data has been selected
     216             :                                     inactive after preparemerge page
     217             :     MM_MERGEPAGE                > only active if address data has been selected
     218             : 
     219             :     MM_OUTPUTPAGE               > only active if address data has been selected
     220             : */
     221             : 
     222             :     // enableState( <page id>, false );
     223           0 :     const sal_uInt16 nCurPage = GetCurLevel();
     224           0 :     TabPage* pCurPage = GetPage( nCurPage );
     225           0 :     if(!pCurPage)
     226           0 :         return;
     227           0 :     bool bEnable = false;
     228           0 :     bool bAddressFieldsConfigured = !m_rConfigItem.IsOutputToLetter() ||
     229           0 :                 !m_rConfigItem.IsAddressBlock() ||
     230           0 :                 m_rConfigItem.IsAddressFieldsAssigned();
     231           0 :     bool bGreetingFieldsConfigured = !m_rConfigItem.IsGreetingLine(sal_False) ||
     232           0 :             !m_rConfigItem.IsIndividualGreeting(sal_False)||
     233           0 :                     m_rConfigItem.IsGreetingFieldsAssigned();
     234             :     //#i97436# if a document has to be loaded then enable output type page only
     235           0 :     m_bDocumentLoad = false;
     236           0 :     bool bEnableOutputTypePage = (nCurPage != MM_DOCUMENTSELECTPAGE) ||
     237           0 :         static_cast<svt::OWizardPage*>(pCurPage)->commitPage( ::svt::WizardTypes::eValidate );
     238             : 
     239           0 :     for(sal_uInt16 nPage = MM_DOCUMENTSELECTPAGE; nPage <= MM_OUTPUTPAGE; ++nPage)
     240             :     {
     241           0 :         switch(nPage)
     242             :         {
     243             :             case MM_DOCUMENTSELECTPAGE :
     244           0 :                 bEnable = true;
     245           0 :             break;
     246             :             case MM_OUTPUTTYPETPAGE :
     247           0 :                 bEnable = bEnableOutputTypePage;
     248           0 :             break;
     249             :             case MM_ADDRESSBLOCKPAGE  :
     250           0 :                 bEnable = !m_bDocumentLoad && bEnableOutputTypePage;
     251           0 :             break;
     252             :             case MM_GREETINGSPAGE     :
     253           0 :                 bEnable = !m_bDocumentLoad && bEnableOutputTypePage &&
     254           0 :                     m_rConfigItem.GetResultSet().is() &&
     255           0 :                             bAddressFieldsConfigured;
     256           0 :             break;
     257             :             case MM_PREPAREMERGEPAGE  :
     258             :             case MM_MERGEPAGE         :
     259             :             case MM_OUTPUTPAGE       :
     260             :             case MM_LAYOUTPAGE        :
     261           0 :                 bEnable = !m_bDocumentLoad && bEnableOutputTypePage &&
     262           0 :                             m_rConfigItem.GetResultSet().is() &&
     263           0 :                             bAddressFieldsConfigured &&
     264           0 :                             bGreetingFieldsConfigured;
     265           0 :                 if(MM_LAYOUTPAGE == nPage)
     266             :                     bEnable &=
     267           0 :                         ((m_rConfigItem.IsAddressBlock() && !m_rConfigItem.IsAddressInserted()) ||
     268           0 :                             (m_rConfigItem.IsGreetingLine(sal_False) && !m_rConfigItem.IsGreetingInserted() ));
     269           0 :             break;
     270             :         }
     271           0 :         enableState( nPage, bEnable );
     272             :     }
     273             : }
     274             : /*-- --------------------------------------------------------------------
     275             :     enables/disables pages in the roadmap depending on the current
     276             :     page and state
     277             :   -----------------------------------------------------------------------*/
     278           0 : void SwMailMergeWizard::CreateTargetDocument()
     279             : {
     280           0 :     GetSwView()->GetWrtShell().GetNewDBMgr()->
     281           0 :                 MergeDocuments( m_rConfigItem, *GetSwView() );
     282           0 :     m_rConfigItem.SetMergeDone();
     283           0 :     if( m_rConfigItem.GetTargetView() )
     284           0 :         m_rConfigItem.GetTargetView()->GetViewFrame()->GetFrame().Appear();
     285           0 : }
     286             : 
     287           0 : void SwMailMergeWizard::updateRoadmapItemLabel( WizardState _nState )
     288             : {
     289           0 :     svt::RoadmapWizard::updateRoadmapItemLabel( _nState );
     290           0 : }
     291             : 
     292           0 : short SwMailMergeWizard::Execute()
     293             : {
     294             :     OSL_FAIL("SwMailMergeWizard cannot be executed via Dialog::Execute!\n"
     295             :                "It creates a thread (MailDispatcher instance) that will call"
     296             :                "back to VCL apartment => deadlock!\n"
     297             :                "Use Dialog::StartExecuteModal to execute the dialog!" );
     298           0 :     return RET_CANCEL;
     299             : }
     300             : 
     301           0 : void SwMailMergeWizard::StartExecuteModal( const Link& rEndDialogHdl )
     302             : {
     303           0 :     ::svt::RoadmapWizard::StartExecuteModal( rEndDialogHdl );
     304           0 : }
     305             : 
     306             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10