From a74f27ab5be68708f40416596b861835986559e6 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Wed, 3 Jul 2013 21:34:21 +0200 Subject: [PATCH] Code refactoring: Now "Preferences" and "Recently" used models are in separate classes for a more cleaner design. --- gui/win_preferences.ui | 5 ++ src/model_jobList.cpp | 5 +- src/model_jobList.h | 7 ++- src/model_preferences.cpp | 88 ++++++++++++++++++++++++++++ src/model_preferences.h | 75 ++++++++++++++++++++++++ src/model_recently.cpp | 73 +++++++++++++++++++++++ src/model_recently.h | 61 ++++++++++++++++++++ src/thread_encode.cpp | 47 +++++++++------ src/thread_encode.h | 5 +- src/version.h | 2 +- src/win_addJob.cpp | 94 +++++++----------------------- src/win_addJob.h | 13 +---- src/win_main.cpp | 50 +++++++++------- src/win_main.h | 9 ++- src/win_preferences.cpp | 102 ++++++++------------------------- src/win_preferences.h | 32 ++--------- x264_launcher_MSVC2012.vcxproj | 6 +- x264_launcher_MSVC2012.vcxproj.filters | 12 ++++ 18 files changed, 440 insertions(+), 246 deletions(-) create mode 100644 src/model_preferences.cpp create mode 100644 src/model_preferences.h create mode 100644 src/model_recently.cpp create mode 100644 src/model_recently.h diff --git a/gui/win_preferences.ui b/gui/win_preferences.ui index 8c84a4a..df5f528 100644 --- a/gui/win_preferences.ui +++ b/gui/win_preferences.ui @@ -312,6 +312,11 @@ Please be aware that this option does NOT have any effect on 32-Bit systems. + Above Normal + + + + Normal diff --git a/src/model_jobList.cpp b/src/model_jobList.cpp index 40f9129..9c6a4fa 100644 --- a/src/model_jobList.cpp +++ b/src/model_jobList.cpp @@ -23,6 +23,7 @@ #include "model_jobList.h" #include "thread_encode.h" #include "model_options.h" +#include "model_preferences.h" #include "resource.h" #include @@ -30,7 +31,7 @@ #include -JobListModel::JobListModel(PreferencesDialog::Preferences *preferences) +JobListModel::JobListModel(PreferencesModel *preferences) { m_preferences = preferences; } @@ -487,7 +488,7 @@ void JobListModel::updateStatus(const QUuid &jobId, EncodeThread::JobStatus newS m_status.insert(jobId, newStatus); emit dataChanged(createIndex(index, 0), createIndex(index, 1)); - if(m_preferences->enableSounds) + if(m_preferences->enableSounds()) { switch(newStatus) { diff --git a/src/model_jobList.h b/src/model_jobList.h index 4791b7c..2774c6f 100644 --- a/src/model_jobList.h +++ b/src/model_jobList.h @@ -23,19 +23,20 @@ #include "thread_encode.h" #include "model_logFile.h" -#include "win_preferences.h" #include "QAbstractItemModel" #include #include #include +class PreferencesModel; + class JobListModel : public QAbstractItemModel { Q_OBJECT public: - JobListModel(PreferencesDialog::Preferences *preferences); + JobListModel(PreferencesModel *preferences); ~JobListModel(void); virtual int columnCount(const QModelIndex &parent) const; @@ -67,7 +68,7 @@ protected: QMap m_progress; QMap m_logFile; QMap m_details; - PreferencesDialog::Preferences *m_preferences; + PreferencesModel *m_preferences; public slots: void updateStatus(const QUuid &jobId, EncodeThread::JobStatus newStatus); diff --git a/src/model_preferences.cpp b/src/model_preferences.cpp new file mode 100644 index 0000000..e2abd50 --- /dev/null +++ b/src/model_preferences.cpp @@ -0,0 +1,88 @@ +/////////////////////////////////////////////////////////////////////////////// +// Simple x264 Launcher +// Copyright (C) 2004-2013 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 "model_preferences.h" + +#include "global.h" + +#include + +#include +#include +#include +#include + +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(); +} diff --git a/src/model_preferences.h b/src/model_preferences.h new file mode 100644 index 0000000..85fd650 --- /dev/null +++ b/src/model_preferences.h @@ -0,0 +1,75 @@ +/////////////////////////////////////////////////////////////////////////////// +// Simple x264 Launcher +// Copyright (C) 2004-2013 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 +/////////////////////////////////////////////////////////////////////////////// + +#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; +}; diff --git a/src/model_recently.cpp b/src/model_recently.cpp new file mode 100644 index 0000000..e42468f --- /dev/null +++ b/src/model_recently.cpp @@ -0,0 +1,73 @@ +/////////////////////////////////////////////////////////////////////////////// +// Simple x264 Launcher +// Copyright (C) 2004-2013 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 "model_recently.h" + +#include "global.h" + +#include +#include +#include + +#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(); + } +} diff --git a/src/model_recently.h b/src/model_recently.h new file mode 100644 index 0000000..18b8be2 --- /dev/null +++ b/src/model_recently.h @@ -0,0 +1,61 @@ +/////////////////////////////////////////////////////////////////////////////// +// Simple x264 Launcher +// Copyright (C) 2004-2013 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 +/////////////////////////////////////////////////////////////////////////////// + +#pragma once + +#include + +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; +}; diff --git a/src/thread_encode.cpp b/src/thread_encode.cpp index dbaf6c4..d47b483 100644 --- a/src/thread_encode.cpp +++ b/src/thread_encode.cpp @@ -23,7 +23,7 @@ #include "global.h" #include "model_options.h" -#include "win_preferences.h" +#include "model_preferences.h" #include "version.h" #include @@ -104,7 +104,7 @@ static const unsigned int REV_MULT = 10000; // 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_sourceFileName(sourceFileName), @@ -1114,24 +1114,10 @@ bool EncodeThread::startProcess(QProcess &process, const QString &program, const if(process.waitForStarted()) { Q_PID pid = process.pid(); - AssignProcessToJobObject(m_handle_jobObject, process.pid()->hProcess); if(pid != NULL) { - switch(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; - } + AssignProcessToJobObject(m_handle_jobObject, process.pid()->hProcess); + setPorcessPriority(process.pid()->hProcess, m_processPriority); } lock.unlock(); @@ -1226,3 +1212,28 @@ QString EncodeThread::sizeToString(qint64 size) 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; + } +} diff --git a/src/thread_encode.h b/src/thread_encode.h index 84ccf60..f943fd0 100644 --- a/src/thread_encode.h +++ b/src/thread_encode.h @@ -53,7 +53,7 @@ public: 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); QUuid getId(void) { return this->m_jobId; }; @@ -92,7 +92,7 @@ protected: const bool m_x264_x64; const bool m_x264_10bit; const bool m_avs2yuv_x64; - const unsigned int m_processPriority; + const int m_processPriority; //Flags volatile bool m_abort; @@ -133,6 +133,7 @@ protected: //Static functions static QString commandline2string(const QString &program, const QStringList &arguments); static QString sizeToString(qint64 size); + static void setPorcessPriority(void *processId, int priroity); signals: void statusChanged(const QUuid &jobId, EncodeThread::JobStatus newStatus); diff --git a/src/version.h b/src/version.h index bcab9dc..2862f9e 100644 --- a/src/version.h +++ b/src/version.h @@ -22,7 +22,7 @@ #define VER_X264_MAJOR 2 #define VER_X264_MINOR 1 #define VER_X264_PATCH 5 -#define VER_X264_BUILD 480 +#define VER_X264_BUILD 494 #define VER_X264_MINIMUM_REV 2282 #define VER_X264_CURRENT_API 133 diff --git a/src/win_addJob.cpp b/src/win_addJob.cpp index 6b00bef..de6931a 100644 --- a/src/win_addJob.cpp +++ b/src/win_addJob.cpp @@ -23,6 +23,7 @@ #include "global.h" #include "model_options.h" +#include "model_recently.h" #include "win_help.h" #include "win_editor.h" @@ -310,7 +311,7 @@ void AddJobDialog::showEvent(QShowEvent *event) 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)); buttonAccept->setFocus(); } @@ -460,10 +461,10 @@ void AddJobDialog::accept(void) } //Update recently used - m_recentlyUsed->filterIndex = currentOutputIndx(); - m_recentlyUsed->sourceDirectory = currentSourcePath(); - m_recentlyUsed->outputDirectory = currentOutputPath(); - saveRecentlyUsed(m_recentlyUsed); + m_recentlyUsed->setFilterIndex(currentOutputIndx()); + m_recentlyUsed->setSourceDirectory(currentSourcePath()); + m_recentlyUsed->setOutputDirectory(currentOutputPath()); + RecentlyUsed::saveRecentlyUsed(m_recentlyUsed); //Save options saveOptions(m_options); @@ -499,7 +500,7 @@ void AddJobDialog::browseButtonClicked(void) } if(tempIndex < 0) { - tempIndex = m_recentlyUsed->filterIndex; + tempIndex = m_recentlyUsed->filterIndex(); } filePath = QString("%1.%2").arg(filePath, getFilterExt(tempIndex)); } @@ -808,7 +809,7 @@ void AddJobDialog::saveOptions(OptionsModel *options) QString AddJobDialog::currentSourcePath(const bool bWithName) { - QString path = m_recentlyUsed->sourceDirectory; + QString path = m_recentlyUsed->sourceDirectory(); QString currentSourceFile = this->sourceFile(); if(!currentSourceFile.isEmpty()) @@ -829,7 +830,7 @@ QString AddJobDialog::currentSourcePath(const bool bWithName) QString AddJobDialog::currentOutputPath(const bool bWithName) { - QString path = m_recentlyUsed->outputDirectory; + QString path = m_recentlyUsed->outputDirectory(); QString currentOutputFile = this->outputFile(); if(!currentOutputFile.isEmpty()) @@ -850,7 +851,7 @@ QString AddJobDialog::currentOutputPath(const bool bWithName) int AddJobDialog::currentOutputIndx(void) { - int index = m_recentlyUsed->filterIndex; + int index = m_recentlyUsed->filterIndex(); QString currentOutputFile = this->outputFile(); if(!currentOutputFile.isEmpty()) @@ -870,58 +871,6 @@ int AddJobDialog::currentOutputIndx(void) // 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 name = QFileInfo(sourceFilePath).completeBaseName(); @@ -931,8 +880,7 @@ QString AddJobDialog::generateOutputFileName(const QString &sourceFilePath, cons if(!VALID_DIR(path)) { RecentlyUsed defaults; - initRecentlyUsed(&defaults); - path = defaults.outputDirectory; + path = defaults.outputDirectory(); } 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) { - const int count = ARRAY_SIZE(FILE_TYPE_FILTERS); + const int count = ARRAY_SIZE(X264_FILE_TYPE_FILTERS); 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) { - const int count = ARRAY_SIZE(FILE_TYPE_FILTERS); + const int count = ARRAY_SIZE(X264_FILE_TYPE_FILTERS); 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; } @@ -977,24 +925,24 @@ int AddJobDialog::getFilterIdx(const QString &fileExt) 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)) { - 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) { 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++) { - 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(";;"); diff --git a/src/win_addJob.h b/src/win_addJob.h index 78db156..2fef82f 100644 --- a/src/win_addJob.h +++ b/src/win_addJob.h @@ -26,20 +26,13 @@ #include class OptionsModel; +class RecentlyUsed; class AddJobDialog : public QDialog, private Ui::AddJobDialog { Q_OBJECT public: - typedef struct - { - QString sourceDirectory; - QString outputDirectory; - int filterIndex; - } - RecentlyUsed; - AddJobDialog(QWidget *parent, OptionsModel *options, RecentlyUsed *recentlyUsed, bool x64supported, bool use10BitEncoding, bool saveToSourceFolder); ~AddJobDialog(void); @@ -56,10 +49,6 @@ public: 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); diff --git a/src/win_main.cpp b/src/win_main.cpp index 05b4958..976f0a8 100644 --- a/src/win_main.cpp +++ b/src/win_main.cpp @@ -23,8 +23,12 @@ #include "model_jobList.h" #include "model_options.h" +#include "model_preferences.h" +#include "model_recently.h" #include "thread_avisynth.h" #include "taskbar7.h" +#include "win_addJob.h" +#include "win_preferences.h" #include "resource.h" #include @@ -67,6 +71,8 @@ MainWindow::MainWindow(const x264_cpu_t *const cpuFeatures) m_options(NULL), m_jobList(NULL), m_droppedFiles(NULL), + m_preferences(NULL), + m_recentlyUsed(NULL), m_firstShow(true) { //Init the dialog, from the .ui file @@ -79,12 +85,12 @@ MainWindow::MainWindow(const x264_cpu_t *const cpuFeatures) qRegisterMetaType("EncodeThread::JobStatus"); //Load preferences - PreferencesDialog::initPreferences(&m_preferences); - PreferencesDialog::loadPreferences(&m_preferences); + m_preferences = new PreferencesModel(); + PreferencesModel::loadPreferences(m_preferences); //Load recently used - AddJobDialog::initRecentlyUsed(&m_recentlyUsed); - AddJobDialog::loadRecentlyUsed(&m_recentlyUsed); + m_recentlyUsed = new RecentlyUsed(); + RecentlyUsed::loadRecentlyUsed(m_recentlyUsed); //Create options object m_options = new OptionsModel(); @@ -113,7 +119,7 @@ MainWindow::MainWindow(const x264_cpu_t *const cpuFeatures) } //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))); jobsView->setModel(m_jobList); @@ -203,6 +209,8 @@ MainWindow::~MainWindow(void) X264_DELETE(m_ipcThread); AvisynthCheckThread::unload(); + X264_DELETE(m_preferences); + X264_DELETE(m_recentlyUsed); } /////////////////////////////////////////////////////////////////////////////// @@ -215,7 +223,7 @@ MainWindow::~MainWindow(void) void 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; if(createJob(sourceFileName, outputFileName, m_options, runImmediately)) @@ -229,17 +237,17 @@ void MainWindow::addButtonPressed() */ 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()) { - m_recentlyUsed.sourceDirectory = QFileInfo(fileList.last()).absolutePath(); + m_recentlyUsed->setSourceDirectory(QFileInfo(fileList.last()).absolutePath()); if(fileList.count() > 1) { createJobMultiple(fileList); } 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; 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(m_preferences.autoRunNextJob) QTimer::singleShot(0, this, SLOT(launchNextJob())); - if(m_preferences.shutdownComputer) QTimer::singleShot(0, this, SLOT(shutdownComputer())); - if(m_preferences.saveLogFiles) saveLogFile(m_jobList->index(i, 1, QModelIndex())); + if(m_preferences->autoRunNextJob()) QTimer::singleShot(0, this, SLOT(launchNextJob())); + if(m_preferences->shutdownComputer()) QTimer::singleShot(0, this, SLOT(shutdownComputer())); + if(m_preferences->saveLogFiles()) saveLogFile(m_jobList->index(i, 1, QModelIndex())); } } } @@ -521,7 +529,7 @@ void MainWindow::showWebLink(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(); X264_DELETE(preferences); } @@ -535,7 +543,7 @@ void MainWindow::launchNextJob(void) 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!"); 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 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); if(!sourceFileName.isEmpty()) addDialog->setSourceFile(sourceFileName); @@ -1065,7 +1073,7 @@ bool MainWindow::createJobMultiple(const QStringList &filePathIn) //Add files individually 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; 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 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 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)) { return false; @@ -1108,9 +1116,9 @@ bool MainWindow::appendJob(const QString &sourceFileName, const QString &outputF options, QString("%1/toolset").arg(m_appDir), m_cpuFeatures->x64, - m_preferences.use10BitEncoding, - m_cpuFeatures->x64 && m_preferences.useAvisyth64Bit, - m_preferences.processPriority + m_preferences->use10BitEncoding(), + m_cpuFeatures->x64 && m_preferences->useAvisyth64Bit(), + m_preferences->processPriority() ); QModelIndex newIndex = m_jobList->insertJob(thrd); diff --git a/src/win_main.h b/src/win_main.h index 410c6ff..23bd88f 100644 --- a/src/win_main.h +++ b/src/win_main.h @@ -24,14 +24,13 @@ #include "uic_win_main.h" #include "thread_ipc.h" #include "thread_encode.h" -#include "win_preferences.h" -#include "win_addJob.h" -#include "global.h" class JobListModel; class OptionsModel; class QFile; class QLibrary; +class PreferencesModel; +class RecentlyUsed; class MainWindow: public QMainWindow, private Ui::MainWindow { @@ -60,8 +59,8 @@ private: QStringList *m_droppedFiles; QList m_toolsList; - PreferencesDialog::Preferences m_preferences; - AddJobDialog::RecentlyUsed m_recentlyUsed; + PreferencesModel *m_preferences; + RecentlyUsed *m_recentlyUsed; const x264_cpu_t *const m_cpuFeatures; const QString m_appDir; diff --git a/src/win_preferences.cpp b/src/win_preferences.cpp index c5912d3..0ab463c 100644 --- a/src/win_preferences.cpp +++ b/src/win_preferences.cpp @@ -22,6 +22,7 @@ #include "win_preferences.h" #include "global.h" +#include "model_preferences.h" #include #include @@ -34,7 +35,7 @@ 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), m_x64(x64) @@ -65,19 +66,19 @@ void PreferencesDialog::showEvent(QShowEvent *event) { if(event) QDialog::showEvent(event); - UPDATE_CHECKBOX(checkRunNextJob, m_preferences->autoRunNextJob); - UPDATE_CHECKBOX(checkShutdownComputer, m_preferences->shutdownComputer); - UPDATE_CHECKBOX(checkUse64BitAvs2YUV, m_preferences->useAvisyth64Bit); - UPDATE_CHECKBOX(checkSaveLogFiles, m_preferences->saveLogFiles); - UPDATE_CHECKBOX(checkSaveToSourceFolder, m_preferences->saveToSourcePath); - UPDATE_CHECKBOX(checkEnableSounds, m_preferences->enableSounds); + UPDATE_CHECKBOX(checkRunNextJob, m_preferences->autoRunNextJob()); + UPDATE_CHECKBOX(checkShutdownComputer, m_preferences->shutdownComputer()); + UPDATE_CHECKBOX(checkUse64BitAvs2YUV, m_preferences->useAvisyth64Bit()); + UPDATE_CHECKBOX(checkSaveLogFiles, m_preferences->saveLogFiles()); + UPDATE_CHECKBOX(checkSaveToSourceFolder, m_preferences->saveToSourcePath()); + UPDATE_CHECKBOX(checkEnableSounds, m_preferences->enableSounds()); checkUse10BitEncoding->blockSignals(true); - UPDATE_CHECKBOX(checkUse10BitEncoding, m_preferences->use10BitEncoding); + UPDATE_CHECKBOX(checkUse10BitEncoding, m_preferences->use10BitEncoding()); checkUse10BitEncoding->blockSignals(false); - spinBoxJobCount->setValue(m_preferences->maxRunningJobCount); - comboBoxPriority->setCurrentIndex(qBound(0U, m_preferences->processPriority, 2U)); + spinBoxJobCount->setValue(m_preferences->maxRunningJobCount()); + comboBoxPriority->setCurrentIndex(qBound(0, m_preferences->processPriority(), comboBoxPriority->count()-1)); checkUse64BitAvs2YUV->setEnabled(m_x64); labelUse64BitAvs2YUV->setEnabled(m_x64); @@ -117,23 +118,23 @@ void PreferencesDialog::emulateMouseEvent(QObject *object, QEvent *event, QWidge void PreferencesDialog::done(int n) { - m_preferences->autoRunNextJob = checkRunNextJob->isChecked(); - m_preferences->shutdownComputer = checkShutdownComputer->isChecked(); - m_preferences->use10BitEncoding = checkUse10BitEncoding->isChecked(); - m_preferences->useAvisyth64Bit = checkUse64BitAvs2YUV->isChecked(); - m_preferences->saveLogFiles = checkSaveLogFiles->isChecked(); - m_preferences->saveToSourcePath = checkSaveToSourceFolder->isChecked(); - m_preferences->maxRunningJobCount = spinBoxJobCount->value(); - m_preferences->processPriority = comboBoxPriority->currentIndex(); - m_preferences->enableSounds = checkEnableSounds->isChecked(); - - savePreferences(m_preferences); + m_preferences->setAutoRunNextJob(checkRunNextJob->isChecked()); + m_preferences->setShutdownComputer(checkShutdownComputer->isChecked()); + m_preferences->setUse10BitEncoding(checkUse10BitEncoding->isChecked()); + m_preferences->setUseAvisyth64Bit(checkUse64BitAvs2YUV->isChecked()); + m_preferences->setSaveLogFiles(checkSaveLogFiles->isChecked()); + m_preferences->setSaveToSourcePath(checkSaveToSourceFolder->isChecked()); + m_preferences->setMaxRunningJobCount(spinBoxJobCount->value()); + m_preferences->setProcessPriority(comboBoxPriority->currentIndex()); + m_preferences->setEnableSounds(checkEnableSounds->isChecked()); + + PreferencesModel::savePreferences(m_preferences); QDialog::done(n); } void PreferencesDialog::resetButtonPressed(void) { - initPreferences(m_preferences); + PreferencesModel::initPreferences(m_preferences); 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(); -} diff --git a/src/win_preferences.h b/src/win_preferences.h index b8cec96..6867398 100644 --- a/src/win_preferences.h +++ b/src/win_preferences.h @@ -23,42 +23,18 @@ #include "uic_win_preferences.h" +class PreferencesModel; + class PreferencesDialog : public QDialog, private Ui::PreferencesDialog { Q_OBJECT public: - enum - { - 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(QWidget *parent, PreferencesModel *preferences, bool x64); ~PreferencesDialog(void); const bool m_x64; - static void initPreferences(Preferences *preferences); - static void loadPreferences(Preferences *preferences); - static void savePreferences(Preferences *preferences); - protected: virtual void done(int n); virtual void showEvent(QShowEvent *event); @@ -67,7 +43,7 @@ protected: void emulateMouseEvent(QObject *object, QEvent *event, QWidget *source, QWidget *target); private: - Preferences *m_preferences; + PreferencesModel *m_preferences; private slots: void resetButtonPressed(void); diff --git a/x264_launcher_MSVC2012.vcxproj b/x264_launcher_MSVC2012.vcxproj index c4f29a1..9e24ad3 100644 --- a/x264_launcher_MSVC2012.vcxproj +++ b/x264_launcher_MSVC2012.vcxproj @@ -150,9 +150,7 @@ mkdir "$(TargetDir)\toolset\x86" mkdir "$(TargetDir)\toolset\x64" mkdir "$(TargetDir)\imageformats" 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\*.dll" "$(TargetDir)\toolset\x64\" copy /Y "$(QTDIR)\bin\QtCore4.dll" "$(TargetDir)" copy /Y "$(QTDIR)\bin\QtGui4.dll" "$(TargetDir)" copy /Y "$(QTDIR)\bin\QtSvg4.dll" "$(TargetDir)" @@ -285,6 +283,8 @@ copy /Y "$(QTDIR)\plugins\imageformats\qgif4.dll" "$(TargetDir)\imageformats" $(SolutionDir)tmp\moc\moc_%(Filename).cpp;%(Outputs) + + @@ -317,6 +317,8 @@ copy /Y "$(QTDIR)\plugins\imageformats\qgif4.dll" "$(TargetDir)\imageformats" + + false false diff --git a/x264_launcher_MSVC2012.vcxproj.filters b/x264_launcher_MSVC2012.vcxproj.filters index f52c306..789e62f 100644 --- a/x264_launcher_MSVC2012.vcxproj.filters +++ b/x264_launcher_MSVC2012.vcxproj.filters @@ -48,6 +48,12 @@ Header Files + + Header Files + + + Header Files + @@ -128,6 +134,12 @@ Generated Files + + Source Files + + + Source Files + -- 2.11.0