Kaydet (Commit) 55d6fdaf authored tarafından Matúš Kukan's avatar Matúš Kukan

Import data streams - reuse infrastructure for ScAreaLink.

Change-Id: I18db991d2e8e665d5e4ca778344993e79772ccd5
üst 47bc5672
...@@ -86,6 +86,7 @@ ...@@ -86,6 +86,7 @@
#include "columniterator.hxx" #include "columniterator.hxx"
#include "globalnames.hxx" #include "globalnames.hxx"
#include "stringutil.hxx" #include "stringutil.hxx"
#include <datastream.hxx>
#include <memory> #include <memory>
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
...@@ -1193,7 +1194,7 @@ bool ScDocument::HasAreaLinks() const ...@@ -1193,7 +1194,7 @@ bool ScDocument::HasAreaLinks() const
const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks(); const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
sal_uInt16 nCount = rLinks.size(); sal_uInt16 nCount = rLinks.size();
for (sal_uInt16 i=0; i<nCount; i++) for (sal_uInt16 i=0; i<nCount; i++)
if ((*rLinks[i])->ISA(ScAreaLink)) if ((*rLinks[i])->ISA(ScAreaLink) || (*rLinks[i])->ISA(DataStream))
return true; return true;
} }
...@@ -1208,7 +1209,7 @@ void ScDocument::UpdateAreaLinks() ...@@ -1208,7 +1209,7 @@ void ScDocument::UpdateAreaLinks()
for (sal_uInt16 i=0; i<rLinks.size(); i++) for (sal_uInt16 i=0; i<rLinks.size(); i++)
{ {
::sfx2::SvBaseLink* pBase = *rLinks[i]; ::sfx2::SvBaseLink* pBase = *rLinks[i];
if (pBase->ISA(ScAreaLink)) if (pBase->ISA(ScAreaLink) || (*rLinks[i])->ISA(DataStream))
pBase->Update(); pBase->Update();
} }
} }
......
...@@ -52,6 +52,8 @@ ...@@ -52,6 +52,8 @@
#include "tokenarray.hxx" #include "tokenarray.hxx"
#include "scmatrix.hxx" #include "scmatrix.hxx"
#include "documentimport.hxx" #include "documentimport.hxx"
#include <datastream.hxx>
#include <rangeutl.hxx>
#include <xmloff/xmltkmap.hxx> #include <xmloff/xmltkmap.hxx>
#include <xmloff/xmltoken.hxx> #include <xmloff/xmltoken.hxx>
...@@ -997,6 +999,19 @@ void ScXMLTableRowCellContext::SetCellRangeSource( const ScAddress& rPosition ) ...@@ -997,6 +999,19 @@ void ScXMLTableRowCellContext::SetCellRangeSource( const ScAddress& rPosition )
rPosition.Row() + static_cast<SCROW>(pCellRangeSource->nRows - 1), rPosition.Tab() ); rPosition.Row() + static_cast<SCROW>(pCellRangeSource->nRows - 1), rPosition.Tab() );
OUString sFilterName( pCellRangeSource->sFilterName ); OUString sFilterName( pCellRangeSource->sFilterName );
OUString sSourceStr( pCellRangeSource->sSourceStr ); OUString sSourceStr( pCellRangeSource->sSourceStr );
OUString sRangeStr;
ScRangeStringConverter::GetStringFromRange( sRangeStr, aDestRange, pDoc, formula::FormulaGrammar::CONV_OOO );
if (pCellRangeSource->sFilterOptions == "DataStream")
{
DataStream::Set( dynamic_cast<ScDocShell*>(pDoc->GetDocumentShell())
, pCellRangeSource->sURL // rURL
, sRangeStr // rRange
, sFilterName.toInt32() // nLimit
, sSourceStr // rMove
, pCellRangeSource->nRefresh // nSettings
);
return;
}
ScAreaLink* pLink = new ScAreaLink( pDoc->GetDocumentShell(), pCellRangeSource->sURL, ScAreaLink* pLink = new ScAreaLink( pDoc->GetDocumentShell(), pCellRangeSource->sURL,
sFilterName, pCellRangeSource->sFilterOptions, sSourceStr, aDestRange, pCellRangeSource->nRefresh ); sFilterName, pCellRangeSource->sFilterOptions, sSourceStr, aDestRange, pCellRangeSource->nRefresh );
sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager(); sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
......
...@@ -138,10 +138,10 @@ private: ...@@ -138,10 +138,10 @@ private:
} }
static void lcl_MakeToolbarVisible(SfxViewFrame *pViewFrame) void DataStream::MakeToolbarVisible(ScDocShell *pShell)
{ {
css::uno::Reference< css::frame::XFrame > xFrame = css::uno::Reference< css::frame::XFrame > xFrame =
pViewFrame->GetFrame().GetFrameInterface(); pShell->GetViewData()->GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface();
if (!xFrame.is()) if (!xFrame.is())
return; return;
...@@ -163,18 +163,18 @@ static void lcl_MakeToolbarVisible(SfxViewFrame *pViewFrame) ...@@ -163,18 +163,18 @@ static void lcl_MakeToolbarVisible(SfxViewFrame *pViewFrame)
} }
} }
void DataStream::Set(ScDocShell *pShell, const OUString& rURL, const OUString& rRange, sal_Int32 nLimit, const OUString& rMove) DataStream* DataStream::Set(ScDocShell *pShell, const OUString& rURL, const OUString& rRange,
sal_Int32 nLimit, const OUString& rMove, sal_uInt32 nSettings)
{ {
sfx2::SvBaseLink *pLink = 0; sfx2::SvBaseLink *pLink = 0;
pLink = new DataStream( pShell, rURL, rRange, nLimit, rMove ); pLink = new DataStream( pShell, rURL, rRange, nLimit, rMove, nSettings );
sfx2::LinkManager* pLinkManager = pShell->GetDocument()->GetLinkManager(); sfx2::LinkManager* pLinkManager = pShell->GetDocument()->GetLinkManager();
pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, rURL, NULL, NULL ); pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, rURL, NULL, NULL );
return dynamic_cast<DataStream*>(pLink);
lcl_MakeToolbarVisible(pShell->GetViewData()->GetViewShell()->GetViewFrame());
} }
DataStream::DataStream(ScDocShell *pShell, const OUString& rURL, DataStream::DataStream(ScDocShell *pShell, const OUString& rURL, const OUString& rRange,
const OUString& rRange, sal_Int32 nLimit, const OUString& rMove) sal_Int32 nLimit, const OUString& rMove, sal_uInt32 nSettings)
: mpScDocShell(pShell) : mpScDocShell(pShell)
, mpScDocument(mpScDocShell->GetDocument()) , mpScDocument(mpScDocShell->GetDocument())
, meMove(NO_MOVE) , meMove(NO_MOVE)
...@@ -187,7 +187,7 @@ DataStream::DataStream(ScDocShell *pShell, const OUString& rURL, ...@@ -187,7 +187,7 @@ DataStream::DataStream(ScDocShell *pShell, const OUString& rURL,
mxThread = new datastreams::CallerThread( this ); mxThread = new datastreams::CallerThread( this );
mxThread->launch(); mxThread->launch();
Decode(rURL, rRange, rMove); Decode(rURL, rRange, rMove, nSettings);
mpStartRange.reset( new ScRange(*mpRange.get()) ); mpStartRange.reset( new ScRange(*mpRange.get()) );
sal_Int32 nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1; sal_Int32 nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1;
...@@ -215,6 +215,8 @@ OString DataStream::ConsumeLine() ...@@ -215,6 +215,8 @@ OString DataStream::ConsumeLine()
if (!mpLines || mnLinesCount >= mpLines->size()) if (!mpLines || mnLinesCount >= mpLines->size())
{ {
mnLinesCount = 0; mnLinesCount = 0;
if (mxReaderThread->mbTerminateReading)
return OString();
osl::ResettableMutexGuard aGuard(mxReaderThread->maLinesProtector); osl::ResettableMutexGuard aGuard(mxReaderThread->maLinesProtector);
if (mpLines) if (mpLines)
mxReaderThread->maUsedLines.push(mpLines); mxReaderThread->maUsedLines.push(mpLines);
...@@ -233,18 +235,18 @@ OString DataStream::ConsumeLine() ...@@ -233,18 +235,18 @@ OString DataStream::ConsumeLine()
return mpLines->at(mnLinesCount++); return mpLines->at(mnLinesCount++);
} }
void DataStream::Decode( const OUString& rURL, const OUString& rRange, const OUString& rMove) void DataStream::Decode( const OUString& rURL, const OUString& rRange,
const OUString& rMove, sal_uInt32 nSettings)
{ {
sal_Int32 nIndex = rURL.indexOf(sfx2::cTokenSeparator);
SvStream *pStream = 0; SvStream *pStream = 0;
if (nIndex != -1) if (nSettings & SCRIPT_STREAM)
pStream = new SvScriptStream(rURL.copy(0, nIndex)); pStream = new SvScriptStream(rURL);
else else
pStream = new SvFileStream(rURL, STREAM_READ); pStream = new SvFileStream(rURL, STREAM_READ);
mxReaderThread = new datastreams::ReaderThread( pStream ); mxReaderThread = new datastreams::ReaderThread( pStream );
mxReaderThread->launch(); mxReaderThread->launch();
mbValuesInLine = !rRange.isEmpty(); mbValuesInLine = nSettings & VALUES_IN_LINE;
if (!mbValuesInLine) if (!mbValuesInLine)
return; return;
...@@ -361,6 +363,14 @@ bool DataStream::ImportData() ...@@ -361,6 +363,14 @@ bool DataStream::ImportData()
return mbRunning; return mbRunning;
} }
sfx2::SvBaseLink::UpdateResult DataStream::DataChanged(
const OUString& , const css::uno::Any& )
{
MakeToolbarVisible(mpScDocShell);
Start();
return SUCCESS;
}
void DataStream::Edit(Window* , const Link& ) void DataStream::Edit(Window* , const Link& )
{ {
} }
......
...@@ -31,18 +31,22 @@ typedef std::vector<OString> LinesList; ...@@ -31,18 +31,22 @@ typedef std::vector<OString> LinesList;
class DataStream : boost::noncopyable, public sfx2::SvBaseLink class DataStream : boost::noncopyable, public sfx2::SvBaseLink
{ {
OString ConsumeLine(); OString ConsumeLine();
void Decode(const OUString& rURL, const OUString& rRange, const OUString& rMove); void Decode(const OUString& rURL, const OUString& rRange, const OUString& rMove, sal_uInt32 nSettings);
void MoveData(); void MoveData();
public: public:
enum MoveEnum { NO_MOVE, RANGE_DOWN, MOVE_DOWN, MOVE_UP }; enum MoveEnum { NO_MOVE, RANGE_DOWN, MOVE_DOWN, MOVE_UP };
enum { SCRIPT_STREAM = 1, VALUES_IN_LINE = 2 };
static void Set(ScDocShell *pShell, const OUString& rURL, static void MakeToolbarVisible(ScDocShell *pShell);
const OUString& rRange, sal_Int32 nLimit, const OUString& rMove); static DataStream* Set(ScDocShell *pShell, const OUString& rURL, const OUString& rRange,
sal_Int32 nLimit, const OUString& rMove, sal_uInt32 nSettings);
DataStream(ScDocShell *pShell, const OUString& rURL, DataStream(ScDocShell *pShell, const OUString& rURL, const OUString& rRange,
const OUString& rRange, sal_Int32 nLimit, const OUString& rMove); sal_Int32 nLimit, const OUString& rMove, sal_uInt32 nSettings);
virtual ~DataStream() SAL_OVERRIDE; virtual ~DataStream() SAL_OVERRIDE;
virtual sfx2::SvBaseLink::UpdateResult DataChanged(
const OUString& , const css::uno::Any& ) SAL_OVERRIDE;
virtual void Edit(Window* , const Link& ) SAL_OVERRIDE; virtual void Edit(Window* , const Link& ) SAL_OVERRIDE;
bool ImportData(); bool ImportData();
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include <datastreamdlg.hxx> #include <datastreamdlg.hxx>
#include <sfx2/filedlghelper.hxx> #include <sfx2/filedlghelper.hxx>
#include <sfx2/linkmgr.hxx>
#include <svtools/inettbc.hxx> #include <svtools/inettbc.hxx>
#include <vcl/layout.hxx> #include <vcl/layout.hxx>
#include <datastream.hxx> #include <datastream.hxx>
...@@ -84,15 +83,21 @@ void DataStreamDlg::StartStream() ...@@ -84,15 +83,21 @@ void DataStreamDlg::StartStream()
if (m_pRBMaxLimit->IsChecked()) if (m_pRBMaxLimit->IsChecked())
nLimit = m_pEdLimit->GetText().toInt32(); nLimit = m_pEdLimit->GetText().toInt32();
OUString rURL = m_pCbUrl->GetText(); OUString rURL = m_pCbUrl->GetText();
sal_uInt32 nSettings = 0;
if (m_pRBScriptData->IsChecked()) if (m_pRBScriptData->IsChecked())
rURL += OUString(sfx2::cTokenSeparator); nSettings |= DataStream::SCRIPT_STREAM;
DataStream::Set( mpDocShell, if (m_pRBValuesInLine->IsChecked())
nSettings |= DataStream::VALUES_IN_LINE;
DataStream *pStream = DataStream::Set( mpDocShell,
rURL, rURL,
m_pEdRange->GetText(), m_pEdRange->GetText(),
nLimit, nLimit,
m_pRBNoMove->IsChecked() ? OUString("NO_MOVE") : m_pRBRangeDown->IsChecked() m_pRBNoMove->IsChecked() ? OUString("NO_MOVE") : m_pRBRangeDown->IsChecked()
? OUString("RANGE_DOWN") : OUString("MOVE_DOWN") ? OUString("RANGE_DOWN") : OUString("MOVE_DOWN")
, nSettings
); );
DataStream::MakeToolbarVisible( mpDocShell );
pStream->Start();
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment