LibreOffice Module sc (master)  1
dataprovider.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 
10 #ifndef INCLUDED_SC_SOURCE_UI_INC_DATAPROVIDER_HXX
11 #define INCLUDED_SC_SOURCE_UI_INC_DATAPROVIDER_HXX
12 
13 #include <memory>
14 #include <salhelper/thread.hxx>
15 #include <rtl/ustring.hxx>
16 #include <rtl/ref.hxx>
17 #include <osl/mutex.hxx>
18 #include <document.hxx>
19 
20 #include <rtl/strbuf.hxx>
21 
22 #include <vector>
23 #include <map>
24 
25 #include <orcus/csv_parser.hpp>
26 
27 class SvStream;
28 class ScDBData;
29 
30 namespace sc {
31 
32 class DataTransformation;
33 class ExternalDataSource;
34 
36 {
38  OUString maURL;
39 
41  osl::Mutex maMtxTerminate;
42 
43  orcus::csv::parser_config maConfig;
44 
45  std::vector<std::shared_ptr<sc::DataTransformation>> maDataTransformations;
46 
47  std::function<void()> maImportFinishedHdl;
48 
49 
50 public:
51  CSVFetchThread(ScDocument& rDoc, const OUString&, std::function<void()> aImportFinishedHdl,
52  const std::vector<std::shared_ptr<sc::DataTransformation>>& mrDataTransformations);
53  virtual ~CSVFetchThread() override;
54 
55  void RequestTerminate();
56  bool IsRequestedTerminate();
57  void Terminate();
58  void EndThread();
59 
60  virtual void execute() override;
61 };
62 
68 {
69 protected:
75 
76 public:
78 
79  virtual ~DataProvider();
80 
81  virtual void Import() = 0;
82 
83  virtual const OUString& GetURL() const = 0;
84 
85  static std::unique_ptr<SvStream> FetchStreamFromURL(const OUString&, OStringBuffer& rBuffer);
86 
87  void setDeterministic();
88 };
89 
91 {
95 
96  void Refresh();
97 
98 public:
100  virtual ~CSVDataProvider() override;
101 
102  virtual void Import() override;
103 
104  const OUString& GetURL() const override;
105  void ImportFinished();
106 };
107 
119 {
120  OUString maDBName;
122 
123 public:
124  ScDBDataManager(const OUString& rDBName, ScDocument* pDoc);
126 
127  void SetDatabase(const OUString& rDBName);
128 
129  ScDBData* getDBData();
130 
131  void WriteToDoc(ScDocument& rDoc);
132 };
133 
135 {
136 private:
137 
138  static bool isInternalDataProvider(const OUString& rProvider);
139 
140 public:
141 
142  static std::shared_ptr<DataProvider> getDataProvider(ScDocument* pDoc, sc::ExternalDataSource& rDataSource);
143 
144  static std::vector<OUString> getDataProviders();
145 };
146 
147 }
148 
149 #endif
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScDocument & mrDocument
static std::vector< OUString > getDataProviders()
sc::ExternalDataSource & mrDataSource
std::function< void()> maImportFinishedHdl
CSVFetchThread(ScDocument &rDoc, const OUString &, std::function< void()> aImportFinishedHdl, const std::vector< std::shared_ptr< sc::DataTransformation >> &mrDataTransformations)
Abstract class for all data provider.
orcus::csv::parser_config maConfig
const OUString & GetURL() const override
ScDBDataManager(const OUString &rDBName, ScDocument *pDoc)
bool mbDeterministic
If true make the threaded import deterministic for the tests.
virtual void execute() override
virtual ~CSVDataProvider() override
This class handles the copying of the data from the imported temporary document to the actual documen...
static std::unique_ptr< SvStream > FetchStreamFromURL(const OUString &, OStringBuffer &rBuffer)
void WriteToDoc(ScDocument &rDoc)
static std::shared_ptr< DataProvider > getDataProvider(ScDocument *pDoc, sc::ExternalDataSource &rDataSource)
std::vector< std::shared_ptr< sc::DataTransformation > > maDataTransformations
std::unique_ptr< ScDocument, o3tl::default_delete< ScDocument > > ScDocumentUniquePtr
Definition: document.hxx:2613
void SetDatabase(const OUString &rDBName)
CSVDataProvider(ScDocument *pDoc, sc::ExternalDataSource &rDataSource)
rtl::Reference< CSVFetchThread > mxCSVFetchThread
virtual void Import()=0
osl::Mutex maMtxTerminate
DataProvider(sc::ExternalDataSource &rDataSource)
ScDocument * mpDocument
virtual ~DataProvider()
virtual void Import() override
virtual ~CSVFetchThread() override
static bool isInternalDataProvider(const OUString &rProvider)
ScDBData * getDBData()
ScDocumentUniquePtr mpDoc
virtual const OUString & GetURL() const =0