Kaydet (Commit) 47bc5672 authored tarafından Matúš Kukan's avatar Matúš Kukan

Rework data streams to be more like file links (ScAreaLink).

By inheriting from sfx2::SvBaseLink and storing in sfx2::LinkManager we can
have more data streams and see / remove them in Edit -> Links... dialog.
Also rename to DataStream to avoid confusion.

Change-Id: I9c3b89020324af7be082f9e6e1cd479aeb72fe81
üst 4cbc3d85
......@@ -385,6 +385,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
sc/source/ui/dialogs/searchresults \
sc/source/ui/docshell/arealink \
sc/source/ui/docshell/autostyl \
sc/source/ui/docshell/datastream \
sc/source/ui/docshell/dbdocfun \
sc/source/ui/docshell/dbdocimp \
sc/source/ui/docshell/docfunc \
......@@ -443,8 +444,7 @@ $(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/datastreamdlg \
sc/source/ui/miscdlgs/highred \
sc/source/ui/miscdlgs/optsolver \
sc/source/ui/miscdlgs/protectiondlg \
......
......@@ -7,13 +7,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <datastreams.hxx>
#include <datastream.hxx>
#include <com/sun/star/frame/XLayoutManager.hpp>
#include <com/sun/star/ui/XUIElement.hpp>
#include <osl/conditn.hxx>
#include <rtl/strbuf.hxx>
#include <salhelper/thread.hxx>
#include <sfx2/linkmgr.hxx>
#include <sfx2/viewfrm.hxx>
#include <asciiopt.hxx>
#include <dbfunc.hxx>
......@@ -30,14 +31,14 @@ namespace datastreams {
class CallerThread : public salhelper::Thread
{
DataStreams *mpDataStreams;
DataStream *mpDataStream;
public:
osl::Condition maStart;
bool mbTerminate;
CallerThread(DataStreams *pData):
CallerThread(DataStream *pData):
Thread("CallerThread")
,mpDataStreams(pData)
,mpDataStream(pData)
,mbTerminate(false)
{}
......@@ -53,7 +54,7 @@ private:
maStart.wait();
maStart.reset();
if (!mbTerminate)
while (mpDataStreams->ImportData())
while (mpDataStream->ImportData())
wait(aTime);
};
}
......@@ -137,19 +138,68 @@ private:
}
DataStreams::DataStreams(ScDocShell *pScDocShell):
mpScDocShell(pScDocShell)
static void lcl_MakeToolbarVisible(SfxViewFrame *pViewFrame)
{
css::uno::Reference< css::frame::XFrame > xFrame =
pViewFrame->GetFrame().GetFrameInterface();
if (!xFrame.is())
return;
css::uno::Reference< css::beans::XPropertySet > xPropSet(xFrame, css::uno::UNO_QUERY);
if (!xPropSet.is())
return;
css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
xPropSet->getPropertyValue("LayoutManager") >>= xLayoutManager;
if (!xLayoutManager.is())
return;
const OUString sResourceURL( "private:resource/toolbar/datastreams" );
css::uno::Reference< css::ui::XUIElement > xUIElement = xLayoutManager->getElement(sResourceURL);
if (!xUIElement.is())
{
xLayoutManager->createElement( sResourceURL );
xLayoutManager->showElement( sResourceURL );
}
}
void DataStream::Set(ScDocShell *pShell, const OUString& rURL, const OUString& rRange, sal_Int32 nLimit, const OUString& rMove)
{
sfx2::SvBaseLink *pLink = 0;
pLink = new DataStream( pShell, rURL, rRange, nLimit, rMove );
sfx2::LinkManager* pLinkManager = pShell->GetDocument()->GetLinkManager();
pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, rURL, NULL, NULL );
lcl_MakeToolbarVisible(pShell->GetViewData()->GetViewShell()->GetViewFrame());
}
DataStream::DataStream(ScDocShell *pShell, const OUString& rURL,
const OUString& rRange, sal_Int32 nLimit, const OUString& rMove)
: mpScDocShell(pShell)
, mpScDocument(mpScDocShell->GetDocument())
, meMove(NO_MOVE)
, mbRunning(false)
, mpLines(0)
, mnLinesCount(0)
, mpRange(new ScRange())
, mpEndRange(NULL)
{
mxThread = new datastreams::CallerThread( this );
mxThread->launch();
Decode(rURL, rRange, rMove);
mpStartRange.reset( new ScRange(*mpRange.get()) );
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) );
mpEndRange->Move(0, nLimit - nHeight, 0);
}
}
DataStreams::~DataStreams()
DataStream::~DataStream()
{
if (mbRunning)
Stop();
......@@ -160,7 +210,7 @@ DataStreams::~DataStreams()
mxReaderThread->endThread();
}
OString DataStreams::ConsumeLine()
OString DataStream::ConsumeLine()
{
if (!mpLines || mnLinesCount >= mpLines->size())
{
......@@ -183,7 +233,32 @@ OString DataStreams::ConsumeLine()
return mpLines->at(mnLinesCount++);
}
void DataStreams::Start()
void DataStream::Decode( const OUString& rURL, const OUString& rRange, const OUString& rMove)
{
sal_Int32 nIndex = rURL.indexOf(sfx2::cTokenSeparator);
SvStream *pStream = 0;
if (nIndex != -1)
pStream = new SvScriptStream(rURL.copy(0, nIndex));
else
pStream = new SvFileStream(rURL, STREAM_READ);
mxReaderThread = new datastreams::ReaderThread( pStream );
mxReaderThread->launch();
mbValuesInLine = !rRange.isEmpty();
if (!mbValuesInLine)
return;
mpRange->Parse(rRange, mpScDocument);
if (rMove == "NO_MOVE")
meMove = NO_MOVE;
else if (rMove == "RANGE_DOWN")
meMove = RANGE_DOWN;
else if (rMove == "MOVE_DOWN")
meMove = MOVE_DOWN;
}
void DataStream::Start()
{
if (mbRunning)
return;
......@@ -191,30 +266,9 @@ void DataStreams::Start()
mpScDocument->EnableUndo(false);
mbRunning = true;
mxThread->maStart.set();
css::uno::Reference< css::frame::XFrame > xFrame =
mpScDocShell->GetViewData()->GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface();
if (!xFrame.is())
return;
css::uno::Reference< css::beans::XPropertySet > xPropSet(xFrame, css::uno::UNO_QUERY);
if (!xPropSet.is())
return;
css::uno::Reference< css::frame::XLayoutManager > xLayoutManager;
xPropSet->getPropertyValue("LayoutManager") >>= xLayoutManager;
if (!xLayoutManager.is())
return;
const OUString sResourceURL( "private:resource/toolbar/datastreams" );
css::uno::Reference< css::ui::XUIElement > xUIElement = xLayoutManager->getElement(sResourceURL);
if (!xUIElement.is())
{
xLayoutManager->createElement( sResourceURL );
xLayoutManager->showElement( sResourceURL );
}
}
void DataStreams::Stop()
void DataStream::Stop()
{
if (!mbRunning)
return;
......@@ -222,36 +276,7 @@ void DataStreams::Stop()
mpScDocument->EnableUndo(mbIsUndoEnabled);
}
void DataStreams::Set(SvStream *pStream, bool bValuesInLine,
const OUString& rRange, sal_Int32 nLimit, MoveEnum eMove)
{
if (mxReaderThread.is())
mxReaderThread->endThread();
mxReaderThread = new datastreams::ReaderThread( pStream );
mxReaderThread->launch();
mpEndRange.reset( NULL );
mpRange.reset ( new ScRange() );
mbValuesInLine = bValuesInLine;
if (!mbValuesInLine)
{
meMove = NO_MOVE;
return;
}
mpRange->Parse(rRange, mpScDocument);
mpStartRange.reset( new ScRange(*mpRange.get()) );
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) );
mpEndRange->Move(0, nLimit - nHeight, 0);
}
}
void DataStreams::MoveData()
void DataStream::MoveData()
{
switch (meMove)
{
......@@ -273,7 +298,7 @@ void DataStreams::MoveData()
}
}
bool DataStreams::ImportData()
bool DataStream::ImportData()
{
SolarMutexGuard aGuard;
MoveData();
......@@ -336,4 +361,8 @@ bool DataStreams::ImportData()
return mbRunning;
}
void DataStream::Edit(Window* , const Link& )
{
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -33,19 +33,16 @@ 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 ) {}
};
......
......@@ -11,6 +11,7 @@
#include <rtl/ref.hxx>
#include <rtl/ustring.hxx>
#include <sfx2/lnkbase.hxx>
#include <boost/noncopyable.hpp>
#include <boost/scoped_ptr.hpp>
......@@ -23,23 +24,28 @@ namespace datastreams {
class ScDocShell;
class ScDocument;
class ScRange;
class SvStream;
class Window;
typedef std::vector<OString> LinesList;
class DataStreams : boost::noncopyable
class DataStream : boost::noncopyable, public sfx2::SvBaseLink
{
OString ConsumeLine();
void Decode(const OUString& rURL, const OUString& rRange, const OUString& rMove);
void MoveData();
public:
enum MoveEnum { NO_MOVE, RANGE_DOWN, MOVE_DOWN, MOVE_UP };
DataStreams(ScDocShell *pScDocShell);
~DataStreams();
OString ConsumeLine();
static void Set(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);
virtual ~DataStream() SAL_OVERRIDE;
virtual void Edit(Window* , const Link& ) SAL_OVERRIDE;
bool ImportData();
void MoveData();
void Set(SvStream *pStream, bool bValuesInLine,
const OUString& rRange, sal_Int32 nLimit, MoveEnum eMove);
void ShowDialog(Window *pParent);
void Start();
void Stop();
......
/* -*- 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 <vcl/dialog.hxx>
#include <vcl/layout.hxx>
class ScDocShell;
class SvtURLBox;
class DataStreamDlg : public ModalDialog
{
ScDocShell *mpDocShell;
SvtURLBox* m_pCbUrl;
PushButton* m_pBtnBrowse;
RadioButton* m_pRBScriptData;
RadioButton* m_pRBValuesInLine;
RadioButton* m_pRBAddressValue;
RadioButton* m_pRBRangeDown;
RadioButton* m_pRBNoMove;
RadioButton* m_pRBMaxLimit;
Edit* m_pEdRange;
Edit* m_pEdLimit;
OKButton* m_pBtnOk;
VclFrame* m_pVclFrameLimit;
VclFrame* m_pVclFrameMove;
VclFrame* m_pVclFrameRange;
DECL_LINK(UpdateHdl, void *);
DECL_LINK(BrowseHdl, void *);
void UpdateEnable();
public:
DataStreamDlg(ScDocShell *pDocShell, Window* pParent);
~DataStreamDlg() {}
void StartStream();
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -7,47 +7,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <datastreamdlg.hxx>
#include <sfx2/filedlghelper.hxx>
#include <sfx2/linkmgr.hxx>
#include <svtools/inettbc.hxx>
#include <vcl/dialog.hxx>
#include <vcl/layout.hxx>
#include <datastreams.hxx>
namespace {
class DataStreamsDlg : public ModalDialog
{
DataStreams *mpDataStreams;
SvtURLBox* m_pCbUrl;
PushButton* m_pBtnBrowse;
RadioButton* m_pRBScriptData;
RadioButton* m_pRBValuesInLine;
RadioButton* m_pRBAddressValue;
RadioButton* m_pRBRangeDown;
RadioButton* m_pRBNoMove;
RadioButton* m_pRBMaxLimit;
Edit* m_pEdRange;
Edit* m_pEdLimit;
OKButton* m_pBtnOk;
VclFrame* m_pVclFrameLimit;
VclFrame* m_pVclFrameMove;
VclFrame* m_pVclFrameRange;
#include <datastream.hxx>
DECL_LINK(UpdateHdl, void *);
DECL_LINK(BrowseHdl, void *);
void UpdateEnable();
public:
DataStreamsDlg(DataStreams *pDataStreams, Window* pParent);
~DataStreamsDlg() {}
void Start();
};
DataStreamsDlg::DataStreamsDlg(DataStreams *pDataStreams, Window* pParent)
: ModalDialog(pParent, "DataStreamsDialog", "modules/scalc/ui/datastreams.ui")
, mpDataStreams(pDataStreams)
DataStreamDlg::DataStreamDlg(ScDocShell *pDocShell, Window* pParent)
: ModalDialog(pParent, "DataStreamDialog", "modules/scalc/ui/datastreams.ui")
, mpDocShell(pDocShell)
{
get(m_pCbUrl, "url");
get(m_pBtnBrowse, "browse");
......@@ -64,30 +34,15 @@ DataStreamsDlg::DataStreamsDlg(DataStreams *pDataStreams, Window* pParent)
get(m_pVclFrameMove, "framemove");
get(m_pVclFrameRange, "framerange");
m_pCbUrl->SetSelectHdl( LINK( this, DataStreamsDlg, UpdateHdl ) );
m_pRBAddressValue->SetClickHdl( LINK( this, DataStreamsDlg, UpdateHdl ) );
m_pRBValuesInLine->SetClickHdl( LINK( this, DataStreamsDlg, UpdateHdl ) );
m_pEdRange->SetModifyHdl( LINK( this, DataStreamsDlg, UpdateHdl ) );
m_pBtnBrowse->SetClickHdl( LINK( this, DataStreamsDlg, BrowseHdl ) );
m_pCbUrl->SetSelectHdl( LINK( this, DataStreamDlg, UpdateHdl ) );
m_pRBAddressValue->SetClickHdl( LINK( this, DataStreamDlg, UpdateHdl ) );
m_pRBValuesInLine->SetClickHdl( LINK( this, DataStreamDlg, UpdateHdl ) );
m_pEdRange->SetModifyHdl( LINK( this, DataStreamDlg, UpdateHdl ) );
m_pBtnBrowse->SetClickHdl( LINK( this, DataStreamDlg, BrowseHdl ) );
UpdateEnable();
}
void DataStreamsDlg::Start()
{
sal_Int32 nLimit = 0;
if (m_pRBMaxLimit->IsChecked())
nLimit = m_pEdLimit->GetText().toInt32();
mpDataStreams->Set(
(m_pRBScriptData->IsChecked() ?
dynamic_cast<SvStream*>( new SvScriptStream(m_pCbUrl->GetText()) ) :
dynamic_cast<SvStream*>( new SvFileStream(m_pCbUrl->GetText(), STREAM_READ) )),
m_pRBValuesInLine->IsChecked(),
m_pEdRange->GetText(), nLimit, (m_pRBNoMove->IsChecked() ? DataStreams::NO_MOVE :
m_pRBRangeDown->IsChecked() ? DataStreams::RANGE_DOWN : DataStreams::MOVE_DOWN) );
mpDataStreams->Start();
}
IMPL_LINK_NOARG(DataStreamsDlg, BrowseHdl)
IMPL_LINK_NOARG(DataStreamDlg, BrowseHdl)
{
sfx2::FileDialogHelper aFileDialog(0, 0);
if ( aFileDialog.Execute() != ERRCODE_NONE )
......@@ -98,13 +53,13 @@ IMPL_LINK_NOARG(DataStreamsDlg, BrowseHdl)
return 0;
}
IMPL_LINK_NOARG(DataStreamsDlg, UpdateHdl)
IMPL_LINK_NOARG(DataStreamDlg, UpdateHdl)
{
UpdateEnable();
return 0;
}
void DataStreamsDlg::UpdateEnable()
void DataStreamDlg::UpdateEnable()
{
bool bOk = !m_pCbUrl->GetURL().isEmpty();
if (m_pRBAddressValue->IsChecked())
......@@ -123,13 +78,21 @@ void DataStreamsDlg::UpdateEnable()
m_pBtnOk->Enable(bOk);
}
}
void DataStreams::ShowDialog(Window *pParent)
void DataStreamDlg::StartStream()
{
DataStreamsDlg aDialog(this, pParent);
if (aDialog.Execute() == RET_OK)
aDialog.Start();
sal_Int32 nLimit = 0;
if (m_pRBMaxLimit->IsChecked())
nLimit = m_pEdLimit->GetText().toInt32();
OUString rURL = m_pCbUrl->GetText();
if (m_pRBScriptData->IsChecked())
rURL += OUString(sfx2::cTokenSeparator);
DataStream::Set( mpDocShell,
rURL,
m_pEdRange->GetText(),
nLimit,
m_pRBNoMove->IsChecked() ? OUString("NO_MOVE") : m_pRBRangeDown->IsChecked()
? OUString("RANGE_DOWN") : OUString("MOVE_DOWN")
);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -55,7 +55,6 @@
#include "postit.hxx"
#include "cliputil.hxx"
#include "clipparam.hxx"
#include "datastreams.hxx"
#include "markdata.hxx"
//------------------------------------------------------------------
......@@ -99,7 +98,6 @@ ScCellShell::~ScCellShell()
}
delete pImpl->m_pLinkedDlg;
delete pImpl->m_pDataStreams;
delete pImpl->m_pRequest;
delete pImpl;
}
......
......@@ -20,6 +20,7 @@
#include "scitems.hxx"
#include <sfx2/viewfrm.hxx>
#include <sfx2/app.hxx>
#include <sfx2/linkmgr.hxx>
#include <sfx2/request.hxx>
#include <svl/aeitem.hxx>
#include <basic/sbxcore.hxx>
......@@ -56,7 +57,8 @@
#include "scabstdlg.hxx"
#include "impex.hxx"
#include "asciiopt.hxx"
#include "datastreams.hxx"
#include "datastream.hxx"
#include "datastreamdlg.hxx"
#include "queryentry.hxx"
#include "markdata.hxx"
......@@ -734,17 +736,35 @@ 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() );
{
DataStreamDlg aDialog( GetViewData()->GetDocShell(), pTabViewShell->GetDialogParent() );
if (aDialog.Execute() == RET_OK)
aDialog.StartStream();
}
break;
case SID_DATA_STREAMS_PLAY:
if (pImpl->m_pDataStreams)
pImpl->m_pDataStreams->Start();
{
ScDocument *pDoc = GetViewData()->GetDocument();
if (pDoc->GetLinkManager())
{
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();
}
}
break;
case SID_DATA_STREAMS_STOP:
if (pImpl->m_pDataStreams)
pImpl->m_pDataStreams->Stop();
{
ScDocument *pDoc = GetViewData()->GetDocument();
if (pDoc->GetLinkManager())
{
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();
}
}
break;
case SID_MANAGE_XML_SOURCE:
ExecuteXMLSourceDialog();
......
......@@ -2,7 +2,7 @@
<interface>
<!-- interface-requires gtk+ 3.0 -->
<!-- interface-requires LibreOffice 1.0 -->
<object class="GtkDialog" id="DataStreamsDialog">
<object class="GtkDialog" id="DataStreamDialog">
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="title" translatable="yes">Live Data Streams</property>
......
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