LCOV - code coverage report
Current view: top level - sw/inc - dbmgr.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 18 28 64.3 %
Date: 2014-11-03 Functions: 12 21 57.1 %
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             : 
      33             : namespace com{namespace sun{namespace star{
      34             :     namespace sdbc{
      35             :         class XConnection;
      36             :         class XStatement;
      37             :         class XDataSource;
      38             :         class XResultSet;
      39             :     }
      40             :     namespace beans{
      41             : 
      42             :         class XPropertySet;
      43             :         struct PropertyValue;
      44             :     }
      45             :     namespace sdbcx{
      46             :         class XColumnsSupplier;
      47             :     }
      48             :     namespace util{
      49             :         class XNumberFormatter;
      50             :     }
      51             :     namespace mail{
      52             :         class XSmtpService;
      53             :     }
      54             : }}}
      55             : namespace svx {
      56             :     class ODataAccessDescriptor;
      57             : }
      58             : 
      59           0 : struct SwDBFormatData
      60             : {
      61             :     com::sun::star::util::Date aNullDate;
      62             :     com::sun::star::uno::Reference< com::sun::star::util::XNumberFormatter> xFormatter;
      63             :     com::sun::star::lang::Locale aLocale;
      64             : };
      65             : 
      66             : class SwView;
      67             : class SwWrtShell;
      68             : class SfxProgress;
      69             : class ListBox;
      70             : class Button;
      71             : class SvNumberFormatter;
      72             : class SwDbtoolsClient;
      73             : class SwXMailMerge;
      74             : class SwMailMergeConfigItem;
      75             : class SwCalc;
      76             : class INetURLObject;
      77             : 
      78             : enum DBManagerOptions
      79             : {
      80             :     DBMGR_MERGE,             ///< Data records in fields.
      81             :     DBMGR_MERGE_PRINTER,     ///< Print mail merge.
      82             :     DBMGR_MERGE_EMAIL,       ///< Send mail merge as email.
      83             :     DBMGR_MERGE_FILE,        ///< Save mail merge as files.
      84             :     DBMGR_MERGE_SHELL        ///< Create merge doc and keep the doc shell.
      85             : };
      86             : 
      87             : // Administration of (new) logical databases.
      88             : #define SW_DB_SELECT_UNKNOWN    0
      89             : #define SW_DB_SELECT_TABLE      1
      90             : #define SW_DB_SELECT_QUERY      2
      91             : 
      92           8 : struct SwDSParam : public SwDBData
      93             : {
      94             :     com::sun::star::util::Date  aNullDate;
      95             : 
      96             :     ::com::sun::star::uno::Reference<com::sun::star::util::XNumberFormatter>    xFormatter;
      97             :     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>      xConnection;
      98             :     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement>       xStatement;
      99             :     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>       xResultSet;
     100             :     ::com::sun::star::uno::Sequence<  ::com::sun::star::uno::Any >              aSelection;
     101             :     bool bScrollable;
     102             :     bool bEndOfDB;
     103             :     bool bAfterSelection;
     104             :     long nSelectionIndex;
     105             : 
     106           0 :     SwDSParam(const SwDBData& rData) :
     107             :         SwDBData(rData),
     108             :         bScrollable(false),
     109             :         bEndOfDB(false),
     110             :         bAfterSelection(false),
     111           0 :         nSelectionIndex(0)
     112           0 :         {}
     113             : 
     114           4 :     SwDSParam(const SwDBData& rData,
     115             :         const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>&    xResSet,
     116             :         const ::com::sun::star::uno::Sequence<  ::com::sun::star::uno::Any >&   rSelection) :
     117             :         SwDBData(rData),
     118             :         xResultSet(xResSet),
     119             :         aSelection(rSelection),
     120             :         bScrollable(true),
     121             :         bEndOfDB(false),
     122             :         bAfterSelection(false),
     123           4 :         nSelectionIndex(0)
     124           4 :         {}
     125             : 
     126          14 :         void CheckEndOfDB()
     127             :         {
     128          14 :             if(bEndOfDB)
     129           6 :                 bAfterSelection = true;
     130          14 :         }
     131             : };
     132             : typedef boost::ptr_vector<SwDSParam> SwDSParamArr;
     133             : 
     134           4 : struct SwMergeDescriptor
     135             : {
     136             :     DBManagerOptions                                    nMergeType;
     137             :     SwWrtShell&                                         rSh;
     138             :     const ::svx::ODataAccessDescriptor&                 rDescriptor;
     139             :     OUString                                            sSaveToFilter; ///< export filter to save resulting files
     140             :     OUString                                            sSaveToFilterOptions;
     141             :     css::uno::Sequence< css::beans::PropertyValue >     aSaveToFilterData;
     142             : 
     143             :     OUString                                            sSubject;
     144             :     OUString                                            sAddressFromColumn;
     145             :     OUString                                            sMailBody;
     146             :     OUString                                            sAttachmentName;
     147             :     css::uno::Sequence< OUString >                      aCopiesTo;
     148             :     css::uno::Sequence< OUString >                      aBlindCopiesTo;
     149             : 
     150             :     css::uno::Reference< css::mail::XSmtpService >      xSmtpServer;
     151             : 
     152             :     bool                                            bSendAsHTML;
     153             :     bool                                            bSendAsAttachment;
     154             : 
     155             :     bool                                            bPrintAsync;
     156             :     bool                                            bCreateSingleFile;
     157             :     bool                                            bSubjectIsFilename;
     158             : 
     159             :     SwMailMergeConfigItem*                              pMailMergeConfigItem;
     160             : 
     161             :     ::com::sun::star::uno::Sequence<  ::com::sun::star::beans::PropertyValue >  aPrintOptions;
     162             : 
     163           4 :     SwMergeDescriptor( DBManagerOptions nType, SwWrtShell& rShell, ::svx::ODataAccessDescriptor& rDesc ) :
     164             :         nMergeType(nType),
     165             :         rSh(rShell),
     166             :         rDescriptor(rDesc),
     167             :         bSendAsHTML( true ),
     168             :         bSendAsAttachment( false ),
     169             :         bPrintAsync( false ),
     170             :         bCreateSingleFile( false ),
     171             :         bSubjectIsFilename( false ),
     172           4 :         pMailMergeConfigItem(0)
     173           4 :         {}
     174             : 
     175             : };
     176             : 
     177             : struct SwDBManager_Impl;
     178             : class SwConnectionDisposedListener_Impl;
     179             : class AbstractMailMergeDlg;
     180             : 
     181             : class SW_DLLPUBLIC SwDBManager
     182             : {
     183             : friend class SwConnectionDisposedListener_Impl;
     184             : 
     185             :     static SwDbtoolsClient* pDbtoolsClient;
     186             : 
     187             :     OUString            sEMailAddrFld;      ///< Mailing: Column name of email address.
     188             :     OUString            sSubject;           ///< Mailing: Subject
     189             :     OUString            sAttached;          ///< Mailing: Attached Files.
     190             :     bool            bCancel;            ///< Mail merge canceled.
     191             :     bool            bInitDBFields : 1;
     192             :     bool            bSingleJobs : 1;    ///< Printing job when called from Basic.
     193             :     bool            bInMerge    : 1;    ///< merge process active
     194             :     bool            bMergeSilent : 1;   ///< suppress display of dialogs/boxes (used when called over API)
     195             :     bool            bMergeLock : 1;     /**< prevent update of database fields while document is
     196             :                                              actually printed at the SwViewShell */
     197             :     SwDSParamArr        aDataSourceParams;
     198             :     SwDBManager_Impl*    pImpl;
     199             :     const SwXMailMerge* pMergeEvtSrc;   ///< != 0 if mail merge events are to be send
     200             : 
     201             :     SAL_DLLPRIVATE SwDSParam*          FindDSData(const SwDBData& rData, bool bCreate);
     202             :     SAL_DLLPRIVATE SwDSParam*          FindDSConnection(const OUString& rSource, bool bCreate);
     203             : 
     204             :     SAL_DLLPRIVATE DECL_LINK( PrtCancelHdl, Button * );
     205             : 
     206             :     /// Insert data record as text into document.
     207             :     SAL_DLLPRIVATE void ImportFromConnection( SwWrtShell* pSh);
     208             : 
     209             :     /// Insert a single data record as text into document.
     210             :     SAL_DLLPRIVATE void ImportDBEntry(SwWrtShell* pSh);
     211             : 
     212             :     /// merge to file _and_ merge to e-Mail
     213             :     SAL_DLLPRIVATE bool          MergeMailFiles(SwWrtShell* pSh,
     214             :                                         const SwMergeDescriptor& rMergeDescriptor );
     215             :     SAL_DLLPRIVATE bool          ToNextRecord(SwDSParam* pParam);
     216             : 
     217             : public:
     218             :     SwDBManager();
     219             :     ~SwDBManager();
     220             : 
     221             :     enum DBConnURITypes {
     222             :         DBCONN_UNKNOWN = 0,
     223             :         DBCONN_ODB,
     224             :         DBCONN_CALC,
     225             :         DBCONN_DBASE,
     226             :         DBCONN_FLAT,
     227             :         DBCONN_MSJET,
     228             :         DBCONN_MSACE
     229             :     };
     230             : 
     231             :     /// MailMergeEvent source
     232          14 :     const SwXMailMerge *    GetMailMergeEvtSrc() const  { return pMergeEvtSrc; }
     233           8 :     void SetMailMergeEvtSrc( const SwXMailMerge *pSrc ) { pMergeEvtSrc = pSrc; }
     234             : 
     235          18 :     inline bool     IsMergeSilent() const           { return bMergeSilent; }
     236           4 :     inline void     SetMergeSilent( bool bVal )     { bMergeSilent = bVal; }
     237             : 
     238             :     /// Merging of data records into fields.
     239             :     bool            MergeNew( const SwMergeDescriptor& rMergeDesc );
     240             :     bool            Merge(SwWrtShell* pSh);
     241             :     void            MergeCancel();
     242             : 
     243             :     /// Initialize data fields that lack name of database.
     244           4 :     inline bool     IsInitDBFields() const  { return bInitDBFields; }
     245         186 :     inline void     SetInitDBFields(bool b) { bInitDBFields = b;    }
     246             : 
     247             :     /// Print / Save mail merge one by one or all together.
     248             :     bool     IsSingleJobs() const    { return bSingleJobs;   }
     249             :     void     SetSingleJobs(bool b)   { bSingleJobs = b;  }
     250             : 
     251             :     /// Mailing: Set email data.
     252           0 :     inline void     SetEMailColumn(const OUString& sColName) { sEMailAddrFld = sColName; }
     253           0 :     inline void     SetSubject(const OUString& sSbj) { sSubject = sSbj; }
     254             :     inline void     SetAttachment(const OUString& sAtt) { sAttached = sAtt; }
     255             : 
     256             :     /// Fill listbox with all table names of a database.
     257             :     bool            GetTableNames(ListBox* pListBox, const OUString& rDBName );
     258             : 
     259             :     /// Fill listbox with all column names of a database table.
     260             :     void            GetColumnNames(ListBox* pListBox,
     261             :                             const OUString& rDBName, const OUString& rTableName, bool bAppend = false);
     262             :     void            GetColumnNames(ListBox* pListBox,
     263             :                             css::uno::Reference< css::sdbc::XConnection> xConnection,
     264             :                             const OUString& rTableName, bool bAppend = false);
     265             : 
     266             :     sal_uLong GetColumnFmt( ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource> xSource,
     267             :                             ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> xConnection,
     268             :                             ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> xColumn,
     269             :                             SvNumberFormatter* pNFmtr,
     270             :                             long nLanguage );
     271             : 
     272             :     sal_uLong GetColumnFmt( const OUString& rDBName,
     273             :                             const OUString& rTableName,
     274             :                             const OUString& rColNm,
     275             :                             SvNumberFormatter* pNFmtr,
     276             :                             long nLanguage );
     277             :     sal_Int32 GetColumnType( const OUString& rDBName,
     278             :                           const OUString& rTableName,
     279             :                           const OUString& rColNm );
     280             : 
     281           0 :     inline bool     IsInMerge() const   { return bInMerge; }
     282             : 
     283             :     void            ExecuteFormLetter(SwWrtShell& rSh,
     284             :                         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rProperties,
     285             :                         bool bWithDataSourceBrowser = false);
     286             : 
     287             :     void            InsertText(SwWrtShell& rSh,
     288             :                         const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rProperties);
     289             : 
     290             :     /// check if a data source is open
     291             :     bool            IsDataSourceOpen(const OUString& rDataSource,
     292             :                                     const OUString& rTableOrQuery, bool bMergeShell);
     293             : 
     294             :     /// open the source while fields are updated - for the calculator only!
     295             :     bool            OpenDataSource(const OUString& rDataSource, const OUString& rTableOrQuery,
     296             :                         sal_Int32 nCommandType = -1, bool bCreate = false);
     297             :     sal_uInt32      GetSelectedRecordId(const OUString& rDataSource, const OUString& rTableOrQuery, sal_Int32 nCommandType = -1);
     298             :     bool            GetColumnCnt(const OUString& rSourceName, const OUString& rTableName,
     299             :                             const OUString& rColumnName, sal_uInt32 nAbsRecordId, long nLanguage,
     300             :                             OUString& rResult, double* pNumber);
     301             :     /** create and store or find an already stored connection to a data source for use
     302             :     in SwFldMgr and SwDBTreeList */
     303             :     ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>
     304             :                     RegisterConnection(OUString& rSource);
     305             : 
     306           0 :     const SwDSParam* CreateDSData(const SwDBData& rData)
     307           0 :                         {return FindDSData(rData, true);}
     308           0 :     const SwDSParamArr& GetDSParamArray() const {return aDataSourceParams;}
     309             : 
     310             :     /// close all data sources - after fields were updated
     311             :     void            CloseAll(bool bIncludingMerge = true);
     312             : 
     313             :     bool            GetMergeColumnCnt(const OUString& rColumnName, sal_uInt16 nLanguage,
     314             :                                       OUString &rResult, double *pNumber, sal_uInt32 *pFormat);
     315             :     bool            FillCalcWithMergeData(SvNumberFormatter *pDocFormatter,
     316             :                                           sal_uInt16 nLanguage, bool asString, SwCalc &aCalc);
     317             :     bool            ToNextMergeRecord();
     318             :     bool            ToNextRecord(const OUString& rDataSource, const OUString& rTableOrQuery, sal_Int32 nCommandType = -1);
     319             : 
     320             :     bool            ExistsNextRecord()const;
     321             :     sal_uInt32      GetSelectedRecordId();
     322             :     bool            ToRecordId(sal_Int32 nSet);
     323             : 
     324             :     const SwDBData& GetAddressDBName();
     325             : 
     326             :     static OUString GetDBField(
     327             :                     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xColumnProp,
     328             :                     const SwDBFormatData& rDBFormatData,
     329             :                     double *pNumber = NULL);
     330             : 
     331             :     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>
     332             :             GetConnection(const OUString& rDataSource,
     333             :                 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource>& rxSource);
     334             : 
     335             :     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier>
     336             :             GetColumnSupplier(::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>,
     337             :                                     const OUString& rTableOrQuery,
     338             :                                     sal_uInt8   eTableOrQuery = SW_DB_SELECT_UNKNOWN);
     339             : 
     340             :     static ::com::sun::star::uno::Sequence<OUString> GetExistingDatabaseNames();
     341             : 
     342             :     static DBConnURITypes GetDBunoURI(const OUString &rURI, ::com::sun::star::uno::Any &aURLAny);
     343             : 
     344             :     /**
     345             :      Loads a data source from file and registers it.
     346             : 
     347             :      This function requires GUI interaction, as it loads the data source from
     348             :      the filename returned by a file picker and additional settings dialog.
     349             :      In case of success it returns the registered name, otherwise an empty string.
     350             :      */
     351             :     static OUString            LoadAndRegisterDataSource();
     352             : 
     353             :     /**
     354             :      Loads a data source from file and registers it.
     355             : 
     356             :      In case of success it returns the registered name, otherwise an empty string.
     357             :      Optionally add a prefix to the registered DB name.
     358             :      */
     359             :     static OUString            LoadAndRegisterDataSource(const DBConnURITypes type, const ::com::sun::star::uno::Any &rUnoURI,
     360             :                                                          const ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySet > *pSettings,
     361             :                                                          const OUString &rURI, const OUString *pPrefix = 0, const OUString *pDestDir = 0);
     362             :     /**
     363             :      Loads a data source from file and registers it.
     364             : 
     365             :      Convenience function, which calls GetDBunoURI and has just one mandatory parameter.
     366             :      In case of success it returns the registered name, otherwise an empty string.
     367             :      */
     368             :     static OUString            LoadAndRegisterDataSource(const OUString& rURI, const OUString *pPrefix = 0, const OUString *pDestDir = 0,
     369             :                                                          const ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySet > *pSettings = 0);
     370             : 
     371             :     static SwDbtoolsClient&    GetDbtoolsClient();
     372             :     /// has to be called from _FinitUI()
     373             :     static void                RemoveDbtoolsClient();
     374             : 
     375             :     /** try to get the data source from the given connection through the XChild interface.
     376             :         If this is not possible, the data source will be created through its name.
     377             :         @param _xConnection
     378             :             The connection which should support the XChild interface. (not a must)
     379             :         @param _sDataSourceName
     380             :             The data source name will be used to create the data source when the connection can not be used for it.
     381             :         @return
     382             :             The data source.
     383             :     */
     384             :     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource>
     385             :             getDataSourceAsParent(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,const OUString& _sDataSourceName);
     386             : 
     387             :     /** creates a RowSet, which must be disposed after use.
     388             :         @param  _sDataSourceName
     389             :             The data source name
     390             :         @param  _sCommand
     391             :             The command.
     392             :         @param  _nCommandType
     393             :             The type of the command.
     394             :         @param  _xConnection
     395             :             The active connection which may be <NULL/>.
     396             :         @return
     397             :             The new created RowSet.
     398             : 
     399             :     */
     400             :     static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>
     401             :             createCursor(   const OUString& _sDataSourceName,
     402             :                             const OUString& _sCommand,
     403             :                             sal_Int32 _nCommandType,
     404             :                             const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection
     405             :                             );
     406             : };
     407             : 
     408             : #endif
     409             : 
     410             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10