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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
|
/***************************************************************************
* Copyright © 2011 Jonathan Thomas <echidnaman@kubuntu.org> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License or (at your option) version 3 or any later version *
* accepted by the membership of KDE e.V. (or its successor approved *
* by the membership of KDE e.V.), which shall act as a proxy *
* defined in Section 14 of version 3 of the license. *
* *
* This program 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
#include "DebCommitWidget.h"
// Qt includes
#include <QDir>
#include <QStringBuilder>
#include <QUuid>
#include <QLabel>
#include <QProgressBar>
#include <QVBoxLayout>
// KDE includes
#include <KLocalizedString>
#include <KMessageBox>
#include <KTextEdit>
// LibQApt/DebconfKDE includes
#include <DebconfGui.h>
#include <QApt/Transaction>
DebCommitWidget::DebCommitWidget(QWidget *parent)
: QWidget(parent)
{
QVBoxLayout *layout = new QVBoxLayout(this);
layout->setMargin(0);
setLayout(layout);
m_headerLabel = new QLabel(this);
m_headerLabel->setText(i18nc("@info The widget's header label",
"<title>Installing</title>"));
m_terminal = new KTextEdit(this);
m_terminal->setReadOnly(true);
m_terminal->setFontFamily(QLatin1String("Monospace"));
m_terminal->setWordWrapMode(QTextOption::NoWrap);
m_terminal->setUndoRedoEnabled(false);
QPalette p = m_terminal->palette();
p.setColor(QPalette::Base, Qt::black);
p.setColor(QPalette::Text, QColor(178, 178, 178));
m_terminal->setPalette(p);
m_terminal->setFrameShape(QFrame::NoFrame);
QString uuid = QUuid::createUuid().toString();
uuid.remove('{').remove('}').remove('-');
m_pipe = QDir::tempPath() % QLatin1String("/qapt-sock-") % uuid;
m_debconfGui = new DebconfKde::DebconfGui(m_pipe, this);
m_debconfGui->connect(m_debconfGui, SIGNAL(activated()), this, SLOT(showDebconf()));
m_debconfGui->connect(m_debconfGui, SIGNAL(deactivated()), this, SLOT(hideDebconf()));
m_debconfGui->hide();
m_progressBar = new QProgressBar(this);
m_progressBar->hide();
layout->addWidget(m_headerLabel);
layout->addWidget(m_terminal);
layout->addWidget(m_debconfGui);
layout->addWidget(m_progressBar);
}
QString DebCommitWidget::pipe() const
{
return m_pipe;
}
void DebCommitWidget::setTransaction(QApt::Transaction *trans)
{
m_trans = trans;
connect(m_trans, SIGNAL(statusChanged(QApt::TransactionStatus)),
this, SLOT(statusChanged(QApt::TransactionStatus)));
connect(m_trans, SIGNAL(errorOccurred(QApt::ErrorCode)),
this, SLOT(errorOccurred(QApt::ErrorCode)));
connect(m_trans, SIGNAL(statusDetailsChanged(QString)),
this, SLOT(updateTerminal(QString)));
}
void DebCommitWidget::statusChanged(QApt::TransactionStatus status)
{
switch (status) {
case QApt::SetupStatus:
case QApt::WaitingStatus:
case QApt::AuthenticationStatus:
m_progressBar->setMaximum(0);
m_headerLabel->setText(i18nc("@info Status information, widget title",
"<title>Starting</title>"));
break;
case QApt::WaitingMediumStatus:
case QApt::WaitingLockStatus:
case QApt::WaitingConfigFilePromptStatus:
m_progressBar->setMaximum(0);
m_headerLabel->setText(i18nc("@info Status information, widget title",
"<title>Waiting</title>"));
break;
case QApt::RunningStatus:
// We're ready for "real" progress now
m_progressBar->setMaximum(100);
break;
case QApt::LoadingCacheStatus:
m_headerLabel->setText(i18nc("@info Status info",
"<title>Loading Software List</title>"));
break;
case QApt::DownloadingStatus:
m_progressBar->setMaximum(100);
m_headerLabel->setText(i18nc("@info Status information, widget title",
"<title>Downloading Packages</title>"));
showProgress();
break;
case QApt::CommittingStatus:
m_headerLabel->setText(i18nc("@info Status information, widget title",
"<title>Committing Changes</title>"));
hideProgress();
break;
case QApt::FinishedStatus:
if (m_trans->role() == QApt::InstallFileRole) {
updateTerminal(i18nc("@label Message that the install is done",
"Done"));
m_headerLabel->setText(i18nc("@info Header label used when the install is done",
"<title>Done</title>"));
}
break;
default:
break;
}
}
void DebCommitWidget::errorOccurred(QApt::ErrorCode error)
{
QString text;
QString title;
QString details;
switch (error) {
case QApt::InitError: {
text = i18nc("@label",
"The package system could not be initialized, your "
"configuration may be broken.");
title = i18nc("@title:window", "Initialization error");
details = m_trans->errorDetails();
KMessageBox::detailedError(this, text, details, title);
break;
}
case QApt::WrongArchError:
text = i18nc("@label",
"This package is incompatible with your computer.");
title = i18nc("@title:window", "Incompatible Package");
details = m_trans->errorDetails();
KMessageBox::detailedError(this, text, details, title);
break;
default:
break;
}
}
void DebCommitWidget::updateProgress(int progress)
{
if (progress > 100) {
m_progressBar->setMaximum(0);
return;
} else
m_progressBar->setMaximum(100);
m_progressBar->setValue(progress);
}
void DebCommitWidget::updateTerminal(const QString &message)
{
m_terminal->insertPlainText(message);
}
void DebCommitWidget::showDebconf()
{
m_terminal->hide();
m_debconfGui->show();
}
void DebCommitWidget::hideDebconf()
{
m_debconfGui->hide();
m_terminal->show();
}
void DebCommitWidget::showProgress()
{
m_terminal->hide();
m_progressBar->show();
}
void DebCommitWidget::hideProgress()
{
m_progressBar->hide();
m_terminal->show();
}
|