ZModemDialog.cpp 2.77 KB
Newer Older
Waldo Bastian's avatar
Waldo Bastian committed
1
/*  This file is part of the KDE libraries
2
 *  Copyright 2002 Waldo Bastian <bastian@kde.org>
Waldo Bastian's avatar
Waldo Bastian committed
3 4 5 6 7 8 9 10 11 12 13 14
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License version 2 as published by the Free Software Foundation;
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
Dirk Mueller's avatar
Dirk Mueller committed
15
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Dirk Mueller's avatar
Dirk Mueller committed
16
 *  Boston, MA 02110-1301, USA.
Waldo Bastian's avatar
Waldo Bastian committed
17 18
 **/

Jekyll Wu's avatar
Jekyll Wu committed
19
// Own
20 21
#include "ZModemDialog.h"

22
// KDE
23
#include <KLocalizedString>
Rick Xing's avatar
Rick Xing committed
24
#include <KTextEdit>
Laurent Montel's avatar
Laurent Montel committed
25 26 27 28
#include <QDialogButtonBox>
#include <QPushButton>
#include <KGuiItem>
#include <QVBoxLayout>
Waldo Bastian's avatar
Waldo Bastian committed
29

30
using Konsole::ZModemDialog;
31

32
ZModemDialog::ZModemDialog(QWidget* aParent, bool modal, const QString& caption)
Laurent Montel's avatar
Laurent Montel committed
33
    : QDialog(aParent)
Waldo Bastian's avatar
Waldo Bastian committed
34
{
35
    setObjectName(QStringLiteral("zmodem_progress"));
Kurt Hindenburg's avatar
Kurt Hindenburg committed
36
    setModal(modal);
Laurent Montel's avatar
Laurent Montel committed
37
    setWindowTitle(caption);
38

Laurent Montel's avatar
Laurent Montel committed
39 40 41 42 43 44 45 46 47 48 49 50
    mButtonBox = new QDialogButtonBox(QDialogButtonBox::Close);
    QWidget *mainWidget = new QWidget(this);
    QVBoxLayout *mainLayout = new QVBoxLayout;
    setLayout(mainLayout);
    mainLayout->addWidget(mainWidget);
    mUser1Button = new QPushButton;
    mButtonBox->addButton(mUser1Button, QDialogButtonBox::ActionRole);
    mainLayout->addWidget(mButtonBox);
    KGuiItem::assign(mUser1Button, KGuiItem(i18n("&Stop")));
    mButtonBox->button(QDialogButtonBox::Close)->setDefault(true);
    mUser1Button->setShortcut(Qt::Key_Escape);
    mButtonBox->button(QDialogButtonBox::Close)->setEnabled(false);
51

Jekyll Wu's avatar
Jekyll Wu committed
52 53 54
    _textEdit = new KTextEdit(this);
    _textEdit->setMinimumSize(400, 100);
    _textEdit->setReadOnly(true);
Laurent Montel's avatar
Laurent Montel committed
55
    mainLayout->addWidget(_textEdit);
56

Laurent Montel's avatar
Laurent Montel committed
57 58
    connect(this, &Konsole::ZModemDialog::user1Clicked, this, &Konsole::ZModemDialog::slotUser1Clicked);
    connect(mButtonBox->button(QDialogButtonBox::Close), &QPushButton::clicked, this, &Konsole::ZModemDialog::slotClose);
Waldo Bastian's avatar
Waldo Bastian committed
59
}
Laurent Montel's avatar
Laurent Montel committed
60

61
void ZModemDialog::addProgressText(const QString& text)
Waldo Bastian's avatar
Waldo Bastian committed
62
{
63
    QTextCursor currentCursor = _textEdit->textCursor();
64

65 66
    currentCursor.insertBlock();
    currentCursor.insertText(text);
Waldo Bastian's avatar
Waldo Bastian committed
67 68
}

Laurent Montel's avatar
Laurent Montel committed
69 70 71 72 73 74
void ZModemDialog::slotUser1Clicked()
{
    Q_EMIT user1Clicked();
    slotClose();
}

75
void ZModemDialog::transferDone()
Waldo Bastian's avatar
Waldo Bastian committed
76
{
Laurent Montel's avatar
Laurent Montel committed
77 78
    mButtonBox->button(QDialogButtonBox::Close)->setEnabled(true);
    mUser1Button->setEnabled(false);
Waldo Bastian's avatar
Waldo Bastian committed
79 80 81 82
}

void ZModemDialog::slotClose()
{
Jekyll Wu's avatar
Jekyll Wu committed
83 84
    delayedDestruct();
    accept();
Waldo Bastian's avatar
Waldo Bastian committed
85 86
}

Laurent Montel's avatar
Laurent Montel committed
87 88 89 90 91 92 93 94
void ZModemDialog::delayedDestruct()
{
    if (isVisible()) {
        hide();
    }

    deleteLater();
}