Store settings in an INI file

This commit is contained in:
LoRd_MuldeR 2010-11-12 19:02:01 +01:00
parent 373e27b088
commit c867f850e0
7 changed files with 248 additions and 47 deletions

View File

@ -337,6 +337,10 @@
RelativePath=".\src\Model_MetaInfo.cpp" RelativePath=".\src\Model_MetaInfo.cpp"
> >
</File> </File>
<File
RelativePath=".\src\Model_Settings.cpp"
>
</File>
<File <File
RelativePath=".\src\Thread_FileAnalyzer.cpp" RelativePath=".\src\Thread_FileAnalyzer.cpp"
> >
@ -366,6 +370,36 @@
<File <File
RelativePath=".\src\Dialog_About.h" RelativePath=".\src\Dialog_About.h"
> >
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCustomBuildTool"
Description="MOC &quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot;"
CommandLine="&quot;$(QTDIR)\bin\moc.exe&quot; -o &quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot; &quot;$(InputPath)&quot;"
Outputs="&quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCustomBuildTool"
Description="MOC &quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot;"
CommandLine="&quot;$(QTDIR)\bin\moc.exe&quot; -o &quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot; &quot;$(InputPath)&quot;"
Outputs="&quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot;"
/>
</FileConfiguration>
<FileConfiguration
Name="Release_Static|Win32"
>
<Tool
Name="VCCustomBuildTool"
Description="MOC &quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot;"
CommandLine="&quot;$(QTDIR)\bin\moc.exe&quot; -o &quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot; &quot;$(InputPath)&quot;"
Outputs="&quot;$(SolutionDir)tmp\MOC_$(SafeInputName).cpp&quot;"
/>
</FileConfiguration>
</File> </File>
<File <File
RelativePath=".\src\Dialog_MainWindow.h" RelativePath=".\src\Dialog_MainWindow.h"
@ -587,6 +621,10 @@
/> />
</FileConfiguration> </FileConfiguration>
</File> </File>
<File
RelativePath=".\src\Model_Settings.h"
>
</File>
<File <File
RelativePath=".\src\Resource.h" RelativePath=".\src\Resource.h"
> >
@ -737,6 +775,10 @@
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav" Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
> >
<File
RelativePath=".\tmp\MOC_Dialog_About.cpp"
>
</File>
<File <File
RelativePath=".\tmp\MOC_Dialog_MainWindow.cpp" RelativePath=".\tmp\MOC_Dialog_MainWindow.cpp"
> >

View File

@ -31,6 +31,7 @@
#include <QPushButton> #include <QPushButton>
#include <QDesktopServices> #include <QDesktopServices>
#include <QUrl> #include <QUrl>
#include <QTimer>
//Win32 includes //Win32 includes
#include <Windows.h> #include <Windows.h>
@ -80,6 +81,8 @@ AboutDialog::AboutDialog(QWidget *parent, bool firstStart)
QPushButton *firstButton = addButton("Show License Text", QMessageBox::AcceptRole); QPushButton *firstButton = addButton("Show License Text", QMessageBox::AcceptRole);
firstButton->setIcon(QIcon(":/icons/script_edit.png")); firstButton->setIcon(QIcon(":/icons/script_edit.png"));
firstButton->setMinimumWidth(135); firstButton->setMinimumWidth(135);
firstButton->disconnect();
connect(firstButton, SIGNAL(clicked()), this, SLOT(openLicenseText()));
QPushButton *secondButton = addButton("Accept License", QMessageBox::AcceptRole); QPushButton *secondButton = addButton("Accept License", QMessageBox::AcceptRole);
secondButton->setIcon(QIcon(":/icons/accept.png")); secondButton->setIcon(QIcon(":/icons/accept.png"));
@ -88,16 +91,21 @@ AboutDialog::AboutDialog(QWidget *parent, bool firstStart)
QPushButton *thirdButton = addButton("Decline License", QMessageBox::AcceptRole); QPushButton *thirdButton = addButton("Decline License", QMessageBox::AcceptRole);
thirdButton->setIcon(QIcon(":/icons/delete.png")); thirdButton->setIcon(QIcon(":/icons/delete.png"));
thirdButton->setMinimumWidth(120); thirdButton->setMinimumWidth(120);
thirdButton->setEnabled(false);
} }
else else
{ {
QPushButton *firstButton = addButton("More About...", QMessageBox::AcceptRole); QPushButton *firstButton = addButton("More About...", QMessageBox::AcceptRole);
firstButton->setIcon(QIcon(":/icons/information.png")); firstButton->setIcon(QIcon(":/icons/information.png"));
firstButton->setMinimumWidth(120); firstButton->setMinimumWidth(120);
firstButton->disconnect();
connect(firstButton, SIGNAL(clicked()), this, SLOT(showMoreAbout()));
QPushButton *secondButton = addButton("About Qt...", QMessageBox::AcceptRole); QPushButton *secondButton = addButton("About Qt...", QMessageBox::AcceptRole);
secondButton->setIcon(QIcon(":/images/Qt.svg")); secondButton->setIcon(QIcon(":/images/Qt.svg"));
secondButton->setMinimumWidth(120); secondButton->setMinimumWidth(120);
secondButton->disconnect();
connect(secondButton, SIGNAL(clicked()), this, SLOT(showAboutQt()));
QPushButton *thirdButton = addButton("Discard", QMessageBox::AcceptRole); QPushButton *thirdButton = addButton("Discard", QMessageBox::AcceptRole);
thirdButton->setIcon(QIcon(":/icons/cross.png")); thirdButton->setIcon(QIcon(":/icons/cross.png"));
@ -119,49 +127,47 @@ int AboutDialog::exec()
{ {
PlaySound(MAKEINTRESOURCE(IDR_WAVE_ABOUT), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC); PlaySound(MAKEINTRESOURCE(IDR_WAVE_ABOUT), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC);
if(m_firstShow) switch(QMessageBox::exec())
{ {
while(1) case 1:
{ return 1;
switch(QMessageBox::exec()) break;
{ case 2:
case 0: return -1;
QDesktopServices::openUrl(QUrl("http://www.gnu.org/licenses/gpl-2.0.txt")); break;
break; default:
case 1: return 0;
return 1; break;
break;
default:
return -1;
}
}
} }
else
{
while(1)
{
switch(QMessageBox::exec())
{
case 0:
showMoreAbout();
break;
case 1:
QMessageBox::aboutQt(dynamic_cast<QWidget*>(this->parent()));
break;
default:
return 0;
}
}
}
return 0;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Private Functions // Slots
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void AboutDialog::showMoreAbout() void AboutDialog::enableButtons(void)
{
const QList<QAbstractButton*> buttonList = buttons();
for(int i = 0; i < buttonList.count(); i++)
{
buttonList.at(i)->setEnabled(true);
}
setCursor(QCursor(Qt::ArrowCursor));
}
void AboutDialog::openLicenseText(void)
{
QDesktopServices::openUrl(QUrl("http://www.gnu.org/licenses/gpl-2.0.txt"));
}
void AboutDialog::showAboutQt(void)
{
QMessageBox::aboutQt(this);
}
void AboutDialog::showMoreAbout(void)
{ {
QString moreAboutText; QString moreAboutText;
moreAboutText += "<h3>The following third-party software is used in LameXP:</h3>"; moreAboutText += "<h3>The following third-party software is used in LameXP:</h3>";
@ -184,7 +190,7 @@ void AboutDialog::showMoreAbout()
moreAboutText += LINK("http://mediainfo.sourceforge.net/"); moreAboutText += LINK("http://mediainfo.sourceforge.net/");
moreAboutText += "<br></ul></div>"; moreAboutText += "<br></ul></div>";
QMessageBox *moreAboutBox = new QMessageBox(dynamic_cast<QWidget*>(this->parent())); QMessageBox *moreAboutBox = new QMessageBox(this);
moreAboutBox->setText(moreAboutText); moreAboutBox->setText(moreAboutText);
moreAboutBox->setIconPixmap(dynamic_cast<QApplication*>(QApplication::instance())->windowIcon().pixmap(QSize(64,64))); moreAboutBox->setIconPixmap(dynamic_cast<QApplication*>(QApplication::instance())->windowIcon().pixmap(QSize(64,64)));
@ -197,3 +203,28 @@ void AboutDialog::showMoreAbout()
LAMEXP_DELETE(moreAboutBox); LAMEXP_DELETE(moreAboutBox);
} }
////////////////////////////////////////////////////////////
// Protected Functions
////////////////////////////////////////////////////////////
void AboutDialog::showEvent(QShowEvent *e)
{
QDialog::showEvent(e);
if(m_firstShow)
{
const QList<QAbstractButton*> buttonList = buttons();
for(int i = 1; i < buttonList.count(); i++)
{
buttonList.at(i)->setEnabled(false);
}
QTimer::singleShot(5000, this, SLOT(enableButtons()));
setCursor(QCursor(Qt::WaitCursor));
}
}
////////////////////////////////////////////////////////////
// Private Functions
////////////////////////////////////////////////////////////

View File

@ -24,15 +24,24 @@
class AboutDialog : public QMessageBox class AboutDialog : public QMessageBox
{ {
Q_OBJECT
public: public:
AboutDialog(QWidget *parent = 0, bool firstStart = false); AboutDialog(QWidget *parent = 0, bool firstStart = false);
~AboutDialog(void); ~AboutDialog(void);
public slots:
int exec();
static const char *neroAacUrl; static const char *neroAacUrl;
public slots:
int exec();
void enableButtons(void);
void openLicenseText(void);
void showMoreAbout(void);
void showAboutQt(void);
protected:
void showEvent(QShowEvent *e);
private: private:
void AboutDialog::showMoreAbout();
bool m_firstShow; bool m_firstShow;
}; };

View File

@ -30,6 +30,7 @@
#include "Thread_FileAnalyzer.h" #include "Thread_FileAnalyzer.h"
#include "Thread_MessageHandler.h" #include "Thread_MessageHandler.h"
#include "Model_MetaInfo.h" #include "Model_MetaInfo.h"
#include "Model_Settings.h"
//Qt includes //Qt includes
#include <QMessageBox> #include <QMessageBox>
@ -78,6 +79,9 @@ MainWindow::MainWindow(QWidget *parent)
setWindowTitle(windowTitle().append(" [DEMO VERSION]")); setWindowTitle(windowTitle().append(" [DEMO VERSION]"));
} }
//Load configuration
m_settings = new SettingsModel();
//Enabled main buttons //Enabled main buttons
connect(buttonAbout, SIGNAL(clicked()), this, SLOT(aboutButtonClicked())); connect(buttonAbout, SIGNAL(clicked()), this, SLOT(aboutButtonClicked()));
connect(buttonStart, SIGNAL(clicked()), this, SLOT(encodeButtonClicked())); connect(buttonStart, SIGNAL(clicked()), this, SLOT(encodeButtonClicked()));
@ -214,6 +218,7 @@ MainWindow::~MainWindow(void)
LAMEXP_DELETE(m_delayedFileTimer); LAMEXP_DELETE(m_delayedFileTimer);
LAMEXP_DELETE(m_metaData); LAMEXP_DELETE(m_metaData);
LAMEXP_DELETE(m_metaInfoModel); LAMEXP_DELETE(m_metaInfoModel);
LAMEXP_DELETE(m_settings);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -269,14 +274,26 @@ void MainWindow::windowShown(void)
{ {
QStringList arguments = QApplication::arguments(); QStringList arguments = QApplication::arguments();
AboutDialog *about = new AboutDialog(this, true); if(m_settings->licenseAccepted() <= 0)
int iAccepted = about->exec();
LAMEXP_DELETE(about);
if(iAccepted <= 0)
{ {
QApplication::quit(); int iAccepted = -1;
return;
if(m_settings->licenseAccepted() == 0)
{
AboutDialog *about = new AboutDialog(this, true);
iAccepted = about->exec();
LAMEXP_DELETE(about);
}
if(iAccepted <= 0)
{
m_settings->setLicenseAccepted(-1);
QMessageBox::critical(this, "License Declined", "You have declined the license. Consequently the application will exit now!");
QApplication::quit();
return;
}
m_settings->setLicenseAccepted(1);
} }
//Check for AAC support //Check for AAC support

View File

@ -31,6 +31,7 @@ class WorkingBanner;
class MessageHandlerThread; class MessageHandlerThread;
class AudioFileModel; class AudioFileModel;
class MetaInfoModel; class MetaInfoModel;
class SettingsModel;
class MainWindow: public QMainWindow, private Ui::MainWindow class MainWindow: public QMainWindow, private Ui::MainWindow
{ {
@ -84,4 +85,5 @@ private:
QTimer *m_delayedFileTimer; QTimer *m_delayedFileTimer;
AudioFileModel *m_metaData; AudioFileModel *m_metaData;
MetaInfoModel *m_metaInfoModel; MetaInfoModel *m_metaInfoModel;
SettingsModel *m_settings;
}; };

60
src/Model_Settings.cpp Normal file
View File

@ -0,0 +1,60 @@
///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
// Copyright (C) 2004-2010 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_Settings.h"
#include "Global.h"
#include <QSettings>
#include <QDesktopServices>
#include <QApplication>
static const char *g_settingsVersionNumber = "VersionNumber";
static const char *g_settingsLicenseAccepted = "LicenseAccepted";
////////////////////////////////////////////////////////////
// Constructor
////////////////////////////////////////////////////////////
SettingsModel::SettingsModel(void)
{
qDebug(QDesktopServices::storageLocation(QDesktopServices::DataLocation).toUtf8().constData());
m_settings = new QSettings(QDesktopServices::storageLocation(QDesktopServices::DataLocation).append("/config.ini"), QSettings::IniFormat);
m_settings->beginGroup(QString().sprintf("LameXP_%u%02u%05u", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build()));
m_settings->setValue(g_settingsVersionNumber, QApplication::applicationVersion());
m_settings->sync();
}
////////////////////////////////////////////////////////////
// Destructor
////////////////////////////////////////////////////////////
SettingsModel::~SettingsModel(void)
{
LAMEXP_DELETE(m_settings);
}
////////////////////////////////////////////////////////////
// Public Functions
////////////////////////////////////////////////////////////
int SettingsModel::licenseAccepted(void) { return m_settings->value(g_settingsLicenseAccepted, 0).toInt(); }
void SettingsModel::setLicenseAccepted(int value) { m_settings->setValue(g_settingsLicenseAccepted, value); }

40
src/Model_Settings.h Normal file
View File

@ -0,0 +1,40 @@
///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
// Copyright (C) 2004-2010 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 QSettings;
class SettingsModel
{
public:
SettingsModel(void);
~SettingsModel(void);
//Getters
int licenseAccepted(void);
//Setters
void setLicenseAccepted(int value);
private:
QSettings *m_settings;
};