1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** Licensees holding valid Qt Commercial licenses may use this file in
12 ** accordance with the Qt Commercial License Agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and Nokia.
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** If you are unsure which license is appropriate for your use, please
26 ** contact the sales department at http://qt.nokia.com/contact.
28 **************************************************************************/
30 #include "progressview.h"
31 #include "futureprogress.h"
33 #include <utils/qtcassert.h>
35 #include <QtGui/QHBoxLayout>
38 using namespace Core::Internal;
40 ProgressView::ProgressView(QWidget *parent)
43 m_layout = new QVBoxLayout;
45 m_layout->setMargin(0);
46 m_layout->setSpacing(0);
47 setWindowTitle(tr("Processes"));
50 ProgressView::~ProgressView()
52 qDeleteAll(m_taskList);
58 FutureProgress *ProgressView::addTask(const QFuture<void> &future,
61 ProgressManager::ProgressFlags flags)
64 if (m_taskList.size() == 3)
66 FutureProgress *progress = new FutureProgress(this);
67 progress->setTitle(title);
68 progress->setFuture(future);
69 m_layout->insertWidget(0, progress);
70 m_taskList.append(progress);
71 m_type.insert(progress, type);
72 m_keep.insert(progress, (flags & ProgressManager::KeepOnFinish));
73 connect(progress, SIGNAL(finished()), this, SLOT(slotFinished()));
77 void ProgressView::removeOldTasks(const QString &type, bool keepOne)
79 bool firstFound = !keepOne; // start with false if we want to keep one
80 QList<FutureProgress *>::iterator i = m_taskList.end();
81 while (i != m_taskList.begin()) {
83 if (m_type.value(*i) == type) {
84 if (firstFound && (*i)->future().isFinished()) {
86 i = m_taskList.erase(i);
93 void ProgressView::deleteTask(FutureProgress *progress)
95 m_type.remove(progress);
96 m_keep.remove(progress);
97 layout()->removeWidget(progress);
99 progress->deleteLater();
102 void ProgressView::removeOneOldTask()
104 if (m_taskList.isEmpty())
106 // look for oldest ended process
107 for (QList<FutureProgress *>::iterator i = m_taskList.begin(); i != m_taskList.end(); ++i) {
108 if ((*i)->future().isFinished()) {
110 i = m_taskList.erase(i);
114 // no ended process, look for a task type with multiple running tasks and remove the oldest one
115 for (QList<FutureProgress *>::iterator i = m_taskList.begin(); i != m_taskList.end(); ++i) {
116 QString type = m_type.value(*i);
117 if (m_type.keys(type).size() > 1) { // don't care for optimizations it's only a handful of entries
119 i = m_taskList.erase(i);
124 // no ended process, no type with multiple processes, just remove the oldest task
125 FutureProgress *task = m_taskList.takeFirst();
129 void ProgressView::removeTask(FutureProgress *task)
131 m_taskList.removeAll(task);
135 void ProgressView::slotFinished()
137 FutureProgress *progress = qobject_cast<FutureProgress *>(sender());
138 QTC_ASSERT(progress, return);
139 if (m_keep.contains(progress) && !m_keep.value(progress) && !progress->hasError())
140 removeTask(progress);
141 removeOldTasks(m_type.value(progress), true);