mirror of
https://github.com/QuasarApp/installer-framework.git
synced 2025-05-21 09:09:33 +00:00
MAke use of QSettingsWrapper. Remove from original source.
This commit is contained in:
parent
610f247601
commit
fc0613de6a
@ -33,7 +33,6 @@
|
||||
#include "elevatedexecuteoperation.h"
|
||||
|
||||
#include "environment.h"
|
||||
#include "fsengineclient.h"
|
||||
#include "common/utils.h"
|
||||
#include "qprocesswrapper.h"
|
||||
|
||||
|
@ -31,16 +31,12 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
#include "environmentvariablesoperation.h"
|
||||
#include "qsettingswrapper.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <QtCore/QSettings>
|
||||
|
||||
#include "KDUpdater/environment.h"
|
||||
|
||||
// this makes us use QSettingsWrapper
|
||||
#include "fsengineclient.h"
|
||||
|
||||
#ifdef Q_WS_WIN
|
||||
# include <windows.h>
|
||||
#endif
|
||||
@ -92,7 +88,7 @@ UpdateOperation::Error writeSetting(const QString ®Path,
|
||||
QString *errorString,
|
||||
QString *oldValue) {
|
||||
oldValue->clear();
|
||||
SettingsType registry(regPath, QSettings::NativeFormat);
|
||||
SettingsType registry(regPath, QSettingsWrapper::NativeFormat);
|
||||
if (!registry.isWritable()) {
|
||||
*errorString = QObject::tr("Registry path %1 is not writable").arg(regPath);
|
||||
return UpdateOperation::UserDefinedError;
|
||||
@ -105,7 +101,7 @@ UpdateOperation::Error writeSetting(const QString ®Path,
|
||||
registry.setValue(name, value);
|
||||
registry.sync();
|
||||
|
||||
if(registry.status() != QSettings::NoError) {
|
||||
if(registry.status() != QSettingsWrapper::NoError) {
|
||||
*errorString = QObject::tr("Could not write to registry path %1").arg(regPath);
|
||||
return UpdateOperation::UserDefinedError;
|
||||
}
|
||||
@ -121,7 +117,7 @@ UpdateOperation::Error undoSetting(const QString ®Path,
|
||||
QString *errorString) {
|
||||
QString actual;
|
||||
{
|
||||
SettingsType registry(regPath, QSettings::NativeFormat);
|
||||
SettingsType registry(regPath, QSettingsWrapper::NativeFormat);
|
||||
actual = registry.value(name).toString();
|
||||
}
|
||||
if (actual != value) //key changed, don't undo
|
||||
@ -162,7 +158,7 @@ bool EnvironmentVariableOperation::performOperation()
|
||||
|
||||
err = isSystemWide
|
||||
? writeSetting<QSettingsWrapper>(regPath, name, value, &errorString, &oldvalue)
|
||||
: writeSetting<QSettings>(regPath, name, value, &errorString, &oldvalue);
|
||||
: writeSetting<QSettingsWrapper>(regPath, name, value, &errorString, &oldvalue);
|
||||
if (err != NoError) {
|
||||
setError(err);
|
||||
setErrorString(errorString);
|
||||
@ -215,7 +211,7 @@ bool EnvironmentVariableOperation::undoOperation()
|
||||
|
||||
const Error err = isSystemWide
|
||||
? undoSetting<QSettingsWrapper>(regPath, name, value, oldvalue, &errorString)
|
||||
: undoSetting<QSettings>(regPath, name, value, oldvalue, &errorString);
|
||||
: undoSetting<QSettingsWrapper>(regPath, name, value, oldvalue, &errorString);
|
||||
|
||||
if (err != NoError) {
|
||||
setError(err);
|
||||
|
@ -32,8 +32,6 @@
|
||||
**************************************************************************/
|
||||
#include "fsengineclient.h"
|
||||
|
||||
#undef QSettings
|
||||
|
||||
#include "adminauthorization.h"
|
||||
#include "templates.cpp"
|
||||
|
||||
@ -889,246 +887,4 @@ void FSEngineClientHandler::Private::maybeStopServer()
|
||||
serverStarted = false;
|
||||
}
|
||||
|
||||
class QSettingsWrapper::Private
|
||||
{
|
||||
public:
|
||||
Private( const QString& organization, const QString& application )
|
||||
: native( true ),
|
||||
settings( organization, application ),
|
||||
socket( 0 )
|
||||
{
|
||||
}
|
||||
Private( QSettings::Scope scope, const QString& organization, const QString& application )
|
||||
: native( true ),
|
||||
settings( scope, organization, application ),
|
||||
socket( 0 )
|
||||
{
|
||||
}
|
||||
Private( QSettings::Format format, QSettings::Scope scope, const QString& organization, const QString& application )
|
||||
: native( format == QSettings::NativeFormat ),
|
||||
settings( format, scope, organization, application ),
|
||||
socket( 0 )
|
||||
{
|
||||
}
|
||||
Private( const QString& fileName, QSettings::Format format )
|
||||
: native( format == QSettings::NativeFormat ),
|
||||
fileName( fileName ),
|
||||
settings( fileName, format ),
|
||||
socket( 0 )
|
||||
{
|
||||
}
|
||||
Private()
|
||||
: native( true ),
|
||||
socket( 0 )
|
||||
{
|
||||
}
|
||||
|
||||
bool createSocket()
|
||||
{
|
||||
if( !native || !FSEngineClientHandler::instance()->isActive() )
|
||||
return false;
|
||||
if( socket != 0 && socket->state() == static_cast< int >( QLocalSocket::ConnectedState ) )
|
||||
return true;
|
||||
if( socket != 0 )
|
||||
delete socket;
|
||||
#ifdef FSENGINE_TCP
|
||||
socket = new QTcpSocket;
|
||||
#else
|
||||
socket = new QLocalSocket;
|
||||
#endif
|
||||
if( !FSEngineClientHandler::instance()->connect( socket ) )
|
||||
return false;
|
||||
stream.setDevice( socket );
|
||||
stream.setVersion( QDataStream::Qt_4_2 );
|
||||
|
||||
stream << QString::fromLatin1( "createQSettings" );
|
||||
stream << this->fileName;
|
||||
socket->flush();
|
||||
stream.device()->waitForReadyRead( -1 );
|
||||
quint32 test;
|
||||
stream >> test;
|
||||
stream.device()->readAll();
|
||||
return true;
|
||||
}
|
||||
|
||||
const bool native;
|
||||
const QString fileName;
|
||||
QSettings settings;
|
||||
#ifdef FSENGINE_TCP
|
||||
mutable QTcpSocket* socket;
|
||||
#else
|
||||
mutable QLocalSocket* socket;
|
||||
#endif
|
||||
mutable QDataStream stream;
|
||||
};
|
||||
|
||||
QSettingsWrapper::QSettingsWrapper( const QString& organization, const QString& application, QObject* parent )
|
||||
: QObject( parent ),
|
||||
d( new Private( organization, application ) )
|
||||
{
|
||||
}
|
||||
|
||||
QSettingsWrapper::QSettingsWrapper( QSettingsWrapper::Scope scope, const QString& organization, const QString& application, QObject* parent )
|
||||
: QObject( parent ),
|
||||
d( new Private( static_cast< QSettings::Scope >( scope ), organization, application ) )
|
||||
{
|
||||
}
|
||||
|
||||
QSettingsWrapper::QSettingsWrapper( QSettingsWrapper::Format format, QSettingsWrapper::Scope scope, const QString& organization, const QString& application, QObject* parent )
|
||||
: QObject( parent ),
|
||||
d( new Private( static_cast< QSettings::Format >( format ), static_cast< QSettings::Scope >( scope ), organization, application ) )
|
||||
{
|
||||
}
|
||||
|
||||
QSettingsWrapper::QSettingsWrapper( const QString& fileName, QSettingsWrapper::Format format, QObject* parent )
|
||||
: QObject( parent ),
|
||||
d( new Private( fileName, static_cast< QSettings::Format >( format ) ) )
|
||||
{
|
||||
}
|
||||
|
||||
QSettingsWrapper::QSettingsWrapper( QObject* parent )
|
||||
: QObject( parent ),
|
||||
d( new Private )
|
||||
{
|
||||
}
|
||||
|
||||
QSettingsWrapper::~QSettingsWrapper()
|
||||
{
|
||||
if( d->socket != 0 )
|
||||
{
|
||||
d->stream << QString::fromLatin1( "destroyQSettings" );
|
||||
d->socket->flush();
|
||||
quint32 result;
|
||||
d->stream >> result;
|
||||
|
||||
if( QThread::currentThread() == d->socket->thread() )
|
||||
{
|
||||
d->socket->close();
|
||||
delete d->socket;
|
||||
}
|
||||
else
|
||||
{
|
||||
d->socket->deleteLater();
|
||||
}
|
||||
}
|
||||
delete d;
|
||||
}
|
||||
|
||||
#define RETURN_NO_ARGS_CONST( RESULT, NAME ) \
|
||||
RESULT QSettingsWrapper::NAME() const \
|
||||
{ \
|
||||
if( d->createSocket() ) \
|
||||
return callRemoteMethod< RESULT >( d->stream, QLatin1String( "QSettings::"#NAME ) ); \
|
||||
else \
|
||||
return static_cast< RESULT >( d->settings.NAME() ); \
|
||||
}
|
||||
|
||||
#define RETURN_ONE_ARG( RESULT, NAME, TYPE1 ) \
|
||||
RESULT QSettingsWrapper::NAME( TYPE1 param1 ) \
|
||||
{ \
|
||||
if( d->createSocket() ) \
|
||||
return callRemoteMethod< RESULT >( d->stream, QLatin1String( "QSettings::"#NAME ), param1 ); \
|
||||
else \
|
||||
return d->settings.NAME( param1 ); \
|
||||
}
|
||||
|
||||
#define RETURN_ONE_ARG_CONST( RESULT, NAME, TYPE1 ) \
|
||||
RESULT QSettingsWrapper::NAME( TYPE1 param1 ) const \
|
||||
{ \
|
||||
if( d->createSocket() ) \
|
||||
return callRemoteMethod< RESULT >( d->stream, QLatin1String( "QSettings::"#NAME ), param1 ); \
|
||||
else \
|
||||
return d->settings.NAME( param1 ); \
|
||||
}
|
||||
|
||||
#define RETURN_TWO_ARGS_CONST( RESULT, NAME, TYPE1, TYPE2 ) \
|
||||
RESULT QSettingsWrapper::NAME( TYPE1 param1, TYPE2 param2 ) const \
|
||||
{ \
|
||||
if( d->createSocket() ) \
|
||||
return callRemoteMethod< RESULT >( d->stream, QLatin1String( "QSettings::"#NAME ), param1, param2 ); \
|
||||
else \
|
||||
return d->settings.NAME( param1, param2 ); \
|
||||
}
|
||||
|
||||
#define VOID_NO_ARGS( NAME ) \
|
||||
void QSettingsWrapper::NAME() \
|
||||
{ \
|
||||
if( d->createSocket() ) \
|
||||
callRemoteVoidMethod<void>( d->stream, QLatin1String( "QSettings::"#NAME ) ); \
|
||||
else \
|
||||
d->settings.NAME(); \
|
||||
}
|
||||
|
||||
#define VOID_ONE_ARG( NAME, TYPE1 ) \
|
||||
void QSettingsWrapper::NAME( TYPE1 param1 ) \
|
||||
{ \
|
||||
if( d->createSocket() ) \
|
||||
callRemoteVoidMethod( d->stream, QLatin1String( "QSettings::"#NAME ), param1 ); \
|
||||
else \
|
||||
d->settings.NAME( param1 ); \
|
||||
}
|
||||
|
||||
#define VOID_TWO_ARGS( NAME, TYPE1, TYPE2 ) \
|
||||
void QSettingsWrapper::NAME( TYPE1 param1, TYPE2 param2 ) \
|
||||
{ \
|
||||
if( d->createSocket() ) \
|
||||
callRemoteVoidMethod( d->stream, QLatin1String( "QSettings::"#NAME ), param1, param2 ); \
|
||||
else \
|
||||
d->settings.NAME( param1, param2 ); \
|
||||
}
|
||||
|
||||
RETURN_NO_ARGS_CONST( QStringList, allKeys )
|
||||
RETURN_NO_ARGS_CONST( QString, applicationName )
|
||||
VOID_ONE_ARG( beginGroup, const QString& )
|
||||
RETURN_ONE_ARG( int, beginReadArray, const QString& )
|
||||
VOID_TWO_ARGS( beginWriteArray, const QString&, int )
|
||||
RETURN_NO_ARGS_CONST( QStringList, childGroups )
|
||||
RETURN_NO_ARGS_CONST( QStringList, childKeys )
|
||||
VOID_NO_ARGS( clear )
|
||||
RETURN_ONE_ARG_CONST( bool, contains, const QString& )
|
||||
VOID_NO_ARGS( endArray )
|
||||
VOID_NO_ARGS( endGroup )
|
||||
RETURN_NO_ARGS_CONST( bool, fallbacksEnabled )
|
||||
RETURN_NO_ARGS_CONST( QString, fileName )
|
||||
|
||||
QSettingsWrapper::Format QSettingsWrapper::format() const
|
||||
{
|
||||
return static_cast< QSettingsWrapper::Format >( d->settings.format() );
|
||||
}
|
||||
|
||||
RETURN_NO_ARGS_CONST( QString, group )
|
||||
|
||||
QTextCodec* QSettingsWrapper::iniCodec() const
|
||||
{
|
||||
return d->settings.iniCodec();
|
||||
}
|
||||
|
||||
RETURN_NO_ARGS_CONST( bool, isWritable )
|
||||
RETURN_NO_ARGS_CONST( QString, organizationName )
|
||||
VOID_ONE_ARG( remove, const QString& )
|
||||
|
||||
QSettingsWrapper::Scope QSettingsWrapper::scope() const
|
||||
{
|
||||
return static_cast< QSettingsWrapper::Scope >( d->settings.scope() );
|
||||
}
|
||||
|
||||
VOID_ONE_ARG( setArrayIndex, int )
|
||||
VOID_ONE_ARG( setFallbacksEnabled, bool )
|
||||
|
||||
void QSettingsWrapper::setIniCodec( QTextCodec* codec )
|
||||
{
|
||||
d->settings.setIniCodec( codec );
|
||||
}
|
||||
|
||||
void QSettingsWrapper::setIniCodec( const char* codecName )
|
||||
{
|
||||
d->settings.setIniCodec( codecName );
|
||||
}
|
||||
|
||||
VOID_TWO_ARGS( setValue, const QString&, const QVariant& )
|
||||
RETURN_NO_ARGS_CONST( QSettingsWrapper::Status, status );
|
||||
VOID_NO_ARGS( sync )
|
||||
RETURN_TWO_ARGS_CONST( QVariant, value, const QString&, const QVariant& )
|
||||
|
||||
#include "moc_fsengineclient.cpp"
|
||||
#include "fsengineclient.moc"
|
||||
|
@ -81,71 +81,4 @@ private:
|
||||
Private* d;
|
||||
};
|
||||
|
||||
class INSTALLER_EXPORT QSettingsWrapper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum Format
|
||||
{
|
||||
NativeFormat,
|
||||
IniFormat,
|
||||
InvalidFormat
|
||||
};
|
||||
|
||||
enum Status
|
||||
{
|
||||
NoError,
|
||||
AccessError,
|
||||
FormatError
|
||||
};
|
||||
|
||||
enum Scope
|
||||
{
|
||||
UserScope,
|
||||
SystemScope
|
||||
};
|
||||
|
||||
explicit QSettingsWrapper( const QString& organization, const QString& application = QString(), QObject* parent = 0 );
|
||||
QSettingsWrapper( QSettingsWrapper::Scope scope, const QString& organization, const QString& application = QString(), QObject* parent = 0 );
|
||||
QSettingsWrapper( QSettingsWrapper::Format format, QSettingsWrapper::Scope scope, const QString& organization, const QString& application = QString(), QObject* parent = 0 );
|
||||
QSettingsWrapper( const QString& fileName, QSettingsWrapper::Format format, QObject* parent = 0 );
|
||||
explicit QSettingsWrapper( QObject* parent = 0 );
|
||||
~QSettingsWrapper();
|
||||
|
||||
QStringList allKeys() const;
|
||||
QString applicationName() const;
|
||||
void beginGroup( const QString& prefix );
|
||||
int beginReadArray( const QString& prefix );
|
||||
void beginWriteArray( const QString& prefix, int size = -1 );
|
||||
QStringList childGroups() const;
|
||||
QStringList childKeys() const;
|
||||
void clear();
|
||||
bool contains( const QString& key ) const;
|
||||
void endArray();
|
||||
void endGroup();
|
||||
bool fallbacksEnabled() const;
|
||||
QString fileName() const;
|
||||
QSettingsWrapper::Format format() const;
|
||||
QString group() const;
|
||||
QTextCodec* iniCodec() const;
|
||||
bool isWritable() const;
|
||||
QString organizationName() const;
|
||||
void remove( const QString& key );
|
||||
QSettingsWrapper::Scope scope() const;
|
||||
void setArrayIndex( int i );
|
||||
void setFallbacksEnabled( bool b );
|
||||
void setIniCodec( QTextCodec* codec );
|
||||
void setIniCodec( const char* codecName );
|
||||
void setValue( const QString& key, const QVariant& value );
|
||||
QSettingsWrapper::Status status() const;
|
||||
void sync();
|
||||
QVariant value( const QString& key, const QVariant& defaultValue = QVariant() ) const;
|
||||
|
||||
private:
|
||||
class Private;
|
||||
Private* d;
|
||||
};
|
||||
|
||||
#define QSettings QSettingsWrapper
|
||||
|
||||
#endif
|
||||
|
@ -31,7 +31,7 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
#include "globalsettingsoperation.h"
|
||||
#include "fsengineclient.h"
|
||||
#include "qsettingswrapper.h"
|
||||
|
||||
using namespace QInstaller;
|
||||
|
||||
@ -65,7 +65,7 @@ bool GlobalSettingsOperation::performOperation()
|
||||
settings->setValue(key, value);
|
||||
settings->sync();
|
||||
|
||||
if (settings->status() != QSettings::NoError) {
|
||||
if (settings->status() != QSettingsWrapper::NoError) {
|
||||
setError(UserDefinedError);
|
||||
setErrorString(tr("Failed to write settings"));
|
||||
return false;
|
||||
@ -118,7 +118,7 @@ QSettingsWrapper* GlobalSettingsOperation::setup(QString *key, QString *value,
|
||||
const QString &filename = arguments.at(0);
|
||||
*key = arguments.at(1);
|
||||
*value = arguments.at(2);
|
||||
return new QSettingsWrapper(filename, QSettings::NativeFormat);
|
||||
return new QSettingsWrapper(filename, QSettingsWrapper::NativeFormat);
|
||||
}
|
||||
|
||||
setError(InvalidArguments);
|
||||
|
@ -46,6 +46,7 @@
|
||||
#include "qinstallercomponent.h"
|
||||
#include "qinstallerglobal.h"
|
||||
#include "qprocesswrapper.h"
|
||||
#include "qsettingswrapper.h"
|
||||
|
||||
#include <QtCore/QTemporaryFile>
|
||||
|
||||
@ -546,7 +547,7 @@ void Installer::rollBackInstallation()
|
||||
|
||||
bool Installer::isFileExtensionRegistered(const QString& extension) const
|
||||
{
|
||||
QSettings settings(QLatin1String("HKEY_CLASSES_ROOT"), QSettings::NativeFormat);
|
||||
QSettingsWrapper settings(QLatin1String("HKEY_CLASSES_ROOT"), QSettingsWrapper::NativeFormat);
|
||||
return settings.value(QString::fromLatin1(".%1/Default").arg(extension)).isValid();
|
||||
}
|
||||
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "qinstaller.h"
|
||||
#include "qinstallercomponent.h"
|
||||
#include "qprocesswrapper.h"
|
||||
#include "qsettingswrapper.h"
|
||||
|
||||
#include <KDToolsCore/KDSaveFile>
|
||||
#include <KDToolsCore/KDSelfRestarter>
|
||||
@ -348,8 +349,8 @@ void InstallerPrivate::initialize()
|
||||
m_vars.insert(QLatin1String("TargetDir"), replaceVariables(m_installerSettings->targetDir()));
|
||||
m_vars.insert(QLatin1String("RemoveTargetDir"), replaceVariables(m_installerSettings->removeTargetDir()));
|
||||
|
||||
QSettings creatorSettings(QSettings::IniFormat, QSettings::UserScope, QLatin1String("Nokia"),
|
||||
QLatin1String("QtCreator"));
|
||||
QSettingsWrapper creatorSettings(QSettingsWrapper::IniFormat, QSettingsWrapper::UserScope,
|
||||
QLatin1String("Nokia"), QLatin1String("QtCreator"));
|
||||
QFileInfo info(creatorSettings.fileName());
|
||||
if (info.exists())
|
||||
m_vars.insert(QLatin1String("QtCreatorSettingsFile"), info.absoluteFilePath());
|
||||
@ -477,7 +478,7 @@ QString InstallerPrivate::uninstallerName() const
|
||||
void InstallerPrivate::readUninstallerIniFile(const QString &targetDir)
|
||||
{
|
||||
const QString iniPath = targetDir + QLatin1Char('/') + m_installerSettings->uninstallerIniFile();
|
||||
QSettings cfg(iniPath, QSettings::IniFormat);
|
||||
QSettingsWrapper cfg(iniPath, QSettingsWrapper::IniFormat);
|
||||
const QVariantHash vars = cfg.value(QLatin1String("Variables")).toHash();
|
||||
QHash<QString, QVariant>::ConstIterator it = vars.constBegin();
|
||||
while (it != vars.constEnd()) {
|
||||
@ -643,7 +644,7 @@ void InstallerPrivate::writeUninstaller(QVector<KDUpdater::UpdateOperation*> per
|
||||
{
|
||||
// write current state (variables) to the uninstaller ini file
|
||||
const QString iniPath = targetDir() + QLatin1Char('/') + m_installerSettings->uninstallerIniFile();
|
||||
QSettings cfg(iniPath, QSettings::IniFormat);
|
||||
QSettingsWrapper cfg(iniPath, QSettingsWrapper::IniFormat);
|
||||
QVariantHash vars;
|
||||
QHash<QString, QString>::ConstIterator it = m_vars.constBegin();
|
||||
while (it != m_vars.constEnd()) {
|
||||
@ -660,8 +661,8 @@ void InstallerPrivate::writeUninstaller(QVector<KDUpdater::UpdateOperation*> per
|
||||
cfg.setValue(QLatin1String("Repositories"), list);
|
||||
|
||||
cfg.sync();
|
||||
if (cfg.status() != QSettings::NoError) {
|
||||
const QString reason = cfg.status() == QSettings::AccessError ? tr("Access error")
|
||||
if (cfg.status() != QSettingsWrapper::NoError) {
|
||||
const QString reason = cfg.status() == QSettingsWrapper::AccessError ? tr("Access error")
|
||||
: tr("Format error");
|
||||
throw Error(tr("Could not write installer configuration to %1: %2").arg(iniPath, reason));
|
||||
}
|
||||
@ -1475,7 +1476,7 @@ void InstallerPrivate::deleteUninstaller()
|
||||
void InstallerPrivate::registerUninstaller()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
QSettings settings(registerPath(), QSettings::NativeFormat);
|
||||
QSettingsWrapper settings(registerPath(), QSettingsWrapper::NativeFormat);
|
||||
settings.setValue(QLatin1String("DisplayName"), m_vars.value(QLatin1String("ProductName")));
|
||||
settings.setValue(QLatin1String("DisplayVersion"), m_vars.value(QLatin1String("ProductVersion")));
|
||||
const QString uninstaller = QDir::toNativeSeparators(uninstallerName());
|
||||
@ -1496,7 +1497,7 @@ void InstallerPrivate::registerUninstaller()
|
||||
void InstallerPrivate::unregisterUninstaller()
|
||||
{
|
||||
#ifdef Q_OS_WIN
|
||||
QSettings settings(registerPath(), QSettings::NativeFormat);
|
||||
QSettingsWrapper settings(registerPath(), QSettingsWrapper::NativeFormat);
|
||||
settings.remove(QString());
|
||||
#endif
|
||||
}
|
||||
|
@ -31,13 +31,13 @@
|
||||
**
|
||||
**************************************************************************/
|
||||
#include "registerdocumentationoperation.h"
|
||||
#include "fsengineclient.h"
|
||||
|
||||
#include "qsettingswrapper.h"
|
||||
|
||||
#include <QHelpEngine>
|
||||
#include <QString>
|
||||
#include <QFileInfo>
|
||||
#include <QDir>
|
||||
#include <QSettings>
|
||||
#include <QDebug>
|
||||
|
||||
using namespace QInstaller;
|
||||
@ -63,23 +63,25 @@ namespace {
|
||||
// If the system settings are writable, don't touch the user settings.
|
||||
// The reason is that a doc registered while running with sudo could otherwise create
|
||||
// a root-owned configuration file a user directory.
|
||||
QScopedPointer<QSettings> settings(new QSettings(QSettings::IniFormat, QSettings::SystemScope, QLatin1String("Nokia"), QLatin1String("QtCreator")));
|
||||
QScopedPointer<QSettingsWrapper> settings(new QSettingsWrapper(QSettingsWrapper::IniFormat,
|
||||
QSettingsWrapper::SystemScope, QLatin1String("Nokia"), QLatin1String("QtCreator")));
|
||||
|
||||
// QSettings::isWritable isn't reliable enough in 4.7, determine writability experimentally
|
||||
// QSettingsWrapper::isWritable isn't reliable enough in 4.7, determine writability experimentally
|
||||
settings->setValue(QLatin1String("iswritable"), QLatin1String("accomplished"));
|
||||
settings->sync();
|
||||
if (settings->status() == QSettings::NoError) {
|
||||
if (settings->status() == QSettingsWrapper::NoError) {
|
||||
// we can use the system settings
|
||||
if (settings->contains(QLatin1String("iswritable")))
|
||||
settings->remove(QLatin1String("iswritable"));
|
||||
} else {
|
||||
// we have to use user settings
|
||||
settings.reset(new QSettings(QSettings::IniFormat, QSettings::UserScope, QLatin1String("Nokia"), QLatin1String("QtCreator")));
|
||||
settings.reset(new QSettingsWrapper(QSettingsWrapper::IniFormat, QSettingsWrapper::UserScope,
|
||||
QLatin1String("Nokia"), QLatin1String("QtCreator")));
|
||||
}
|
||||
|
||||
#else
|
||||
QScopedPointer<QSettings> settings(new QSettings(QSettings::IniFormat, QSettings::UserScope,
|
||||
QLatin1String("Nokia"), QLatin1String("QtCreator")));
|
||||
QScopedPointer<QSettingsWrapper> settings(new QSettingsWrapper(QSettingsWrapper::IniFormat,
|
||||
QSettingsWrapper::UserScope, QLatin1String("Nokia"), QLatin1String("QtCreator")));
|
||||
#endif
|
||||
return settings->fileName();
|
||||
}
|
||||
|
@ -32,10 +32,7 @@
|
||||
**************************************************************************/
|
||||
#include "registerfiletypeoperation.h"
|
||||
|
||||
#include <QSettings>
|
||||
|
||||
// this makes us use QSettingsWrapper
|
||||
#include "fsengineclient.h"
|
||||
#include "qsettingswrapper.h"
|
||||
|
||||
using namespace QInstaller;
|
||||
|
||||
@ -73,8 +70,8 @@ bool RegisterFileTypeOperation::performOperation()
|
||||
const QString className = QString::fromLatin1( "%1_auto_file" ).arg( extension );
|
||||
const QString settingsPrefix = QString::fromLatin1( "Software/Classes/" );
|
||||
|
||||
//QSettings settings( QLatin1String( "HKEY_CLASSES_ROOT" ), QSettings::NativeFormat );
|
||||
QSettings settings(QLatin1String("HKEY_CURRENT_USER"), QSettings::NativeFormat);
|
||||
//QSettingsWrapper settings( QLatin1String( "HKEY_CLASSES_ROOT" ), QSettingsWrapper::NativeFormat );
|
||||
QSettingsWrapper settings(QLatin1String("HKEY_CURRENT_USER"), QSettingsWrapper::NativeFormat);
|
||||
// first backup the old values
|
||||
setValue(QLatin1String("oldClass"), settings.value(QString::fromLatin1("%1.%2/Default").arg(settingsPrefix, extension)));
|
||||
setValue(QLatin1String("oldContentType"), settings.value(QString::fromLatin1("%1.%2/Content Type").arg(settingsPrefix, extension)));
|
||||
@ -136,7 +133,7 @@ bool RegisterFileTypeOperation::undoOperation()
|
||||
const QString className = QString::fromLatin1("%1_auto_file").arg(extension);
|
||||
const QString settingsPrefix = QString::fromLatin1("Software/Classes/");
|
||||
|
||||
QSettings settings(QLatin1String("HKEY_CURRENT_USER"), QSettings::NativeFormat);
|
||||
QSettingsWrapper settings(QLatin1String("HKEY_CURRENT_USER"), QSettingsWrapper::NativeFormat);
|
||||
|
||||
const QString restoredClassName = value(QLatin1String("oldClassName")).toString();
|
||||
// register the command to open the file
|
||||
|
Loading…
x
Reference in New Issue
Block a user