1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
33 #include "progressview.h"
34 #include "futureprogress.h"
36 #include <utils/qtcassert.h>
38 #include <QtGui/QHBoxLayout>
39 #include <QtGui/QVBoxLayout>
42 using namespace Core::Internal;
44 ProgressView::ProgressView(QWidget *parent)
47 m_layout = new QVBoxLayout;
49 m_layout->setMargin(0);
50 m_layout->setSpacing(0);
51 setWindowTitle(tr("Processes"));
54 ProgressView::~ProgressView()
56 qDeleteAll(m_taskList);
60 FutureProgress *ProgressView::addTask(const QFuture<void> &future,
63 ProgressManager::ProgressFlags flags)
66 if (m_taskList.size() == 3)
68 FutureProgress *progress = new FutureProgress(this);
69 progress->setTitle(title);
70 progress->setFuture(future);
72 m_layout->insertWidget(0, progress);
73 m_taskList.append(progress);
74 progress->setType(type);
75 if (flags.testFlag(ProgressManager::KeepOnFinish)) {
76 progress->setKeepOnFinish(FutureProgress::KeepOnFinishTillUserInteraction);
78 progress->setKeepOnFinish(FutureProgress::DontKeepOnFinish);
80 connect(progress, SIGNAL(removeMe()), this, SLOT(slotRemoveTask()));
84 void ProgressView::removeOldTasks(const QString &type, bool keepOne)
86 bool firstFound = !keepOne; // start with false if we want to keep one
87 QList<FutureProgress *>::iterator i = m_taskList.end();
88 while (i != m_taskList.begin()) {
90 if ((*i)->type() == type) {
91 if (firstFound && (*i)->future().isFinished()) {
93 i = m_taskList.erase(i);
100 void ProgressView::deleteTask(FutureProgress *progress)
102 layout()->removeWidget(progress);
104 progress->deleteLater();
107 void ProgressView::removeOneOldTask()
109 if (m_taskList.isEmpty())
111 // look for oldest ended process
112 for (QList<FutureProgress *>::iterator i = m_taskList.begin(); i != m_taskList.end(); ++i) {
113 if ((*i)->future().isFinished()) {
115 i = m_taskList.erase(i);
119 // no ended process, look for a task type with multiple running tasks and remove the oldest one
120 for (QList<FutureProgress *>::iterator i = m_taskList.begin(); i != m_taskList.end(); ++i) {
121 QString type = (*i)->type();
124 foreach (FutureProgress *p, m_taskList)
125 if (p->type() == type)
128 if (taskCount > 1) { // don't care for optimizations it's only a handful of entries
130 i = m_taskList.erase(i);
135 // no ended process, no type with multiple processes, just remove the oldest task
136 FutureProgress *task = m_taskList.takeFirst();
140 void ProgressView::removeTask(FutureProgress *task)
142 m_taskList.removeAll(task);
146 void ProgressView::slotRemoveTask()
148 FutureProgress *progress = qobject_cast<FutureProgress *>(sender());
149 QTC_ASSERT(progress, return);
150 QString type = progress->type();
151 removeTask(progress);
152 removeOldTasks(type, true);