diff --git a/krusader/Queue/queue.cpp b/krusader/Queue/queue.cpp index 1799c656..82d5f4f4 100644 --- a/krusader/Queue/queue.cpp +++ b/krusader/Queue/queue.cpp @@ -1,215 +1,216 @@ /***************************************************************************** * Copyright (C) 2008-2009 Csaba Karai * * * * 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 package 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 package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #include "queue.h" #include "../krglobal.h" -#include +// QtCore +#include #include #include Queue::Queue(const QString& name): _name(name), _suspended(false), _percent(PERCENT_UNUSED) { connect(&_scheduleTimer, SIGNAL(timeout()), this, SLOT(resume())); } Queue::~Queue() { foreach(KIOJobWrapper * job, _jobs) { job->abort(); delete job; } _jobs.clear(); // TODO: save queue on delete? or just delete jobs } void Queue::enqueue(KIOJobWrapper *job) { bool isRunning = _jobs.count(); _jobs.append(job); connect(job, SIGNAL(destroyed(QObject *)), this, SLOT(slotJobDestroyed(QObject *))); job->connectTo(SIGNAL(result(KJob*)), this, SLOT(slotResult(KJob*))); job->connectTo(SIGNAL(percent(KJob*, unsigned long)), this, SLOT(slotPercent(KJob*, unsigned long))); if (!_suspended && !isRunning) { job->start(); slotPercent(0, PERCENT_UNKNOWN); } emit changed(); emit showQueueDialog(); } void Queue::slotJobDestroyed(QObject * obj) { KIOJobWrapper * jw = (KIOJobWrapper*) obj; bool current = false; if (_jobs.count() > 0 && _jobs[ 0 ] == jw) current = true; _jobs.removeAll(jw); if (current) slotPercent(0, PERCENT_UNUSED); if (!_suspended && current && _jobs.count() > 0) { _jobs[ 0 ]->start(); slotPercent(0, PERCENT_UNKNOWN); } emit changed(); } void Queue::slotResult(KJob * job) { if (_jobs.count() > 0) { KIOJobWrapper * jw = _jobs[ 0 ]; KIO::Job * kjob = jw->job(); if (kjob && kjob == job) { slotPercent(0, PERCENT_UNUSED); _jobs.removeAll(jw); if (job->error() && _jobs.count() > 0) { // what to do with the other elements in the queue QString message = i18n("An error occurred during processing the queue.\n"); if (job->error() == KIO::ERR_USER_CANCELED) message = i18n("The last processed element in the queue was aborted.\n"); message += i18n("Do you wish to continue with the next element, delete the queue or suspend the queue?"); int res = KMessageBox::questionYesNoCancel(krMainWindow, message, i18n("Krusader::Queue"), KStandardGuiItem::cont(), KStandardGuiItem::del(), KGuiItem(i18n("Suspend"))); switch (res) { case KMessageBox::Yes: // continue break; case KMessageBox::No: // delete the queue foreach(KIOJobWrapper * job, _jobs) { job->abort(); delete job; } _jobs.clear(); emit changed(); emit emptied(); return; default: // suspend emit changed(); suspend(); return; } } emit changed(); if (!_suspended) { if (_jobs.count() > 0) { _jobs[ 0 ]->start(); slotPercent(0, PERCENT_UNKNOWN); } else emit emptied(); } } } } QList Queue::items() { return _jobs; } QList Queue::itemDescriptions() { QList ret; foreach(KIOJobWrapper *job, _jobs) { ret.append(job->typeStr() + " : " + job->url().toDisplayString()); } return ret; } void Queue::suspend() { _suspended = true; if ((_jobs.count() > 0) && _jobs[ 0 ]->isStarted()) _jobs[ 0 ]->suspend(); emit stateChanged(); } void Queue::resume() { _suspended = false; _scheduleTimer.stop(); if (_jobs.count() > 0) { if (_jobs[ 0 ]->isSuspended()) _jobs[ 0 ]->resume(); else if (!_jobs[ 0 ]->isStarted()) { _jobs[ 0 ]->start(); slotPercent(0, PERCENT_UNKNOWN); } } emit stateChanged(); } void Queue::schedule(const QTime &time) { QTime nowTime = QTime::currentTime(); _suspended = true; if ((_jobs.count() > 0) && _jobs[ 0 ]->isStarted()) _jobs[ 0 ]->suspend(); int now = ((nowTime.hour() * 60) + nowTime.minute()) * 60 + nowTime.second(); int schedule = ((time.hour() * 60) + time.minute()) * 60 + time.second(); int diff = schedule - now; if (diff < 0) diff += 24 * 60 * 60; // 1 day plus diff *= 1000; // milliseconds _scheduleTime = time; _scheduleTimer.stop(); _scheduleTimer.setSingleShot(true); _scheduleTimer.start(diff); emit stateChanged(); } QTime Queue::scheduleTime() { if (_suspended && _scheduleTimer.isActive()) return _scheduleTime; else return QTime(); } void Queue::slotPercent(KJob *, unsigned long percent_) { _percent = percent_; emit percent(this, percent_); } void Queue::remove(KIOJobWrapper * jw) { bool current = false; if (_jobs.count() > 0 && _jobs[ 0 ] == jw) current = true; _jobs.removeAll(jw); jw->abort(); delete jw; if (current) slotPercent(0, PERCENT_UNUSED); if (!_suspended && current && _jobs.count() > 0) { _jobs[ 0 ]->start(); slotPercent(0, PERCENT_UNKNOWN); } emit changed(); } diff --git a/krusader/Queue/queue.h b/krusader/Queue/queue.h index 350e26c6..0f5767eb 100644 --- a/krusader/Queue/queue.h +++ b/krusader/Queue/queue.h @@ -1,93 +1,94 @@ /***************************************************************************** * Copyright (C) 2008-2009 Csaba Karai * * * * 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 package 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 package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #ifndef QUEUE_H #define QUEUE_H #include "../VFS/kiojobwrapper.h" -#include -#include -#include -#include +// QtCore +#include +#include +#include +#include class KJob; #define PERCENT_UNUSED -2 #define PERCENT_UNKNOWN -1 /** * Queue can hold anything which inherits KIO::Job, and schedule it, start it, stop etc... * the main reason to hold the Job itself (at least for phase 1) is to keep the code * in krusader relatively unchaged, and allow to create the job as usual and choose if * to start it, or queue it. * */ class Queue: public QObject { Q_OBJECT public: Queue(const QString& name); virtual ~Queue(); inline const QString& name() const { return _name; } void enqueue(KIOJobWrapper *job); int count() { return _jobs.size(); } bool isSuspended() { return _suspended; } QTime scheduleTime(); int getPercent() { return _percent; } void remove(KIOJobWrapper *); QList itemDescriptions(); QList items(); public slots: void suspend(); void resume(); void schedule(const QTime &); protected slots: void slotJobDestroyed(QObject *); void slotResult(KJob *); void slotPercent(KJob *, unsigned long percent); protected: QString _name; QList _jobs; bool _suspended; QTimer _scheduleTimer; QTime _scheduleTime; int _percent; signals: void showQueueDialog(); void changed(); void emptied(); void stateChanged(); void percent(Queue *, int value); }; #endif // QUEUE_H diff --git a/krusader/Queue/queue_mgr.cpp b/krusader/Queue/queue_mgr.cpp index edbdebc6..7c3ff897 100644 --- a/krusader/Queue/queue_mgr.cpp +++ b/krusader/Queue/queue_mgr.cpp @@ -1,179 +1,180 @@ /***************************************************************************** * Copyright (C) 2008-2009 Csaba Karai * * * * 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 package 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 package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #include "queue_mgr.h" #include "queuedialog.h" #include "queue.h" -#include -#include -#include +// QtCore +#include +#include +#include #include #include #include "../krglobal.h" QMap QueueManager::_queues; Queue * QueueManager::_current = 0; QueueManager * QueueManager::_self = 0; int QueueManager::_nextId = 1; QueueManager::QueueManager(QObject *parent): QObject(parent) { _self = this; QStringList queues; queues << defaultName(); int current = 0; KConfigGroup group(krConfig, "QueueManager"); queues = group.readEntry("Queues", queues); current = group.readEntry("Active", current); const int queuesSize = queues.size(); if (queuesSize == 0) queues << defaultName(); QVector queueArray; foreach(const QString &queueName, queues) queueArray.append(createQueue(queueName)); if (current < queuesSize) setCurrentQueue(queueArray[ current ]); else setCurrentQueue(queueArray[ 0 ]); } QueueManager::~QueueManager() { QList idList; QStringList nameList; int currentId = 0; QMap::iterator it; for (it = _queues.begin(); it != _queues.end(); ++it) { QString name = it.key(); int id = (*it)->property("QueueID").toInt(); if ((*it) == currentQueue()) currentId = id; int pos = 0; while (pos < idList.count() && idList[ pos ] < id) pos++; idList.insert(pos, id); nameList.insert(pos, name); delete it.value(); } _queues.clear(); QueueDialog::deleteDialog(); KConfigGroup group(krConfig, "QueueManager"); group.writeEntry("Queues", nameList); int active = 0; for (int p = 0; p < idList.count(); p++) if (idList[ p ] == currentId) { active = p; break; } group.writeEntry("Active", active); } QString QueueManager::defaultName() { return QString(i18n("default")); } Queue* QueueManager::queue(const QString& queueName) { if (!_queues.contains(queueName)) return 0; return _queues[queueName]; } QList QueueManager::queues() { return _queues.keys(); } Queue* QueueManager::currentQueue() { return _current; } void QueueManager::setCurrentQueue(Queue * queue) { if (queue == 0) return; if (_queues.contains(queue->name())) { _current = queue; _self->emit currentChanged(queue); } } void QueueManager::slotShowQueueDialog() { QueueDialog::showDialog(); } void QueueManager::slotQueueEmptied() { bool empty = true; QList queues = _queues.values(); foreach(Queue * queue, queues) { if (queue->count() != 0) { empty = false; break; } } if (empty) QueueDialog::everyQueueIsEmpty(); } Queue * QueueManager::createQueue(const QString& queueName) { if (_queues.contains(queueName)) return 0; Queue *queue = new Queue(queueName); int id = _nextId++; queue->setProperty("QueueID", QVariant(id)); connect(queue, SIGNAL(showQueueDialog()), _self, SLOT(slotShowQueueDialog())); connect(queue, SIGNAL(emptied()), _self, SLOT(slotQueueEmptied())); connect(queue, SIGNAL(percent(Queue *, int)), _self, SIGNAL(percent(Queue *, int))); _queues.insert(queue->name(), queue); _current = queue; _self->emit queueInserted(queue); _self->emit currentChanged(queue); return queue; } void QueueManager::removeQueue(Queue * queue) { if (_queues.count() < 2 && _queues.contains(queue->name())) return; _self->emit queueDeleted(queue); _queues.remove(queue->name()); QMap::iterator it; _current = _queues.begin().value(); _self->emit currentChanged(queue); delete queue; } diff --git a/krusader/Queue/queue_mgr.h b/krusader/Queue/queue_mgr.h index fa311434..f66a5887 100644 --- a/krusader/Queue/queue_mgr.h +++ b/krusader/Queue/queue_mgr.h @@ -1,70 +1,71 @@ /***************************************************************************** * Copyright (C) 2008-2009 Csaba Karai * * * * 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 package 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 package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #ifndef QUEUE_MGR_H #define QUEUE_MGR_H #include "queue.h" -#include -#include +// QtCore +#include +#include /** * QueueManager holds multiple queues and has a static * method that fetches a queue by name. calling it with * no arguments will fetch the default queue */ class QueueManager : public QObject { Q_OBJECT static QString defaultName(); public: QueueManager(QObject *parent = 0); ~QueueManager(); static Queue* queue(const QString& queueName = defaultName()); static QList queues(); static Queue* currentQueue(); static void setCurrentQueue(Queue * queue); static Queue* createQueue(const QString& queueName); static void removeQueue(Queue * queue); static QueueManager * instance() { return _self; } protected slots: void slotShowQueueDialog(); void slotQueueEmptied(); signals: void queueInserted(Queue *); void queueDeleted(Queue *); void currentChanged(Queue *); void percent(Queue *, int); protected: static QMap _queues; static Queue * _current; static QueueManager * _self; static int _nextId; }; #endif // QUEUE_MGR_H diff --git a/krusader/Queue/queuedialog.cpp b/krusader/Queue/queuedialog.cpp index e66939a3..5de69eb7 100644 --- a/krusader/Queue/queuedialog.cpp +++ b/krusader/Queue/queuedialog.cpp @@ -1,350 +1,351 @@ /***************************************************************************** * Copyright (C) 2008-2009 Csaba Karai * * * * 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 package 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 package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #include "queuedialog.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include +// QtWidgets +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include #include #include "queuewidget.h" #include "queue_mgr.h" #include "../krglobal.h" class KrTimeDialog : public QDialog { public: KrTimeDialog(QWidget * parent = 0) : QDialog(parent) { setWindowTitle(i18n("Krusader::Queue Manager")); setWindowModality(Qt::WindowModal); QVBoxLayout *mainLayout = new QVBoxLayout; setLayout(mainLayout); mainLayout->addWidget(new QLabel(i18n("Please enter the time to start processing the queue:"))); QTime time = QTime::currentTime(); time = time.addSecs(60 * 60); // add 1 hour _timeEdit = new QTimeEdit(time, this); _timeEdit->setDisplayFormat("hh:mm:ss"); mainLayout->addWidget(_timeEdit); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); mainLayout->addWidget(buttonBox); QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); okButton->setDefault(true); okButton->setShortcut(Qt::CTRL | Qt::Key_Return); connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); _timeEdit->setFocus(); } QTime getStartTime() { return _timeEdit->time(); } private: QTimeEdit * _timeEdit; }; QueueDialog * QueueDialog::_queueDialog = 0; QueueDialog::QueueDialog() : QDialog(), _autoHide(true) { setWindowModality(Qt::NonModal); setWindowTitle(i18n("Krusader::Queue Manager")); QVBoxLayout *mainLayout = new QVBoxLayout; setLayout(mainLayout); QHBoxLayout * hbox2 = new QHBoxLayout; QAction *act = new QAction(this); act->setIcon(QIcon::fromTheme("tab-new")); act->setToolTip(i18n("Create a new queue")); act->setShortcuts(QKeySequence::keyBindings(QKeySequence::AddTab)); connect(act, SIGNAL(triggered(bool)), this, SLOT(slotNewTab())); _newTabButton = new QToolButton(this); _newTabButton->setDefaultAction(act); hbox2->addWidget(_newTabButton); _closeTabButton = new QToolButton(this); _closeTabButton->setIcon(QIcon::fromTheme("tab-close")); _closeTabButton->setToolTip(i18n("Remove the current queue")); _closeTabButton->setShortcut(QKeySequence::Close); connect(_closeTabButton, SIGNAL(clicked()), this, SLOT(slotDeleteCurrentTab())); hbox2->addWidget(_closeTabButton); _pauseButton = new QToolButton(this); _pauseButton->setIcon(QIcon::fromTheme("media-playback-pause")); _pauseButton->setShortcut(Qt::CTRL + Qt::Key_P); connect(_pauseButton, SIGNAL(clicked()), this, SLOT(slotPauseClicked())); hbox2->addWidget(_pauseButton); _progressBar = new QProgressBar(this); _progressBar->setMinimum(0); _progressBar->setMaximum(100); _progressBar->setValue(0); _progressBar->setFormat(i18n("unused")); _progressBar->setTextVisible(true); hbox2->addWidget(_progressBar); _scheduleButton = new QToolButton(this); _scheduleButton->setIcon(QIcon::fromTheme("chronometer")); _scheduleButton->setToolTip(i18n("Schedule queue starting (Ctrl+S)")); _scheduleButton->setShortcut(Qt::CTRL + Qt::Key_S); connect(_scheduleButton, SIGNAL(clicked()), this, SLOT(slotScheduleClicked())); hbox2->addWidget(_scheduleButton); mainLayout->addLayout(hbox2); _queueWidget = new QueueWidget(this); _queueWidget->setDocumentMode(true); connect(_queueWidget, SIGNAL(currentChanged()), this, SLOT(slotUpdateToolbar())); mainLayout->addWidget(_queueWidget); _statusLabel = new QLabel(this); QSizePolicy statuspolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); statuspolicy.setHeightForWidth(_statusLabel->sizePolicy().hasHeightForWidth()); _statusLabel->setSizePolicy(statuspolicy); mainLayout->addWidget(_statusLabel); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Close); mainLayout->addWidget(buttonBox); KConfigGroup group(krConfig, "QueueManager"); int sizeX = group.readEntry("Window Width", -1); int sizeY = group.readEntry("Window Height", -1); int x = group.readEntry("Window X", -1); int y = group.readEntry("Window Y", -1); if (sizeX != -1 && sizeY != -1) resize(sizeX, sizeY); else resize(300, 400); if (x != -1 && y != -1) move(x, y); else move(20, 20); slotUpdateToolbar(); QAction *nextTabAction = new QAction(this); nextTabAction->setShortcuts(KStandardShortcut::tabNext()); addAction(nextTabAction); connect(nextTabAction, SIGNAL(triggered()), SLOT(slotNextTab())); QAction *prevTabAction = new QAction(this); prevTabAction->setShortcuts(KStandardShortcut::tabPrev()); addAction(prevTabAction); connect(prevTabAction, SIGNAL(triggered()), SLOT(slotPrevTab())); QAction *deleteQueueAction = new QAction(this); deleteQueueAction->setShortcut(Qt::Key_Delete); addAction(deleteQueueAction); connect(deleteQueueAction, SIGNAL(triggered()), _queueWidget, SLOT(deleteCurrent())); connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); connect(QueueManager::instance(), SIGNAL(queueInserted(Queue *)), this, SLOT(slotUpdateToolbar())); connect(QueueManager::instance(), SIGNAL(percent(Queue *, int)), this, SLOT(slotPercentChanged(Queue *, int))); show(); _queueWidget->currentWidget()->setFocus(); _queueDialog = this; } QueueDialog::~QueueDialog() { if (_queueDialog) saveSettings(); _queueDialog = 0; } void QueueDialog::showDialog(bool autoHide) { if (_queueDialog == 0) _queueDialog = new QueueDialog(); else { _queueDialog->show(); if (!autoHide) { _queueDialog->raise(); _queueDialog->activateWindow(); } } if (!autoHide) _queueDialog->_autoHide = false; } void QueueDialog::everyQueueIsEmpty() { if (_queueDialog->_autoHide && _queueDialog != 0 && !_queueDialog->isHidden()) _queueDialog->reject(); } void QueueDialog::reject() { _autoHide = true; saveSettings(); QDialog::reject(); } void QueueDialog::saveSettings() { KConfigGroup group(krConfig, "QueueManager"); group.writeEntry("Window Width", width()); group.writeEntry("Window Height", height()); group.writeEntry("Window X", x()); group.writeEntry("Window Y", y()); } void QueueDialog::deleteDialog() { if (_queueDialog) delete _queueDialog; } void QueueDialog::slotUpdateToolbar() { Queue * currentQueue = QueueManager::currentQueue(); if (currentQueue) { if (currentQueue->isSuspended()) { _pauseButton->setIcon(QIcon::fromTheme("media-playback-start")); _pauseButton->setToolTip(i18n("Start processing the queue (Ctrl+P)")); QTime time = currentQueue->scheduleTime(); if (time.isNull()) { _statusLabel->setText(i18n("The queue is paused.")); } else { _statusLabel->setText(i18n("Scheduled to start at %1.", time.toString("hh:mm:ss"))); } } else { _statusLabel->setText(i18n("The queue is running.")); _pauseButton->setIcon(QIcon::fromTheme("media-playback-pause")); _pauseButton->setToolTip(i18n("Pause processing the queue (Ctrl+P)")); } _closeTabButton->setEnabled(_queueWidget->count() > 1); slotPercentChanged(currentQueue, currentQueue->getPercent()); } } void QueueDialog::slotPauseClicked() { Queue * currentQueue = QueueManager::currentQueue(); if (currentQueue) { if (currentQueue->isSuspended()) currentQueue->resume(); else currentQueue->suspend(); } } void QueueDialog::slotScheduleClicked() { QPointer dialog = new KrTimeDialog(this); if (dialog->exec() == QDialog::Accepted) { QTime startTime = dialog->getStartTime(); Queue * queue = QueueManager::currentQueue(); queue->schedule(startTime); } delete dialog; } void QueueDialog::slotNewTab() { bool ok = false; QString queueName = QInputDialog::getText(this, i18n("Krusader::Queue Manager"), i18n("Please enter the name of the new queue"), QLineEdit::Normal, QString(), &ok); if (!ok || queueName.isEmpty()) return; Queue * queue = QueueManager::createQueue(queueName); if (queue == 0) { KMessageBox::error(this, i18n("A queue already exists with this name.")); } } void QueueDialog::slotNextTab() { int curr = _queueWidget->currentIndex(); int count = _queueWidget->count(); _queueWidget->setCurrentIndex((curr + 1) % count); } void QueueDialog::slotPrevTab() { int curr = _queueWidget->currentIndex(); int count = _queueWidget->count(); _queueWidget->setCurrentIndex((curr + count - 1) % count); } void QueueDialog::slotDeleteCurrentTab() { Queue * currentQueue = QueueManager::currentQueue(); if (currentQueue) { if (currentQueue->count() != 0) { if (KMessageBox::warningContinueCancel(this, i18n("Deleting the queue requires aborting all pending jobs. Do you wish to continue?"), i18n("Warning")) != KMessageBox::Continue) return; } QueueManager::removeQueue(currentQueue); } } void QueueDialog::slotPercentChanged(Queue * queue, int percent) { if (QueueManager::currentQueue() == queue) { switch (percent) { case PERCENT_UNUSED: _progressBar->setMaximum(100); _progressBar->setValue(0); _progressBar->setFormat(i18n("unused")); break; case PERCENT_UNKNOWN: if (_progressBar->maximum() != 0) { _progressBar->setMaximum(0); _progressBar->setFormat(""); } break; default: if (_progressBar->maximum() != 100) _progressBar->setMaximum(100); _progressBar->setValue(percent); _progressBar->setFormat("%p%"); break; } } } diff --git a/krusader/Queue/queuedialog.h b/krusader/Queue/queuedialog.h index 6b03a093..060a2f5e 100644 --- a/krusader/Queue/queuedialog.h +++ b/krusader/Queue/queuedialog.h @@ -1,75 +1,76 @@ /***************************************************************************** * Copyright (C) 2008-2009 Csaba Karai * * * * 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 package 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 package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #ifndef QUEUEDIALOG_H #define QUEUEDIALOG_H -#include +// QtWidgets +#include class QToolButton; class QueueWidget; class QLabel; class QProgressBar; class Queue; class QueueDialog : public QDialog { Q_OBJECT private: QueueDialog(); public: virtual ~QueueDialog(); static void showDialog(bool autoHide = true); static void deleteDialog(); static void everyQueueIsEmpty(); public slots: void reject() Q_DECL_OVERRIDE; void slotUpdateToolbar(); void slotPauseClicked(); void slotScheduleClicked(); void slotNewTab(); void slotNextTab(); void slotPrevTab(); void slotDeleteCurrentTab(); void slotPercentChanged(Queue *, int); protected: void saveSettings(); private: static QueueDialog * _queueDialog; QToolButton * _newTabButton; QToolButton * _closeTabButton; QToolButton * _pauseButton; QToolButton * _scheduleButton; QProgressBar * _progressBar; QueueWidget * _queueWidget; QLabel * _statusLabel; bool _autoHide; }; #endif // __QUEUEDIALOG_H__ diff --git a/krusader/Queue/queuewidget.cpp b/krusader/Queue/queuewidget.cpp index 94bbb97f..05e41b70 100644 --- a/krusader/Queue/queuewidget.cpp +++ b/krusader/Queue/queuewidget.cpp @@ -1,165 +1,167 @@ /***************************************************************************** * Copyright (C) 2008-2009 Csaba Karai * * * * 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 package 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 package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #include "queuewidget.h" #include "queue_mgr.h" -#include -#include +// QtGui +#include +// QtWidgets +#include #include #include QueueWidget::QueueWidget(QWidget * parent): QTabWidget(parent) { QList queueList = QueueManager::queues(); foreach(const QString &name, queueList) { KrQueueListWidget * jobWidget = new KrQueueListWidget(QueueManager::queue(name), this); connect(jobWidget, SIGNAL(stateChanged()), this, SIGNAL(currentChanged())); addTab(jobWidget, name); _queueWidgets[ name ] = jobWidget; } connect(QueueManager::instance(), SIGNAL(queueInserted(Queue *)), this, SLOT(slotQueueAdded(Queue *))); connect(QueueManager::instance(), SIGNAL(queueDeleted(Queue *)), this, SLOT(slotQueueDeleted(Queue *))); connect(QueueManager::instance(), SIGNAL(currentChanged(Queue *)), this, SLOT(slotCurrentChanged(Queue *))); connect(this, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentChanged(int))); Queue * current = QueueManager::currentQueue(); if (current) { QString name = current->name(); setCurrentWidget(_queueWidgets[ name ]); } } QueueWidget::~QueueWidget() { } void QueueWidget::slotQueueAdded(Queue * queue) { KrQueueListWidget * jobWidget = new KrQueueListWidget(queue, this); connect(jobWidget, SIGNAL(stateChanged()), this, SIGNAL(currentChanged())); addTab(jobWidget, queue->name()); _queueWidgets[ queue->name()] = jobWidget; setCurrentWidget(jobWidget); } void QueueWidget::slotQueueDeleted(Queue * queue) { KrQueueListWidget * queueWidget = _queueWidgets[ queue->name()]; _queueWidgets.remove(queue->name()); int index = indexOf(queueWidget); removeTab(index); delete queueWidget; } void QueueWidget::slotCurrentChanged(int index) { KrQueueListWidget * queueWidget = dynamic_cast(widget(index)); if (queueWidget->queue()) QueueManager::setCurrentQueue(queueWidget->queue()); emit currentChanged(); } void QueueWidget::slotCurrentChanged(Queue * queue) { KrQueueListWidget * queueWidget = _queueWidgets[ queue->name()]; setCurrentWidget(queueWidget); } void QueueWidget::deleteCurrent() { QWidget * current = currentWidget(); if (current) { KrQueueListWidget * lw = (KrQueueListWidget *)current; QListWidgetItem * lvitem = lw->currentItem(); if (lvitem == 0) lvitem = lw->item(0); if (lvitem) lw->deleteItem(lvitem); } } class KrQueueListWidgetItem : public QListWidgetItem { public: KrQueueListWidgetItem(const QString & label_, KIOJobWrapper * job_) : QListWidgetItem(label_), _job(job_) { setToolTip(job_->toolTip()); } KIOJobWrapper * job() { return _job; } private: QPointer _job; }; KrQueueListWidget::KrQueueListWidget(Queue * queue, QWidget * parent) : KrListWidget(parent), _queue(queue) { connect(queue, SIGNAL(changed()), this, SLOT(slotChanged())); connect(queue, SIGNAL(stateChanged()), this, SIGNAL(stateChanged())); connect(this, SIGNAL(itemRightClicked(QListWidgetItem *, const QPoint &)), this, SLOT(slotItemRightClicked(QListWidgetItem *))); slotChanged(); } void KrQueueListWidget::slotChanged() { clear(); if (_queue) { QList itdescs = _queue->itemDescriptions(); QList items = _queue->items(); for (int i = 0; i != items.count(); i++) addItem(new KrQueueListWidgetItem(itdescs[ i ], items[ i ])); } } void KrQueueListWidget::slotItemRightClicked(QListWidgetItem * item) { if (item) { KrQueueListWidgetItem * kitem = (KrQueueListWidgetItem *)item; if (kitem->job()) { QMenu popup(this); popup.setTitle(i18n("Queue Manager")); QAction * actDelete = popup.addAction(i18n("Delete")); QAction * res = popup.exec(QCursor::pos()); if (res == actDelete) deleteItem(kitem); } } } void KrQueueListWidget::deleteItem(QListWidgetItem * item) { KrQueueListWidgetItem * kitem = (KrQueueListWidgetItem *)item; if (kitem->job() && kitem->job()->isStarted()) { if (KMessageBox::warningContinueCancel(this, i18n("Deleting this job will abort the pending job. Do you wish to continue?"), i18n("Warning")) != KMessageBox::Continue) return; } if (kitem->job()) _queue->remove(kitem->job()); } diff --git a/krusader/Queue/queuewidget.h b/krusader/Queue/queuewidget.h index aa91e938..43831cb3 100644 --- a/krusader/Queue/queuewidget.h +++ b/krusader/Queue/queuewidget.h @@ -1,74 +1,76 @@ /***************************************************************************** * Copyright (C) 2008-2009 Csaba Karai * * * * 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 package 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 package; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #ifndef QUEUEWIDGET_H #define QUEUEWIDGET_H -#include -#include +// QtCore +#include +// QtWidgets +#include #include "queue.h" #include "../GUI/krlistwidget.h" class KrQueueListWidget; class QueueWidget: public QTabWidget { Q_OBJECT public: QueueWidget(QWidget * parent = 0); ~QueueWidget(); protected slots: void deleteCurrent(); void slotQueueAdded(Queue *); void slotQueueDeleted(Queue *); void slotCurrentChanged(Queue *); void slotCurrentChanged(int); signals: void currentChanged(); private: QMap _queueWidgets; }; class KrQueueListWidget : public KrListWidget { Q_OBJECT public: KrQueueListWidget(Queue * queue, QWidget * parent); Queue * queue() { return _queue; } void deleteItem(QListWidgetItem * item); public slots: void slotChanged(); void slotItemRightClicked(QListWidgetItem *); signals: void stateChanged(); private: QPointer _queue; }; #endif // QUEUE_WIDGET_H