LCOV - code coverage report
Current view: top level - sw/inc - dbmgr.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 28 0.0 %
Date: 2014-04-14 Functions: 0 21 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #ifndef INCLUDED_SW_INC_DBMGR_HXX
      20             : #define INCLUDED_SW_INC_DBMGR_HXX
      21             : 
      22             : #include <rtl/ustring.hxx>
      23             : #include <tools/link.hxx>
      24             : #include <com/sun/star/util/Date.hpp>
      25             : #include "swdllapi.h"
      26             : #include <swdbdata.hxx>
      27             : #include <com/sun/star/uno/Reference.h>
      28             : #include <com/sun/star/uno/Sequence.hxx>
      29             : #include <com/sun/star/lang/Locale.hpp>
      30             : #include <com/sun/star/beans/PropertyValue.hpp>
      31             : #include <boost/ptr_container/ptr_vector.hpp>
      32             : namespace com{namespace sun{namespace star{
      33             :     namespace sdbc{
      34             :         class XConnection;
      35             :         class XStatement;
      36             :         class XDataSource;
      37             :         class XResultSet;
      38             :     }
      39             :     namespace beans{
      40             : 
      41             :         class XPropertySet;
      42             :         struct PropertyValue;
      43             :     }
      44             :     namespace sdbcx{
      45             :         class XColumnsSupplier;
      46             :     }
      47             :     namespace util{
      48             :         class XNumberFormatter;
      49             :     }
      50             :     namespace mail{
      51             :         class XSmtpService;
      52             :     }
      53             : }}}
      54             : namespace svx {
      55             :     class ODataAccessDescriptor;
      56             : }
      57             : 
      58           0 : struct SwDBFormatData
      59             : {
      60             :     com::sun::star::util::Date aNullDate;
      61             :     com::sun::star::uno::Reference< com::sun::star::util::XNumberFormatter> xFormatter;
      62             :     com::sun::star::lang::Locale aLocale;
      63             : };
      64             : 
      65             : class SwView;
      66             : class SwWrtShell;
      67             : class SfxProgress;
      68             : class ListBox;
      69             : class Button;
      70             : class SvNumberFormatter;
      71             : class SwDbtoolsClient;
      72             : class SwXMailMerge;
      73             : class SwMailMergeConfigItem;
      74             : 
      75             : enum DBMgrOptions
      76             : {
      77             :     DBMGR_MERGE,             ///< Data records in fields.
      78             :     DBMGR_INSERT,            ///< Data records in text.
      79             :     DBMGR_MERGE_MAILMERGE,   ///< Print mail merge.
      80             :     DBMGR_MERGE_MAILING,     ///< Send mail merge as email.
      81             :     DBMGR_MERGE_MAILFILES,   ///< Save mail merg as files.
      82             :     DBMGR_MERGE_DOCUMENTS,   ///< Print merged documents.
      83             :     DBMGR_MERGE_SINGLE_FILE  ///< Save merge as single file.
      84             : };
      85             : 
      86             : /*--------------------------------------------------------------------
      87             :      Administration of (new) logical databases.
      88             :  --------------------------------------------------------------------*/
      89             : #define SW_DB_SELECT_UNKNOWN    0
      90             : #define SW_DB_SELECT_TABLE      1
      91             : #define SW_DB_SELECT_QUERY      2
      92             : 
      93           0 : struct SwDSParam : public SwDBData
      94             : {
      95             :     com::sun::star::util::Date  aNullDate;
      96             : 
      97             :     ::com::sun::star::uno::Reference<com::sun::star::util::XNumberFormatter>    xFormatter;
      98             :     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>      xConnection;
      99             :     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement>       xStatement;
     100             :     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>       xResultSet;
     101             :     ::com::sun::star::uno::Sequence<  ::com::sun::star::uno::Any >              aSelection;
     102             :     sal_Bool bScrollable;
     103             :     sal_Bool bEndOfDB;
     104             :     sal_Bool bAfterSelection;
     105             :     long nSelectionIndex;
     106             : 
     107           0 :     SwDSParam(const SwDBData& rData) :
     108             :         SwDBData(rData),
     109             :         bScrollable(sal_False),
     110             :         bEndOfDB(sal_False),
     111             :         bAfterSelection(sal_False),
     112           0 :         nSelectionIndex(0)
     113           0 :         {}
     114             : 
     115           0 :     SwDSParam(const SwDBData& rData,
     116             :         const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>&    xResSet,
     117             :         const ::com::sun::star::uno::Sequence<  ::com::sun::star::uno::Any >&   rSelection) :
     118             :         SwDBData(rData),
     119             :         xResultSet(xResSet),
     120             :         aSelection(rSelection),
     121             :         bScrollable(sal_True),
     122             :         bEndOfDB(sal_False),
     123             :         bAfterSelection(sal_False),
     124           0 :         nSelectionIndex(0)
     125           0 :         {}
     126             : 
     127           0 :         void CheckEndOfDB()
     128             :         {
     129           0 :             if(bEndOfDB)
     130           0 :                 bAfterSelection = sal_True;
     131           0 :         }
     132             : };
     133             : typedef boost::ptr_vector<SwDSParam> SwDSParamArr;
     134             : 
     135           0 : struct SwMergeDescriptor
     136             : {
     137             :     sal_uInt16                                              nMergeType;
     138             :     SwWrtShell&                                         rSh;
     139             :     const ::svx::ODataAccessDescriptor&                 rDescriptor;
     140             :     OUString                                            sSaveToFilter; ///< export filter to save resulting files
     141             :     OUString                                            sSaveToFilterOptions;
     142             :     ::css::uno::Sequence< ::css::beans::PropertyValue > aSaveToFilterData;
     143             : 
     144             :     OUString                                            sSubject;
     145             :     OUString                                            sAddressFromColumn;
     146             :     OUString                                            sMailBody;
     147             :     OUString                                            sAttachmentName;
     148             :     ::css::uno::Sequence< OUString >                    aCopiesTo;
     149             :     ::css::uno::Sequence< OUString >                    aBlindCopiesTo;
     150             : 
     151             :     ::css::uno::Reference< ::css::mail::XSmtpService >  xSmtpServer;
     152             : 
     153             :     sal_Bool                                            bSendAsHTML;
     154             :     sal_Bool                                            bSendAsAttachment;
     155             : 
     156             :     sal_Bool                                            bPrintAsync;
     157             :     sal_Bool                                            bCreateSingleFile;
     158             : 
     159             :     SwMailMergeConfigItem*                              pMailMergeConfigItem;
     160             : 
     161             :     ::com::sun::star::uno::Sequence<  ::com::sun::star::beans::PropertyValue >  aPrintOptions;
     162             : 
     163           0 :     SwMergeDescriptor( sal_uInt16 nType, SwWrtShell& rShell, ::svx::ODataAccessDescriptor& rDesc ) :
     164             :         nMergeType(nType),
     165             :         rSh(rShell),
     166             :         rDescriptor(rDesc),
     167             :         bSendAsHTML( sal_True ),
     168             :         bSendAsAttachment( sal_False ),
     169             :         bPrintAsync( sal_False ),
     170             :         bCreateSingleFile( sal_False ),
     171           0 :         pMailMergeConfigItem(0)
     172           0 :         {}
     173             : 
     174             : };
     175             : 
     176             : struct SwNewDBMgr_Impl;
     177             : class SwConnectionDisposedListener_Impl;
     178             : class AbstractMailMergeDlg;
     179             : 
     180             : class SW_DLLPUBLIC SwNewDBMgr
     181             : {
     182             : friend class SwConnectionDisposedListener_Impl;
     183             : 
     184             :     static SwDbtoolsClient* pDbtoolsClient;
     185             : 
     186             :     OUString            sEMailAddrFld;      ///< Mailing: Column name of email address.
     187             :     OUString            sSubject;           ///< Mailing: Subject
     188             :     OUString            sAttached;          ///< Mailing: Attached Files.
     189             :     sal_Bool            bCancel;            ///< Mail merge canceled.
     190             :     sal_Bool            bInitDBFields : 1;
     191             :     sal_Bool            bSingleJobs : 1;    ///< Printing job when called from Basic.
     192             :     sal_Bool            bInMerge    : 1;    ///< merge process active
     193             :     sal_Bool            bMergeSilent : 1;   ///< suppress display of dialogs/boxes (used when called over API)
     194             :     sal_Bool            bMergeLock : 1;     /**< prevent update of database fields while document is
     195             :                                              actually printed at the SwViewShell */
     196             :     SwDSParamArr        aDataSourceParams;
     197             :     SwNewDBMgr_Impl*    pImpl;
     198             :     const SwXMailMerge* pMergeEvtSrc;   ///< != 0 if mail merge events are to be send
     199             : 
     200             :     SAL_DLLPRIVATE SwDSParam*          FindDSData(const SwDBData& rData, sal_Bool bCreate);
     201             :     SAL_DLLPRIVATE SwDSParam*          FindDSConnection(const OUString& rSource, sal_Bool bCreate);
     202             : 
     203             :     SAL_DLLPRIVATE DECL_LINK( PrtCancelHdl, Button * );
     204             : 
     205             :     /// Insert data record as text into document.
     206             :     SAL_DLLPRIVATE void ImportFromConnection( SwWrtShell* pSh);
     207             : 
     208             :     /// Insert a single data record as text into document.
     209             :     SAL_DLLPRIVATE void ImportDBEntry(SwWrtShell* pSh);
     210             : 
     211             :     /// merge to file _and_ merge to e-Mail
     212             :     SAL_DLLPRIVATE sal_Bool          MergeMailFiles(SwWrtShell* pSh,
     213             :                                         const SwMergeDescriptor& rMergeDescriptor );
     214             :     SAL_DLLPRIVATE sal_Bool          ToNextRecord(SwDSParam* pParam);
     215             : 
     216             : public:
     217             :     SwNewDBMgr();
     218             :     ~SwNewDBMgr();
     219             : 
     220             :     /// MailMergeEvent source
     221           0 :     const SwXMailMerge *    GetMailMergeEvtSrc() const  { return pMergeEvtSrc; }
     222           0 :     void SetMailMergeEvtSrc( const SwXMailMerge *pSrc ) { pMergeEvtSrc = pSrc; }
     223             : 
     224           0 :     inline sal_Bool     IsMergeSilent() const           { return bMergeSilent != 0; }
     225           0 :     inline void     SetMergeSilent( sal_Bool bVal )     { bMergeSilent = bVal; }
     226             : 
     227             :     /// Merging of data records into fields.
     228             :     sal_Bool            MergeNew( const SwMergeDescriptor& rMergeDesc );
     229             :     sal_Bool            Merge(SwWrtShell* pSh);
     230             :     void                MergeCancel();
     231             : 
     232             :     /// Initialize data fields that lack name of database.
     233           0 :     inline sal_Bool     IsInitDBFields() const  { return bInitDBFields; }
     234           0 :     inline void     SetInitDBFields(sal_Bool b) { bInitDBFields = b;    }
     235             : 
     236             :     /// Print / Save mail merge one by one or all together.
     237             :     inline sal_Bool     IsSingleJobs() const    { return bSingleJobs;   }
     238             :     inline void     SetSingleJobs(sal_Bool b)   { bSingleJobs = b;  }
     239             : 
     240             :     /// Mailing: Set email data.
     241           0 :     inline void     SetEMailColumn(const OUString& sColName) { sEMailAddrFld = sColName; }
     242           0 :     inline void     SetSubject(const OUString& sSbj) { sSubject = sSbj; }
     243             :     inline void     SetAttachment(const OUString& sAtt) { sAttached = sAtt; }
     244             : 
     245             :     /// Fill listbox with all table names of a database.
     246             :     sal_Bool            GetTableNames(ListBox* pListBox, const OUString& rDBName );
     247             : 
     248             :     /// Fill listbox with all column names of a database table.
     249             :     sal_Bool            GetColumnNames(ListBox* pListBox,
     250             :                             const OUString& rDBName, const OUString& rTableName, sal_Bool bAppend = sal_False);
     251             :     sal_Bool            GetColumnNames(ListBox* pListBox,
     252             :                             ::css::uno::Reference< ::css::sdbc::XConnection> xConnection,
     253             :                             const OUString& rTableName, sal_Bool bAppend = sal_False);
     254             : 
     255             :     sal_uLong GetColumnFmt( ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource> xSource,
     256             :                             ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> xConnection,
     257             :                             ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> xColumn,
     258             :                             SvNumberFormatter* pNFmtr,
     259             :                             long nLanguage );
     260             : 
     261             :     sal_uLong GetColumnFmt( const OUString& rDBName,
     262             :                             const OUString& rTableName,
     263             :                             const OUString& rColNm,
     264             :                             SvNumberFormatter* pNFmtr,
     265             :                             long nLanguage );
     266             :     sal_Int32 GetColumnType( const OUString& rDBName,
     267             :                           const OUString& rTableName,
     268             :                           const OUString& rColNm );
     269             : 
     270           0 :     inline sal_Bool     IsInMerge() const   { return bInMerge; }
     271             :     void            EndMerge();
     272             : 
     273             :     void            ExecuteFormLetter(SwWrtShell& rSh,
     274             :                         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rProperties,
     275             :                         sal_Bool bWithDataSourceBrowser = sal_False);
     276             : 
     277             :     void            InsertText(SwWrtShell& rSh,
     278             :                         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rProperties);
     279             : 
     280             :     /// check if a data source is open
     281             :     sal_Bool            IsDataSourceOpen(const OUString& rDataSource,
     282             :                                     const OUString& rTableOrQuery, sal_Bool bMergeOnly);
     283             : 
     284             :     /// open the source while fields are updated - for the calculator only!
     285             :     sal_Bool            OpenDataSource(const OUString& rDataSource, const OUString& rTableOrQuery,
     286             :                         sal_Int32 nCommandType = -1, bool bCreate = false);
     287             :     sal_uInt32      GetSelectedRecordId(const OUString& rDataSource, const OUString& rTableOrQuery, sal_Int32 nCommandType = -1);
     288             :     sal_Bool            GetColumnCnt(const OUString& rSourceName, const OUString& rTableName,
     289             :                             const OUString& rColumnName, sal_uInt32 nAbsRecordId, long nLanguage,
     290             :                             OUString& rResult, double* pNumber);
     291             :     /** create and store or find an already stored connection to a data source for use
     292             :     in SwFldMgr and SwDBTreeList */
     293             :     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>
     294             :                     RegisterConnection(OUString& rSource);
     295             : 
     296           0 :     const SwDSParam* CreateDSData(const SwDBData& rData)
     297           0 :                         {return FindDSData(rData, sal_True);}
     298           0 :     const SwDSParamArr& GetDSParamArray() const {return aDataSourceParams;}
     299             : 
     300             :     /// close all data sources - after fields were updated
     301             :     void            CloseAll(sal_Bool bIncludingMerge = sal_True);
     302             : 
     303             :     sal_Bool            GetMergeColumnCnt(const OUString& rColumnName, sal_uInt16 nLanguage,
     304             :                                 OUString &rResult, double *pNumber, sal_uInt32 *pFormat);
     305             :     sal_Bool            ToNextMergeRecord();
     306             :     sal_Bool            ToNextRecord(const OUString& rDataSource, const OUString& rTableOrQuery, sal_Int32 nCommandType = -1);
     307             : 
     308             :     sal_Bool            ExistsNextRecord()const;
     309             :     sal_uInt32      GetSelectedRecordId();
     310             :     sal_Bool        ToRecordId(sal_Int32 nSet);
     311             : 
     312             :     const SwDBData& GetAddressDBName();
     313             : 
     314             :     static OUString GetDBField(
     315             :                     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xColumnProp,
     316             :                     const SwDBFormatData& rDBFormatData,
     317             :                     double *pNumber = NULL);
     318             : 
     319             :     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>
     320             :             GetConnection(const OUString& rDataSource,
     321             :                 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource>& rxSource);
     322             : 
     323             :     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier>
     324             :             GetColumnSupplier(::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>,
     325             :                                     const OUString& rTableOrQuery,
     326             :                                     sal_uInt8   eTableOrQuery = SW_DB_SELECT_UNKNOWN);
     327             : 
     328             :     static ::com::sun::star::uno::Sequence<OUString> GetExistingDatabaseNames();
     329             : 
     330             :     /**
     331             :      Loads a data source from file and registers it. Returns the registered name.
     332             :      */
     333             :     static OUString            LoadAndRegisterDataSource();
     334             : 
     335             :     static SwDbtoolsClient&    GetDbtoolsClient();
     336             :     /// has to be called from _FinitUI()
     337             :     static void                RemoveDbtoolsClient();
     338             : 
     339             :     /** try to get the data source from the given connection through the XChild interface.
     340             :         If this is not possible, the data source will be created through its name.
     341             :         @param _xConnection
     342             :             The connection which should support the XChild interface. (not a must)
     343             :         @param _sDataSourceName
     344             :             The data source name will be used to create the data source when the connection can not be used for it.
     345             :         @return
     346             :             The data source.
     347             :     */
     348             :     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource>
     349             :             getDataSourceAsParent(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,const OUString& _sDataSourceName);
     350             : 
     351             :     /** creates a RowSet, which must be disposed after use.
     352             :         @param  _sDataSourceName
     353             :             The data source name
     354             :         @param  _sCommand
     355             :             The command.
     356             :         @param  _nCommandType
     357             :             The type of the command.
     358             :         @param  _xConnection
     359             :             The active connection which may be <NULL/>.
     360             :         @return
     361             :             The new created RowSet.
     362             : 
     363             :     */
     364             :     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>
     365             :             createCursor(   const OUString& _sDataSourceName,
     366             :                             const OUString& _sCommand,
     367             :                             sal_Int32 _nCommandType,
     368             :                             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection
     369             :                             );
     370             :     //merge into one document - returns the number of merged docs
     371             :     sal_Int32 MergeDocuments( SwMailMergeConfigItem& rMMConfig, SwView& rSourceView );
     372             : };
     373             : 
     374             : #endif
     375             : 
     376             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10