[Libreoffice-commits] core.git: Branch 'private/matus/sc-hacks' - 3 commits - officecfg/registry postprocess/packimages sc/inc sc/Library_sc.mk sc/sdi sc/source sc/uiconfig sc/UIConfig_scalc.mk

Matúš Kukan matus.kukan at gmail.com
Tue Nov 12 12:35:31 PST 2013


Rebased ref, commits from common ancestor:
commit 90fc43ff39e9bfe1bfc397bf3d6e7b232972d573
Author: Matúš Kukan <matus.kukan at gmail.com>
Date:   Tue Nov 12 19:58:29 2013 +0100

    datastreams: add toolbar buttons to stop / resume importing
    
    Change-Id: I601a4a174ea191c799623d29ed6eb229f9f372da

diff --git a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
index b04b2e2..d7866ca 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/CalcCommands.xcu
@@ -1277,6 +1277,22 @@
           <value xml:lang="en-US">Strea~ms...</value>
         </prop>
       </node>
+      <node oor:name=".uno:DataStreamsPlay" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">Resume importing</value>
+        </prop>
+        <prop oor:name="Properties" oor:type="xs:int">
+          <value>1</value>
+        </prop>
+      </node>
+      <node oor:name=".uno:DataStreamsStop" oor:op="replace">
+        <prop oor:name="Label" oor:type="xs:string">
+          <value xml:lang="en-US">Stop importing</value>
+        </prop>
+        <prop oor:name="Properties" oor:type="xs:int">
+          <value>1</value>
+        </prop>
+      </node>
       <node oor:name=".uno:ManageXMLSource" oor:op="replace">
         <prop oor:name="Label" oor:type="xs:string">
           <value xml:lang="en-US">~XML Source...</value>
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/CalcWindowState.xcu b/officecfg/registry/data/org/openoffice/Office/UI/CalcWindowState.xcu
index 4b201a1..8ef44d3 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/CalcWindowState.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/CalcWindowState.xcu
@@ -54,6 +54,17 @@
           <value>true</value>
         </prop>
       </node>
+      <node oor:name="private:resource/toolbar/datastreams" oor:op="replace">
+        <prop oor:name="Docked" oor:type="xs:boolean">
+          <value>false</value>
+        </prop>
+        <prop oor:name="UIName" oor:type="xs:string">
+          <value xml:lang="en-US">Data Streams</value>
+        </prop>
+        <prop oor:name="Visible" oor:type="xs:boolean">
+          <value>true</value>
+        </prop>
+      </node>
       <node oor:name="private:resource/toolbar/drawobjectbar" oor:op="replace">
         <prop oor:name="DockPos" oor:type="xs:string">
           <value>0,1</value>
diff --git a/postprocess/packimages/image-sort.lst b/postprocess/packimages/image-sort.lst
index 223668c..823528a 100644
--- a/postprocess/packimages/image-sort.lst
+++ b/postprocess/packimages/image-sort.lst
@@ -103,6 +103,7 @@ modules/scalc/toolbar/arrowshapes.xml
 modules/scalc/toolbar/basicshapes.xml
 modules/scalc/toolbar/calloutshapes.xml
 modules/scalc/toolbar/colorbar.xml
+modules/scalc/toolbar/datastreams.xml
 modules/scalc/toolbar/drawbar.xml
 modules/scalc/toolbar/drawobjectbar.xml
 modules/scalc/toolbar/extrusionobjectbar.xml
diff --git a/sc/UIConfig_scalc.mk b/sc/UIConfig_scalc.mk
index dceaf9a..0da612e 100644
--- a/sc/UIConfig_scalc.mk
+++ b/sc/UIConfig_scalc.mk
@@ -29,6 +29,7 @@ $(eval $(call gb_UIConfig_add_toolbarfiles,modules/scalc,\
 	sc/uiconfig/scalc/toolbar/basicshapes \
 	sc/uiconfig/scalc/toolbar/calloutshapes \
 	sc/uiconfig/scalc/toolbar/colorbar \
+	sc/uiconfig/scalc/toolbar/datastreams \
 	sc/uiconfig/scalc/toolbar/drawbar \
 	sc/uiconfig/scalc/toolbar/drawobjectbar \
 	sc/uiconfig/scalc/toolbar/extrusionobjectbar \
diff --git a/sc/inc/sc.hrc b/sc/inc/sc.hrc
index 40c43a6..b0e20a5 100644
--- a/sc/inc/sc.hrc
+++ b/sc/inc/sc.hrc
@@ -91,6 +91,8 @@
 #define SID_SCFORMULAOPTIONS    (SC_VIEW_START + 20)
 #define SID_SCDEFAULTSOPTIONS   (SC_VIEW_START + 21)
 
+#define SID_DATA_STREAMS_PLAY   (SC_VIEW_START + 33)
+#define SID_DATA_STREAMS_STOP   (SC_VIEW_START + 34)
 #define SID_DATA_STREAMS        (SC_VIEW_START + 35)
 
 // slot-IDs for attributes
diff --git a/sc/sdi/cellsh.sdi b/sc/sdi/cellsh.sdi
index f06d848..9b82d0d 100644
--- a/sc/sdi/cellsh.sdi
+++ b/sc/sdi/cellsh.sdi
@@ -52,6 +52,8 @@ interface CellSelection
     SID_SBA_BRW_INSERT      [ ExecMethod = ExecuteDB; StateMethod = GetDBState; ]
     SID_SELECT_DB           [ ExecMethod = ExecuteDB; StateMethod = GetDBState; ]
     SID_DATA_STREAMS        [ ExecMethod = ExecuteDB; ]
+    SID_DATA_STREAMS_PLAY   [ ExecMethod = ExecuteDB; ]
+    SID_DATA_STREAMS_STOP   [ ExecMethod = ExecuteDB; ]
     SID_MANAGE_XML_SOURCE   [ ExecMethod = ExecuteDB; StateMethod = GetDBState; ]
     SID_SORT                [ ExecMethod = ExecuteDB; StateMethod = GetDBState; ]
     SID_DATA_FORM           [ ExecMethod = ExecuteDB; StateMethod = GetDBState; ]
diff --git a/sc/sdi/scalc.sdi b/sc/sdi/scalc.sdi
index 8d1a4e7..149f058 100644
--- a/sc/sdi/scalc.sdi
+++ b/sc/sdi/scalc.sdi
@@ -6100,6 +6100,52 @@ SfxVoidItem DataStreams SID_DATA_STREAMS
     GroupId = GID_DATA;
 ]
 
+SfxVoidItem DataStreamsPlay SID_DATA_STREAMS_PLAY
+[
+    /* flags: */
+    AutoUpdate = FALSE,
+    Cachable = Cachable,
+    FastCall = FALSE,
+    HasCoreId = FALSE,
+    HasDialog = FALSE,
+    ReadOnlyDoc = TRUE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+    Synchron;
+
+    /* config: */
+    AccelConfig = TRUE,
+    MenuConfig = TRUE,
+    StatusBarConfig = FALSE,
+    ToolBoxConfig = TRUE,
+    GroupId = GID_DATA;
+]
+
+SfxVoidItem DataStreamsStop SID_DATA_STREAMS_STOP
+[
+    /* flags: */
+    AutoUpdate = FALSE,
+    Cachable = Cachable,
+    FastCall = FALSE,
+    HasCoreId = FALSE,
+    HasDialog = FALSE,
+    ReadOnlyDoc = TRUE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+    Synchron;
+
+    /* config: */
+    AccelConfig = TRUE,
+    MenuConfig = TRUE,
+    StatusBarConfig = FALSE,
+    ToolBoxConfig = TRUE,
+    GroupId = GID_DATA;
+]
+
 SfxVoidItem ManageXMLSource SID_MANAGE_XML_SOURCE
 (SfxStringItem DbName SID_MANAGE_XML_SOURCE)
 [
diff --git a/sc/source/ui/inc/datastreams.hxx b/sc/source/ui/inc/datastreams.hxx
index bacfefe..a48ac62 100644
--- a/sc/source/ui/inc/datastreams.hxx
+++ b/sc/source/ui/inc/datastreams.hxx
@@ -44,13 +44,13 @@ public:
     ~DataStreams();
     bool ImportData();
     void ShowDialog(Window *pParent);
+    void Start();
+    void Stop();
 
 private:
     void MoveData();
     void Set(const OUString& rUrl, bool bIsScript, const OUString& rRange,
             sal_Int32 nLimit, MoveEnum eMove);
-    void Start();
-    void Stop();
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/miscdlgs/datastreams.cxx b/sc/source/ui/miscdlgs/datastreams.cxx
index 4ab9180..a1ebd01 100644
--- a/sc/source/ui/miscdlgs/datastreams.cxx
+++ b/sc/source/ui/miscdlgs/datastreams.cxx
@@ -58,6 +58,7 @@ DataStreams::DataStreams(ScDocShell *pScDocShell):
     , mpScDocShell(pScDocShell)
     , mpScDocument(mpScDocShell->GetDocument())
     , meMove(NO_MOVE)
+    , mbRunning(false)
 {
     mxThread = new datastreams::CallerThread( this );
     mxThread->launch();
@@ -74,6 +75,8 @@ DataStreams::~DataStreams()
 
 void DataStreams::Start()
 {
+    if (mbRunning)
+        return;
     mbIsUndoEnabled = mpScDocument->IsUndoEnabled();
     mpScDocument->EnableUndo(false);
     mbRunning = true;
@@ -82,6 +85,8 @@ void DataStreams::Start()
 
 void DataStreams::Stop()
 {
+    if (!mbRunning)
+        return;
     mbRunning = false;
     mpScDocument->EnableUndo(mbIsUndoEnabled);
 }
diff --git a/sc/source/ui/miscdlgs/datastreamsdlg.cxx b/sc/source/ui/miscdlgs/datastreamsdlg.cxx
index d99af8b..f7c2a43 100644
--- a/sc/source/ui/miscdlgs/datastreamsdlg.cxx
+++ b/sc/source/ui/miscdlgs/datastreamsdlg.cxx
@@ -20,7 +20,6 @@ class DataStreamsDlg : public ModelessDialog
 
     SvtURLBox*      m_pCbUrl;
     PushButton*     m_pBtnBrowse;
-    PushButton*     m_pBtnStop;
     RadioButton*    m_pRBDirectData;
     RadioButton*    m_pRBScriptData;
     RadioButton*    m_pRBDataDown;
@@ -35,7 +34,6 @@ class DataStreamsDlg : public ModelessDialog
     DECL_LINK(UpdateHdl, void *);
     DECL_LINK(BrowseHdl, void *);
     DECL_LINK(StartHdl, void *);
-    DECL_LINK(StopHdl, void *);
 
     void UpdateEnable();
 
@@ -50,7 +48,6 @@ DataStreamsDlg::DataStreamsDlg(DataStreams *pDataStreams, Window* pParent)
 {
     get(m_pCbUrl, "url");
     get(m_pBtnBrowse, "browse");
-    get(m_pBtnStop, "stop");
     get(m_pRBDirectData, "directdata");
     get(m_pRBScriptData, "scriptdata");
     get(m_pRBDataDown, "datadown");
@@ -65,7 +62,6 @@ DataStreamsDlg::DataStreamsDlg(DataStreams *pDataStreams, Window* pParent)
     m_pCbUrl->SetSelectHdl( LINK( this, DataStreamsDlg, UpdateHdl ) );
     m_pEdRange->SetModifyHdl( LINK( this, DataStreamsDlg, UpdateHdl ) );
     m_pBtnBrowse->SetClickHdl( LINK( this, DataStreamsDlg, BrowseHdl ) );
-    m_pBtnStop->SetClickHdl( LINK( this, DataStreamsDlg, StopHdl ) );
     m_pBtnOk->SetClickHdl( LINK( this, DataStreamsDlg, StartHdl ) );
     m_pBtnOk->SetClickHdl( LINK( this, DataStreamsDlg, StartHdl ) );
     UpdateEnable();
@@ -101,12 +97,6 @@ IMPL_LINK_NOARG(DataStreamsDlg, StartHdl)
     return 0;
 }
 
-IMPL_LINK_NOARG(DataStreamsDlg, StopHdl)
-{
-    mpDataStreams->Stop();
-    return 0;
-}
-
 IMPL_LINK_NOARG(DataStreamsDlg, UpdateHdl)
 {
     UpdateEnable();
diff --git a/sc/source/ui/view/cellsh2.cxx b/sc/source/ui/view/cellsh2.cxx
index b5d4bf7..4450bd9 100644
--- a/sc/source/ui/view/cellsh2.cxx
+++ b/sc/source/ui/view/cellsh2.cxx
@@ -738,6 +738,14 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
                 pImpl->m_pDataStreams = new DataStreams(GetViewData()->GetDocShell());
             pImpl->m_pDataStreams->ShowDialog( pTabViewShell->GetDialogParent() );
             break;
+        case SID_DATA_STREAMS_PLAY:
+            if (pImpl->m_pDataStreams)
+                pImpl->m_pDataStreams->Start();
+            break;
+        case SID_DATA_STREAMS_STOP:
+            if (pImpl->m_pDataStreams)
+                pImpl->m_pDataStreams->Stop();
+            break;
         case SID_MANAGE_XML_SOURCE:
             ExecuteXMLSourceDialog();
         break;
diff --git a/sc/uiconfig/scalc/toolbar/datastreams.xml b/sc/uiconfig/scalc/toolbar/datastreams.xml
new file mode 100644
index 0000000..dd3a5e4
--- /dev/null
+++ b/sc/uiconfig/scalc/toolbar/datastreams.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE toolbar:toolbar PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "toolbar.dtd">
+<!--
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+-->
+<toolbar:toolbar xmlns:toolbar="http://openoffice.org/2001/toolbar" xmlns:xlink="http://www.w3.org/1999/xlink" toolbar:id="toolbar">
+ <toolbar:toolbaritem xlink:href=".uno:DataStreamsPlay"/>
+ <toolbar:toolbarseparator/>
+ <toolbar:toolbaritem xlink:href=".uno:DataStreamsStop"/>
+</toolbar:toolbar>
diff --git a/sc/uiconfig/scalc/ui/datastreams.ui b/sc/uiconfig/scalc/ui/datastreams.ui
index de211ec..12282f8 100644
--- a/sc/uiconfig/scalc/ui/datastreams.ui
+++ b/sc/uiconfig/scalc/ui/datastreams.ui
@@ -447,20 +447,6 @@
                 <property name="position">2</property>
               </packing>
             </child>
-            <child>
-              <object class="GtkButton" id="stop">
-                <property name="label" translatable="yes">Stop</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_underline">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">3</property>
-              </packing>
-            </child>
           </object>
           <packing>
             <property name="expand">False</property>
@@ -475,7 +461,6 @@
       <action-widget response="0">ok</action-widget>
       <action-widget response="0">cancel</action-widget>
       <action-widget response="0">help</action-widget>
-      <action-widget response="0">stop</action-widget>
     </action-widgets>
   </object>
   <object class="GtkAdjustment" id="adjustment1">
commit b5a1e7a174c11dfb868802781790ce854b047159
Author: Matúš Kukan <matus.kukan at gmail.com>
Date:   Mon Nov 11 22:26:54 2013 +0100

    datastreams: implement moving the import range down until the limit is reached
    
    Change-Id: Iaaed4399a980697c37683d838fcb1f99208233e8

diff --git a/sc/source/ui/inc/datastreams.hxx b/sc/source/ui/inc/datastreams.hxx
index ea1b407..bacfefe 100644
--- a/sc/source/ui/inc/datastreams.hxx
+++ b/sc/source/ui/inc/datastreams.hxx
@@ -14,6 +14,7 @@
 
 #include <boost/scoped_ptr.hpp>
 
+namespace { class DataStreamsDlg; }
 class Dialog;
 class ScDocShell;
 class ScDocument;
@@ -24,27 +25,32 @@ namespace datastreams { class CallerThread; }
 
 class DataStreams
 {
+    friend DataStreamsDlg;
+    enum MoveEnum { NO_MOVE, RANGE_DOWN, MOVE_DOWN, MOVE_UP };
     Dialog *mpDialog;
     ScDocShell *mpScDocShell;
     ScDocument *mpScDocument;
-    bool mbMove;
+    MoveEnum meMove;
     bool mbRunning;
     bool mbIsUndoEnabled;
     boost::scoped_ptr<ScRange> mpRange;
+    boost::scoped_ptr<ScRange> mpStartRange;
     boost::scoped_ptr<ScRange> mpEndRange;
     boost::scoped_ptr<SvStream> mpStream;
     rtl::Reference<datastreams::CallerThread> mxThread;
 
 public:
     DataStreams(ScDocShell *pScDocShell);
-    virtual ~DataStreams();
+    ~DataStreams();
     bool ImportData();
-    void Move();
     void ShowDialog(Window *pParent);
+
+private:
+    void MoveData();
+    void Set(const OUString& rUrl, bool bIsScript, const OUString& rRange,
+            sal_Int32 nLimit, MoveEnum eMove);
     void Start();
     void Stop();
-    void Set(const OUString& rUrl, bool bIsScript, const OUString& rRange);
-    void SetMove(sal_Int32 nLimit);
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/miscdlgs/datastreams.cxx b/sc/source/ui/miscdlgs/datastreams.cxx
index a88a8ca..4ab9180 100644
--- a/sc/source/ui/miscdlgs/datastreams.cxx
+++ b/sc/source/ui/miscdlgs/datastreams.cxx
@@ -15,6 +15,8 @@
 #include <asciiopt.hxx>
 #include <docsh.hxx>
 #include <impex.hxx>
+#include <viewdata.hxx>
+#include <dbfunc.hxx>
 
 namespace datastreams {
 
@@ -55,7 +57,7 @@ DataStreams::DataStreams(ScDocShell *pScDocShell):
     mpDialog(NULL)
     , mpScDocShell(pScDocShell)
     , mpScDocument(mpScDocShell->GetDocument())
-    , mbMove(false)
+    , meMove(NO_MOVE)
 {
     mxThread = new datastreams::CallerThread( this );
     mxThread->launch();
@@ -82,41 +84,50 @@ void DataStreams::Stop()
 {
     mbRunning = false;
     mpScDocument->EnableUndo(mbIsUndoEnabled);
-    mbMove = false;
 }
 
-void DataStreams::Set(const OUString& rUrl, bool bIsScript, const OUString& rRange)
+void DataStreams::Set(const OUString& rUrl, bool bIsScript,
+        const OUString& rRange, sal_Int32 nLimit, MoveEnum eMove)
 {
     mpRange.reset ( new ScRange() );
     mpRange->Parse(rRange, mpScDocument);
+    mpStartRange.reset( new ScRange(*mpRange.get()) );
     if (bIsScript)
         mpStream.reset( new SvScriptStream(rUrl) );
     else
         mpStream.reset( new SvFileStream(rUrl, STREAM_READ) );
-}
 
-void DataStreams::SetMove(sal_Int32 nLimit)
-{
     mpEndRange.reset( NULL );
-    mbMove = true;
+    meMove = eMove;
     sal_Int32 nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1;
     nLimit = nHeight * (nLimit / nHeight);
     if (nLimit && mpRange->aStart.Row() + nLimit - 1 < MAXROW)
     {
-        mpEndRange.reset( new ScRange(*(mpRange.get())) );
+        mpEndRange.reset( new ScRange(*mpRange.get()) );
         mpEndRange->Move(0, nLimit - nHeight, 0);
     }
 }
 
-void DataStreams::Move()
+void DataStreams::MoveData()
 {
-    if (!mbMove)
-        return;
-    if (mpEndRange.get())
+    switch (meMove)
     {
-        mpScDocument->DeleteRow(*(mpEndRange.get()));
+        case RANGE_DOWN:
+            if (mpRange->aStart == mpEndRange->aStart)
+                meMove = MOVE_UP;
+            break;
+        case MOVE_UP:
+            mpScDocument->DeleteRow(*mpStartRange.get());
+            mpScDocument->InsertRow(*mpEndRange.get());
+            break;
+        case MOVE_DOWN:
+            if (mpEndRange.get())
+                mpScDocument->DeleteRow(*mpEndRange.get());
+            mpScDocument->InsertRow(*mpRange.get());
+            break;
+        case NO_MOVE:
+            break;
     }
-    mpScDocument->InsertRow(*(mpRange.get()));
 }
 
 bool DataStreams::ImportData()
@@ -128,8 +139,6 @@ bool DataStreams::ImportData()
         return mbRunning;
     }
 
-    SolarMutexGuard aGuard;
-    Move();
     sal_Int32 nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1;
     OStringBuffer aBuf;
     OString sTmp;
@@ -139,17 +148,25 @@ bool DataStreams::ImportData()
         aBuf.append(sTmp);
         aBuf.append('\n');
     }
+    SolarMutexGuard aGuard;
+    MoveData();
     SvMemoryStream aMemoryStream((void *)aBuf.getStr(), aBuf.getLength(), STREAM_READ);
     ScImportExport aImport(mpScDocument, *mpRange.get());
     aImport.SetSeparator(',');
     aImport.ImportStream(aMemoryStream, OUString(), FORMAT_STRING);
     // ImportStream calls PostPaint for relevant area,
     // we need to call it explicitly only when moving rows.
-    if (!mbMove)
+    if (meMove == NO_MOVE)
         return mbRunning;
 
+    if (meMove == RANGE_DOWN)
+    {
+        mpRange->Move(0, mpRange->aEnd.Row() - mpRange->aStart.Row() + 1, 0);
+        mpScDocShell->GetViewData()->GetView()->AlignToCursor(
+                mpRange->aStart.Col(), mpRange->aStart.Row(), SC_FOLLOW_JUMP);
+    }
     SCROW aEndRow = mpEndRange.get() ? mpEndRange->aEnd.Row() : MAXROW;
-    mpScDocShell->PostPaint( ScRange( mpRange->aStart, ScAddress( mpRange->aEnd.Col(),
+    mpScDocShell->PostPaint( ScRange( mpStartRange->aStart, ScAddress( mpRange->aEnd.Col(),
                     aEndRow, mpRange->aStart.Tab()) ), PAINT_GRID );
 
     return mbRunning;
diff --git a/sc/source/ui/miscdlgs/datastreamsdlg.cxx b/sc/source/ui/miscdlgs/datastreamsdlg.cxx
index 4519c60..d99af8b 100644
--- a/sc/source/ui/miscdlgs/datastreamsdlg.cxx
+++ b/sc/source/ui/miscdlgs/datastreamsdlg.cxx
@@ -90,14 +90,12 @@ IMPL_LINK_NOARG(DataStreamsDlg, BrowseHdl)
 IMPL_LINK_NOARG(DataStreamsDlg, StartHdl)
 {
     bool bIsScript = m_pRBScriptData->IsChecked();
-    mpDataStreams->Set(m_pCbUrl->GetText(), bIsScript, m_pEdRange->GetText());
-    if (!m_pRBNoMove->IsChecked())
-    {
-        sal_Int32 nLimit = 0;
-        if (m_pRBMaxLimit->IsChecked())
-            nLimit = m_pEdLimit->GetText().toInt32();
-        mpDataStreams->SetMove(nLimit);
-    }
+    sal_Int32 nLimit = 0;
+    if (m_pRBMaxLimit->IsChecked())
+        nLimit = m_pEdLimit->GetText().toInt32();
+    mpDataStreams->Set(m_pCbUrl->GetText(), bIsScript, m_pEdRange->GetText(),
+            nLimit, m_pRBNoMove->IsChecked() ? DataStreams::NO_MOVE :
+                    m_pRBRangeDown->IsChecked() ? DataStreams::RANGE_DOWN : DataStreams::MOVE_DOWN);
     mpDataStreams->Start();
     UpdateEnable();
     return 0;
commit bb18e367abc7e5cd396f6481bd5b1a7e9d56e8da
Author: Matúš Kukan <matus.kukan at gmail.com>
Date:   Fri Nov 8 22:15:36 2013 +0100

    Implement data streams dialog that allows importing a stream of data
    
    in CSV format.
    It's possible to read directly from a URL
    or to run a process and read its output.
    
    Change-Id: I3266c3bb175b73f1023440cca40b2cfab5fcc201

diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 3cd88db..25ca17b 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -440,6 +440,8 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
 	sc/source/ui/miscdlgs/autofmt \
 	sc/source/ui/miscdlgs/conflictsdlg \
 	sc/source/ui/miscdlgs/crnrdlg \
+	sc/source/ui/miscdlgs/datastreams \
+	sc/source/ui/miscdlgs/datastreamsdlg \
 	sc/source/ui/miscdlgs/highred \
 	sc/source/ui/miscdlgs/optsolver \
 	sc/source/ui/miscdlgs/protectiondlg \
diff --git a/sc/UIConfig_scalc.mk b/sc/UIConfig_scalc.mk
index 6ec6ee4..dceaf9a 100644
--- a/sc/UIConfig_scalc.mk
+++ b/sc/UIConfig_scalc.mk
@@ -66,6 +66,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/scalc,\
 	sc/uiconfig/scalc/ui/consolidatedialog \
 	sc/uiconfig/scalc/ui/createnamesdialog \
 	sc/uiconfig/scalc/ui/dataform \
+	sc/uiconfig/scalc/ui/datastreams \
 	sc/uiconfig/scalc/ui/definedatabaserangedialog \
 	sc/uiconfig/scalc/ui/definename \
 	sc/uiconfig/scalc/ui/deletecells \
diff --git a/sc/source/ui/inc/cellsh.hxx b/sc/source/ui/inc/cellsh.hxx
index b44eb9f..d7be8ac 100644
--- a/sc/source/ui/inc/cellsh.hxx
+++ b/sc/source/ui/inc/cellsh.hxx
@@ -33,16 +33,19 @@ class SvxClipboardFmtItem;
 class TransferableDataHelper;
 class TransferableClipboardListener;
 class AbstractScLinkedAreaDlg;
+class DataStreams;
 
 struct CellShell_Impl
 {
     TransferableClipboardListener*  m_pClipEvtLstnr;
     AbstractScLinkedAreaDlg*        m_pLinkedDlg;
+    DataStreams*                    m_pDataStreams;
     SfxRequest*                     m_pRequest;
 
     CellShell_Impl() :
         m_pClipEvtLstnr( NULL ),
         m_pLinkedDlg( NULL ),
+        m_pDataStreams( NULL ),
         m_pRequest( NULL ) {}
 };
 
diff --git a/sc/source/ui/inc/datastreams.hxx b/sc/source/ui/inc/datastreams.hxx
new file mode 100644
index 0000000..ea1b407
--- /dev/null
+++ b/sc/source/ui/inc/datastreams.hxx
@@ -0,0 +1,50 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sal/config.h>
+
+#include <rtl/ref.hxx>
+#include <rtl/ustring.hxx>
+
+#include <boost/scoped_ptr.hpp>
+
+class Dialog;
+class ScDocShell;
+class ScDocument;
+class ScRange;
+class SvStream;
+class Window;
+namespace datastreams { class CallerThread; }
+
+class DataStreams
+{
+    Dialog *mpDialog;
+    ScDocShell *mpScDocShell;
+    ScDocument *mpScDocument;
+    bool mbMove;
+    bool mbRunning;
+    bool mbIsUndoEnabled;
+    boost::scoped_ptr<ScRange> mpRange;
+    boost::scoped_ptr<ScRange> mpEndRange;
+    boost::scoped_ptr<SvStream> mpStream;
+    rtl::Reference<datastreams::CallerThread> mxThread;
+
+public:
+    DataStreams(ScDocShell *pScDocShell);
+    virtual ~DataStreams();
+    bool ImportData();
+    void Move();
+    void ShowDialog(Window *pParent);
+    void Start();
+    void Stop();
+    void Set(const OUString& rUrl, bool bIsScript, const OUString& rRange);
+    void SetMove(sal_Int32 nLimit);
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/miscdlgs/datastreams.cxx b/sc/source/ui/miscdlgs/datastreams.cxx
new file mode 100644
index 0000000..a88a8ca
--- /dev/null
+++ b/sc/source/ui/miscdlgs/datastreams.cxx
@@ -0,0 +1,158 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <datastreams.hxx>
+
+#include <osl/conditn.hxx>
+#include <rtl/strbuf.hxx>
+#include <salhelper/thread.hxx>
+#include <asciiopt.hxx>
+#include <docsh.hxx>
+#include <impex.hxx>
+
+namespace datastreams {
+
+class CallerThread : public salhelper::Thread
+{
+    DataStreams *mpDataStreams;
+public:
+    osl::Condition maStart;
+    bool mbTerminate;
+
+    CallerThread(DataStreams *pData):
+        Thread("CallerThread")
+        ,mpDataStreams(pData)
+        ,mbTerminate(false)
+    {}
+
+private:
+    virtual void execute()
+    {
+        while (!mbTerminate)
+        {
+            // wait for a small amount of time, so that
+            // painting methods have a chance to be called.
+            // And also to make UI more responsive.
+            TimeValue const aTime = {0, 100000};
+            maStart.wait();
+            maStart.reset();
+            if (!mbTerminate)
+                while (mpDataStreams->ImportData())
+                    wait(aTime);
+        };
+    }
+};
+
+}
+
+DataStreams::DataStreams(ScDocShell *pScDocShell):
+    mpDialog(NULL)
+    , mpScDocShell(pScDocShell)
+    , mpScDocument(mpScDocShell->GetDocument())
+    , mbMove(false)
+{
+    mxThread = new datastreams::CallerThread( this );
+    mxThread->launch();
+}
+
+DataStreams::~DataStreams()
+{
+    if (mbRunning)
+        Stop();
+    mxThread->mbTerminate = true;
+    mxThread->maStart.set();
+    mxThread->join();
+}
+
+void DataStreams::Start()
+{
+    mbIsUndoEnabled = mpScDocument->IsUndoEnabled();
+    mpScDocument->EnableUndo(false);
+    mbRunning = true;
+    mxThread->maStart.set();
+}
+
+void DataStreams::Stop()
+{
+    mbRunning = false;
+    mpScDocument->EnableUndo(mbIsUndoEnabled);
+    mbMove = false;
+}
+
+void DataStreams::Set(const OUString& rUrl, bool bIsScript, const OUString& rRange)
+{
+    mpRange.reset ( new ScRange() );
+    mpRange->Parse(rRange, mpScDocument);
+    if (bIsScript)
+        mpStream.reset( new SvScriptStream(rUrl) );
+    else
+        mpStream.reset( new SvFileStream(rUrl, STREAM_READ) );
+}
+
+void DataStreams::SetMove(sal_Int32 nLimit)
+{
+    mpEndRange.reset( NULL );
+    mbMove = true;
+    sal_Int32 nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1;
+    nLimit = nHeight * (nLimit / nHeight);
+    if (nLimit && mpRange->aStart.Row() + nLimit - 1 < MAXROW)
+    {
+        mpEndRange.reset( new ScRange(*(mpRange.get())) );
+        mpEndRange->Move(0, nLimit - nHeight, 0);
+    }
+}
+
+void DataStreams::Move()
+{
+    if (!mbMove)
+        return;
+    if (mpEndRange.get())
+    {
+        mpScDocument->DeleteRow(*(mpEndRange.get()));
+    }
+    mpScDocument->InsertRow(*(mpRange.get()));
+}
+
+bool DataStreams::ImportData()
+{
+    if (!mpStream->good())
+    {
+        // if there is a problem with SvStream, stop running
+        mbRunning = false;
+        return mbRunning;
+    }
+
+    SolarMutexGuard aGuard;
+    Move();
+    sal_Int32 nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1;
+    OStringBuffer aBuf;
+    OString sTmp;
+    while (nHeight--)
+    {
+        mpStream->ReadLine(sTmp);
+        aBuf.append(sTmp);
+        aBuf.append('\n');
+    }
+    SvMemoryStream aMemoryStream((void *)aBuf.getStr(), aBuf.getLength(), STREAM_READ);
+    ScImportExport aImport(mpScDocument, *mpRange.get());
+    aImport.SetSeparator(',');
+    aImport.ImportStream(aMemoryStream, OUString(), FORMAT_STRING);
+    // ImportStream calls PostPaint for relevant area,
+    // we need to call it explicitly only when moving rows.
+    if (!mbMove)
+        return mbRunning;
+
+    SCROW aEndRow = mpEndRange.get() ? mpEndRange->aEnd.Row() : MAXROW;
+    mpScDocShell->PostPaint( ScRange( mpRange->aStart, ScAddress( mpRange->aEnd.Col(),
+                    aEndRow, mpRange->aStart.Tab()) ), PAINT_GRID );
+
+    return mbRunning;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/miscdlgs/datastreamsdlg.cxx b/sc/source/ui/miscdlgs/datastreamsdlg.cxx
new file mode 100644
index 0000000..4519c60
--- /dev/null
+++ b/sc/source/ui/miscdlgs/datastreamsdlg.cxx
@@ -0,0 +1,134 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <sfx2/filedlghelper.hxx>
+#include <svtools/inettbc.hxx>
+#include <vcl/dialog.hxx>
+#include <datastreams.hxx>
+
+namespace {
+
+class DataStreamsDlg : public ModelessDialog
+{
+    DataStreams *mpDataStreams;
+
+    SvtURLBox*      m_pCbUrl;
+    PushButton*     m_pBtnBrowse;
+    PushButton*     m_pBtnStop;
+    RadioButton*    m_pRBDirectData;
+    RadioButton*    m_pRBScriptData;
+    RadioButton*    m_pRBDataDown;
+    RadioButton*    m_pRBRangeDown;
+    RadioButton*    m_pRBNoMove;
+    RadioButton*    m_pRBMaxLimit;
+    RadioButton*    m_pRBUnlimited;
+    Edit*           m_pEdRange;
+    Edit*           m_pEdLimit;
+    OKButton*       m_pBtnOk;
+
+    DECL_LINK(UpdateHdl, void *);
+    DECL_LINK(BrowseHdl, void *);
+    DECL_LINK(StartHdl, void *);
+    DECL_LINK(StopHdl, void *);
+
+    void UpdateEnable();
+
+public:
+    DataStreamsDlg(DataStreams *pDataStreams, Window* pParent);
+    ~DataStreamsDlg();
+};
+
+DataStreamsDlg::DataStreamsDlg(DataStreams *pDataStreams, Window* pParent)
+    : ModelessDialog(pParent, "DataStreamsDialog", "modules/scalc/ui/datastreams.ui")
+      , mpDataStreams(pDataStreams)
+{
+    get(m_pCbUrl, "url");
+    get(m_pBtnBrowse, "browse");
+    get(m_pBtnStop, "stop");
+    get(m_pRBDirectData, "directdata");
+    get(m_pRBScriptData, "scriptdata");
+    get(m_pRBDataDown, "datadown");
+    get(m_pRBRangeDown, "rangedown");
+    get(m_pRBNoMove, "nomove");
+    get(m_pRBMaxLimit, "maxlimit");
+    get(m_pRBUnlimited, "unlimited");
+    get(m_pEdRange, "range");
+    get(m_pEdLimit, "limit");
+    get(m_pBtnOk, "ok");
+
+    m_pCbUrl->SetSelectHdl( LINK( this, DataStreamsDlg, UpdateHdl ) );
+    m_pEdRange->SetModifyHdl( LINK( this, DataStreamsDlg, UpdateHdl ) );
+    m_pBtnBrowse->SetClickHdl( LINK( this, DataStreamsDlg, BrowseHdl ) );
+    m_pBtnStop->SetClickHdl( LINK( this, DataStreamsDlg, StopHdl ) );
+    m_pBtnOk->SetClickHdl( LINK( this, DataStreamsDlg, StartHdl ) );
+    m_pBtnOk->SetClickHdl( LINK( this, DataStreamsDlg, StartHdl ) );
+    UpdateEnable();
+    Show();
+}
+
+DataStreamsDlg::~DataStreamsDlg()
+{
+}
+
+IMPL_LINK_NOARG(DataStreamsDlg, BrowseHdl)
+{
+    sfx2::FileDialogHelper aFileDialog(0, 0);
+    if ( aFileDialog.Execute() != ERRCODE_NONE )
+        return 0;
+
+    m_pCbUrl->SetText( aFileDialog.GetPath() );
+    UpdateEnable();
+    return 0;
+}
+
+IMPL_LINK_NOARG(DataStreamsDlg, StartHdl)
+{
+    bool bIsScript = m_pRBScriptData->IsChecked();
+    mpDataStreams->Set(m_pCbUrl->GetText(), bIsScript, m_pEdRange->GetText());
+    if (!m_pRBNoMove->IsChecked())
+    {
+        sal_Int32 nLimit = 0;
+        if (m_pRBMaxLimit->IsChecked())
+            nLimit = m_pEdLimit->GetText().toInt32();
+        mpDataStreams->SetMove(nLimit);
+    }
+    mpDataStreams->Start();
+    UpdateEnable();
+    return 0;
+}
+
+IMPL_LINK_NOARG(DataStreamsDlg, StopHdl)
+{
+    mpDataStreams->Stop();
+    return 0;
+}
+
+IMPL_LINK_NOARG(DataStreamsDlg, UpdateHdl)
+{
+    UpdateEnable();
+    return 0;
+}
+
+void DataStreamsDlg::UpdateEnable()
+{
+    bool bOk = !m_pEdRange->GetText().isEmpty();
+    bOk = bOk && !m_pCbUrl->GetURL().isEmpty();
+    m_pBtnOk->Enable(bOk);
+}
+
+}
+
+void DataStreams::ShowDialog(Window *pParent)
+{
+    if (!mpDialog)
+        mpDialog = new DataStreamsDlg(this, pParent);
+    mpDialog->Show();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/view/cellsh.cxx b/sc/source/ui/view/cellsh.cxx
index e1ed032..943379f 100644
--- a/sc/source/ui/view/cellsh.cxx
+++ b/sc/source/ui/view/cellsh.cxx
@@ -55,6 +55,7 @@
 #include "postit.hxx"
 #include "cliputil.hxx"
 #include "clipparam.hxx"
+#include "datastreams.hxx"
 #include "markdata.hxx"
 
 //------------------------------------------------------------------
@@ -98,6 +99,7 @@ ScCellShell::~ScCellShell()
     }
 
     delete pImpl->m_pLinkedDlg;
+    delete pImpl->m_pDataStreams;
     delete pImpl->m_pRequest;
     delete pImpl;
 }
diff --git a/sc/source/ui/view/cellsh2.cxx b/sc/source/ui/view/cellsh2.cxx
index 12a46a8..b5d4bf7 100644
--- a/sc/source/ui/view/cellsh2.cxx
+++ b/sc/source/ui/view/cellsh2.cxx
@@ -56,6 +56,7 @@
 #include "scabstdlg.hxx"
 #include "impex.hxx"
 #include "asciiopt.hxx"
+#include "datastreams.hxx"
 #include "queryentry.hxx"
 #include "markdata.hxx"
 
@@ -733,6 +734,9 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
             }
             break;
         case SID_DATA_STREAMS:
+            if (!pImpl->m_pDataStreams)
+                pImpl->m_pDataStreams = new DataStreams(GetViewData()->GetDocShell());
+            pImpl->m_pDataStreams->ShowDialog( pTabViewShell->GetDialogParent() );
             break;
         case SID_MANAGE_XML_SOURCE:
             ExecuteXMLSourceDialog();


More information about the Libreoffice-commits mailing list