diff options
author | Jaskaran Singh <jvsg1303@gmail.com> | 2016-12-08 13:21:34 +0530 |
---|---|---|
committer | Jaskaran singh <jvsg1303@gmail.com> | 2016-12-11 15:12:19 +0000 |
commit | 777c22bca071942a14f2db4b38d711a5a00df1b3 (patch) | |
tree | 84c6efd7b656cac15769d2b839f22818ef3f5acb /sc | |
parent | cc6da0af33380eb598ecfd47b4c4bde8db764289 (diff) |
Implement CSVDataProvider and perform some cleanup on it
Change-Id: Ic409bd4977fdf610294bd13b7ea83ef9a4c48667
Reviewed-on: https://gerrit.libreoffice.org/31750
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Jaskaran singh <jvsg1303@gmail.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/docshell/dataprovider.cxx | 58 | ||||
-rw-r--r-- | sc/source/ui/inc/dataprovider.hxx | 28 |
2 files changed, 71 insertions, 15 deletions
diff --git a/sc/source/ui/docshell/dataprovider.cxx b/sc/source/ui/docshell/dataprovider.cxx index 80a6b2b19774..7df702ca4d29 100644 --- a/sc/source/ui/docshell/dataprovider.cxx +++ b/sc/source/ui/docshell/dataprovider.cxx @@ -17,6 +17,10 @@ namespace sc { +DataProvider::~DataProvider() +{ +} + Cell::Cell() : mfValue(0.0), mbValue(true) {} Cell::Cell(const Cell& r) : mbValue(r.mbValue) @@ -68,9 +72,10 @@ public: } }; -CSVFetchThread::CSVFetchThread(SvStream *pData): +CSVFetchThread::CSVFetchThread(SvStream *pData, size_t nColCount): Thread("ReaderThread"), mpStream(pData), + mnColCount(nColCount), mbTerminate(false) { maConfig.delimiters.push_back(','); @@ -117,6 +122,57 @@ void CSVFetchThread::execute() RequestTerminate(); } +CSVDataProvider::CSVDataProvider(const OUString& rURL, const ScRange& rRange): + maURL(rURL), + mrRange(rRange), + mbImportUnderway(false) +{ +} + +CSVDataProvider::~CSVDataProvider() +{ + if(mbImportUnderway) + StopImport(); + + if (mxCSVFetchThread.is()) + { + mxCSVFetchThread->EndThread(); + mxCSVFetchThread->join(); + } +} + +void CSVDataProvider::StartImport() +{ + if (mbImportUnderway) + return; + + if (!mxCSVFetchThread.is()) + { + SvStream *pStream = nullptr; + pStream = new SvFileStream(maURL, StreamMode::READ); + mxCSVFetchThread = new CSVFetchThread(pStream, mrRange.aEnd.Col() - mrRange.aStart.Col() + 1); + mxCSVFetchThread->launch(); + } + mbImportUnderway = true; + + maImportTimer.Start(); +} + +void CSVDataProvider::StopImport() +{ + if (!mbImportUnderway) + return; + + mbImportUnderway = false; + Refresh(); + maImportTimer.Stop(); +} + +void CSVDataProvider::Refresh() +{ + +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/dataprovider.hxx b/sc/source/ui/inc/dataprovider.hxx index d0101dc37e51..1a01512394a4 100644 --- a/sc/source/ui/inc/dataprovider.hxx +++ b/sc/source/ui/inc/dataprovider.hxx @@ -13,9 +13,12 @@ #include <salhelper/thread.hxx> #include <tools/stream.hxx> #include <rtl/ustring.hxx> +#include <rtl/ref.hxx> #include <address.hxx> #include <osl/mutex.hxx> #include <osl/conditn.hxx> +#include <vcl/timer.hxx> + #include <queue> #include "officecfg/Office/Calc.hxx" @@ -68,7 +71,7 @@ class CSVFetchThread : public salhelper::Thread virtual void execute() override; public: - CSVFetchThread(SvStream*); + CSVFetchThread(SvStream*, size_t); virtual ~CSVFetchThread() override; void RequestTerminate(); @@ -80,43 +83,40 @@ public: class DataProvider { +public: virtual ~DataProvider() = 0; +private: virtual void StartImport() = 0; virtual void StopImport() = 0; virtual void Refresh() = 0; - virtual void SetUrl(OUString) = 0; - virtual void SetRefreshRate(double) = 0; virtual ScRange GetRange() const = 0; virtual const OUString& GetURL() const = 0; - -protected: - virtual void DecodeURL() = 0; }; class CSVDataProvider : public DataProvider { OUString maURL; - double mnRefreshRate; + ScRange mrRange; + Timer maImportTimer; + rtl::Reference<CSVFetchThread> mxCSVFetchThread; bool mbImportUnderway; public: - CSVDataProvider (OUString& rUrl); + CSVDataProvider (const OUString& rUrl, const ScRange& rRange); virtual ~CSVDataProvider() override; virtual void StartImport() override; virtual void StopImport() override; virtual void Refresh() override; - virtual void SetUrl(OUString) override; - virtual void SetRefreshRate(double mnRefreshRate) override; - ScRange GetRange() const override; + ScRange GetRange() const override + { + return mrRange; + } const OUString& GetURL() const override { return maURL; } - -private: - virtual void DecodeURL() override; }; } |