1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
/****************************************************************************
Copyright (C) 2005 - 2011 Filipe AZEVEDO & The Monkey Studio Team
http://monkeystudio.org licensing under the GNU GPL.
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 St, Fifth Floor, Boston, MA 02110-1301 USA
****************************************************************************/
#include "pSettings.h"
#include <QApplication>
#include <QDir>
#include <QFile>
#include <QMainWindow>
QString pSettings::mProgramName;
QString pSettings::mProgramVersion;
/*!
\details Construct a new pSettings
\param parent The object parent
\param name The settings name
\param version The settings version.
*/
pSettings::pSettings( QObject* parent, const QString& name, const QString& version )
: QSettings( getIniFile( name, version ), QSettings::IniFormat, parent )
{}
/*!
\details Initialize the default settings name and version
\param name The settings name
\param version The settings version
*/
void pSettings::setIniInformations( const QString& name, const QString& version )
{
mProgramName = name;
mProgramVersion = version;
}
/*!
\details Return the default name
*/
QString pSettings::programName()
{ return mProgramName; }
/*!
\details Return the default version
*/
QString pSettings::programVersion()
{ return mProgramVersion; }
/*!
\details Return a filePath for storing the ini file according to it's parameters
\param name The settings name
\param version The settings version
\return
*/
QString pSettings::getIniFile( const QString& name, const QString& version )
{
#ifdef Q_OS_MAC
return QDir::toNativeSeparators( QString( "%1/../%2 %3.ini" ).arg( QApplication::applicationDirPath() ).arg( name ).arg( version ) );
#elif defined Q_OS_WIN
return QDir::toNativeSeparators( QString( "%1/%2 %3.ini" ).arg( QApplication::applicationDirPath() ).arg( name ).arg( version ) );
#else
return QDir::toNativeSeparators( QString( "%1/.%2/%3 %4.ini" ).arg( QDir::homePath() ).arg( mProgramName ).arg( name ).arg( version ) );
#endif
}
/*!
\details Restore a main winow state
\param window The main window to restore
*/
void pSettings::restoreState( QMainWindow* window )
{
if ( !window )
return;
window->restoreGeometry( value( "MainWindow/Geometry" ).toByteArray() );
window->restoreState( value( "MainWindow/State" ).toByteArray() );
if ( value( "MainWindow/Geometry" ).toByteArray().isEmpty() )
window->showMaximized();
}
/*!
\details Save a main winow state
\param window The main window to save
*/
void pSettings::saveState( QMainWindow* window )
{
if ( !window )
return;
setValue( "MainWindow/Geometry", window->saveGeometry() );
setValue( "MainWindow/State", window->saveState() );
}
/*!
\details A virtual member that you can reimplement for creating a default settings member
*/
void pSettings::setDefaultSettings()
{}
|