LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/dbui - mailmergehelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 447 0.2 %
Date: 2013-07-09 Functions: 2 77 2.6 %
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 <swtypes.hxx>
      21             : #include <mailmergehelper.hxx>
      22             : #include <svtools/stdctrl.hxx>
      23             : #include <mmconfigitem.hxx>
      24             : #include <docsh.hxx>
      25             : #include <sfx2/filedlghelper.hxx>
      26             : #include <sfx2/docfile.hxx>
      27             : #include <sfx2/app.hxx>
      28             : #include <sfx2/fcontnr.hxx>
      29             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      30             : #include <com/sun/star/sdb/XColumn.hpp>
      31             : #include <com/sun/star/beans/XPropertySet.hpp>
      32             : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
      33             : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
      34             : #include "com/sun/star/mail/MailServiceProvider.hpp"
      35             : #include "com/sun/star/mail/XSmtpService.hpp"
      36             : #include <comphelper/processfactory.hxx>
      37             : #include <comphelper/string.hxx>
      38             : #include <vcl/msgbox.hxx>
      39             : #include <sfx2/passwd.hxx>
      40             : 
      41             : #include <dbui.hrc>
      42             : 
      43             : using namespace ::com::sun::star;
      44             : using namespace ::com::sun::star::uno;
      45             : using namespace ::com::sun::star::container;
      46             : using namespace ::com::sun::star::sdb;
      47             : using namespace ::com::sun::star::sdbc;
      48             : using namespace ::com::sun::star::sdbcx;
      49             : 
      50             : 
      51             : namespace SwMailMergeHelper
      52             : {
      53             : 
      54           0 : String  CallSaveAsDialog(String& rFilter)
      55             : {
      56             :     ErrCode nRet;
      57           0 :     String sFactory(OUString::createFromAscii(SwDocShell::Factory().GetShortName()));
      58             :     ::sfx2::FileDialogHelper aDialog( ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
      59             :                 0,
      60           0 :                 sFactory );
      61             : 
      62           0 :     String sRet;
      63           0 :     nRet = aDialog.Execute();
      64           0 :     if(ERRCODE_NONE == nRet)
      65             :     {
      66           0 :         uno::Reference < ui::dialogs::XFilePicker > xFP = aDialog.GetFilePicker();
      67           0 :         sRet = xFP->getFiles().getConstArray()[0];
      68           0 :         rFilter = aDialog.GetRealFilter();
      69             :     }
      70           0 :     return sRet;
      71             : }
      72             : 
      73             : /*
      74             :     simple address check: check for '@'
      75             :                             for at least one '.' after the '@'
      76             :                             and for at least to characters before and after the dot
      77             : */
      78           0 : bool CheckMailAddress( const OUString& rMailAddress )
      79             : {
      80           0 :     String sAddress(rMailAddress);
      81           0 :     if (!(comphelper::string::getTokenCount(sAddress, '@') == 2))
      82           0 :         return false;
      83           0 :     sAddress = sAddress.GetToken(1, '@');
      84           0 :     if (comphelper::string::getTokenCount(sAddress, '.') < 2)
      85           0 :         return false;
      86           0 :     if(sAddress.GetToken( 0, '.').Len() < 2 || sAddress.GetToken( 1, '.').Len() < 2)
      87           0 :         return false;
      88           0 :     return true;
      89             : }
      90             : 
      91           0 : uno::Reference< mail::XSmtpService > ConnectToSmtpServer(
      92             :         SwMailMergeConfigItem& rConfigItem,
      93             :         uno::Reference< mail::XMailService >&  rxInMailService,
      94             :         const String& rInMailServerPassword,
      95             :         const String& rOutMailServerPassword,
      96             :         Window* pDialogParentWindow )
      97             : {
      98           0 :     uno::Reference< mail::XSmtpService > xSmtpServer;
      99           0 :     uno::Reference< uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext();
     100             :     try
     101             :     {
     102             :         uno::Reference< mail::XMailServiceProvider > xMailServiceProvider(
     103           0 :             mail::MailServiceProvider::create( xContext ) );
     104           0 :         xSmtpServer = uno::Reference< mail::XSmtpService > (
     105           0 :                         xMailServiceProvider->create(
     106             :                         mail::MailServiceType_SMTP
     107           0 :                         ), uno::UNO_QUERY);
     108             : 
     109           0 :         uno::Reference< mail::XConnectionListener> xConnectionListener(new SwConnectionListener());
     110             : 
     111           0 :         if(rConfigItem.IsAuthentication() && rConfigItem.IsSMTPAfterPOP())
     112             :         {
     113             :             uno::Reference< mail::XMailService > xInMailService =
     114           0 :                     xMailServiceProvider->create(
     115           0 :                     rConfigItem.IsInServerPOP() ?
     116           0 :                         mail::MailServiceType_POP3 : mail::MailServiceType_IMAP);
     117             :             //authenticate at the POP or IMAP server first
     118           0 :             String sPasswd = rConfigItem.GetInServerPassword();
     119           0 :             if(rInMailServerPassword.Len())
     120           0 :                 sPasswd = rInMailServerPassword;
     121             :             uno::Reference<mail::XAuthenticator> xAuthenticator =
     122             :                 new SwAuthenticator(
     123             :                     rConfigItem.GetInServerUserName(),
     124             :                     sPasswd,
     125           0 :                     pDialogParentWindow);
     126             : 
     127           0 :             xInMailService->addConnectionListener(xConnectionListener);
     128             :             //check connection
     129             :             uno::Reference< uno::XCurrentContext> xConnectionContext =
     130             :                     new SwConnectionContext(
     131             :                         rConfigItem.GetInServerName(),
     132           0 :                         rConfigItem.GetInServerPort(),
     133           0 :                         OUString("Insecure"));
     134           0 :             xInMailService->connect(xConnectionContext, xAuthenticator);
     135           0 :             rxInMailService = xInMailService;
     136             :         }
     137           0 :         uno::Reference< mail::XAuthenticator> xAuthenticator;
     138           0 :         if(rConfigItem.IsAuthentication() &&
     139           0 :                 !rConfigItem.IsSMTPAfterPOP() &&
     140           0 :                 !rConfigItem.GetMailUserName().isEmpty())
     141             :         {
     142           0 :             String sPasswd = rConfigItem.GetMailPassword();
     143           0 :             if(rOutMailServerPassword.Len())
     144           0 :                 sPasswd = rOutMailServerPassword;
     145           0 :             xAuthenticator =
     146             :                 new SwAuthenticator(rConfigItem.GetMailUserName(),
     147             :                         sPasswd,
     148           0 :                         pDialogParentWindow);
     149             :         }
     150             :         else
     151           0 :             xAuthenticator =  new SwAuthenticator();
     152             :         //just to check if the server exists
     153           0 :         xSmtpServer->getSupportedConnectionTypes();
     154             :         //check connection
     155             : 
     156             :         uno::Reference< uno::XCurrentContext> xConnectionContext =
     157             :                 new SwConnectionContext(
     158             :                     rConfigItem.GetMailServer(),
     159           0 :                     rConfigItem.GetMailPort(),
     160           0 :                     rConfigItem.IsSecureConnection() ? OUString("Ssl") : OUString("Insecure") );
     161           0 :         xSmtpServer->connect(xConnectionContext, xAuthenticator);
     162           0 :         rxInMailService = uno::Reference< mail::XMailService >( xSmtpServer, uno::UNO_QUERY );
     163             :     }
     164           0 :     catch (const uno::Exception&)
     165             :     {
     166             :         OSL_FAIL("exception caught");
     167             :     }
     168           0 :     return xSmtpServer;
     169             : }
     170             : 
     171             : 
     172             : } //namespace
     173             : 
     174           0 : SwBoldFixedInfo::SwBoldFixedInfo(Window* pParent, const ResId& rResId) :
     175           0 :     FixedInfo(pParent, rResId)
     176             : {
     177           0 :     Font aFont = GetFont();
     178           0 :     aFont.SetWeight( WEIGHT_BOLD );
     179           0 :     SetFont( aFont );
     180           0 : }
     181             : 
     182           0 : SwBoldFixedInfo::~SwBoldFixedInfo()
     183             : {
     184           0 : }
     185             : 
     186             : struct  SwAddressPreview_Impl
     187             : {
     188             :     ::std::vector< OUString >    aAdresses;
     189             :     sal_uInt16                          nRows;
     190             :     sal_uInt16                          nColumns;
     191             :     sal_uInt16                          nSelectedAddress;
     192             :     bool                                bEnableScrollBar;
     193             : 
     194           0 :     SwAddressPreview_Impl() :
     195             :         nRows(1),
     196             :         nColumns(1),
     197             :         nSelectedAddress(0),
     198           0 :         bEnableScrollBar(false)
     199             :     {
     200           0 :     }
     201             : };
     202             : 
     203           0 : SwAddressPreview::SwAddressPreview(Window* pParent, const ResId rResId) :
     204             :     Window( pParent, rResId ),
     205             :     aVScrollBar(this, WB_VSCROLL),
     206           0 :     pImpl(new SwAddressPreview_Impl())
     207             : {
     208           0 :     aVScrollBar.SetScrollHdl(LINK(this, SwAddressPreview, ScrollHdl));
     209           0 :     Size aSize(GetOutputSizePixel());
     210           0 :     Size aScrollSize(aVScrollBar.GetSizePixel());
     211           0 :     aScrollSize.Height() = aSize.Height();
     212           0 :     aVScrollBar.SetSizePixel(aScrollSize);
     213           0 :     Point aSrollPos(aSize.Width() - aScrollSize.Width(), 0);
     214           0 :     aVScrollBar.SetPosPixel(aSrollPos);
     215           0 :     Show();
     216           0 : }
     217             : 
     218           0 : SwAddressPreview::~SwAddressPreview()
     219             : {
     220           0 : }
     221             : 
     222           0 : IMPL_LINK_NOARG(SwAddressPreview, ScrollHdl)
     223             : {
     224           0 :     Invalidate();
     225           0 :     return 0;
     226             : }
     227             : 
     228           0 : void SwAddressPreview::AddAddress(const OUString& rAddress)
     229             : {
     230           0 :     pImpl->aAdresses.push_back(rAddress);
     231           0 :     UpdateScrollBar();
     232           0 : }
     233             : 
     234           0 : void SwAddressPreview::SetAddress(const OUString& rAddress)
     235             : {
     236           0 :     pImpl->aAdresses.clear();
     237           0 :     pImpl->aAdresses.push_back(rAddress);
     238           0 :     aVScrollBar.Show(sal_False);
     239           0 :     Invalidate();
     240           0 : }
     241             : 
     242           0 : sal_uInt16   SwAddressPreview::GetSelectedAddress()const
     243             : {
     244             :     OSL_ENSURE(pImpl->nSelectedAddress < pImpl->aAdresses.size(), "selection invalid");
     245           0 :     return pImpl->nSelectedAddress;
     246             : }
     247             : 
     248           0 : void SwAddressPreview::SelectAddress(sal_uInt16 nSelect)
     249             : {
     250             :     OSL_ENSURE(pImpl->nSelectedAddress < pImpl->aAdresses.size(), "selection invalid");
     251           0 :     pImpl->nSelectedAddress = nSelect;
     252             :     // now make it visible..
     253           0 :     sal_uInt16 nSelectRow = nSelect / pImpl->nColumns;
     254           0 :     sal_uInt16 nStartRow = (sal_uInt16)aVScrollBar.GetThumbPos();
     255           0 :     if( (nSelectRow < nStartRow) || (nSelectRow >= (nStartRow + pImpl->nRows) ))
     256           0 :         aVScrollBar.SetThumbPos( nSelectRow );
     257           0 : }
     258             : 
     259           0 : void SwAddressPreview::Clear()
     260             : {
     261           0 :     pImpl->aAdresses.clear();
     262           0 :     pImpl->nSelectedAddress = 0;
     263           0 :     UpdateScrollBar();
     264           0 : }
     265             : 
     266           0 : void SwAddressPreview::ReplaceSelectedAddress(const OUString& rNew)
     267             : {
     268           0 :     pImpl->aAdresses[pImpl->nSelectedAddress] = rNew;
     269           0 :     Invalidate();
     270           0 : }
     271             : 
     272           0 : void SwAddressPreview::RemoveSelectedAddress()
     273             : {
     274           0 :     pImpl->aAdresses.erase(pImpl->aAdresses.begin() + pImpl->nSelectedAddress);
     275           0 :     if(pImpl->nSelectedAddress)
     276           0 :         --pImpl->nSelectedAddress;
     277           0 :     UpdateScrollBar();
     278           0 :     Invalidate();
     279           0 : }
     280             : 
     281           0 : void SwAddressPreview::SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns)
     282             : {
     283           0 :     pImpl->nRows = nRows;
     284           0 :     pImpl->nColumns = nColumns;
     285           0 :     UpdateScrollBar();
     286           0 : }
     287             : 
     288           0 : void SwAddressPreview::EnableScrollBar(bool bEnable)
     289             : {
     290           0 :     pImpl->bEnableScrollBar = bEnable;
     291           0 : }
     292             : 
     293           0 : void SwAddressPreview::UpdateScrollBar()
     294             : {
     295           0 :     if(pImpl->nColumns)
     296             :     {
     297           0 :         aVScrollBar.SetVisibleSize(pImpl->nRows);
     298           0 :         sal_uInt16 nResultingRows = (sal_uInt16)(pImpl->aAdresses.size() + pImpl->nColumns - 1) / pImpl->nColumns;
     299           0 :         ++nResultingRows;
     300           0 :         aVScrollBar.Show(pImpl->bEnableScrollBar && nResultingRows > pImpl->nRows);
     301           0 :         aVScrollBar.SetRange(Range(0, nResultingRows));
     302           0 :         if(aVScrollBar.GetThumbPos() > nResultingRows)
     303           0 :             aVScrollBar.SetThumbPos(nResultingRows);
     304             :     }
     305           0 : }
     306             : 
     307           0 : void SwAddressPreview::Paint(const Rectangle&)
     308             : {
     309           0 :     const StyleSettings& rSettings = GetSettings().GetStyleSettings();
     310           0 :     SetFillColor(rSettings.GetWindowColor());
     311           0 :     SetLineColor( Color(COL_TRANSPARENT) );
     312           0 :     DrawRect( Rectangle(Point(0, 0), GetOutputSizePixel()) );
     313           0 :     Color aPaintColor(IsEnabled() ? rSettings.GetWindowTextColor() : rSettings.GetDisableColor());
     314           0 :     SetLineColor(aPaintColor);
     315           0 :     Font aFont(GetFont());
     316           0 :     aFont.SetColor(aPaintColor);
     317           0 :     SetFont(aFont);
     318             : 
     319           0 :     Size aSize = GetOutputSizePixel();
     320           0 :     sal_uInt16 nStartRow = 0;
     321           0 :     if(aVScrollBar.IsVisible())
     322             :     {
     323           0 :         aSize.Width() -= aVScrollBar.GetSizePixel().Width();
     324           0 :         nStartRow = (sal_uInt16)aVScrollBar.GetThumbPos();
     325             :     }
     326           0 :     Size aPartSize( aSize.Width()/pImpl->nColumns, aSize.Height()/pImpl->nRows );
     327           0 :     aPartSize.Width() -= 2;
     328           0 :     aPartSize.Height() -= 2;
     329             : 
     330           0 :     sal_uInt16 nAddress = nStartRow * pImpl->nColumns;
     331           0 :     const sal_uInt16 nNumAddresses = static_cast< sal_uInt16 >(pImpl->aAdresses.size());
     332           0 :     for(sal_uInt16 nRow = 0; nRow < pImpl->nRows ; ++nRow)
     333             :     {
     334           0 :         for(sal_uInt16 nCol = 0; nCol < pImpl->nColumns; ++nCol)
     335             :         {
     336           0 :             if(nAddress >= nNumAddresses)
     337           0 :                 break;
     338           0 :             Point aPos(nCol * aPartSize.Width(), (nRow) * aPartSize.Height());
     339           0 :             aPos.Move(1,1);
     340           0 :             bool bIsSelected = nAddress == pImpl->nSelectedAddress;
     341           0 :             if((pImpl->nColumns * pImpl->nRows) == 1)
     342           0 :                 bIsSelected = false;
     343           0 :             OUString adr(pImpl->aAdresses[nAddress]);
     344           0 :             DrawText_Impl(adr,aPos,aPartSize,bIsSelected);
     345           0 :             ++nAddress;
     346           0 :         }
     347             :     }
     348           0 :     SetClipRegion();
     349           0 : }
     350             : 
     351           0 : void  SwAddressPreview::MouseButtonDown( const MouseEvent& rMEvt )
     352             : {
     353           0 :     Window::MouseButtonDown(rMEvt);
     354           0 :     if(rMEvt.IsLeft() && ( pImpl->nRows || pImpl->nColumns))
     355             :     {
     356             :         //determine the selected address
     357           0 :         const Point& rMousePos = rMEvt.GetPosPixel();
     358           0 :         Size aSize(GetOutputSizePixel());
     359           0 :         Size aPartSize( aSize.Width()/pImpl->nColumns, aSize.Height()/pImpl->nRows );
     360           0 :         sal_uInt32 nRow = rMousePos.Y() / aPartSize.Height() ;
     361           0 :         if(aVScrollBar.IsVisible())
     362             :         {
     363           0 :             nRow += (sal_uInt16)aVScrollBar.GetThumbPos();
     364             :         }
     365           0 :         sal_uInt32 nCol = rMousePos.X() / aPartSize.Width();
     366           0 :         sal_uInt32 nSelect = nRow * pImpl->nColumns + nCol;
     367             : 
     368           0 :         if( nSelect < pImpl->aAdresses.size() &&
     369           0 :                 pImpl->nSelectedAddress != (sal_uInt16)nSelect)
     370             :         {
     371           0 :             pImpl->nSelectedAddress = (sal_uInt16)nSelect;
     372           0 :             m_aSelectHdl.Call(this);
     373             :         }
     374           0 :         Invalidate();
     375             :     }
     376           0 : }
     377             : 
     378           0 : void  SwAddressPreview::KeyInput( const KeyEvent& rKEvt )
     379             : {
     380           0 :     sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
     381           0 :     if(pImpl->nRows || pImpl->nColumns)
     382             :     {
     383           0 :         sal_uInt32 nSelectedRow =    (pImpl->nSelectedAddress + 1)/ pImpl->nColumns;
     384           0 :         sal_uInt32 nSelectedColumn = pImpl->nSelectedAddress % nSelectedRow;
     385           0 :         switch(nKey)
     386             :         {
     387             :             case KEY_UP:
     388           0 :                 if(nSelectedRow)
     389           0 :                     --nSelectedRow;
     390           0 :             break;
     391             :             case KEY_DOWN:
     392           0 :                 if(pImpl->aAdresses.size() > sal_uInt32(pImpl->nSelectedAddress + pImpl->nColumns))
     393           0 :                     ++nSelectedRow;
     394           0 :             break;
     395             :             case KEY_LEFT:
     396           0 :                 if(nSelectedColumn)
     397           0 :                     --nSelectedColumn;
     398           0 :             break;
     399             :             case KEY_RIGHT:
     400           0 :                 if(nSelectedColumn < sal_uInt32(pImpl->nColumns - 1) &&
     401           0 :                        pImpl->aAdresses.size() - 1 > pImpl->nSelectedAddress )
     402           0 :                     ++nSelectedColumn;
     403           0 :             break;
     404             :         }
     405           0 :         sal_uInt32 nSelect = nSelectedRow * pImpl->nColumns + nSelectedColumn;
     406           0 :         if( nSelect < pImpl->aAdresses.size() &&
     407           0 :                 pImpl->nSelectedAddress != (sal_uInt16)nSelect)
     408             :         {
     409           0 :             pImpl->nSelectedAddress = (sal_uInt16)nSelect;
     410           0 :             m_aSelectHdl.Call(this);
     411           0 :             Invalidate();
     412           0 :         }
     413             :     }
     414             :     else
     415           0 :         Window::KeyInput(rKEvt);
     416           0 : }
     417             : 
     418           0 : void SwAddressPreview::StateChanged( StateChangedType nStateChange )
     419             : {
     420           0 :     if(nStateChange == STATE_CHANGE_ENABLE)
     421           0 :         Invalidate();
     422           0 :     Window::StateChanged(nStateChange);
     423           0 : }
     424             : 
     425           0 : void SwAddressPreview::DrawText_Impl(
     426             :         const OUString& rAddress, const Point& rTopLeft, const Size& rSize, bool bIsSelected)
     427             : {
     428           0 :     SetClipRegion( Region( Rectangle(rTopLeft, rSize)) );
     429           0 :     if(bIsSelected)
     430             :     {
     431             :         //selection rectangle
     432           0 :         SetFillColor(Color(COL_TRANSPARENT));
     433           0 :         DrawRect(Rectangle(rTopLeft, rSize));
     434             :     }
     435           0 :     sal_Int32 nHeight = GetTextHeight();
     436           0 :     String sAddress(rAddress);
     437           0 :     sal_uInt16 nTokens = comphelper::string::getTokenCount(sAddress, '\n');
     438           0 :     Point aStart = rTopLeft;
     439             :     //put it away from the border
     440           0 :     aStart.Move( 2, 2);
     441           0 :     for(sal_uInt16 nToken = 0; nToken < nTokens; nToken++)
     442             :     {
     443           0 :         DrawText( aStart, sAddress.GetToken(nToken, '\n') );
     444           0 :         aStart.Y() += nHeight;
     445           0 :     }
     446           0 : }
     447             : 
     448           0 : String SwAddressPreview::FillData(
     449             :         const OUString& rAddress,
     450             :         SwMailMergeConfigItem& rConfigItem,
     451             :         const Sequence< OUString>* pAssignments)
     452             : {
     453             :     //find the column names in the address string (with name assignment!) and
     454             :     //exchange the placeholder (like <Firstname>) with the database content
     455             :     //unassigned columns are expanded to <not assigned>
     456           0 :     Reference< XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), UNO_QUERY);
     457           0 :     Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
     458             :     Sequence< OUString> aAssignment = pAssignments ?
     459             :                     *pAssignments :
     460             :                     rConfigItem.GetColumnAssignment(
     461           0 :                                                 rConfigItem.GetCurrentDBData() );
     462           0 :     const OUString* pAssignment = aAssignment.getConstArray();
     463           0 :     const ResStringArray& rDefHeaders = rConfigItem.GetDefaultAddressHeaders();
     464           0 :     String sAddress(rAddress);
     465           0 :     String sNotAssigned(SW_RES(STR_NOTASSIGNED));
     466           0 :     sNotAssigned.Insert('<', 0);
     467           0 :     sNotAssigned += '>';
     468             : 
     469           0 :     sal_Bool bIncludeCountry = rConfigItem.IsIncludeCountry();
     470           0 :     const OUString rExcludeCountry = rConfigItem.GetExcludeCountry();
     471           0 :     bool bSpecialReplacementForCountry = (!bIncludeCountry || !rExcludeCountry.isEmpty());
     472           0 :     String sCountryColumn;
     473           0 :     if( bSpecialReplacementForCountry )
     474             :     {
     475           0 :         sCountryColumn = rDefHeaders.GetString(MM_PART_COUNTRY);
     476             :         Sequence< OUString> aSpecialAssignment =
     477           0 :                         rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
     478           0 :         if(aSpecialAssignment.getLength() > MM_PART_COUNTRY && aSpecialAssignment[MM_PART_COUNTRY].getLength())
     479           0 :             sCountryColumn = aSpecialAssignment[MM_PART_COUNTRY];
     480             :     }
     481             : 
     482           0 :     SwAddressIterator aIter(sAddress);
     483           0 :     sAddress.Erase();
     484           0 :     while(aIter.HasMore())
     485             :     {
     486           0 :         SwMergeAddressItem aItem = aIter.Next();
     487           0 :         if(aItem.bIsColumn)
     488             :         {
     489             :             //get the default column name
     490             : 
     491             :             //find the appropriate assignment
     492           0 :             String sConvertedColumn = aItem.sText;
     493           0 :             for(sal_uInt16 nColumn = 0;
     494           0 :                     nColumn < rDefHeaders.Count() && nColumn < aAssignment.getLength();
     495             :                                                                                 ++nColumn)
     496             :             {
     497           0 :                 if (rDefHeaders.GetString(nColumn).equals(aItem.sText) &&
     498           0 :                     !pAssignment[nColumn].isEmpty())
     499             :                 {
     500           0 :                     sConvertedColumn = pAssignment[nColumn];
     501           0 :                     break;
     502             :                 }
     503             :             }
     504           0 :             if(sConvertedColumn.Len() &&
     505           0 :                     xColAccess.is() &&
     506           0 :                     xColAccess->hasByName(sConvertedColumn))
     507             :             {
     508             :                 //get the content and exchange it in the address string
     509           0 :                 Any aCol = xColAccess->getByName(sConvertedColumn);
     510           0 :                 Reference< XColumn > xColumn;
     511           0 :                 aCol >>= xColumn;
     512           0 :                 if(xColumn.is())
     513             :                 {
     514             :                     try
     515             :                     {
     516           0 :                         OUString sReplace = xColumn->getString();
     517             : 
     518           0 :                         if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn )
     519             :                         {
     520           0 :                             if( !rExcludeCountry.isEmpty() && sReplace != rExcludeCountry )
     521           0 :                                 aItem.sText = sReplace;
     522             :                             else
     523           0 :                                 aItem.sText.Erase();
     524             :                         }
     525             :                         else
     526             :                         {
     527           0 :                             aItem.sText = sReplace;
     528           0 :                         }
     529             :                     }
     530           0 :                     catch (const sdbc::SQLException&)
     531             :                     {
     532             :                         OSL_FAIL("SQLException caught");
     533             :                     }
     534           0 :                 }
     535             :             }
     536             :             else
     537             :             {
     538           0 :                 aItem.sText = sNotAssigned;
     539           0 :             }
     540             : 
     541             :         }
     542           0 :         sAddress += aItem.sText;
     543           0 :     }
     544           0 :     return sAddress;
     545             : }
     546             : 
     547           0 : SwMergeAddressItem   SwAddressIterator::Next()
     548             : {
     549             :     //currently the string may either start with a '<' then it's a column
     550             :     //otherwise it's simple text maybe containing a return
     551           0 :     SwMergeAddressItem   aRet;
     552           0 :     if(sAddress.Len())
     553             :     {
     554           0 :         if(sAddress.GetChar(0) == '<')
     555             :         {
     556           0 :             aRet.bIsColumn = true;
     557           0 :             xub_StrLen nClose = sAddress.Search('>');
     558             :             OSL_ENSURE(nClose != STRING_NOTFOUND, "closing '>' not found");
     559           0 :             if( nClose != STRING_NOTFOUND )
     560             :             {
     561           0 :                 aRet.sText = sAddress.Copy(1, nClose - 1);
     562           0 :                 sAddress.Erase(0, nClose + 1);
     563             :             }
     564             :             else
     565             :             {
     566           0 :                 aRet.sText = sAddress.Copy(1, 1);
     567           0 :                 sAddress.Erase(0, 1);
     568             :             }
     569             :         }
     570             :         else
     571             :         {
     572           0 :             xub_StrLen nOpen = sAddress.Search('<');
     573           0 :             xub_StrLen nReturn = sAddress.Search('\n');
     574           0 :             if(nReturn == 0)
     575             :             {
     576           0 :                 aRet.bIsReturn = true;
     577           0 :                 aRet.sText = '\n';
     578           0 :                 sAddress.Erase(0, 1);
     579             :             }
     580           0 :             else if(STRING_NOTFOUND == nOpen && STRING_NOTFOUND == nReturn)
     581             :             {
     582           0 :                 nOpen = sAddress.Len();
     583           0 :                 aRet.sText = sAddress;
     584           0 :                 sAddress.Erase();
     585             :             }
     586             :             else
     587             :             {
     588           0 :                 xub_StrLen nTarget = ::std::min(nOpen, nReturn);
     589           0 :                 aRet.sText = sAddress.Copy(0, nTarget);
     590           0 :                 sAddress.Erase(0, nTarget);
     591             :             }
     592             :         }
     593             :     }
     594           0 :     return aRet;
     595             : 
     596             : }
     597             : 
     598           0 : SwAuthenticator::~SwAuthenticator()
     599             : {
     600           0 : }
     601             : 
     602           0 : OUString SwAuthenticator::getUserName( ) throw (RuntimeException)
     603             : {
     604           0 :     return m_aUserName;
     605             : }
     606             : 
     607           0 : OUString SwAuthenticator::getPassword(  ) throw (RuntimeException)
     608             : {
     609           0 :     if(!m_aUserName.isEmpty() && m_aPassword.isEmpty() && m_pParentWindow)
     610             :     {
     611             :        SfxPasswordDialog* pPasswdDlg =
     612           0 :                 new SfxPasswordDialog( m_pParentWindow );
     613           0 :        pPasswdDlg->SetMinLen( 0 );
     614           0 :        if(RET_OK == pPasswdDlg->Execute())
     615           0 :             m_aPassword = pPasswdDlg->GetPassword();
     616             :     }
     617           0 :     return m_aPassword;
     618             : }
     619             : 
     620           0 : SwConnectionContext::SwConnectionContext(
     621             :         const OUString& rMailServer, sal_Int16 nPort,
     622             :         const OUString& rConnectionType) :
     623             :     m_sMailServer(rMailServer),
     624             :     m_nPort(nPort),
     625           0 :     m_sConnectionType(rConnectionType)
     626             : {
     627           0 : }
     628             : 
     629           0 : SwConnectionContext::~SwConnectionContext()
     630             : {
     631           0 : }
     632             : 
     633           0 : uno::Any SwConnectionContext::getValueByName( const OUString& rName )
     634             :                                                 throw (uno::RuntimeException)
     635             : {
     636           0 :     uno::Any aRet;
     637           0 :     if( !rName.compareToAscii( "ServerName" ))
     638           0 :         aRet <<= m_sMailServer;
     639           0 :     else if( !rName.compareToAscii( "Port" ))
     640           0 :         aRet <<= (sal_Int32) m_nPort;
     641           0 :     else if( !rName.compareToAscii( "ConnectionType" ))
     642           0 :         aRet <<= m_sConnectionType;
     643           0 :     return aRet;
     644             : }
     645             : 
     646           0 : SwConnectionListener::~SwConnectionListener()
     647             : {
     648           0 : }
     649             : 
     650           0 : void SwConnectionListener::connected(const lang::EventObject& /*aEvent*/)
     651             :     throw (uno::RuntimeException)
     652             : {
     653           0 : }
     654             : 
     655           0 : void SwConnectionListener::disconnected(const lang::EventObject& /*aEvent*/)
     656             :     throw (uno::RuntimeException)
     657             : {
     658           0 : }
     659             : 
     660           0 : void SwConnectionListener::disposing(const lang::EventObject& /*aEvent*/)
     661             :     throw(uno::RuntimeException)
     662             : {
     663           0 : }
     664             : 
     665           0 : SwMailTransferable::SwMailTransferable(const OUString& rBody, const OUString& rMimeType) :
     666             :     cppu::WeakComponentImplHelper2< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
     667             :     m_aMimeType( rMimeType ),
     668             :     m_sBody( rBody ),
     669           0 :     m_bIsBody( true )
     670             : {
     671           0 : }
     672             : 
     673           0 : SwMailTransferable::SwMailTransferable(const OUString& rURL,
     674             :                 const OUString& rName, const OUString& rMimeType) :
     675             :     cppu::WeakComponentImplHelper2< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
     676             :     m_aMimeType( rMimeType ),
     677             :     m_aURL(rURL),
     678             :     m_aName( rName ),
     679           0 :     m_bIsBody( false )
     680             : {
     681           0 : }
     682             : 
     683           0 : SwMailTransferable::~SwMailTransferable()
     684             : {
     685           0 : }
     686             : 
     687           0 : uno::Any SwMailTransferable::getTransferData( const datatransfer::DataFlavor& /*aFlavor*/ )
     688             :                             throw (datatransfer::UnsupportedFlavorException,
     689             :                             io::IOException, uno::RuntimeException)
     690             : {
     691           0 :     uno::Any aRet;
     692           0 :     if( m_bIsBody )
     693           0 :         aRet <<= OUString(m_sBody);
     694             :     else
     695             :     {
     696           0 :         Sequence<sal_Int8> aData;
     697           0 :         SfxMedium aMedium( m_aURL, STREAM_STD_READ );
     698           0 :         SvStream* pStream = aMedium.GetInStream();
     699           0 :         if ( aMedium.GetErrorCode() == ERRCODE_NONE && pStream)
     700             :         {
     701           0 :             pStream->Seek(STREAM_SEEK_TO_END);
     702           0 :             aData.realloc(pStream->Tell());
     703           0 :             pStream->Seek(0);
     704           0 :             sal_Int8 * pData = aData.getArray();
     705           0 :             pStream->Read( pData, aData.getLength() );
     706             :         }
     707           0 :         aRet <<= aData;
     708             :     }
     709           0 :     return aRet;
     710             : }
     711             : 
     712           0 : uno::Sequence< datatransfer::DataFlavor > SwMailTransferable::getTransferDataFlavors(  )
     713             :                             throw (uno::RuntimeException)
     714             : {
     715           0 :     uno::Sequence< datatransfer::DataFlavor > aRet(1);
     716           0 :     aRet[0].MimeType = m_aMimeType;
     717           0 :     if( m_bIsBody )
     718             :     {
     719           0 :         aRet[0].DataType = getCppuType((OUString*)0);
     720             :     }
     721             :     else
     722             :     {
     723           0 :         aRet[0].HumanPresentableName = m_aName;
     724           0 :         aRet[0].DataType = getCppuType((uno::Sequence<sal_Int8>*)0);
     725             :     }
     726           0 :     return aRet;
     727             : }
     728             : 
     729           0 : sal_Bool SwMailTransferable::isDataFlavorSupported(
     730             :             const datatransfer::DataFlavor& aFlavor )
     731             :                             throw (uno::RuntimeException)
     732             : {
     733           0 :     return (aFlavor.MimeType == OUString(m_aMimeType));
     734             : }
     735             : 
     736           0 : uno::Reference< beans::XPropertySetInfo > SwMailTransferable::getPropertySetInfo(  ) throw(uno::RuntimeException)
     737             : {
     738           0 :     return uno::Reference< beans::XPropertySetInfo >();
     739             : }
     740             : 
     741           0 : void SwMailTransferable::setPropertyValue( const OUString& , const uno::Any& )
     742             :     throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException,
     743             :           lang::WrappedTargetException, uno::RuntimeException)
     744             : {
     745           0 : }
     746             : 
     747           0 : uno::Any SwMailTransferable::getPropertyValue( const OUString& rPropertyName )
     748             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
     749             : {
     750           0 :     uno::Any aRet;
     751           0 :     if ( rPropertyName == "URL" )
     752           0 :         aRet <<= m_aURL;
     753           0 :     return aRet;
     754             : }
     755             : 
     756           0 : void SwMailTransferable::addPropertyChangeListener(
     757             :     const OUString&, const uno::Reference< beans::XPropertyChangeListener >&  )
     758             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
     759             : {
     760           0 : }
     761             : 
     762           0 : void SwMailTransferable::removePropertyChangeListener(
     763             :     const OUString&,
     764             :     const uno::Reference< beans::XPropertyChangeListener >& )
     765             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
     766             : {
     767           0 : }
     768             : 
     769           0 : void SwMailTransferable::addVetoableChangeListener(
     770             :     const OUString&,
     771             :     const uno::Reference< beans::XVetoableChangeListener >& )
     772             :     throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
     773             : {
     774           0 : }
     775             : 
     776           0 : void SwMailTransferable::removeVetoableChangeListener(
     777             :     const OUString& ,
     778             :     const uno::Reference< beans::XVetoableChangeListener >&  )
     779             :         throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
     780             : {
     781           0 : }
     782             : 
     783           0 : SwMailMessage::SwMailMessage() :
     784           0 :         cppu::WeakComponentImplHelper1< mail::XMailMessage>(m_aMutex)
     785             : {
     786           0 : }
     787             : 
     788           0 : SwMailMessage::~SwMailMessage()
     789             : {
     790           0 : }
     791             : 
     792           0 : OUString SwMailMessage::getSenderName() throw (uno::RuntimeException)
     793             : {
     794           0 :     return m_sSenderName;
     795             : }
     796             : 
     797           0 : OUString SwMailMessage::getSenderAddress() throw (uno::RuntimeException)
     798             : {
     799           0 :     return m_sSenderAddress;
     800             : }
     801             : 
     802           0 : OUString SwMailMessage::getReplyToAddress() throw (uno::RuntimeException)
     803             : {
     804           0 :     return m_sReplyToAddress;
     805             : }
     806             : 
     807           0 : void SwMailMessage::setReplyToAddress( const OUString& _replytoaddress ) throw (uno::RuntimeException)
     808             : {
     809           0 :     m_sReplyToAddress = _replytoaddress;
     810           0 : }
     811             : 
     812           0 : OUString SwMailMessage::getSubject() throw (uno::RuntimeException)
     813             : {
     814           0 :     return m_sSubject;
     815             : }
     816             : 
     817           0 : void SwMailMessage::setSubject( const OUString& _subject ) throw (uno::RuntimeException)
     818             : {
     819           0 :     m_sSubject = _subject;
     820           0 : }
     821             : 
     822           0 : uno::Reference< datatransfer::XTransferable > SwMailMessage::getBody() throw (uno::RuntimeException)
     823             : {
     824           0 :     return m_xBody;
     825             : }
     826             : 
     827           0 : void SwMailMessage::setBody(
     828             :         const uno::Reference< datatransfer::XTransferable >& rBody )
     829             :                                                 throw (uno::RuntimeException)
     830             : {
     831           0 :     m_xBody = rBody;
     832           0 : }
     833             : 
     834           0 : void  SwMailMessage::addRecipient( const OUString& rRecipientAddress )
     835             :         throw (uno::RuntimeException)
     836             : {
     837           0 :     m_aRecipients.realloc(m_aRecipients.getLength() + 1);
     838           0 :     m_aRecipients[m_aRecipients.getLength() - 1] = rRecipientAddress;
     839           0 : }
     840             : 
     841           0 : void  SwMailMessage::addCcRecipient( const OUString& rRecipientAddress )
     842             :         throw (uno::RuntimeException)
     843             : {
     844           0 :     m_aCcRecipients.realloc(m_aCcRecipients.getLength() + 1);
     845           0 :     m_aCcRecipients[m_aCcRecipients.getLength() - 1] = rRecipientAddress;
     846             : 
     847           0 : }
     848             : 
     849           0 : void  SwMailMessage::addBccRecipient( const OUString& rRecipientAddress ) throw (uno::RuntimeException)
     850             : {
     851           0 :     m_aBccRecipients.realloc(m_aBccRecipients.getLength() + 1);
     852           0 :     m_aBccRecipients[m_aBccRecipients.getLength() - 1] = rRecipientAddress;
     853           0 : }
     854             : 
     855           0 : uno::Sequence< OUString > SwMailMessage::getRecipients(  ) throw (uno::RuntimeException)
     856             : {
     857           0 :     return m_aRecipients;
     858             : }
     859             : 
     860           0 : uno::Sequence< OUString > SwMailMessage::getCcRecipients(  ) throw (uno::RuntimeException)
     861             : {
     862           0 :     return m_aCcRecipients;
     863             : }
     864             : 
     865           0 : uno::Sequence< OUString > SwMailMessage::getBccRecipients(  ) throw (uno::RuntimeException)
     866             : {
     867           0 :     return m_aBccRecipients;
     868             : }
     869             : 
     870           0 : void SwMailMessage::addAttachment( const mail::MailAttachment& rMailAttachment )
     871             :             throw (uno::RuntimeException)
     872             : {
     873           0 :     m_aAttachments.realloc(m_aAttachments.getLength() + 1);
     874           0 :     m_aAttachments[m_aAttachments.getLength() - 1] = rMailAttachment;
     875           0 : }
     876             : 
     877           0 : uno::Sequence< mail::MailAttachment > SwMailMessage::getAttachments(  )
     878             :                                             throw (uno::RuntimeException)
     879             : {
     880           0 :     return m_aAttachments;
     881          99 : }
     882             : 
     883             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10