Changeset View
Changeset View
Standalone View
Standalone View
krusader/JobMan/jobman.cpp
Show All 30 Lines | |||||
31 | #include <QWidgetAction> | 31 | #include <QWidgetAction> | ||
32 | 32 | | |||
33 | #include <KConfigCore/KSharedConfig> | 33 | #include <KConfigCore/KSharedConfig> | ||
34 | #include <KI18n/KLocalizedString> | 34 | #include <KI18n/KLocalizedString> | ||
35 | #include <KIOWidgets/KIO/FileUndoManager> | 35 | #include <KIOWidgets/KIO/FileUndoManager> | ||
36 | 36 | | |||
37 | #include "krjob.h" | 37 | #include "krjob.h" | ||
38 | #include "../krglobal.h" | 38 | #include "../krglobal.h" | ||
39 | #include "../icon.h" | ||||
39 | 40 | | |||
40 | const int MAX_OLD_MENU_ACTIONS = 10; | 41 | const int MAX_OLD_MENU_ACTIONS = 10; | ||
41 | 42 | | |||
42 | /** The menu action entry for a job in the popup menu.*/ | 43 | /** The menu action entry for a job in the popup menu.*/ | ||
43 | class JobMenuAction : public QWidgetAction | 44 | class JobMenuAction : public QWidgetAction | ||
44 | { | 45 | { | ||
45 | Q_OBJECT | 46 | Q_OBJECT | ||
46 | public: | 47 | public: | ||
Show All 9 Lines | 50 | { | |||
56 | 57 | | |||
57 | m_pauseResumeButton = new QPushButton(); | 58 | m_pauseResumeButton = new QPushButton(); | ||
58 | updatePauseResumeButton(); | 59 | updatePauseResumeButton(); | ||
59 | connect(m_pauseResumeButton, &QPushButton::clicked, this, | 60 | connect(m_pauseResumeButton, &QPushButton::clicked, this, | ||
60 | &JobMenuAction::slotPauseResumeButtonClicked); | 61 | &JobMenuAction::slotPauseResumeButtonClicked); | ||
61 | layout->addWidget(m_pauseResumeButton, 1, 1); | 62 | layout->addWidget(m_pauseResumeButton, 1, 1); | ||
62 | 63 | | |||
63 | m_cancelButton = new QPushButton(); | 64 | m_cancelButton = new QPushButton(); | ||
64 | m_cancelButton->setIcon(QIcon::fromTheme("remove")); | 65 | m_cancelButton->setIcon(Icon("remove")); | ||
65 | m_cancelButton->setToolTip(i18n("Cancel Job")); | 66 | m_cancelButton->setToolTip(i18n("Cancel Job")); | ||
66 | connect(m_cancelButton, &QPushButton::clicked, | 67 | connect(m_cancelButton, &QPushButton::clicked, | ||
67 | this, &JobMenuAction::slotCancelButtonClicked); | 68 | this, &JobMenuAction::slotCancelButtonClicked); | ||
68 | layout->addWidget(m_cancelButton, 1, 2); | 69 | layout->addWidget(m_cancelButton, 1, 2); | ||
69 | 70 | | |||
70 | setDefaultWidget(container); | 71 | setDefaultWidget(container); | ||
71 | 72 | | |||
72 | if (kJob) { | 73 | if (kJob) { | ||
Show All 24 Lines | 96 | if (!field2.first.isEmpty() && !field1.first.isEmpty()) { | |||
97 | m_progressBar->setToolTip(QString("%1: %2").arg(field1.first, field1.second)); | 98 | m_progressBar->setToolTip(QString("%1: %2").arg(field1.first, field1.second)); | ||
98 | } | 99 | } | ||
99 | } | 100 | } | ||
100 | 101 | | |||
101 | void slotPercent(KJob *, unsigned long percent) { m_progressBar->setValue(percent); } | 102 | void slotPercent(KJob *, unsigned long percent) { m_progressBar->setValue(percent); } | ||
102 | 103 | | |||
103 | void updatePauseResumeButton() | 104 | void updatePauseResumeButton() | ||
104 | { | 105 | { | ||
105 | m_pauseResumeButton->setIcon(QIcon::fromTheme( | 106 | m_pauseResumeButton->setIcon(Icon( | ||
106 | m_krJob->isRunning() ? "media-playback-pause" : | 107 | m_krJob->isRunning() ? "media-playback-pause" : | ||
107 | m_krJob->isPaused() ? "media-playback-start" : "chronometer-start")); | 108 | m_krJob->isPaused() ? "media-playback-start" : "chronometer-start")); | ||
108 | m_pauseResumeButton->setToolTip(m_krJob->isRunning() ? i18n("Pause Job") : | 109 | m_pauseResumeButton->setToolTip(m_krJob->isRunning() ? i18n("Pause Job") : | ||
109 | m_krJob->isPaused() ? i18n("Resume Job") : | 110 | m_krJob->isPaused() ? i18n("Resume Job") : | ||
110 | i18n("Start Job")); | 111 | i18n("Start Job")); | ||
111 | } | 112 | } | ||
112 | 113 | | |||
113 | void slotResult(KJob *job) | 114 | void slotResult(KJob *job) | ||
114 | { | 115 | { | ||
115 | // NOTE: m_job may already set to NULL now | 116 | // NOTE: m_job may already set to NULL now | ||
116 | if(!job->error()) { | 117 | if(!job->error()) { | ||
117 | // percent signal is not reliable, set manually | 118 | // percent signal is not reliable, set manually | ||
118 | m_progressBar->setValue(100); | 119 | m_progressBar->setValue(100); | ||
119 | } | 120 | } | ||
120 | } | 121 | } | ||
121 | 122 | | |||
122 | void slotTerminated() | 123 | void slotTerminated() | ||
123 | { | 124 | { | ||
124 | qDebug() << "job description=" << m_krJob->description(); | 125 | qDebug() << "job description=" << m_krJob->description(); | ||
125 | m_pauseResumeButton->setEnabled(false); | 126 | m_pauseResumeButton->setEnabled(false); | ||
126 | m_cancelButton->setIcon(QIcon::fromTheme("edit-clear")); | 127 | m_cancelButton->setIcon(Icon("edit-clear")); | ||
127 | m_cancelButton->setToolTip(i18n("Clear")); | 128 | m_cancelButton->setToolTip(i18n("Clear")); | ||
128 | 129 | | |||
129 | m_krJob = nullptr; | 130 | m_krJob = nullptr; | ||
130 | } | 131 | } | ||
131 | 132 | | |||
132 | void slotPauseResumeButtonClicked() | 133 | void slotPauseResumeButtonClicked() | ||
133 | { | 134 | { | ||
134 | if (!m_krJob) | 135 | if (!m_krJob) | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
176 | #include "jobman.moc" // required for class definitions with Q_OBJECT macro in implementation files | 177 | #include "jobman.moc" // required for class definitions with Q_OBJECT macro in implementation files | ||
177 | 178 | | |||
178 | 179 | | |||
179 | const QString JobMan::sDefaultToolTip = i18n("No jobs"); | 180 | const QString JobMan::sDefaultToolTip = i18n("No jobs"); | ||
180 | 181 | | |||
181 | JobMan::JobMan(QObject *parent) : QObject(parent), m_messageBox(0) | 182 | JobMan::JobMan(QObject *parent) : QObject(parent), m_messageBox(0) | ||
182 | { | 183 | { | ||
183 | // job control action | 184 | // job control action | ||
184 | m_controlAction = new KToolBarPopupAction(QIcon::fromTheme("media-playback-pause"), | 185 | m_controlAction = new KToolBarPopupAction(Icon("media-playback-pause"), | ||
185 | i18n("Play/Pause &Job"), this); | 186 | i18n("Play/Pause &Job"), this); | ||
186 | m_controlAction->setEnabled(false); | 187 | m_controlAction->setEnabled(false); | ||
187 | connect(m_controlAction, &QAction::triggered, this, &JobMan::slotControlActionTriggered); | 188 | connect(m_controlAction, &QAction::triggered, this, &JobMan::slotControlActionTriggered); | ||
188 | 189 | | |||
189 | QMenu *menu = new QMenu(krMainWindow); | 190 | QMenu *menu = new QMenu(krMainWindow); | ||
190 | menu->setMinimumWidth(300); | 191 | menu->setMinimumWidth(300); | ||
191 | // make scrollable if menu is too long | 192 | // make scrollable if menu is too long | ||
192 | menu->setStyleSheet("QMenu { menu-scrollable: 1; }"); | 193 | menu->setStyleSheet("QMenu { menu-scrollable: 1; }"); | ||
Show All 9 Lines | |||||
202 | QWidgetAction *progressAction = new QWidgetAction(krMainWindow); | 203 | QWidgetAction *progressAction = new QWidgetAction(krMainWindow); | ||
203 | progressAction->setText(i18n("Job Progress Bar")); | 204 | progressAction->setText(i18n("Job Progress Bar")); | ||
204 | progressAction->setDefaultWidget(m_progressBar); | 205 | progressAction->setDefaultWidget(m_progressBar); | ||
205 | m_progressAction = progressAction; | 206 | m_progressAction = progressAction; | ||
206 | 207 | | |||
207 | // job queue mode action | 208 | // job queue mode action | ||
208 | KConfigGroup cfg(krConfig, "JobManager"); | 209 | KConfigGroup cfg(krConfig, "JobManager"); | ||
209 | m_queueMode = cfg.readEntry("Queue Mode", false); | 210 | m_queueMode = cfg.readEntry("Queue Mode", false); | ||
210 | m_modeAction = new QAction(QIcon::fromTheme("media-playlist-repeat"), i18n("Job Queue Mode"), | 211 | m_modeAction = new QAction(Icon("media-playlist-repeat"), i18n("Job Queue Mode"), | ||
211 | krMainWindow); | 212 | krMainWindow); | ||
212 | m_modeAction->setToolTip(i18n("Run only one job in parallel")); | 213 | m_modeAction->setToolTip(i18n("Run only one job in parallel")); | ||
213 | m_modeAction->setCheckable(true); | 214 | m_modeAction->setCheckable(true); | ||
214 | m_modeAction->setChecked(m_queueMode); | 215 | m_modeAction->setChecked(m_queueMode); | ||
215 | connect(m_modeAction, &QAction::toggled, this, [=](bool checked) mutable { | 216 | connect(m_modeAction, &QAction::toggled, this, [=](bool checked) mutable { | ||
216 | m_queueMode = checked; | 217 | m_queueMode = checked; | ||
217 | cfg.writeEntry("Queue Mode", m_queueMode); | 218 | cfg.writeEntry("Queue Mode", m_queueMode); | ||
218 | }); | 219 | }); | ||
219 | 220 | | |||
220 | // undo action | 221 | // undo action | ||
221 | KIO::FileUndoManager *undoManager = KIO::FileUndoManager::self(); | 222 | KIO::FileUndoManager *undoManager = KIO::FileUndoManager::self(); | ||
222 | undoManager->uiInterface()->setParentWidget(krMainWindow); | 223 | undoManager->uiInterface()->setParentWidget(krMainWindow); | ||
223 | 224 | | |||
224 | m_undoAction = new QAction(QIcon::fromTheme("edit-undo"), i18n("Undo Last Job"), krMainWindow); | 225 | m_undoAction = new QAction(Icon("edit-undo"), i18n("Undo Last Job"), krMainWindow); | ||
225 | m_undoAction->setEnabled(false); | 226 | m_undoAction->setEnabled(false); | ||
226 | connect(m_undoAction, &QAction::triggered, undoManager, &KIO::FileUndoManager::undo); | 227 | connect(m_undoAction, &QAction::triggered, undoManager, &KIO::FileUndoManager::undo); | ||
227 | connect(undoManager, static_cast<void(KIO::FileUndoManager::*)(bool)>(&KIO::FileUndoManager::undoAvailable), | 228 | connect(undoManager, static_cast<void(KIO::FileUndoManager::*)(bool)>(&KIO::FileUndoManager::undoAvailable), | ||
228 | m_undoAction, &QAction::setEnabled); | 229 | m_undoAction, &QAction::setEnabled); | ||
229 | connect(undoManager, &KIO::FileUndoManager::undoTextChanged, this, &JobMan::slotUndoTextChange); | 230 | connect(undoManager, &KIO::FileUndoManager::undoTextChanged, this, &JobMan::slotUndoTextChange); | ||
230 | } | 231 | } | ||
231 | 232 | | |||
232 | bool JobMan::waitForJobs(bool waitForUserInput) | 233 | bool JobMan::waitForJobs(bool waitForUserInput) | ||
233 | { | 234 | { | ||
234 | if (m_jobs.isEmpty() && !waitForUserInput) | 235 | if (m_jobs.isEmpty() && !waitForUserInput) | ||
235 | return true; | 236 | return true; | ||
236 | 237 | | |||
237 | // attempt to get all job threads does not work | 238 | // attempt to get all job threads does not work | ||
238 | //QList<QThread *> threads = krMainWindow->findChildren<QThread *>(); | 239 | //QList<QThread *> threads = krMainWindow->findChildren<QThread *>(); | ||
239 | 240 | | |||
240 | m_autoCloseMessageBox = !waitForUserInput; | 241 | m_autoCloseMessageBox = !waitForUserInput; | ||
241 | 242 | | |||
242 | m_messageBox = new QMessageBox(krMainWindow); | 243 | m_messageBox = new QMessageBox(krMainWindow); | ||
243 | m_messageBox->setWindowTitle(i18n("Warning")); | 244 | m_messageBox->setWindowTitle(i18n("Warning")); | ||
244 | m_messageBox->setIconPixmap(QIcon::fromTheme("dialog-warning") | 245 | m_messageBox->setIconPixmap(Icon("dialog-warning") | ||
245 | .pixmap(QMessageBox::standardIcon(QMessageBox::Information).size())); | 246 | .pixmap(QMessageBox::standardIcon(QMessageBox::Information).size())); | ||
246 | m_messageBox->setText(i18n("Are you sure you want to quit?")); | 247 | m_messageBox->setText(i18n("Are you sure you want to quit?")); | ||
247 | m_messageBox->addButton(QMessageBox::Abort); | 248 | m_messageBox->addButton(QMessageBox::Abort); | ||
248 | m_messageBox->addButton(QMessageBox::Cancel); | 249 | m_messageBox->addButton(QMessageBox::Cancel); | ||
249 | m_messageBox->setDefaultButton(QMessageBox::Cancel); | 250 | m_messageBox->setDefaultButton(QMessageBox::Cancel); | ||
250 | for (KrJob *job: m_jobs) | 251 | for (KrJob *job: m_jobs) | ||
251 | connect(job, &KrJob::terminated, this, &JobMan::slotUpdateMessageBox); | 252 | connect(job, &KrJob::terminated, this, &JobMan::slotUpdateMessageBox); | ||
252 | slotUpdateMessageBox(); | 253 | slotUpdateMessageBox(); | ||
▲ Show 20 Lines • Show All 183 Lines • ▼ Show 20 Line(s) | 436 | } else { | |||
436 | m_progressBar->reset(); | 437 | m_progressBar->reset(); | ||
437 | } | 438 | } | ||
438 | if (!hasJobs) | 439 | if (!hasJobs) | ||
439 | m_progressBar->setToolTip(i18n("No Jobs")); | 440 | m_progressBar->setToolTip(i18n("No Jobs")); | ||
440 | if (m_jobs.length() > 1) | 441 | if (m_jobs.length() > 1) | ||
441 | m_progressBar->setToolTip(i18np("%1 Job", "%1 Jobs", m_jobs.length())); | 442 | m_progressBar->setToolTip(i18np("%1 Job", "%1 Jobs", m_jobs.length())); | ||
442 | 443 | | |||
443 | const bool running = jobsAreRunning(); | 444 | const bool running = jobsAreRunning(); | ||
444 | m_controlAction->setIcon(QIcon::fromTheme( | 445 | m_controlAction->setIcon(Icon( | ||
445 | !hasJobs ? "edit-clear" : running ? "media-playback-pause" : "media-playback-start")); | 446 | !hasJobs ? "edit-clear" : running ? "media-playback-pause" : "media-playback-start")); | ||
446 | m_controlAction->setToolTip(!hasJobs ? i18n("Clear Job List") : running ? | 447 | m_controlAction->setToolTip(!hasJobs ? i18n("Clear Job List") : running ? | ||
447 | i18n("Pause All Jobs") : | 448 | i18n("Pause All Jobs") : | ||
448 | i18n("Resume Job List")); | 449 | i18n("Resume Job List")); | ||
449 | } | 450 | } | ||
450 | 451 | | |||
451 | bool JobMan::jobsAreRunning() | 452 | bool JobMan::jobsAreRunning() | ||
452 | { | 453 | { | ||
453 | for (KrJob *job: m_jobs) | 454 | for (KrJob *job: m_jobs) | ||
454 | if (job->isRunning()) | 455 | if (job->isRunning()) | ||
455 | return true; | 456 | return true; | ||
456 | 457 | | |||
457 | return false; | 458 | return false; | ||
458 | } | 459 | } |