1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
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 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "progressview.h"
35 #include "futureprogress.h"
37 #include <utils/qtcassert.h>
39 #include <QtGui/QHBoxLayout>
40 #include <QtGui/QVBoxLayout>
43 using namespace Core::Internal;
45 ProgressView::ProgressView(QWidget *parent)
48 m_layout = new QVBoxLayout;
50 m_layout->setMargin(0);
51 m_layout->setSpacing(0);
52 setWindowTitle(tr("Processes"));
55 ProgressView::~ProgressView()
57 qDeleteAll(m_taskList);
61 FutureProgress *ProgressView::addTask(const QFuture<void> &future,
64 ProgressManager::ProgressFlags flags)
67 if (m_taskList.size() == 3)
69 FutureProgress *progress = new FutureProgress(this);
70 progress->setTitle(title);
71 progress->setFuture(future);
73 m_layout->insertWidget(0, progress);
74 m_taskList.append(progress);
75 progress->setType(type);
76 if (flags.testFlag(ProgressManager::KeepOnFinish)) {
77 progress->setKeepOnFinish(FutureProgress::KeepOnFinishTillUserInteraction);
79 progress->setKeepOnFinish(FutureProgress::DontKeepOnFinish);
81 connect(progress, SIGNAL(removeMe()), this, SLOT(slotRemoveTask()));
85 void ProgressView::removeOldTasks(const QString &type, bool keepOne)
87 bool firstFound = !keepOne; // start with false if we want to keep one
88 QList<FutureProgress *>::iterator i = m_taskList.end();
89 while (i != m_taskList.begin()) {
91 if ((*i)->type() == type) {
92 if (firstFound && (*i)->future().isFinished()) {
94 i = m_taskList.erase(i);
101 void ProgressView::deleteTask(FutureProgress *progress)
103 layout()->removeWidget(progress);
105 progress->deleteLater();
108 void ProgressView::removeOneOldTask()
110 if (m_taskList.isEmpty())
112 // look for oldest ended process
113 for (QList<FutureProgress *>::iterator i = m_taskList.begin(); i != m_taskList.end(); ++i) {
114 if ((*i)->future().isFinished()) {
116 i = m_taskList.erase(i);
120 // no ended process, look for a task type with multiple running tasks and remove the oldest one
121 for (QList<FutureProgress *>::iterator i = m_taskList.begin(); i != m_taskList.end(); ++i) {
122 QString type = (*i)->type();
125 foreach (FutureProgress *p, m_taskList)
126 if (p->type() == type)
129 if (taskCount > 1) { // don't care for optimizations it's only a handful of entries
131 i = m_taskList.erase(i);
136 // no ended process, no type with multiple processes, just remove the oldest task
137 FutureProgress *task = m_taskList.takeFirst();
141 void ProgressView::removeTask(FutureProgress *task)
143 m_taskList.removeAll(task);
147 void ProgressView::slotRemoveTask()
149 FutureProgress *progress = qobject_cast<FutureProgress *>(sender());
150 QTC_ASSERT(progress, return);
151 QString type = progress->type();
152 removeTask(progress);
153 removeOldTasks(type, true);