Code refactoring: Now "Preferences" and "Recently" used models are in separate classes for a more cleaner design.

This commit is contained in:
LoRd_MuldeR 2013-07-03 21:34:21 +02:00
parent 43e1146263
commit a74f27ab5b
18 changed files with 439 additions and 245 deletions

View File

@ -310,6 +310,11 @@ Please be aware that this option does NOT have any effect on 32-Bit systems.</st
<property name="frame"> <property name="frame">
<bool>true</bool> <bool>true</bool>
</property> </property>
<item>
<property name="text">
<string>Above Normal</string>
</property>
</item>
<item> <item>
<property name="text"> <property name="text">
<string>Normal</string> <string>Normal</string>

View File

@ -23,6 +23,7 @@
#include "model_jobList.h" #include "model_jobList.h"
#include "thread_encode.h" #include "thread_encode.h"
#include "model_options.h" #include "model_options.h"
#include "model_preferences.h"
#include "resource.h" #include "resource.h"
#include <QIcon> #include <QIcon>
@ -30,7 +31,7 @@
#include <Mmsystem.h> #include <Mmsystem.h>
JobListModel::JobListModel(PreferencesDialog::Preferences *preferences) JobListModel::JobListModel(PreferencesModel *preferences)
{ {
m_preferences = preferences; m_preferences = preferences;
} }
@ -487,7 +488,7 @@ void JobListModel::updateStatus(const QUuid &jobId, EncodeThread::JobStatus newS
m_status.insert(jobId, newStatus); m_status.insert(jobId, newStatus);
emit dataChanged(createIndex(index, 0), createIndex(index, 1)); emit dataChanged(createIndex(index, 0), createIndex(index, 1));
if(m_preferences->enableSounds) if(m_preferences->enableSounds())
{ {
switch(newStatus) switch(newStatus)
{ {

View File

@ -23,19 +23,20 @@
#include "thread_encode.h" #include "thread_encode.h"
#include "model_logFile.h" #include "model_logFile.h"
#include "win_preferences.h"
#include "QAbstractItemModel" #include "QAbstractItemModel"
#include <QUuid> #include <QUuid>
#include <QList> #include <QList>
#include <QMap> #include <QMap>
class PreferencesModel;
class JobListModel : public QAbstractItemModel class JobListModel : public QAbstractItemModel
{ {
Q_OBJECT Q_OBJECT
public: public:
JobListModel(PreferencesDialog::Preferences *preferences); JobListModel(PreferencesModel *preferences);
~JobListModel(void); ~JobListModel(void);
virtual int columnCount(const QModelIndex &parent) const; virtual int columnCount(const QModelIndex &parent) const;
@ -67,7 +68,7 @@ protected:
QMap<QUuid, unsigned int> m_progress; QMap<QUuid, unsigned int> m_progress;
QMap<QUuid, LogFileModel*> m_logFile; QMap<QUuid, LogFileModel*> m_logFile;
QMap<QUuid, QString> m_details; QMap<QUuid, QString> m_details;
PreferencesDialog::Preferences *m_preferences; PreferencesModel *m_preferences;
public slots: public slots:
void updateStatus(const QUuid &jobId, EncodeThread::JobStatus newStatus); void updateStatus(const QUuid &jobId, EncodeThread::JobStatus newStatus);

88
src/model_preferences.cpp Normal file
View File

@ -0,0 +1,88 @@
///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
// Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
//
// 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 "model_preferences.h"
#include "global.h"
#include <cstring>
#include <QSettings>
#include <QDesktopServices>
#include <QMouseEvent>
#include <QMessageBox>
PreferencesModel::PreferencesModel(void)
{
initPreferences(this);
}
void PreferencesModel::initPreferences(PreferencesModel *preferences)
{
memset(preferences, 0, sizeof(PreferencesModel));
preferences->m_autoRunNextJob = true;
preferences->m_maxRunningJobCount = 1;
preferences->m_shutdownComputer = false;
preferences->m_use10BitEncoding = false;
preferences->m_useAvisyth64Bit = false;
preferences->m_saveLogFiles = false;
preferences->m_saveToSourcePath = false;
preferences->m_processPriority = X264_PRIORITY_BELOWNORMAL;
preferences->m_enableSounds = false;
}
void PreferencesModel::loadPreferences(PreferencesModel *preferences)
{
const QString appDir = x264_data_path();
QSettings settings(QString("%1/preferences.ini").arg(appDir), QSettings::IniFormat);
PreferencesModel defaults;
settings.beginGroup("preferences");
preferences->m_autoRunNextJob = settings.value("auto_run_next_job", QVariant(defaults.m_autoRunNextJob)).toBool();
preferences->m_maxRunningJobCount = qBound(1U, settings.value("max_running_job_count", QVariant(defaults.m_maxRunningJobCount)).toUInt(), 16U);
preferences->m_shutdownComputer = settings.value("shutdown_computer_on_completion", QVariant(defaults.m_shutdownComputer)).toBool();
preferences->m_use10BitEncoding = settings.value("use_10bit_encoding", QVariant(defaults.m_use10BitEncoding)).toBool();
preferences->m_useAvisyth64Bit = settings.value("use_64bit_avisynth", QVariant(defaults.m_useAvisyth64Bit)).toBool();
preferences->m_saveLogFiles = settings.value("save_log_files", QVariant(defaults.m_saveLogFiles)).toBool();
preferences->m_saveToSourcePath = settings.value("save_to_source_path", QVariant(defaults.m_saveToSourcePath)).toBool();
preferences->m_processPriority = settings.value("process_priority", QVariant(defaults.m_processPriority)).toInt();
preferences->m_enableSounds = settings.value("enable_sounds", QVariant(defaults.m_enableSounds)).toBool();
}
void PreferencesModel::savePreferences(PreferencesModel *preferences)
{
const QString appDir = x264_data_path();
QSettings settings(QString("%1/preferences.ini").arg(appDir), QSettings::IniFormat);
settings.beginGroup("preferences");
settings.setValue("auto_run_next_job", preferences->m_autoRunNextJob);
settings.setValue("shutdown_computer_on_completion", preferences->m_shutdownComputer);
settings.setValue("max_running_job_count", preferences->m_maxRunningJobCount);
settings.setValue("use_10bit_encoding", preferences->m_use10BitEncoding);
settings.setValue("use_64bit_avisynth", preferences->m_useAvisyth64Bit);
settings.setValue("save_log_files", preferences->m_saveLogFiles);
settings.setValue("save_to_source_path", preferences->m_saveToSourcePath);
settings.setValue("process_priority", preferences->m_processPriority);
settings.setValue("enable_sounds", preferences->m_enableSounds);
settings.sync();
}

75
src/model_preferences.h Normal file
View File

@ -0,0 +1,75 @@
///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
// Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
//
// 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
///////////////////////////////////////////////////////////////////////////////
#pragma once
class PreferencesModel
{
public:
PreferencesModel(void);
enum
{
X264_PRIORITY_ABOVENORMAL = 0,
X264_PRIORITY_NORMAL = 1,
X264_PRIORITY_BELOWNORMAL = 2,
X264_PRIORITY_IDLE = 3,
}
x264_priority_t;
//Getter
bool autoRunNextJob(void) { return m_autoRunNextJob; }
unsigned int maxRunningJobCount(void) { return m_maxRunningJobCount; }
bool shutdownComputer(void) { return m_shutdownComputer; }
bool use10BitEncoding(void) { return m_use10BitEncoding; }
bool useAvisyth64Bit(void) { return m_useAvisyth64Bit; }
bool saveLogFiles(void) { return m_saveLogFiles; }
bool saveToSourcePath(void) { return m_saveToSourcePath; }
int processPriority(void) { return m_processPriority; }
bool enableSounds(void) { return m_enableSounds; }
//Setter
void setAutoRunNextJob(const bool autoRunNextJob) { m_autoRunNextJob = autoRunNextJob; }
void setMaxRunningJobCount(const unsigned int maxRunningJobCount) { m_maxRunningJobCount = maxRunningJobCount; }
void setShutdownComputer(const bool shutdownComputer) { m_shutdownComputer = shutdownComputer; }
void setUse10BitEncoding(const bool use10BitEncoding) { m_use10BitEncoding = use10BitEncoding; }
void setUseAvisyth64Bit(const bool useAvisyth64Bit) { m_useAvisyth64Bit = useAvisyth64Bit; }
void setSaveLogFiles(const bool saveLogFiles) { m_saveLogFiles = saveLogFiles; }
void setSaveToSourcePath(const bool saveToSourcePath) { m_saveToSourcePath = saveToSourcePath; }
void setProcessPriority(const int processPriority) { m_processPriority = processPriority; }
void setEnableSounds(const bool enableSounds) { m_enableSounds = enableSounds; }
//Static
static void initPreferences(PreferencesModel *preferences);
static void loadPreferences(PreferencesModel *preferences);
static void savePreferences(PreferencesModel *preferences);
protected:
bool m_autoRunNextJob;
unsigned int m_maxRunningJobCount;
bool m_shutdownComputer;
bool m_use10BitEncoding;
bool m_useAvisyth64Bit;
bool m_saveLogFiles;
bool m_saveToSourcePath;
int m_processPriority;
bool m_enableSounds;
};

73
src/model_recently.cpp Normal file
View File

@ -0,0 +1,73 @@
///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
// Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
//
// 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 "model_recently.h"
#include "global.h"
#include <QDesktopServices>
#include <QDir>
#include <QSettings>
#define ARRAY_SIZE(ARRAY) (sizeof((ARRAY))/sizeof((ARRAY[0])))
#define VALID_DIR(PATH) ((!(PATH).isEmpty()) && QFileInfo(PATH).exists() && QFileInfo(PATH).isDir())
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";
RecentlyUsed::RecentlyUsed(void)
{
initRecentlyUsed(this);
}
void RecentlyUsed::initRecentlyUsed(RecentlyUsed *recentlyUsed)
{
recentlyUsed->m_sourceDirectory = QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
recentlyUsed->m_outputDirectory = QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
recentlyUsed->m_filterIndex = 0;
}
void RecentlyUsed::loadRecentlyUsed(RecentlyUsed *recentlyUsed)
{
RecentlyUsed defaults;
QSettings settings(QString("%1/last.ini").arg(x264_data_path()), QSettings::IniFormat);
recentlyUsed->m_sourceDirectory = settings.value(KEY_SOURCE_DIR, defaults.m_sourceDirectory).toString();
recentlyUsed->m_outputDirectory = settings.value(KEY_OUTPUT_DIR, defaults.m_outputDirectory).toString();
recentlyUsed->m_filterIndex = settings.value(KEY_FILTER_IDX, defaults.m_filterIndex).toInt();
if(!VALID_DIR(recentlyUsed->m_sourceDirectory)) recentlyUsed->m_sourceDirectory = defaults.m_sourceDirectory;
if(!VALID_DIR(recentlyUsed->m_outputDirectory)) recentlyUsed->m_outputDirectory = defaults.m_outputDirectory;
recentlyUsed->m_filterIndex = qBound(0, recentlyUsed->m_filterIndex, int(ARRAY_SIZE(X264_FILE_TYPE_FILTERS)-1));
}
void RecentlyUsed::saveRecentlyUsed(RecentlyUsed *recentlyUsed)
{
QSettings settings(QString("%1/last.ini").arg(x264_data_path()), QSettings::IniFormat);
if(settings.isWritable())
{
settings.setValue(KEY_SOURCE_DIR, recentlyUsed->m_sourceDirectory);
settings.setValue(KEY_OUTPUT_DIR, recentlyUsed->m_outputDirectory);
settings.setValue(KEY_FILTER_IDX, recentlyUsed->m_filterIndex);
settings.sync();
}
}

61
src/model_recently.h Normal file
View File

@ -0,0 +1,61 @@
///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
// Copyright (C) 2004-2013 LoRd_MuldeR <MuldeR2@GMX.de>
//
// 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
///////////////////////////////////////////////////////////////////////////////
#pragma once
#include <QString>
static const struct
{
const char *pcExt;
const char *pcStr;
}
X264_FILE_TYPE_FILTERS[] =
{
{ "mkv", "Matroska Files" },
{ "mp4", "MPEG-4 Part 14 Container" },
{ "264", "H.264 Elementary Stream"},
};
class RecentlyUsed
{
public:
RecentlyUsed(void);
static void initRecentlyUsed(RecentlyUsed *recentlyUsed);
static void loadRecentlyUsed(RecentlyUsed *recentlyUsed);
static void saveRecentlyUsed(RecentlyUsed *recentlyUsed);
//Getter
QString sourceDirectory(void) { return m_sourceDirectory; }
QString outputDirectory(void) { return m_outputDirectory; }
int filterIndex(void) { return m_filterIndex; }
//Setter
void setSourceDirectory(const QString &sourceDirectory) { m_sourceDirectory = sourceDirectory; }
void setOutputDirectory(const QString &outputDirectory) { m_outputDirectory = outputDirectory; }
void setFilterIndex(const int filterIndex) { m_filterIndex = filterIndex; }
protected:
QString m_sourceDirectory;
QString m_outputDirectory;
int m_filterIndex;
};

View File

@ -23,7 +23,7 @@
#include "global.h" #include "global.h"
#include "model_options.h" #include "model_options.h"
#include "win_preferences.h" #include "model_preferences.h"
#include "version.h" #include "version.h"
#include <QDate> #include <QDate>
@ -104,7 +104,7 @@ static const unsigned int REV_MULT = 10000;
// Constructor & Destructor // Constructor & Destructor
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
EncodeThread::EncodeThread(const QString &sourceFileName, const QString &outputFileName, const OptionsModel *options, const QString &binDir, bool x264_x64, bool x264_10bit, bool avs2yuv_x64, unsigned int processPriroity) EncodeThread::EncodeThread(const QString &sourceFileName, const QString &outputFileName, const OptionsModel *options, const QString &binDir, bool x264_x64, bool x264_10bit, bool avs2yuv_x64, int processPriroity)
: :
m_jobId(QUuid::createUuid()), m_jobId(QUuid::createUuid()),
m_sourceFileName(sourceFileName), m_sourceFileName(sourceFileName),
@ -1114,24 +1114,10 @@ bool EncodeThread::startProcess(QProcess &process, const QString &program, const
if(process.waitForStarted()) if(process.waitForStarted())
{ {
Q_PID pid = process.pid(); Q_PID pid = process.pid();
AssignProcessToJobObject(m_handle_jobObject, process.pid()->hProcess);
if(pid != NULL) if(pid != NULL)
{ {
switch(m_processPriority) AssignProcessToJobObject(m_handle_jobObject, process.pid()->hProcess);
{ setPorcessPriority(process.pid()->hProcess, m_processPriority);
case PreferencesDialog::X264_PRIORITY_NORMAL:
SetPriorityClass(process.pid()->hProcess, NORMAL_PRIORITY_CLASS);
break;
case PreferencesDialog::X264_PRIORITY_BELOWNORMAL:
if(!SetPriorityClass(process.pid()->hProcess, BELOW_NORMAL_PRIORITY_CLASS))
{
SetPriorityClass(process.pid()->hProcess, IDLE_PRIORITY_CLASS);
}
break;
case PreferencesDialog::X264_PRIORITY_IDLE:
SetPriorityClass(process.pid()->hProcess, IDLE_PRIORITY_CLASS);
break;
}
} }
lock.unlock(); lock.unlock();
@ -1226,3 +1212,28 @@ QString EncodeThread::sizeToString(qint64 size)
return tr("N/A"); return tr("N/A");
} }
void EncodeThread::setPorcessPriority(void *processId, int priroity)
{
switch(priroity)
{
case PreferencesModel::X264_PRIORITY_ABOVENORMAL:
if(!SetPriorityClass(processId, ABOVE_NORMAL_PRIORITY_CLASS))
{
SetPriorityClass(processId, NORMAL_PRIORITY_CLASS);
}
break;
case PreferencesModel::X264_PRIORITY_NORMAL:
SetPriorityClass(processId, NORMAL_PRIORITY_CLASS);
break;
case PreferencesModel::X264_PRIORITY_BELOWNORMAL:
if(!SetPriorityClass(processId, BELOW_NORMAL_PRIORITY_CLASS))
{
SetPriorityClass(processId, IDLE_PRIORITY_CLASS);
}
break;
case PreferencesModel::X264_PRIORITY_IDLE:
SetPriorityClass(processId, IDLE_PRIORITY_CLASS);
break;
}
}

View File

@ -53,7 +53,7 @@ public:
JobStatus_Undefined = 666 JobStatus_Undefined = 666
}; };
EncodeThread(const QString &sourceFileName, const QString &outputFileName, const OptionsModel *options, const QString &binDir, bool x264_x64, bool x264_10bit, bool avs2yuv_x64, unsigned int processPriroity); EncodeThread(const QString &sourceFileName, const QString &outputFileName, const OptionsModel *options, const QString &binDir, bool x264_x64, bool x264_10bit, bool avs2yuv_x64, int processPriroity);
~EncodeThread(void); ~EncodeThread(void);
QUuid getId(void) { return this->m_jobId; }; QUuid getId(void) { return this->m_jobId; };
@ -92,7 +92,7 @@ protected:
const bool m_x264_x64; const bool m_x264_x64;
const bool m_x264_10bit; const bool m_x264_10bit;
const bool m_avs2yuv_x64; const bool m_avs2yuv_x64;
const unsigned int m_processPriority; const int m_processPriority;
//Flags //Flags
volatile bool m_abort; volatile bool m_abort;
@ -133,6 +133,7 @@ protected:
//Static functions //Static functions
static QString commandline2string(const QString &program, const QStringList &arguments); static QString commandline2string(const QString &program, const QStringList &arguments);
static QString sizeToString(qint64 size); static QString sizeToString(qint64 size);
static void setPorcessPriority(void *processId, int priroity);
signals: signals:
void statusChanged(const QUuid &jobId, EncodeThread::JobStatus newStatus); void statusChanged(const QUuid &jobId, EncodeThread::JobStatus newStatus);

View File

@ -22,7 +22,7 @@
#define VER_X264_MAJOR 2 #define VER_X264_MAJOR 2
#define VER_X264_MINOR 1 #define VER_X264_MINOR 1
#define VER_X264_PATCH 5 #define VER_X264_PATCH 5
#define VER_X264_BUILD 480 #define VER_X264_BUILD 494
#define VER_X264_MINIMUM_REV 2282 #define VER_X264_MINIMUM_REV 2282
#define VER_X264_CURRENT_API 133 #define VER_X264_CURRENT_API 133

View File

@ -23,6 +23,7 @@
#include "global.h" #include "global.h"
#include "model_options.h" #include "model_options.h"
#include "model_recently.h"
#include "win_help.h" #include "win_help.h"
#include "win_editor.h" #include "win_editor.h"
@ -310,7 +311,7 @@ void AddJobDialog::showEvent(QShowEvent *event)
if((!editSource->text().isEmpty()) && editOutput->text().isEmpty()) if((!editSource->text().isEmpty()) && editOutput->text().isEmpty())
{ {
QString outPath = generateOutputFileName(QDir::fromNativeSeparators(editSource->text()), m_recentlyUsed->outputDirectory, m_recentlyUsed->filterIndex, m_saveToSourceFolder); QString outPath = generateOutputFileName(QDir::fromNativeSeparators(editSource->text()), m_recentlyUsed->outputDirectory(), m_recentlyUsed->filterIndex(), m_saveToSourceFolder);
editOutput->setText(QDir::toNativeSeparators(outPath)); editOutput->setText(QDir::toNativeSeparators(outPath));
buttonAccept->setFocus(); buttonAccept->setFocus();
} }
@ -460,10 +461,10 @@ void AddJobDialog::accept(void)
} }
//Update recently used //Update recently used
m_recentlyUsed->filterIndex = currentOutputIndx(); m_recentlyUsed->setFilterIndex(currentOutputIndx());
m_recentlyUsed->sourceDirectory = currentSourcePath(); m_recentlyUsed->setSourceDirectory(currentSourcePath());
m_recentlyUsed->outputDirectory = currentOutputPath(); m_recentlyUsed->setOutputDirectory(currentOutputPath());
saveRecentlyUsed(m_recentlyUsed); RecentlyUsed::saveRecentlyUsed(m_recentlyUsed);
//Save options //Save options
saveOptions(m_options); saveOptions(m_options);
@ -499,7 +500,7 @@ void AddJobDialog::browseButtonClicked(void)
} }
if(tempIndex < 0) if(tempIndex < 0)
{ {
tempIndex = m_recentlyUsed->filterIndex; tempIndex = m_recentlyUsed->filterIndex();
} }
filePath = QString("%1.%2").arg(filePath, getFilterExt(tempIndex)); filePath = QString("%1.%2").arg(filePath, getFilterExt(tempIndex));
} }
@ -808,7 +809,7 @@ void AddJobDialog::saveOptions(OptionsModel *options)
QString AddJobDialog::currentSourcePath(const bool bWithName) QString AddJobDialog::currentSourcePath(const bool bWithName)
{ {
QString path = m_recentlyUsed->sourceDirectory; QString path = m_recentlyUsed->sourceDirectory();
QString currentSourceFile = this->sourceFile(); QString currentSourceFile = this->sourceFile();
if(!currentSourceFile.isEmpty()) if(!currentSourceFile.isEmpty())
@ -829,7 +830,7 @@ QString AddJobDialog::currentSourcePath(const bool bWithName)
QString AddJobDialog::currentOutputPath(const bool bWithName) QString AddJobDialog::currentOutputPath(const bool bWithName)
{ {
QString path = m_recentlyUsed->outputDirectory; QString path = m_recentlyUsed->outputDirectory();
QString currentOutputFile = this->outputFile(); QString currentOutputFile = this->outputFile();
if(!currentOutputFile.isEmpty()) if(!currentOutputFile.isEmpty())
@ -850,7 +851,7 @@ QString AddJobDialog::currentOutputPath(const bool bWithName)
int AddJobDialog::currentOutputIndx(void) int AddJobDialog::currentOutputIndx(void)
{ {
int index = m_recentlyUsed->filterIndex; int index = m_recentlyUsed->filterIndex();
QString currentOutputFile = this->outputFile(); QString currentOutputFile = this->outputFile();
if(!currentOutputFile.isEmpty()) if(!currentOutputFile.isEmpty())
@ -870,58 +871,6 @@ int AddJobDialog::currentOutputIndx(void)
// Static functions // 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";
static const struct
{
const char *pcExt;
const char *pcStr;
}
FILE_TYPE_FILTERS[] =
{
{ "mkv", "Matroska Files" },
{ "mp4", "MPEG-4 Part 14 Container" },
{ "264", "H.264 Elementary Stream"},
};
/* ------------------------------------------------------------------------- */
void AddJobDialog::initRecentlyUsed(RecentlyUsed *recentlyUsed)
{
recentlyUsed->sourceDirectory = QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
recentlyUsed->outputDirectory = QDir::fromNativeSeparators(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
recentlyUsed->filterIndex = 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;
recentlyUsed->filterIndex = qBound(0, recentlyUsed->filterIndex, int(ARRAY_SIZE(FILE_TYPE_FILTERS)-1));
}
void AddJobDialog::saveRecentlyUsed(RecentlyUsed *recentlyUsed)
{
QSettings settings(QString("%1/last.ini").arg(x264_data_path()), QSettings::IniFormat);
if(settings.isWritable())
{
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 AddJobDialog::generateOutputFileName(const QString &sourceFilePath, const QString &destinationDirectory, const int filterIndex, const bool saveToSourceDir)
{ {
QString name = QFileInfo(sourceFilePath).completeBaseName(); QString name = QFileInfo(sourceFilePath).completeBaseName();
@ -931,8 +880,7 @@ QString AddJobDialog::generateOutputFileName(const QString &sourceFilePath, cons
if(!VALID_DIR(path)) if(!VALID_DIR(path))
{ {
RecentlyUsed defaults; RecentlyUsed defaults;
initRecentlyUsed(&defaults); path = defaults.outputDirectory();
path = defaults.outputDirectory;
} }
QString outPath = QString("%1/%2.%3").arg(path, name, fext); QString outPath = QString("%1/%2.%3").arg(path, name, fext);
@ -950,23 +898,23 @@ QString AddJobDialog::generateOutputFileName(const QString &sourceFilePath, cons
QString AddJobDialog::getFilterExt(const int filterIndex) QString AddJobDialog::getFilterExt(const int filterIndex)
{ {
const int count = ARRAY_SIZE(FILE_TYPE_FILTERS); const int count = ARRAY_SIZE(X264_FILE_TYPE_FILTERS);
if((filterIndex >= 0) && (filterIndex < count)) if((filterIndex >= 0) && (filterIndex < count))
{ {
return QString::fromLatin1(FILE_TYPE_FILTERS[filterIndex].pcExt); return QString::fromLatin1(X264_FILE_TYPE_FILTERS[filterIndex].pcExt);
} }
return QString::fromLatin1(FILE_TYPE_FILTERS[0].pcExt); return QString::fromLatin1(X264_FILE_TYPE_FILTERS[0].pcExt);
} }
int AddJobDialog::getFilterIdx(const QString &fileExt) int AddJobDialog::getFilterIdx(const QString &fileExt)
{ {
const int count = ARRAY_SIZE(FILE_TYPE_FILTERS); const int count = ARRAY_SIZE(X264_FILE_TYPE_FILTERS);
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++)
{ {
if(fileExt.compare(QString::fromLatin1(FILE_TYPE_FILTERS[i].pcExt), Qt::CaseInsensitive) == 0) if(fileExt.compare(QString::fromLatin1(X264_FILE_TYPE_FILTERS[i].pcExt), Qt::CaseInsensitive) == 0)
{ {
return i; return i;
} }
@ -977,24 +925,24 @@ int AddJobDialog::getFilterIdx(const QString &fileExt)
QString AddJobDialog::getFilterStr(const int filterIndex) QString AddJobDialog::getFilterStr(const int filterIndex)
{ {
const int count = ARRAY_SIZE(FILE_TYPE_FILTERS); const int count = ARRAY_SIZE(X264_FILE_TYPE_FILTERS);
if((filterIndex >= 0) && (filterIndex < count)) if((filterIndex >= 0) && (filterIndex < count))
{ {
return QString("%1 (*.%2)").arg(QString::fromLatin1(FILE_TYPE_FILTERS[filterIndex].pcStr), QString::fromLatin1(FILE_TYPE_FILTERS[filterIndex].pcExt)); return QString("%1 (*.%2)").arg(QString::fromLatin1(X264_FILE_TYPE_FILTERS[filterIndex].pcStr), QString::fromLatin1(X264_FILE_TYPE_FILTERS[filterIndex].pcExt));
} }
return QString("%1 (*.%2)").arg(QString::fromLatin1(FILE_TYPE_FILTERS[0].pcStr), QString::fromLatin1(FILE_TYPE_FILTERS[0].pcExt)); return QString("%1 (*.%2)").arg(QString::fromLatin1(X264_FILE_TYPE_FILTERS[0].pcStr), QString::fromLatin1(X264_FILE_TYPE_FILTERS[0].pcExt));
} }
QString AddJobDialog::getFilterLst(void) QString AddJobDialog::getFilterLst(void)
{ {
QStringList filters; QStringList filters;
const int count = ARRAY_SIZE(FILE_TYPE_FILTERS); const int count = ARRAY_SIZE(X264_FILE_TYPE_FILTERS);
for(int i = 0; i < count; i++) for(int i = 0; i < count; i++)
{ {
filters << QString("%1 (*.%2)").arg(QString::fromLatin1(FILE_TYPE_FILTERS[i].pcStr), QString::fromLatin1(FILE_TYPE_FILTERS[i].pcExt)); filters << QString("%1 (*.%2)").arg(QString::fromLatin1(X264_FILE_TYPE_FILTERS[i].pcStr), QString::fromLatin1(X264_FILE_TYPE_FILTERS[i].pcExt));
} }
return filters.join(";;"); return filters.join(";;");

View File

@ -26,20 +26,13 @@
#include <QDir> #include <QDir>
class OptionsModel; class OptionsModel;
class RecentlyUsed;
class AddJobDialog : public QDialog, private Ui::AddJobDialog class AddJobDialog : public QDialog, private Ui::AddJobDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
typedef struct
{
QString sourceDirectory;
QString outputDirectory;
int filterIndex;
}
RecentlyUsed;
AddJobDialog(QWidget *parent, OptionsModel *options, RecentlyUsed *recentlyUsed, bool x64supported, bool use10BitEncoding, bool saveToSourceFolder); AddJobDialog(QWidget *parent, OptionsModel *options, RecentlyUsed *recentlyUsed, bool x64supported, bool use10BitEncoding, bool saveToSourceFolder);
~AddJobDialog(void); ~AddJobDialog(void);
@ -57,10 +50,6 @@ public:
void setSourceEditable(const bool editable) { buttonBrowseSource->setEnabled(editable); } void setSourceEditable(const bool editable) { buttonBrowseSource->setEnabled(editable); }
void setApplyToAllVisible(const bool visible) { checkBoxApplyToAll->setVisible(visible); } 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 QString generateOutputFileName(const QString &sourceFilePath, const QString &destinationDirectory, const int filterIndex, const bool saveToSourceDir);
static int getFilterIdx(const QString &fileExt); static int getFilterIdx(const QString &fileExt);
static QString getFilterExt(const int filterIndex); static QString getFilterExt(const int filterIndex);

View File

@ -23,8 +23,12 @@
#include "model_jobList.h" #include "model_jobList.h"
#include "model_options.h" #include "model_options.h"
#include "model_preferences.h"
#include "model_recently.h"
#include "thread_avisynth.h" #include "thread_avisynth.h"
#include "taskbar7.h" #include "taskbar7.h"
#include "win_addJob.h"
#include "win_preferences.h"
#include "resource.h" #include "resource.h"
#include <QDate> #include <QDate>
@ -67,6 +71,8 @@ MainWindow::MainWindow(const x264_cpu_t *const cpuFeatures)
m_options(NULL), m_options(NULL),
m_jobList(NULL), m_jobList(NULL),
m_droppedFiles(NULL), m_droppedFiles(NULL),
m_preferences(NULL),
m_recentlyUsed(NULL),
m_firstShow(true) m_firstShow(true)
{ {
//Init the dialog, from the .ui file //Init the dialog, from the .ui file
@ -79,12 +85,12 @@ MainWindow::MainWindow(const x264_cpu_t *const cpuFeatures)
qRegisterMetaType<EncodeThread::JobStatus>("EncodeThread::JobStatus"); qRegisterMetaType<EncodeThread::JobStatus>("EncodeThread::JobStatus");
//Load preferences //Load preferences
PreferencesDialog::initPreferences(&m_preferences); m_preferences = new PreferencesModel();
PreferencesDialog::loadPreferences(&m_preferences); PreferencesModel::loadPreferences(m_preferences);
//Load recently used //Load recently used
AddJobDialog::initRecentlyUsed(&m_recentlyUsed); m_recentlyUsed = new RecentlyUsed();
AddJobDialog::loadRecentlyUsed(&m_recentlyUsed); RecentlyUsed::loadRecentlyUsed(m_recentlyUsed);
//Create options object //Create options object
m_options = new OptionsModel(); m_options = new OptionsModel();
@ -113,7 +119,7 @@ MainWindow::MainWindow(const x264_cpu_t *const cpuFeatures)
} }
//Create model //Create model
m_jobList = new JobListModel(&m_preferences); m_jobList = new JobListModel(m_preferences);
connect(m_jobList, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(jobChangedData(QModelIndex, QModelIndex))); connect(m_jobList, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(jobChangedData(QModelIndex, QModelIndex)));
jobsView->setModel(m_jobList); jobsView->setModel(m_jobList);
@ -203,6 +209,8 @@ MainWindow::~MainWindow(void)
X264_DELETE(m_ipcThread); X264_DELETE(m_ipcThread);
AvisynthCheckThread::unload(); AvisynthCheckThread::unload();
X264_DELETE(m_preferences);
X264_DELETE(m_recentlyUsed);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -215,7 +223,7 @@ MainWindow::~MainWindow(void)
void MainWindow::addButtonPressed() void MainWindow::addButtonPressed()
{ {
qDebug("MainWindow::addButtonPressed"); qDebug("MainWindow::addButtonPressed");
bool runImmediately = (countRunningJobs() < (m_preferences.autoRunNextJob ? m_preferences.maxRunningJobCount : 1)); bool runImmediately = (countRunningJobs() < (m_preferences->autoRunNextJob() ? m_preferences->maxRunningJobCount() : 1));
QString sourceFileName, outputFileName; QString sourceFileName, outputFileName;
if(createJob(sourceFileName, outputFileName, m_options, runImmediately)) if(createJob(sourceFileName, outputFileName, m_options, runImmediately))
@ -229,17 +237,17 @@ void MainWindow::addButtonPressed()
*/ */
void MainWindow::openActionTriggered() void MainWindow::openActionTriggered()
{ {
QStringList fileList = QFileDialog::getOpenFileNames(this, tr("Open Source File(s)"), m_recentlyUsed.sourceDirectory, AddJobDialog::getInputFilterLst(), NULL, QFileDialog::DontUseNativeDialog); QStringList fileList = QFileDialog::getOpenFileNames(this, tr("Open Source File(s)"), m_recentlyUsed->sourceDirectory(), AddJobDialog::getInputFilterLst(), NULL, QFileDialog::DontUseNativeDialog);
if(!fileList.empty()) if(!fileList.empty())
{ {
m_recentlyUsed.sourceDirectory = QFileInfo(fileList.last()).absolutePath(); m_recentlyUsed->setSourceDirectory(QFileInfo(fileList.last()).absolutePath());
if(fileList.count() > 1) if(fileList.count() > 1)
{ {
createJobMultiple(fileList); createJobMultiple(fileList);
} }
else else
{ {
bool runImmediately = (countRunningJobs() < (m_preferences.autoRunNextJob ? m_preferences.maxRunningJobCount : 1)); bool runImmediately = (countRunningJobs() < (m_preferences->autoRunNextJob() ? m_preferences->maxRunningJobCount() : 1));
QString sourceFileName(fileList.first()), outputFileName; QString sourceFileName(fileList.first()), outputFileName;
if(createJob(sourceFileName, outputFileName, m_options, runImmediately)) if(createJob(sourceFileName, outputFileName, m_options, runImmediately))
{ {
@ -384,9 +392,9 @@ void MainWindow::jobChangedData(const QModelIndex &topLeft, const QModelIndex &
} }
if((status == EncodeThread::JobStatus_Completed) || (status == EncodeThread::JobStatus_Failed)) if((status == EncodeThread::JobStatus_Completed) || (status == EncodeThread::JobStatus_Failed))
{ {
if(m_preferences.autoRunNextJob) QTimer::singleShot(0, this, SLOT(launchNextJob())); if(m_preferences->autoRunNextJob()) QTimer::singleShot(0, this, SLOT(launchNextJob()));
if(m_preferences.shutdownComputer) QTimer::singleShot(0, this, SLOT(shutdownComputer())); if(m_preferences->shutdownComputer()) QTimer::singleShot(0, this, SLOT(shutdownComputer()));
if(m_preferences.saveLogFiles) saveLogFile(m_jobList->index(i, 1, QModelIndex())); if(m_preferences->saveLogFiles()) saveLogFile(m_jobList->index(i, 1, QModelIndex()));
} }
} }
} }
@ -521,7 +529,7 @@ void MainWindow::showWebLink(void)
*/ */
void MainWindow::showPreferences(void) void MainWindow::showPreferences(void)
{ {
PreferencesDialog *preferences = new PreferencesDialog(this, &m_preferences, m_cpuFeatures->x64); PreferencesDialog *preferences = new PreferencesDialog(this, m_preferences, m_cpuFeatures->x64);
preferences->exec(); preferences->exec();
X264_DELETE(preferences); X264_DELETE(preferences);
} }
@ -535,7 +543,7 @@ void MainWindow::launchNextJob(void)
const int rows = m_jobList->rowCount(QModelIndex()); const int rows = m_jobList->rowCount(QModelIndex());
if(countRunningJobs() >= m_preferences.maxRunningJobCount) if(countRunningJobs() >= m_preferences->maxRunningJobCount())
{ {
qDebug("Still have too many jobs running, won't launch next one yet!"); qDebug("Still have too many jobs running, won't launch next one yet!");
return; return;
@ -1022,7 +1030,7 @@ void MainWindow::dropEvent(QDropEvent *event)
bool MainWindow::createJob(QString &sourceFileName, QString &outputFileName, OptionsModel *options, bool &runImmediately, const bool restart, int fileNo, int fileTotal, bool *applyToAll) bool MainWindow::createJob(QString &sourceFileName, QString &outputFileName, OptionsModel *options, bool &runImmediately, const bool restart, int fileNo, int fileTotal, bool *applyToAll)
{ {
bool okay = false; bool okay = false;
AddJobDialog *addDialog = new AddJobDialog(this, options, &m_recentlyUsed, m_cpuFeatures->x64, m_preferences.use10BitEncoding, m_preferences.saveToSourcePath); AddJobDialog *addDialog = new AddJobDialog(this, options, m_recentlyUsed, m_cpuFeatures->x64, m_preferences->use10BitEncoding(), m_preferences->saveToSourcePath());
addDialog->setRunImmediately(runImmediately); addDialog->setRunImmediately(runImmediately);
if(!sourceFileName.isEmpty()) addDialog->setSourceFile(sourceFileName); if(!sourceFileName.isEmpty()) addDialog->setSourceFile(sourceFileName);
@ -1065,7 +1073,7 @@ bool MainWindow::createJobMultiple(const QStringList &filePathIn)
//Add files individually //Add files individually
for(iter = filePathIn.constBegin(); (iter != filePathIn.constEnd()) && (!applyToAll); iter++) for(iter = filePathIn.constBegin(); (iter != filePathIn.constEnd()) && (!applyToAll); iter++)
{ {
runImmediately = (countRunningJobs() < (m_preferences.autoRunNextJob ? m_preferences.maxRunningJobCount : 1)); runImmediately = (countRunningJobs() < (m_preferences->autoRunNextJob() ? m_preferences->maxRunningJobCount() : 1));
QString sourceFileName(*iter), outputFileName; QString sourceFileName(*iter), outputFileName;
if(createJob(sourceFileName, outputFileName, m_options, runImmediately, false, counter++, filePathIn.count(), &applyToAll)) if(createJob(sourceFileName, outputFileName, m_options, runImmediately, false, counter++, filePathIn.count(), &applyToAll))
{ {
@ -1080,9 +1088,9 @@ bool MainWindow::createJobMultiple(const QStringList &filePathIn)
//Add remaining files //Add remaining files
while(applyToAll && (iter != filePathIn.constEnd())) while(applyToAll && (iter != filePathIn.constEnd()))
{ {
const bool runImmediatelyTmp = runImmediately && (countRunningJobs() < (m_preferences.autoRunNextJob ? m_preferences.maxRunningJobCount : 1)); const bool runImmediatelyTmp = runImmediately && (countRunningJobs() < (m_preferences->autoRunNextJob() ? m_preferences->maxRunningJobCount() : 1));
const QString sourceFileName = *iter; const QString sourceFileName = *iter;
const QString outputFileName = AddJobDialog::generateOutputFileName(sourceFileName, m_recentlyUsed.outputDirectory, m_recentlyUsed.filterIndex, m_preferences.saveToSourcePath); const QString outputFileName = AddJobDialog::generateOutputFileName(sourceFileName, m_recentlyUsed->outputDirectory(), m_recentlyUsed->filterIndex(), m_preferences->saveToSourcePath());
if(!appendJob(sourceFileName, outputFileName, m_options, runImmediatelyTmp)) if(!appendJob(sourceFileName, outputFileName, m_options, runImmediatelyTmp))
{ {
return false; return false;
@ -1108,9 +1116,9 @@ bool MainWindow::appendJob(const QString &sourceFileName, const QString &outputF
options, options,
QString("%1/toolset").arg(m_appDir), QString("%1/toolset").arg(m_appDir),
m_cpuFeatures->x64, m_cpuFeatures->x64,
m_preferences.use10BitEncoding, m_preferences->use10BitEncoding(),
m_cpuFeatures->x64 && m_preferences.useAvisyth64Bit, m_cpuFeatures->x64 && m_preferences->useAvisyth64Bit(),
m_preferences.processPriority m_preferences->processPriority()
); );
QModelIndex newIndex = m_jobList->insertJob(thrd); QModelIndex newIndex = m_jobList->insertJob(thrd);

View File

@ -24,14 +24,13 @@
#include "uic_win_main.h" #include "uic_win_main.h"
#include "thread_ipc.h" #include "thread_ipc.h"
#include "thread_encode.h" #include "thread_encode.h"
#include "win_preferences.h"
#include "win_addJob.h"
#include "global.h"
class JobListModel; class JobListModel;
class OptionsModel; class OptionsModel;
class QFile; class QFile;
class QLibrary; class QLibrary;
class PreferencesModel;
class RecentlyUsed;
class MainWindow: public QMainWindow, private Ui::MainWindow class MainWindow: public QMainWindow, private Ui::MainWindow
{ {
@ -60,8 +59,8 @@ private:
QStringList *m_droppedFiles; QStringList *m_droppedFiles;
QList<QFile*> m_toolsList; QList<QFile*> m_toolsList;
PreferencesDialog::Preferences m_preferences; PreferencesModel *m_preferences;
AddJobDialog::RecentlyUsed m_recentlyUsed; RecentlyUsed *m_recentlyUsed;
const x264_cpu_t *const m_cpuFeatures; const x264_cpu_t *const m_cpuFeatures;
const QString m_appDir; const QString m_appDir;

View File

@ -22,6 +22,7 @@
#include "win_preferences.h" #include "win_preferences.h"
#include "global.h" #include "global.h"
#include "model_preferences.h"
#include <QSettings> #include <QSettings>
#include <QDesktopServices> #include <QDesktopServices>
@ -34,7 +35,7 @@
if((CHKBOX)->isChecked() != (VALUE)) (CHKBOX)->setChecked(VALUE); \ if((CHKBOX)->isChecked() != (VALUE)) (CHKBOX)->setChecked(VALUE); \
} }
PreferencesDialog::PreferencesDialog(QWidget *parent, Preferences *preferences, bool x64) PreferencesDialog::PreferencesDialog(QWidget *parent, PreferencesModel *preferences, bool x64)
: :
QDialog(parent), QDialog(parent),
m_x64(x64) m_x64(x64)
@ -65,19 +66,19 @@ void PreferencesDialog::showEvent(QShowEvent *event)
{ {
if(event) QDialog::showEvent(event); if(event) QDialog::showEvent(event);
UPDATE_CHECKBOX(checkRunNextJob, m_preferences->autoRunNextJob); UPDATE_CHECKBOX(checkRunNextJob, m_preferences->autoRunNextJob());
UPDATE_CHECKBOX(checkShutdownComputer, m_preferences->shutdownComputer); UPDATE_CHECKBOX(checkShutdownComputer, m_preferences->shutdownComputer());
UPDATE_CHECKBOX(checkUse64BitAvs2YUV, m_preferences->useAvisyth64Bit); UPDATE_CHECKBOX(checkUse64BitAvs2YUV, m_preferences->useAvisyth64Bit());
UPDATE_CHECKBOX(checkSaveLogFiles, m_preferences->saveLogFiles); UPDATE_CHECKBOX(checkSaveLogFiles, m_preferences->saveLogFiles());
UPDATE_CHECKBOX(checkSaveToSourceFolder, m_preferences->saveToSourcePath); UPDATE_CHECKBOX(checkSaveToSourceFolder, m_preferences->saveToSourcePath());
UPDATE_CHECKBOX(checkEnableSounds, m_preferences->enableSounds); UPDATE_CHECKBOX(checkEnableSounds, m_preferences->enableSounds());
checkUse10BitEncoding->blockSignals(true); checkUse10BitEncoding->blockSignals(true);
UPDATE_CHECKBOX(checkUse10BitEncoding, m_preferences->use10BitEncoding); UPDATE_CHECKBOX(checkUse10BitEncoding, m_preferences->use10BitEncoding());
checkUse10BitEncoding->blockSignals(false); checkUse10BitEncoding->blockSignals(false);
spinBoxJobCount->setValue(m_preferences->maxRunningJobCount); spinBoxJobCount->setValue(m_preferences->maxRunningJobCount());
comboBoxPriority->setCurrentIndex(qBound(0U, m_preferences->processPriority, 2U)); comboBoxPriority->setCurrentIndex(qBound(0, m_preferences->processPriority(), comboBoxPriority->count()-1));
checkUse64BitAvs2YUV->setEnabled(m_x64); checkUse64BitAvs2YUV->setEnabled(m_x64);
labelUse64BitAvs2YUV->setEnabled(m_x64); labelUse64BitAvs2YUV->setEnabled(m_x64);
@ -117,23 +118,23 @@ void PreferencesDialog::emulateMouseEvent(QObject *object, QEvent *event, QWidge
void PreferencesDialog::done(int n) void PreferencesDialog::done(int n)
{ {
m_preferences->autoRunNextJob = checkRunNextJob->isChecked(); m_preferences->setAutoRunNextJob(checkRunNextJob->isChecked());
m_preferences->shutdownComputer = checkShutdownComputer->isChecked(); m_preferences->setShutdownComputer(checkShutdownComputer->isChecked());
m_preferences->use10BitEncoding = checkUse10BitEncoding->isChecked(); m_preferences->setUse10BitEncoding(checkUse10BitEncoding->isChecked());
m_preferences->useAvisyth64Bit = checkUse64BitAvs2YUV->isChecked(); m_preferences->setUseAvisyth64Bit(checkUse64BitAvs2YUV->isChecked());
m_preferences->saveLogFiles = checkSaveLogFiles->isChecked(); m_preferences->setSaveLogFiles(checkSaveLogFiles->isChecked());
m_preferences->saveToSourcePath = checkSaveToSourceFolder->isChecked(); m_preferences->setSaveToSourcePath(checkSaveToSourceFolder->isChecked());
m_preferences->maxRunningJobCount = spinBoxJobCount->value(); m_preferences->setMaxRunningJobCount(spinBoxJobCount->value());
m_preferences->processPriority = comboBoxPriority->currentIndex(); m_preferences->setProcessPriority(comboBoxPriority->currentIndex());
m_preferences->enableSounds = checkEnableSounds->isChecked(); m_preferences->setEnableSounds(checkEnableSounds->isChecked());
savePreferences(m_preferences); PreferencesModel::savePreferences(m_preferences);
QDialog::done(n); QDialog::done(n);
} }
void PreferencesDialog::resetButtonPressed(void) void PreferencesDialog::resetButtonPressed(void)
{ {
initPreferences(m_preferences); PreferencesModel::initPreferences(m_preferences);
showEvent(NULL); showEvent(NULL);
} }
@ -152,60 +153,3 @@ void PreferencesDialog::use10BitEncodingToggled(bool checked)
} }
} }
} }
///////////////////////////////////////////////////////////////////////////////
// Static Functions
///////////////////////////////////////////////////////////////////////////////
void PreferencesDialog::initPreferences(Preferences *preferences)
{
memset(preferences, 0, sizeof(Preferences));
preferences->autoRunNextJob = true;
preferences->maxRunningJobCount = 1;
preferences->shutdownComputer = false;
preferences->use10BitEncoding = false;
preferences->useAvisyth64Bit = false;
preferences->saveLogFiles = false;
preferences->saveToSourcePath = false;
preferences->processPriority = X264_PRIORITY_BELOWNORMAL;
preferences->enableSounds = false;
}
void PreferencesDialog::loadPreferences(Preferences *preferences)
{
const QString appDir = x264_data_path();
QSettings settings(QString("%1/preferences.ini").arg(appDir), QSettings::IniFormat);
Preferences defaults;
initPreferences(&defaults);
settings.beginGroup("preferences");
preferences->autoRunNextJob = settings.value("auto_run_next_job", QVariant(defaults.autoRunNextJob)).toBool();
preferences->maxRunningJobCount = qBound(1U, settings.value("max_running_job_count", QVariant(defaults.maxRunningJobCount)).toUInt(), 16U);
preferences->shutdownComputer = settings.value("shutdown_computer_on_completion", QVariant(defaults.shutdownComputer)).toBool();
preferences->use10BitEncoding = settings.value("use_10bit_encoding", QVariant(defaults.use10BitEncoding)).toBool();
preferences->useAvisyth64Bit = settings.value("use_64bit_avisynth", QVariant(defaults.useAvisyth64Bit)).toBool();
preferences->saveLogFiles = settings.value("save_log_files", QVariant(defaults.saveLogFiles)).toBool();
preferences->saveToSourcePath = settings.value("save_to_source_path", QVariant(defaults.saveToSourcePath)).toBool();
preferences->processPriority = settings.value("process_priority", QVariant(defaults.processPriority)).toUInt();
preferences->enableSounds = settings.value("enable_sounds", QVariant(defaults.enableSounds)).toBool();
}
void PreferencesDialog::savePreferences(Preferences *preferences)
{
const QString appDir = x264_data_path();
QSettings settings(QString("%1/preferences.ini").arg(appDir), QSettings::IniFormat);
settings.beginGroup("preferences");
settings.setValue("auto_run_next_job", preferences->autoRunNextJob);
settings.setValue("shutdown_computer_on_completion", preferences->shutdownComputer);
settings.setValue("max_running_job_count", preferences->maxRunningJobCount);
settings.setValue("use_10bit_encoding", preferences->use10BitEncoding);
settings.setValue("use_64bit_avisynth", preferences->useAvisyth64Bit);
settings.setValue("save_log_files", preferences->saveLogFiles);
settings.setValue("save_to_source_path", preferences->saveToSourcePath);
settings.setValue("process_priority", preferences->processPriority);
settings.setValue("enable_sounds", preferences->enableSounds);
settings.sync();
}

View File

@ -23,42 +23,18 @@
#include "uic_win_preferences.h" #include "uic_win_preferences.h"
class PreferencesModel;
class PreferencesDialog : public QDialog, private Ui::PreferencesDialog class PreferencesDialog : public QDialog, private Ui::PreferencesDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
enum PreferencesDialog(QWidget *parent, PreferencesModel *preferences, bool x64);
{
X264_PRIORITY_NORMAL = 0,
X264_PRIORITY_BELOWNORMAL = 1,
X264_PRIORITY_IDLE = 2,
}
x264_priority_t;
typedef struct
{
bool autoRunNextJob;
unsigned int maxRunningJobCount;
bool shutdownComputer;
bool use10BitEncoding;
bool useAvisyth64Bit;
bool saveLogFiles;
bool saveToSourcePath;
unsigned int processPriority;
bool enableSounds;
}
Preferences;
PreferencesDialog(QWidget *parent, Preferences *preferences, bool x64);
~PreferencesDialog(void); ~PreferencesDialog(void);
const bool m_x64; const bool m_x64;
static void initPreferences(Preferences *preferences);
static void loadPreferences(Preferences *preferences);
static void savePreferences(Preferences *preferences);
protected: protected:
virtual void done(int n); virtual void done(int n);
virtual void showEvent(QShowEvent *event); virtual void showEvent(QShowEvent *event);
@ -67,7 +43,7 @@ protected:
void emulateMouseEvent(QObject *object, QEvent *event, QWidget *source, QWidget *target); void emulateMouseEvent(QObject *object, QEvent *event, QWidget *source, QWidget *target);
private: private:
Preferences *m_preferences; PreferencesModel *m_preferences;
private slots: private slots:
void resetButtonPressed(void); void resetButtonPressed(void);

View File

@ -150,9 +150,7 @@ mkdir "$(TargetDir)\toolset\x86"
mkdir "$(TargetDir)\toolset\x64" mkdir "$(TargetDir)\toolset\x64"
mkdir "$(TargetDir)\imageformats" mkdir "$(TargetDir)\imageformats"
copy /Y "$(SolutionDir)res\toolset\x86\*.exe" "$(TargetDir)\toolset\x86\" copy /Y "$(SolutionDir)res\toolset\x86\*.exe" "$(TargetDir)\toolset\x86\"
copy /Y "$(SolutionDir)res\toolset\x86\*.dll" "$(TargetDir)\toolset\x86\"
copy /Y "$(SolutionDir)res\toolset\x64\*.exe" "$(TargetDir)\toolset\x64\" copy /Y "$(SolutionDir)res\toolset\x64\*.exe" "$(TargetDir)\toolset\x64\"
copy /Y "$(SolutionDir)res\toolset\x64\*.dll" "$(TargetDir)\toolset\x64\"
copy /Y "$(QTDIR)\bin\QtCore4.dll" "$(TargetDir)" copy /Y "$(QTDIR)\bin\QtCore4.dll" "$(TargetDir)"
copy /Y "$(QTDIR)\bin\QtGui4.dll" "$(TargetDir)" copy /Y "$(QTDIR)\bin\QtGui4.dll" "$(TargetDir)"
copy /Y "$(QTDIR)\bin\QtSvg4.dll" "$(TargetDir)" copy /Y "$(QTDIR)\bin\QtSvg4.dll" "$(TargetDir)"
@ -285,6 +283,8 @@ copy /Y "$(QTDIR)\plugins\imageformats\qgif4.dll" "$(TargetDir)\imageformats"
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)tmp\moc\moc_%(Filename).cpp;%(Outputs)</Outputs> <Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)tmp\moc\moc_%(Filename).cpp;%(Outputs)</Outputs>
</CustomBuild> </CustomBuild>
<ClInclude Include="src\model_options.h" /> <ClInclude Include="src\model_options.h" />
<ClInclude Include="src\model_preferences.h" />
<ClInclude Include="src\model_recently.h" />
<ClInclude Include="src\targetver.h" /> <ClInclude Include="src\targetver.h" />
<ClInclude Include="src\taskbar7.h" /> <ClInclude Include="src\taskbar7.h" />
<CustomBuild Include="src\thread_ipc.h"> <CustomBuild Include="src\thread_ipc.h">
@ -317,6 +317,8 @@ copy /Y "$(QTDIR)\plugins\imageformats\qgif4.dll" "$(TargetDir)\imageformats"
<ClCompile Include="src\model_jobList.cpp" /> <ClCompile Include="src\model_jobList.cpp" />
<ClCompile Include="src\model_logFile.cpp" /> <ClCompile Include="src\model_logFile.cpp" />
<ClCompile Include="src\model_options.cpp" /> <ClCompile Include="src\model_options.cpp" />
<ClCompile Include="src\model_preferences.cpp" />
<ClCompile Include="src\model_recently.cpp" />
<ClCompile Include="src\qtmain_win.cpp"> <ClCompile Include="src\qtmain_win.cpp">
<TreatWChar_tAsBuiltInType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</TreatWChar_tAsBuiltInType> <TreatWChar_tAsBuiltInType Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</TreatWChar_tAsBuiltInType>
<TreatWChar_tAsBuiltInType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</TreatWChar_tAsBuiltInType> <TreatWChar_tAsBuiltInType Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</TreatWChar_tAsBuiltInType>

View File

@ -48,6 +48,12 @@
<ClInclude Include="src\taskbar7.h"> <ClInclude Include="src\taskbar7.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\model_preferences.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\model_recently.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="src\main.cpp"> <ClCompile Include="src\main.cpp">
@ -128,6 +134,12 @@
<ClCompile Include="tmp\moc\moc_thread_avisynth.cpp"> <ClCompile Include="tmp\moc\moc_thread_avisynth.cpp">
<Filter>Generated Files</Filter> <Filter>Generated Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\model_preferences.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\model_recently.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<CustomBuild Include="src\win_main.h"> <CustomBuild Include="src\win_main.h">