nss: upgrade to release 3.73
[LibreOffice.git] / sc / source / ui / inc / dataprovider.hxx
bloba7a5f9b10d4295b2e8bd5be1a4aebc408ff30c83
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/.
8 */
10 #ifndef INCLUDED_SC_SOURCE_UI_INC_DATAPROVIDER_HXX
11 #define INCLUDED_SC_SOURCE_UI_INC_DATAPROVIDER_HXX
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>
20 #include <rtl/strbuf.hxx>
22 #include <vector>
23 #include <map>
25 #include <orcus/csv_parser.hpp>
27 class SvStream;
28 class ScDBData;
30 namespace sc {
32 class DataTransformation;
33 class ExternalDataSource;
35 class CSVFetchThread : public salhelper::Thread
37 ScDocument& mrDocument;
38 OUString maURL;
40 bool mbTerminate;
41 osl::Mutex maMtxTerminate;
43 orcus::csv::parser_config maConfig;
45 std::vector<std::shared_ptr<sc::DataTransformation>> maDataTransformations;
47 std::function<void()> maImportFinishedHdl;
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;
55 void RequestTerminate();
56 bool IsRequestedTerminate();
57 void Terminate();
58 void EndThread();
60 virtual void execute() override;
63 /**
64 * Abstract class for all data provider.
67 class DataProvider
69 protected:
70 /**
71 * If true make the threaded import deterministic for the tests.
73 bool mbDeterministic;
74 sc::ExternalDataSource& mrDataSource;
76 public:
77 DataProvider(sc::ExternalDataSource& rDataSource);
79 virtual ~DataProvider();
81 virtual void Import() = 0;
83 virtual const OUString& GetURL() const = 0;
85 static std::unique_ptr<SvStream> FetchStreamFromURL(const OUString&, OStringBuffer& rBuffer);
87 void setDeterministic();
90 class CSVDataProvider : public DataProvider
92 rtl::Reference<CSVFetchThread> mxCSVFetchThread;
93 ScDocument* mpDocument;
94 ScDocumentUniquePtr mpDoc;
96 void Refresh();
98 public:
99 CSVDataProvider (ScDocument* pDoc, sc::ExternalDataSource& rDataSource);
100 virtual ~CSVDataProvider() override;
102 virtual void Import() override;
104 const OUString& GetURL() const override;
105 void ImportFinished();
109 * This class handles the copying of the data from the imported
110 * temporary document to the actual document. Additionally, in the future
111 * we may decide to store data transformations in this class.
113 * In addition this class also handles how to deal with excess data by for example extending the ScDBData or by only showing the first or last entries.
115 * TODO: move the DataProvider::WriteToDoc here
118 class ScDBDataManager
120 OUString maDBName;
121 ScDocument* mpDoc;
123 public:
124 ScDBDataManager(const OUString& rDBName, ScDocument* pDoc);
125 ~ScDBDataManager();
127 void SetDatabase(const OUString& rDBName);
129 ScDBData* getDBData();
131 void WriteToDoc(ScDocument& rDoc);
134 class DataProviderFactory
136 private:
138 static bool isInternalDataProvider(const OUString& rProvider);
140 public:
142 static std::shared_ptr<DataProvider> getDataProvider(ScDocument* pDoc, sc::ExternalDataSource& rDataSource);
144 static std::vector<OUString> getDataProviders();
149 #endif
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */