2010-11-06 23:04:47 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// LameXP - Audio Encoder Front-End
|
2012-01-02 00:52:27 +01:00
|
|
|
// Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
|
2010-11-06 23:04:47 +01:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
|
|
|
// http://www.gnu.org/licenses/gpl-2.0.txt
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "Dialog_SplashScreen.h"
|
|
|
|
|
|
|
|
#include "Global.h"
|
|
|
|
|
|
|
|
#include <QThread>
|
|
|
|
#include <QMovie>
|
|
|
|
#include <QKeyEvent>
|
2012-02-23 17:00:22 +01:00
|
|
|
#include <QTimer>
|
2010-11-06 23:04:47 +01:00
|
|
|
|
2011-11-07 17:13:41 +01:00
|
|
|
#include "WinSevenTaskbar.h"
|
|
|
|
|
2010-11-06 23:04:47 +01:00
|
|
|
#define EPS (1.0E-5)
|
2011-11-11 18:08:22 +01:00
|
|
|
#define FADE_DELAY 4
|
2010-11-06 23:04:47 +01:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Constructor
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
SplashScreen::SplashScreen(QWidget *parent)
|
2012-03-23 01:29:50 +01:00
|
|
|
:
|
|
|
|
QFrame(parent, Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)
|
2010-11-06 23:04:47 +01:00
|
|
|
{
|
|
|
|
//Init the dialog, from the .ui file
|
|
|
|
setupUi(this);
|
|
|
|
|
|
|
|
//Start animation
|
|
|
|
m_working = new QMovie(":/images/Loading.gif");
|
|
|
|
labelLoading->setMovie(m_working);
|
|
|
|
m_working->start();
|
|
|
|
|
|
|
|
//Set wait cursor
|
|
|
|
setCursor(Qt::WaitCursor);
|
|
|
|
|
|
|
|
//Prevent close
|
|
|
|
m_canClose = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// Destructor
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
SplashScreen::~SplashScreen(void)
|
|
|
|
{
|
|
|
|
if(m_working)
|
|
|
|
{
|
|
|
|
m_working->stop();
|
|
|
|
delete m_working;
|
|
|
|
m_working = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// PUBLIC FUNCTIONS
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void SplashScreen::showSplash(QThread *thread)
|
|
|
|
{
|
2011-11-11 18:08:22 +01:00
|
|
|
double opacity = 0.0;
|
2010-11-06 23:04:47 +01:00
|
|
|
SplashScreen *splashScreen = new SplashScreen();
|
|
|
|
|
|
|
|
//Show splash
|
|
|
|
splashScreen->m_canClose = false;
|
2011-11-11 18:08:22 +01:00
|
|
|
splashScreen->setWindowOpacity(opacity);
|
2010-11-06 23:04:47 +01:00
|
|
|
splashScreen->show();
|
2011-11-11 18:08:22 +01:00
|
|
|
|
|
|
|
//Wait for window to show
|
|
|
|
QApplication::processEvents();
|
|
|
|
Sleep(100);
|
2010-11-06 23:04:47 +01:00
|
|
|
QApplication::processEvents();
|
|
|
|
|
2011-11-11 18:08:22 +01:00
|
|
|
//Setup the event loop
|
2011-11-07 17:13:41 +01:00
|
|
|
QEventLoop *loop = new QEventLoop(splashScreen);
|
|
|
|
connect(thread, SIGNAL(terminated()), loop, SLOT(quit()), Qt::QueuedConnection);
|
|
|
|
connect(thread, SIGNAL(finished()), loop, SLOT(quit()), Qt::QueuedConnection);
|
|
|
|
|
2012-02-23 21:21:02 +01:00
|
|
|
//Create timer
|
|
|
|
QTimer *timer = new QTimer();
|
|
|
|
connect(timer, SIGNAL(timeout()), loop, SLOT(quit()));
|
|
|
|
|
2011-11-11 18:08:22 +01:00
|
|
|
//Start thread
|
|
|
|
QApplication::processEvents();
|
2010-11-06 23:04:47 +01:00
|
|
|
thread->start();
|
2011-11-11 18:08:22 +01:00
|
|
|
QApplication::processEvents();
|
|
|
|
|
|
|
|
//Init taskbar
|
|
|
|
WinSevenTaskbar::setTaskbarState(splashScreen, WinSevenTaskbar::WinSevenTaskbarIndeterminateState);
|
2011-11-07 17:13:41 +01:00
|
|
|
|
2010-11-06 23:04:47 +01:00
|
|
|
//Fade in
|
2011-11-11 18:08:22 +01:00
|
|
|
for(int i = 0; i <= 100; i++)
|
2010-11-06 23:04:47 +01:00
|
|
|
{
|
2011-11-11 18:08:22 +01:00
|
|
|
opacity = 0.01 * static_cast<double>(i);
|
|
|
|
splashScreen->setWindowOpacity(opacity);
|
2012-03-01 02:45:21 +01:00
|
|
|
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents, FADE_DELAY);
|
2011-11-11 18:08:22 +01:00
|
|
|
Sleep(FADE_DELAY);
|
2010-11-06 23:04:47 +01:00
|
|
|
}
|
|
|
|
|
2012-02-23 21:21:02 +01:00
|
|
|
//Start the timer
|
2012-03-06 22:29:55 +01:00
|
|
|
timer->start(30720);
|
2012-02-23 21:21:02 +01:00
|
|
|
|
2012-03-22 22:26:54 +01:00
|
|
|
//Loop while thread is still running
|
2012-03-23 01:29:50 +01:00
|
|
|
bool bStillRunning = threadStillRunning(thread);
|
|
|
|
while(bStillRunning)
|
2012-02-23 17:00:22 +01:00
|
|
|
{
|
|
|
|
loop->exec();
|
2012-03-23 01:29:50 +01:00
|
|
|
if(bStillRunning = threadStillRunning(thread))
|
2012-02-23 21:21:02 +01:00
|
|
|
{
|
2012-03-23 01:29:50 +01:00
|
|
|
qWarning("Potential deadlock in initialization thread!");
|
2012-02-23 21:21:02 +01:00
|
|
|
}
|
2012-02-23 17:00:22 +01:00
|
|
|
}
|
2012-03-22 22:26:54 +01:00
|
|
|
|
2012-02-23 21:21:02 +01:00
|
|
|
//Stop the timer
|
|
|
|
timer->stop();
|
|
|
|
|
2010-11-06 23:04:47 +01:00
|
|
|
//Fade out
|
2011-11-11 18:08:22 +01:00
|
|
|
for(int i = 100; i >= 0; i--)
|
2010-11-06 23:04:47 +01:00
|
|
|
{
|
2011-11-11 18:08:22 +01:00
|
|
|
opacity = 0.01 * static_cast<double>(i);
|
|
|
|
splashScreen->setWindowOpacity(opacity);
|
2012-03-01 02:45:21 +01:00
|
|
|
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents, FADE_DELAY);
|
2011-11-11 18:08:22 +01:00
|
|
|
Sleep(FADE_DELAY);
|
2010-11-06 23:04:47 +01:00
|
|
|
}
|
|
|
|
|
2011-11-07 17:13:41 +01:00
|
|
|
//Restore taskbar
|
|
|
|
WinSevenTaskbar::setTaskbarState(splashScreen, WinSevenTaskbar::WinSevenTaskbarNoState);
|
|
|
|
|
2010-11-06 23:04:47 +01:00
|
|
|
//Hide splash
|
|
|
|
splashScreen->m_canClose = true;
|
|
|
|
splashScreen->close();
|
|
|
|
|
2011-11-11 18:08:22 +01:00
|
|
|
//Free
|
2011-11-07 17:13:41 +01:00
|
|
|
LAMEXP_DELETE(loop);
|
2012-02-23 21:21:02 +01:00
|
|
|
LAMEXP_DELETE(timer);
|
2010-11-06 23:04:47 +01:00
|
|
|
LAMEXP_DELETE(splashScreen);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// EVENTS
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
void SplashScreen::keyPressEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SplashScreen::keyReleaseEvent(QKeyEvent *event)
|
|
|
|
{
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SplashScreen::closeEvent(QCloseEvent *event)
|
|
|
|
{
|
2011-12-29 14:42:20 +01:00
|
|
|
if(!m_canClose) event->ignore();
|
2010-11-06 23:04:47 +01:00
|
|
|
}
|
2011-11-07 17:13:41 +01:00
|
|
|
|
|
|
|
bool SplashScreen::winEvent(MSG *message, long *result)
|
|
|
|
{
|
|
|
|
return WinSevenTaskbar::handleWinEvent(message, result);
|
|
|
|
}
|
2012-03-23 01:29:50 +01:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
// HELPER FUNCTIONS
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
bool SplashScreen::threadStillRunning(const QThread *thread)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < 128; i++)
|
|
|
|
{
|
|
|
|
if(!(thread->isRunning()))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
QThread::yieldCurrentThread();
|
|
|
|
}
|
|
|
|
|
|
|
|
return thread->isRunning();
|
|
|
|
}
|