update credits
[LibreOffice.git] / sw / inc / dbmgr.hxx
blob978f779c248aba41d401edd5ffc55fa495f85e46
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef _SWDBMGR_HXX
20 #define _SWDBMGR_HXX
23 #include <tools/string.hxx>
24 #include <tools/link.hxx>
25 #include <com/sun/star/util/Date.hpp>
26 #include "swdllapi.h"
27 #include <swdbdata.hxx>
28 #include <com/sun/star/uno/Reference.h>
29 #include <com/sun/star/uno/Sequence.hxx>
30 #include <com/sun/star/lang/Locale.hpp>
31 #include <com/sun/star/beans/PropertyValue.hpp>
32 #include <boost/ptr_container/ptr_vector.hpp>
33 namespace com{namespace sun{namespace star{
34 namespace sdbc{
35 class XConnection;
36 class XStatement;
37 class XDataSource;
38 class XResultSet;
40 namespace beans{
42 class XPropertySet;
43 struct PropertyValue;
45 namespace sdbcx{
46 class XColumnsSupplier;
48 namespace util{
49 class XNumberFormatter;
51 namespace mail{
52 class XSmtpService;
54 }}}
55 namespace svx {
56 class ODataAccessDescriptor;
59 struct SwDBFormatData
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;
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;
76 // -----------------------------------------------------------------------
78 enum DBMgrOptions
80 DBMGR_MERGE, ///< Data records in fields.
81 DBMGR_INSERT, ///< Data records in text.
82 DBMGR_MERGE_MAILMERGE, ///< Print mail merge.
83 DBMGR_MERGE_MAILING, ///< Send mail merge as email.
84 DBMGR_MERGE_MAILFILES, ///< Save mail merg as files.
85 DBMGR_MERGE_DOCUMENTS, ///< Print merged documents.
86 DBMGR_MERGE_SINGLE_FILE ///< Save merge as single file.
89 // -----------------------------------------------------------------------
91 /*--------------------------------------------------------------------
92 Administration of (new) logical databases.
93 --------------------------------------------------------------------*/
94 #define SW_DB_SELECT_UNKNOWN 0
95 #define SW_DB_SELECT_TABLE 1
96 #define SW_DB_SELECT_QUERY 2
98 struct SwDSParam : public SwDBData
100 com::sun::star::util::Date aNullDate;
102 ::com::sun::star::uno::Reference<com::sun::star::util::XNumberFormatter> xFormatter;
103 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> xConnection;
104 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XStatement> xStatement;
105 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet> xResultSet;
106 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aSelection;
107 sal_Bool bScrollable;
108 sal_Bool bEndOfDB;
109 sal_Bool bAfterSelection;
110 long nSelectionIndex;
112 SwDSParam(const SwDBData& rData) :
113 SwDBData(rData),
114 bScrollable(sal_False),
115 bEndOfDB(sal_False),
116 bAfterSelection(sal_False),
117 nSelectionIndex(0)
120 SwDSParam(const SwDBData& rData,
121 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>& xResSet,
122 const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& rSelection) :
123 SwDBData(rData),
124 xResultSet(xResSet),
125 aSelection(rSelection),
126 bScrollable(sal_True),
127 bEndOfDB(sal_False),
128 bAfterSelection(sal_False),
129 nSelectionIndex(0)
132 void CheckEndOfDB()
134 if(bEndOfDB)
135 bAfterSelection = sal_True;
138 typedef boost::ptr_vector<SwDSParam> SwDSParamArr;
140 struct SwMergeDescriptor
142 sal_uInt16 nMergeType;
143 SwWrtShell& rSh;
144 const ::svx::ODataAccessDescriptor& rDescriptor;
145 String sSaveToFilter; ///< export filter to save resulting files
146 String sSaveToFilterOptions;
147 com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aSaveToFilterData;
149 String sSubject;
150 String sAddressFromColumn;
151 String sMailBody;
152 String sAttachmentName;
153 ::com::sun::star::uno::Sequence< OUString > aCopiesTo;
154 ::com::sun::star::uno::Sequence< OUString > aBlindCopiesTo;
156 ::com::sun::star::uno::Reference< com::sun::star::mail::XSmtpService > xSmtpServer;
158 sal_Bool bSendAsHTML;
159 sal_Bool bSendAsAttachment;
161 sal_Bool bPrintAsync;
162 sal_Bool bCreateSingleFile;
164 SwMailMergeConfigItem* pMailMergeConfigItem;
166 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aPrintOptions;
168 SwMergeDescriptor( sal_uInt16 nType, SwWrtShell& rShell, ::svx::ODataAccessDescriptor& rDesc ) :
169 nMergeType(nType),
170 rSh(rShell),
171 rDescriptor(rDesc),
172 bSendAsHTML( sal_True ),
173 bSendAsAttachment( sal_False ),
174 bPrintAsync( sal_False ),
175 bCreateSingleFile( sal_False ),
176 pMailMergeConfigItem(0)
181 struct SwNewDBMgr_Impl;
182 class SwConnectionDisposedListener_Impl;
183 class AbstractMailMergeDlg;
185 class SW_DLLPUBLIC SwNewDBMgr
187 friend class SwConnectionDisposedListener_Impl;
189 static SwDbtoolsClient* pDbtoolsClient;
191 String sEMailAddrFld; ///< Mailing: Column name of email address.
192 String sSubject; ///< Mailing: Subject
193 String sAttached; ///< Mailing: Attached Files.
194 sal_uInt16 nMergeType;
195 sal_Bool bInitDBFields : 1;
196 sal_Bool bSingleJobs : 1; ///< Printing job when called from Basic.
197 sal_Bool bCancel : 1; ///< Mail merge save canceled.
199 sal_Bool bInMerge : 1; ///< merge process active
200 sal_Bool bMergeSilent : 1; ///< suppress display of dialogs/boxes (used when called over API)
201 sal_Bool bMergeLock : 1; /**< prevent update of database fields while document is
202 actually printed at the ViewShell */
203 SwDSParamArr aDataSourceParams;
204 SwNewDBMgr_Impl* pImpl;
205 const SwXMailMerge* pMergeEvtSrc; ///< != 0 if mail merge events are to be send
207 SW_DLLPRIVATE SwDSParam* FindDSData(const SwDBData& rData, sal_Bool bCreate);
208 SW_DLLPRIVATE SwDSParam* FindDSConnection(const OUString& rSource, sal_Bool bCreate);
211 SW_DLLPRIVATE DECL_LINK( PrtCancelHdl, Button * );
213 /// Insert data record as text into document.
214 SW_DLLPRIVATE void ImportFromConnection( SwWrtShell* pSh);
216 /// Insert a single data record as text into document.
217 SW_DLLPRIVATE void ImportDBEntry(SwWrtShell* pSh);
219 /// merge to file _and_ merge to e-Mail
220 SW_DLLPRIVATE sal_Bool MergeMailFiles(SwWrtShell* pSh,
221 const SwMergeDescriptor& rMergeDescriptor );
222 SW_DLLPRIVATE sal_Bool ToNextRecord(SwDSParam* pParam);
224 public:
225 SwNewDBMgr();
226 ~SwNewDBMgr();
228 /// Current merge type. Cf. DBMgrOptions-enum.
229 inline sal_uInt16 GetMergeType() const { return nMergeType; }
230 inline void SetMergeType( sal_uInt16 nTyp ) { nMergeType = nTyp; }
232 /// MailMergeEvent source
233 const SwXMailMerge * GetMailMergeEvtSrc() const { return pMergeEvtSrc; }
234 void SetMailMergeEvtSrc( const SwXMailMerge *pSrc ) { pMergeEvtSrc = pSrc; }
236 inline sal_Bool IsMergeSilent() const { return bMergeSilent != 0; }
237 inline void SetMergeSilent( sal_Bool bVal ) { bMergeSilent = bVal; }
239 /// Merging of data records into fields.
240 sal_Bool MergeNew( const SwMergeDescriptor& rMergeDesc );
241 sal_Bool Merge(SwWrtShell* pSh);
243 /// Initialize data fields that lack name of database.
244 inline sal_Bool IsInitDBFields() const { return bInitDBFields; }
245 inline void SetInitDBFields(sal_Bool b) { bInitDBFields = b; }
247 /// Print / Save mail merge one by one or all together.
248 inline sal_Bool IsSingleJobs() const { return bSingleJobs; }
249 inline void SetSingleJobs(sal_Bool b) { bSingleJobs = b; }
251 /// Mailing: Set email data.
252 inline void SetEMailColumn(const String& sColName) { sEMailAddrFld = sColName; }
253 inline void SetSubject(const String& sSbj) { sSubject = sSbj; }
254 inline void SetAttachment(const String& sAtt) { sAttached = sAtt; }
257 /// Fill listbox with all table names of a database.
258 sal_Bool GetTableNames(ListBox* pListBox, const String& rDBName );
260 /// Fill listbox with all column names of a database table.
261 sal_Bool GetColumnNames(ListBox* pListBox,
262 const String& rDBName, const String& rTableName, sal_Bool bAppend = sal_False);
263 sal_Bool GetColumnNames(ListBox* pListBox,
264 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> xConnection,
265 const String& rTableName, sal_Bool bAppend = sal_False);
267 sal_uLong GetColumnFmt( ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource> xSource,
268 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection> xConnection,
269 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> xColumn,
270 SvNumberFormatter* pNFmtr,
271 long nLanguage );
273 sal_uLong GetColumnFmt( const String& rDBName,
274 const String& rTableName,
275 const String& rColNm,
276 SvNumberFormatter* pNFmtr,
277 long nLanguage );
278 sal_Int32 GetColumnType( const String& rDBName,
279 const String& rTableName,
280 const String& rColNm );
282 inline sal_Bool IsInMerge() const { return bInMerge; }
283 void EndMerge();
285 void ExecuteFormLetter(SwWrtShell& rSh,
286 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rProperties,
287 sal_Bool bWithDataSourceBrowser = sal_False);
289 void InsertText(SwWrtShell& rSh,
290 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue>& rProperties);
292 /// check if a data source is open
293 sal_Bool IsDataSourceOpen(const String& rDataSource,
294 const String& rTableOrQuery, sal_Bool bMergeOnly);
296 /// open the source while fields are updated - for the calculator only!
297 sal_Bool OpenDataSource(const String& rDataSource, const String& rTableOrQuery,
298 sal_Int32 nCommandType = -1, bool bCreate = false);
299 sal_uInt32 GetSelectedRecordId(const String& rDataSource, const String& rTableOrQuery, sal_Int32 nCommandType = -1);
300 sal_Bool GetColumnCnt(const String& rSourceName, const String& rTableName,
301 const String& rColumnName, sal_uInt32 nAbsRecordId, long nLanguage,
302 OUString& rResult, double* pNumber);
303 /** create and store or find an already stored connection to a data source for use
304 in SwFldMgr and SwDBTreeList */
305 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>
306 RegisterConnection(OUString& rSource);
308 const SwDSParam* CreateDSData(const SwDBData& rData)
309 {return FindDSData(rData, sal_True);}
310 const SwDSParamArr& GetDSParamArray() const {return aDataSourceParams;}
313 /// close all data sources - after fields were updated
314 void CloseAll(sal_Bool bIncludingMerge = sal_True);
316 sal_Bool GetMergeColumnCnt(const String& rColumnName, sal_uInt16 nLanguage,
317 OUString &rResult, double *pNumber, sal_uInt32 *pFormat);
318 sal_Bool ToNextMergeRecord();
319 sal_Bool ToNextRecord(const String& rDataSource, const String& rTableOrQuery, sal_Int32 nCommandType = -1);
321 sal_Bool ExistsNextRecord()const;
322 sal_uInt32 GetSelectedRecordId();
323 sal_Bool ToRecordId(sal_Int32 nSet);
325 const SwDBData& GetAddressDBName();
327 static String GetDBField(
328 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xColumnProp,
329 const SwDBFormatData& rDBFormatData,
330 double *pNumber = NULL);
332 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>
333 GetConnection(const String& rDataSource,
334 ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource>& rxSource);
336 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbcx::XColumnsSupplier>
337 GetColumnSupplier(::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>,
338 const String& rTableOrQuery,
339 sal_uInt8 eTableOrQuery = SW_DB_SELECT_UNKNOWN);
341 static ::com::sun::star::uno::Sequence<OUString> GetExistingDatabaseNames();
344 Loads a data source from file and registers it. Returns the registered name.
346 static String LoadAndRegisterDataSource();
348 static SwDbtoolsClient& GetDbtoolsClient();
349 /// has to be called from _FinitUI()
350 static void RemoveDbtoolsClient();
352 /** try to get the data source from the given connection through the XChild interface.
353 If this is not possible, the data source will be created through its name.
354 @param _xConnection
355 The connection which should support the XChild interface. (not a must)
356 @param _sDataSourceName
357 The data source name will be used to create the data source when the connection can not be used for it.
358 @return
359 The data source.
361 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XDataSource>
362 getDataSourceAsParent(const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection,const OUString& _sDataSourceName);
364 /** creates a RowSet, which must be disposed after use.
365 @param _sDataSourceName
366 The data source name
367 @param _sCommand
368 The command.
369 @param _nCommandType
370 The type of the command.
371 @param _xConnection
372 The active connection which may be <NULL/>.
373 @return
374 The new created RowSet.
377 static ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet>
378 createCursor( const OUString& _sDataSourceName,
379 const OUString& _sCommand,
380 sal_Int32 _nCommandType,
381 const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection>& _xConnection
383 //merge into one document - returns the number of merged docs
384 sal_Int32 MergeDocuments( SwMailMergeConfigItem& rMMConfig, SwView& rSourceView );
387 #endif
389 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */