summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatúš Kukan <matus.kukan@collabora.com>2013-11-27 12:42:59 +0100
committerMatúš Kukan <matus.kukan@collabora.com>2013-12-02 11:13:44 +0100
commit01e8167a7e89961b5a985d18dab5b8af34f8b97e (patch)
tree54157da1dfd3e77c772576c2ea4bda8978a73a6c
parentb5b18e81fb58eae5fcb92d76f2c487c766978453 (diff)
Let's use ScRefreshTimer for data streams instead of our own thread.
As was the original idea, for some reason abandoned, and as ScAreaLink does. The main advantage is that ImportData() is not called anymore with invalid mpScDocument (when we close it). There is surely something going on with SolarMutex and it just works better. We do not need to use our own SolarMutexGuard. Change-Id: I09256a18ffa14606fc8e06b968016bbc0562a6fa
-rw-r--r--sc/source/ui/docshell/datastream.cxx62
-rw-r--r--sc/source/ui/inc/datastream.hxx11
-rw-r--r--sc/source/ui/miscdlgs/datastreamdlg.cxx2
-rw-r--r--sc/source/ui/view/cellsh2.cxx4
4 files changed, 26 insertions, 53 deletions
diff --git a/sc/source/ui/docshell/datastream.cxx b/sc/source/ui/docshell/datastream.cxx
index 514cefdfb0ac..4305d3fbc403 100644
--- a/sc/source/ui/docshell/datastream.cxx
+++ b/sc/source/ui/docshell/datastream.cxx
@@ -31,37 +31,6 @@
namespace datastreams {
-class CallerThread : public salhelper::Thread
-{
- DataStream *mpDataStream;
-public:
- osl::Condition maStart;
- bool mbTerminate;
-
- CallerThread(DataStream *pData):
- Thread("CallerThread")
- ,mpDataStream(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 (mpDataStream->ImportData())
- wait(aTime);
- };
- }
-};
-
class ReaderThread : public salhelper::Thread
{
SvStream *mpStream;
@@ -219,19 +188,16 @@ DataStream::DataStream(ScDocShell *pShell, const OUString& rURL, const OUString&
, mpLines(0)
, mnLinesCount(0)
{
- mxThread = new datastreams::CallerThread( this );
- mxThread->launch();
-
+ SetRefreshHandler(LINK( this, DataStream, RefreshHdl ));
+ SetRefreshControl(mpScDocument->GetRefreshTimerControlAddress());
+ SetTimeout( 1 );
Decode(rURL, rRange, nLimit, rMove, nSettings);
}
DataStream::~DataStream()
{
if (mbRunning)
- Stop();
- mxThread->mbTerminate = true;
- mxThread->maStart.set();
- mxThread->join();
+ StopImport();
if (mxReaderThread.is())
mxReaderThread->endThread();
}
@@ -299,21 +265,22 @@ void DataStream::Decode(const OUString& rURL, const OUString& rRange,
}
}
-void DataStream::Start()
+void DataStream::StartImport()
{
if (mbRunning)
return;
mbIsUndoEnabled = mpScDocument->IsUndoEnabled();
mpScDocument->EnableUndo(false);
mbRunning = true;
- mxThread->maStart.set();
+ AutoTimer::Start();
}
-void DataStream::Stop()
+void DataStream::StopImport()
{
if (!mbRunning)
return;
mbRunning = false;
+ AutoTimer::Stop();
mpScDocument->EnableUndo(mbIsUndoEnabled);
}
@@ -339,9 +306,14 @@ void DataStream::MoveData()
}
}
+IMPL_LINK_NOARG(DataStream, RefreshHdl)
+{
+ ImportData();
+ return 0;
+}
+
bool DataStream::ImportData()
{
- SolarMutexGuard aGuard;
MoveData();
if (mbValuesInLine)
{
@@ -406,7 +378,7 @@ sfx2::SvBaseLink::UpdateResult DataStream::DataChanged(
const OUString& , const css::uno::Any& )
{
MakeToolbarVisible();
- Start();
+ StartImport();
return SUCCESS;
}
@@ -417,10 +389,10 @@ void DataStream::Edit(Window* pWindow, const Link& )
if (aDialog.Execute() == RET_OK)
{
bool bWasRunning = mbRunning;
- Stop();
+ StopImport();
aDialog.StartStream(this);
if (bWasRunning)
- Start();
+ StartImport();
}
}
diff --git a/sc/source/ui/inc/datastream.hxx b/sc/source/ui/inc/datastream.hxx
index 3b0f745b7cc7..039cc4833119 100644
--- a/sc/source/ui/inc/datastream.hxx
+++ b/sc/source/ui/inc/datastream.hxx
@@ -13,13 +13,13 @@
#include <rtl/ustring.hxx>
#include <sfx2/lnkbase.hxx>
#include <address.hxx>
+#include <refreshtimer.hxx>
#include <boost/noncopyable.hpp>
#include <boost/scoped_ptr.hpp>
#include <vector>
namespace datastreams {
- class CallerThread;
class ReaderThread;
}
class ScDocShell;
@@ -28,10 +28,11 @@ class Window;
typedef std::vector<OString> LinesList;
-class DataStream : boost::noncopyable, public sfx2::SvBaseLink
+class DataStream : boost::noncopyable, public sfx2::SvBaseLink, ScRefreshTimer
{
OString ConsumeLine();
void MoveData();
+ DECL_LINK( RefreshHdl, void* );
public:
enum MoveEnum { NO_MOVE, RANGE_DOWN, MOVE_DOWN, MOVE_UP };
@@ -44,6 +45,7 @@ public:
DataStream(ScDocShell *pShell, const OUString& rURL, const OUString& rRange,
sal_Int32 nLimit, const OUString& rMove, sal_uInt32 nSettings);
virtual ~DataStream();
+ // sfx2::SvBaseLink
virtual sfx2::SvBaseLink::UpdateResult DataChanged(
const OUString& , const css::uno::Any& ) SAL_OVERRIDE;
virtual void Edit(Window* , const Link& ) SAL_OVERRIDE;
@@ -56,8 +58,8 @@ public:
void Decode(const OUString& rURL, const OUString& rRange, sal_Int32 nLimit,
const OUString& rMove, const sal_uInt32 nSettings);
bool ImportData();
- void Start();
- void Stop();
+ void StartImport();
+ void StopImport();
private:
ScDocShell *mpScDocShell;
@@ -76,7 +78,6 @@ private:
ScRange maRange;
ScRange maStartRange;
boost::scoped_ptr<ScRange> mpEndRange;
- rtl::Reference<datastreams::CallerThread> mxThread;
rtl::Reference<datastreams::ReaderThread> mxReaderThread;
};
diff --git a/sc/source/ui/miscdlgs/datastreamdlg.cxx b/sc/source/ui/miscdlgs/datastreamdlg.cxx
index 7b3e151f37f6..405c7c03ffc2 100644
--- a/sc/source/ui/miscdlgs/datastreamdlg.cxx
+++ b/sc/source/ui/miscdlgs/datastreamdlg.cxx
@@ -128,7 +128,7 @@ void DataStreamDlg::StartStream(DataStream *pStream)
, nSettings
);
DataStream::MakeToolbarVisible();
- pStream->Start();
+ pStream->StartImport();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/view/cellsh2.cxx b/sc/source/ui/view/cellsh2.cxx
index aceb41cea89b..a8d301e8c061 100644
--- a/sc/source/ui/view/cellsh2.cxx
+++ b/sc/source/ui/view/cellsh2.cxx
@@ -750,7 +750,7 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
const sfx2::SvBaseLinks& rLinks = pDoc->GetLinkManager()->GetLinks();
for (size_t i = 0; i < rLinks.size(); i++)
if (DataStream *pStream = dynamic_cast<DataStream*>(&(*(*rLinks[i]))))
- pStream->Start();
+ pStream->StartImport();
}
}
break;
@@ -762,7 +762,7 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
const sfx2::SvBaseLinks& rLinks = pDoc->GetLinkManager()->GetLinks();
for (size_t i = 0; i < rLinks.size(); i++)
if (DataStream *pStream = dynamic_cast<DataStream*>(&(*(*rLinks[i]))))
- pStream->Stop();
+ pStream->StopImport();
}
}
break;