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

Generated by: LCOV version 1.11