tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / inc / dataprovider.hxx
blob680bf3819390e19c6e1c8f61fa2159a10c7a8675
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 #pragma once
12 #include <memory>
13 #include <string_view>
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 <atomic>
23 #include <vector>
24 //#include <map>
26 #include <orcus/csv_parser.hpp>
28 class SvStream;
29 class ScDBData;
31 namespace sc {
33 class DataTransformation;
34 class ExternalDataSource;
36 class CSVFetchThread : public salhelper::Thread
38 ScDocument& mrDocument;
39 OUString maURL;
41 std::atomic<bool> mbTerminate;
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, OUString , std::function<void()> aImportFinishedHdl,
52 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(OUString aDBName, 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(std::u16string_view rProvider);
140 public:
142 static std::shared_ptr<DataProvider> getDataProvider(ScDocument* pDoc, sc::ExternalDataSource& rDataSource);
144 static std::vector<OUString> getDataProviders();
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */