2014-06-06 16:00:42 +02:00
|
|
|
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
|
|
|
*
|
|
|
|
* Copyright 2013-2014, Teo Mrnjavac <teo@kde.org>
|
|
|
|
*
|
|
|
|
* Originally from Tomahawk, portions:
|
|
|
|
* Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org>
|
|
|
|
* Copyright 2010-2011, Leo Franchi <lfranchi@kde.org>
|
|
|
|
* Copyright 2010-2012, Jeff Mitchell <jeff@tomahawk-player.org>
|
|
|
|
*
|
|
|
|
* Calamares 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares 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 Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "CalamaresUtils.h"
|
|
|
|
|
2014-06-26 14:18:32 +02:00
|
|
|
#include "CalamaresConfig.h"
|
2014-06-13 16:40:42 +02:00
|
|
|
|
2014-06-06 16:00:42 +02:00
|
|
|
#include <QCoreApplication>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QLocale>
|
|
|
|
#include <QTranslator>
|
|
|
|
|
|
|
|
namespace CalamaresUtils
|
|
|
|
{
|
|
|
|
|
2014-07-28 18:11:24 +02:00
|
|
|
static QDir s_appDataDir;
|
|
|
|
|
|
|
|
void
|
|
|
|
setAppDataDir( const QDir& dir )
|
|
|
|
{
|
|
|
|
s_appDataDir = dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-06 16:00:42 +02:00
|
|
|
QDir
|
|
|
|
appDataDir()
|
|
|
|
{
|
2014-07-28 18:11:24 +02:00
|
|
|
if ( s_appDataDir.path().isEmpty() )
|
|
|
|
{
|
|
|
|
s_appDataDir = QDir( CMAKE_INSTALL_FULL_DATADIR );
|
|
|
|
if ( !s_appDataDir.exists() || !s_appDataDir.isReadable() )
|
|
|
|
s_appDataDir.mkpath( s_appDataDir.absolutePath() );
|
|
|
|
}
|
2014-06-06 16:00:42 +02:00
|
|
|
|
2014-07-28 18:11:24 +02:00
|
|
|
return s_appDataDir;
|
2014-06-06 16:00:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-24 13:35:21 +02:00
|
|
|
QDir
|
|
|
|
systemLibDir()
|
|
|
|
{
|
|
|
|
QDir path( CMAKE_INSTALL_FULL_LIBDIR );
|
|
|
|
return path;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-06-06 16:00:42 +02:00
|
|
|
QDir
|
|
|
|
appLogDir()
|
|
|
|
{
|
|
|
|
return appDataDir();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
installTranslator( QObject* parent )
|
|
|
|
{
|
|
|
|
QString locale = QLocale::system().uiLanguages().first().replace( "-", "_" );
|
|
|
|
|
|
|
|
if ( locale == "C" )
|
|
|
|
locale = "en";
|
|
|
|
|
|
|
|
// Calamares translations
|
|
|
|
QTranslator* translator = new QTranslator( parent );
|
|
|
|
if ( translator->load( QString( ":/lang/calamares_" ) + locale ) )
|
|
|
|
{
|
|
|
|
qDebug() << "Translation: Calamares: Using system locale:" << locale;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug() << "Translation: Calamares: Using default locale, system locale one not found:" << locale;
|
|
|
|
translator->load( QString( ":/lang/calamares_en" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
QCoreApplication::installTranslator( translator );
|
|
|
|
|
|
|
|
// Qt translations
|
|
|
|
translator = new QTranslator( parent );
|
|
|
|
if ( translator->load( QString( ":/lang/qt_" ) + locale ) )
|
|
|
|
{
|
|
|
|
qDebug() << "Translation: Qt: Using system locale:" << locale;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
qDebug() << "Translation: Qt: Using default locale, system locale one not found:" << locale;
|
|
|
|
}
|
|
|
|
|
|
|
|
QCoreApplication::installTranslator( translator );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|