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

Generated by: LCOV version 1.10