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

Generated by: LCOV version 1.11