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 @@
#include "columniterator.hxx"
#include "globalnames.hxx"
#include "stringutil.hxx"
#include <datastream.hxx>
#include <memory>
#include <boost/scoped_ptr.hpp>
......@@ -1193,7 +1194,7 @@ bool ScDocument::HasAreaLinks() const
const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
sal_uInt16 nCount = rLinks.size();
for (sal_uInt16 i=0; i<nCount; i++)
if ((*rLinks[i])->ISA(ScAreaLink))
if ((*rLinks[i])->ISA(ScAreaLink) || (*rLinks[i])->ISA(DataStream))
return true;
}
......@@ -1208,7 +1209,7 @@ void ScDocument::UpdateAreaLinks()
for (sal_uInt16 i=0; i<rLinks.size(); i++)
{
::sfx2::SvBaseLink* pBase = *rLinks[i];
if (pBase->ISA(ScAreaLink))
if (pBase->ISA(ScAreaLink) || (*rLinks[i])->ISA(DataStream))
pBase->Update();
}
}
......
......@@ -52,6 +52,8 @@
#include "tokenarray.hxx"
#include "scmatrix.hxx"
#include "documentimport.hxx"
#include <datastream.hxx>
#include <rangeutl.hxx>
#include <xmloff/xmltkmap.hxx>
#include <xmloff/xmltoken.hxx>
......@@ -997,6 +999,19 @@ void ScXMLTableRowCellContext::SetCellRangeSource( const ScAddress& rPosition )
rPosition.Row() + static_cast<SCROW>(pCellRangeSource->nRows - 1), rPosition.Tab() );
OUString sFilterName( pCellRangeSource->sFilterName );
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,
sFilterName, pCellRangeSource->sFilterOptions, sSourceStr, aDestRange, pCellRangeSource->nRefresh );
sfx2::LinkManager* pLinkManager = pDoc->GetLinkManager();
......
......@@ -138,10 +138,10 @@ private:
}
static void lcl_MakeToolbarVisible(SfxViewFrame *pViewFrame)
void DataStream::MakeToolbarVisible(ScDocShell *pShell)
{
css::uno::Reference< css::frame::XFrame > xFrame =
pViewFrame->GetFrame().GetFrameInterface();
pShell->GetViewData()->GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface();
if (!xFrame.is())
return;
......@@ -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;
pLink = new DataStream( pShell, rURL, rRange, nLimit, rMove );
pLink = new DataStream( pShell, rURL, rRange, nLimit, rMove, nSettings );
sfx2::LinkManager* pLinkManager = pShell->GetDocument()->GetLinkManager();
pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, rURL, NULL, NULL );
lcl_MakeToolbarVisible(pShell->GetViewData()->GetViewShell()->GetViewFrame());
return dynamic_cast<DataStream*>(pLink);
}
DataStream::DataStream(ScDocShell *pShell, const OUString& rURL,
const OUString& rRange, sal_Int32 nLimit, const OUString& rMove)
DataStream::DataStream(ScDocShell *pShell, const OUString& rURL, const OUString& rRange,
sal_Int32 nLimit, const OUString& rMove, sal_uInt32 nSettings)
: mpScDocShell(pShell)
, mpScDocument(mpScDocShell->GetDocument())
, meMove(NO_MOVE)
......@@ -187,7 +187,7 @@ DataStream::DataStream(ScDocShell *pShell, const OUString& rURL,
mxThread = new datastreams::CallerThread( this );
mxThread->launch();
Decode(rURL, rRange, rMove);
Decode(rURL, rRange, rMove, nSettings);
mpStartRange.reset( new ScRange(*mpRange.get()) );
sal_Int32 nHeight = mpRange->aEnd.Row() - mpRange->aStart.Row() + 1;
......@@ -215,6 +215,8 @@ OString DataStream::ConsumeLine()
if (!mpLines || mnLinesCount >= mpLines->size())
{
mnLinesCount = 0;
if (mxReaderThread->mbTerminateReading)
return OString();
osl::ResettableMutexGuard aGuard(mxReaderThread->maLinesProtector);
if (mpLines)
mxReaderThread->maUsedLines.push(mpLines);
......@@ -233,18 +235,18 @@ OString DataStream::ConsumeLine()
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;
if (nIndex != -1)
pStream = new SvScriptStream(rURL.copy(0, nIndex));
if (nSettings & SCRIPT_STREAM)
pStream = new SvScriptStream(rURL);
else
pStream = new SvFileStream(rURL, STREAM_READ);
mxReaderThread = new datastreams::ReaderThread( pStream );
mxReaderThread->launch();
mbValuesInLine = !rRange.isEmpty();
mbValuesInLine = nSettings & VALUES_IN_LINE;
if (!mbValuesInLine)
return;
......@@ -361,6 +363,14 @@ bool DataStream::ImportData()
return mbRunning;
}
sfx2::SvBaseLink::UpdateResult DataStream::DataChanged(
const OUString& , const css::uno::Any& )
{
MakeToolbarVisible(mpScDocShell);
Start();
return SUCCESS;
}
void DataStream::Edit(Window* , const Link& )
{
}
......
......@@ -31,18 +31,22 @@ typedef std::vector<OString> LinesList;
class DataStream : boost::noncopyable, public sfx2::SvBaseLink
{
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();
public:
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,
const OUString& rRange, sal_Int32 nLimit, const OUString& rMove);
static void MakeToolbarVisible(ScDocShell *pShell);
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,
const OUString& rRange, sal_Int32 nLimit, const OUString& rMove);
DataStream(ScDocShell *pShell, const OUString& rURL, const OUString& rRange,
sal_Int32 nLimit, const OUString& rMove, sal_uInt32 nSettings);
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;
bool ImportData();
......
......@@ -10,7 +10,6 @@
#include <datastreamdlg.hxx>
#include <sfx2/filedlghelper.hxx>
#include <sfx2/linkmgr.hxx>
#include <svtools/inettbc.hxx>
#include <vcl/layout.hxx>
#include <datastream.hxx>
......@@ -84,15 +83,21 @@ void DataStreamDlg::StartStream()
if (m_pRBMaxLimit->IsChecked())
nLimit = m_pEdLimit->GetText().toInt32();
OUString rURL = m_pCbUrl->GetText();
sal_uInt32 nSettings = 0;
if (m_pRBScriptData->IsChecked())
rURL += OUString(sfx2::cTokenSeparator);
DataStream::Set( mpDocShell,
nSettings |= DataStream::SCRIPT_STREAM;
if (m_pRBValuesInLine->IsChecked())
nSettings |= DataStream::VALUES_IN_LINE;
DataStream *pStream = DataStream::Set( mpDocShell,
rURL,
m_pEdRange->GetText(),
nLimit,
m_pRBNoMove->IsChecked() ? OUString("NO_MOVE") : m_pRBRangeDown->IsChecked()
? OUString("RANGE_DOWN") : OUString("MOVE_DOWN")
, nSettings
);
DataStream::MakeToolbarVisible( mpDocShell );
pStream->Start();
}
/* 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