LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/dbui - mailmergehelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 443 0.2 %
Date: 2012-12-17 Functions: 2 77 2.6 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10