LibreOffice Module sc (master)  1
datastreamdlg.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  */
9 
10 #include <datastreamdlg.hxx>
11 
12 #include <sfx2/filedlghelper.hxx>
13 #include <svtools/inettbc.hxx>
14 #include <address.hxx>
15 #include <docsh.hxx>
16 #include <datastream.hxx>
17 
18 namespace sc
19 {
21  : GenericDialogController(pParent, "modules/scalc/ui/datastreams.ui", "DataStreamDialog")
22  , m_pDocShell(pDocShell)
23  , m_xCbUrl(new SvtURLBox(m_xBuilder->weld_combo_box("url")))
24  , m_xBtnBrowse(m_xBuilder->weld_button("browse"))
25  , m_xRBValuesInLine(m_xBuilder->weld_radio_button("valuesinline"))
26  , m_xRBAddressValue(m_xBuilder->weld_radio_button("addressvalue"))
27  , m_xCBRefreshOnEmpty(m_xBuilder->weld_check_button("refresh_ui"))
28  , m_xRBDataDown(m_xBuilder->weld_radio_button("datadown"))
29  , m_xRBRangeDown(m_xBuilder->weld_radio_button("rangedown"))
30  , m_xRBNoMove(m_xBuilder->weld_radio_button("nomove"))
31  , m_xRBMaxLimit(m_xBuilder->weld_radio_button("maxlimit"))
32  , m_xRBUnlimited(m_xBuilder->weld_radio_button("unlimited"))
33  , m_xEdRange(m_xBuilder->weld_entry("range"))
34  , m_xEdLimit(m_xBuilder->weld_entry("limit"))
35  , m_xBtnOk(m_xBuilder->weld_button("ok"))
36  , m_xVclFrameLimit(m_xBuilder->weld_frame("framelimit"))
37  , m_xVclFrameMove(m_xBuilder->weld_frame("framemove"))
38 {
39  m_xCbUrl->connect_changed(LINK(this, DataStreamDlg, UpdateComboBoxHdl));
40  m_xRBAddressValue->connect_toggled(LINK(this, DataStreamDlg, UpdateClickHdl));
41  m_xRBAddressValue->set_sensitive(false);
42  m_xRBNoMove->hide();
43  m_xRBValuesInLine->connect_toggled(LINK(this, DataStreamDlg, UpdateClickHdl));
44  m_xEdRange->connect_changed(LINK(this, DataStreamDlg, UpdateHdl));
45  m_xBtnBrowse->connect_clicked(LINK(this, DataStreamDlg, BrowseHdl));
46  UpdateEnable();
47 }
48 
50 
52 {
53  sfx2::FileDialogHelper aFileDialog(0, FileDialogFlags::NONE, m_xDialog.get());
55  if (aFileDialog.Execute() != ERRCODE_NONE)
56  return;
57 
58  m_xCbUrl->set_entry_text(aFileDialog.GetPath());
59  UpdateEnable();
60 }
61 
62 IMPL_LINK_NOARG(DataStreamDlg, UpdateClickHdl, weld::Toggleable&, void) { UpdateEnable(); }
63 
64 IMPL_LINK_NOARG(DataStreamDlg, UpdateComboBoxHdl, weld::ComboBox&, void) { UpdateEnable(); }
65 
66 IMPL_LINK_NOARG(DataStreamDlg, UpdateHdl, weld::Entry&, void) { UpdateEnable(); }
67 
69 {
70  bool bOk = !m_xCbUrl->GetURL().isEmpty();
71  if (m_xRBAddressValue->get_active())
72  {
73  m_xVclFrameLimit->set_sensitive(false);
74  m_xVclFrameMove->set_sensitive(false);
75  m_xEdRange->set_sensitive(false);
76  }
77  else
78  {
79  m_xVclFrameLimit->set_sensitive(true);
80  m_xVclFrameMove->set_sensitive(true);
81  m_xEdRange->set_sensitive(true);
82  if (bOk)
83  {
84  // Check the given range to make sure it's valid.
85  ScRange aTest = GetStartRange();
86  if (!aTest.IsValid())
87  bOk = false;
88  }
89  }
90  m_xBtnOk->set_sensitive(bOk);
91  // setOptimalLayoutSize();
92 }
93 
95 {
96  OUString aStr = m_xEdRange->get_text();
98  ScRange aRange;
99  ScRefFlags nRes = aRange.Parse(aStr, rDoc, rDoc.GetAddressConvention());
100  if (((nRes & ScRefFlags::VALID) == ScRefFlags::ZERO) || !aRange.IsValid())
101  {
102  // Invalid range.
103  aRange.SetInvalid();
104  return aRange;
105  }
106 
107  // Make sure it's only one row tall.
108  if (aRange.aStart.Row() != aRange.aEnd.Row())
109  aRange.SetInvalid();
110 
111  return aRange;
112 }
113 
114 void DataStreamDlg::Init(const DataStream& rStrm)
115 {
116  m_xCbUrl->set_entry_text(rStrm.GetURL());
118 
119  ScRange aRange = rStrm.GetRange();
120  ScRange aTopRange = aRange;
121  aTopRange.aEnd.SetRow(aTopRange.aStart.Row());
122  OUString aStr = aTopRange.Format(rDoc, ScRefFlags::RANGE_ABS_3D, rDoc.GetAddressConvention());
123  m_xEdRange->set_text(aStr);
124  SCROW nRows = aRange.aEnd.Row() - aRange.aStart.Row() + 1;
125 
126  if (aRange.aEnd.Row() == rDoc.MaxRow())
127  m_xRBUnlimited->set_active(true);
128  else
129  {
130  m_xRBMaxLimit->set_active(true);
131  m_xEdLimit->set_text(OUString::number(nRows));
132  }
133 
134  DataStream::MoveType eMove = rStrm.GetMove();
135  switch (eMove)
136  {
138  m_xRBDataDown->set_active(true);
139  break;
141  m_xRBRangeDown->set_active(true);
142  break;
143  case DataStream::MOVE_UP:
144  case DataStream::NO_MOVE:
145  default:;
146  }
147 
148  m_xCBRefreshOnEmpty->set_active(rStrm.IsRefreshOnEmptyLine());
149 
150  UpdateEnable();
151 }
152 
154 {
155  ScRange aStartRange = GetStartRange();
156  if (!aStartRange.IsValid())
157  // Don't start the stream without a valid range.
158  return;
159 
160  sal_Int32 nLimit = 0;
161  if (m_xRBMaxLimit->get_active())
162  nLimit = m_xEdLimit->get_text().toInt32();
163  OUString rURL = m_xCbUrl->get_active_text();
164  sal_uInt32 nSettings = 0;
165  if (m_xRBValuesInLine->get_active())
166  nSettings |= DataStream::VALUES_IN_LINE;
167 
170 
171  DataStream* pStream = DataStream::Set(m_pDocShell, rURL, aStartRange, nLimit, eMove, nSettings);
172  pStream->SetRefreshOnEmptyLine(m_xCBRefreshOnEmpty->get_active());
174  pStream->StartImport();
175 }
176 }
177 
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScAddress aStart
Definition: address.hxx:499
std::unique_ptr< weld::RadioButton > m_xRBDataDown
SCROW Row() const
Definition: address.hxx:261
std::unique_ptr< weld::CheckButton > m_xCBRefreshOnEmpty
const OUString & GetURL() const
Definition: datastream.hxx:78
void StartImport()
Definition: datastream.cxx:376
std::unique_ptr< weld::Frame > m_xVclFrameMove
ScAddress aEnd
Definition: address.hxx:500
std::unique_ptr< weld::RadioButton > m_xRBMaxLimit
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:494
std::unique_ptr< weld::Button > m_xBtnBrowse
void SetRefreshOnEmptyLine(bool bVal)
Definition: datastream.cxx:403
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:872
ScRange GetStartRange()
DataStreamDlg(ScDocShell *pDocShell, weld::Window *pParent)
void SetRow(SCROW nRowP)
Definition: address.hxx:274
void SetContext(Context _eNewContext)
virtual ~DataStreamDlg() override
IMPL_LINK_NOARG(SearchResultsDlg, ListSelectHdl, weld::TreeView &, void)
OUString Format(const ScDocument &rDocument, ScRefFlags nFlags=ScRefFlags::ZERO, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1, bool bFullAddressNotation=false) const
Returns string with formatted cell range from aStart to aEnd, according to provided address conventio...
Definition: address.cxx:2212
std::unique_ptr< weld::Button > m_xBtnOk
std::unique_ptr< weld::Frame > m_xVclFrameLimit
void SetInvalid()
Definition: address.hxx:541
bool IsValid() const
Definition: address.hxx:546
void Init(const DataStream &rStrm)
sal_Int32 SCROW
Definition: types.hxx:17
std::unique_ptr< weld::RadioButton > m_xRBNoMove
#define ERRCODE_NONE
MoveType GetMove() const
Definition: datastream.hxx:79
static DataStream * Set(ScDocShell *pShell, const OUString &rURL, const ScRange &rRange, sal_Int32 nLimit, MoveType eMove, sal_uInt32 nSettings)
Definition: datastream.cxx:263
static void MakeToolbarVisible()
Definition: datastream.cxx:238
std::unique_ptr< weld::RadioButton > m_xRBAddressValue
ScRefFlags Parse(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1, ScAddress::ExternalInfo *pExtInfo=nullptr, const css::uno::Sequence< css::sheet::ExternalLinkInfo > *pExternalLinks=nullptr, const OUString *pErrRef=nullptr)
Definition: address.cxx:1742
ScRange GetRange() const
Definition: datastream.cxx:333
Reference< XExecutableDialog > m_xDialog
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
std::unique_ptr< weld::RadioButton > m_xRBUnlimited
bool IsRefreshOnEmptyLine() const
Definition: datastream.hxx:80
std::unique_ptr< weld::RadioButton > m_xRBValuesInLine
std::unique_ptr< weld::Entry > m_xEdLimit
ScRefFlags
Definition: address.hxx:144
aStr
std::unique_ptr< SvtURLBox > m_xCbUrl
ScDocShell * m_pDocShell
std::unique_ptr< weld::Entry > m_xEdRange
std::unique_ptr< weld::RadioButton > m_xRBRangeDown