1 ///////////////////////////////////////////////////////////////////////////////
2 // Simple x264 Launcher
3 // Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
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.
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 ///////////////////////////////////////////////////////////////////////////////
25 #include "model_jobList.h"
29 #include <QCloseEvent>
30 #include <QMessageBox>
32 ///////////////////////////////////////////////////////////////////////////////
33 // Constructor & Destructor
34 ///////////////////////////////////////////////////////////////////////////////
36 MainWindow::MainWindow(void)
38 //Init the dialog, from the .ui file
40 setWindowFlags(windowFlags() ^ Qt::WindowMaximizeButtonHint);
43 qRegisterMetaType<QUuid>("QUuid");
44 qRegisterMetaType<EncodeThread::JobStatus>("EncodeThread::JobStatus");
47 setMinimumSize(size());
50 setWindowTitle(QString("%1 [%2]").arg(windowTitle(), x264_version_date().toString(Qt::ISODate)));
53 m_jobList = new JobListModel();
54 connect(m_jobList, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(jobChangedData(QModelIndex, QModelIndex)));
55 jobsView->setModel(m_jobList);
58 jobsView->horizontalHeader()->setSectionHidden(3, true);
59 jobsView->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
60 jobsView->horizontalHeader()->setResizeMode(1, QHeaderView::Fixed);
61 jobsView->horizontalHeader()->setResizeMode(2, QHeaderView::Fixed);
62 jobsView->horizontalHeader()->resizeSection(1, 150);
63 jobsView->horizontalHeader()->resizeSection(2, 90);
64 jobsView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
65 connect(jobsView->selectionModel(), SIGNAL(currentChanged(QModelIndex, QModelIndex)), this, SLOT(jobSelected(QModelIndex, QModelIndex)));
68 connect(buttonAddJob, SIGNAL(clicked()), this, SLOT(addButtonPressed()));
69 connect(buttonStartJob, SIGNAL(clicked()), this, SLOT(startButtonPressed()));
70 connect(buttonAbortJob, SIGNAL(clicked()), this, SLOT(abortButtonPressed()));
73 connect(actionAbout, SIGNAL(triggered()), this, SLOT(showAbout()));
76 MainWindow::~MainWindow(void)
78 X264_DELETE(m_jobList);
81 ///////////////////////////////////////////////////////////////////////////////
83 ///////////////////////////////////////////////////////////////////////////////
85 void MainWindow::addButtonPressed(void)
87 EncodeThread *thrd = new EncodeThread();
88 QModelIndex newIndex = m_jobList->insertJob(thrd);
89 jobsView->selectRow(newIndex.row());
92 void MainWindow::startButtonPressed(void)
94 m_jobList->startJob(jobsView->currentIndex());
97 void MainWindow::abortButtonPressed(void)
99 m_jobList->abortJob(jobsView->currentIndex());
102 void MainWindow::jobSelected(const QModelIndex & current, const QModelIndex & previous)
104 qDebug("Job selected: %d", current.row());
108 disconnect(logView->model(), SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(jobLogExtended(QModelIndex, int, int)));
111 logView->setModel(m_jobList->getLogFile(current));
112 connect(logView->model(), SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(jobLogExtended(QModelIndex, int, int)));
113 QTimer::singleShot(0, logView, SLOT(scrollToBottom()));
115 progressBar->setValue(m_jobList->getJobProgress(current));
116 editDetails->setText(m_jobList->data(m_jobList->index(current.row(), 3, QModelIndex()), Qt::DisplayRole).toString());
117 updateButtons(m_jobList->getJobStatus(current));
120 void MainWindow::jobChangedData(const QModelIndex &topLeft, const QModelIndex &bottomRight)
122 int selected = jobsView->currentIndex().row();
124 if(topLeft.column() <= 1 && bottomRight.column() >= 1)
126 for(int i = topLeft.row(); i <= bottomRight.row(); i++)
128 EncodeThread::JobStatus status = m_jobList->getJobStatus(m_jobList->index(i, 0, QModelIndex()));
131 qDebug("Current job changed status!");
132 updateButtons(status);
134 if(status == EncodeThread::JobStatus_Completed)
136 QTimer::singleShot(0, this, SLOT(launchNextJob()));
140 else if(topLeft.column() <= 2 && bottomRight.column() >= 2)
142 for(int i = topLeft.row(); i <= bottomRight.row(); i++)
146 progressBar->setValue(m_jobList->getJobProgress(m_jobList->index(i, 0, QModelIndex())));
151 else if(topLeft.column() <= 3 && bottomRight.column() >= 3)
153 for(int i = topLeft.row(); i <= bottomRight.row(); i++)
157 editDetails->setText(m_jobList->data(m_jobList->index(i, 3, QModelIndex()), Qt::DisplayRole).toString());
164 void MainWindow::jobLogExtended(const QModelIndex & parent, int start, int end)
166 QTimer::singleShot(0, logView, SLOT(scrollToBottom()));
169 void MainWindow::showAbout(void)
172 const char *url = "http://mulder.brhack.net/";
174 text += QString().sprintf("<nobr><tt>Simple x264 Launcher v%u.%02u - use 64-Bit x264 with 32-Bit Avisynth<br>", x264_version_major(), x264_version_minor());
175 text += QString().sprintf("Copyright (c) 2004-%04d LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.<br>", qMax(x264_version_date().year(),QDate::currentDate().year()));
176 text += QString().sprintf("Built on %s at %s with %s for Win-%s.<br><br>", x264_version_date().toString(Qt::ISODate).toLatin1().constData(), x264_version_time(), x264_version_compiler(), x264_version_arch());
177 text += QString().sprintf("This program is free software: you can redistribute it and/or modify<br>");
178 text += QString().sprintf("it under the terms of the GNU General Public License <http://www.gnu.org/>.<br>");
179 text += QString().sprintf("Note that this program is distributed with ABSOLUTELY NO WARRANTY.<br><br>");
180 text += QString().sprintf("Please check the web-site at <a href=\"%s\">%s</a> for updates !!!<br></tt></nobr>", url, url);
182 QMessageBox::information(this, tr("About..."), text.replace("-", "−"));
185 void MainWindow::launchNextJob(void)
187 const int rows = m_jobList->rowCount(QModelIndex());
189 for(int i = 0; i < rows; i++)
191 EncodeThread::JobStatus status = m_jobList->getJobStatus(m_jobList->index(i, 0, QModelIndex()));
192 if(status == EncodeThread::JobStatus_Running || status == EncodeThread::JobStatus_Running_Pass1 || status == EncodeThread::JobStatus_Running_Pass2)
194 qWarning("Still have a job running, won't launch next yet!");
199 for(int i = 0; i < rows; i++)
201 EncodeThread::JobStatus status = m_jobList->getJobStatus(m_jobList->index(i, 0, QModelIndex()));
202 if(status == EncodeThread::JobStatus_Enqueued)
204 m_jobList->startJob(m_jobList->index(i, 0, QModelIndex()));
209 qWarning("No enqueued jobs left!");
212 ///////////////////////////////////////////////////////////////////////////////
214 ///////////////////////////////////////////////////////////////////////////////
216 void MainWindow::closeEvent(QCloseEvent *e)
218 const int rows = m_jobList->rowCount(QModelIndex());
220 for(int i = 0; i < rows; i++)
222 EncodeThread::JobStatus status = m_jobList->getJobStatus(m_jobList->index(i, 0, QModelIndex()));
223 if(status != EncodeThread::JobStatus_Completed && status != EncodeThread::JobStatus_Aborted && status != EncodeThread::JobStatus_Failed)
226 MessageBeep(MB_ICONWARNING);
232 ///////////////////////////////////////////////////////////////////////////////
234 ///////////////////////////////////////////////////////////////////////////////
236 void MainWindow::updateButtons(EncodeThread::JobStatus status)
238 qDebug("MainWindow::updateButtons(void)");
240 buttonStartJob->setEnabled(status == EncodeThread::JobStatus_Enqueued);
241 buttonAbortJob->setEnabled(status == EncodeThread::JobStatus_Indexing || status == EncodeThread::JobStatus_Running ||
242 status == EncodeThread::JobStatus_Running_Pass1 || status == EncodeThread::JobStatus_Running_Pass2 );