summaryrefslogtreecommitdiff
path: root/sc/source/ui
diff options
context:
space:
mode:
authorJaskaran Singh <jvsg1303@gmail.com>2017-08-07 23:39:39 +0530
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2017-08-10 18:53:31 +0200
commit213a83ce46edf1b81f2285fd59f1d04935760caa (patch)
tree29355aa1f1242661d4055c8e561746473945931e /sc/source/ui
parent772686adb99137733db79b7d1ab6ebb21bf93b4a (diff)
Add UI for the sc::dataprovider
Change-Id: I29acc8903d5694e46e7575133ee852bbaae6eeee Reviewed-on: https://gerrit.libreoffice.org/40851 Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com> Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'sc/source/ui')
-rw-r--r--sc/source/ui/docshell/dataprovider.cxx4
-rw-r--r--sc/source/ui/inc/dataproviderdlg.hxx69
-rw-r--r--sc/source/ui/miscdlgs/dataproviderdlg.cxx171
-rw-r--r--sc/source/ui/view/cellsh2.cxx17
4 files changed, 261 insertions, 0 deletions
diff --git a/sc/source/ui/docshell/dataprovider.cxx b/sc/source/ui/docshell/dataprovider.cxx
index 2ce549156146..703bf6b363e6 100644
--- a/sc/source/ui/docshell/dataprovider.cxx
+++ b/sc/source/ui/docshell/dataprovider.cxx
@@ -65,6 +65,10 @@ ExternalDataSource::ExternalDataSource(const OUString& rURL,
{
}
+ExternalDataSource::~ExternalDataSource()
+{
+}
+
void ExternalDataSource::setID(const OUString& rID)
{
maID = rID;
diff --git a/sc/source/ui/inc/dataproviderdlg.hxx b/sc/source/ui/inc/dataproviderdlg.hxx
new file mode 100644
index 000000000000..05e607157931
--- /dev/null
+++ b/sc/source/ui/inc/dataproviderdlg.hxx
@@ -0,0 +1,69 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_SC_SOURCE_UI_INC_DATAPROVIDERDLG_HXX
+#define INCLUDED_SC_SOURCE_UI_INC_DATAPROVIDERDLG_HXX
+
+#include <sal/config.h>
+
+#include <rtl/ref.hxx>
+#include <vcl/dialog.hxx>
+#include <vcl/layout.hxx>
+
+#include "address.hxx"
+#include "datamapper.hxx"
+#include "dataprovider.hxx"
+
+class ScDocShell;
+class SvtURLBox;
+class ScRange;
+class ComboBox;
+
+namespace sc {
+
+class DataProviderDlg : public ModalDialog
+{
+ ScDocShell *mpDocShell;
+
+ VclPtr<SvtURLBox> m_pCbUrl;
+ VclPtr<PushButton> m_pBtnBrowse;
+ VclPtr<RadioButton> m_pRBAddressValue;
+ VclPtr<CheckBox> m_pCBRefreshOnEmpty;
+ VclPtr<RadioButton> m_pRBMaxLimit;
+ VclPtr<RadioButton> m_pRBUnlimited;
+ VclPtr<Edit> m_pEdRange;
+ VclPtr<Edit> m_pEdLimit;
+ VclPtr<OKButton> m_pBtnOk;
+ VclPtr<VclFrame> m_pVclFrameLimit;
+
+ DECL_LINK(UpdateClickHdl, Button*, void);
+ DECL_LINK(UpdateHdl, Edit&, void);
+ DECL_LINK(UpdateComboBoxHdl, ComboBox&, void);
+ DECL_LINK(BrowseHdl, Button*, void);
+
+ void UpdateEnable();
+ ScRange GetStartRange();
+
+ std::shared_ptr<ExternalDataSource> mpDataSource;
+
+public:
+ DataProviderDlg(ScDocShell *pDocShell, vcl::Window* pParent);
+ virtual ~DataProviderDlg() override;
+ virtual void dispose() override;
+
+ void Init();
+
+ void StartImport();
+};
+
+}
+
+#endif // INCLUDED_SC_SOURCE_UI_INC_DATAPROVIDERDLG_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/miscdlgs/dataproviderdlg.cxx b/sc/source/ui/miscdlgs/dataproviderdlg.cxx
new file mode 100644
index 000000000000..ae0427217ed9
--- /dev/null
+++ b/sc/source/ui/miscdlgs/dataproviderdlg.cxx
@@ -0,0 +1,171 @@
+/* -*- 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 <dataproviderdlg.hxx>
+
+#include <sfx2/filedlghelper.hxx>
+#include <svtools/inettbc.hxx>
+#include <vcl/layout.hxx>
+#include <address.hxx>
+#include <docsh.hxx>
+#include <dbdata.hxx>
+#include "datamapper.hxx"
+
+namespace sc {
+
+DataProviderDlg::DataProviderDlg(ScDocShell *pDocShell, vcl::Window* pParent)
+ : ModalDialog(pParent, "DataProviderDialog", "modules/scalc/ui/dataprovider.ui")
+ , mpDocShell(pDocShell)
+{
+ get(m_pCbUrl, "url");
+ get(m_pBtnBrowse, "browse");
+ get(m_pRBAddressValue, "addressvalue");
+ get(m_pCBRefreshOnEmpty, "refresh_ui");
+ //get(m_pRBRangeDown, "rangedown");
+ //get(m_pRBNoMove, "nomove");
+ get(m_pRBMaxLimit, "maxlimit");
+ get(m_pRBUnlimited, "unlimited");
+ get(m_pEdRange, "range");
+ get(m_pEdLimit, "limit");
+ get(m_pBtnOk, "ok");
+ get(m_pVclFrameLimit, "framelimit");
+ //get(m_pVclFrameMove, "framemove");
+
+ m_pCbUrl->SetSelectHdl( LINK( this, DataProviderDlg, UpdateComboBoxHdl ) );
+ m_pRBAddressValue->SetClickHdl( LINK( this, DataProviderDlg, UpdateClickHdl ) );
+ m_pRBAddressValue->Enable(false);
+ //m_pRBScriptData->Enable(false);
+ //m_pRBDirectData->Hide();
+ //m_pRBScriptData->Hide();
+ //m_pRBNoMove->Hide();
+ //m_pRBValuesInLine->SetClickHdl( LINK( this, DataProviderDlg, UpdateClickHdl ) );
+ m_pEdRange->SetModifyHdl( LINK( this, DataProviderDlg, UpdateHdl ) );
+ m_pBtnBrowse->SetClickHdl( LINK( this, DataProviderDlg, BrowseHdl ) );
+ UpdateEnable();
+}
+
+DataProviderDlg::~DataProviderDlg()
+{
+ disposeOnce();
+}
+
+void DataProviderDlg::dispose()
+{
+ m_pCbUrl.clear();
+ m_pBtnBrowse.clear();
+ //m_pRBDirectData.clear();
+ //m_pRBScriptData.clear();
+ //m_pRBValuesInLine.clear();
+ m_pRBAddressValue.clear();
+ m_pCBRefreshOnEmpty.clear();
+ //m_pRBDataDown.clear();
+ //m_pRBRangeDown.clear();
+ //m_pRBNoMove.clear();
+ m_pRBMaxLimit.clear();
+ m_pRBUnlimited.clear();
+ m_pEdRange.clear();
+ m_pEdLimit.clear();
+ m_pBtnOk.clear();
+ m_pVclFrameLimit.clear();
+ //m_pVclFrameMove.clear();
+ ModalDialog::dispose();
+}
+
+IMPL_LINK_NOARG(DataProviderDlg, BrowseHdl, Button*, void)
+{
+ sfx2::FileDialogHelper aFileDialog(0);
+ if ( aFileDialog.Execute() != ERRCODE_NONE )
+ return;
+
+ m_pCbUrl->SetText( aFileDialog.GetPath() );
+ UpdateEnable();
+}
+
+IMPL_LINK_NOARG(DataProviderDlg, UpdateClickHdl, Button*, void)
+{
+ UpdateEnable();
+}
+IMPL_LINK_NOARG(DataProviderDlg, UpdateComboBoxHdl, ComboBox&, void)
+{
+ UpdateEnable();
+}
+IMPL_LINK_NOARG(DataProviderDlg, UpdateHdl, Edit&, void)
+{
+ UpdateEnable();
+}
+
+void DataProviderDlg::UpdateEnable()
+{
+ bool bOk = !m_pCbUrl->GetURL().isEmpty();
+ if (m_pRBAddressValue->IsChecked())
+ {
+ m_pVclFrameLimit->Disable();
+ //m_pVclFrameMove->Disable();
+ m_pEdRange->Disable();
+ }
+ else
+ {
+ m_pVclFrameLimit->Enable();
+ //m_pVclFrameMove->Enable();
+ m_pEdRange->Enable();
+ if (bOk)
+ {
+ // Check the given range to make sure it's valid.
+ ScRange aTest = GetStartRange();
+ if (!aTest.IsValid())
+ bOk = false;
+ }
+ }
+ m_pBtnOk->Enable(bOk);
+ setOptimalLayoutSize();
+}
+
+ScRange DataProviderDlg::GetStartRange()
+{
+ OUString aStr = m_pEdRange->GetText();
+ ScDocument& rDoc = mpDocShell->GetDocument();
+ ScRange aRange;
+ ScRefFlags nRes = aRange.Parse(aStr, &rDoc, rDoc.GetAddressConvention());
+ if ( ((nRes & ScRefFlags::VALID) == ScRefFlags::ZERO) || !aRange.IsValid())
+ {
+ // Invalid range.
+ aRange.SetInvalid();
+ return aRange;
+ }
+
+ // Make sure it's only one row tall.
+ if (aRange.aStart.Row() != aRange.aEnd.Row())
+ aRange.SetInvalid();
+
+ return aRange;
+}
+
+void DataProviderDlg::Init()
+{
+ // TODO : Get the user specified Url and Range
+ (void)this;
+}
+
+void DataProviderDlg::StartImport()
+{
+ ScRange aRange = GetStartRange();
+ if (!aRange.IsValid())
+ // Don't start the stream without a valid range.
+ return;
+
+ OUString aURL;
+ // TODO : replace those strings with something that is obtained from user
+ ExternalDataSource aDataSource(aURL, "org.libreoffice.calc.csv");
+ //aDataSource.setDBData(pDBData);
+ mpDocShell->GetDocument().GetExternalDataMapper().insertDataSource(aDataSource);
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/view/cellsh2.cxx b/sc/source/ui/view/cellsh2.cxx
index 6b3fd6245ba0..7866f7693e9f 100644
--- a/sc/source/ui/view/cellsh2.cxx
+++ b/sc/source/ui/view/cellsh2.cxx
@@ -62,6 +62,7 @@
#include "asciiopt.hxx"
#include "datastream.hxx"
#include "datastreamdlg.hxx"
+#include "dataproviderdlg.hxx"
#include "queryentry.hxx"
#include "markdata.hxx"
#include <documentlinkmgr.hxx>
@@ -778,6 +779,20 @@ void ScCellShell::ExecuteDB( SfxRequest& rReq )
pStrm->StopImport();
}
break;
+ case SID_DATA_PROVIDER:
+ {
+ ScopedVclPtrInstance< sc::DataProviderDlg > aDialog( GetViewData()->GetDocShell(), pTabViewShell->GetDialogParent() );
+ //ScDocument *pDoc = GetViewData()->GetDocument();
+ //sc::DocumentLinkManager& rMgr = pDoc->GetDocLinkManager();
+ //sc::DataStream* pStrm = rMgr.getDataStream();
+ //if (pStrm)
+ aDialog->Init(/**pStrm*/);
+ aDialog->Execute();
+
+ //if (aDialog->Execute() == RET_OK)
+ //aDialog->StartStream();
+ }
+ break;
case SID_MANAGE_XML_SOURCE:
ExecuteXMLSourceDialog();
break;
@@ -1184,6 +1199,8 @@ void ScCellShell::GetDBState( SfxItemSet& rSet )
}
}
break;
+ case SID_DATA_PROVIDER:
+ break;
case SID_DATA_STREAMS:
case SID_DATA_STREAMS_PLAY:
case SID_DATA_STREAMS_STOP: