1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include <datastreamdlg.hxx>
12 #include <sfx2/filedlghelper.hxx>
13 #include <svtools/inettbc.hxx>
14 #include <address.hxx>
16 #include <datastream.hxx>
20 DataStreamDlg::DataStreamDlg(ScDocShell
* pDocShell
, weld::Window
* pParent
)
21 : GenericDialogController(pParent
, u
"modules/scalc/ui/datastreams.ui"_ustr
,
22 u
"DataStreamDialog"_ustr
)
23 , m_pDocShell(pDocShell
)
24 , m_xCbUrl(new SvtURLBox(m_xBuilder
->weld_combo_box(u
"url"_ustr
)))
25 , m_xBtnBrowse(m_xBuilder
->weld_button(u
"browse"_ustr
))
26 , m_xRBValuesInLine(m_xBuilder
->weld_radio_button(u
"valuesinline"_ustr
))
27 , m_xRBAddressValue(m_xBuilder
->weld_radio_button(u
"addressvalue"_ustr
))
28 , m_xCBRefreshOnEmpty(m_xBuilder
->weld_check_button(u
"refresh_ui"_ustr
))
29 , m_xRBDataDown(m_xBuilder
->weld_radio_button(u
"datadown"_ustr
))
30 , m_xRBRangeDown(m_xBuilder
->weld_radio_button(u
"rangedown"_ustr
))
31 , m_xRBNoMove(m_xBuilder
->weld_radio_button(u
"nomove"_ustr
))
32 , m_xRBMaxLimit(m_xBuilder
->weld_radio_button(u
"maxlimit"_ustr
))
33 , m_xRBUnlimited(m_xBuilder
->weld_radio_button(u
"unlimited"_ustr
))
34 , m_xEdRange(m_xBuilder
->weld_entry(u
"range"_ustr
))
35 , m_xEdLimit(m_xBuilder
->weld_entry(u
"limit"_ustr
))
36 , m_xBtnOk(m_xBuilder
->weld_button(u
"ok"_ustr
))
37 , m_xVclFrameLimit(m_xBuilder
->weld_frame(u
"framelimit"_ustr
))
38 , m_xVclFrameMove(m_xBuilder
->weld_frame(u
"framemove"_ustr
))
40 m_xCbUrl
->connect_changed(LINK(this, DataStreamDlg
, UpdateComboBoxHdl
));
41 m_xRBAddressValue
->connect_toggled(LINK(this, DataStreamDlg
, UpdateClickHdl
));
42 m_xRBAddressValue
->set_sensitive(false);
44 m_xRBValuesInLine
->connect_toggled(LINK(this, DataStreamDlg
, UpdateClickHdl
));
45 m_xEdRange
->connect_changed(LINK(this, DataStreamDlg
, UpdateHdl
));
46 m_xBtnBrowse
->connect_clicked(LINK(this, DataStreamDlg
, BrowseHdl
));
50 DataStreamDlg::~DataStreamDlg() {}
52 IMPL_LINK_NOARG(DataStreamDlg
, BrowseHdl
, weld::Button
&, void)
54 sfx2::FileDialogHelper
aFileDialog(0, FileDialogFlags::NONE
, m_xDialog
.get());
55 aFileDialog
.SetContext(sfx2::FileDialogHelper::CalcDataStream
);
56 if (aFileDialog
.Execute() != ERRCODE_NONE
)
59 m_xCbUrl
->set_entry_text(aFileDialog
.GetPath());
63 IMPL_LINK_NOARG(DataStreamDlg
, UpdateClickHdl
, weld::Toggleable
&, void) { UpdateEnable(); }
65 IMPL_LINK_NOARG(DataStreamDlg
, UpdateComboBoxHdl
, weld::ComboBox
&, void) { UpdateEnable(); }
67 IMPL_LINK_NOARG(DataStreamDlg
, UpdateHdl
, weld::Entry
&, void) { UpdateEnable(); }
69 void DataStreamDlg::UpdateEnable()
71 bool bOk
= !m_xCbUrl
->GetURL().isEmpty();
72 if (m_xRBAddressValue
->get_active())
74 m_xVclFrameLimit
->set_sensitive(false);
75 m_xVclFrameMove
->set_sensitive(false);
76 m_xEdRange
->set_sensitive(false);
80 m_xVclFrameLimit
->set_sensitive(true);
81 m_xVclFrameMove
->set_sensitive(true);
82 m_xEdRange
->set_sensitive(true);
85 // Check the given range to make sure it's valid.
86 ScRange aTest
= GetStartRange();
91 m_xBtnOk
->set_sensitive(bOk
);
92 // setOptimalLayoutSize();
95 ScRange
DataStreamDlg::GetStartRange()
97 OUString aStr
= m_xEdRange
->get_text();
98 ScDocument
& rDoc
= m_pDocShell
->GetDocument();
100 ScRefFlags nRes
= aRange
.Parse(aStr
, rDoc
, rDoc
.GetAddressConvention());
101 if (((nRes
& ScRefFlags::VALID
) == ScRefFlags::ZERO
) || !aRange
.IsValid())
108 // Make sure it's only one row tall.
109 if (aRange
.aStart
.Row() != aRange
.aEnd
.Row())
115 void DataStreamDlg::Init(const DataStream
& rStrm
)
117 m_xCbUrl
->set_entry_text(rStrm
.GetURL());
118 ScDocument
& rDoc
= m_pDocShell
->GetDocument();
120 ScRange aRange
= rStrm
.GetRange();
121 ScRange aTopRange
= aRange
;
122 aTopRange
.aEnd
.SetRow(aTopRange
.aStart
.Row());
123 OUString aStr
= aTopRange
.Format(rDoc
, ScRefFlags::RANGE_ABS_3D
, rDoc
.GetAddressConvention());
124 m_xEdRange
->set_text(aStr
);
125 SCROW nRows
= aRange
.aEnd
.Row() - aRange
.aStart
.Row() + 1;
127 if (aRange
.aEnd
.Row() == rDoc
.MaxRow())
128 m_xRBUnlimited
->set_active(true);
131 m_xRBMaxLimit
->set_active(true);
132 m_xEdLimit
->set_text(OUString::number(nRows
));
135 DataStream::MoveType eMove
= rStrm
.GetMove();
138 case DataStream::MOVE_DOWN
:
139 m_xRBDataDown
->set_active(true);
141 case DataStream::RANGE_DOWN
:
142 m_xRBRangeDown
->set_active(true);
144 case DataStream::MOVE_UP
:
145 case DataStream::NO_MOVE
:
149 m_xCBRefreshOnEmpty
->set_active(rStrm
.IsRefreshOnEmptyLine());
154 void DataStreamDlg::StartStream()
156 ScRange aStartRange
= GetStartRange();
157 if (!aStartRange
.IsValid())
158 // Don't start the stream without a valid range.
161 sal_Int32 nLimit
= 0;
162 if (m_xRBMaxLimit
->get_active())
163 nLimit
= m_xEdLimit
->get_text().toInt32();
164 OUString rURL
= m_xCbUrl
->get_active_text();
166 DataStream::MoveType eMove
167 = m_xRBRangeDown
->get_active() ? DataStream::RANGE_DOWN
: DataStream::MOVE_DOWN
;
169 DataStream
* pStream
= DataStream::Set(m_pDocShell
, rURL
, aStartRange
, nLimit
, eMove
);
170 pStream
->SetRefreshOnEmptyLine(m_xCBRefreshOnEmpty
->get_active());
171 DataStream::MakeToolbarVisible();
172 pStream
->StartImport();
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */