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