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 {
51 }
52 
54 {
55  sfx2::FileDialogHelper aFileDialog(0, FileDialogFlags::NONE, m_xDialog.get());
56  if ( aFileDialog.Execute() != ERRCODE_NONE )
57  return;
58 
59  m_xCbUrl->set_entry_text(aFileDialog.GetPath());
60  UpdateEnable();
61 }
62 
64 {
65  UpdateEnable();
66 }
67 
68 IMPL_LINK_NOARG(DataStreamDlg, UpdateComboBoxHdl, weld::ComboBox&, void)
69 {
70  UpdateEnable();
71 }
72 
74 {
75  UpdateEnable();
76 }
77 
79 {
80  bool bOk = !m_xCbUrl->GetURL().isEmpty();
81  if (m_xRBAddressValue->get_active())
82  {
83  m_xVclFrameLimit->set_sensitive(false);
84  m_xVclFrameMove->set_sensitive(false);
85  m_xEdRange->set_sensitive(false);
86  }
87  else
88  {
89  m_xVclFrameLimit->set_sensitive(true);
90  m_xVclFrameMove->set_sensitive(true);
91  m_xEdRange->set_sensitive(true);
92  if (bOk)
93  {
94  // Check the given range to make sure it's valid.
95  ScRange aTest = GetStartRange();
96  if (!aTest.IsValid())
97  bOk = false;
98  }
99  }
100  m_xBtnOk->set_sensitive(bOk);
101 // setOptimalLayoutSize();
102 }
103 
105 {
106  OUString aStr = m_xEdRange->get_text();
108  ScRange aRange;
109  ScRefFlags nRes = aRange.Parse(aStr, &rDoc, rDoc.GetAddressConvention());
110  if ( ((nRes & ScRefFlags::VALID) == ScRefFlags::ZERO) || !aRange.IsValid())
111  {
112  // Invalid range.
113  aRange.SetInvalid();
114  return aRange;
115  }
116 
117  // Make sure it's only one row tall.
118  if (aRange.aStart.Row() != aRange.aEnd.Row())
119  aRange.SetInvalid();
120 
121  return aRange;
122 }
123 
124 void DataStreamDlg::Init( const DataStream& rStrm )
125 {
126  m_xCbUrl->set_entry_text(rStrm.GetURL());
128 
129  ScRange aRange = rStrm.GetRange();
130  ScRange aTopRange = aRange;
131  aTopRange.aEnd.SetRow(aTopRange.aStart.Row());
132  OUString aStr = aTopRange.Format(rDoc, ScRefFlags::RANGE_ABS_3D, rDoc.GetAddressConvention());
133  m_xEdRange->set_text(aStr);
134  SCROW nRows = aRange.aEnd.Row() - aRange.aStart.Row() + 1;
135 
136  if (aRange.aEnd.Row() == rDoc.MaxRow())
137  m_xRBUnlimited->set_active(true);
138  else
139  {
140  m_xRBMaxLimit->set_active(true);
141  m_xEdLimit->set_text(OUString::number(nRows));
142  }
143 
144  DataStream::MoveType eMove = rStrm.GetMove();
145  switch (eMove)
146  {
148  m_xRBDataDown->set_active(true);
149  break;
151  m_xRBRangeDown->set_active(true);
152  break;
153  case DataStream::MOVE_UP:
154  case DataStream::NO_MOVE:
155  default:
156  ;
157  }
158 
159  m_xCBRefreshOnEmpty->set_active(rStrm.IsRefreshOnEmptyLine());
160 
161  UpdateEnable();
162 }
163 
165 {
166  ScRange aStartRange = GetStartRange();
167  if (!aStartRange.IsValid())
168  // Don't start the stream without a valid range.
169  return;
170 
171  sal_Int32 nLimit = 0;
172  if (m_xRBMaxLimit->get_active())
173  nLimit = m_xEdLimit->get_text().toInt32();
174  OUString rURL = m_xCbUrl->get_active_text();
175  sal_uInt32 nSettings = 0;
176  if (m_xRBValuesInLine->get_active())
177  nSettings |= DataStream::VALUES_IN_LINE;
178 
179  DataStream::MoveType eMove =
181 
182  DataStream* pStream = DataStream::Set(m_pDocShell, rURL, aStartRange, nLimit, eMove, nSettings);
183  pStream->SetRefreshOnEmptyLine(m_xCBRefreshOnEmpty->get_active());
185  pStream->StartImport();
186 }
187 
188 }
189 
190 /* 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:475
std::unique_ptr< weld::Button > m_xBtnBrowse
void SetRefreshOnEmptyLine(bool bVal)
Definition: datastream.cxx:403
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:873
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:2207
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
SC_DLLPUBLIC ScRefFlags Parse(const OUString &, const ScDocument *=nullptr, 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:1737
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
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: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