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->selectionModel()->setCurrentIndex(newIndex, QItemSelectionModel::ClearAndSelect);
92 void MainWindow::startButtonPressed(void)
94 m_jobList->startJob(jobsView->currentIndex());
97 void MainWindow::abortButtonPressed(void)
99 m_jobList->abortJob(jobsView->currentIndex());
101 void MainWindow::jobSelected(const QModelIndex & current, const QModelIndex & previous)
103 qDebug("Job selected: %d", current.row());
107 disconnect(logView->model(), SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(jobLogExtended(QModelIndex, int, int)));
110 logView->setModel(m_jobList->getLogFile(current));
111 connect(logView->model(), SIGNAL(rowsInserted(QModelIndex, int, int)), this, SLOT(jobLogExtended(QModelIndex, int, int)));
112 QTimer::singleShot(0, logView, SLOT(scrollToBottom()));
114 progressBar->setValue(m_jobList->getJobProgress(current));
115 editDetails->setText(m_jobList->data(m_jobList->index(current.row(), 3, QModelIndex()), Qt::DisplayRole).toString());
116 updateButtons(m_jobList->getJobStatus(current));
119 void MainWindow::jobChangedData(const QModelIndex &topLeft, const QModelIndex &bottomRight)
121 int selected = jobsView->currentIndex().row();
123 if(topLeft.column() <= 1 && bottomRight.column() >= 1)
125 for(int i = topLeft.row(); i <= bottomRight.row(); i++)
129 qDebug("Current job changed status!");
130 updateButtons(m_jobList->getJobStatus(m_jobList->index(i, 0, QModelIndex())));
135 else if(topLeft.column() <= 2 && bottomRight.column() >= 2)
137 for(int i = topLeft.row(); i <= bottomRight.row(); i++)
141 progressBar->setValue(m_jobList->getJobProgress(m_jobList->index(i, 0, QModelIndex())));
146 else if(topLeft.column() <= 3 && bottomRight.column() >= 3)
148 for(int i = topLeft.row(); i <= bottomRight.row(); i++)
152 editDetails->setText(m_jobList->data(m_jobList->index(i, 3, QModelIndex()), Qt::DisplayRole).toString());
159 void MainWindow::jobLogExtended(const QModelIndex & parent, int start, int end)
161 QTimer::singleShot(0, logView, SLOT(scrollToBottom()));
164 void MainWindow::showAbout(void)
167 const char *url = "http://mulder.brhack.net/";
169 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());
170 text += QString().sprintf("Copyright (c) 2004−%04d LoRd_MuldeR <mulder2@gmx.de>. Some rights reserved.<br>", qMax(x264_version_date().year(),QDate::currentDate().year()));
171 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());
172 text += QString().sprintf("This program is free software: you can redistribute it and/or modify<br>");
173 text += QString().sprintf("it under the terms of the GNU General Public License <http://www.gnu.org/>.<br>");
174 text += QString().sprintf("Note that this program is distributed with ABSOLUTELY NO WARRANTY.<br><br>");
175 text += QString().sprintf("Please check the web−site at <a href=\"%s\">%s</a> for updates !!!<br></tt></nobr>", url, url);
177 QMessageBox::information(this, tr("About..."), text);
180 ///////////////////////////////////////////////////////////////////////////////
182 ///////////////////////////////////////////////////////////////////////////////
184 void MainWindow::closeEvent(QCloseEvent *e)
186 const int rows = m_jobList->rowCount(QModelIndex());
188 for(int i = 0; i < rows; i++)
190 EncodeThread::JobStatus status = m_jobList->getJobStatus(m_jobList->index(i, 0, QModelIndex()));
191 if(status != EncodeThread::JobStatus_Completed && status != EncodeThread::JobStatus_Aborted && status != EncodeThread::JobStatus_Failed)
194 MessageBeep(MB_ICONWARNING);
200 ///////////////////////////////////////////////////////////////////////////////
202 ///////////////////////////////////////////////////////////////////////////////
204 void MainWindow::updateButtons(EncodeThread::JobStatus status)
206 qDebug("MainWindow::updateButtons(void)");
208 buttonStartJob->setEnabled(status == EncodeThread::JobStatus_Enqueued);
209 buttonAbortJob->setEnabled(status == EncodeThread::JobStatus_Indexing || status == EncodeThread::JobStatus_Running);