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

Generated by: LCOV version 1.10