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());
54  if (aFileDialog.Execute() != ERRCODE_NONE)
55  return;
56 
57  m_xCbUrl->set_entry_text(aFileDialog.GetPath());
58  UpdateEnable();
59 }
60 
61 IMPL_LINK_NOARG(DataStreamDlg, UpdateClickHdl, weld::ToggleButton&, void) { UpdateEnable(); }
62 
63 IMPL_LINK_NOARG(DataStreamDlg, UpdateComboBoxHdl, weld::ComboBox&, void) { UpdateEnable(); }
64 
65 IMPL_LINK_NOARG(DataStreamDlg, UpdateHdl, weld::Entry&, void) { UpdateEnable(); }
66 
68 {
69  bool bOk = !m_xCbUrl->GetURL().isEmpty();
70  if (m_xRBAddressValue->get_active())
71  {
72  m_xVclFrameLimit->set_sensitive(false);
73  m_xVclFrameMove->set_sensitive(false);
74  m_xEdRange->set_sensitive(false);
75  }
76  else
77  {
78  m_xVclFrameLimit->set_sensitive(true);
79  m_xVclFrameMove->set_sensitive(true);
80  m_xEdRange->set_sensitive(true);
81  if (bOk)
82  {
83  // Check the given range to make sure it's valid.
84  ScRange aTest = GetStartRange();
85  if (!aTest.IsValid())
86  bOk = false;
87  }
88  }
89  m_xBtnOk->set_sensitive(bOk);
90  // setOptimalLayoutSize();
91 }
92 
94 {
95  OUString aStr = m_xEdRange->get_text();
97  ScRange aRange;
98  ScRefFlags nRes = aRange.Parse(aStr, rDoc, rDoc.GetAddressConvention());
99  if (((nRes & ScRefFlags::VALID) == ScRefFlags::ZERO) || !aRange.IsValid())
100  {
101  // Invalid range.
102  aRange.SetInvalid();
103  return aRange;
104  }
105 
106  // Make sure it's only one row tall.
107  if (aRange.aStart.Row() != aRange.aEnd.Row())
108  aRange.SetInvalid();
109 
110  return aRange;
111 }
112 
113 void DataStreamDlg::Init(const DataStream& rStrm)
114 {
115  m_xCbUrl->set_entry_text(rStrm.GetURL());
117 
118  ScRange aRange = rStrm.GetRange();
119  ScRange aTopRange = aRange;
120  aTopRange.aEnd.SetRow(aTopRange.aStart.Row());
121  OUString aStr = aTopRange.Format(rDoc, ScRefFlags::RANGE_ABS_3D, rDoc.GetAddressConvention());
122  m_xEdRange->set_text(aStr);
123  SCROW nRows = aRange.aEnd.Row() - aRange.aStart.Row() + 1;
124 
125  if (aRange.aEnd.Row() == rDoc.MaxRow())
126  m_xRBUnlimited->set_active(true);
127  else
128  {
129  m_xRBMaxLimit->set_active(true);
130  m_xEdLimit->set_text(OUString::number(nRows));
131  }
132 
133  DataStream::MoveType eMove = rStrm.GetMove();
134  switch (eMove)
135  {
137  m_xRBDataDown->set_active(true);
138  break;
140  m_xRBRangeDown->set_active(true);
141  break;
142  case DataStream::MOVE_UP:
143  case DataStream::NO_MOVE:
144  default:;
145  }
146 
147  m_xCBRefreshOnEmpty->set_active(rStrm.IsRefreshOnEmptyLine());
148 
149  UpdateEnable();
150 }
151 
153 {
154  ScRange aStartRange = GetStartRange();
155  if (!aStartRange.IsValid())
156  // Don't start the stream without a valid range.
157  return;
158 
159  sal_Int32 nLimit = 0;
160  if (m_xRBMaxLimit->get_active())
161  nLimit = m_xEdLimit->get_text().toInt32();
162  OUString rURL = m_xCbUrl->get_active_text();
163  sal_uInt32 nSettings = 0;
164  if (m_xRBValuesInLine->get_active())
165  nSettings |= DataStream::VALUES_IN_LINE;
166 
169 
170  DataStream* pStream = DataStream::Set(m_pDocShell, rURL, aStartRange, nLimit, eMove, nSettings);
171  pStream->SetRefreshOnEmptyLine(m_xCBRefreshOnEmpty->get_active());
173  pStream->StartImport();
174 }
175 }
176 
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScAddress aStart
Definition: address.hxx:500
std::unique_ptr< weld::RadioButton > m_xRBDataDown
SCROW Row() const
Definition: address.hxx:262
std::unique_ptr< weld::CheckButton > m_xCBRefreshOnEmpty
const OUString & GetURL() const
Definition: datastream.hxx:79
void StartImport()
Definition: datastream.cxx:376
std::unique_ptr< weld::Frame > m_xVclFrameMove
ScAddress aEnd
Definition: address.hxx:501
std::unique_ptr< weld::RadioButton > m_xRBMaxLimit
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:488
std::unique_ptr< weld::Button > m_xBtnBrowse
void SetRefreshOnEmptyLine(bool bVal)
Definition: datastream.cxx:403
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:870
ScRange GetStartRange()
DataStreamDlg(ScDocShell *pDocShell, weld::Window *pParent)
void SetRow(SCROW nRowP)
Definition: address.hxx:275
virtual ~DataStreamDlg() override
IMPL_LINK_NOARG(SearchResultsDlg, ListSelectHdl, weld::TreeView &, void)
SC_DLLPUBLIC 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:542
bool IsValid() const
Definition: address.hxx:547
void Init(const DataStream &rStrm)
sal_Int32 SCROW
Definition: types.hxx:18
std::unique_ptr< weld::RadioButton > m_xRBNoMove
#define ERRCODE_NONE
MoveType GetMove() const
Definition: datastream.hxx:80
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
SC_DLLPUBLIC 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:217
std::unique_ptr< weld::RadioButton > m_xRBUnlimited
bool IsRefreshOnEmptyLine() const
Definition: datastream.hxx:81
std::unique_ptr< weld::RadioButton > m_xRBValuesInLine
std::unique_ptr< weld::Entry > m_xEdLimit
ScRefFlags
Definition: address.hxx:145
aStr
std::unique_ptr< SvtURLBox > m_xCbUrl
ScDocShell * m_pDocShell
std::unique_ptr< weld::Entry > m_xEdRange
std::unique_ptr< weld::RadioButton > m_xRBRangeDown