KDELIBS/KDECORE Index: jobs/kjob.cpp =================================================================== --- jobs/kjob.cpp (revisión: 644360) +++ jobs/kjob.cpp (copia de trabajo) @@ -24,6 +24,7 @@ #include "kjobuidelegate.h" #include +#include #include #include #include @@ -31,10 +32,10 @@ class KJob::Private { public: - Private(KJob *job) : q(job), uiDelegate(0), error(KJob::NoError), - progressUnit(KJob::Bytes), percentage(0), - suspended(false), capabilities(KJob::NoCapabilities), - speedTimer(0) {} + Private() : uiDelegate( 0 ), progressId( 0 ), error( KJob::NoError ), + progressUnit(KJob::Bytes), percentage( 0 ), + capabilities( KJob::NoCapabilities ), state( KJob::Regular ), + speedTimer(0) {} KJob *const q; @@ -45,10 +46,9 @@ QMap processedAmount; QMap totalAmount; unsigned long percentage; - bool suspended; KJob::Capabilities capabilities; + KJob::State state; QTimer *speedTimer; - void _k_speedTimeout(); }; @@ -92,9 +92,9 @@ return d->capabilities; } -bool KJob::isSuspended() const +KJob::State KJob::jobState() const { - return d->suspended; + return d->state; } bool KJob::kill( KillVerbosity verbosity ) @@ -125,12 +125,17 @@ bool KJob::suspend() { - if ( !d->suspended ) + kDebug() << "KJob:: suspend()" << endl; + + if ( (d->state != Suspended) && doSuspend() ) { - d->suspended = true; - doSuspend(); + kDebug() << "KJob:: suspend() entered" << endl; + KJob::State previousState = d->state; + d->state = Suspended; + emit suspended(this); + emit stateChanged( previousState, Suspended, d->progressId ); return true; } @@ -140,12 +145,16 @@ bool KJob::resume() { - if ( d->suspended ) + kDebug() << "KJob:: resume()" << endl; + + if ( (d->state == Suspended) && doResume() ) { - d->suspended = false; - doResume(); + kDebug() << "KJob:: resume() entered" << endl; + d->state = Regular; + emit resumed(this); + emit stateChanged( Suspended, Regular, d->progressId ); return true; } Index: jobs/kjob.h =================================================================== --- jobs/kjob.h (revisión: 644360) +++ jobs/kjob.h (copia de trabajo) @@ -75,6 +75,10 @@ Killable = 0x0001, Suspendable = 0x0002 }; + enum State { Killed, + Regular, + Suspended }; + Q_DECLARE_FLAGS( Capabilities, Capability ) /** @@ -116,14 +120,6 @@ Capabilities capabilities() const; /** - * Returns if the job was suspended with the suspend() call. - * - * @return if the job was suspended - * @see suspend() resume() - */ - bool isSuspended() const; - - /** * Starts the job asynchronously. When the job is finished, * result() is emitted. */ @@ -131,6 +127,8 @@ enum KillVerbosity { Quietly, EmitResult }; + State jobState() const; + public Q_SLOTS: /** * Aborts this job. @@ -166,6 +164,8 @@ * This simply kills the job, no error reporting or job deletion should be involved. * * @return true if the operation is supported and succeeded, false otherwise + * + * @warning if you reimplement this method do not forget to emit the signal stateChanged */ virtual bool doKill() { return false; } @@ -173,6 +173,8 @@ * Suspends this job. * * @return true if the operation is supported and succeeded, false otherwise + * + * @warning if you reimplement this method do not forget to emit the signal stateChanged */ virtual bool doSuspend() { return false; } @@ -180,6 +182,8 @@ * Resumes this job. * * @return true if the operation is supported and succeeded, false otherwise + * + * @warning if you reimplement this method do not forget to emit the signal stateChanged */ virtual bool doResume() { return false; } @@ -268,9 +272,6 @@ unsigned long percent() const; Q_SIGNALS: -#ifndef Q_MOC_RUN -private: // don't tell moc, but those signals are in fact private -#endif /** * Emitted when the job is finished, in any case. It is used to notify * observers that the job is terminated and that progress can be hidden. @@ -305,6 +306,8 @@ */ void result(KJob *job); + void stateChanged(int oldState, int newState, int jobId); + Q_SIGNALS: /** * Emitted to display general description of this job. A description has KDEBASE Index: progresslistdelegate.h =================================================================== --- progresslistdelegate.h (revisión: 644362) +++ progresslistdelegate.h (copia de trabajo) @@ -22,6 +22,7 @@ #include #include +#include class QListView; @@ -89,7 +90,7 @@ }; Q_SIGNALS: - void actionPerformed(int actionId, int jobId); + void actionPerformed(int newState, int jobId); private: class Private; Index: uiserver.cpp =================================================================== --- uiserver.cpp (revisión: 644362) +++ uiserver.cpp (copia de trabajo) @@ -123,30 +123,6 @@ progressListDelegateFinished->setEditorHeight(20); listFinished->setItemDelegate(progressListDelegateFinished); - connect(progressListModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), - listProgress, SLOT(rowsInserted(const QModelIndex&,int,int))); - - connect(progressListModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), - listProgress, SLOT(rowsAboutToBeRemoved(const QModelIndex&,int,int))); - - connect(progressListModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), - this, SLOT(slotRowsRemoved(const QModelIndex&,int,int))); - - connect(progressListModel, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), - listProgress, SLOT(dataChanged(const QModelIndex&,const QModelIndex&))); - - connect(progressListFinishedModel, SIGNAL(rowsInserted(const QModelIndex&,int,int)), - listFinished, SLOT(rowsInserted(const QModelIndex&,int,int))); - - connect(progressListFinishedModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), - listFinished, SLOT(rowsAboutToBeRemoved(const QModelIndex&,int,int))); - - connect(progressListFinishedModel, SIGNAL(rowsRemoved(const QModelIndex&,int,int)), - this, SLOT(slotRowsRemoved(const QModelIndex&,int,int))); - - connect(progressListFinishedModel, SIGNAL(dataChanged(const QModelIndex&,const QModelIndex&)), - listFinished, SLOT(dataChanged(const QModelIndex&,const QModelIndex&))); - applySettings(); hide(); @@ -164,7 +140,7 @@ int UIServer::newJob(const QString &appServiceName, int capabilities, bool showProgress, const QString &internalAppName, const QString &jobIcon, const QString &appName) { // Uncomment if you want to see kuiserver in action (ereslibre) - // if (isHidden()) show(); + if (isHidden()) show(); s_jobId++; @@ -172,6 +148,9 @@ m_hashObserverInterfaces.insert(s_jobId, observer); + connect(observer, SIGNAL(stateChanged(int,int,int)), this, + SLOT(slotStateChanged(int,int,int))); + connect(progressListDelegate, SIGNAL(actionPerformed(int,int)), observer, SLOT(slotActionPerformed(int,int))); @@ -186,10 +165,10 @@ return s_jobId; if (capabilities & KJob::Suspendable) - newAction(s_jobId, KJob::Suspendable, i18n("Pause")); + newAction(s_jobId, KJob::Suspended, i18n("Pause")); if (capabilities & KJob::Killable) - newAction(s_jobId, KJob::Killable, i18n("Cancel")); + newAction(s_jobId, KJob::Killed, i18n("Cancel")); return s_jobId; } @@ -217,11 +196,11 @@ /// =========================================================== -void UIServer::newAction(int jobId, int actionId, const QString &actionText) +void UIServer::newAction(int jobId, KJob::State state, const QString &actionText) { - m_hashActions.insert(actionId, jobId); + m_hashActions.insert(state, jobId); - progressListModel->newAction(jobId, actionId, actionText); + progressListModel->newAction(jobId, state, actionText); } /// =========================================================== @@ -392,7 +371,12 @@ // TODO: unify all width's of progress bars } +void UIServer::slotStateChanged(int nextState, int newState, int jobId) +{ + progressListModel->editAction(jobId, (KJob::State) nextState, (KJob::State) newState); +} + /// =========================================================== Index: uiserver.h =================================================================== --- uiserver.h (revisión: 644362) +++ uiserver.h (copia de trabajo) @@ -90,7 +90,7 @@ * @param actionText the button text * @return the identification number of the action (actionId) */ - void newAction(int jobId, int actionId, const QString &actionText); + void newAction(int jobId, KJob::State state, const QString &actionText); /** * Sets the total size of a job @@ -214,6 +214,7 @@ private Q_SLOTS: void showConfigurationDialog(); void slotRowsRemoved(const QModelIndex &parent, int start, int end); + void slotStateChanged(int nextState, int newState, int jobId); private: ProgressListModel *progressListModel; Index: progresslistdelegate_p.h =================================================================== --- progresslistdelegate_p.h (revisión: 644362) +++ progresslistdelegate_p.h (copia de trabajo) @@ -97,16 +97,16 @@ Q_OBJECT public: - QActionPushButton(int actionId, int jobId, const QString &actionText, QWidget *parent = 0); + QActionPushButton(int state, int jobId, const QString &actionText, QWidget *parent = 0); public Q_SLOTS: void buttonPressed(); Q_SIGNALS: - void actionButtonPressed(int actionId, int jobId); + void actionButtonPressed(int newState, int jobId); private: - int actionId; + int state; int jobId; }; Index: tests/kuiservertest.cpp =================================================================== --- tests/kuiservertest.cpp (revisión: 644362) +++ tests/kuiservertest.cpp (copia de trabajo) @@ -29,7 +29,7 @@ : KIO::Job(true), timer(new QTimer(this)), clockTimer(new QTimer(this)), seconds(numberOfSeconds), total(numberOfSeconds) { - setCapabilities(KJob::NoCapabilities); + setCapabilities(KJob::Killable | KJob::Suspendable); } KJobTest::~KJobTest() @@ -71,6 +71,7 @@ bool KJobTest::doSuspend() { + timer->stop(); clockTimer->stop(); Job::doSuspend(); @@ -78,11 +79,21 @@ return true; } +bool KJobTest::doResume() +{ + timer->start(seconds * 1000); + clockTimer->start(); + + Job::doResume(); + + return true; +} + #include "kuiservertest.moc" int main(int argc, char **argv) { - KCmdLineArgs::init(argc, argv, "kjobtest", "KJobTest", "A KJob tester", "0.01"); + KCmdLineArgs::init(argc, argv, "konqueror", "KJobTest", "A KJob tester", "0.01"); KApplication app; Index: tests/kuiservertest.h =================================================================== --- tests/kuiservertest.h (revisión: 644362) +++ tests/kuiservertest.h (copia de trabajo) @@ -43,6 +43,7 @@ protected: bool doSuspend(); + bool doResume(); private: QTimer *timer, *clockTimer; Index: progresslistmodel.cpp =================================================================== --- progresslistmodel.cpp (revisión: 644362) +++ progresslistmodel.cpp (copia de trabajo) @@ -24,6 +24,7 @@ #include #include +#include ProgressListModel::ProgressListModel(QObject *parent) : QAbstractItemModel(parent) @@ -302,7 +303,7 @@ removeRow(indexToRemove.row()); } -void ProgressListModel::newAction(uint jobId, uint actionId, const QString &actionText) +void ProgressListModel::newAction(uint jobId, KJob::State state, const QString &actionText) { QModelIndex index = indexForJob(jobId); @@ -310,7 +311,7 @@ ActionInfo newActionInfo; newActionInfo.enabled = true; - newActionInfo.actionId = actionId; + newActionInfo.state = state; newActionInfo.actionText = actionText; jobInfoList[row].actionInfoList.append(newActionInfo); @@ -319,7 +320,7 @@ emit dataChanged(index, index); } -void ProgressListModel::editAction(int jobId, int actionId, const QString &actionText) +void ProgressListModel::editAction(int jobId, KJob::State nextState, KJob::State newState) { QModelIndex index = indexForJob(jobId); @@ -331,10 +332,20 @@ { actionIt = jobInfoList[index.row()].actionInfoList[i]; - if (actionId == actionIt.actionId) + if (newState == actionIt.state) { + switch (newState) + { + case KJob::Regular: + jobInfoList[index.row()].actionInfoList[i].actionText = i18n("Pause"); + break; + case KJob::Suspended: + jobInfoList[index.row()].actionInfoList[i].actionText = i18n("Resume"); + break; + } + jobInfoList[index.row()].actionInfoList[i].enabled = true; - jobInfoList[index.row()].actionInfoList[i].actionText = actionText; + jobInfoList[index.row()].actionInfoList[i].state = nextState; keepSearching = false; } @@ -348,7 +359,7 @@ void ProgressListModel::enableAction(int jobId, int actionId) { - QModelIndex index = indexForJob(jobId); + /*QModelIndex index = indexForJob(jobId); int i = 0; bool keepSearching = true; @@ -369,12 +380,12 @@ } emit actionEdited(index); - emit dataChanged(index, index); + emit dataChanged(index, index);*/ } void ProgressListModel::disableAction(int jobId, int actionId) { - QModelIndex index = indexForJob(jobId); + /*QModelIndex index = indexForJob(jobId); int i = 0; bool keepSearching = true; @@ -395,12 +406,12 @@ } emit actionEdited(index); - emit dataChanged(index, index); + emit dataChanged(index, index);*/ } void ProgressListModel::removeAction(int jobId, int actionId) { - QModelIndex index = indexForJob(jobId); + /*QModelIndex index = indexForJob(jobId); int i = 0; bool keepSearching = true; @@ -421,7 +432,7 @@ } emit actionRemoved(index); - emit dataChanged(index, index); + emit dataChanged(index, index);*/ } const QList &ProgressListModel::actions(uint jobId) const Index: progresslistmodel.h =================================================================== --- progresslistmodel.h (revisión: 644362) +++ progresslistmodel.h (copia de trabajo) @@ -37,7 +37,7 @@ struct ActionInfo { bool enabled; ///< Button enabled or not - int actionId; ///< The number that identificates the action + KJob::State state; ///< The state of the job QString actionText; ///< The text that is shown on the button on the editor }; @@ -187,16 +187,16 @@ * @param actionId the identification number of the new action * @param actionText the text that will be shown for this action */ - void newAction(uint jobId, uint actionId, const QString &actionText); + void newAction(uint jobId, KJob::State state, const QString &actionText); /** * Edits an existing action * * @param jobId the identification number of the job that contains the action to be modified - * @param actionId the identification number of the action to be modified - * @param actionText the new text to be shown related to this action + * @param nextState the next new state for the job + * @param newState the new state of the job */ - void editAction(int jobId, int actionId, const QString &actionText); + void editAction(int jobId, KJob::State nextState, KJob::State newState); /** * Enables an existing action (the press button) Index: progresslistdelegate.cpp =================================================================== --- progresslistdelegate.cpp (revisión: 644362) +++ progresslistdelegate.cpp (copia de trabajo) @@ -173,10 +173,10 @@ listView->closePersistentEditor(index); } -ProgressListDelegate::Private::QActionPushButton::QActionPushButton(int actionId, int jobId, const QString &actionText, QWidget *parent) +ProgressListDelegate::Private::QActionPushButton::QActionPushButton(int state, int jobId, const QString &actionText, QWidget *parent) : QPushButton(actionText, parent) { - this->actionId = actionId; + this->state = state; this->jobId = jobId; connect(this, SIGNAL(clicked(bool)), this, @@ -185,7 +185,7 @@ void ProgressListDelegate::Private::QActionPushButton::buttonPressed() { - emit actionButtonPressed(actionId, jobId); + emit actionButtonPressed(state, jobId); } ProgressListDelegate::ProgressListDelegate(QObject *parent, QListView *listView) @@ -221,7 +221,7 @@ int i = 0; foreach (const ActionInfo &actionIt, actionsModel) { - newButton = new Private::QActionPushButton(actionIt.actionId, jobIdModel, actionIt.actionText); + newButton = new Private::QActionPushButton(actionIt.state, jobIdModel, actionIt.actionText); newButton->setEnabled(actionIt.enabled); connect(newButton, SIGNAL(actionButtonPressed(int,int)), this,