Store settings in an INI file
This commit is contained in:
parent
373e27b088
commit
c867f850e0
@ -337,6 +337,10 @@
|
||||
RelativePath=".\src\Model_MetaInfo.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Model_Settings.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Thread_FileAnalyzer.cpp"
|
||||
>
|
||||
@ -366,6 +370,36 @@
|
||||
<File
|
||||
RelativePath=".\src\Dialog_About.h"
|
||||
>
|
||||
<FileConfiguration
|
||||
Name="Debug|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
Description="MOC "$(SolutionDir)tmp\MOC_$(SafeInputName).cpp""
|
||||
CommandLine=""$(QTDIR)\bin\moc.exe" -o "$(SolutionDir)tmp\MOC_$(SafeInputName).cpp" "$(InputPath)""
|
||||
Outputs=""$(SolutionDir)tmp\MOC_$(SafeInputName).cpp""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
Description="MOC "$(SolutionDir)tmp\MOC_$(SafeInputName).cpp""
|
||||
CommandLine=""$(QTDIR)\bin\moc.exe" -o "$(SolutionDir)tmp\MOC_$(SafeInputName).cpp" "$(InputPath)""
|
||||
Outputs=""$(SolutionDir)tmp\MOC_$(SafeInputName).cpp""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
<FileConfiguration
|
||||
Name="Release_Static|Win32"
|
||||
>
|
||||
<Tool
|
||||
Name="VCCustomBuildTool"
|
||||
Description="MOC "$(SolutionDir)tmp\MOC_$(SafeInputName).cpp""
|
||||
CommandLine=""$(QTDIR)\bin\moc.exe" -o "$(SolutionDir)tmp\MOC_$(SafeInputName).cpp" "$(InputPath)""
|
||||
Outputs=""$(SolutionDir)tmp\MOC_$(SafeInputName).cpp""
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Dialog_MainWindow.h"
|
||||
@ -587,6 +621,10 @@
|
||||
/>
|
||||
</FileConfiguration>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Model_Settings.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
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"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\tmp\MOC_Dialog_About.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tmp\MOC_Dialog_MainWindow.cpp"
|
||||
>
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include <QPushButton>
|
||||
#include <QDesktopServices>
|
||||
#include <QUrl>
|
||||
#include <QTimer>
|
||||
|
||||
//Win32 includes
|
||||
#include <Windows.h>
|
||||
@ -80,6 +81,8 @@ AboutDialog::AboutDialog(QWidget *parent, bool firstStart)
|
||||
QPushButton *firstButton = addButton("Show License Text", QMessageBox::AcceptRole);
|
||||
firstButton->setIcon(QIcon(":/icons/script_edit.png"));
|
||||
firstButton->setMinimumWidth(135);
|
||||
firstButton->disconnect();
|
||||
connect(firstButton, SIGNAL(clicked()), this, SLOT(openLicenseText()));
|
||||
|
||||
QPushButton *secondButton = addButton("Accept License", QMessageBox::AcceptRole);
|
||||
secondButton->setIcon(QIcon(":/icons/accept.png"));
|
||||
@ -88,16 +91,21 @@ AboutDialog::AboutDialog(QWidget *parent, bool firstStart)
|
||||
QPushButton *thirdButton = addButton("Decline License", QMessageBox::AcceptRole);
|
||||
thirdButton->setIcon(QIcon(":/icons/delete.png"));
|
||||
thirdButton->setMinimumWidth(120);
|
||||
thirdButton->setEnabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
QPushButton *firstButton = addButton("More About...", QMessageBox::AcceptRole);
|
||||
firstButton->setIcon(QIcon(":/icons/information.png"));
|
||||
firstButton->setMinimumWidth(120);
|
||||
firstButton->disconnect();
|
||||
connect(firstButton, SIGNAL(clicked()), this, SLOT(showMoreAbout()));
|
||||
|
||||
QPushButton *secondButton = addButton("About Qt...", QMessageBox::AcceptRole);
|
||||
secondButton->setIcon(QIcon(":/images/Qt.svg"));
|
||||
secondButton->setMinimumWidth(120);
|
||||
secondButton->disconnect();
|
||||
connect(secondButton, SIGNAL(clicked()), this, SLOT(showAboutQt()));
|
||||
|
||||
QPushButton *thirdButton = addButton("Discard", QMessageBox::AcceptRole);
|
||||
thirdButton->setIcon(QIcon(":/icons/cross.png"));
|
||||
@ -119,49 +127,47 @@ int AboutDialog::exec()
|
||||
{
|
||||
PlaySound(MAKEINTRESOURCE(IDR_WAVE_ABOUT), GetModuleHandle(NULL), SND_RESOURCE | SND_ASYNC);
|
||||
|
||||
if(m_firstShow)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
switch(QMessageBox::exec())
|
||||
{
|
||||
case 0:
|
||||
QDesktopServices::openUrl(QUrl("http://www.gnu.org/licenses/gpl-2.0.txt"));
|
||||
break;
|
||||
case 1:
|
||||
return 1;
|
||||
break;
|
||||
default:
|
||||
case 2:
|
||||
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;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
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 += "<br></ul></div>";
|
||||
|
||||
QMessageBox *moreAboutBox = new QMessageBox(dynamic_cast<QWidget*>(this->parent()));
|
||||
QMessageBox *moreAboutBox = new QMessageBox(this);
|
||||
moreAboutBox->setText(moreAboutText);
|
||||
moreAboutBox->setIconPixmap(dynamic_cast<QApplication*>(QApplication::instance())->windowIcon().pixmap(QSize(64,64)));
|
||||
|
||||
@ -197,3 +203,28 @@ void AboutDialog::showMoreAbout()
|
||||
|
||||
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
|
||||
////////////////////////////////////////////////////////////
|
||||
|
@ -24,15 +24,24 @@
|
||||
|
||||
class AboutDialog : public QMessageBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AboutDialog(QWidget *parent = 0, bool firstStart = false);
|
||||
~AboutDialog(void);
|
||||
|
||||
public slots:
|
||||
int exec();
|
||||
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:
|
||||
void AboutDialog::showMoreAbout();
|
||||
bool m_firstShow;
|
||||
};
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "Thread_FileAnalyzer.h"
|
||||
#include "Thread_MessageHandler.h"
|
||||
#include "Model_MetaInfo.h"
|
||||
#include "Model_Settings.h"
|
||||
|
||||
//Qt includes
|
||||
#include <QMessageBox>
|
||||
@ -78,6 +79,9 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
setWindowTitle(windowTitle().append(" [DEMO VERSION]"));
|
||||
}
|
||||
|
||||
//Load configuration
|
||||
m_settings = new SettingsModel();
|
||||
|
||||
//Enabled main buttons
|
||||
connect(buttonAbout, SIGNAL(clicked()), this, SLOT(aboutButtonClicked()));
|
||||
connect(buttonStart, SIGNAL(clicked()), this, SLOT(encodeButtonClicked()));
|
||||
@ -214,6 +218,7 @@ MainWindow::~MainWindow(void)
|
||||
LAMEXP_DELETE(m_delayedFileTimer);
|
||||
LAMEXP_DELETE(m_metaData);
|
||||
LAMEXP_DELETE(m_metaInfoModel);
|
||||
LAMEXP_DELETE(m_settings);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -269,16 +274,28 @@ void MainWindow::windowShown(void)
|
||||
{
|
||||
QStringList arguments = QApplication::arguments();
|
||||
|
||||
if(m_settings->licenseAccepted() <= 0)
|
||||
{
|
||||
int iAccepted = -1;
|
||||
|
||||
if(m_settings->licenseAccepted() == 0)
|
||||
{
|
||||
AboutDialog *about = new AboutDialog(this, true);
|
||||
int iAccepted = about->exec();
|
||||
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
|
||||
if(lamexp_check_tool("neroAacEnc.exe") && lamexp_check_tool("neroAacDec.exe") && lamexp_check_tool("neroAacTag.exe"))
|
||||
{
|
||||
|
@ -31,6 +31,7 @@ class WorkingBanner;
|
||||
class MessageHandlerThread;
|
||||
class AudioFileModel;
|
||||
class MetaInfoModel;
|
||||
class SettingsModel;
|
||||
|
||||
class MainWindow: public QMainWindow, private Ui::MainWindow
|
||||
{
|
||||
@ -84,4 +85,5 @@ private:
|
||||
QTimer *m_delayedFileTimer;
|
||||
AudioFileModel *m_metaData;
|
||||
MetaInfoModel *m_metaInfoModel;
|
||||
SettingsModel *m_settings;
|
||||
};
|
||||
|
60
src/Model_Settings.cpp
Normal file
60
src/Model_Settings.cpp
Normal 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
40
src/Model_Settings.h
Normal 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;
|
||||
};
|
Loading…
Reference in New Issue
Block a user