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

Generated by: LCOV version 1.10