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
13#include <svtools/inettbc.hxx>
14#include <address.hxx>
15#include <docsh.hxx>
16#include <datastream.hxx>
17
18namespace 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));
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
62IMPL_LINK_NOARG(DataStreamDlg, UpdateClickHdl, weld::Toggleable&, void) { UpdateEnable(); }
63
64IMPL_LINK_NOARG(DataStreamDlg, UpdateComboBoxHdl, weld::ComboBox&, void) { UpdateEnable(); }
65
66IMPL_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
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;
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: */
ScRefFlags
Definition: address.hxx:158
Reference< XExecutableDialog > m_xDialog
SCROW Row() const
Definition: address.hxx:274
void SetRow(SCROW nRowP)
Definition: address.hxx:287
const ScDocument & GetDocument() const
Definition: docsh.hxx:219
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:492
SC_DLLPUBLIC SCROW MaxRow() const
Definition: document.hxx:893
void SetInvalid()
Definition: address.hxx:539
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:2170
ScAddress aEnd
Definition: address.hxx:498
bool IsValid() const
Definition: address.hxx:544
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:1700
ScAddress aStart
Definition: address.hxx:497
std::unique_ptr< weld::RadioButton > m_xRBNoMove
std::unique_ptr< weld::Frame > m_xVclFrameLimit
virtual ~DataStreamDlg() override
std::unique_ptr< weld::Entry > m_xEdLimit
std::unique_ptr< weld::RadioButton > m_xRBMaxLimit
std::unique_ptr< SvtURLBox > m_xCbUrl
std::unique_ptr< weld::Frame > m_xVclFrameMove
std::unique_ptr< weld::Entry > m_xEdRange
std::unique_ptr< weld::RadioButton > m_xRBValuesInLine
std::unique_ptr< weld::CheckButton > m_xCBRefreshOnEmpty
void Init(const DataStream &rStrm)
std::unique_ptr< weld::RadioButton > m_xRBDataDown
std::unique_ptr< weld::Button > m_xBtnBrowse
std::unique_ptr< weld::RadioButton > m_xRBUnlimited
std::unique_ptr< weld::RadioButton > m_xRBRangeDown
DataStreamDlg(ScDocShell *pDocShell, weld::Window *pParent)
ScRange GetStartRange()
std::unique_ptr< weld::RadioButton > m_xRBAddressValue
ScDocShell * m_pDocShell
std::unique_ptr< weld::Button > m_xBtnOk
void StartImport()
Definition: datastream.cxx:382
static void MakeToolbarVisible()
Definition: datastream.cxx:236
static DataStream * Set(ScDocShell *pShell, const OUString &rURL, const ScRange &rRange, sal_Int32 nLimit, MoveType eMove, sal_uInt32 nSettings)
Definition: datastream.cxx:265
void SetRefreshOnEmptyLine(bool bVal)
Definition: datastream.cxx:409
OUString GetPath() const
void SetContext(Context _eNewContext)
#define ERRCODE_NONE
aStr
void SvStream & rStrm
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15
IMPL_LINK_NOARG(SharedStringPoolPurge, timerHandler, Timer *, void)
sal_Int32 SCROW
Definition: types.hxx:17