From 20be1cda48e7d0530125a08cd205745a94467276 Mon Sep 17 00:00:00 2001 From: Daniel Nicoletti Date: Fri, 13 Jun 2008 20:20:16 -0300 Subject: AddRm almost working --- gui/ui/AddRm/CMakeLists.txt | 2 + gui/ui/AddRm/PkAddRm.cpp | 124 +++++++++++------- gui/ui/AddRm/PkAddRm.h | 16 ++- gui/ui/AddRm/PkAddRm.ui | 61 ++++----- gui/ui/AddRm/PkAddRm_Model.cpp | 93 +++++++++++-- gui/ui/AddRm/PkAddRm_Model.h | 25 +++- gui/ui/AddRm/PkDelegate.cpp | 42 +++--- gui/ui/AddRm/PkDelegate.h | 6 +- gui/ui/AddRm/PkReviewChanges.cpp | 273 +++++++++++++++++++++++++++++++++++++++ gui/ui/AddRm/PkReviewChanges.h | 82 ++++++++++++ gui/ui/AddRm/PkReviewChanges.ui | 77 +++++++++++ gui/ui/AddRm/PkTransaction.cpp | 25 +--- gui/ui/AddRm/PkTransaction.h | 4 +- gui/ui/AddRm/PkTransaction.ui | 2 +- gui/ui/AddRm/kpk-addrm.cpp | 5 +- gui/ui/AddRm/kpk-addrm.h | 8 ++ gui/ui/Settings/kpk-settings.cpp | 6 - gui/ui/Settings/kpk-settings.h | 4 +- 18 files changed, 686 insertions(+), 169 deletions(-) create mode 100755 gui/ui/AddRm/PkReviewChanges.cpp create mode 100755 gui/ui/AddRm/PkReviewChanges.h create mode 100644 gui/ui/AddRm/PkReviewChanges.ui diff --git a/gui/ui/AddRm/CMakeLists.txt b/gui/ui/AddRm/CMakeLists.txt index 5e81b91..60c7291 100644 --- a/gui/ui/AddRm/CMakeLists.txt +++ b/gui/ui/AddRm/CMakeLists.txt @@ -3,12 +3,14 @@ set(kpk_addrm_SRCS PkAddRm.cpp PkAddRm_Model.cpp PkDelegate.cpp + PkReviewChanges.cpp PkTransaction.cpp PkRequirements.cpp ) kde4_add_ui_files(kpk_addrm_SRCS PkAddRm.ui + PkReviewChanges.ui PkTransaction.ui PkRequirements.ui ) diff --git a/gui/ui/AddRm/PkAddRm.cpp b/gui/ui/AddRm/PkAddRm.cpp index 15b415a..ae28adb 100755 --- a/gui/ui/AddRm/PkAddRm.cpp +++ b/gui/ui/AddRm/PkAddRm.cpp @@ -20,10 +20,12 @@ #include #include +#include + #include #include -#include "PkTransaction.h" +#include "PkReviewChanges.h" #include "PkAddRm.h" #define UNIVERSAL_PADDING 6 @@ -33,26 +35,45 @@ PkAddRm::PkAddRm( QWidget *parent ) { setupUi( this ); + // Create a new daemon + m_daemon = new Daemon(this); + //initialize the model, delegate, client and connect it's signals packageView->setItemDelegate(pkg_delegate = new PkDelegate(this)); packageView->setModel(m_pkg_model_main = new PkAddRmModel(this)); - updateColumnsWidth(true); - // Create a new daemon - m_daemon = new Daemon(this); -qDebug() << m_daemon->getActions(); - // create the install transaction - m_pkClient_install = m_daemon->newTransaction(); - connect( m_pkClient_install, SIGNAL(GotPackage(Package *)), m_pkg_model_main, SLOT(addPackage(Package *)) ); - connect( m_pkClient_install, SIGNAL(Finished(Exit::Value, uint)), this, SLOT(Finished(Exit::Value, uint)) ); - connect( m_pkClient_install, SIGNAL(Files(Package *, QStringList)), this, SLOT(Files(Package *, QStringList)) ); - connect( m_pkClient_install, SIGNAL( Message(const QString&, const QString&) ), this, SLOT( Message(const QString&, const QString&) ) ); - connect( m_pkClient_install, SIGNAL( ErrorCode(const QString&, const QString&) ), this, SLOT( Message(const QString&, const QString&) ) ); + // check to see if the backend support these actions +// if ( m_daemon->getActions() & Actions::Install_package || m_daemon->getActions() & Actions::Remove_packages) + connect( m_pkg_model_main, SIGNAL( changed(bool) ), this, SIGNAL( changed(bool) ) ); +// qDebug() << "actions" << m_daemon->getActions(); +// qDebug() << "details" << Actions::Get_details; +// if ( m_daemon->getActions() & Actions::Search_group ) +// qDebug() << "ok"; +// else +// qDebug() << "no"; + +// if ( !(m_daemon->getActions() & Actions::Get_details) ) +// tabWidget->setTabEnabled(0, false); +// +// if ( !(m_daemon->getActions() & Actions::Get_requires) ) +// tabWidget->setTabEnabled(1, false); +// +// if ( !(m_daemon->getActions() & Actions::Get_depends) ) +// tabWidget->setTabEnabled(2, false); +// +// if ( !(m_daemon->getActions() & Actions::Get_files) ) +// tabWidget->setTabEnabled(3, false); +// +// if ( !(m_daemon->getActions() & Actions::Search_name) ) +// searchPB->setEnabled(false); +// +// if ( !(m_daemon->getActions() & Actions::Search_group) ) +// groupsCB->setEnabled(false); // create the main transaction m_pkClient_main = m_daemon->newTransaction(); - connect( m_pkClient_main, SIGNAL(GotPackage(Package *)), m_pkg_model_main, SLOT(addPackage(Package *)) ); - connect( m_pkClient_main, SIGNAL(Finished(Exit::Value, uint)), this, SLOT(Finished(Exit::Value, uint)) ); + connect( m_pkClient_main, SIGNAL( GotPackage(Package *)), m_pkg_model_main, SLOT( addPackage(Package *)) ); + connect( m_pkClient_main, SIGNAL( Finished(Exit::Value, uint)), this, SLOT( Finished(Exit::Value, uint)) ); connect( m_pkClient_main, SIGNAL( Message(const QString&, const QString&) ), this, SLOT( Message(const QString&, const QString&) ) ); //initialize the groups @@ -104,14 +125,16 @@ qDebug() << m_daemon->getActions(); // connect the timer... connect(&m_notifyT, SIGNAL(timeout()), this, SLOT(notifyUpdate())); + // set fucus on the search lineEdit + lineEdit->setFocus(Qt::OtherFocusReason); + infoHide(); } void PkAddRm::resizeEvent ( QResizeEvent * event ) { - updateColumnsWidth(); - QWidget::resizeEvent(event); + updateColumnsWidth(); } bool PkAddRm::event ( QEvent * event ) @@ -156,25 +179,22 @@ void PkAddRm::infoHide() { // hides the description to have more space. descriptionDW->setVisible(false); - actionPB->hide(); notifyF->hide(); // cleans the models - m_currPkg = 0; - m_pkg_model_main->clear(); - m_pkg_model_req->clear(); - m_pkg_model_dep->clear(); + m_pkg_model_main->clearPkg(); + m_pkg_model_req->clearPkg(); + m_pkg_model_dep->clearPkg(); } void PkAddRm::infoShow() { descriptionDW->setVisible(true); - notifyF->show(); - actionPB->show(); } void PkAddRm::on_searchPB_clicked() { infoHide(); + updateColumnsWidth(); // qDebug() << "Search Name " << filters() ; m_pkClient_main->searchName( filters(), lineEdit->text() ); } @@ -189,25 +209,41 @@ void PkAddRm::on_groupsCB_currentIndexChanged( const QString & text ) //TODO fix this mapping qDebug() << "Search Group " << text.toLower(); infoHide(); + updateColumnsWidth(); m_pkClient_main->searchGroup( filters(), text.toLower() ); } void PkAddRm::on_packageView_pressed( const QModelIndex & index ) { - m_pkClient_desc->getDetails(m_pkg_model_main->package(index)); - m_currPkg = m_pkg_model_main->package(index); - if (m_currPkg) { - if (m_currPkg->info() == "installed") - actionPB->setText( i18n("Remove") ); - else - actionPB->setText( i18n("Install") ); + if ( index.column() == 0 ) { + Package *p = m_pkg_model_main->package(index); + + // check to see if the backend support and get info + if ( m_daemon->getActions() & Actions::Get_details ) + m_pkClient_desc->getDetails(m_pkg_model_main->package(index)); + + //ask required by packages + if ( m_daemon->getActions() & Actions::Get_requires ) + m_pkClient_req->getRequires("none", p, false); + + //ask depends on packages + if ( m_daemon->getActions() & Actions::Get_depends ) + m_pkClient_dep->getDepends("none", p, false); + + //ask files in packages + if ( m_daemon->getActions() & Actions::Get_files ) + m_pkClient_files->getFiles(p); + } - qDebug() << index.model()->data(index, PkAddRmModel::IdRole).toString(); } -void PkAddRm::on_actionPB_clicked() +void PkAddRm::save() { -packageView->resizeColumnToContents(1); +// KMessageBox::detailedSorry( this, "oi", "oi", i18n("Error PackageKit"), KMessageBox::Notify ); + PkReviewChanges *frm = new PkReviewChanges( m_pkg_model_main->packagesChanges(), this); + frm->exec(); + delete frm; + // Transaction *trans = m_daemon->newTransaction(); // if (m_daemon->getActions().contains("get-depends") ) { // trans->getDepends("~installed", m_currPkg, true); @@ -221,6 +257,11 @@ packageView->resizeColumnToContents(1); // qDebug() << "mainEXEC()"; } +void PkAddRm::load() +{ + m_pkg_model_main->clearPkgChanges(); +} + void PkAddRm::Finished(Exit::Value status, uint runtime) { notifyF->show(); @@ -240,7 +281,9 @@ void PkAddRm::Finished(Exit::Value status, uint runtime) notifyL->setAutoFillBackground(true); m_notifyT.start(50); break; - case Exit::Quit : break; + case Exit::Cancelled : break; + case Exit::KeyRequired : break; + case Exit::EulaRequired : break; case Exit::Kill : break; case Exit::Unknown : break; } @@ -253,8 +296,7 @@ void PkAddRm::notifyUpdate() if ( colorN.alpha() <= 0 ) { m_notifyT.stop(); notifyL->setAutoFillBackground(false); - if ( !actionPB->isVisible() ) - notifyF->hide(); + notifyF->hide(); } else { colorN.setAlpha(colorN.alpha() - 5); @@ -265,16 +307,6 @@ void PkAddRm::notifyUpdate() void PkAddRm::Description(Package *p, const QString& license, const QString& group, const QString& detail, const QString& url, qulonglong size) { - qDebug() << p->id(); - //ask required by packages - m_pkClient_req->getRequires("none", p, false); - - //ask depends on packages - m_pkClient_dep->getDepends("none", p, false); - - //ask files in packages - m_pkClient_files->getFiles(p); - //format and show description QString description; description += "" + i18n("Package Name") + ": " + p->name() + "
"; diff --git a/gui/ui/AddRm/PkAddRm.h b/gui/ui/AddRm/PkAddRm.h index 505ca7a..90f1de3 100755 --- a/gui/ui/AddRm/PkAddRm.h +++ b/gui/ui/AddRm/PkAddRm.h @@ -27,6 +27,7 @@ #include "PkAddRm_Model.h" #include "PkDelegate.h" +#include "../../../lib/QPackageKit.h" #include "ui_PkAddRm.h" using namespace PackageKit; @@ -40,41 +41,48 @@ public: public slots: void on_searchPB_clicked(); - void on_actionPB_clicked(); void on_groupsCB_currentIndexChanged( const QString &text ); void on_packageView_pressed( const QModelIndex &index ); void Description(Package *p, const QString &license, const QString &group, const QString &detail, const QString &url, qulonglong size); void Files(Package *p, QStringList files); void Finished(Exit::Value status, uint runtime); void Message(const QString &one, const QString &two); + void load(); + void save(); private: void infoHide(); void infoShow(); + PkAddRmModel *m_pkg_model_main; PkAddRmModel *m_pkg_model_dep; PkAddRmModel *m_pkg_model_req; PkDelegate *pkg_delegate; + + Daemon *m_daemon; Transaction *m_pkClient_main; Transaction *m_pkClient_desc; Transaction *m_pkClient_files; Transaction *m_pkClient_dep; Transaction *m_pkClient_req; - Transaction *m_pkClient_install; + QTimer m_notifyT; QMenu *m_toolQM; - Daemon *m_daemon; + // We need to keep a list to build the filters string QList actions; void FilterMenu(const QStringList &filters); QString filters(); - Package *m_currPkg; + void updateColumnsWidth(bool force = false); int m_viewWidth; private slots: void notifyUpdate(); +signals: + void changed(bool state); + protected: virtual void resizeEvent ( QResizeEvent * event ); virtual bool event ( QEvent * event ); diff --git a/gui/ui/AddRm/PkAddRm.ui b/gui/ui/AddRm/PkAddRm.ui index f350b96..1d36b4d 100644 --- a/gui/ui/AddRm/PkAddRm.ui +++ b/gui/ui/AddRm/PkAddRm.ui @@ -5,7 +5,7 @@ 0 0 - 694 + 541 426 @@ -88,6 +88,12 @@ 0 + + + 300 + 0 + + 0 @@ -126,10 +132,10 @@ - 2 + 4 22 - 690 - 183 + 533 + 191 @@ -161,8 +167,8 @@ 0 0 - 670 - 135 + 513 + 146 @@ -183,8 +189,8 @@ 0 0 - 670 - 135 + 513 + 146 @@ -208,8 +214,8 @@ 0 0 - 662 - 68 + 272 + 140 @@ -236,8 +242,8 @@ 0 0 - 662 - 68 + 272 + 140 @@ -279,31 +285,6 @@ 0 - - - - 0 - 0 - - - - - 80 - 0 - - - - - 80 - 16777215 - - - - Install - - - - @@ -317,6 +298,12 @@ Notify + + true + + + 5 + diff --git a/gui/ui/AddRm/PkAddRm_Model.cpp b/gui/ui/AddRm/PkAddRm_Model.cpp index 9bc99fa..0b0b0a6 100644 --- a/gui/ui/AddRm/PkAddRm_Model.cpp +++ b/gui/ui/AddRm/PkAddRm_Model.cpp @@ -2,7 +2,17 @@ using namespace PackageKit; -PkAddRmModel::PkAddRmModel(QObject *parent) : QAbstractTableModel(parent), +PkAddRmModel::PkAddRmModel(QObject *parent) + : QAbstractTableModel(parent), +m_iconDeb("application-x-deb"), m_iconRpm("application-x-rpm"), +m_iconTgz("application-x-compressed-tar"), m_iconGeneric("utilities-file-archiver") +{ + +} + +PkAddRmModel::PkAddRmModel(const QList &packages, QObject *parent) + : QAbstractTableModel(parent), +m_packages(packages), m_packagesChanges(packages), m_iconDeb("application-x-deb"), m_iconRpm("application-x-rpm"), m_iconTgz("application-x-compressed-tar"), m_iconGeneric("utilities-file-archiver") { @@ -11,7 +21,7 @@ m_iconTgz("application-x-compressed-tar"), m_iconGeneric("utilities-file-archive int PkAddRmModel::rowCount(const QModelIndex &) const { - return packages.size(); + return m_packages.size(); } int PkAddRmModel::columnCount(const QModelIndex &) const @@ -21,9 +31,9 @@ int PkAddRmModel::columnCount(const QModelIndex &) const QVariant PkAddRmModel::data(const QModelIndex &index, int role) const { - if(index.row() > packages.size()) return QVariant(); + if(index.row() > m_packages.size()) return QVariant(); - Package *p = packages.at(index.row()); + Package *p = m_packages.at(index.row()); switch(role) { case Qt::DisplayRole: @@ -49,34 +59,93 @@ QVariant PkAddRmModel::data(const QModelIndex &index, int role) const case IdRole: return p->id(); + case Qt::CheckStateRole : + for (int i = 0; i < m_packagesChanges.size(); ++i) { + if ( m_packagesChanges.at(i)->id() == package(index)->id() ) + return Qt::Checked; + } + return Qt::Unchecked; + default: return QVariant(); } } -Package * PkAddRmModel::package(const QModelIndex &index) +bool PkAddRmModel::setData( const QModelIndex &index, const QVariant &value, int role) +{ + if ( role == Qt::CheckStateRole && index.column() == 1 ) { + // now we check if we need to add or remove from the list + if ( value.toBool() ) { + // Add + m_packagesChanges.append( package(index) ); + emit dataChanged(index, index); + emit changed( !m_packagesChanges.isEmpty() ); + return true; + } + else { + //remove + for (int i = 0; i < m_packagesChanges.size(); ++i) { + if ( m_packagesChanges.at(i)->id() == package(index)->id() ) + m_packagesChanges.removeAt(i); + } + emit changed( !m_packagesChanges.isEmpty() ); + emit dataChanged(index, index); + return true; + } + } + else + return false; +} + +Qt::ItemFlags PkAddRmModel::flags(const QModelIndex &index) const { - return packages.at(index.row()); + Qt::ItemFlags defaultFlags = QAbstractTableModel::flags(index); + + if ( index.isValid() && index.column() == 1 ) + return Qt::ItemIsUserCheckable | QAbstractTableModel::flags(index); + else + return QAbstractTableModel::flags(index); +} + +Package * PkAddRmModel::package(const QModelIndex &index) const +{ + return m_packages.at(index.row()); } void PkAddRmModel::addPackage(Package *package) { // qDebug() << package->name() << package->version() << package->arch() << package->data() << package->info() << package->summary() ; - beginInsertRows(QModelIndex(), packages.size(), packages.size()); - packages.append(package); + beginInsertRows(QModelIndex(), m_packages.size(), m_packages.size()); + m_packages.append(package); + endInsertRows(); +} + +void PkAddRmModel::addUniquePackage(Package *package) +{ + for (int i = 0; i < m_packages.size(); ++i) + if ( m_packages.at(i)->id() == package->id() ) + return; + beginInsertRows(QModelIndex(), m_packages.size(), m_packages.size()); + m_packages.append(package); endInsertRows(); } void PkAddRmModel::removePackage(Package *package) { beginRemoveRows(QModelIndex(), 1, 1); - packages.removeAt(packages.indexOf(package)); + m_packages.removeAt(m_packages.indexOf(package)); endRemoveRows(); } -void PkAddRmModel::clear() +void PkAddRmModel::clearPkg() { - beginRemoveRows(QModelIndex(), 0, packages.size()); - packages.clear(); + beginRemoveRows(QModelIndex(), 0, m_packages.size()); + m_packages.clear(); endRemoveRows(); } + +void PkAddRmModel::clearPkgChanges() +{ + m_packagesChanges.clear(); + emit changed( !m_packagesChanges.isEmpty() ); +} diff --git a/gui/ui/AddRm/PkAddRm_Model.h b/gui/ui/AddRm/PkAddRm_Model.h index 7753cf5..a74aca8 100644 --- a/gui/ui/AddRm/PkAddRm_Model.h +++ b/gui/ui/AddRm/PkAddRm_Model.h @@ -14,15 +14,20 @@ Q_OBJECT public: PkAddRmModel(QObject *parent = 0); + PkAddRmModel(const QList &packages, QObject *parent = 0); + int rowCount(const QModelIndex &/*parent = QModelIndex()*/) const; int columnCount(const QModelIndex &) const; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; -public slots: - void addPackage(Package *package); -public: + bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); + Qt::ItemFlags flags(const QModelIndex &index) const; + void removePackage(Package *package); - Package * package(const QModelIndex &index); - void clear(); + Package * package(const QModelIndex &index) const; + void clearPkg(); + void clearPkgChanges(); + + QList packagesChanges() { return m_packagesChanges; }; enum { SummaryRole = 32, @@ -30,8 +35,16 @@ public: IdRole }; +public slots: + void addPackage(Package *package); + void addUniquePackage(Package *package); + +signals: + void changed(bool state); + private: - QList packages; + QList m_packages; + QList m_packagesChanges; KIcon m_iconDeb; KIcon m_iconRpm; KIcon m_iconTgz; diff --git a/gui/ui/AddRm/PkDelegate.cpp b/gui/ui/AddRm/PkDelegate.cpp index 02c7c3c..666af55 100644 --- a/gui/ui/AddRm/PkDelegate.cpp +++ b/gui/ui/AddRm/PkDelegate.cpp @@ -47,10 +47,7 @@ void PkDelegate::paint(QPainter *painter, { // KCategorizedItemsViewModels::AbstractItem * item = // getItemByProxyIndex(index); -// if (!item) return; - -if ( option.state & QStyle::State_MouseOver ) - kDebug() << "oi"; + if (!index.isValid()) return; QStyleOptionViewItemV4 opt(option); QStyle *style = opt.widget ? opt.widget->style() : QApplication::style(); @@ -209,11 +206,15 @@ void PkDelegate::paintColFav(QPainter *painter, // m_onFavoriteIconItem = NULL; QIcon::Mode iconMode = QIcon::Normal; -// if (!index.model()->data(index, PkAddRmModel::InstalledRole).toBool()) { + if ( index.model()->data(index, Qt::CheckStateRole).toBool() ) { + iconMode = QIcon::Active; + } else /*if (option.state & QStyle::State_MouseOver)*/ { iconMode = QIcon::Disabled; -// } else if (option.state & QStyle::State_MouseOver) { -// iconMode = QIcon::Active; -// } + } + +// kDebug() << index.column(); + +// const KIcon * icon = ( index.model()->data(index, PkAddRmModel::InstalledRole).toBool() )? & m_removeIcon : & m_addIcon; if ( index.model()->data(index, PkAddRmModel::InstalledRole).toBool() ) m_removeIcon.paint(painter, @@ -224,18 +225,15 @@ void PkDelegate::paintColFav(QPainter *painter, left + width - FAV_ICON_SIZE - UNIVERSAL_PADDING, top + UNIVERSAL_PADDING, FAV_ICON_SIZE, FAV_ICON_SIZE, Qt::AlignCenter, iconMode); - iconMode = QIcon::Active; + iconMode = QIcon::Active; - const KIcon * icon = (index.model()->data(index, PkAddRmModel::InstalledRole).toBool())? & m_removeIcon : & m_addIcon; + const KIcon * icon = (index.model()->data(index, Qt::CheckStateRole).toBool() )? & m_removeIcon : & m_addIcon; if ( option.state & QStyle::State_MouseOver ) -{ -kDebug() << "oi"; icon->paint(painter, left + width - EMBLEM_ICON_SIZE - UNIVERSAL_PADDING, top + UNIVERSAL_PADDING, EMBLEM_ICON_SIZE, EMBLEM_ICON_SIZE, Qt::AlignCenter, iconMode); } -} // void PkDelegate::paintColRemove(QPainter *painter, // const QStyleOptionViewItem &option, const KCategorizedItemsViewModels::AbstractItem * item) const @@ -279,20 +277,10 @@ bool PkDelegate::editorEvent(QEvent *event, const QStyleOptionViewItem &option, const QModelIndex &index) { -// if (event->type() == QEvent::MouseButtonPress) { -// KCategorizedItemsViewModels::AbstractItem * item = getItemByProxyIndex(index); -// if (index.column() == 1) { -// m_onFavoriteIconItem = item; -// item->setFavorite(!item->isFavorite()); -// return true; -// } else if (index.column() == 2 && item->running()) { -// item->setRunning(0); -// emit destroyApplets(item->name()); -// return true; -// } -// } -// -// return QItemDelegate::editorEvent(event, model, option, index); + if ( event->type() == QEvent::MouseButtonPress && index.column() == 1 ) + return model->setData(index, !model->data(index, Qt::CheckStateRole).toBool(), Qt::CheckStateRole ); + else + return QItemDelegate::editorEvent(event, model, option, index); } QSize PkDelegate::sizeHint(const QStyleOptionViewItem &option, diff --git a/gui/ui/AddRm/PkDelegate.h b/gui/ui/AddRm/PkDelegate.h index 9c6317b..a7244e6 100644 --- a/gui/ui/AddRm/PkDelegate.h +++ b/gui/ui/AddRm/PkDelegate.h @@ -26,7 +26,7 @@ #include /** - * Delegate for displaying the items + * Delegate for displaying the packages */ class PkDelegate: public QItemDelegate { @@ -44,8 +44,6 @@ public: const QStyleOptionViewItem &option, const QModelIndex &index); -Q_SIGNALS: - void destroyApplets(const QString name); private: KIcon m_addIcon; KIcon m_removeIcon; @@ -58,4 +56,4 @@ private: int calcItemHeight(const QStyleOptionViewItem &option) const; }; -#endif /*KCATEGORIZEDITEMSVIEWDELEGATE_H_*/ +#endif diff --git a/gui/ui/AddRm/PkReviewChanges.cpp b/gui/ui/AddRm/PkReviewChanges.cpp new file mode 100755 index 0000000..b36e910 --- /dev/null +++ b/gui/ui/AddRm/PkReviewChanges.cpp @@ -0,0 +1,273 @@ +/*************************************************************************** + * Copyright (C) 2008 by Daniel Nicoletti * + * mirttex85-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 "PkTransaction.h" +#include "PkRequirements.h" +#include "PkReviewChanges.h" + +#define UNIVERSAL_PADDING 6 + +PkReviewChanges::PkReviewChanges( const QList &packages, QWidget *parent ) + : KDialog(parent) +{ + setupUi( mainWidget() ); + + //initialize the model, delegate, client and connect it's signals + packageView->setItemDelegate(m_pkgDelegate = new PkDelegate(this)); + packageView->setModel(m_pkgModelMain = new PkAddRmModel(packages, this)); + connect( m_pkgModelMain, SIGNAL( changed(bool) ), this, SLOT( enableButtonApply(bool) ) ); + + setCaption( "Review Changes - KPackageKit" ); + + // Set Apply and Cancel buttons + setButtons( KDialog::Apply | KDialog::Cancel ); + +// m_pbTimer = new QTimer(this); +// connect(m_pbTimer, SIGNAL(timeout()), this, SLOT(updateProgress() )); +// m_pbTimer->start(5); + + label->setText( i18n("Please Wait..." ) ); +} + +void PkReviewChanges::updateProgress() +{ +// progressBar->setValue(progressBar->value() + 1); +} + +void PkReviewChanges::ProgressChanged(uint /*percentage*/, uint /*subpercentage*/, uint /*elapsed*/, uint /*remaining*/) +{ +// m_pbTimer->stop(); +// progressBar->setMaximum(100); +// progressBar->setValue(percentage); +} + +void PkReviewChanges::currPackage(Package */*p*/) +{ +// packageL->setText( p->name() + " - " + p->version() + " (" + p->arch() + ")" ); +// descriptionL->setText( p->summary() ); +} + +PkReviewChanges::~PkReviewChanges() +{ + +} + +void PkReviewChanges::ErrorCode(const QString &one, const QString &two) +{ + KMessageBox::detailedSorry( this, one, two, i18n("Erro PackageKit"), KMessageBox::Notify ); +} + +void PkReviewChanges::doAction() +{ + m_daemon = new Daemon(this); + + // check what packages are installed and marked to be removed + for (int i = 0; i < m_pkgModelMain->packagesChanges().size(); ++i) { + if ( m_pkgModelMain->packagesChanges().at(i)->info() == "installed" ) + m_remPackages << m_pkgModelMain->packagesChanges().takeAt(i); + } + + // check what packages are avaliable and marked to be installed + for (int i = 0; i < m_pkgModelMain->packagesChanges().size(); ++i) { + if ( m_pkgModelMain->packagesChanges().at(i)->info() == "available" ) + m_addPackages << m_pkgModelMain->packagesChanges().takeAt(i); + } + + checkTask(); +} + +void PkReviewChanges::checkTask() +{ + if ( !m_remPackages.isEmpty() ) { + if ( m_daemon->getActions() & Actions::Remove_packages ) { + if ( m_daemon->getActions() & Actions::Get_requires ) { + m_reqDepPackages = m_remPackages; + // Create the requirements transaction and it's model + m_transactionReq = m_daemon->newTransaction(); + m_pkgModelReq = new PkAddRmModel(this); + connect( m_transactionReq, SIGNAL( GotPackage(Package *) ), m_pkgModelReq, SLOT( addUniquePackage(Package *) ) ); + connect( m_transactionReq, SIGNAL( Finished(Exit::Value, uint) ), this, SLOT( reqFinished(Exit::Value, uint) ) ); + m_transactionReq->getRequires("installed", m_remPackages.takeFirst(), true); + } + } + else + KMessageBox::error( this, i18n("Sorry, your backend does not support removing packages"), i18n("Erro KPackageKit") ); + } + else if ( !m_addPackages.isEmpty() ) { + if ( m_daemon->getActions() & Actions::Install_package ) { + if ( m_daemon->getActions() & Actions::Get_depends ) { + m_reqDepPackages = m_addPackages; + // Create the depends transaction and it's model + m_transactionDep = m_daemon->newTransaction(); + m_pkgModelDep = new PkAddRmModel(this); + connect( m_transactionDep, SIGNAL( GotPackage(Package *) ), m_pkgModelDep, SLOT( addUniquePackage(Package *) ) ); + connect( m_transactionDep, SIGNAL( Finished(Exit::Value, uint) ), this, SLOT( reqFinished(Exit::Value, uint) ) ); + m_transactionDep->getDepends("~installed", m_reqDepPackages.takeFirst(), true); + } + } + else + KMessageBox::error( this, i18n("Sorry, your backend does not support installing packages"), i18n("Erro KPackageKit") ); + } + else + close(); +} + +void PkReviewChanges::reqFinished(Exit::Value status, uint /*runtime*/) +{ + if (status == Exit::Success) { + if ( m_reqDepPackages.isEmpty() ) { + if ( m_pkgModelReq->rowCount( QModelIndex() ) > 0 ) { + KDialog *dialog = new KDialog( this ); + dialog->setCaption( "Confirm" ); + dialog->setButtons( KDialog::Ok | KDialog::Cancel ); + PkRequirements *widget = new PkRequirements( i18n("The following packages must also be removed"), m_pkgModelReq, this ); + dialog->setMainWidget( widget ); + connect( dialog, SIGNAL( okClicked() ), this, SLOT( removePackages() ) ); + connect( dialog, SIGNAL( cancelClicked() ), this, SLOT( close() ) ); + dialog->exec(); + } + else + removePackages(); + } + else + m_transactionReq->getRequires("installed", m_reqDepPackages.takeFirst(), true); + } + else { + qDebug() << "getReq Failed: " << status; + m_reqDepPackages.clear(); + checkTask(); + } +} + +void PkReviewChanges::removePackages() +{ + m_trans = m_daemon->newTransaction(); + PkTransaction *frm = new PkTransaction(m_trans, i18n("Install Packages"), this); + connect( m_trans, SIGNAL( Finished(Exit::Value, uint) ), this, SLOT( remFinished(Exit::Vaue, uint) ) ); + m_trans->removePackages(m_remPackages); + frm->exec(); +} + +void PkReviewChanges::depFinished(Exit::Value status, uint /*runtime*/) +{ + if (status == Exit::Success) { + if ( m_reqDepPackages.isEmpty() ) { + if ( m_pkgModelDep->rowCount( QModelIndex() ) > 0 ) { + KDialog *dialog = new KDialog( this ); + dialog->setCaption( "Confirm" ); + dialog->setButtons( KDialog::Ok | KDialog::Cancel ); + PkRequirements *widget = new PkRequirements( i18n("The following packages must also be installed"), m_pkgModelDep, this ); + dialog->setMainWidget( widget ); + connect( dialog, SIGNAL( okClicked() ), this, SLOT( installPackages() ) ); + connect( dialog, SIGNAL( cancelClicked() ), this, SLOT( close() ) ); + dialog->exec(); + } + else + installPackages(); + } + else + m_transactionDep->getDepends("~installed", m_reqDepPackages.takeFirst(), true); + } + else { + qDebug() << "getDep Failed: " << status; + m_reqDepPackages.clear(); + checkTask(); + } +} + +void PkReviewChanges::installPackages() +{ + m_trans = m_daemon->newTransaction(); + PkTransaction *frm = new PkTransaction(m_trans, QString(i18n("Install Packages")), this); + connect( m_trans, SIGNAL( Finished(Exit::Value, uint) ), this, SLOT( addFinished(Exit::Vaue, uint) ) ); + m_trans->installPackages(m_remPackages); + frm->exec(); +} + +void PkReviewChanges::remFinished(Exit::Value status, uint /*runtime*/) +{ + if (status == Exit::Success) { + m_remPackages.clear(); + checkTask(); + } + else + KMessageBox::error( this, i18n("Sorry an error ocoured"), i18n("Erro KPackageKit") ); +} + +void PkReviewChanges::addFinished(Exit::Value status, uint /*runtime*/) +{ + if (status == Exit::Success) { + m_addPackages.clear(); + checkTask(); + } + else + KMessageBox::error( this, i18n("Sorry an error ocoured"), i18n("Erro KPackageKit") ); +} + +void PkReviewChanges::slotButtonClicked(int button) +{ + switch(button) { + case KDialog::Cancel : + close(); + break; + case KDialog::Apply : + doAction(); + break; + default : + KDialog::slotButtonClicked(button); + } +} + +void PkReviewChanges::resizeEvent ( QResizeEvent * event ) +{ + QWidget::resizeEvent(event); + updateColumnsWidth(); +} + +bool PkReviewChanges::event ( QEvent * event ) +{ + switch (event->type()) { + case QEvent::PolishRequest: + case QEvent::Polish: + updateColumnsWidth(true); + break; + default: + break; + } + + return QWidget::event(event); +} + +void PkReviewChanges::updateColumnsWidth(bool force) +{ + m_viewWidth = packageView->viewport()->width(); + + if (force) { + m_viewWidth -= style()->pixelMetric(QStyle::PM_ScrollBarExtent) + UNIVERSAL_PADDING; + } + + packageView->setColumnWidth(0, m_pkgDelegate->columnWidth(0, m_viewWidth)); + packageView->setColumnWidth(1, m_pkgDelegate->columnWidth(1, m_viewWidth)); +} + +#include "PkReviewChanges.moc" diff --git a/gui/ui/AddRm/PkReviewChanges.h b/gui/ui/AddRm/PkReviewChanges.h new file mode 100755 index 0000000..a1fe971 --- /dev/null +++ b/gui/ui/AddRm/PkReviewChanges.h @@ -0,0 +1,82 @@ +/*************************************************************************** + * Copyright (C) 2008 by Daniel Nicoletti * + * mirttex85-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 PKREVIEWCHANGES_H +#define PKREVIEWCHANGES_H + +#include + +#include "PkDelegate.h" +#include "PkAddRm_Model.h" +#include "ui_PkReviewChanges.h" +#include "../../../lib/QPackageKit.h" + +using namespace PackageKit; + +class PkReviewChanges : public KDialog, Ui::PkReviewChanges +{ + Q_OBJECT +public: + PkReviewChanges( const QList &packages, QWidget *parent=0); + ~PkReviewChanges(); + +public slots: + void remFinished(Exit::Value status, uint runtime); + void addFinished(Exit::Value status, uint runtime); + void ErrorCode(const QString &one, const QString &two); +// void StatusChanged(Status::Value v); + void ProgressChanged(uint percentage, uint subpercentage, uint elapsed, uint remaining); + void reqFinished(Exit::Value status, uint runtime); + void depFinished(Exit::Value status, uint runtime); + void installPackages(); + void removePackages(); + +private: + PkAddRmModel *m_pkgModelMain, *m_pkgModelReq, *m_pkgModelDep; + PkDelegate *m_pkgDelegate; + Daemon *m_daemon; + Transaction *m_trans; + Transaction *m_transactionReq; + Transaction *m_transactionDep; + QTimer m_notifyT; + QTimer *m_pbTimer; + int m_viewWidth; + + void updateColumnsWidth(bool force = false); + void doAction(); + void checkTask(); + + QList m_remPackages; + QList m_addPackages; + QList m_reqDepPackages; + +private slots: + void currPackage(Package *); + void updateProgress(); + +protected slots: + virtual void slotButtonClicked(int button); + +protected: + virtual void resizeEvent( QResizeEvent * event ); + virtual bool event( QEvent * event ); +}; + +#endif diff --git a/gui/ui/AddRm/PkReviewChanges.ui b/gui/ui/AddRm/PkReviewChanges.ui new file mode 100644 index 0000000..fca0f10 --- /dev/null +++ b/gui/ui/AddRm/PkReviewChanges.ui @@ -0,0 +1,77 @@ + + PkReviewChanges + + + + 0 + 0 + 451 + 402 + + + + Review Changes - KPackageKit + + + + + + + 12 + 75 + true + + + + You selected the folowwing packages to be INSTALLED/REMOVED, press ok to proced: + + + Qt::AlignCenter + + + true + + + + + + + + 2 + 0 + + + + + 300 + 0 + + + + + 0 + 2 + + + + + + + false + + + false + + + true + + + false + + + + + + + + diff --git a/gui/ui/AddRm/PkTransaction.cpp b/gui/ui/AddRm/PkTransaction.cpp index 9b73f74..b90151b 100755 --- a/gui/ui/AddRm/PkTransaction.cpp +++ b/gui/ui/AddRm/PkTransaction.cpp @@ -27,37 +27,25 @@ // #include "PkRequirements.h" #include "PkTransaction.h" -PkTransaction::PkTransaction( Transaction *trans, QString &caption, QWidget *parent ) +PkTransaction::PkTransaction( Transaction *trans, QString caption, QWidget *parent ) : KDialog(parent), m_trans(trans) { setupUi( mainWidget() ); setCaption( caption ); -// // Create a new daemon -// m_daemon = new Daemon(this); -// // Create the requirements transaction and it's model -// m_pkClient_req = m_daemon->newTransaction(); -// m_pkg_model_req = new PkAddRmModel(this); -// connect( m_pkClient_req, SIGNAL( GotPackage(Package *) ), m_pkg_model_req, SLOT( addPackage(Package *) ) ); -// connect( m_pkClient_req, SIGNAL( Finished(Exit::Value, uint) ), this, SLOT( reqFinished(Exit::Value, uint) ) ); - -// // create the install transaction -// m_pkClient_action = m_daemon->newTransaction(); + 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(const QString&, const QString&) ), this, SLOT( ErrorCode(const QString&, 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 bt hide + // 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_pkClient_req->getDepends("~installed", pkg, true); m_pbTimer = new QTimer(this); connect(m_pbTimer, SIGNAL(timeout()), this, SLOT(updateProgress() )); m_pbTimer->start(5); @@ -168,14 +156,9 @@ void PkTransaction::StatusChanged(Status::Value v) void PkTransaction::ErrorCode(const QString &one, const QString &two) { - KMessageBox::detailedSorry( this, one, two, i18n("Error PackageKit"), KMessageBox::Notify ); + KMessageBox::detailedSorry( this, one, two, i18n("Erro PackageKit"), KMessageBox::Notify ); } -// void PkTransaction::doAction() -// { -// m_pkClient_action->installPackage(m_targetPackage); -// } - // void PkTransaction::reqFinished(Exit::Value status, uint runtime) // { // switch(status) { diff --git a/gui/ui/AddRm/PkTransaction.h b/gui/ui/AddRm/PkTransaction.h index 46e9876..898b5cd 100755 --- a/gui/ui/AddRm/PkTransaction.h +++ b/gui/ui/AddRm/PkTransaction.h @@ -23,7 +23,6 @@ #include -// #include "PkAddRm_Model.h" #include "ui_PkTransaction.h" #include "../../../lib/QPackageKit.h" @@ -33,7 +32,7 @@ class PkTransaction : public KDialog, Ui::PkTransaction { Q_OBJECT public: - PkTransaction( Transaction *trans, QString &caption, QWidget *parent=0); + PkTransaction( Transaction *trans, QString caption, QWidget *parent=0); ~PkTransaction(); public slots: @@ -43,7 +42,6 @@ public slots: void StatusChanged(Status::Value v); void ProgressChanged(uint percentage, uint subpercentage, uint elapsed, uint remaining); private: -// PkAddRmModel *m_pkg_model_req; Transaction *m_trans; QTimer m_notifyT; QTimer *m_pbTimer; diff --git a/gui/ui/AddRm/PkTransaction.ui b/gui/ui/AddRm/PkTransaction.ui index 5982683..1dc82a3 100644 --- a/gui/ui/AddRm/PkTransaction.ui +++ b/gui/ui/AddRm/PkTransaction.ui @@ -2,7 +2,7 @@ PkTransaction - Qt::ApplicationModal + Qt::WindowModal diff --git a/gui/ui/AddRm/kpk-addrm.cpp b/gui/ui/AddRm/kpk-addrm.cpp index 2ca4053..041d760 100644 --- a/gui/ui/AddRm/kpk-addrm.cpp +++ b/gui/ui/AddRm/kpk-addrm.cpp @@ -30,8 +30,11 @@ KPackageKit::KPackageKit(QWidget *parent, const QVariantList &args) { KAboutData *about = new KAboutData("kcm_kpk_addrm", 0, ki18n("Add and Remove Software"),"0.1"); setAboutData(about); - setButtons(0);/*NoAdditionalButton*/ + setButtons(Apply); m_grid = new QGridLayout(this); view = new PkAddRm(this); + connect(this, SIGNAL(s_load()), view, SLOT(load()) ); + connect(this, SIGNAL(s_save()), view, SLOT(save()) ); + connect(view, SIGNAL(changed(bool)), this, SIGNAL(changed(bool)) ); m_grid->addWidget(view); } diff --git a/gui/ui/AddRm/kpk-addrm.h b/gui/ui/AddRm/kpk-addrm.h index c7a5d84..d4a5674 100644 --- a/gui/ui/AddRm/kpk-addrm.h +++ b/gui/ui/AddRm/kpk-addrm.h @@ -29,6 +29,14 @@ Q_OBJECT public: KPackageKit(QWidget *parent, const QVariantList &args); +public slots: + virtual void load() { emit(s_load()); }; + virtual void save() { emit(s_save()); }; + +signals: + void s_load(); + void s_save(); + private: PkAddRm *view; QGridLayout *m_grid; diff --git a/gui/ui/Settings/kpk-settings.cpp b/gui/ui/Settings/kpk-settings.cpp index 5d28d41..f678e64 100644 --- a/gui/ui/Settings/kpk-settings.cpp +++ b/gui/ui/Settings/kpk-settings.cpp @@ -38,9 +38,3 @@ KPackageKit::KPackageKit(QWidget *parent, const QVariantList &args) connect(view, SIGNAL(changed(bool)), this, SIGNAL(changed(bool)) ); m_grid->addWidget(view); } - -KPackageKit::~KPackageKit() -{ - delete view; - delete m_grid; -} diff --git a/gui/ui/Settings/kpk-settings.h b/gui/ui/Settings/kpk-settings.h index d244923..5703254 100644 --- a/gui/ui/Settings/kpk-settings.h +++ b/gui/ui/Settings/kpk-settings.h @@ -29,15 +29,17 @@ Q_OBJECT public: KPackageKit(QWidget *parent, const QVariantList &args); - ~KPackageKit(); + public slots: virtual void load() { emit(s_load()); }; virtual void save() { emit(s_save()); }; virtual void defaults() { emit(s_defaults()); }; + signals: void s_load(); void s_save(); void s_defaults(); + private: PkSettings *view; QGridLayout *m_grid; -- cgit v1.2.3