LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/dbui - mailmergewizard.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 121 0.0 %
Date: 2012-12-27 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" // RET_CANCEL
      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(sal_True);
      65           0 :     defaultButton(WZB_NEXT);
      66           0 :     enableButtons(WZB_FINISH, sal_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 : String  SwMailMergeWizard::getStateDisplayName( WizardState _nState ) const
     178             : {
     179           0 :     String sRet;
     180           0 :     switch(_nState)
     181             :     {
     182           0 :         case MM_DOCUMENTSELECTPAGE :sRet = m_sStarting;      break;
     183           0 :         case MM_OUTPUTTYPETPAGE :   sRet = m_sDocumentType;  break;
     184             :         case MM_ADDRESSBLOCKPAGE  :
     185           0 :             sRet =  m_rConfigItem.IsOutputToLetter() ?
     186           0 :                     m_sAddressBlock : m_sAddressList;
     187             : 
     188           0 :         break;
     189           0 :         case MM_GREETINGSPAGE     : sRet = m_sGreetingsLine; break;
     190           0 :         case MM_LAYOUTPAGE        : sRet = m_sLayout;        break;
     191           0 :         case MM_PREPAREMERGEPAGE  : sRet = m_sPrepareMerge;  break;
     192           0 :         case MM_MERGEPAGE         : sRet = m_sMerge;         break;
     193           0 :         case MM_OUTPUTPAGE       : sRet = m_sOutput;        break;
     194             :     }
     195           0 :     return sRet;
     196             : }
     197             : /*----------------------------------------------------------------------
     198             :     enables/disables pages in the roadmap depending on the current
     199             :     page and state
     200             :   -----------------------------------------------------------------------*/
     201           0 : void SwMailMergeWizard::UpdateRoadmap()
     202             : {
     203             : /*
     204             :     MM_DOCUMENTSELECTPAGE       > inactive after the layoutpage
     205             :     MM_OUTPUTTYPETPAGE :        > inactive after the layoutpage
     206             :     MM_ADDRESSBLOCKPAGE         > inactive after the layoutpage
     207             :     MM_GREETINGSPAGE            > inactive after the layoutpage
     208             :     MM_LAYOUTPAGE               >   inactive after the layoutpage
     209             :                                     inactive if address block and greeting are switched off
     210             :                                     or are already inserted into the source document
     211             :     MM_PREPAREMERGEPAGE         > only active if address data has been selected
     212             :                                     inactive after preparemerge page
     213             :     MM_MERGEPAGE                > only active if address data has been selected
     214             : 
     215             :     MM_OUTPUTPAGE               > only active if address data has been selected
     216             : */
     217             : 
     218             :     // enableState( <page id>, false );
     219           0 :     const sal_uInt16 nCurPage = GetCurLevel();
     220           0 :     TabPage* pCurPage = GetPage( nCurPage );
     221           0 :     if(!pCurPage)
     222           0 :         return;
     223           0 :     bool bEnable = false;
     224           0 :     bool bAddressFieldsConfigured = !m_rConfigItem.IsOutputToLetter() ||
     225           0 :                 !m_rConfigItem.IsAddressBlock() ||
     226           0 :                 m_rConfigItem.IsAddressFieldsAssigned();
     227           0 :     bool bGreetingFieldsConfigured = !m_rConfigItem.IsGreetingLine(sal_False) ||
     228           0 :             !m_rConfigItem.IsIndividualGreeting(sal_False)||
     229           0 :                     m_rConfigItem.IsGreetingFieldsAssigned();
     230             :     //#i97436# if a document has to be loaded then enable output type page only
     231           0 :     m_bDocumentLoad = false;
     232             :     bool bEnableOutputTypePage = (nCurPage != MM_DOCUMENTSELECTPAGE) ||
     233           0 :         static_cast<svt::OWizardPage*>(pCurPage)->commitPage( ::svt::WizardTypes::eValidate );
     234             : 
     235           0 :     for(sal_uInt16 nPage = MM_DOCUMENTSELECTPAGE; nPage <= MM_OUTPUTPAGE; ++nPage)
     236             :     {
     237           0 :         switch(nPage)
     238             :         {
     239             :             case MM_DOCUMENTSELECTPAGE :
     240           0 :                 bEnable = sal_True;
     241           0 :             break;
     242             :             case MM_OUTPUTTYPETPAGE :
     243           0 :                 bEnable = bEnableOutputTypePage;
     244           0 :             break;
     245             :             case MM_ADDRESSBLOCKPAGE  :
     246           0 :                 bEnable = !m_bDocumentLoad && bEnableOutputTypePage;
     247           0 :             break;
     248             :             case MM_GREETINGSPAGE     :
     249           0 :                 bEnable = !m_bDocumentLoad && bEnableOutputTypePage &&
     250           0 :                     m_rConfigItem.GetResultSet().is() &&
     251           0 :                             bAddressFieldsConfigured;
     252           0 :             break;
     253             :             case MM_PREPAREMERGEPAGE  :
     254             :             case MM_MERGEPAGE         :
     255             :             case MM_OUTPUTPAGE       :
     256             :             case MM_LAYOUTPAGE        :
     257           0 :                 bEnable = !m_bDocumentLoad && bEnableOutputTypePage &&
     258           0 :                             m_rConfigItem.GetResultSet().is() &&
     259             :                             bAddressFieldsConfigured &&
     260           0 :                             bGreetingFieldsConfigured;
     261           0 :                 if(MM_LAYOUTPAGE == nPage)
     262             :                     bEnable &=
     263           0 :                         ((m_rConfigItem.IsAddressBlock() && !m_rConfigItem.IsAddressInserted()) ||
     264           0 :                             (m_rConfigItem.IsGreetingLine(sal_False) && !m_rConfigItem.IsGreetingInserted() ));
     265           0 :             break;
     266             :         }
     267           0 :         enableState( nPage, bEnable );
     268             :     }
     269             : }
     270             : /*-- --------------------------------------------------------------------
     271             :     enables/disables pages in the roadmap depending on the current
     272             :     page and state
     273             :   -----------------------------------------------------------------------*/
     274           0 : void SwMailMergeWizard::CreateTargetDocument()
     275             : {
     276           0 :     GetSwView()->GetWrtShell().GetNewDBMgr()->
     277           0 :                 MergeDocuments( m_rConfigItem, *GetSwView() );
     278           0 :     m_rConfigItem.SetMergeDone();
     279           0 :     if( m_rConfigItem.GetTargetView() )
     280           0 :         m_rConfigItem.GetTargetView()->GetViewFrame()->GetFrame().Appear();
     281           0 : }
     282             : 
     283           0 : void SwMailMergeWizard::updateRoadmapItemLabel( WizardState _nState )
     284             : {
     285           0 :     svt::RoadmapWizard::updateRoadmapItemLabel( _nState );
     286           0 : }
     287             : 
     288           0 : short SwMailMergeWizard::Execute()
     289             : {
     290             :     OSL_FAIL("SwMailMergeWizard cannot be executed via Dialog::Execute!\n"
     291             :                "It creates a thread (MailDispatcher instance) that will call"
     292             :                "back to VCL apartment => deadlock!\n"
     293             :                "Use Dialog::StartExecuteModal to execute the dialog!" );
     294           0 :     return RET_CANCEL;
     295             : }
     296             : 
     297           0 : void SwMailMergeWizard::StartExecuteModal( const Link& rEndDialogHdl )
     298             : {
     299           0 :     ::svt::RoadmapWizard::StartExecuteModal( rEndDialogHdl );
     300           0 : }
     301             : 
     302             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10