Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:12.3
apper
0015-Change-the-way-we-toggle-repos-so-that-we-...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 0015-Change-the-way-we-toggle-repos-so-that-we-can-report.patch of Package apper
From 856a72c2c4e9b30081093fbfc97eb3e40359bed5 Mon Sep 17 00:00:00 2001 From: Daniel Nicoletti <dantti12@gmail.com> Date: Thu, 17 Jan 2013 18:42:02 -0200 Subject: [PATCH 15/20] Change the way we toggle repos so that we can report that an error happened to the user --- ApperKCM/Settings/OriginModel.cpp | 99 +++++++++++++++++---------------------- ApperKCM/Settings/OriginModel.h | 19 ++++++-- ApperKCM/Settings/Settings.cpp | 28 ++++------- ApperKCM/Settings/Settings.h | 1 + 4 files changed, 69 insertions(+), 78 deletions(-) diff --git a/ApperKCM/Settings/OriginModel.cpp b/ApperKCM/Settings/OriginModel.cpp index 6cb4907..faae248 100644 --- a/ApperKCM/Settings/OriginModel.cpp +++ b/ApperKCM/Settings/OriginModel.cpp @@ -22,16 +22,13 @@ #include <PkStrings.h> -#include <KDebug> #include <KMessageBox> #include <KLocale> -#include <QEventLoop> +#include <KDebug> using namespace PackageKit; -Q_DECLARE_METATYPE(Qt::CheckState) - OriginModel::OriginModel(QObject *parent) : QStandardItemModel(parent), m_finished(true) @@ -44,6 +41,37 @@ OriginModel::~OriginModel() { } +bool OriginModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if (role == Qt::CheckStateRole && index.isValid()) { + Transaction *transaction = new Transaction(this); + connect(transaction, SIGNAL(errorCode(PackageKit::Transaction::Error,QString)), + SLOT(errorCode(PackageKit::Transaction::Error,QString))); + connect(transaction, SIGNAL(finished(PackageKit::Transaction::Exit,uint)), + SLOT(setRepoFinished(PackageKit::Transaction::Exit))); + + transaction->repoEnable(index.data(RepoId).toString(), + value.toBool()); + if (transaction->error()) { + KMessageBox::sorry(0, PkStrings::daemonError(transaction->error())); + } + } + return false; +} + +QVariantHash OriginModel::changes() const +{ + QVariantHash ret; + for (int i = 0; i < rowCount(); ++i) { + QStandardItem *repo = item(i); + bool currentState = repo->checkState(); + if (currentState != repo->data(RepoInitialState).toBool()) { + ret[repo->data(RepoId).toString()] = currentState; + } + } + return ret; +} + void OriginModel::addOriginItem(const QString &repo_id, const QString &details, bool enabled) { if (m_finished) { @@ -52,12 +80,11 @@ void OriginModel::addOriginItem(const QString &repo_id, const QString &details, m_finished = false; } - Qt::CheckState state = enabled ? Qt::Checked : Qt::Unchecked; QStandardItem *item = new QStandardItem(details); item->setCheckable(true); - item->setCheckState(state); - item->setData(repo_id, Qt::UserRole); - item->setData(qVariantFromValue(state)); + item->setCheckState(enabled ? Qt::Checked : Qt::Unchecked); + item->setData(repo_id, RepoId); + item->setData(enabled, RepoInitialState); appendRow(item); } @@ -66,61 +93,19 @@ void OriginModel::finished() m_finished = true; } -void OriginModel::clearChanges() +void OriginModel::errorCode(PackageKit::Transaction::Error error, const QString &details) { - for (int i = 0; i < rowCount(); ++i) { - QStandardItem *repo = item(i); - if (repo->checkState() != repo->data().value<Qt::CheckState>()) { - repo->setCheckState(repo->data().value<Qt::CheckState>()); - } + if (error != Transaction::ErrorTransactionCancelled) { + KMessageBox::detailedSorry(0, PkStrings::errorMessage(error), details, PkStrings::error(error), KMessageBox::Notify); } } -bool OriginModel::changed() const +void OriginModel::setRepoFinished(Transaction::Exit exit) { - for (int i = 0; i < rowCount(); ++i) { - QStandardItem *repo = item(i); - if (repo->checkState() != repo->data().value<Qt::CheckState>()) { - return true; - } - } - return false; -} - -bool OriginModel::save() -{ - bool changed = false; - int rows = rowCount(); - QEventLoop loop; - for (int i = 0; i < rows; ++i) { - QStandardItem *repo = item(i); - if (repo->checkState() != repo->data().value<Qt::CheckState>()) { - Transaction *transaction = new Transaction(this); - QWeakPointer<Transaction> pointer = transaction; - connect(transaction, SIGNAL(finished(PackageKit::Transaction::Exit,uint)), - &loop, SLOT(quit())); - transaction->repoEnable(repo->data(Qt::UserRole).toString(), - static_cast<bool>(repo->checkState())); - if (transaction->error()) { - KMessageBox::sorry(0, PkStrings::daemonError(transaction->error())); - return false; - } - loop.exec(); - changed = true; - - if (pointer.isNull()) { - // Avoid crashing when the application is quitting - return false; - } - } - } - - // refresh the user cache if he or she enables/disables any of it - if (changed) { - // TODO ask to refresh the cache - // TODO emit refresh requested + if (exit == Transaction::ExitSuccess) { + emit refreshRepoList(); } - return true; + sender()->deleteLater(); } #include "OriginModel.moc" diff --git a/ApperKCM/Settings/OriginModel.h b/ApperKCM/Settings/OriginModel.h index 294baf2..318017c 100644 --- a/ApperKCM/Settings/OriginModel.h +++ b/ApperKCM/Settings/OriginModel.h @@ -23,21 +23,34 @@ #include <QStandardItemModel> +#include <Transaction> + class OriginModel : public QStandardItemModel { Q_OBJECT public: + enum { + RepoId = Qt::UserRole, + RepoInitialState + } RepoRole; OriginModel(QObject *parent = 0); ~OriginModel(); - bool changed() const; - bool save(); - void clearChanges(); + bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); + + QVariantHash changes() const; + +signals: + void refreshRepoList(); public slots: void addOriginItem(const QString &repo_id, const QString &details, bool enabled); void finished(); +private slots: + void errorCode(PackageKit::Transaction::Error error, const QString &details); + void setRepoFinished(PackageKit::Transaction::Exit exit); + private: bool m_finished; }; diff --git a/ApperKCM/Settings/Settings.cpp b/ApperKCM/Settings/Settings.cpp index 7f54adb..d526494 100644 --- a/ApperKCM/Settings/Settings.cpp +++ b/ApperKCM/Settings/Settings.cpp @@ -25,6 +25,7 @@ #include "OriginModel.h" #include <Enum.h> +#include <PkStrings.h> #include <QTimer> #include <QSortFilterProxyModel> @@ -59,6 +60,8 @@ Settings::Settings(Transaction::Roles roles, QWidget *parent) : } m_originModel = new OriginModel(this); + connect(m_originModel, SIGNAL(refreshRepoList()), + SLOT(refreshRepoModel())); QSortFilterProxyModel *proxy = new QSortFilterProxyModel(this); proxy->setDynamicSortFilter(true); proxy->setSourceModel(m_originModel); @@ -67,11 +70,7 @@ Settings::Settings(Transaction::Roles roles, QWidget *parent) : // This is needed to keep the oring right ui->originTV->header()->setSortIndicator(0, Qt::AscendingOrder); proxy->sort(0); - if (m_roles & Transaction::RoleGetRepoList) { - // The data will be loaded when Load is called - connect(m_originModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), - this, SLOT(checkChanges())); - } else { + if (!(m_roles & Transaction::RoleGetRepoList)) { // Disables the group box ui->originTV->setEnabled(false); ui->showOriginsCB->setEnabled(false); @@ -134,6 +133,11 @@ void Settings::on_editOriginsPB_clicked() #endif //EDIT_ORIGNS_DESKTOP_NAME } +void Settings::refreshRepoModel() +{ + on_showOriginsCB_stateChanged(ui->showOriginsCB->checkState()); +} + // TODO update the repo list connecting to repo changed signal void Settings::on_showOriginsCB_stateChanged(int state) { @@ -189,8 +193,6 @@ bool Settings::hasChanges() const || ui->installUpdatesMobileCB->isChecked() != checkUpdateGroup.readEntry(CFG_INSTALL_UP_MOBILE, DEFAULT_INSTALL_UP_MOBILE) || - ((m_roles & Transaction::RoleGetRepoList) ? m_originModel->changed() : false) - || ui->autoConfirmCB->isChecked() != !requirementsDialog.readEntry("autoConfirm", false) || ui->appLauncherCB->isChecked() != transaction.readEntry("ShowApplicationLauncher", true)) { @@ -264,7 +266,7 @@ void Settings::load() KConfigGroup originsDialog(&config, "originsDialog"); bool showDevel = originsDialog.readEntry("showDevel", false); ui->showOriginsCB->setChecked(showDevel); - on_showOriginsCB_stateChanged(ui->showOriginsCB->checkState()); + refreshRepoModel(); ui->originTV->setEnabled(true); } else { ui->originTV->setEnabled(false); @@ -306,15 +308,6 @@ void Settings::save() checkUpdateGroup.writeEntry("autoUpdate", ui->autoCB->itemData(ui->autoCB->currentIndex()).toUInt()); checkUpdateGroup.writeEntry("installUpdatesOnBattery", ui->installUpdatesBatteryCB->isChecked()); checkUpdateGroup.writeEntry("installUpdatesOnMobile", ui->installUpdatesMobileCB->isChecked()); - // check to see if the backend support this - if (m_roles & Transaction::RoleGetRepoList) { - on_showOriginsCB_stateChanged(ui->showOriginsCB->checkState()); - if (!m_originModel->save()) { - KMessageBox::sorry(this, - i18n("You do not have the necessary privileges to perform this action."), - i18n("Failed to set origin data")); - } - } } void Settings::defaults() @@ -324,7 +317,6 @@ void Settings::defaults() ui->distroIntervalCB->setCurrentIndex(ui->distroIntervalCB->findData(Enum::DistroUpgradeDefault)); ui->intervalCB->setCurrentIndex(ui->intervalCB->findData(Enum::TimeIntervalDefault)); ui->autoCB->setCurrentIndex(ui->autoCB->findData(Enum::AutoUpdateDefault) ); - m_originModel->clearChanges(); checkChanges(); } diff --git a/ApperKCM/Settings/Settings.h b/ApperKCM/Settings/Settings.h index 2213f6e..f73d91d 100644 --- a/ApperKCM/Settings/Settings.h +++ b/ApperKCM/Settings/Settings.h @@ -53,6 +53,7 @@ signals: void changed(bool state); private slots: + void refreshRepoModel(); void on_showOriginsCB_stateChanged(int state); void on_editOriginsPB_clicked(); void checkChanges(); -- 1.8.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor