summaryrefslogtreecommitdiff
path: root/sc/source/ui/miscdlgs/datastreamdlg.cxx
blob: cbfd46baff0dcbb2be14d043db5615f92a1c3d15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <datastreamdlg.hxx>

#include <sfx2/filedlghelper.hxx>
#include <svtools/inettbc.hxx>
#include <vcl/layout.hxx>
#include <datastream.hxx>

DataStreamDlg::DataStreamDlg(ScDocShell *pDocShell, Window* pParent)
    : ModalDialog(pParent, "DataStreamDialog", "modules/scalc/ui/datastreams.ui")
    , mpDocShell(pDocShell)
{
    get(m_pCbUrl, "url");
    get(m_pBtnBrowse, "browse");
    get(m_pRBScriptData, "scriptdata");
    get(m_pRBValuesInLine, "valuesinline");
    get(m_pRBAddressValue, "addressvalue");
    get(m_pRBDataDown, "datadown");
    get(m_pRBRangeDown, "rangedown");
    get(m_pRBNoMove, "nomove");
    get(m_pRBMaxLimit, "maxlimit");
    get(m_pEdRange, "range");
    get(m_pEdLimit, "limit");
    get(m_pBtnOk, "ok");
    get(m_pVclFrameLimit, "framelimit");
    get(m_pVclFrameMove, "framemove");
    get(m_pVclFrameRange, "framerange");

    m_pCbUrl->SetSelectHdl( LINK( this, DataStreamDlg, UpdateHdl ) );
    m_pRBAddressValue->SetClickHdl( LINK( this, DataStreamDlg, UpdateHdl ) );
    m_pRBValuesInLine->SetClickHdl( LINK( this, DataStreamDlg, UpdateHdl ) );
    m_pEdRange->SetModifyHdl( LINK( this, DataStreamDlg, UpdateHdl ) );
    m_pBtnBrowse->SetClickHdl( LINK( this, DataStreamDlg, BrowseHdl ) );
    UpdateEnable();
}

IMPL_LINK_NOARG(DataStreamDlg, BrowseHdl)
{
    sfx2::FileDialogHelper aFileDialog(0, 0);
    if ( aFileDialog.Execute() != ERRCODE_NONE )
        return 0;

    m_pCbUrl->SetText( aFileDialog.GetPath() );
    UpdateEnable();
    return 0;
}

IMPL_LINK_NOARG(DataStreamDlg, UpdateHdl)
{
    UpdateEnable();
    return 0;
}

void DataStreamDlg::UpdateEnable()
{
    bool bOk = !m_pCbUrl->GetURL().isEmpty();
    if (m_pRBAddressValue->IsChecked())
    {
        m_pRBNoMove->Check();
        m_pVclFrameLimit->Hide();
        m_pVclFrameMove->Hide();
        m_pVclFrameRange->Hide();
        m_pEdRange->SetText("");
    }
    else
    {
        m_pVclFrameLimit->Show();
        m_pVclFrameMove->Show();
        m_pVclFrameRange->Show();
        bOk = bOk && !m_pEdRange->GetText().isEmpty();
    }
    m_pBtnOk->Enable(bOk);
    setOptimalLayoutSize();
}

void DataStreamDlg::Init(const OUString& rURL, const OUString& rRange, const sal_Int32 nLimit,
        const OUString& rMove, const sal_uInt32 nSettings)
{
    m_pEdLimit->SetText(OUString::number(nLimit));
    m_pCbUrl->SetText(rURL);
    if (nSettings & DataStream::SCRIPT_STREAM)
        m_pRBScriptData->Check();
    if (!(nSettings & DataStream::VALUES_IN_LINE))
        m_pRBAddressValue->Check();
    m_pEdRange->SetText(rRange);
    if (rMove == "NO_MOVE")
        m_pRBNoMove->Check();
    else if (rMove == "RANGE_DOWN")
        m_pRBRangeDown->Check();
    else if (rMove == "MOVE_DOWN")
        m_pRBDataDown->Check();
    UpdateEnable();
}

void DataStreamDlg::StartStream(DataStream *pStream)
{
    sal_Int32 nLimit = 0;
    if (m_pRBMaxLimit->IsChecked())
        nLimit = m_pEdLimit->GetText().toInt32();
    OUString rURL = m_pCbUrl->GetText();
    sal_uInt32 nSettings = 0;
    if (m_pRBScriptData->IsChecked())
       nSettings |= DataStream::SCRIPT_STREAM;
    if (m_pRBValuesInLine->IsChecked())
       nSettings |= DataStream::VALUES_IN_LINE;
    if (pStream)
    {
        pStream->Decode(rURL, m_pEdRange->GetText(), nLimit,
                m_pRBNoMove->IsChecked() ? OUString("NO_MOVE") : m_pRBRangeDown->IsChecked()
                    ? OUString("RANGE_DOWN") : OUString("MOVE_DOWN"),
                nSettings);
        return;
    }
    pStream = DataStream::Set( mpDocShell,
            rURL,
            m_pEdRange->GetText(),
            nLimit,
            m_pRBNoMove->IsChecked() ? OUString("NO_MOVE") : m_pRBRangeDown->IsChecked()
                ? OUString("RANGE_DOWN") : OUString("MOVE_DOWN")
            , nSettings
            );
    DataStream::MakeToolbarVisible( mpDocShell );
    pStream->StartImport();
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */