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 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
|
/***************************************************************************
* Copyright (C) 2008-2011 by Daniel Nicoletti *
* dantti12@gmail.com *
* *
* 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) any later version. *
* *
* 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; see the file COPYING. If not, write to *
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
* Boston, MA 02110-1301, USA. *
***************************************************************************/
#include <config.h>
#include "PkTransactionWidget.h"
#include "ui_PkTransactionWidget.h"
#include <KLocalizedString>
#include <KPushButton>
#include <KPixmapSequence>
#include <KPixmapSequenceOverlayPainter>
#include <KIconLoader>
#include <KDebug>
#include <QtDBus/QDBusMessage>
#include <QtDBus/QDBusConnection>
#include <QScrollBar>
#include <Daemon>
#include "Enum.h"
#include "PkStrings.h"
#include "RepoSig.h"
#include "LicenseAgreement.h"
#include "PkIcons.h"
#include "ApplicationLauncher.h"
#include "Requirements.h"
#include "PkTransaction.h"
#include "TransactionDelegate.h"
#include "PkTransactionProgressModel.h"
#include "PackageModel.h"
class PkTransactionWidgetPrivate
{
public:
ApplicationLauncher *launcher;
Transaction::Role role;
KPixmapSequenceOverlayPainter *busySeq;
};
PkTransactionWidget::PkTransactionWidget(QWidget *parent) :
QWidget(parent),
m_trans(0),
m_keepScrollBarAtBottom(true),
m_handlingActionRequired(false),
m_showingError(false),
m_status(Transaction::StatusUnknown),
ui(new Ui::PkTransactionWidget),
d(new PkTransactionWidgetPrivate)
{
ui->setupUi(this);
// Setup the animation sequence
d->busySeq = new KPixmapSequenceOverlayPainter(this);
d->busySeq->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
d->busySeq->setWidget(ui->label);
ui->label->clear();
// Connect stuff from the progressView
QScrollBar *scrollBar = ui->progressView->verticalScrollBar();
connect(scrollBar, SIGNAL(sliderMoved(int)),
this, SLOT(followBottom(int)));
connect(scrollBar, SIGNAL(valueChanged(int)),
this, SLOT(followBottom(int)));
connect(scrollBar, SIGNAL(rangeChanged(int,int)),
this, SLOT(rangeChanged(int,int)));
ui->progressView->setItemDelegate(new TransactionDelegate(this));
connect(ui->cancelButton, SIGNAL(rejected()), this, SLOT(cancel()));
}
PkTransactionWidget::~PkTransactionWidget()
{
// DO NOT disconnect the transaction here,
// it might not exist when this happen
delete d;
}
void PkTransactionWidget::hideCancelButton()
{
// On the session installed we hide the
// cancel button to use the KDialog main one
ui->cancelButton->hide();
}
void PkTransactionWidget::cancel()
{
if (m_trans) {
m_trans->cancel();
}
}
void PkTransactionWidget::setTransaction(PkTransaction *trans, Transaction::Role role)
{
Q_ASSERT(trans);
m_trans = trans;
d->role = role;
// This makes sure the Columns will properly resize to contents
ui->progressView->header()->setStretchLastSection(false);
if (role == Transaction::RoleRefreshCache) {
trans->progressModel()->setColumnCount(1);
ui->progressView->setModel(trans->progressModel());
ui->progressView->header()->setResizeMode(0, QHeaderView::Stretch);
} else {
trans->progressModel()->setColumnCount(3);
ui->progressView->setModel(trans->progressModel());
ui->progressView->header()->reset();
ui->progressView->header()->setResizeMode(0, QHeaderView::ResizeToContents);
ui->progressView->header()->setResizeMode(1, QHeaderView::ResizeToContents);
ui->progressView->header()->setResizeMode(2, QHeaderView::Stretch);
}
connect(m_trans, SIGNAL(percentageChanged()),
SLOT(updateUi()));
connect(m_trans, SIGNAL(speedChanged()),
SLOT(updateUi()));
connect(m_trans, SIGNAL(statusChanged()),
SLOT(updateUi()));
connect(m_trans, SIGNAL(downloadSizeRemainingChanged()),
SLOT(updateUi()));
connect(m_trans, SIGNAL(remainingTimeChanged()),
SLOT(updateUi()));
connect(m_trans, SIGNAL(roleChanged()),
SLOT(updateUi()));
connect(m_trans, SIGNAL(transactionFlagsChanged()),
SLOT(updateUi()));
connect(m_trans, SIGNAL(allowCancelChanged()),
SLOT(updateUi()));
// Forward Q_SIGNALS:
connect(m_trans, SIGNAL(sorry(QString,QString,QString)),
this, SIGNAL(sorry(QString,QString,QString)));
connect(m_trans, SIGNAL(errorMessage(QString,QString,QString)),
SIGNAL(error(QString,QString,QString)));
connect(m_trans, SIGNAL(dialog(KDialog*)),
this, SIGNAL(dialog(KDialog*)));
// sets ui
updateUi();
}
void PkTransactionWidget::unsetTransaction()
{
if (m_trans == 0) {
return;
}
connect(m_trans, SIGNAL(percentageChanged()),
SLOT(updateUi()));
connect(m_trans, SIGNAL(speedChanged()),
SLOT(updateUi()));
connect(m_trans, SIGNAL(statusChanged()),
SLOT(updateUi()));
connect(m_trans, SIGNAL(downloadSizeRemainingChanged()),
SLOT(updateUi()));
connect(m_trans, SIGNAL(remainingTimeChanged()),
SLOT(updateUi()));
connect(m_trans, SIGNAL(roleChanged()),
SLOT(updateUi()));
connect(m_trans, SIGNAL(transactionFlagsChanged()),
SLOT(updateUi()));
connect(m_trans, SIGNAL(allowCancelChanged()),
SLOT(updateUi()));
}
void PkTransactionWidget::updateUi()
{
// sets the action icon to be the window icon
PkTransaction *transaction = qobject_cast<PkTransaction*>(sender());
if (transaction == 0 && (transaction = m_trans) == 0) {
kWarning() << "no transaction object";
return;
}
uint percentage = transaction->percentage();
QString percentageString;
if (percentage <= 100) {
if (ui->progressBar->value() != static_cast<int>(percentage)) {
ui->progressBar->setMaximum(100);
ui->progressBar->setValue(percentage);
percentageString = QString::number(percentage);
}
} else if (ui->progressBar->maximum() != 0) {
ui->progressBar->setMaximum(0);
ui->progressBar->reset();
percentageString = QLatin1String("");
}
ui->progressBar->setRemaining(transaction->remainingTime());
// Status & Speed
Transaction::Status status = transaction->status();
uint speed = transaction->speed();
qulonglong downloadSizeRemaining = transaction->downloadSizeRemaining();
if (m_status != status) {
m_status = status;
ui->currentL->setText(PkStrings::status(status,
speed,
downloadSizeRemaining));
KPixmapSequence sequence = KPixmapSequence(PkIcons::statusAnimation(status),
KIconLoader::SizeLarge);
if (sequence.isValid()) {
d->busySeq->setSequence(sequence);
d->busySeq->start();
}
} else if (status == Transaction::StatusDownload) {
ui->currentL->setText(PkStrings::status(status,
speed,
downloadSizeRemaining));
}
QString windowTitle;
QString windowTitleProgress;
QIcon windowIcon;
Transaction::Role role = transaction->role();
if (role == Transaction::RoleUnknown) {
windowTitle = PkStrings::status(Transaction::StatusSetup);
if (percentageString.isEmpty()) {
windowTitleProgress = PkStrings::status(status,
speed,
downloadSizeRemaining);
} else {
QString statusText = PkStrings::status(status,
speed,
downloadSizeRemaining);
windowTitleProgress = i18n("%1 (%2%)", statusText, percentageString);
}
windowIcon = PkIcons::statusIcon(Transaction::StatusSetup);
} else {
windowTitle = PkStrings::action(role, transaction->transactionFlags());
if (percentageString.isEmpty()) {
windowTitleProgress = PkStrings::status(status,
speed,
downloadSizeRemaining);
} else {
QString statusText = PkStrings::status(status,
speed,
downloadSizeRemaining);
windowTitleProgress = i18n("%1 (%2%)", statusText, percentageString);
}
windowIcon = PkIcons::actionIcon(role);
}
if (d->role != role) {
d->role = role;
setWindowIcon(PkIcons::actionIcon(role));
setWindowTitle(windowTitle);
emit titleChanged(windowTitle);
emit titleChangedProgress(windowTitleProgress);
} else if (!percentageString.isNull()) {
emit titleChangedProgress(windowTitleProgress);
}
// check to see if we can cancel
bool cancel = transaction->allowCancel();
emit allowCancel(cancel);
ui->cancelButton->setEnabled(cancel);
}
bool PkTransactionWidget::isFinished() const
{
// return d->finished;
return false;
}
bool PkTransactionWidget::isCancelVisible() const
{
return ui->cancelButton->isVisible();
}
void PkTransactionWidget::reject()
{
// d->finished = true;
// setExitStatus(Cancelled);
}
void PkTransactionWidget::followBottom(int value)
{
// If the user moves the slider to the bottom
// keep it there as the list expands
QScrollBar *scrollBar = qobject_cast<QScrollBar*>(sender());
m_keepScrollBarAtBottom = value == scrollBar->maximum();
}
void PkTransactionWidget::rangeChanged(int min, int max)
{
Q_UNUSED(min)
QScrollBar *scrollBar = qobject_cast<QScrollBar*>(sender());
if (m_keepScrollBarAtBottom && scrollBar->value() != max) {
scrollBar->setValue(max);
}
}
Transaction::Role PkTransactionWidget::role() const
{
return d->role;
}
PkTransaction *PkTransactionWidget::transaction() const
{
return m_trans;
}
#include "PkTransactionWidget.moc"
|