Some initial refactoring to allow better handling of multiple input files.
This commit is contained in:
parent
8078a6b90d
commit
aacf84b88a
@ -1221,6 +1221,29 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_14">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>12</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBoxApplyToAll">
|
||||
<property name="text">
|
||||
<string>Apply Configuration To All Files</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
|
@ -22,7 +22,7 @@
|
||||
#define VER_X264_MAJOR 2
|
||||
#define VER_X264_MINOR 1
|
||||
#define VER_X264_PATCH 0
|
||||
#define VER_X264_BUILD 422
|
||||
#define VER_X264_BUILD 435
|
||||
|
||||
#define VER_X264_MINIMUM_REV 2282
|
||||
#define VER_X264_CURRENT_API 132
|
||||
|
@ -222,6 +222,9 @@ AddJobDialog::AddJobDialog(QWidget *parent, OptionsModel *options, bool x64suppo
|
||||
setMinimumSize(size());
|
||||
setMaximumHeight(height());
|
||||
|
||||
//Hide optional controls
|
||||
checkBoxApplyToAll->setVisible(false);
|
||||
|
||||
//Setup file type filter
|
||||
m_types.clear();
|
||||
m_types << tr("Matroska Files (*.mkv)");
|
||||
@ -857,6 +860,7 @@ QString AddJobDialog::makeFileFilter(void)
|
||||
return filters;
|
||||
}
|
||||
|
||||
/*
|
||||
void AddJobDialog::generateOutputFileName(const QString &filePath)
|
||||
{
|
||||
QString name = QFileInfo(filePath).completeBaseName();
|
||||
@ -896,16 +900,110 @@ int AddJobDialog::getFilterIndex(const QString &fileExt)
|
||||
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
|
||||
QString AddJobDialog::getFilterExt(int filterIdx)
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Static functions
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static const char *KEY_FILTER_IDX = "path/filterIndex";
|
||||
static const char *KEY_SOURCE_DIR = "path/directory_openFrom";
|
||||
static const char *KEY_OUTPUT_DIR = "path/directory_saveTo";
|
||||
|
||||
void AddJobDialog::initRecentlyUsed(RecentlyUsed *recentlyUsed)
|
||||
{
|
||||
int index = qBound(0, filterIdx, m_types.count()-1);
|
||||
recentlyUsed->sourceDirectory = QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
|
||||
recentlyUsed->outputDirectory = QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
|
||||
recentlyUsed->filterIndex = 0;
|
||||
}
|
||||
|
||||
QRegExp ext("\\(\\*\\.(.+)\\)");
|
||||
if(ext.lastIndexIn(m_types.at(index)) >= 0)
|
||||
void AddJobDialog::loadRecentlyUsed(RecentlyUsed *recentlyUsed)
|
||||
{
|
||||
RecentlyUsed defaults;
|
||||
initRecentlyUsed(&defaults);
|
||||
|
||||
QSettings settings(QString("%1/last.ini").arg(x264_data_path()), QSettings::IniFormat);
|
||||
recentlyUsed->sourceDirectory = settings.value(KEY_SOURCE_DIR, defaults.sourceDirectory).toString();
|
||||
recentlyUsed->outputDirectory = settings.value(KEY_OUTPUT_DIR, defaults.outputDirectory).toString();
|
||||
recentlyUsed->filterIndex = settings.value(KEY_FILTER_IDX, defaults.filterIndex).toInt();
|
||||
|
||||
if(!VALID_DIR(recentlyUsed->sourceDirectory)) recentlyUsed->sourceDirectory = defaults.sourceDirectory;
|
||||
if(!VALID_DIR(recentlyUsed->outputDirectory)) recentlyUsed->outputDirectory = defaults.outputDirectory;
|
||||
}
|
||||
|
||||
void AddJobDialog::saveRecentlyUsed(RecentlyUsed *recentlyUsed)
|
||||
{
|
||||
QSettings settings(QString("%1/last.ini").arg(x264_data_path()), QSettings::IniFormat);
|
||||
if(settings.isWritable())
|
||||
{
|
||||
return ext.cap(1).toLower();
|
||||
settings.setValue(KEY_SOURCE_DIR, recentlyUsed->sourceDirectory);
|
||||
settings.setValue(KEY_OUTPUT_DIR, recentlyUsed->outputDirectory);
|
||||
settings.setValue(KEY_FILTER_IDX, recentlyUsed->filterIndex);
|
||||
settings.sync();
|
||||
}
|
||||
}
|
||||
|
||||
QString AddJobDialog::generateOutputFileName(const QString &sourceFilePath, const QString &destinationDirectory, const int filterIndex, const bool saveToSourceDir)
|
||||
{
|
||||
QString name = QFileInfo(sourceFilePath).completeBaseName();
|
||||
QString path = saveToSourceDir ? QFileInfo(sourceFilePath).canonicalPath() : destinationDirectory;
|
||||
QString fext = getFilterExt(filterIndex);
|
||||
|
||||
if(!VALID_DIR(path))
|
||||
{
|
||||
RecentlyUsed defaults; initRecentlyUsed(&defaults);
|
||||
path = defaults.outputDirectory;
|
||||
}
|
||||
|
||||
return QString::fromLatin1("mkv");
|
||||
QString outPath = QString("%1/%2.%3").arg(path, name, fext);
|
||||
|
||||
if(QFileInfo(outPath).exists())
|
||||
{
|
||||
int i = 2;
|
||||
while(QFileInfo(outPath).exists())
|
||||
{
|
||||
outPath = QString("%1/%2 (%3).%4").arg(path, name, QString::number(i++), fext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
static const struct
|
||||
{
|
||||
const char *pcExt;
|
||||
const char *pcStr;
|
||||
}
|
||||
FILE_TYPE_FILTERS[] =
|
||||
{
|
||||
{ "mkv", "Matroska Files (*.mkv)" },
|
||||
{ "mp4", "MPEG-4 Part 14 Container (*.mp4)" },
|
||||
{ "264", "H.264 Elementary Stream (*.264)"},
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
QString AddJobDialog::getFilterExt(const int filterIndex)
|
||||
{
|
||||
int count = 0;
|
||||
while((FILE_TYPE_FILTERS[count].pcExt) && (FILE_TYPE_FILTERS[count].pcStr)) count++;
|
||||
|
||||
if((filterIndex >= 0) && (filterIndex < count))
|
||||
{
|
||||
return QString::fromLatin1(FILE_TYPE_FILTERS[filterIndex].pcExt);
|
||||
}
|
||||
|
||||
return QString::fromLatin1(FILE_TYPE_FILTERS[0].pcExt);
|
||||
}
|
||||
|
||||
int AddJobDialog::getFilterIdx(const QString &fileExt)
|
||||
{
|
||||
for(int i = 0; FILE_TYPE_FILTERS[i].pcExt; i++)
|
||||
{
|
||||
if(fileExt.compare(QString::fromLatin1(FILE_TYPE_FILTERS[i].pcExt), Qt::CaseInsensitive) == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
@ -35,6 +35,14 @@ public:
|
||||
AddJobDialog(QWidget *parent, OptionsModel *options, bool x64supported, bool use10BitEncoding, bool saveToSourceFolder);
|
||||
~AddJobDialog(void);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
QString sourceDirectory;
|
||||
QString outputDirectory;
|
||||
int filterIndex;
|
||||
}
|
||||
RecentlyUsed;
|
||||
|
||||
QString sourceFile(void);
|
||||
QString outputFile(void);
|
||||
QString preset(void) { return cbxPreset->itemText(cbxPreset->currentIndex()); }
|
||||
@ -42,22 +50,32 @@ public:
|
||||
QString profile(void) { return cbxProfile->itemText(cbxProfile->currentIndex()); }
|
||||
QString params(void) { return editCustomX264Params->text().simplified(); }
|
||||
bool runImmediately(void) { return checkBoxRun->isChecked(); }
|
||||
bool applyToAll(void) { return checkBoxApplyToAll->isChecked(); }
|
||||
void setRunImmediately(bool run) { checkBoxRun->setChecked(run); }
|
||||
void setSourceFile(const QString &path) { editSource->setText(QDir::toNativeSeparators(path)); }
|
||||
void setOutputFile(const QString &path) { editOutput->setText(QDir::toNativeSeparators(path)); }
|
||||
void setSourceEditable(const bool editable) { buttonBrowseSource->setEnabled(editable); }
|
||||
void setApplyToAllVisible(const bool visible) { checkBoxApplyToAll->setVisible(visible); }
|
||||
|
||||
static void initRecentlyUsed(RecentlyUsed *recentlyUsed);
|
||||
static void loadRecentlyUsed(RecentlyUsed *recentlyUsed);
|
||||
static void saveRecentlyUsed(RecentlyUsed *recentlyUsed);
|
||||
|
||||
static QString generateOutputFileName(const QString &sourceFilePath, const QString &destinationDirectory, const int filterIndex, const bool saveToSourceDir);
|
||||
static int getFilterIdx(const QString &fileExt);
|
||||
static QString getFilterExt(const int filterIndex);
|
||||
|
||||
protected:
|
||||
OptionsModel *m_options;
|
||||
OptionsModel *m_defaults;
|
||||
|
||||
RecentlyUsed *m_recentlyUsed;
|
||||
|
||||
const bool m_x64supported;
|
||||
const bool m_use10BitEncoding;
|
||||
const bool m_saveToSourceFolder;
|
||||
|
||||
QStringList m_types;
|
||||
QString m_initialDir_src;
|
||||
QString m_initialDir_out;
|
||||
int m_lastFilterIndex;
|
||||
|
||||
virtual void showEvent(QShowEvent *event);
|
||||
virtual bool eventFilter(QObject *o, QEvent *e);
|
||||
@ -84,6 +102,4 @@ private:
|
||||
void updateComboBox(QComboBox *cbox, const QString &text);
|
||||
QString makeFileFilter(void);
|
||||
void generateOutputFileName(const QString &filePath);
|
||||
int getFilterIndex(const QString &fileExt);
|
||||
QString getFilterExt(int filterIdx);
|
||||
};
|
||||
|
183
src/win_main.cpp
183
src/win_main.cpp
@ -41,6 +41,7 @@
|
||||
#include <QProgressDialog>
|
||||
#include <QScrollBar>
|
||||
#include <QTextStream>
|
||||
#include <QSettings>
|
||||
|
||||
#include <Mmsystem.h>
|
||||
|
||||
@ -207,52 +208,16 @@ MainWindow::~MainWindow(void)
|
||||
/*
|
||||
* The "add" button was clicked
|
||||
*/
|
||||
void MainWindow::addButtonPressed(const QString &filePathIn, const QString &filePathOut, OptionsModel *options, int fileNo, int fileTotal, bool *ok)
|
||||
void MainWindow::addButtonPressed()
|
||||
{
|
||||
qDebug("MainWindow::addButtonPressed");
|
||||
bool runImmediately = (countRunningJobs() < (m_preferences.autoRunNextJob ? m_preferences.maxRunningJobCount : 1));
|
||||
QString sourceFileName, outputFileName;
|
||||
|
||||
if(ok) *ok = false;
|
||||
|
||||
AddJobDialog *addDialog = new AddJobDialog(this, options ? options : m_options, m_cpuFeatures->x64, m_preferences.use10BitEncoding, m_preferences.saveToSourcePath);
|
||||
addDialog->setRunImmediately(countRunningJobs() < (m_preferences.autoRunNextJob ? m_preferences.maxRunningJobCount : 1));
|
||||
|
||||
if(options) addDialog->setWindowTitle(tr("Restart Job"));
|
||||
if((fileNo >= 0) && (fileTotal > 1)) addDialog->setWindowTitle(addDialog->windowTitle().append(tr(" (File %1 of %2)").arg(QString::number(fileNo+1), QString::number(fileTotal))));
|
||||
if(!filePathIn.isEmpty()) addDialog->setSourceFile(filePathIn);
|
||||
if(!filePathOut.isEmpty()) addDialog->setOutputFile(filePathOut);
|
||||
|
||||
int result = addDialog->exec();
|
||||
if(result == QDialog::Accepted)
|
||||
if(createJob(sourceFileName, outputFileName, m_options, runImmediately))
|
||||
{
|
||||
EncodeThread *thrd = new EncodeThread
|
||||
(
|
||||
addDialog->sourceFile(),
|
||||
addDialog->outputFile(),
|
||||
options ? options : m_options,
|
||||
QString("%1/toolset").arg(m_appDir),
|
||||
m_cpuFeatures->x64,
|
||||
m_preferences.use10BitEncoding,
|
||||
m_cpuFeatures->x64 && m_preferences.useAvisyth64Bit
|
||||
);
|
||||
|
||||
QModelIndex newIndex = m_jobList->insertJob(thrd);
|
||||
|
||||
if(newIndex.isValid())
|
||||
{
|
||||
if(addDialog->runImmediately())
|
||||
{
|
||||
jobsView->selectRow(newIndex.row());
|
||||
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
m_jobList->startJob(newIndex);
|
||||
appendJob(sourceFileName, outputFileName, m_options, runImmediately);
|
||||
}
|
||||
|
||||
if(ok) *ok = true;
|
||||
}
|
||||
|
||||
m_label->setVisible(m_jobList->rowCount(QModelIndex()) == 0);
|
||||
}
|
||||
|
||||
X264_DELETE(addDialog);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -317,15 +282,18 @@ void MainWindow::pauseButtonPressed(bool checked)
|
||||
void MainWindow::restartButtonPressed(void)
|
||||
{
|
||||
const QModelIndex index = jobsView->currentIndex();
|
||||
|
||||
const QString &source = m_jobList->getJobSourceFile(index);
|
||||
const QString &output = m_jobList->getJobOutputFile(index);
|
||||
const OptionsModel *options = m_jobList->getJobOptions(index);
|
||||
QString sourceFileName = m_jobList->getJobSourceFile(index);
|
||||
QString outputFileName = m_jobList->getJobOutputFile(index);
|
||||
|
||||
if((options) && (!source.isEmpty()) && (!output.isEmpty()))
|
||||
if((options) && (!sourceFileName.isEmpty()) && (!outputFileName.isEmpty()))
|
||||
{
|
||||
bool runImmediately = true;
|
||||
OptionsModel *tempOptions = new OptionsModel(*options);
|
||||
addButtonPressed(source, output, tempOptions);
|
||||
if(createJob(sourceFileName, outputFileName, tempOptions, runImmediately, true))
|
||||
{
|
||||
appendJob(sourceFileName, outputFileName, tempOptions, runImmediately);
|
||||
}
|
||||
X264_DELETE(tempOptions);
|
||||
}
|
||||
}
|
||||
@ -822,7 +790,8 @@ void MainWindow::init(void)
|
||||
{
|
||||
QString currentFile = files.takeFirst();
|
||||
qDebug("Adding file: %s", currentFile.toUtf8().constData());
|
||||
addButtonPressed(currentFile, QString(), NULL, n++, totalFiles, &ok);
|
||||
/*TODO: Add multiple files!*/
|
||||
//ok = createJob(currentFile, QString(), NULL, n++, totalFiles);
|
||||
}
|
||||
}
|
||||
|
||||
@ -863,14 +832,17 @@ void MainWindow::handleDroppedFiles(void)
|
||||
{
|
||||
QStringList droppedFiles(*m_droppedFiles);
|
||||
m_droppedFiles->clear();
|
||||
/*
|
||||
int totalFiles = droppedFiles.count();
|
||||
bool ok = true; int n = 0;
|
||||
while((!droppedFiles.isEmpty()) && ok)
|
||||
{
|
||||
QString currentFile = droppedFiles.takeFirst();
|
||||
qDebug("Adding file: %s", currentFile.toUtf8().constData());
|
||||
addButtonPressed(currentFile, QString(), NULL, n++, totalFiles, &ok);
|
||||
ok = createJob(currentFile, QString(), NULL, n++, totalFiles);
|
||||
}
|
||||
*/
|
||||
//createJobMultiple(droppedFiles);
|
||||
}
|
||||
qDebug("Leave from MainWindow::handleDroppedFiles!");
|
||||
}
|
||||
@ -1032,6 +1004,121 @@ void MainWindow::dropEvent(QDropEvent *event)
|
||||
// Private functions
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/*
|
||||
* Creates a new job
|
||||
*/
|
||||
bool MainWindow::createJob(QString &sourceFileName, QString &outputFileName, OptionsModel *options, bool &runImmediately, const bool restart, int fileNo, int fileTotal, bool *applyToAll)
|
||||
{
|
||||
bool okay = false;
|
||||
AddJobDialog *addDialog = new AddJobDialog(this, options, m_cpuFeatures->x64, m_preferences.use10BitEncoding, m_preferences.saveToSourcePath);
|
||||
|
||||
addDialog->setRunImmediately(runImmediately);
|
||||
if(!sourceFileName.isEmpty()) addDialog->setSourceFile(sourceFileName);
|
||||
if(!outputFileName.isEmpty()) addDialog->setOutputFile(outputFileName);
|
||||
if(restart) addDialog->setWindowTitle(tr("Restart Job"));
|
||||
|
||||
const bool multiFile = (fileNo >= 0) && (fileTotal > 1);
|
||||
if(multiFile)
|
||||
{
|
||||
addDialog->setSourceEditable(false);
|
||||
addDialog->setWindowTitle(addDialog->windowTitle().append(tr(" (File %1 of %2)").arg(QString::number(fileNo+1), QString::number(fileTotal))));
|
||||
addDialog->setApplyToAllVisible(applyToAll);
|
||||
}
|
||||
|
||||
if(addDialog->exec() == QDialog::Accepted)
|
||||
{
|
||||
sourceFileName = addDialog->sourceFile();
|
||||
outputFileName = addDialog->outputFile();
|
||||
runImmediately = addDialog->runImmediately();
|
||||
if(applyToAll)
|
||||
{
|
||||
*applyToAll = addDialog->applyToAll();
|
||||
}
|
||||
okay = true;
|
||||
}
|
||||
|
||||
X264_DELETE(addDialog);
|
||||
return okay;
|
||||
}
|
||||
|
||||
/*
|
||||
* Append a new job
|
||||
*/
|
||||
bool MainWindow::appendJob(const QString &sourceFileName, const QString &outputFileName, OptionsModel *options, const bool runImmediately)
|
||||
{
|
||||
bool okay = false;
|
||||
|
||||
EncodeThread *thrd = new EncodeThread
|
||||
(
|
||||
sourceFileName,
|
||||
outputFileName,
|
||||
options,
|
||||
QString("%1/toolset").arg(m_appDir),
|
||||
m_cpuFeatures->x64,
|
||||
m_preferences.use10BitEncoding,
|
||||
m_cpuFeatures->x64 && m_preferences.useAvisyth64Bit
|
||||
);
|
||||
|
||||
QModelIndex newIndex = m_jobList->insertJob(thrd);
|
||||
|
||||
if(newIndex.isValid())
|
||||
{
|
||||
if(runImmediately)
|
||||
{
|
||||
jobsView->selectRow(newIndex.row());
|
||||
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
|
||||
m_jobList->startJob(newIndex);
|
||||
}
|
||||
|
||||
okay = true;
|
||||
}
|
||||
|
||||
m_label->setVisible(m_jobList->rowCount(QModelIndex()) == 0);
|
||||
return okay;
|
||||
}
|
||||
|
||||
/*
|
||||
* Creates a new job
|
||||
*/
|
||||
bool MainWindow::createJobMultiple(const QStringList &filePathIn)
|
||||
{
|
||||
//bool ok = true, force = false; int counter = 0;
|
||||
//
|
||||
////Add files
|
||||
//QStringList::ConstIterator iter = filePathIn.constBegin();
|
||||
//while(ok && (!force) && (iter != filePathIn.constEnd()))
|
||||
//{
|
||||
// ok = createJob(*iter, QString(), NULL, ++counter, filePathIn.count(), &force);
|
||||
// iter++;
|
||||
//}
|
||||
|
||||
//if(force) qWarning("Force mode!");
|
||||
|
||||
////Add remaining files
|
||||
//if(force && (iter != filePathIn.constEnd()))
|
||||
//{
|
||||
// QSettings settings(QString("%1/last.ini").arg(x264_data_path()), QSettings::IniFormat);
|
||||
// QString outDirectory = settings.value("path/directory_saveTo", QDesktopServices::storageLocation(QDesktopServices::MoviesLocation)).toString();
|
||||
//
|
||||
// while(iter != filePathIn.constEnd())
|
||||
// {
|
||||
// int n = 2;
|
||||
// QString outBaseName = QFileInfo(*iter).completeBaseName();
|
||||
// QString outPath = QString("%1/%2.mkv").arg(outDirectory, outBaseName);
|
||||
// while(QFileInfo(outPath).exists())
|
||||
// {
|
||||
// outPath = QString("%1/%2 (%3).mkv").arg(outDirectory, outBaseName, QString::number(n++));
|
||||
// }
|
||||
// ok = createJob(*iter, outPath, NULL, ++counter, filePathIn.count(), &force);
|
||||
// iter++;
|
||||
// }
|
||||
//}
|
||||
|
||||
//return ok;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Jobs that are not completed (or failed, or aborted) yet
|
||||
*/
|
||||
|
@ -64,13 +64,17 @@ private:
|
||||
const x264_cpu_t *const m_cpuFeatures;
|
||||
const QString m_appDir;
|
||||
|
||||
bool createJob(QString &sourceFileName, QString &outputFileName, OptionsModel *options, bool &runImmediately, const bool restart = false, int fileNo = -1, int fileTotal = 0, bool *applyToAll = NULL);
|
||||
bool createJobMultiple(const QStringList &filePathIn);
|
||||
|
||||
bool appendJob(const QString &sourceFileName, const QString &outputFileName, OptionsModel *options, const bool runImmediately);
|
||||
void updateButtons(EncodeThread::JobStatus status);
|
||||
void updateTaskbar(EncodeThread::JobStatus status, const QIcon &icon);
|
||||
unsigned int countPendingJobs(void);
|
||||
unsigned int countRunningJobs(void);
|
||||
|
||||
private slots:
|
||||
void addButtonPressed(const QString &filePathIn = QString(), const QString &filePathOut = QString(), OptionsModel *options = NULL, int fileNo = -1, int fileTotal = 0, bool *ok = NULL);
|
||||
void addButtonPressed();
|
||||
void abortButtonPressed(void);
|
||||
void browseButtonPressed(void);
|
||||
void deleteButtonPressed(void);
|
||||
|
Loading…
Reference in New Issue
Block a user