Added "Preferences" dialog.

This commit is contained in:
LoRd_MuldeR 2012-02-03 00:53:14 +01:00
parent 6121903aa0
commit c81b23c81e
10 changed files with 309 additions and 16 deletions

View File

@ -476,9 +476,6 @@
</property>
</action>
<action name="actionPreferences">
<property name="enabled">
<bool>false</bool>
</property>
<property name="icon">
<iconset resource="../res/resources.qrc">
<normaloff>:/buttons/wrench.png</normaloff>:/buttons/wrench.png</iconset>

122
gui/win_preferences.ui Normal file
View File

@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PreferencesDialog</class>
<widget class="QDialog" name="PreferencesDialog">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>393</width>
<height>134</height>
</rect>
</property>
<property name="windowTitle">
<string>Preferences</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string> Preferences </string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QCheckBox" name="checkRunNextJob">
<property name="text">
<string>Automatically launch next job when a running job completes</string>
</property>
</widget>
</item>
<item row="0" column="0">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>8</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="closeButton">
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>Close</string>
</property>
<property name="icon">
<iconset resource="../res/resources.qrc">
<normaloff>:/buttons/accept.png</normaloff>:/buttons/accept.png</iconset>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../res/resources.qrc"/>
</resources>
<connections>
<connection>
<sender>closeButton</sender>
<signal>clicked()</signal>
<receiver>PreferencesDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>339</x>
<y>157</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>89</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@ -209,7 +209,10 @@ void AddJobDialog::showEvent(QShowEvent *event)
QDialog::showEvent(event);
templateSelected();
if(!editSource->text().isEmpty())
if(!editSource->text().isEmpty()) initialDir_src = QFileInfo(QDir::fromNativeSeparators(editSource->text())).path();
if(!editOutput->text().isEmpty()) initialDir_out = QFileInfo(QDir::fromNativeSeparators(editOutput->text())).path();
if((!editSource->text().isEmpty()) && editOutput->text().isEmpty())
{
generateOutputFileName(QDir::fromNativeSeparators(editSource->text()));
buttonAccept->setFocus();

View File

@ -52,7 +52,6 @@ protected:
QString initialDir_src;
QString initialDir_out;
virtual void showEvent(QShowEvent *event);
virtual bool eventFilter(QObject *o, QEvent *e);

View File

@ -25,6 +25,7 @@
#include "model_jobList.h"
#include "model_options.h"
#include "win_addJob.h"
#include "win_preferences.h"
#include <QDate>
#include <QTimer>
@ -61,6 +62,10 @@ MainWindow::MainWindow(bool x64supported)
qRegisterMetaType<QUuid>("QUuid");
qRegisterMetaType<EncodeThread::JobStatus>("EncodeThread::JobStatus");
//Load preferences
memset(&m_preferences, 0, sizeof(PreferencesDialog::Preferences));
PreferencesDialog::loadPreferences(&m_preferences);
//Freeze minimum size
setMinimumSize(size());
splitter->setSizes(QList<int>() << 16 << 196);
@ -70,8 +75,7 @@ MainWindow::MainWindow(bool x64supported)
labelBuildDate->installEventFilter(this);
setWindowTitle(QString("%1 (%2 Mode)").arg(windowTitle(), m_x64supported ? "64-Bit" : "32-Bit"));
if(x264_is_prerelease()) setWindowTitle(QString("%1 | PRE-RELEASE VERSION").arg(windowTitle()));
//Create model
m_jobList = new JobListModel();
connect(m_jobList, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(jobChangedData(QModelIndex, QModelIndex)));
@ -110,6 +114,7 @@ MainWindow::MainWindow(bool x64supported)
connect(actionWebJarod, SIGNAL(triggered()), this, SLOT(showWebLink()));
connect(actionWebWiki, SIGNAL(triggered()), this, SLOT(showWebLink()));
connect(actionWebBluRay, SIGNAL(triggered()), this, SLOT(showWebLink()));
connect(actionPreferences, SIGNAL(triggered()), this, SLOT(showPreferences()));
//Create floating label
m_label = new QLabel(jobsView);
@ -271,7 +276,7 @@ void MainWindow::jobChangedData(const QModelIndex &topLeft, const QModelIndex &
qDebug("Current job changed status!");
updateButtons(status);
}
if(status == EncodeThread::JobStatus_Completed)
if((status == EncodeThread::JobStatus_Completed) && m_preferences.autoRunNextJob)
{
QTimer::singleShot(0, this, SLOT(launchNextJob()));
}
@ -353,18 +358,21 @@ void MainWindow::showWebLink(void)
if(QObject::sender() == actionWebBluRay) QDesktopServices::openUrl(QUrl("http://www.x264bluray.com/"));
}
void MainWindow::showPreferences(void)
{
PreferencesDialog *preferences = new PreferencesDialog(this, &m_preferences);
preferences->exec();
X264_DELETE(preferences);
}
void MainWindow::launchNextJob(void)
{
const int rows = m_jobList->rowCount(QModelIndex());
for(int i = 0; i < rows; i++)
if(haveRunningJobs())
{
EncodeThread::JobStatus status = m_jobList->getJobStatus(m_jobList->index(i, 0, QModelIndex()));
if(status == EncodeThread::JobStatus_Running || status == EncodeThread::JobStatus_Running_Pass1 || status == EncodeThread::JobStatus_Running_Pass2)
{
qWarning("Still have a job running, won't launch next yet!");
return;
}
qWarning("Still have a job running, won't launch next yet!");
return;
}
for(int i = 0; i < rows; i++)
@ -372,7 +380,10 @@ void MainWindow::launchNextJob(void)
EncodeThread::JobStatus status = m_jobList->getJobStatus(m_jobList->index(i, 0, QModelIndex()));
if(status == EncodeThread::JobStatus_Enqueued)
{
m_jobList->startJob(m_jobList->index(i, 0, QModelIndex()));
if(m_jobList->startJob(m_jobList->index(i, 0, QModelIndex())))
{
jobsView->selectRow(i);
}
return;
}
}

View File

@ -23,6 +23,7 @@
#include "uic_win_main.h"
#include "thread_encode.h"
#include "win_preferences.h"
class JobListModel;
class OptionsModel;
@ -51,6 +52,8 @@ private:
JobListModel *m_jobList;
OptionsModel *m_options;
QList<QFile*> m_toolsList;
PreferencesDialog::Preferences m_preferences;
const bool m_x64supported;
const QString m_appDir;
@ -72,6 +75,7 @@ private slots:
void launchNextJob(void);
void pauseButtonPressed(bool checked);
void showAbout(void);
void showPreferences(void);
void showWebLink(void);
void startButtonPressed(void);
void updateLabel(void);

77
src/win_preferences.cpp Normal file
View File

@ -0,0 +1,77 @@
///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
// Copyright (C) 2004-2012 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 "win_preferences.h"
#include "global.h"
#include <QSettings>
#include <QDesktopServices>
PreferencesDialog::PreferencesDialog(QWidget *parent, Preferences *preferences)
:
QDialog(parent)
{
setupUi(this);
setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint));
setFixedSize(size());
HMENU hMenu = GetSystemMenu((HWND) winId(), FALSE);
EnableMenuItem(hMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
m_preferences = preferences;
}
PreferencesDialog::~PreferencesDialog(void)
{
}
void PreferencesDialog::showEvent(QShowEvent *event)
{
checkRunNextJob->setChecked(m_preferences->autoRunNextJob);
}
void PreferencesDialog::accept(void)
{
m_preferences->autoRunNextJob = checkRunNextJob->isChecked();
savePreferences(m_preferences);
QDialog::accept();
}
void PreferencesDialog::loadPreferences(Preferences *preferences)
{
const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
QSettings settings(QString("%1/preferences.ini").arg(appDir), QSettings::IniFormat);
settings.beginGroup("preferences");
preferences->autoRunNextJob = settings.value("auto_run_next_job", QVariant(true)).toBool();
}
void PreferencesDialog::savePreferences(Preferences *preferences)
{
const QString appDir = QDesktopServices::storageLocation(QDesktopServices::DataLocation);
QSettings settings(QString("%1/preferences.ini").arg(appDir), QSettings::IniFormat);
settings.beginGroup("preferences");
settings.setValue("auto_run_next_job", preferences->autoRunNextJob);
settings.sync();
}

49
src/win_preferences.h Normal file
View File

@ -0,0 +1,49 @@
///////////////////////////////////////////////////////////////////////////////
// Simple x264 Launcher
// Copyright (C) 2004-2012 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 "uic_win_preferences.h"
class PreferencesDialog : public QDialog, private Ui::PreferencesDialog
{
Q_OBJECT
public:
typedef struct
{
bool autoRunNextJob;
}
Preferences;
PreferencesDialog(QWidget *parent, Preferences *preferences);
~PreferencesDialog(void);
static void loadPreferences(Preferences *preferences);
static void savePreferences(Preferences *preferences);
protected:
virtual void accept(void);
virtual void showEvent(QShowEvent *event);
private:
Preferences *m_preferences;
};

View File

@ -143,6 +143,15 @@ copy "$(SolutionDir)res\toolset\*.exe" "$(SolutionDir)bin\$(Configuration)\tools
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)tmp\uic\uic_%(Filename).h;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)tmp\uic\uic_%(Filename).h;%(Outputs)</Outputs>
</CustomBuild>
<CustomBuild Include="gui\win_preferences.ui">
<FileType>Document</FileType>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(QTDIR)\bin\uic.exe" -o "$(SolutionDir)tmp\uic\uic_%(Filename).h" "%(FullPath)"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(QTDIR)\bin\uic.exe" -o "$(SolutionDir)tmp\uic\uic_%(Filename).h" "%(FullPath)"</Command>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">UIC "$(SolutionDir)tmp\uic\uic_%(Filename).h"</Message>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">UIC "$(SolutionDir)tmp\uic\uic_%(Filename).h"</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)tmp\uic\uic_%(Filename).h;%(Outputs)</Outputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)tmp\uic\uic_%(Filename).h;%(Outputs)</Outputs>
</CustomBuild>
<None Include="ReadMe.txt" />
<CustomBuild Include="res\resources.qrc">
<FileType>Document</FileType>
@ -157,6 +166,14 @@ copy "$(SolutionDir)res\toolset\*.exe" "$(SolutionDir)bin\$(Configuration)\tools
<None Include="res\icons\movie.ico" />
</ItemGroup>
<ItemGroup>
<CustomBuild Include="src\win_preferences.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(QTDIR)\bin\moc.exe" -o "$(SolutionDir)tmp\moc\moc_%(Filename).cpp" "%(FullPath)"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(QTDIR)\bin\moc.exe" -o "$(SolutionDir)tmp\moc\moc_%(Filename).cpp" "%(FullPath)"</Command>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">MOC "$(SolutionDir)tmp\moc\moc_%(Filename).cpp"</Message>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">MOC "$(SolutionDir)tmp\moc\moc_%(Filename).cpp"</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|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 Include="src\win_help.h">
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">"$(QTDIR)\bin\moc.exe" -o "$(SolutionDir)tmp\moc\moc_%(Filename).cpp" "%(FullPath)"</Command>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">"$(QTDIR)\bin\moc.exe" -o "$(SolutionDir)tmp\moc\moc_%(Filename).cpp" "%(FullPath)"</Command>
@ -221,12 +238,14 @@ copy "$(SolutionDir)res\toolset\*.exe" "$(SolutionDir)bin\$(Configuration)\tools
<ClCompile Include="src\win_addJob.cpp" />
<ClCompile Include="src\win_help.cpp" />
<ClCompile Include="src\win_main.cpp" />
<ClCompile Include="src\win_preferences.cpp" />
<ClCompile Include="tmp\moc\moc_model_jobList.cpp" />
<ClCompile Include="tmp\moc\moc_model_logFile.cpp" />
<ClCompile Include="tmp\moc\moc_thread_encode.cpp" />
<ClCompile Include="tmp\moc\moc_win_addJob.cpp" />
<ClCompile Include="tmp\moc\moc_win_help.cpp" />
<ClCompile Include="tmp\moc\moc_win_main.cpp" />
<ClCompile Include="tmp\moc\moc_win_preferences.cpp" />
<ClCompile Include="tmp\qrc\qrc_resources.cpp" />
</ItemGroup>
<ItemGroup>

View File

@ -92,6 +92,12 @@
<ClCompile Include="tmp\moc\moc_win_help.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
<ClCompile Include="src\win_preferences.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="tmp\moc\moc_win_preferences.cpp">
<Filter>Generated Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="gui\win_main.ui">
@ -124,6 +130,12 @@
<CustomBuild Include="src\win_help.h">
<Filter>Header Files</Filter>
</CustomBuild>
<CustomBuild Include="gui\win_preferences.ui">
<Filter>Dialogs</Filter>
</CustomBuild>
<CustomBuild Include="src\win_preferences.h">
<Filter>Header Files</Filter>
</CustomBuild>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="x264_launcher.rc">