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