1 /* Copyright (C) 2006 - 2014 Jan Kundrát <jkt@flaska.net>
2 Copyright (C) 2014 Thomas Lübking <thomas.luebking@gmail.com>
4 This file is part of the Trojita Qt IMAP e-mail client,
5 http://trojita.flaska.net/
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of
10 the License or (at your option) version 3 or any later version
11 accepted by the membership of KDE e.V. (or its successor approved
12 by the membership of KDE e.V.), which shall act as a proxy
13 defined in Section 14 of version 3 of the license.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "TaskProgressIndicator.h"
25 #include <QApplication>
26 #include <QMouseEvent>
28 #include "Gui/Spinner.h"
29 #include "Imap/Model/Model.h"
30 #include "Imap/Model/VisibleTasksModel.h"
35 TaskProgressIndicator::TaskProgressIndicator(QWidget
*parent
) :
36 Spinner(parent
), m_busyCursorTrigger(new QTimer(this)), m_busy(false)
38 connect(m_busyCursorTrigger
, &QTimer::timeout
, []() {
39 QApplication::setOverrideCursor(Qt::BusyCursor
);
41 m_busyCursorTrigger
->setSingleShot(true);
42 m_busyCursorTrigger
->setInterval(666);
44 setType(Spinner::Elastic
);
45 setContext(Spinner::Throbber
);
48 /** @short Connect to the specified IMAP model as the source of the activity information */
49 void TaskProgressIndicator::setImapModel(Imap::Mailbox::Model
*model
)
52 m_visibleTasksModel
= new Imap::Mailbox::VisibleTasksModel(model
, model
->taskModel());
53 connect(m_visibleTasksModel
.data(), &QAbstractItemModel::layoutChanged
, this, &TaskProgressIndicator::updateActivityIndication
);
54 connect(m_visibleTasksModel
.data(), &QAbstractItemModel::modelReset
, this, &TaskProgressIndicator::updateActivityIndication
);
55 connect(m_visibleTasksModel
.data(), &QAbstractItemModel::rowsInserted
, this, &TaskProgressIndicator::updateActivityIndication
);
56 connect(m_visibleTasksModel
.data(), &QAbstractItemModel::rowsRemoved
, this, &TaskProgressIndicator::updateActivityIndication
);
60 /** @short Reflect a possible change in the activity in the GUI */
61 void TaskProgressIndicator::updateActivityIndication()
63 if (!m_visibleTasksModel
)
66 bool busy
= m_visibleTasksModel
->hasChildren();
67 if (!m_busy
&& busy
) {
69 if (!m_busyCursorTrigger
->isActive()) {
70 // do NOT restart, we don't want to prolong this delay
71 m_busyCursorTrigger
->start();
73 } else if (m_busy
&& !busy
) {
75 if (!m_busyCursorTrigger
->isActive()) {
76 // don't restore unless we've alredy set it
77 QApplication::restoreOverrideCursor();
79 // don't cause future timeout
80 m_busyCursorTrigger
->stop();
84 setToolTip(tr("%n ongoing actions", 0, m_visibleTasksModel
->rowCount()));
86 setToolTip(tr("IMAP connection idle"));