/////////////////////////////////////////////////////////////////////////////// // LameXP - Audio Encoder Front-End // Copyright (C) 2004-2010 LoRd_MuldeR // // 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_Processing.h" #include "Global.h" #include "Model_Progress.h" #include "Thread_Process.h" #include #include #include #include #include #include #include #include #include #include //////////////////////////////////////////////////////////// // Constructor //////////////////////////////////////////////////////////// ProcessingDialog::ProcessingDialog(void) { //Init the dialog, from the .ui file setupUi(this); setWindowFlags(windowFlags() ^ Qt::WindowContextHelpButtonHint); label_versionInfo->setText(QString().sprintf("v%d.%02d %s (Build %d)", lamexp_version_major(), lamexp_version_minor(), lamexp_version_release(), lamexp_version_build())); label_versionInfo->installEventFilter(this); //Center window in screen QRect desktopRect = QApplication::desktop()->screenGeometry(); QRect thisRect = this->geometry(); move((desktopRect.width() - thisRect.width()) / 2, (desktopRect.height() - thisRect.height()) / 2); setMinimumSize(thisRect.width(), thisRect.height()); //Enable buttons connect(button_AbortProcess, SIGNAL(clicked()), this, SLOT(abortEncoding())); //Init progress indicator m_progressIndicator = new QMovie(":/images/Working.gif"); label_headerWorking->setMovie(m_progressIndicator); progressBar->setRange(0, 4); progressBar->setValue(0); //Init progress model m_progressModel = new ProgressModel(); view_log->setModel(m_progressModel); view_log->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); view_log->verticalHeader()->hide(); view_log->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); view_log->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); //Init member vars for(int i = 0; i < 4; i++) m_thread[i] = NULL; } //////////////////////////////////////////////////////////// // Destructor //////////////////////////////////////////////////////////// ProcessingDialog::~ProcessingDialog(void) { view_log->setModel(NULL); if(m_progressIndicator) m_progressIndicator->stop(); LAMEXP_DELETE(m_progressIndicator); LAMEXP_DELETE(m_progressModel); } //////////////////////////////////////////////////////////// // EVENTS //////////////////////////////////////////////////////////// void ProcessingDialog::showEvent(QShowEvent *event) { setCloseButtonEnabled(false); button_closeDialog->setEnabled(false); button_AbortProcess->setEnabled(false); QTimer::singleShot(1000, this, SLOT(initEncoding())); } void ProcessingDialog::closeEvent(QCloseEvent *event) { if(!button_closeDialog->isEnabled() || m_thread) event->ignore(); } bool ProcessingDialog::eventFilter(QObject *obj, QEvent *event) { static QColor defaultColor = QColor(); if(obj == label_versionInfo) { if(event->type() == QEvent::Enter) { QPalette palette = label_versionInfo->palette(); defaultColor = palette.color(QPalette::Normal, QPalette::WindowText); palette.setColor(QPalette::Normal, QPalette::WindowText, Qt::red); label_versionInfo->setPalette(palette); } else if(event->type() == QEvent::Leave) { QPalette palette = label_versionInfo->palette(); palette.setColor(QPalette::Normal, QPalette::WindowText, defaultColor); label_versionInfo->setPalette(palette); } else if(event->type() == QEvent::MouseButtonPress) { QUrl url("http://mulder.dummwiedeutsch.de/"); QDesktopServices::openUrl(url); } } return false; } //////////////////////////////////////////////////////////// // SLOTS //////////////////////////////////////////////////////////// void ProcessingDialog::initEncoding(void) { label_progress->setText("Encoding files, please wait..."); m_progressIndicator->start(); m_pendingJobs = 4; for(int i = 0; i < 4; i++) { m_thread[i] = new ProcessThread(); connect(m_thread[i], SIGNAL(finished()), this, SLOT(doneEncoding()), Qt::QueuedConnection); connect(m_thread[i], SIGNAL(processStateInitialized(QString,QString,QString,int)), m_progressModel, SLOT(addJob(QString,QString,QString,int)), Qt::QueuedConnection); connect(m_thread[i], SIGNAL(processStateChanged(QString,QString,int)), m_progressModel, SLOT(updateJob(QString,QString,int)), Qt::QueuedConnection); m_thread[i]->start(); } button_closeDialog->setEnabled(false); button_AbortProcess->setEnabled(true); } void ProcessingDialog::abortEncoding(void) { button_AbortProcess->setEnabled(false); for(int i = 0; i < 4; i++) { if(m_thread[i]) { m_thread[i]->abort(); } } } void ProcessingDialog::doneEncoding(void) { progressBar->setValue(progressBar->value() + 1); if(--m_pendingJobs > 0) { return; } label_progress->setText("Completed."); m_progressIndicator->stop(); setCloseButtonEnabled(true); button_closeDialog->setEnabled(true); button_AbortProcess->setEnabled(false); for(int i = 0; i < 4; i++) { if(m_thread[i]) { m_thread[i]->terminate(); m_thread[i]->wait(); LAMEXP_DELETE(m_thread[i]); } } progressBar->setValue(100); } //////////////////////////////////////////////////////////// // Private Functions //////////////////////////////////////////////////////////// void ProcessingDialog::setCloseButtonEnabled(bool enabled) { HMENU hMenu = GetSystemMenu((HWND) winId(), FALSE); EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_GRAYED)); }