LCOV - code coverage report
Current view: top level - sw/source/ui/dbui - mmoutputpage.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 727 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 58 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 <mmoutputpage.hxx>
      21             : #include <mailmergewizard.hxx>
      22             : #include <mmconfigitem.hxx>
      23             : #include <mailmergechildwindow.hxx>
      24             : #include <mailconfigpage.hxx>
      25             : #include <swmessdialog.hxx>
      26             : #include <cmdid.h>
      27             : #include <swtypes.hxx>
      28             : #include <view.hxx>
      29             : #include <wrtsh.hxx>
      30             : #include <docsh.hxx>
      31             : #include <IDocumentDeviceAccess.hxx>
      32             : #include <hintids.hxx>
      33             : #include <editeng/scripttypeitem.hxx>
      34             : #include <editeng/langitem.hxx>
      35             : #include <svl/itemset.hxx>
      36             : #include <svl/stritem.hxx>
      37             : #include <svtools/ehdl.hxx>
      38             : #include <svtools/sfxecode.hxx>
      39             : #include <vcl/layout.hxx>
      40             : #include <vcl/msgbox.hxx>
      41             : #include <sfx2/dinfdlg.hxx>
      42             : #include <sfx2/printer.hxx>
      43             : #include <sfx2/fcontnr.hxx>
      44             : #include <sfx2/viewfrm.hxx>
      45             : #include <sfx2/dispatch.hxx>
      46             : #include <sfx2/docfile.hxx>
      47             : #include <tools/urlobj.hxx>
      48             : #include <svl/urihelper.hxx>
      49             : #include <vcl/print.hxx>
      50             : #include <vcl/settings.hxx>
      51             : 
      52             : #include <unotools/tempfile.hxx>
      53             : #include <osl/file.hxx>
      54             : #include <mmgreetingspage.hxx>
      55             : #include <com/sun/star/frame/XStorable.hpp>
      56             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      57             : #include <com/sun/star/sdb/XColumn.hpp>
      58             : #include <com/sun/star/task/ErrorCodeIOException.hpp>
      59             : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
      60             : #include <dbmgr.hxx>
      61             : #include <swunohelper.hxx>
      62             : #include <osl/mutex.hxx>
      63             : #include <shellio.hxx>
      64             : #include <svtools/htmlcfg.hxx>
      65             : #include <sfx2/event.hxx>
      66             : #include <swevent.hxx>
      67             : #include <dbui.hxx>
      68             : #include <dbui.hrc>
      69             : #include <helpid.h>
      70             : #include <doc.hxx>
      71             : #include <sfx2/app.hxx>
      72             : #include <statstr.hrc>
      73             : #include <unomid.h>
      74             : #include <comphelper/string.hxx>
      75             : #include <boost/scoped_ptr.hpp>
      76             : 
      77             : using namespace svt;
      78             : using namespace ::com::sun::star;
      79             : using namespace ::com::sun::star::uno;
      80             : 
      81             : #define MM_DOCTYPE_OOO              1
      82             : #define MM_DOCTYPE_PDF              2
      83             : #define MM_DOCTYPE_WORD             3
      84             : #define MM_DOCTYPE_HTML             4
      85             : #define MM_DOCTYPE_TEXT             5
      86             : 
      87           0 : static OUString lcl_GetExtensionForDocType(sal_uLong nDocType)
      88             : {
      89           0 :     OUString sExtension;
      90           0 :     switch( nDocType )
      91             :     {
      92           0 :         case MM_DOCTYPE_OOO : sExtension = "odt"; break;
      93           0 :         case MM_DOCTYPE_PDF : sExtension = "pdf"; break;
      94           0 :         case MM_DOCTYPE_WORD: sExtension = "doc"; break;
      95           0 :         case MM_DOCTYPE_HTML: sExtension = "html"; break;
      96           0 :         case MM_DOCTYPE_TEXT: sExtension = "txt"; break;
      97             :     }
      98           0 :     return sExtension;
      99             : }
     100             : 
     101           0 : static OUString lcl_GetColumnValueOf(const OUString& rColumn, Reference < container::XNameAccess>& rxColAccess )
     102             : {
     103           0 :     OUString sRet;
     104             :     try
     105             :     {
     106           0 :         if (rxColAccess->hasByName(rColumn))
     107             :         {
     108           0 :             Any aCol = rxColAccess->getByName(rColumn);
     109           0 :             Reference< sdb::XColumn > xColumn;
     110           0 :             aCol >>= xColumn;
     111           0 :             if(xColumn.is())
     112           0 :                 sRet = xColumn->getString();
     113             :         }
     114             :     }
     115           0 :     catch (const uno::Exception&)
     116             :     {
     117             :     }
     118           0 :     return sRet;
     119             : }
     120             : 
     121           0 : class SwSaveWarningBox_Impl : public SwMessageAndEditDialog
     122             : {
     123             :     DECL_LINK( ModifyHdl, Edit*);
     124             : public:
     125             :     SwSaveWarningBox_Impl(vcl::Window* pParent, const OUString& rFileName);
     126             : 
     127           0 :     OUString        GetFileName() const
     128             :     {
     129           0 :         return m_pEdit->GetText();
     130             :     }
     131             : };
     132             : 
     133           0 : class SwSendQueryBox_Impl : public SwMessageAndEditDialog
     134             : {
     135             :     bool            bIsEmptyAllowed;
     136             :     DECL_LINK( ModifyHdl, Edit*);
     137             : public:
     138             :     SwSendQueryBox_Impl(vcl::Window* pParent, const OUString& rID,
     139             :         const OUString& rUIXMLDescription);
     140             : 
     141           0 :     void SetValue(const OUString& rSet)
     142             :     {
     143           0 :         m_pEdit->SetText(rSet);
     144           0 :         ModifyHdl(m_pEdit);
     145           0 :     }
     146             : 
     147           0 :     OUString GetValue() const
     148             :     {
     149           0 :         return m_pEdit->GetText();
     150             :     }
     151             : 
     152           0 :     void SetIsEmptyTextAllowed(bool bSet)
     153             :     {
     154           0 :         bIsEmptyAllowed = bSet;
     155           0 :         ModifyHdl(m_pEdit);
     156           0 :     }
     157             : };
     158             : 
     159           0 : SwSaveWarningBox_Impl::SwSaveWarningBox_Impl(vcl::Window* pParent, const OUString& rFileName)
     160             :     : SwMessageAndEditDialog(pParent, "AlreadyExistsDialog",
     161           0 :         "modules/swriter/ui/alreadyexistsdialog.ui")
     162             : {
     163           0 :     m_pEdit->SetText(rFileName);
     164           0 :     m_pEdit->SetModifyHdl(LINK(this, SwSaveWarningBox_Impl, ModifyHdl));
     165             : 
     166           0 :     INetURLObject aTmp(rFileName);
     167           0 :     m_pPrimaryMessage->SetText(m_pPrimaryMessage->GetText().replaceAll("%1", aTmp.getName(
     168           0 :             INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET)));
     169             : 
     170           0 :     ModifyHdl(m_pEdit);
     171           0 : }
     172             : 
     173           0 : IMPL_LINK( SwSaveWarningBox_Impl, ModifyHdl, Edit*, pEdit)
     174             : {
     175           0 :     m_pOKPB->Enable(!pEdit->GetText().isEmpty());
     176           0 :     return 0;
     177             : }
     178             : 
     179           0 : SwSendQueryBox_Impl::SwSendQueryBox_Impl(vcl::Window* pParent, const OUString& rID,
     180             :         const OUString& rUIXMLDescription)
     181             :     : SwMessageAndEditDialog(pParent, rID, rUIXMLDescription)
     182           0 :     , bIsEmptyAllowed(true)
     183             : {
     184           0 :     m_pImageIM->SetImage(QueryBox::GetStandardImage());
     185           0 :     m_pEdit->SetModifyHdl(LINK(this, SwSendQueryBox_Impl, ModifyHdl));
     186           0 :     ModifyHdl(m_pEdit);
     187           0 : }
     188             : 
     189           0 : IMPL_LINK( SwSendQueryBox_Impl, ModifyHdl, Edit*, pEdit)
     190             : {
     191           0 :     m_pOKPB->Enable(bIsEmptyAllowed  || !pEdit->GetText().isEmpty());
     192           0 :     return 0;
     193             : }
     194             : 
     195             : class SwCopyToDialog : public SfxModalDialog
     196             : {
     197             :     VclPtr<Edit> m_pCCED;
     198             :     VclPtr<Edit> m_pBCCED;
     199             : 
     200             : public:
     201           0 :     explicit SwCopyToDialog(vcl::Window* pParent)
     202             :         : SfxModalDialog(pParent, "CCDialog",
     203           0 :             "modules/swriter/ui/ccdialog.ui")
     204             :     {
     205           0 :         get(m_pCCED, "cc");
     206           0 :         get(m_pBCCED, "bcc");
     207           0 :     }
     208           0 :     virtual ~SwCopyToDialog() { disposeOnce(); }
     209           0 :     virtual void dispose() SAL_OVERRIDE
     210             :     {
     211           0 :         m_pCCED.clear();
     212           0 :         m_pBCCED.clear();
     213           0 :         SfxModalDialog::dispose();
     214           0 :     }
     215             : 
     216           0 :     OUString GetCC() {return m_pCCED->GetText();}
     217           0 :     void SetCC(const OUString& rSet) {m_pCCED->SetText(rSet);}
     218             : 
     219           0 :     OUString GetBCC() {return m_pBCCED->GetText();}
     220           0 :     void SetBCC(const OUString& rSet) {m_pBCCED->SetText(rSet);}
     221             : };
     222             : 
     223           0 : SwMailMergeOutputPage::SwMailMergeOutputPage(SwMailMergeWizard* _pParent)
     224             :     : svt::OWizardPage(_pParent, "MMOutputPage",
     225             :         "modules/swriter/ui/mmoutputpage.ui")
     226             :     , m_sSaveStartST(SW_RES(ST_SAVESTART))
     227             :     , m_sSaveMergedST(SW_RES(ST_SAVEMERGED))
     228             :     , m_sPrintST(SW_RES(ST_PRINT))
     229             :     , m_sSendMailST(SW_RES(ST_SENDMAIL))
     230             :     , m_sDefaultAttachmentST(SW_RES(ST_DEFAULTATTACHMENT))
     231             :     , m_sNoSubjectST(SW_RES(ST_NOSUBJECT))
     232             :     , m_sConfigureMail(SW_RES(ST_CONFIGUREMAIL))
     233             :     , m_bCancelSaving(false)
     234             :     , m_pWizard(_pParent)
     235           0 :     , m_pTempPrinter(0)
     236             : {
     237           0 :     get(m_pSaveStartDocRB, "savestarting");
     238           0 :     get(m_pSaveMergedDocRB, "savemerged");
     239           0 :     get(m_pPrintRB, "printmerged");
     240           0 :     get(m_pSendMailRB, "sendmerged");
     241           0 :     get(m_pSeparator, "frame");
     242           0 :     get(m_pSaveStartDocPB, "savestartingdoc");
     243           0 :     get(m_pSaveAsOneRB, "singlerb");
     244           0 :     get(m_pSaveIndividualRB, "individualrb");
     245           0 :     get(m_pPrintAllRB, "printallrb");
     246           0 :     get(m_pSendAllRB, "sendallrb");
     247           0 :     get(m_pFromRB, "fromrb");
     248           0 :     get(m_pFromNF, "from-nospin");
     249           0 :     get(m_pToFT, "toft");
     250           0 :     get(m_pToNF, "to-nospin");
     251           0 :     get(m_pSaveNowPB, "savenow");
     252           0 :     get(m_pPrinterFT, "printerft");
     253           0 :     get(m_pPrinterLB, "printers");
     254           0 :     m_pPrinterLB->SetStyle(m_pPrinterLB->GetStyle() | WB_SORT);
     255           0 :     get(m_pPrinterSettingsPB, "printersettings");
     256           0 :     get(m_pPrintNowPB, "printnow");
     257           0 :     get(m_pMailToFT, "mailtoft");
     258           0 :     get(m_pMailToLB, "mailto");
     259           0 :     get(m_pCopyToPB, "copyto");
     260           0 :     get(m_pSubjectFT, "subjectft");
     261           0 :     get(m_pSubjectED, "subject");
     262           0 :     get(m_pSendAsFT, "sendasft");
     263           0 :     get(m_pSendAsLB, "sendas");
     264           0 :     get(m_pAttachmentGroup, "attachgroup");
     265           0 :     get(m_pAttachmentED, "attach");
     266           0 :     get(m_pSendAsPB, "sendassettings");
     267           0 :     get(m_pSendDocumentsPB, "sendnow");
     268             : 
     269           0 :     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
     270             :     // #i51949# hide e-Mail option if e-Mail is not supported
     271           0 :     if(!rConfigItem.IsMailAvailable())
     272           0 :         m_pSendMailRB->Hide();
     273             : 
     274           0 :     Link<> aLink = LINK(this, SwMailMergeOutputPage, OutputTypeHdl_Impl);
     275           0 :     m_pSaveStartDocRB->SetClickHdl(aLink);
     276           0 :     m_pSaveMergedDocRB->SetClickHdl(aLink);
     277           0 :     m_pPrintRB->SetClickHdl(aLink);
     278           0 :     m_pSendMailRB->SetClickHdl(aLink);
     279           0 :     m_pSaveStartDocRB->Check();
     280           0 :     m_pPrintAllRB->Check();
     281           0 :     m_pSaveAsOneRB->Check();
     282           0 :     m_pSendAllRB->Check();
     283             : 
     284           0 :     m_pSaveStartDocPB->SetClickHdl(LINK(this, SwMailMergeOutputPage, SaveStartHdl_Impl));
     285           0 :     m_pSaveNowPB->SetClickHdl(LINK(this, SwMailMergeOutputPage, SaveOutputHdl_Impl));
     286           0 :     m_pPrinterLB->SetSelectHdl(LINK(this, SwMailMergeOutputPage, PrinterChangeHdl_Impl));
     287           0 :     m_pPrintNowPB->SetClickHdl(LINK(this, SwMailMergeOutputPage, PrintHdl_Impl));
     288           0 :     m_pPrinterSettingsPB->SetClickHdl(LINK(this, SwMailMergeOutputPage, PrinterSetupHdl_Impl));
     289             : 
     290           0 :     m_pSendAsPB->SetClickHdl(LINK(this, SwMailMergeOutputPage, SendAsHdl_Impl)),
     291           0 :     m_pSendDocumentsPB->SetClickHdl(LINK(this, SwMailMergeOutputPage, SendDocumentsHdl_Impl)),
     292           0 :     m_pSendAsLB->SetSelectHdl(LINK(this, SwMailMergeOutputPage, SendTypeHdl_Impl));
     293             : 
     294           0 :     OutputTypeHdl_Impl(m_pSaveStartDocRB);
     295             : 
     296           0 :     m_pCopyToPB->SetClickHdl(LINK(this, SwMailMergeOutputPage, CopyToHdl_Impl));
     297             : 
     298           0 :     m_pSaveAsOneRB->SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
     299           0 :     m_pSaveIndividualRB->SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
     300           0 :     m_pPrintAllRB->SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
     301           0 :     m_pSendAllRB->SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
     302             : 
     303           0 :     m_pFromRB->SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
     304             :     //#i63267# printing might be disabled
     305           0 :     m_pPrintRB->Enable(!Application::GetSettings().GetMiscSettings().GetDisablePrinting());
     306           0 : }
     307             : 
     308           0 : SwMailMergeOutputPage::~SwMailMergeOutputPage()
     309             : {
     310           0 :     disposeOnce();
     311           0 : }
     312             : 
     313           0 : void SwMailMergeOutputPage::dispose()
     314             : {
     315           0 :     m_pTempPrinter.disposeAndClear();
     316           0 :     m_pSaveStartDocRB.clear();
     317           0 :     m_pSaveMergedDocRB.clear();
     318           0 :     m_pPrintRB.clear();
     319           0 :     m_pSendMailRB.clear();
     320           0 :     m_pSeparator.clear();
     321           0 :     m_pSaveStartDocPB.clear();
     322           0 :     m_pSaveAsOneRB.clear();
     323           0 :     m_pSaveIndividualRB.clear();
     324           0 :     m_pPrintAllRB.clear();
     325           0 :     m_pSendAllRB.clear();
     326           0 :     m_pFromRB.clear();
     327           0 :     m_pFromNF.clear();
     328           0 :     m_pToFT.clear();
     329           0 :     m_pToNF.clear();
     330           0 :     m_pSaveNowPB.clear();
     331           0 :     m_pPrinterFT.clear();
     332           0 :     m_pPrinterLB.clear();
     333           0 :     m_pPrinterSettingsPB.clear();
     334           0 :     m_pPrintNowPB.clear();
     335           0 :     m_pMailToFT.clear();
     336           0 :     m_pMailToLB.clear();
     337           0 :     m_pCopyToPB.clear();
     338           0 :     m_pSubjectFT.clear();
     339           0 :     m_pSubjectED.clear();
     340           0 :     m_pSendAsFT.clear();
     341           0 :     m_pSendAsLB.clear();
     342           0 :     m_pAttachmentGroup.clear();
     343           0 :     m_pAttachmentED.clear();
     344           0 :     m_pSendAsPB.clear();
     345           0 :     m_pSendDocumentsPB.clear();
     346           0 :     m_pWizard.clear();
     347           0 :     svt::OWizardPage::dispose();
     348           0 : }
     349             : 
     350           0 : void SwMailMergeOutputPage::ActivatePage()
     351             : {
     352             :     //fill printer ListBox
     353           0 :     const std::vector<OUString>& rPrinters = Printer::GetPrinterQueues();
     354           0 :     unsigned int nCount = rPrinters.size();
     355           0 :     if ( nCount )
     356             :     {
     357           0 :         for( unsigned int i = 0; i < nCount; i++ )
     358             :         {
     359           0 :             m_pPrinterLB->InsertEntry( rPrinters[i] );
     360             :         }
     361             : 
     362             :     }
     363           0 :     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
     364             : 
     365           0 :     SwView* pTargetView = rConfigItem.GetTargetView();
     366             :     OSL_ENSURE(pTargetView, "no target view exists");
     367           0 :     if(pTargetView)
     368             :     {
     369           0 :         SfxPrinter* pPrinter = pTargetView->GetWrtShell().getIDocumentDeviceAccess()->getPrinter( true );
     370           0 :         m_pPrinterLB->SelectEntry( pPrinter->GetName() );
     371           0 :         m_pToNF->SetValue( rConfigItem.GetMergedDocumentCount() );
     372           0 :         m_pToNF->SetMax( rConfigItem.GetMergedDocumentCount() );
     373             :     }
     374           0 :     m_pPrinterLB->SelectEntry( rConfigItem.GetSelectedPrinter() );
     375             : 
     376           0 :     SwView* pSourceView = rConfigItem.GetSourceView();
     377             :     OSL_ENSURE(pSourceView, "no source view exists");
     378           0 :     if(pSourceView)
     379             :     {
     380           0 :         SwDocShell* pDocShell = pSourceView->GetDocShell();
     381           0 :         if ( pDocShell->HasName() )
     382             :         {
     383           0 :             INetURLObject aTmp( pDocShell->GetMedium()->GetName() );
     384           0 :             m_pAttachmentED->SetText(aTmp.getName(
     385           0 :                     INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ));
     386             :         }
     387             :     }
     388           0 : }
     389             : 
     390           0 : bool SwMailMergeOutputPage::canAdvance() const
     391             : {
     392           0 :     return false;
     393             : }
     394             : 
     395           0 : IMPL_LINK(SwMailMergeOutputPage, OutputTypeHdl_Impl, RadioButton*, pButton)
     396             : {
     397             :     vcl::Window* aControls[] =
     398             :     {
     399             :         m_pSaveStartDocPB,
     400             :         m_pSaveAsOneRB, m_pSaveIndividualRB,
     401             :         m_pFromRB, m_pFromNF, m_pToFT, m_pToNF,
     402             :         m_pSaveNowPB,
     403             :         m_pPrinterFT, m_pPrinterLB, m_pPrinterSettingsPB, m_pPrintAllRB,
     404             :         m_pPrintNowPB,
     405             :         m_pMailToFT, m_pMailToLB, m_pCopyToPB,
     406             :         m_pSubjectFT, m_pSubjectED,
     407             :         m_pSendAsFT, m_pSendAsLB, m_pSendAsPB,
     408             :         m_pAttachmentGroup,
     409             :         m_pSendAllRB, m_pSendDocumentsPB,
     410             :         0
     411           0 :     };
     412           0 :     SetUpdateMode(true);
     413           0 :     vcl::Window** pControl = aControls;
     414           0 :     do
     415             :     {
     416           0 :         (*pControl)->Show(false);
     417             : 
     418             :     } while(*(++pControl));
     419             : 
     420           0 :     if (m_pSaveStartDocRB == pButton)
     421             :     {
     422           0 :         m_pSaveStartDocPB->Show();
     423           0 :         m_pSeparator->set_label(m_sSaveStartST);
     424             : 
     425             :     }
     426           0 :     else if (m_pSaveMergedDocRB == pButton)
     427             :     {
     428             :         Control* aSaveMergedControls[] =
     429             :         {
     430             :             m_pSaveAsOneRB, m_pSaveIndividualRB,
     431             :             m_pFromRB, m_pFromNF, m_pToFT, m_pToNF,
     432             :             m_pSaveNowPB,
     433             :             0
     434           0 :         };
     435           0 :         Control** pSaveMergeControl = aSaveMergedControls;
     436           0 :         do
     437             :         {
     438           0 :             (*pSaveMergeControl)->Show(true);
     439             : 
     440             :         } while(*(++pSaveMergeControl));
     441           0 :         if(!m_pFromRB->IsChecked() && !m_pSaveAsOneRB->IsChecked())
     442             :         {
     443           0 :             m_pSaveIndividualRB->Check();
     444             :         }
     445           0 :         m_pSeparator->set_label(m_sSaveMergedST);
     446             :     }
     447           0 :     else if (m_pPrintRB == pButton)
     448             :     {
     449             :         Control* aPrintControls[] =
     450             :         {
     451             :             m_pFromRB, m_pFromNF, m_pToFT, m_pToNF,
     452             :             m_pPrinterFT, m_pPrinterLB, m_pPrinterSettingsPB, m_pPrintAllRB,
     453             :             m_pPrintNowPB,
     454             :             0
     455           0 :         };
     456           0 :         Control** pPrinterControl = aPrintControls;
     457           0 :         do
     458             :         {
     459           0 :             (*pPrinterControl)->Show(true);
     460             : 
     461             :         } while(*(++pPrinterControl));
     462           0 :         if(!m_pFromRB->IsChecked())
     463           0 :             m_pPrintAllRB->Check();
     464             : 
     465           0 :         m_pSeparator->set_label(m_sPrintST);
     466             :     }
     467             :     else
     468             :     {
     469             :         vcl::Window* aMailControls[] =
     470             :         {
     471             :             m_pFromRB, m_pFromNF, m_pToFT, m_pToNF,
     472             :             m_pMailToFT, m_pMailToLB, m_pCopyToPB,
     473             :             m_pSubjectFT, m_pSubjectED,
     474             :             m_pSendAsFT, m_pSendAsLB, m_pSendAsPB,
     475             :             m_pAttachmentGroup,
     476             :             m_pSendAllRB, m_pSendDocumentsPB, 0
     477           0 :         };
     478           0 :         vcl::Window** pMailControl = aMailControls;
     479           0 :         do
     480             :         {
     481           0 :             (*pMailControl)->Show(true);
     482             : 
     483             :         } while(*(++pMailControl));
     484             : 
     485           0 :         if(!m_pFromRB->IsChecked())
     486           0 :             m_pSendAllRB->Check();
     487           0 :         if(m_pAttachmentED->GetText().isEmpty())
     488             :         {
     489           0 :             OUString sAttach( m_sDefaultAttachmentST );
     490           0 :             sAttach += ".";
     491           0 :             sAttach += lcl_GetExtensionForDocType(
     492           0 :                         reinterpret_cast<sal_uLong>(m_pSendAsLB->GetSelectEntryData()));
     493           0 :             m_pAttachmentED->SetText( sAttach );
     494             : 
     495             :         }
     496           0 :         m_pSeparator->set_label(m_sSendMailST);
     497             :         //fill mail address ListBox
     498           0 :         if(!m_pMailToLB->GetEntryCount())
     499             :         {
     500           0 :             SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
     501             :             //select first column
     502           0 :             uno::Reference< sdbcx::XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), uno::UNO_QUERY);
     503             :             //get the name of the actual columns
     504           0 :             uno::Reference < container::XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
     505           0 :             uno::Sequence< OUString > aFields;
     506           0 :             if(xColAccess.is())
     507           0 :                 aFields = xColAccess->getElementNames();
     508           0 :             const OUString* pFields = aFields.getConstArray();
     509           0 :             for(sal_Int32 nField = 0; nField < aFields.getLength(); ++nField)
     510           0 :                 m_pMailToLB->InsertEntry(pFields[nField]);
     511             : 
     512           0 :             m_pMailToLB->SelectEntryPos(0);
     513             :             // then select the right one - may not be available
     514           0 :             const ResStringArray& rHeaders = rConfigItem.GetDefaultAddressHeaders();
     515           0 :             OUString sEMailColumn = rHeaders.GetString( MM_PART_E_MAIL );
     516             :             Sequence< OUString> aAssignment =
     517           0 :                             rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
     518           0 :             if(aAssignment.getLength() > MM_PART_E_MAIL && !aAssignment[MM_PART_E_MAIL].isEmpty())
     519           0 :                 sEMailColumn = aAssignment[MM_PART_E_MAIL];
     520           0 :             m_pMailToLB->SelectEntry(sEMailColumn);
     521             :             // HTML format pre-selected
     522           0 :             m_pSendAsLB->SelectEntryPos(3);
     523           0 :             SendTypeHdl_Impl(m_pSendAsLB);
     524             :         }
     525             :     }
     526           0 :     m_pFromRB->GetClickHdl().Call(m_pFromRB->IsChecked() ? m_pFromRB.get() : 0);
     527             : 
     528           0 :     SetUpdateMode(false);
     529           0 :     return 0;
     530             : }
     531             : 
     532           0 : IMPL_LINK(SwMailMergeOutputPage, DocumentSelectionHdl_Impl, RadioButton*, pButton)
     533             : {
     534           0 :     bool bEnableFromTo = pButton == m_pFromRB;
     535           0 :     m_pFromNF->Enable(bEnableFromTo);
     536           0 :     m_pToFT->Enable(bEnableFromTo);
     537           0 :     m_pToNF->Enable(bEnableFromTo);
     538           0 :     return 0;
     539             : }
     540             : 
     541           0 : IMPL_LINK(SwMailMergeOutputPage, CopyToHdl_Impl, PushButton*, pButton)
     542             : {
     543           0 :     ScopedVclPtrInstance< SwCopyToDialog > pDlg(pButton);
     544           0 :     pDlg->SetCC(m_sCC );
     545           0 :     pDlg->SetBCC(m_sBCC);
     546           0 :     if(RET_OK == pDlg->Execute())
     547             :     {
     548           0 :         m_sCC =     pDlg->GetCC() ;
     549           0 :         m_sBCC =    pDlg->GetBCC();
     550             :     }
     551           0 :     return 0;
     552             : }
     553             : 
     554           0 : IMPL_LINK(SwMailMergeOutputPage, SaveStartHdl_Impl, PushButton*, pButton)
     555             : {
     556           0 :     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
     557           0 :     SwView* pSourceView = rConfigItem.GetSourceView();
     558             :     OSL_ENSURE( pSourceView, "source view missing");
     559           0 :     if(pSourceView)
     560             :     {
     561           0 :         SfxViewFrame* pSourceViewFrm = pSourceView->GetViewFrame();
     562             :         uno::Reference< frame::XFrame > xFrame =
     563           0 :                 pSourceViewFrm->GetFrame().GetFrameInterface();
     564           0 :         xFrame->getContainerWindow()->setVisible(sal_True);
     565           0 :         pSourceViewFrm->GetDispatcher()->Execute(SID_SAVEDOC, SfxCallMode::SYNCHRON);
     566           0 :         xFrame->getContainerWindow()->setVisible(sal_False);
     567           0 :         SwDocShell* pDocShell = pSourceView->GetDocShell();
     568             :         //if the document has been saved its URL has to be stored for
     569             :         // later use and it can be closed now
     570           0 :         if(pDocShell->HasName() && !pDocShell->IsModified())
     571             :         {
     572           0 :             INetURLObject aURL = pDocShell->GetMedium()->GetURLObject();
     573             :             //update the attachment name
     574           0 :             if(m_pAttachmentED->GetText().isEmpty())
     575             :             {
     576           0 :                 if ( pDocShell->HasName() )
     577             :                 {
     578           0 :                     m_pAttachmentED->SetText(aURL.getName(
     579           0 :                             INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ));
     580             :                 }
     581             :             }
     582             : 
     583             :             rConfigItem.AddSavedDocument(
     584           0 :                     aURL.GetMainURL(INetURLObject::DECODE_TO_IURI));
     585           0 :             pButton->Enable(false);
     586           0 :             m_pWizard->enableButtons(WizardButtonFlags::FINISH, true);
     587           0 :             pButton->Enable(false);
     588             : 
     589           0 :         }
     590             :     }
     591           0 :     return 0;
     592             : }
     593             : 
     594           0 : IMPL_LINK_NOARG(SwMailMergeOutputPage, SaveCancelHdl_Impl)
     595             : {
     596           0 :     m_bCancelSaving = true;
     597           0 :     return 0;
     598             : }
     599             : 
     600           0 : int SwMailMergeOutputPage::documentStartPageNumber( int document ) const
     601             : {
     602           0 :     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
     603           0 :     SwView* pTargetView = rConfigItem.GetTargetView();
     604             :     assert( pTargetView );
     605           0 :     SwCrsrShell& shell = pTargetView->GetWrtShell();
     606           0 :     const SwDocMergeInfo& info = rConfigItem.GetDocumentMergeInfo( document );
     607             :     sal_uInt16 page, dummy;
     608           0 :     shell.Push();
     609           0 :     shell.GotoMark( info.startPageInTarget );
     610           0 :     shell.GetPageNum( page, dummy );
     611           0 :     shell.Pop(false);
     612           0 :     return page;
     613             : }
     614             : 
     615           0 : int SwMailMergeOutputPage::documentEndPageNumber( int document ) const
     616             : {
     617           0 :     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
     618           0 :     SwView* pTargetView = rConfigItem.GetTargetView();
     619             :     assert( pTargetView );
     620           0 :     SwWrtShell& shell = pTargetView->GetWrtShell();
     621           0 :     if( document < int( rConfigItem.GetMergedDocumentCount()) - 1 )
     622             :     {
     623             :         // Go to the page before the starting page of the next merged document.
     624           0 :         const SwDocMergeInfo& info = rConfigItem.GetDocumentMergeInfo( document + 1 );
     625             :         sal_uInt16 page, dummy;
     626           0 :         shell.Push();
     627           0 :         shell.GotoMark( info.startPageInTarget );
     628           0 :         shell.EndPrvPg();
     629           0 :         shell.GetPageNum( page, dummy );
     630           0 :         shell.Pop(false);
     631           0 :         return page;
     632             :     }
     633             :     else
     634             :     {   // This is the last merged document, so it ends on the page at which the document ends.
     635             :         sal_uInt16 page, dummy;
     636           0 :         shell.Push();
     637           0 :         shell.SttEndDoc( false ); // go to doc end
     638           0 :         shell.GetPageNum( page, dummy );
     639           0 :         shell.Pop(false);
     640           0 :         return page;
     641             :     }
     642             : }
     643             : 
     644           0 : IMPL_LINK(SwMailMergeOutputPage, SaveOutputHdl_Impl, PushButton*, pButton)
     645             : {
     646           0 :     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
     647           0 :     SwView* pTargetView = rConfigItem.GetTargetView();
     648             :     OSL_ENSURE(pTargetView, "no target view exists");
     649           0 :     if(!pTargetView)
     650           0 :         return 0;
     651             : 
     652           0 :     if(m_pSaveAsOneRB->IsChecked())
     653             :     {
     654           0 :         OUString sFilter;
     655           0 :         const OUString sPath = SwMailMergeHelper::CallSaveAsDialog(sFilter);
     656           0 :         if (sPath.isEmpty())
     657           0 :             return 0;
     658           0 :         uno::Sequence< beans::PropertyValue > aValues(1);
     659           0 :         beans::PropertyValue* pValues = aValues.getArray();
     660           0 :         pValues[0].Name = "FilterName";
     661           0 :         pValues[0].Value <<= sFilter;
     662             : 
     663           0 :         uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
     664           0 :         sal_uInt32 nErrorCode = ERRCODE_NONE;
     665             :         try
     666             :         {
     667           0 :             xStore->storeToURL( sPath, aValues );
     668             :         }
     669           0 :         catch (const task::ErrorCodeIOException& rErrorEx)
     670             :         {
     671           0 :             nErrorCode = (sal_uInt32)rErrorEx.ErrCode;
     672             :         }
     673           0 :         catch (const Exception&)
     674             :         {
     675           0 :             nErrorCode = ERRCODE_IO_GENERAL;
     676             :         }
     677           0 :         if( nErrorCode != ERRCODE_NONE )
     678             :         {
     679           0 :             SfxErrorContext aEc(ERRCTX_SFX_SAVEASDOC, pTargetView->GetDocShell()->GetTitle());
     680           0 :             ErrorHandler::HandleError( nErrorCode );
     681           0 :         }
     682             :     }
     683             :     else
     684             :     {
     685           0 :         sal_uInt32 nBegin = 0;
     686           0 :         sal_uInt32 nEnd = 0;
     687           0 :         if(m_pSaveIndividualRB->IsChecked())
     688             :         {
     689           0 :             nBegin = 0;
     690           0 :             nEnd = rConfigItem.GetMergedDocumentCount();
     691             :         }
     692             :         else
     693             :         {
     694           0 :             nBegin  = static_cast< sal_Int32 >(m_pFromNF->GetValue() - 1);
     695           0 :             nEnd    = static_cast< sal_Int32 >(m_pToNF->GetValue());
     696           0 :             if(nEnd > rConfigItem.GetMergedDocumentCount())
     697           0 :                 nEnd = rConfigItem.GetMergedDocumentCount();
     698             :         }
     699           0 :         OUString sFilter;
     700           0 :         OUString sPath = SwMailMergeHelper::CallSaveAsDialog(sFilter);
     701           0 :         if (sPath.isEmpty())
     702           0 :             return 0;
     703             :         OUString sTargetTempURL = URIHelper::SmartRel2Abs(
     704             :             INetURLObject(), utl::TempFile::CreateTempName(),
     705           0 :             URIHelper::GetMaybeFileHdl());
     706             :         const SfxFilter *pSfxFlt = SwIoSystem::GetFilterOfFormat(
     707             :                 OUString( FILTER_XML ),
     708           0 :                 SwDocShell::Factory().GetFilterContainer() );
     709             : 
     710           0 :         uno::Sequence< beans::PropertyValue > aValues(1);
     711           0 :         beans::PropertyValue* pValues = aValues.getArray();
     712           0 :         pValues[0].Name = "FilterName";
     713           0 :         pValues[0].Value <<= OUString(pSfxFlt->GetFilterName());
     714             : 
     715           0 :         uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
     716           0 :         sal_uInt32 nErrorCode = ERRCODE_NONE;
     717             :         try
     718             :         {
     719           0 :             xStore->storeToURL( sTargetTempURL, aValues );
     720             :         }
     721           0 :         catch (const task::ErrorCodeIOException& rErrorEx)
     722             :         {
     723           0 :             nErrorCode = (sal_uInt32)rErrorEx.ErrCode;
     724             :         }
     725           0 :         catch (const Exception&)
     726             :         {
     727           0 :             nErrorCode = ERRCODE_IO_GENERAL;
     728             :         }
     729           0 :         if( nErrorCode != ERRCODE_NONE )
     730             :         {
     731           0 :             SfxErrorContext aEc(ERRCTX_SFX_SAVEASDOC, pTargetView->GetDocShell()->GetTitle());
     732           0 :             ErrorHandler::HandleError( nErrorCode );
     733             :         }
     734             : 
     735           0 :         SwView* pSourceView = rConfigItem.GetSourceView();
     736           0 :         ScopedVclPtrInstance< PrintMonitor > aSaveMonitor(this, false, PrintMonitor::MONITOR_TYPE_SAVE);
     737           0 :         aSaveMonitor->m_pDocName->SetText(pSourceView->GetDocShell()->GetTitle(22));
     738           0 :         aSaveMonitor->SetCancelHdl(LINK(this, SwMailMergeOutputPage, SaveCancelHdl_Impl));
     739           0 :         aSaveMonitor->m_pPrinter->SetText( INetURLObject( sPath ).getFSysPath( INetURLObject::FSYS_DETECT ) );
     740           0 :         m_bCancelSaving = false;
     741           0 :         aSaveMonitor->Show();
     742           0 :         m_pWizard->enableButtons(WizardButtonFlags::CANCEL, false);
     743             : 
     744           0 :         for(sal_uInt32 nDoc = nBegin; nDoc < nEnd && !m_bCancelSaving; ++nDoc)
     745             :         {
     746           0 :             INetURLObject aURL(sPath);
     747           0 :             OUString sExtension = aURL.getExtension();
     748           0 :             if (sExtension.isEmpty())
     749             :             {
     750           0 :                 sExtension = pSfxFlt->GetWildcard().getGlob().getToken(1, '.');
     751           0 :                 sPath += "." + sExtension;
     752             :             }
     753           0 :             OUString sStat = OUString(SW_RES(STR_STATSTR_LETTER)) + " " + OUString::number( nDoc );
     754           0 :             aSaveMonitor->m_pPrintInfo->SetText(sStat);
     755             : 
     756             :             //now extract a document from the target document
     757             :             // the shell will be closed at the end, but it is more safe to use SfxObjectShellLock here
     758           0 :             SfxObjectShellLock xTempDocShell( new SwDocShell( SfxObjectCreateMode::STANDARD ) );
     759           0 :             xTempDocShell->DoInitNew( 0 );
     760           0 :             SfxViewFrame* pTempFrame = SfxViewFrame::LoadHiddenDocument( *xTempDocShell, 0 );
     761           0 :             SwView* pTempView = static_cast<SwView*>( pTempFrame->GetViewShell() );
     762           0 :             pTargetView->GetWrtShell().StartAction();
     763           0 :             SwgReaderOption aOpt;
     764           0 :             aOpt.SetTextFormats( true );
     765           0 :             aOpt.SetFrameFormats( true );
     766           0 :             aOpt.SetPageDescs( true );
     767           0 :             aOpt.SetNumRules( true );
     768           0 :             aOpt.SetMerge( false );
     769             :             pTempView->GetDocShell()->LoadStylesFromFile(
     770           0 :                     sTargetTempURL, aOpt, true );
     771           0 :             pTempView->GetDocShell()->GetDoc()->ReplaceCompatibilityOptions( *pTargetView->GetDocShell()->GetDoc());
     772           0 :             pTempView->GetDocShell()->GetDoc()->ReplaceDefaults( *pTargetView->GetDocShell()->GetDoc());
     773           0 :             pTempView->GetDocShell()->GetDoc()->ReplaceDocumentProperties( *pTargetView->GetDocShell()->GetDoc(), true );
     774             : 
     775           0 :             pTargetView->GetWrtShell().PastePages(pTempView->GetWrtShell(),
     776           0 :                 documentStartPageNumber( nDoc ), documentEndPageNumber( nDoc ));
     777           0 :             pTargetView->GetWrtShell().EndAction();
     778             :             //then save it
     779           0 :             OUString sOutPath = aURL.GetMainURL(INetURLObject::DECODE_TO_IURI);
     780           0 :             OUString sCounter = "_" + OUString::number(nDoc);
     781           0 :             sOutPath = sOutPath.replaceAt( sOutPath.getLength() - sExtension.getLength() - 1, 0, sCounter);
     782             : 
     783             :             while(true)
     784             :             {
     785             :                 //time for other slots is needed
     786           0 :                 for(sal_Int16 r = 0; r < 10; ++r)
     787           0 :                     Application::Reschedule();
     788           0 :                 bool bFailed = false;
     789             :                 try
     790             :                 {
     791           0 :                     pValues[0].Value <<= sFilter;
     792           0 :                     uno::Reference< frame::XStorable > xTempStore( xTempDocShell->GetModel(), uno::UNO_QUERY);
     793           0 :                     xTempStore->storeToURL( sOutPath, aValues   );
     794             :                 }
     795           0 :                 catch (const uno::Exception&)
     796             :                 {
     797           0 :                     bFailed = true;
     798             :                 }
     799             : 
     800           0 :                 if(bFailed)
     801             :                 {
     802           0 :                     ScopedVclPtrInstance< SwSaveWarningBox_Impl > aWarning( pButton, sOutPath );
     803           0 :                     if(RET_OK == aWarning->Execute())
     804           0 :                         sOutPath = aWarning->GetFileName();
     805             :                     else
     806             :                     {
     807           0 :                         xTempDocShell->DoClose();
     808           0 :                         return 0;
     809           0 :                     }
     810             :                 }
     811             :                 else
     812             :                 {
     813           0 :                     xTempDocShell->DoClose();
     814           0 :                     break;
     815             :                 }
     816             :             }
     817           0 :         }
     818           0 :         ::osl::File::remove( sTargetTempURL );
     819             :     }
     820           0 :     m_pWizard->enableButtons(WizardButtonFlags::CANCEL, true);
     821           0 :     m_pWizard->enableButtons(WizardButtonFlags::FINISH, true);
     822           0 :     return 0;
     823             : }
     824             : 
     825           0 : IMPL_LINK(SwMailMergeOutputPage, PrinterChangeHdl_Impl, ListBox*, pBox)
     826             : {
     827           0 :     SwView *const pTargetView = m_pWizard->GetConfigItem().GetTargetView();
     828           0 :     SfxPrinter *const pDocumentPrinter = pTargetView->GetWrtShell()
     829           0 :         .getIDocumentDeviceAccess()->getPrinter(true);
     830           0 :     if (pDocumentPrinter && pBox->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND)
     831             :     {
     832           0 :         const QueueInfo* pInfo = Printer::GetQueueInfo( pBox->GetSelectEntry(), false );
     833             : 
     834           0 :         if( pInfo )
     835             :         {
     836           0 :             if ( !m_pTempPrinter )
     837             :             {
     838           0 :                 if ((pDocumentPrinter->GetName() == pInfo->GetPrinterName()) &&
     839           0 :                     (pDocumentPrinter->GetDriverName() == pInfo->GetDriver()))
     840             :                 {
     841           0 :                     m_pTempPrinter = VclPtr<Printer>::Create(pDocumentPrinter->GetJobSetup());
     842             :                 }
     843             :                 else
     844           0 :                     m_pTempPrinter = VclPtr<Printer>::Create( *pInfo );
     845             :             }
     846             :             else
     847             :             {
     848           0 :                 if( (m_pTempPrinter->GetName() != pInfo->GetPrinterName()) ||
     849           0 :                      (m_pTempPrinter->GetDriverName() != pInfo->GetDriver()) )
     850             :                 {
     851           0 :                     m_pTempPrinter.disposeAndClear();
     852           0 :                     m_pTempPrinter = VclPtr<Printer>::Create( *pInfo );
     853             :                 }
     854             :             }
     855             :         }
     856           0 :         else if( ! m_pTempPrinter )
     857           0 :             m_pTempPrinter = VclPtr<Printer>::Create();
     858             : 
     859           0 :         m_pPrinterSettingsPB->Enable( m_pTempPrinter->HasSupport( SUPPORT_SETUPDIALOG ) );
     860             :     }
     861             :     else
     862           0 :         m_pPrinterSettingsPB->Disable();
     863           0 :     m_pWizard->GetConfigItem().SetSelectedPrinter( pBox->GetSelectEntry() );
     864             : 
     865           0 :     return 0;
     866             : }
     867             : 
     868           0 : IMPL_LINK_NOARG(SwMailMergeOutputPage, PrintHdl_Impl)
     869             : {
     870           0 :     SwView* pTargetView = m_pWizard->GetConfigItem().GetTargetView();
     871             :     OSL_ENSURE(pTargetView, "no target view exists");
     872           0 :     if(!pTargetView)
     873           0 :         return 0;
     874             : 
     875           0 :     sal_uInt32 nBegin = 0;
     876           0 :     sal_uInt32 nEnd = 0;
     877           0 :     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
     878           0 :     if(m_pPrintAllRB->IsChecked())
     879             :     {
     880           0 :         nBegin = 0;
     881           0 :         nEnd = rConfigItem.GetMergedDocumentCount();
     882             :     }
     883             :     else
     884             :     {
     885           0 :         nBegin  = static_cast< sal_Int32 >(m_pFromNF->GetValue() - 1);
     886           0 :         nEnd    = static_cast< sal_Int32 >(m_pToNF->GetValue());
     887           0 :         if(nEnd > rConfigItem.GetMergedDocumentCount())
     888           0 :             nEnd = rConfigItem.GetMergedDocumentCount();
     889             :     }
     890           0 :     rConfigItem.SetPrintRange( (sal_uInt16)nBegin, (sal_uInt16)nEnd );
     891             : 
     892           0 :     OUString sPages(OUString::number( documentStartPageNumber( nBegin )));
     893           0 :     sPages += " - ";
     894           0 :     sPages += OUString::number( documentEndPageNumber( nEnd - 1 ));
     895             : 
     896           0 :     pTargetView->SetMailMergeConfigItem(&rConfigItem, 0, false);
     897           0 :     if(m_pTempPrinter)
     898             :     {
     899           0 :         SfxPrinter *const pDocumentPrinter = pTargetView->GetWrtShell()
     900           0 :             .getIDocumentDeviceAccess()->getPrinter(true);
     901           0 :         pDocumentPrinter->SetPrinterProps(m_pTempPrinter);
     902             :         // this should be able to handle setting its own printer
     903           0 :         pTargetView->SetPrinter(pDocumentPrinter);
     904             :     }
     905             : 
     906           0 :     SfxObjectShell* pObjSh = pTargetView->GetViewFrame()->GetObjectShell();
     907           0 :     SfxGetpApp()->NotifyEvent(SfxEventHint(SW_EVENT_MAIL_MERGE, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE), pObjSh));
     908           0 :     SfxBoolItem aMergeSilent(SID_SILENT, false);
     909           0 :     m_pWizard->enableButtons(WizardButtonFlags::CANCEL, false);
     910             : 
     911           0 :     uno::Sequence < beans::PropertyValue > aProps( 2 );
     912           0 :     aProps[0]. Name = "MonitorVisible";
     913           0 :     aProps[0].Value <<= sal_True;
     914           0 :     aProps[1]. Name = "Pages";
     915           0 :     aProps[1]. Value <<= sPages;
     916             : 
     917           0 :     pTargetView->ExecPrint( aProps, false, true );
     918           0 :     SfxGetpApp()->NotifyEvent(SfxEventHint(SW_EVENT_MAIL_MERGE_END, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE_END), pObjSh));
     919             : 
     920           0 :     pTargetView->SetMailMergeConfigItem(0, 0, false);
     921           0 :     m_pWizard->enableButtons(WizardButtonFlags::CANCEL, true);
     922           0 :     m_pWizard->enableButtons(WizardButtonFlags::FINISH, true);
     923           0 :     return 0;
     924             : }
     925             : 
     926           0 : IMPL_LINK(SwMailMergeOutputPage, PrinterSetupHdl_Impl, PushButton*, pButton)
     927             : {
     928           0 :     if( !m_pTempPrinter )
     929           0 :         PrinterChangeHdl_Impl(m_pPrinterLB);
     930           0 :     if(m_pTempPrinter)
     931           0 :         m_pTempPrinter->Setup(pButton);
     932           0 :     return 0;
     933             : }
     934             : 
     935           0 : IMPL_LINK(SwMailMergeOutputPage, SendTypeHdl_Impl, ListBox*, pBox)
     936             : {
     937           0 :     sal_uLong nDocType = reinterpret_cast<sal_uLong>(pBox->GetSelectEntryData());
     938           0 :     bool bEnable = MM_DOCTYPE_HTML != nDocType && MM_DOCTYPE_TEXT != nDocType;
     939           0 :     m_pSendAsPB->Enable( bEnable );
     940           0 :     m_pAttachmentGroup->Enable( bEnable );
     941           0 :     if(bEnable)
     942             :     {
     943             :         //add the correct extension
     944           0 :         OUString sAttach(m_pAttachmentED->GetText());
     945             :         //do nothing if the user has removed the name - the warning will come early enough
     946           0 :         if (!sAttach.isEmpty())
     947             :         {
     948           0 :             sal_Int32 nTokenCount = comphelper::string::getTokenCount(sAttach, '.');
     949           0 :             if( 2 > nTokenCount)
     950             :             {
     951           0 :                 sAttach += ".";
     952           0 :                 ++nTokenCount;
     953             :             }
     954           0 :             sAttach = comphelper::string::setToken(sAttach, nTokenCount - 1, '.', lcl_GetExtensionForDocType( nDocType ));
     955           0 :             m_pAttachmentED->SetText(sAttach);
     956           0 :         }
     957             :     }
     958           0 :     return 0;
     959             : }
     960             : 
     961           0 : IMPL_LINK(SwMailMergeOutputPage, SendAsHdl_Impl, PushButton*, pButton)
     962             : {
     963           0 :     VclPtr<SwMailBodyDialog> pDlg = VclPtr<SwMailBodyDialog>::Create(pButton, m_pWizard);
     964           0 :     pDlg->SetBody(m_sBody);
     965           0 :     if(RET_OK == pDlg->Execute())
     966             :     {
     967           0 :         m_sBody = pDlg->GetBody();
     968             :     }
     969           0 :     return 0;
     970             : }
     971             : 
     972             : // Send documents as e-mail
     973           0 : IMPL_LINK(SwMailMergeOutputPage, SendDocumentsHdl_Impl, PushButton*, pButton)
     974             : {
     975           0 :     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
     976             : 
     977             :     //get the composed document
     978           0 :     SwView* pTargetView = rConfigItem.GetTargetView();
     979             :     OSL_ENSURE(pTargetView, "no target view exists");
     980           0 :     if(!pTargetView)
     981           0 :         return 0;
     982             : 
     983           0 :     if(rConfigItem.GetMailServer().isEmpty() ||
     984           0 :             !SwMailMergeHelper::CheckMailAddress(rConfigItem.GetMailAddress()) )
     985             :     {
     986           0 :         ScopedVclPtrInstance< QueryBox > aQuery(pButton, WB_YES_NO_CANCEL, m_sConfigureMail);
     987           0 :         sal_uInt16 nRet = aQuery->Execute();
     988           0 :         if(RET_YES == nRet )
     989             :         {
     990           0 :             SfxAllItemSet aSet(pTargetView->GetPool());
     991           0 :             ScopedVclPtrInstance< SwMailConfigDlg > pDlg(pButton, aSet);
     992           0 :             nRet = pDlg->Execute();
     993             :         }
     994             : 
     995           0 :         if(nRet != RET_OK && nRet != RET_YES)
     996           0 :             return 0;
     997             :     }
     998             :     //add the documents
     999           0 :     sal_uInt32 nBegin = 0;
    1000           0 :     sal_uInt32 nEnd = 0;
    1001           0 :     if(m_pSendAllRB->IsChecked())
    1002             :     {
    1003           0 :         nBegin = 0;
    1004           0 :         nEnd = rConfigItem.GetMergedDocumentCount();
    1005             :     }
    1006             :     else
    1007             :     {
    1008           0 :         nBegin  = static_cast< sal_Int32 >(m_pFromNF->GetValue() - 1);
    1009           0 :         nEnd    = static_cast< sal_Int32 >(m_pToNF->GetValue());
    1010           0 :         if(nEnd > rConfigItem.GetMergedDocumentCount())
    1011           0 :             nEnd = rConfigItem.GetMergedDocumentCount();
    1012             :     }
    1013           0 :     bool bAsBody = false;
    1014           0 :     rtl_TextEncoding eEncoding = ::osl_getThreadTextEncoding();
    1015           0 :     SfxFilterContainer* pFilterContainer = SwDocShell::Factory().GetFilterContainer();
    1016           0 :     const SfxFilter *pSfxFlt = 0;
    1017           0 :     sal_uLong nDocType = reinterpret_cast<sal_uLong>(m_pSendAsLB->GetSelectEntryData());
    1018           0 :     OUString sExtension = lcl_GetExtensionForDocType(nDocType);
    1019           0 :     switch( nDocType )
    1020             :     {
    1021             :         case MM_DOCTYPE_OOO:
    1022             :         {
    1023             :             //Make sure we don't pick e.g. the flat xml filter
    1024             :             //for this format
    1025             :             pSfxFlt = SwIoSystem::GetFilterOfFormat(
    1026             :                 OUString( FILTER_XML ),
    1027           0 :                 SwDocShell::Factory().GetFilterContainer() );
    1028             :         }
    1029           0 :         break;
    1030             :         case MM_DOCTYPE_PDF:
    1031             :         {
    1032             :             pSfxFlt = pFilterContainer->GetFilter4FilterName(
    1033             :                 OUString("writer_pdf_Export"),
    1034           0 :                 SfxFilterFlags::EXPORT);
    1035             :         }
    1036           0 :         break;
    1037             :         case MM_DOCTYPE_WORD:
    1038             :         {
    1039             :             //the method SwIOSystemGetFilterOfFormat( ) returns the template filter
    1040             :             //because it uses the same user data :-(
    1041           0 :             SfxFilterMatcher aMatcher( pFilterContainer->GetName() );
    1042           0 :             SfxFilterMatcherIter aIter( aMatcher );
    1043           0 :             const SfxFilter* pFilter = aIter.First();
    1044           0 :             while ( pFilter )
    1045             :             {
    1046           0 :                 if( pFilter->GetUserData() == FILTER_WW8 && pFilter->CanExport() )
    1047             :                 {
    1048           0 :                     pSfxFlt = pFilter;
    1049           0 :                     break;
    1050             :                 }
    1051           0 :                 pFilter = aIter.Next();
    1052           0 :             }
    1053             : 
    1054             :         }
    1055           0 :         break;
    1056             :         case MM_DOCTYPE_HTML:
    1057             :         {
    1058           0 :             bAsBody = true;
    1059           0 :             SvxHtmlOptions& rHtmlOptions = SvxHtmlOptions::Get();
    1060           0 :             eEncoding = rHtmlOptions.GetTextEncoding();
    1061             :         }
    1062           0 :         break;
    1063             :         case MM_DOCTYPE_TEXT:
    1064             :         {
    1065           0 :             bAsBody = true;
    1066             :             pSfxFlt = pFilterContainer->GetFilter4FilterName(
    1067           0 :                 OUString("Text (encoded)"), SfxFilterFlags::EXPORT);
    1068             :         }
    1069           0 :         break;
    1070             :     }
    1071           0 :     if(!pSfxFlt)
    1072           0 :         pSfxFlt = pFilterContainer->GetFilter4Extension(sExtension, SfxFilterFlags::EXPORT);
    1073             : 
    1074           0 :     if(!pSfxFlt)
    1075           0 :         return 0;
    1076           0 :     OUString sMimeType = pSfxFlt->GetMimeType();
    1077             : 
    1078           0 :     if(m_pSubjectED->GetText().isEmpty())
    1079             :     {
    1080             :         ScopedVclPtrInstance<SwSendQueryBox_Impl> aQuery(pButton, "SubjectDialog",
    1081           0 :                                                          "modules/swriter/ui/subjectdialog.ui");
    1082           0 :         aQuery->SetIsEmptyTextAllowed(true);
    1083           0 :         aQuery->SetValue(m_sNoSubjectST);
    1084           0 :         if(RET_OK == aQuery->Execute())
    1085             :         {
    1086           0 :             if(aQuery->GetValue() != m_sNoSubjectST)
    1087           0 :                 m_pSubjectED->SetText(aQuery->GetValue());
    1088             :         }
    1089             :         else
    1090           0 :             return 0;
    1091             :     }
    1092           0 :     if(!bAsBody && m_pAttachmentED->GetText().isEmpty())
    1093             :     {
    1094             :         ScopedVclPtrInstance<SwSendQueryBox_Impl> aQuery(pButton, "AttachNameDialog",
    1095           0 :                                                          "modules/swriter/ui/attachnamedialog.ui");
    1096           0 :         aQuery->SetIsEmptyTextAllowed(false);
    1097           0 :         if(RET_OK == aQuery->Execute())
    1098             :         {
    1099           0 :             OUString sAttach(aQuery->GetValue());
    1100           0 :             sal_Int32 nTokenCount = comphelper::string::getTokenCount(sAttach, '.');
    1101           0 :             if (2 > nTokenCount)
    1102             :             {
    1103           0 :                 sAttach += ".";
    1104           0 :                 ++nTokenCount;
    1105             :             }
    1106           0 :             sAttach = comphelper::string::setToken(sAttach, nTokenCount - 1, '.', lcl_GetExtensionForDocType(
    1107           0 :                      reinterpret_cast<sal_uLong>(m_pSendAsLB->GetSelectEntryData())));
    1108           0 :             m_pAttachmentED->SetText(sAttach);
    1109             :         }
    1110             :         else
    1111           0 :             return 0;
    1112             :     }
    1113           0 :     SfxStringItem aFilterName( SID_FILTER_NAME, pSfxFlt->GetFilterName() );
    1114           0 :     OUString sEMailColumn = m_pMailToLB->GetSelectEntry();
    1115             :     OSL_ENSURE( !sEMailColumn.isEmpty(), "No email column selected");
    1116           0 :     Reference< sdbcx::XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), UNO_QUERY);
    1117           0 :     Reference < container::XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
    1118           0 :     if(sEMailColumn.isEmpty() || !xColAccess.is() || !xColAccess->hasByName(sEMailColumn))
    1119           0 :         return 0;
    1120             : 
    1121           0 :     OUString sFilterOptions;
    1122           0 :     if(MM_DOCTYPE_TEXT == nDocType)
    1123             :     {
    1124           0 :         SwAsciiOptions aOpt;
    1125           0 :         sal_uInt16 nAppScriptType = SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() );
    1126           0 :         sal_uInt16 nWhich = GetWhichOfScript( RES_CHRATR_LANGUAGE, nAppScriptType);
    1127           0 :         aOpt.SetLanguage( static_cast<const SvxLanguageItem&>(pTargetView->GetWrtShell().
    1128           0 :                             GetDefault( nWhich )).GetLanguage());
    1129           0 :         aOpt.SetParaFlags( LINEEND_CR );
    1130           0 :         aOpt.WriteUserData( sFilterOptions );
    1131             :     }
    1132             :     OUString sTargetTempURL = URIHelper::SmartRel2Abs(
    1133             :         INetURLObject(), utl::TempFile::CreateTempName(),
    1134           0 :         URIHelper::GetMaybeFileHdl());
    1135             :     const SfxFilter *pTargetSfxFlt = SwIoSystem::GetFilterOfFormat(
    1136             :             OUString( FILTER_XML ),
    1137           0 :             SwDocShell::Factory().GetFilterContainer() );
    1138             : 
    1139           0 :     uno::Sequence< beans::PropertyValue > aValues(1);
    1140           0 :     beans::PropertyValue* pValues = aValues.getArray();
    1141           0 :     pValues[0].Name = "FilterName";
    1142           0 :     pValues[0].Value <<= OUString(pTargetSfxFlt->GetFilterName());
    1143             : 
    1144           0 :     uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
    1145           0 :     xStore->storeToURL( sTargetTempURL, aValues   );
    1146             : 
    1147             :     //create the send dialog
    1148           0 :     VclPtr<SwSendMailDialog> pDlg = VclPtr<SwSendMailDialog>::Create( pButton, rConfigItem );
    1149           0 :     pDlg->SetDocumentCount( nEnd );
    1150           0 :     pDlg->ShowDialog();
    1151             :     //help to force painting the dialog
    1152             :     //TODO/CLEANUP
    1153             :     //predetermined breaking point
    1154           0 :     for ( sal_Int16 i = 0; i < 25; i++)
    1155           0 :         Application::Reschedule();
    1156           0 :     for(sal_uInt32 nDoc = nBegin; nDoc < nEnd; ++nDoc)
    1157             :     {
    1158           0 :         m_pWizard->EnterWait();
    1159           0 :         SwDocMergeInfo& rInfo = rConfigItem.GetDocumentMergeInfo(nDoc);
    1160             : 
    1161             :         //now extract a document from the target document
    1162             :         // the shell will be closed at the end, but it is more safe to use SfxObjectShellLock here
    1163           0 :         SfxObjectShellLock xTempDocShell( new SwDocShell( SfxObjectCreateMode::STANDARD ) );
    1164           0 :         xTempDocShell->DoInitNew( 0 );
    1165           0 :         SfxViewFrame* pTempFrame = SfxViewFrame::LoadHiddenDocument( *xTempDocShell, 0 );
    1166           0 :         SwView* pTempView = static_cast<SwView*>( pTempFrame->GetViewShell() );
    1167           0 :         pTargetView->GetWrtShell().StartAction();
    1168           0 :         SwgReaderOption aOpt;
    1169           0 :         aOpt.SetTextFormats( true );
    1170           0 :         aOpt.SetFrameFormats( true );
    1171           0 :         aOpt.SetPageDescs( true );
    1172           0 :         aOpt.SetNumRules( true );
    1173           0 :         aOpt.SetMerge( false );
    1174             :         pTempView->GetDocShell()->LoadStylesFromFile(
    1175           0 :                 sTargetTempURL, aOpt, true );
    1176           0 :         pTempView->GetDocShell()->GetDoc()->ReplaceCompatibilityOptions( *pTargetView->GetDocShell()->GetDoc());
    1177           0 :         pTempView->GetDocShell()->GetDoc()->ReplaceDefaults( *pTargetView->GetDocShell()->GetDoc());
    1178           0 :         pTempView->GetDocShell()->GetDoc()->ReplaceDocumentProperties( *pTargetView->GetDocShell()->GetDoc(), true );
    1179           0 :         pTargetView->GetWrtShell().PastePages(pTempView->GetWrtShell(),
    1180           0 :             documentStartPageNumber( nDoc ), documentEndPageNumber( nDoc ));
    1181           0 :         pTargetView->GetWrtShell().EndAction();
    1182             : 
    1183             :         //then save it
    1184             :         SfxStringItem aName(SID_FILE_NAME,
    1185             :                 URIHelper::SmartRel2Abs(
    1186             :                     INetURLObject(), utl::TempFile::CreateTempName(),
    1187           0 :                     URIHelper::GetMaybeFileHdl()) );
    1188             : 
    1189             :         {
    1190           0 :             uno::Sequence< beans::PropertyValue > aFilterValues(MM_DOCTYPE_TEXT == nDocType ? 2 : 1);
    1191           0 :             beans::PropertyValue* pFilterValues = aFilterValues.getArray();
    1192           0 :             pFilterValues[0].Name = "FilterName";
    1193           0 :             pFilterValues[0].Value <<= OUString(pSfxFlt->GetFilterName());
    1194           0 :             if(MM_DOCTYPE_TEXT == nDocType)
    1195             :             {
    1196           0 :                 pFilterValues[1].Name = "FilterOptions";
    1197           0 :                 pFilterValues[1].Value <<= sFilterOptions;
    1198             :             }
    1199             : 
    1200           0 :             uno::Reference< frame::XStorable > xTempStore( pTempView->GetDocShell()->GetModel(), uno::UNO_QUERY);
    1201           0 :             xTempStore->storeToURL( aName.GetValue(), aFilterValues );
    1202             :         }
    1203           0 :         xTempDocShell->DoClose();
    1204             : 
    1205           0 :         sal_Int32 nTarget = rConfigItem.MoveResultSet(rInfo.nDBRow);
    1206             :         OSL_ENSURE( nTarget == rInfo.nDBRow, "row of current document could not be selected");
    1207             :         (void)nTarget;
    1208             :         OSL_ENSURE( !sEMailColumn.isEmpty(), "No email column selected");
    1209           0 :         OUString sEMail = lcl_GetColumnValueOf(sEMailColumn, xColAccess);
    1210           0 :         SwMailDescriptor aDesc;
    1211           0 :         aDesc.sEMail = sEMail;
    1212           0 :         OUString sBody;
    1213           0 :         if(bAsBody)
    1214             :         {
    1215             :             {
    1216             :                 //read in the temporary file and use it as mail body
    1217           0 :                 SfxMedium aMedium( aName.GetValue(),    StreamMode::READ);
    1218           0 :                 SvStream* pInStream = aMedium.GetInStream();
    1219           0 :                 if(pInStream)
    1220           0 :                     pInStream->SetStreamCharSet( eEncoding );
    1221             :                 else
    1222             :                 {
    1223             :                     OSL_FAIL("no output file created?");
    1224           0 :                     continue;
    1225             :                 }
    1226           0 :                 OString sLine;
    1227           0 :                 bool bDone = pInStream->ReadLine( sLine );
    1228           0 :                 while ( bDone )
    1229             :                 {
    1230           0 :                     sBody += OStringToOUString(sLine, eEncoding);
    1231           0 :                     sBody += "\n";
    1232           0 :                     bDone = pInStream->ReadLine( sLine );
    1233           0 :                 }
    1234             :             }
    1235             :             //remove the temporary file
    1236           0 :             SWUnoHelper::UCB_DeleteFile( aName.GetValue() );
    1237             :         }
    1238             :         else
    1239             :         {
    1240           0 :             sBody = m_sBody;
    1241           0 :             aDesc.sAttachmentURL = aName.GetValue();
    1242           0 :             OUString sAttachment(m_pAttachmentED->GetText());
    1243           0 :             sal_Int32 nTokenCount = comphelper::string::getTokenCount(sAttachment, '.');
    1244           0 :             if (2 > nTokenCount)
    1245             :             {
    1246           0 :                 sAttachment += ".";
    1247           0 :                 sAttachment = comphelper::string::setToken(sAttachment, nTokenCount, '.', sExtension);
    1248             :             }
    1249           0 :             else if (sAttachment.getToken( nTokenCount - 1, '.') != sExtension)
    1250           0 :                 sAttachment += sExtension;
    1251           0 :             aDesc.sAttachmentName = sAttachment;
    1252           0 :             aDesc.sMimeType = sMimeType;
    1253             : 
    1254           0 :             if(rConfigItem.IsGreetingLine(true))
    1255             :             {
    1256           0 :                 OUString sNameColumn = rConfigItem.GetAssignedColumn(MM_PART_LASTNAME);
    1257           0 :                 OUString sName = lcl_GetColumnValueOf(sNameColumn, xColAccess);
    1258           0 :                 OUString sGreeting;
    1259           0 :                 if(!sName.isEmpty() && rConfigItem.IsIndividualGreeting(true))
    1260             :                 {
    1261           0 :                     OUString sGenderColumn = rConfigItem.GetAssignedColumn(MM_PART_GENDER);
    1262           0 :                     const OUString& sFemaleValue = rConfigItem.GetFemaleGenderValue();
    1263           0 :                     OUString sGenderValue = lcl_GetColumnValueOf(sGenderColumn, xColAccess);
    1264           0 :                     SwMailMergeConfigItem::Gender eGenderType = sGenderValue == sFemaleValue ?
    1265             :                         SwMailMergeConfigItem::FEMALE :
    1266           0 :                         SwMailMergeConfigItem::MALE;
    1267             : 
    1268           0 :                     sGreeting = SwAddressPreview::FillData(
    1269             :                         rConfigItem.GetGreetings(eGenderType)
    1270           0 :                         [rConfigItem.GetCurrentGreeting(eGenderType)],
    1271           0 :                             rConfigItem);
    1272             :                 }
    1273             :                 else
    1274             :                 {
    1275             :                     sGreeting =
    1276             :                         rConfigItem.GetGreetings(SwMailMergeConfigItem::NEUTRAL)
    1277           0 :                         [rConfigItem.GetCurrentGreeting(SwMailMergeConfigItem::NEUTRAL)];
    1278             : 
    1279             :                 }
    1280           0 :                 sGreeting += "\n";
    1281           0 :                 sBody = sGreeting + sBody;
    1282           0 :             }
    1283             :         }
    1284           0 :         aDesc.sBodyContent = sBody;
    1285           0 :         if(MM_DOCTYPE_HTML == nDocType)
    1286             :         {
    1287           0 :             aDesc.sBodyMimeType = "text/html; charset=" +
    1288           0 :                 OUString::createFromAscii(rtl_getBestMimeCharsetFromTextEncoding( eEncoding ));
    1289             :         }
    1290             :         else
    1291           0 :             aDesc.sBodyMimeType = "text/plain; charset=UTF-8; format=flowed";
    1292             : 
    1293           0 :         aDesc.sSubject = m_pSubjectED->GetText();
    1294           0 :         aDesc.sCC = m_sCC;
    1295           0 :         aDesc.sBCC = m_sBCC;
    1296           0 :         pDlg->AddDocument( aDesc );
    1297             :         //help to force painting the dialog
    1298           0 :         for ( sal_Int16 i = 0; i < 25; i++)
    1299           0 :             Application::Reschedule();
    1300             :         //stop creating of data when dialog has been closed
    1301           0 :         if(!pDlg->IsVisible())
    1302             :         {
    1303           0 :             m_pWizard->LeaveWait();
    1304           0 :             break;
    1305             :         }
    1306           0 :         m_pWizard->LeaveWait();
    1307           0 :     }
    1308           0 :     pDlg->EnableDesctruction();
    1309           0 :     ::osl::File::remove( sTargetTempURL );
    1310             : 
    1311           0 :     m_pWizard->enableButtons(WizardButtonFlags::FINISH, true);
    1312             :     //the dialog deletes itself
    1313             :     //delete pDlg;
    1314           0 :     return 0;
    1315           0 : }
    1316             : 
    1317             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11