1
/***************************************************************************
2
* Copyright (C) 2008-2011 by Daniel Nicoletti *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License as published by *
7
* the Free Software Foundation; either version 2 of the License, or *
8
* (at your option) any later version. *
10
* This program is distributed in the hope that it will be useful, *
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13
* GNU General Public License for more details. *
15
* You should have received a copy of the GNU General Public License *
16
* along with this program; see the file COPYING. If not, write to *
17
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, *
18
* Boston, MA 02110-1301, USA. *
19
***************************************************************************/
23
#include "PkTransactionWidget.h"
24
#include "ui_PkTransactionWidget.h"
27
#include <KMessageBox>
28
#include <KPushButton>
30
#include <KPixmapSequence>
31
#include <KPixmapSequenceOverlayPainter>
35
#include <QStringBuilder>
36
#include <QPropertyAnimation>
37
#include <QtDBus/QDBusMessage>
38
#include <QtDBus/QDBusConnection>
44
#include "PkStrings.h"
46
#include "LicenseAgreement.h"
48
#include "ApplicationLauncher.h"
49
#include "Requirements.h"
50
#include "PkTransaction.h"
51
#include "TransactionDelegate.h"
52
#include "PkTransactionProgressModel.h"
53
#include "PackageModel.h"
55
class PkTransactionWidgetPrivate
58
ApplicationLauncher *launcher;
59
Transaction::Role role;
60
KPixmapSequenceOverlayPainter *busySeq;
63
PkTransactionWidget::PkTransactionWidget(QWidget *parent) :
66
m_keepScrollBarAtBottom(true),
67
m_handlingActionRequired(false),
68
m_showingError(false),
69
m_status(Transaction::StatusUnknown),
70
ui(new Ui::PkTransactionWidget),
71
d(new PkTransactionWidgetPrivate)
75
// Setup the animation sequence
76
d->busySeq = new KPixmapSequenceOverlayPainter(this);
77
d->busySeq->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
78
d->busySeq->setWidget(ui->label);
81
// Connect stuff from the progressView
82
QScrollBar *scrollBar = ui->progressView->verticalScrollBar();
83
connect(scrollBar, SIGNAL(sliderMoved(int)),
84
this, SLOT(followBottom(int)));
85
connect(scrollBar, SIGNAL(valueChanged(int)),
86
this, SLOT(followBottom(int)));
87
connect(scrollBar, SIGNAL(rangeChanged(int,int)),
88
this, SLOT(rangeChanged(int,int)));
90
ui->progressView->setItemDelegate(new TransactionDelegate(this));
92
connect(ui->cancelButton, SIGNAL(rejected()), this, SLOT(cancel()));
95
PkTransactionWidget::~PkTransactionWidget()
97
// DO NOT disconnect the transaction here,
98
// it might not exist when this happen
102
void PkTransactionWidget::hideCancelButton()
104
// On the session installed we hide the
105
// cancel button to use the KDialog main one
106
ui->cancelButton->hide();
109
void PkTransactionWidget::cancel()
116
void PkTransactionWidget::setTransaction(PkTransaction *trans, Transaction::Role role)
123
// This makes sure the Columns will properly resize to contents
124
ui->progressView->header()->setStretchLastSection(false);
125
if (role == Transaction::RoleRefreshCache) {
126
trans->progressModel()->setColumnCount(1);
127
ui->progressView->setModel(trans->progressModel());
128
ui->progressView->header()->setResizeMode(0, QHeaderView::Stretch);
130
trans->progressModel()->setColumnCount(3);
131
ui->progressView->setModel(trans->progressModel());
132
ui->progressView->header()->reset();
133
ui->progressView->header()->setResizeMode(0, QHeaderView::ResizeToContents);
134
ui->progressView->header()->setResizeMode(1, QHeaderView::ResizeToContents);
135
ui->progressView->header()->setResizeMode(2, QHeaderView::Stretch);
138
connect(trans, SIGNAL(changed()), this, SLOT(updateUi()));
141
connect(m_trans, SIGNAL(sorry(QString,QString,QString)),
142
this, SIGNAL(sorry(QString,QString,QString)));
143
connect(m_trans, SIGNAL(errorMessage(QString,QString,QString)),
144
SIGNAL(error(QString,QString,QString)));
145
connect(m_trans, SIGNAL(dialog(KDialog*)),
146
this, SIGNAL(dialog(KDialog*)));
148
// DISCONNECT ALL THESE SIGNALS BEFORE SETTING A NEW ONE
149
connect(m_trans, SIGNAL(changed()),
150
this, SLOT(updateUi()));
152
// DISCONNECT ALL THESE SIGNALS BEFORE SETTING A NEW ONE
158
void PkTransactionWidget::unsetTransaction()
164
disconnect(m_trans, SIGNAL(changed()),
165
this, SLOT(updateUi()));
168
void PkTransactionWidget::updateUi()
170
// sets the action icon to be the window icon
171
Transaction *transaction = qobject_cast<Transaction*>(sender());
172
if (transaction == 0 && (transaction = m_trans) == 0) {
173
kWarning() << "no transaction object";
177
uint percentage = transaction->percentage();
178
if (percentage <= 100) {
179
ui->progressBar->setMaximum(100);
180
ui->progressBar->setValue(percentage);
181
} else if (ui->progressBar->maximum() != 0) {
182
ui->progressBar->setMaximum(0);
183
ui->progressBar->reset();
186
ui->progressBar->setRemaining(transaction->remainingTime());
189
Transaction::Status status = transaction->status();
190
if (m_status != status) {
192
ui->currentL->setText(PkStrings::status(status,
193
transaction->speed(),
194
transaction->downloadSizeRemaining()));
196
KPixmapSequence sequence = KPixmapSequence(PkIcons::statusAnimation(status),
197
KIconLoader::SizeLarge);
198
if (sequence.isValid()) {
199
d->busySeq->setSequence(sequence);
202
} else if (status == Transaction::StatusDownload) {
203
ui->currentL->setText(PkStrings::status(status,
204
transaction->speed(),
205
transaction->downloadSizeRemaining()));
208
Transaction::Role role = transaction->role();
209
if (d->role != role) {
212
if (role == Transaction::RoleUnknown) {
213
windowTitle = PkStrings::status(Transaction::StatusSetup);
214
windowIcon = PkIcons::statusIcon(Transaction::StatusSetup);
216
windowTitle = PkStrings::action(role);
217
windowIcon = PkIcons::actionIcon(role);
220
setWindowIcon(PkIcons::actionIcon(role));
221
setWindowTitle(windowTitle);
222
emit titleChanged(windowTitle);
225
// check to see if we can cancel
226
bool cancel = transaction->allowCancel();
227
emit allowCancel(cancel);
228
ui->cancelButton->setEnabled(cancel);
231
bool PkTransactionWidget::isFinished() const
233
// return d->finished;
237
bool PkTransactionWidget::isCancelVisible() const
239
return ui->cancelButton->isVisible();
242
void PkTransactionWidget::reject()
244
// d->finished = true;
245
// setExitStatus(Cancelled);
248
void PkTransactionWidget::followBottom(int value)
250
// If the user moves the slider to the bottom
251
// keep it there as the list expands
252
QScrollBar *scrollBar = qobject_cast<QScrollBar*>(sender());
253
m_keepScrollBarAtBottom = value == scrollBar->maximum();
256
void PkTransactionWidget::rangeChanged(int min, int max)
259
QScrollBar *scrollBar = qobject_cast<QScrollBar*>(sender());
260
if (m_keepScrollBarAtBottom && scrollBar->value() != max) {
261
scrollBar->setValue(max);
265
QString PkTransactionWidget::title() const
267
return PkStrings::action(d->role);
270
Transaction::Role PkTransactionWidget::role() const
275
#include "PkTransactionWidget.moc"