LibreOffice Module sw (master)  1
dbmgr.hxx
Go to the documentation of this file.
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/solar.h>
24 #include <tools/long.hxx>
25 #include <i18nlangtag/lang.h>
26 #include <com/sun/star/util/Date.hpp>
27 #include "swdllapi.h"
28 #include "swdbdata.hxx"
29 #include <com/sun/star/uno/Reference.h>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <com/sun/star/lang/Locale.hpp>
32 #include <com/sun/star/beans/PropertyValue.hpp>
33 
34 #include <memory>
35 #include <vector>
36 
37 namespace com::sun::star{
38  namespace sdbc{
39  class XConnection;
40  class XStatement;
41  class XDataSource;
42  class XResultSet;
43  }
44  namespace beans{
45 
46  class XPropertySet;
47  }
48  namespace sdbcx{
49  class XColumnsSupplier;
50  }
51  namespace util{
52  class XNumberFormatter;
53  }
54  namespace mail{
55  class XSmtpService;
56  }
57  namespace embed { class XStorage; }
58  namespace frame { class XStorable; }
59 }
60 namespace svx {
61  class ODataAccessDescriptor;
62 }
63 
65 {
66  css::util::Date aNullDate;
67  css::uno::Reference< css::util::XNumberFormatter> xFormatter;
68  css::lang::Locale aLocale;
69 };
70 
71 namespace weld {
72  class ComboBox;
73  class Window;
74 }
75 
76 class SwView;
77 class SwWrtShell;
78 class ListBox;
79 class SvNumberFormatter;
80 class SwXMailMerge;
82 class SwCalc;
83 class INetURLObject;
84 class SwDocShell;
85 
87 {
93 };
94 
95 // Administration of (new) logical databases.
96 enum class SwDBSelect
97 {
99 };
100 
101 struct SwDSParam : public SwDBData
102 {
103  css::util::Date aNullDate;
104 
105  css::uno::Reference<css::util::XNumberFormatter> xFormatter;
106  css::uno::Reference< css::sdbc::XConnection> xConnection;
107  css::uno::Reference< css::sdbc::XStatement> xStatement;
108  css::uno::Reference< css::sdbc::XResultSet> xResultSet;
109  css::uno::Sequence< css::uno::Any > aSelection;
111  bool bEndOfDB;
113 
114  SwDSParam(const SwDBData& rData) :
115  SwDBData(rData),
116  bScrollable(false),
117  bEndOfDB(false),
118  nSelectionIndex(0)
119  {}
120 
121  SwDSParam(const SwDBData& rData,
122  const css::uno::Reference< css::sdbc::XResultSet>& xResSet,
123  const css::uno::Sequence< css::uno::Any >& rSelection) :
124  SwDBData(rData),
125  xResultSet(xResSet),
126  aSelection(rSelection),
127  bScrollable(true),
128  bEndOfDB(false),
129  nSelectionIndex(0)
130  {}
131 
132  bool HasValidRecord() const
133  { return( !bEndOfDB && xResultSet.is() ); }
134 };
135 
136 typedef std::vector<std::unique_ptr<SwDSParam>> SwDSParams_t;
137 
139 {
143 
151 
156  OUString sSaveToFilter;
158  css::uno::Sequence< css::beans::PropertyValue > aSaveToFilterData;
173  OUString sPrefix;
188  OUString sSubject;
189  OUString sMailBody;
190  OUString sAttachmentName;
191  css::uno::Sequence< OUString > aCopiesTo;
192  css::uno::Sequence< OUString > aBlindCopiesTo;
193  css::uno::Reference< css::mail::XSmtpService > xSmtpServer;
204  OUString sDBcolumn;
205 
209 
216  css::uno::Sequence< css::beans::PropertyValue > aPrintOptions;
220 
222  SwWrtShell& rShell,
223  const svx::ODataAccessDescriptor& rDesc ) :
224  nMergeType(nType),
225  rSh(rShell),
226  rDescriptor(rDesc),
227  bCreateSingleFile( false ),
228  bPrefixIsFilename( false ),
229  bSendAsHTML( true ),
230  bSendAsAttachment( false ),
231  pMailMergeConfigItem( nullptr )
232  {
233  if( nType == DBMGR_MERGE_SHELL || nType == DBMGR_MERGE_PRINTER )
234  bCreateSingleFile = true;
235  }
236 };
237 
238 class SwDoc;
239 
241 {
242  struct SwDBManager_Impl;
243  class SAL_DLLPRIVATE ConnectionDisposedListener_Impl;
245 
246  enum class MergeStatus
247  {
248  Ok = 0, Cancel, Error
249  };
250 
252  bool m_bInitDBFields : 1;
253  bool m_bInMerge : 1;
254  bool m_bMergeSilent : 1;
256  std::unique_ptr<SwDBManager_Impl> m_pImpl;
258  OUString m_sEmbeddedName;
260 
262  static std::vector<std::pair<SwDocShell*, OUString>> s_aUncommittedRegistrations;
263 
265  std::vector<OUString> m_aNotUsedConnections;
266 
268  void SetAsUsed(const OUString& rName);
269 
272 
273  SAL_DLLPRIVATE SwDSParam* FindDSData(const SwDBData& rData, bool bCreate);
274  SAL_DLLPRIVATE SwDSParam* FindDSConnection(const OUString& rSource, bool bCreate);
275 
277  SAL_DLLPRIVATE void ImportFromConnection( SwWrtShell* pSh);
278 
280  SAL_DLLPRIVATE void ImportDBEntry(SwWrtShell* pSh);
281 
283  SAL_DLLPRIVATE bool MergeMailFiles( SwWrtShell* pSh,
284  const SwMergeDescriptor& rMergeDescriptor );
285 
286  SAL_DLLPRIVATE bool ToNextMergeRecord();
287  SAL_DLLPRIVATE bool IsValidMergeRecord() const;
288  SAL_DLLPRIVATE void ImplDestroy();
289 
290  SwDBManager(SwDBManager const&) = delete;
291  SwDBManager& operator=(SwDBManager const&) = delete;
292 
293 public:
294  SwDBManager(SwDoc* pDoc);
295  ~SwDBManager();
296 
298  const SwXMailMerge * GetMailMergeEvtSrc() const { return m_pMergeEvtSrc; }
299  void SetMailMergeEvtSrc( const SwXMailMerge *pSrc ) { m_pMergeEvtSrc = pSrc; }
300 
301  bool IsMergeSilent() const { return m_bMergeSilent; }
302  void SetMergeSilent( bool bVal ) { m_bMergeSilent = bVal; }
303 
305  bool Merge( const SwMergeDescriptor& rMergeDesc );
306  void MergeCancel();
307 
308  bool IsMergeOk() const { return MergeStatus::Ok == m_aMergeStatus; }
309  bool IsMergeError() const { return MergeStatus::Error <= m_aMergeStatus; }
310 
311  static std::shared_ptr<SwMailMergeConfigItem> PerformMailMerge(SwView const * pView);
312 
314  bool IsInitDBFields() const { return m_bInitDBFields; }
315  void SetInitDBFields(bool b) { m_bInitDBFields = b; }
316 
318  bool GetTableNames(weld::ComboBox& rBox, const OUString& rDBName);
319 
321  void GetColumnNames(weld::ComboBox& rBox,
322  const OUString& rDBName, const OUString& rTableName);
323  static void GetColumnNames(weld::ComboBox& rBox,
324  css::uno::Reference< css::sdbc::XConnection> const & xConnection,
325  const OUString& rTableName);
326 
327  static sal_uLong GetColumnFormat( css::uno::Reference< css::sdbc::XDataSource> const & xSource,
328  css::uno::Reference< css::sdbc::XConnection> const & xConnection,
329  css::uno::Reference< css::beans::XPropertySet> const & xColumn,
330  SvNumberFormatter* pNFormatr,
331  LanguageType nLanguage );
332 
333  sal_uLong GetColumnFormat( const OUString& rDBName,
334  const OUString& rTableName,
335  const OUString& rColNm,
336  SvNumberFormatter* pNFormatr,
337  LanguageType nLanguage );
338  sal_Int32 GetColumnType( const OUString& rDBName,
339  const OUString& rTableName,
340  const OUString& rColNm );
341 
342  bool IsInMerge() const { return m_bInMerge; }
343 
344  void ExecuteFormLetter(SwWrtShell& rSh,
345  const css::uno::Sequence< css::beans::PropertyValue>& rProperties);
346 
347  static void InsertText(SwWrtShell& rSh,
348  const css::uno::Sequence< css::beans::PropertyValue>& rProperties);
349 
351  bool IsDataSourceOpen(const OUString& rDataSource,
352  const OUString& rTableOrQuery, bool bMergeShell);
353 
355  bool OpenDataSource(const OUString& rDataSource, const OUString& rTableOrQuery);
356  sal_uInt32 GetSelectedRecordId(const OUString& rDataSource, const OUString& rTableOrQuery, sal_Int32 nCommandType = -1);
357  bool GetColumnCnt(const OUString& rSourceName, const OUString& rTableName,
358  const OUString& rColumnName, sal_uInt32 nAbsRecordId, LanguageType nLanguage,
359  OUString& rResult, double* pNumber);
362  css::uno::Reference< css::sdbc::XConnection> const &
363  RegisterConnection(OUString const& rSource);
364 
365  void CreateDSData(const SwDBData& rData)
366  { FindDSData(rData, true); }
367  const SwDSParams_t& GetDSParamArray() const { return m_DataSourceParams; }
368 
370  void CloseAll(bool bIncludingMerge = true);
371 
372  bool GetMergeColumnCnt(const OUString& rColumnName, LanguageType nLanguage,
373  OUString &rResult, double *pNumber);
374  bool FillCalcWithMergeData(SvNumberFormatter *pDocFormatter,
375  LanguageType nLanguage, SwCalc &aCalc);
376  void ToNextRecord(const OUString& rDataSource, const OUString& rTableOrQuery);
377 
378  sal_uInt32 GetSelectedRecordId();
379  bool ToRecordId(sal_Int32 nSet);
380 
381  static const SwDBData& GetAddressDBName();
382 
383  static OUString GetDBField(
384  css::uno::Reference< css::beans::XPropertySet > const & xColumnProp,
385  const SwDBFormatData& rDBFormatData,
386  double *pNumber = nullptr);
387 
388  static css::uno::Reference< css::sdbc::XConnection>
389  GetConnection(const OUString& rDataSource,
390  css::uno::Reference< css::sdbc::XDataSource>& rxSource,
391  const SwView* pView);
392 
393  static css::uno::Reference< css::sdbcx::XColumnsSupplier>
394  GetColumnSupplier(css::uno::Reference< css::sdbc::XConnection> const & xConnection,
395  const OUString& rTableOrQuery,
396  SwDBSelect eTableOrQuery = SwDBSelect::UNKNOWN);
397 
398  static css::uno::Sequence<OUString> GetExistingDatabaseNames();
399 
407  static OUString LoadAndRegisterDataSource(weld::Window* pParent, SwDocShell* pDocShell = nullptr);
408 
415  static OUString LoadAndRegisterDataSource(const OUString& rURI, const OUString *pDestDir);
416 
418  void LoadAndRegisterEmbeddedDataSource(const SwDBData& rData, const SwDocShell& rDocShell);
419 
421  static void RevokeDataSource(const OUString& rName);
422 
432  static css::uno::Reference< css::sdbc::XDataSource>
433  getDataSourceAsParent(const css::uno::Reference< css::sdbc::XConnection>& _xConnection,const OUString& _sDataSourceName);
434 
448  static css::uno::Reference< css::sdbc::XResultSet>
449  createCursor(const OUString& _sDataSourceName,
450  const OUString& _sCommand,
451  sal_Int32 _nCommandType,
452  const css::uno::Reference< css::sdbc::XConnection>& _xConnection,
453  const SwView* pView);
454 
455  void setEmbeddedName(const OUString& rEmbeddedName, SwDocShell& rDocShell);
456  const OUString& getEmbeddedName() const;
457 
458  // rOwnURL should be taken using INetURLObject::GetMainURL(INetURLObject::DecodeMechanism::NONE)
459  static void StoreEmbeddedDataSource(const css::uno::Reference<css::frame::XStorable>& xStorable,
460  const css::uno::Reference<css::embed::XStorage>& xStorage,
461  const OUString& rStreamRelPath,
462  const OUString& rOwnURL, bool bCopyTo = false);
463 
464  SwDoc* getDoc() const;
466  void releaseRevokeListener();
467 
469  void RevokeLastRegistrations();
470 
472  void CommitLastRegistrations();
473 
475  void RevokeNotUsedConnections();
476 };
477 
478 namespace sw
479 {
480 enum class DBConnURIType
481 {
482  UNKNOWN = 0,
483  ODB,
484  CALC,
485  DBASE,
486  FLAT,
487  MSJET,
488  MSACE,
489  WRITER
490 };
491 
493 }
494 
495 #endif
496 
497 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::sdbc::XResultSet > xResultSet
Definition: dbmgr.hxx:108
bool bCreateSingleFile
Create a single or multiple results.
Definition: dbmgr.hxx:150
Definition: calc.hxx:192
exports com.sun.star. mail
const SwXMailMerge * GetMailMergeEvtSrc() const
MailMergeEvent source.
Definition: dbmgr.hxx:298
exports com.sun.star. sdbc
void SetMailMergeEvtSrc(const SwXMailMerge *pSrc)
Definition: dbmgr.hxx:299
css::util::Date aNullDate
Definition: dbmgr.hxx:66
SwDSParams_t m_DataSourceParams
Definition: dbmgr.hxx:255
SwMailMergeConfigItem * pMailMergeConfigItem
Definition: dbmgr.hxx:219
bool bEndOfDB
Definition: dbmgr.hxx:111
sal_uIntPtr sal_uLong
long Long
css::uno::Reference< css::mail::XSmtpService > xSmtpServer
Definition: dbmgr.hxx:193
exports com.sun.star. embed
Definition: doc.hxx:188
bool HasValidRecord() const
Definition: dbmgr.hxx:132
css::util::Date aNullDate
Definition: dbmgr.hxx:103
bool bSendAsAttachment
Definition: dbmgr.hxx:195
Data records in fields.
Definition: dbmgr.hxx:88
Dialog to specify the properties of date form field.
bool IsInMerge() const
Definition: dbmgr.hxx:342
css::uno::Reference< css::sdbc::XConnection > xConnection
Definition: dbmgr.hxx:106
css::uno::Sequence< css::beans::PropertyValue > aSaveToFilterData
Definition: dbmgr.hxx:158
bool IsMergeError() const
Definition: dbmgr.hxx:309
SwDBSelect
Definition: dbmgr.hxx:96
Used by the UI to modify the document model.
Definition: wrtsh.hxx:93
SwDSParam(const SwDBData &rData, const css::uno::Reference< css::sdbc::XResultSet > &xResSet, const css::uno::Sequence< css::uno::Any > &rSelection)
Definition: dbmgr.hxx:121
bool IsInitDBFields() const
Initialize data fields that lack name of database.
Definition: dbmgr.hxx:314
exports com.sun.star. frame
Print mail merge.
Definition: dbmgr.hxx:89
DBManagerOptions
Definition: dbmgr.hxx:86
Send mail merge as email.
Definition: dbmgr.hxx:90
OUString sSaveToFilter
Definition: dbmgr.hxx:156
css::lang::Locale aLocale
Definition: dbmgr.hxx:68
Create merge doc and keep the doc shell.
Definition: dbmgr.hxx:92
OUString sMailBody
Definition: dbmgr.hxx:189
SwWrtShell & rSh
Definition: dbmgr.hxx:141
SwDoc * m_pDoc
The document that owns this manager.
Definition: dbmgr.hxx:271
bool bPrefixIsFilename
Use the sPrefix as the target filename also overwriting an existing target file.
Definition: dbmgr.hxx:181
OUString sPrefix
Basename incl.
Definition: dbmgr.hxx:173
OUString sSaveToFilterOptions
Definition: dbmgr.hxx:157
OUString sSubject
Definition: dbmgr.hxx:188
bool bScrollable
Definition: dbmgr.hxx:110
class SAL_NO_VTABLE XPropertySet
void SetMergeSilent(bool bVal)
Definition: dbmgr.hxx:302
OUString sAttachmentName
Definition: dbmgr.hxx:190
SwMergeDescriptor(const DBManagerOptions nType, SwWrtShell &rShell, const svx::ODataAccessDescriptor &rDesc)
Definition: dbmgr.hxx:221
std::unique_ptr< SwDBManager_Impl > m_pImpl
Definition: dbmgr.hxx:256
Error
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
tools::Long nSelectionIndex
Definition: dbmgr.hxx:112
exports com.sun.star. sdbcx
std::vector< OUString > m_aNotUsedConnections
Not used connections.
Definition: dbmgr.hxx:265
exports com.sun.star. beans
static std::vector< std::pair< SwDocShell *, OUString > > s_aUncommittedRegistrations
Store last registrations to revoke or commit.
Definition: dbmgr.hxx:262
const DBManagerOptions nMergeType
Definition: dbmgr.hxx:140
std::vector< std::unique_ptr< SwDSParam > > SwDSParams_t
Definition: dbmgr.hxx:136
css::uno::Sequence< OUString > aCopiesTo
Definition: dbmgr.hxx:191
css::uno::Sequence< css::beans::PropertyValue > aPrintOptions
Definition: dbmgr.hxx:216
css::uno::Reference< css::util::XNumberFormatter > xFormatter
Definition: dbmgr.hxx:105
Save mail merge as files.
Definition: dbmgr.hxx:91
const svx::ODataAccessDescriptor & rDescriptor
Definition: dbmgr.hxx:142
DBConnURIType GetDBunoType(const INetURLObject &rURL)
Definition: dbmgr.cxx:2519
OUString sDBPasswordColumn
DB column to fetch password.
Definition: dbmgr.hxx:208
void SetInitDBFields(bool b)
Definition: dbmgr.hxx:315
bool IsMergeSilent() const
Definition: dbmgr.hxx:301
const SwXMailMerge * m_pMergeEvtSrc
!= 0 if mail merge events are to be send
Definition: dbmgr.hxx:257
css::uno::Sequence< OUString > aBlindCopiesTo
Definition: dbmgr.hxx:192
css::uno::Reference< css::util::XNumberFormatter > xFormatter
Definition: dbmgr.hxx:67
OUString sDBcolumn
DB column to fetch EMail of Filename from.
Definition: dbmgr.hxx:204
DBConnURIType
Definition: dbmgr.hxx:480
css::uno::Sequence< css::uno::Any > aSelection
Definition: dbmgr.hxx:109
SwDSParam(const SwDBData &rData)
Definition: dbmgr.hxx:114
css::uno::Reference< css::sdbc::XStatement > xStatement
Definition: dbmgr.hxx:107
MergeStatus m_aMergeStatus
current / last merge status
Definition: dbmgr.hxx:251
const SwDSParams_t & GetDSParamArray() const
Definition: dbmgr.hxx:367
void CreateDSData(const SwDBData &rData)
Definition: dbmgr.hxx:365
bool IsMergeOk() const
Definition: dbmgr.hxx:308
Definition: view.hxx:144