[Libreoffice-commits] core.git: sc/source

Jaskaran Singh jvsg1303 at gmail.com
Sun Dec 11 15:12:48 UTC 2016


 sc/source/ui/docshell/dataprovider.cxx |   58 ++++++++++++++++++++++++++++++++-
 sc/source/ui/inc/dataprovider.hxx      |   28 +++++++--------
 2 files changed, 71 insertions(+), 15 deletions(-)

New commits:
commit 777c22bca071942a14f2db4b38d711a5a00df1b3
Author: Jaskaran Singh <jvsg1303 at gmail.com>
Date:   Thu Dec 8 13:21:34 2016 +0530

    Implement CSVDataProvider and perform some cleanup on it
    
    Change-Id: Ic409bd4977fdf610294bd13b7ea83ef9a4c48667
    Reviewed-on: https://gerrit.libreoffice.org/31750
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Jaskaran singh <jvsg1303 at gmail.com>

diff --git a/sc/source/ui/docshell/dataprovider.cxx b/sc/source/ui/docshell/dataprovider.cxx
index 80a6b2b..7df702c 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 d0101dc..1a01512 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;
 };
 
 }


More information about the Libreoffice-commits mailing list