Added indicators for current CPU usage, RAM usage and free disk space to the processi...
[LameXP.git] / src / Dialog_WorkingBanner.cpp
blobf39f8110b49c146294c4a5838a60723c54877a22
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "Dialog_WorkingBanner.h"
24 #include "Global.h"
25 #include "WinSevenTaskbar.h"
27 #include <QThread>
28 #include <QMovie>
29 #include <QKeyEvent>
30 #include <QFontMetrics>
32 #define EPS (1.0E-5)
34 ////////////////////////////////////////////////////////////
35 // Constructor
36 ////////////////////////////////////////////////////////////
38 WorkingBanner::WorkingBanner(QWidget *parent)
40 QDialog(parent, Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)
42 //Init the dialog, from the .ui file
43 setupUi(this);
44 setModal(true);
46 //Start animation
47 m_working = new QMovie(":/images/Busy.gif");
48 labelWorking->setMovie(m_working);
49 m_working->start();
51 //Set wait cursor
52 setCursor(Qt::WaitCursor);
54 //Init taskbar
55 WinSevenTaskbar::initTaskbar();
58 ////////////////////////////////////////////////////////////
59 // Destructor
60 ////////////////////////////////////////////////////////////
62 WorkingBanner::~WorkingBanner(void)
64 if(m_working)
66 m_working->stop();
67 delete m_working;
68 m_working = NULL;
72 ////////////////////////////////////////////////////////////
73 // PUBLIC FUNCTIONS
74 ////////////////////////////////////////////////////////////
76 void WorkingBanner::show(const QString &text)
78 m_canClose = false;
79 QDialog::show();
80 setText(text);
81 QApplication::processEvents();
84 void WorkingBanner::close(void)
86 m_canClose = true;
87 QDialog::close();
90 void WorkingBanner::show(const QString &text, QThread *thread)
92 //Show splash
93 this->show(text);
95 //Start the thread
96 thread->start();
98 //Set taskbar state
99 WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), &QIcon(":/icons/hourglass.png"));
100 WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarIndeterminateState);
102 //Loop while thread is running
103 while(thread->isRunning())
105 QApplication::processEvents(QEventLoop::AllEvents | QEventLoop::WaitForMoreEvents);
108 //Set taskbar state
109 WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarNoState);
110 WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), NULL);
112 //Hide splash
113 this->close();
116 void WorkingBanner::show(const QString &text, QEventLoop *loop)
118 //Show splash
119 this->show(text);
121 //Set taskbar state
122 WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), &QIcon(":/icons/hourglass.png"));
123 WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarIndeterminateState);
125 //Loop while thread is running
126 loop->exec(QEventLoop::ExcludeUserInputEvents);
128 //Set taskbar state
129 WinSevenTaskbar::setTaskbarState(dynamic_cast<QWidget*>(this->parent()), WinSevenTaskbar::WinSevenTaskbarNoState);
130 WinSevenTaskbar::setOverlayIcon(dynamic_cast<QWidget*>(this->parent()), NULL);
132 //Hide splash
133 this->close();
136 ////////////////////////////////////////////////////////////
137 // EVENTS
138 ////////////////////////////////////////////////////////////
140 void WorkingBanner::keyPressEvent(QKeyEvent *event)
142 if(event->key() == Qt::Key_Escape)
144 qDebug("QT::KEY_ESCAPE pressed!");
145 emit userAbort();
148 event->ignore();
151 void WorkingBanner::keyReleaseEvent(QKeyEvent *event)
153 event->ignore();
156 void WorkingBanner::closeEvent(QCloseEvent *event)
158 if(!m_canClose) event->ignore();
161 ////////////////////////////////////////////////////////////
162 // SLOTS
163 ////////////////////////////////////////////////////////////
165 void WorkingBanner::setText(const QString &text)
167 QFontMetrics metrics(labelStatus->font());
168 if(metrics.width(text) <= labelStatus->width())
170 labelStatus->setText(text);
172 else
174 QString choppedText = text.simplified().append("...");
175 while(metrics.width(choppedText) > labelStatus->width() && choppedText.length() > 8)
177 choppedText.chop(4);
178 choppedText = choppedText.trimmed();
179 choppedText.append("...");
181 labelStatus->setText(choppedText);
183 if(this->isVisible())
185 QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);