Files
libreoffice/sw/inc/dbmgr.hxx

375 lines
16 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patches contributed by Oliver-Rainer Wittmann sw34bf06: #i117783# - Writer's implementation of XPagePrintable - apply print settings to new printing routines http://svn.apache.org/viewvc?view=revision&revision=1172115 sw34bf06: #o12311627# use <rtl_random> methods to create unique ids for list styles and list ids http://svn.apache.org/viewvc?view=revision&revision=1172112 sw34bf06 #i114725#,#i115828# - method <SwDoc::ClearDoc()> - clear list structures completely http://svn.apache.org/viewvc?view=revision&revision=1172122 i#118572 - remove ui string and help content regarding usage of Java Mail in Writer's Mail Merge as Java Mail is not used. http://svn.apache.org/viewvc?view=revision&revision=1197035 Patches contributed by Mathias Bauer cws mba34issues01: #i117718#: provide filter name in case storage of medium does not allow to detect one http://svn.apache.org/viewvc?view=revision&revision=1172350 cws mba34issues01: #i117721#: directly provide parameters retrieved from SfxMedium http://svn.apache.org/viewvc?view=revision&revision=1172353 gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 cws mba34issues01: #i117723#: convert assertion into trace http://svn.apache.org/viewvc?view=revision&revision=1172355 cws mba34issues01: #i117699#: keep layout alive until swdoc dies http://svn.apache.org/viewvc?view=revision&revision=1172362 cws mba34issues01: #i117943#: missing color attributes in RTF clipboard http://svn.apache.org/viewvc?view=revision&revision=1172363 Patch contributed by Henning Brinkmann imported patch i#103878 http://svn.apache.org/viewvc?view=revision&revision=1172109 Patches contributed by Michael Stahl sw34bf06: #i117955#: WW8 export: disable storing of section breaks in endnotes http://svn.apache.org/viewvc?view=revision&revision=1172119 Patch contributed by imacat Fixed the Asian language work count. http://svn.apache.org/viewvc?view=revision&revision=1241345 Patch contributed by Pedro Giffuni i#20878 - Add comment with BZ issue for reference. http://svn.apache.org/viewvc?view=revision&revision=1244517 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 add writerperfect dependency.
2011-03-31 10:05:04 +02:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_SW_INC_DBMGR_HXX
#define INCLUDED_SW_INC_DBMGR_HXX
2000-09-18 16:15:01 +00:00
#include <rtl/ustring.hxx>
#include <tools/link.hxx>
2000-09-18 16:15:01 +00:00
#include <com/sun/star/util/Date.hpp>
#include "swdllapi.h"
#include <swdbdata.hxx>
2000-09-18 16:15:01 +00:00
#include <com/sun/star/uno/Reference.h>
#include <com/sun/star/uno/Sequence.hxx>
2000-09-18 16:15:01 +00:00
#include <com/sun/star/lang/Locale.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
2000-09-18 16:15:01 +00:00
namespace com{namespace sun{namespace star{
namespace sdbc{
class XConnection;
class XStatement;
class XDataSource;
class XResultSet;
}
namespace beans{
class XPropertySet;
2000-11-13 07:32:00 +00:00
struct PropertyValue;
2000-09-18 16:15:01 +00:00
}
namespace sdbcx{
class XColumnsSupplier;
}
namespace util{
class XNumberFormatter;
}
namespace mail{
class XSmtpService;
}
2000-09-18 16:15:01 +00:00
}}}
namespace svx {
class ODataAccessDescriptor;
}
2000-09-18 16:15:01 +00:00
struct SwDBFormatData
{
com::sun::star::util::Date aNullDate;
com::sun::star::uno::Reference< com::sun::star::util::XNumberFormatter> xFormatter;
com::sun::star::lang::Locale aLocale;
};
class SwView;
class SwWrtShell;
class SfxProgress;
class ListBox;
class Button;
class SvNumberFormatter;
class SwDbtoolsClient;
class SwXMailMerge;
class SwMailMergeConfigItem;
enum DBManagerOptions
2000-09-18 16:15:01 +00:00
{
DBMGR_MERGE, ///< Data records in fields.
DBMGR_INSERT, ///< Data records in text.
DBMGR_MERGE_MAILMERGE, ///< Print mail merge.
DBMGR_MERGE_MAILING, ///< Send mail merge as email.
DBMGR_MERGE_MAILFILES, ///< Save mail merg as files.
DBMGR_MERGE_DOCUMENTS, ///< Print merged documents.
DBMGR_MERGE_SINGLE_FILE ///< Save merge as single file.
2000-09-18 16:15:01 +00:00
};
// Administration of (new) logical databases.
2000-09-18 16:15:01 +00:00
#define SW_DB_SELECT_UNKNOWN 0
#define SW_DB_SELECT_TABLE 1
#define SW_DB_SELECT_QUERY 2
struct SwDSParam : public SwDBData
2000-09-18 16:15:01 +00:00
{
com::sun::star::util::Date aNullDate;
::com::sun::star::uno::Reference<com::sun::star::util::XNumberFormatter> xFormatter;
2000-10-31 14:26:08 +00:00
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> xConnection;
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement> xStatement;
2000-11-13 07:32:00 +00:00
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet> xResultSet;
::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aSelection;
bool bScrollable;
bool bEndOfDB;
bool bAfterSelection;
2000-09-18 16:15:01 +00:00
long nSelectionIndex;
SwDSParam(const SwDBData& rData) :
SwDBData(rData),
bScrollable(false),
bEndOfDB(false),
bAfterSelection(false),
2000-09-18 16:15:01 +00:00
nSelectionIndex(0)
{}
2000-11-13 07:32:00 +00:00
SwDSParam(const SwDBData& rData,
const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& xResSet,
const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rSelection) :
SwDBData(rData),
xResultSet(xResSet),
aSelection(rSelection),
bScrollable(true),
bEndOfDB(false),
bAfterSelection(false),
nSelectionIndex(0)
2000-11-13 07:32:00 +00:00
{}
void CheckEndOfDB()
{
if(bEndOfDB)
bAfterSelection = true;
}
2000-09-18 16:15:01 +00:00
};
typedef boost::ptr_vector<SwDSParam> SwDSParamArr;
2000-09-18 16:15:01 +00:00
struct SwMergeDescriptor
{
sal_uInt16 nMergeType;
SwWrtShell& rSh;
const ::svx::ODataAccessDescriptor& rDescriptor;
OUString sSaveToFilter; ///< export filter to save resulting files
OUString sSaveToFilterOptions;
::css::uno::Sequence< ::css::beans::PropertyValue > aSaveToFilterData;
OUString sSubject;
OUString sAddressFromColumn;
OUString sMailBody;
OUString sAttachmentName;
::css::uno::Sequence< OUString > aCopiesTo;
::css::uno::Sequence< OUString > aBlindCopiesTo;
::css::uno::Reference< ::css::mail::XSmtpService > xSmtpServer;
bool bSendAsHTML;
bool bSendAsAttachment;
bool bPrintAsync;
bool bCreateSingleFile;
SwMailMergeConfigItem* pMailMergeConfigItem;
::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aPrintOptions;
SwMergeDescriptor( sal_uInt16 nType, SwWrtShell& rShell, ::svx::ODataAccessDescriptor& rDesc ) :
nMergeType(nType),
rSh(rShell),
rDescriptor(rDesc),
bSendAsHTML( true ),
bSendAsAttachment( false ),
bPrintAsync( false ),
bCreateSingleFile( false ),
pMailMergeConfigItem(0)
{}
};
struct SwDBManager_Impl;
class SwConnectionDisposedListener_Impl;
class AbstractMailMergeDlg;
class SW_DLLPUBLIC SwDBManager
2000-09-18 16:15:01 +00:00
{
friend class SwConnectionDisposedListener_Impl;
static SwDbtoolsClient* pDbtoolsClient;
OUString sEMailAddrFld; ///< Mailing: Column name of email address.
OUString sSubject; ///< Mailing: Subject
OUString sAttached; ///< Mailing: Attached Files.
bool bCancel; ///< Mail merge canceled.
bool bInitDBFields : 1;
bool bSingleJobs : 1; ///< Printing job when called from Basic.
bool bInMerge : 1; ///< merge process active
bool bMergeSilent : 1; ///< suppress display of dialogs/boxes (used when called over API)
bool bMergeLock : 1; /**< prevent update of database fields while document is
actually printed at the SwViewShell */
2000-09-18 16:15:01 +00:00
SwDSParamArr aDataSourceParams;
SwDBManager_Impl* pImpl;
const SwXMailMerge* pMergeEvtSrc; ///< != 0 if mail merge events are to be send
2000-09-18 16:15:01 +00:00
SAL_DLLPRIVATE SwDSParam* FindDSData(const SwDBData& rData, bool bCreate);
SAL_DLLPRIVATE SwDSParam* FindDSConnection(const OUString& rSource, bool bCreate);
2000-09-18 16:15:01 +00:00
SAL_DLLPRIVATE DECL_LINK( PrtCancelHdl, Button * );
2000-09-18 16:15:01 +00:00
/// Insert data record as text into document.
SAL_DLLPRIVATE void ImportFromConnection( SwWrtShell* pSh);
2000-09-18 16:15:01 +00:00
/// Insert a single data record as text into document.
SAL_DLLPRIVATE void ImportDBEntry(SwWrtShell* pSh);
2000-09-18 16:15:01 +00:00
/// merge to file _and_ merge to e-Mail
SAL_DLLPRIVATE bool MergeMailFiles(SwWrtShell* pSh,
const SwMergeDescriptor& rMergeDescriptor );
SAL_DLLPRIVATE bool ToNextRecord(SwDSParam* pParam);
2000-09-18 16:15:01 +00:00
public:
SwDBManager();
~SwDBManager();
2000-09-18 16:15:01 +00:00
/// MailMergeEvent source
const SwXMailMerge * GetMailMergeEvtSrc() const { return pMergeEvtSrc; }
void SetMailMergeEvtSrc( const SwXMailMerge *pSrc ) { pMergeEvtSrc = pSrc; }
inline bool IsMergeSilent() const { return bMergeSilent; }
inline void SetMergeSilent( bool bVal ) { bMergeSilent = bVal; }
/// Merging of data records into fields.
bool MergeNew( const SwMergeDescriptor& rMergeDesc );
bool Merge(SwWrtShell* pSh);
void MergeCancel();
/// Initialize data fields that lack name of database.
inline bool IsInitDBFields() const { return bInitDBFields; }
inline void SetInitDBFields(bool b) { bInitDBFields = b; }
2000-09-18 16:15:01 +00:00
/// Print / Save mail merge one by one or all together.
bool IsSingleJobs() const { return bSingleJobs; }
void SetSingleJobs(bool b) { bSingleJobs = b; }
2000-09-18 16:15:01 +00:00
/// Mailing: Set email data.
inline void SetEMailColumn(const OUString& sColName) { sEMailAddrFld = sColName; }
inline void SetSubject(const OUString& sSbj) { sSubject = sSbj; }
inline void SetAttachment(const OUString& sAtt) { sAttached = sAtt; }
2000-09-18 16:15:01 +00:00
/// Fill listbox with all table names of a database.
bool GetTableNames(ListBox* pListBox, const OUString& rDBName );
/// Fill listbox with all column names of a database table.
void GetColumnNames(ListBox* pListBox,
const OUString& rDBName, const OUString& rTableName, bool bAppend = false);
void GetColumnNames(ListBox* pListBox,
::css::uno::Reference< ::css::sdbc::XConnection> xConnection,
const OUString& rTableName, bool bAppend = false);
sal_uLong GetColumnFmt( ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource> xSource,
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> xConnection,
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> xColumn,
SvNumberFormatter* pNFmtr,
long nLanguage );
sal_uLong GetColumnFmt( const OUString& rDBName,
const OUString& rTableName,
const OUString& rColNm,
SvNumberFormatter* pNFmtr,
long nLanguage );
sal_Int32 GetColumnType( const OUString& rDBName,
const OUString& rTableName,
const OUString& rColNm );
2000-09-18 16:15:01 +00:00
inline bool IsInMerge() const { return bInMerge; }
2000-09-18 16:15:01 +00:00
void EndMerge();
2000-11-13 07:32:00 +00:00
void ExecuteFormLetter(SwWrtShell& rSh,
const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rProperties,
bool bWithDataSourceBrowser = false);
2000-11-13 07:32:00 +00:00
void InsertText(SwWrtShell& rSh,
const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rProperties);
/// check if a data source is open
bool IsDataSourceOpen(const OUString& rDataSource,
const OUString& rTableOrQuery, bool bMergeOnly);
2000-09-18 16:15:01 +00:00
/// open the source while fields are updated - for the calculator only!
bool OpenDataSource(const OUString& rDataSource, const OUString& rTableOrQuery,
sal_Int32 nCommandType = -1, bool bCreate = false);
sal_uInt32 GetSelectedRecordId(const OUString& rDataSource, const OUString& rTableOrQuery, sal_Int32 nCommandType = -1);
bool GetColumnCnt(const OUString& rSourceName, const OUString& rTableName,
const OUString& rColumnName, sal_uInt32 nAbsRecordId, long nLanguage,
OUString& rResult, double* pNumber);
/** create and store or find an already stored connection to a data source for use
in SwFldMgr and SwDBTreeList */
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>
RegisterConnection(OUString& rSource);
2000-09-18 16:15:01 +00:00
const SwDSParam* CreateDSData(const SwDBData& rData)
{return FindDSData(rData, true);}
2000-09-18 16:15:01 +00:00
const SwDSParamArr& GetDSParamArray() const {return aDataSourceParams;}
/// close all data sources - after fields were updated
void CloseAll(bool bIncludingMerge = true);
2000-09-18 16:15:01 +00:00
bool GetMergeColumnCnt(const OUString& rColumnName, sal_uInt16 nLanguage,
OUString &rResult, double *pNumber, sal_uInt32 *pFormat);
bool ToNextMergeRecord();
bool ToNextRecord(const OUString& rDataSource, const OUString& rTableOrQuery, sal_Int32 nCommandType = -1);
bool ExistsNextRecord()const;
2000-09-18 16:15:01 +00:00
sal_uInt32 GetSelectedRecordId();
bool ToRecordId(sal_Int32 nSet);
2000-09-18 16:15:01 +00:00
const SwDBData& GetAddressDBName();
2000-09-18 16:15:01 +00:00
static OUString GetDBField(
2000-09-18 16:15:01 +00:00
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xColumnProp,
const SwDBFormatData& rDBFormatData,
double *pNumber = NULL);
static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>
GetConnection(const OUString& rDataSource,
2000-09-18 16:15:01 +00:00
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource>& rxSource);
static ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier>
2000-10-31 14:26:08 +00:00
GetColumnSupplier(::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>,
const OUString& rTableOrQuery,
sal_uInt8 eTableOrQuery = SW_DB_SELECT_UNKNOWN);
2000-09-18 16:15:01 +00:00
static ::com::sun::star::uno::Sequence<OUString> GetExistingDatabaseNames();
2000-09-18 16:15:01 +00:00
/**
Loads a data source from file and registers it. Returns the registered name.
*/
static OUString LoadAndRegisterDataSource();
static SwDbtoolsClient& GetDbtoolsClient();
/// has to be called from _FinitUI()
static void RemoveDbtoolsClient();
/** try to get the data source from the given connection through the XChild interface.
If this is not possible, the data source will be created through its name.
@param _xConnection
The connection which should support the XChild interface. (not a must)
@param _sDataSourceName
The data source name will be used to create the data source when the connection can not be used for it.
@return
The data source.
*/
static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource>
getDataSourceAsParent(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,const OUString& _sDataSourceName);
/** creates a RowSet, which must be disposed after use.
@param _sDataSourceName
The data source name
@param _sCommand
The command.
@param _nCommandType
The type of the command.
@param _xConnection
The active connection which may be <NULL/>.
@return
The new created RowSet.
*/
static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>
createCursor( const OUString& _sDataSourceName,
const OUString& _sCommand,
sal_Int32 _nCommandType,
const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection
);
//merge into one document - returns the number of merged docs
sal_Int32 MergeDocuments( SwMailMergeConfigItem& rMMConfig, SwView& rSourceView );
2000-09-18 16:15:01 +00:00
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */