From 8d7602dc26b223f6653d541544da58cc3b343756 Mon Sep 17 00:00:00 2001 From: Daniel Nicoletti Date: Fri, 4 Jul 2008 22:55:31 -0300 Subject: I moved the Transaction files --- gui/Common/PkTransaction.cpp | 133 +++++++++++++++++++++++++++++++++++++++++++ gui/Common/PkTransaction.h | 57 +++++++++++++++++++ gui/Common/PkTransaction.ui | 108 +++++++++++++++++++++++++++++++++++ 3 files changed, 298 insertions(+) create mode 100755 gui/Common/PkTransaction.cpp create mode 100755 gui/Common/PkTransaction.h create mode 100644 gui/Common/PkTransaction.ui diff --git a/gui/Common/PkTransaction.cpp b/gui/Common/PkTransaction.cpp new file mode 100755 index 0000000..2892479 --- /dev/null +++ b/gui/Common/PkTransaction.cpp @@ -0,0 +1,133 @@ +/*************************************************************************** + * Copyright (C) 2008 by Daniel Nicoletti * + * dantti85-pk@yahoo.com.br * + * * + * 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; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include +#include + +#include "../Common/PkStrings.h" +#include "PkTransaction.h" + +PkTransaction::PkTransaction( Transaction *trans, QString caption, QWidget *parent ) + : KDialog(parent), m_trans(trans) +{ + setupUi( mainWidget() ); + setCaption( caption ); + + connect( m_trans, SIGNAL( GotPackage(Package *) ), this, SLOT( currPackage(Package *) ) ); + connect( m_trans, SIGNAL( Finished(Exit::Value, uint) ), this, SLOT( Finished(Exit::Value, uint) ) ); + connect( m_trans, SIGNAL( AllowCancel(bool) ), this, SLOT( enableButtonCancel(bool) ) ); + connect( m_trans, SIGNAL( ErrorCode(Error::Value, const QString&) ), this, SLOT( ErrorCode(Error::Value, const QString&) ) ); + connect( m_trans, SIGNAL( ProgressChanged(uint, uint, uint, uint) ), this, SLOT( ProgressChanged(uint, uint, uint, uint) ) ); + connect( m_trans, SIGNAL( StatusChanged(Status::Value) ), this, SLOT( StatusChanged(Status::Value) ) ); + + // Set Cancel and custom buoton hide + setButtons( KDialog::Cancel | KDialog::User1 ); + setButtonText( KDialog::User1, i18n("Hide") ); + setButtonToolTip( KDialog::User1, i18n("Allows you to hide the window but keeps running transaction task") ); + enableButtonCancel(false); + + m_pbTimer = new QTimer(this); + connect(m_pbTimer, SIGNAL(timeout()), this, SLOT(updateProgress() )); + m_pbTimer->start(5); + setModal(true); + + // set wait msg + currentL->setText( i18n("Please Wait..." ) ); +} + +void PkTransaction::updateProgress() +{ + progressBar->setValue(progressBar->value() + 1); +} + +void PkTransaction::ProgressChanged(uint percentage, uint /*subpercentage*/, uint /*elapsed*/, uint /*remaining*/) +{ + m_pbTimer->stop(); + progressBar->setMaximum(100); + progressBar->setValue(percentage); +} + +void PkTransaction::currPackage(Package *p) +{ + packageL->setText( p->name() + " - " + p->version() + " (" + p->arch() + ")" ); + descriptionL->setText( p->summary() ); +} + +void PkTransaction::slotButtonClicked(int button) +{ + switch(button) { + case KDialog::Cancel : + m_trans->cancel(); + break; + case KDialog::User1 : + emit Finished(false); + KDialog::slotButtonClicked(KDialog::Close); + break; + case KDialog::Close : + emit Finished(true); + KDialog::slotButtonClicked(KDialog::Close); + break; + default : + KDialog::slotButtonClicked(button); + } +} + +PkTransaction::~PkTransaction() +{ + +} + +void PkTransaction::StatusChanged(Status::Value v) +{ + currentL->setText( PkStrings::StatusChanged(v) ); +} + +void PkTransaction::ErrorCode(Error::Value v, const QString &details) +{ + KMessageBox::detailedSorry( this, PkStrings::ErrorMessage(v), details, PkStrings::Error(v), KMessageBox::Notify ); +} + +void PkTransaction::Finished(Exit::Value status, uint /*runtime*/) +{ + qDebug() << "trans finished: " << status ; + switch(status) { + case Exit::Success : + qDebug() << "trans succes: "; + emit Finished(false); + KDialog::slotButtonClicked(KDialog::Close); + break; + case Exit::Failed : + qDebug() << "trans failed: "; + setButtons( KDialog::Close ); + break; + case Exit::Kill : + qDebug() << "trans quit: "; + break; + case Exit::Cancelled : + qDebug() << "trans cancelled: "; + setButtons( KDialog::Close ); + break; + case Exit::Unknown : + qDebug() << "trans quit: "; + break; + } +} + +#include "PkTransaction.moc" diff --git a/gui/Common/PkTransaction.h b/gui/Common/PkTransaction.h new file mode 100755 index 0000000..6d39f55 --- /dev/null +++ b/gui/Common/PkTransaction.h @@ -0,0 +1,57 @@ +/*************************************************************************** + * Copyright (C) 2008 by Daniel Nicoletti * + * dantti85-pk@yahoo.com.br * + * * + * 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; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef PKTRANSACTION_H +#define PKTRANSACTION_H + +#include + +#include "ui_PkTransaction.h" +#include + +using namespace PackageKit; + +class PkTransaction : public KDialog, Ui::PkTransaction +{ + Q_OBJECT +public: + PkTransaction( Transaction *trans, QString caption, QWidget *parent=0); + ~PkTransaction(); + +signals: + void Finished(bool error); + +private: + Transaction *m_trans; + QTimer *m_pbTimer; + +private slots: + void Finished(Exit::Value status, uint runtime); + void ErrorCode(Error::Value v, const QString &details); + void StatusChanged(Status::Value v); + void currPackage(Package *); + void updateProgress(); + void ProgressChanged(uint percentage, uint subpercentage, uint elapsed, uint remaining); + +protected slots: + virtual void slotButtonClicked(int button); +}; + +#endif diff --git a/gui/Common/PkTransaction.ui b/gui/Common/PkTransaction.ui new file mode 100644 index 0000000..399644a --- /dev/null +++ b/gui/Common/PkTransaction.ui @@ -0,0 +1,108 @@ + + PkTransaction + + + Qt::NonModal + + + + 0 + 0 + 400 + 106 + + + + + 0 + 0 + + + + + 360 + 0 + + + + KPackageKit - Transaction + + + + + + + + + + 12 + 75 + true + + + + + + + + + + Qt::AlignCenter + + + + + + + + + + 0 + + + + + + + + 75 + true + + + + + + + + + + + + + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + + + + -- cgit v1.2.3