diff options
author | Matúš Kukan <matus.kukan@collabora.com> | 2013-11-27 12:42:59 +0100 |
---|---|---|
committer | Matúš Kukan <matus.kukan@collabora.com> | 2013-11-28 20:40:39 +0100 |
commit | d925f6072914c66816b9c69c47141053282f9960 (patch) | |
tree | 86fab4bb29be448c6f3eb297ebe74178445d868f | |
parent | 6ce9618ef9ebe58bc6f3ced34c465bbeb5df5b23 (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.cxx | 62 | ||||
-rw-r--r-- | sc/source/ui/inc/datastream.hxx | 11 | ||||
-rw-r--r-- | sc/source/ui/miscdlgs/datastreamdlg.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/view/cellsh2.cxx | 4 |
4 files changed, 26 insertions, 53 deletions
diff --git a/sc/source/ui/docshell/datastream.cxx b/sc/source/ui/docshell/datastream.cxx index ff095f5e6090..fff0bbd6639f 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(mpScDocShell); - 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 91dda2e931d5..092539b7f9c9 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() SAL_OVERRIDE; + // 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 e56cc039e544..cbfd46baff0d 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( mpDocShell ); - 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; |