Commit 61e95e9a authored by Tobias Hunger's avatar Tobias Hunger

Replace some QStrings with Utils::FileName

Change-Id: Ia96963b90788250b4bc6bc89c2bb697de103535f
Reviewed-by: default avatarTobias Hunger <tobias.hunger@nokia.com>
parent a03c2d2f
......@@ -312,11 +312,11 @@ QVariantMap PersistentSettingsReader::restoreValues() const
return m_valueMap;
}
bool PersistentSettingsReader::load(const QString &fileName)
bool PersistentSettingsReader::load(const Utils::FileName &fileName)
{
m_valueMap.clear();
QFile file(fileName);
QFile file(fileName.toString());
if (!file.open(QIODevice::ReadOnly|QIODevice::Text))
return false;
ParseContext ctx;
......@@ -381,12 +381,12 @@ void PersistentSettingsWriter::saveValue(const QString &variable, const QVariant
m_valueMap.insert(variable, value);
}
bool PersistentSettingsWriter::save(const QString &fileName, const QString &docType,
bool PersistentSettingsWriter::save(const Utils::FileName &fileName, const QString &docType,
QWidget *parent) const
{
QDir tmp;
tmp.mkpath(QFileInfo(fileName).path());
Utils::FileSaver saver(fileName, QIODevice::Text);
tmp.mkpath(fileName.toFileInfo().path());
Utils::FileSaver saver(fileName.toString(), QIODevice::Text);
if (!saver.hasError()) {
const Context ctx;
QXmlStreamWriter w(saver.file());
......
......@@ -33,6 +33,8 @@
#include "utils_global.h"
#include "fileutils.h"
#include <QMap>
#include <QVariant>
......@@ -48,7 +50,7 @@ public:
PersistentSettingsReader();
QVariant restoreValue(const QString &variable) const;
QVariantMap restoreValues() const;
bool load(const QString &fileName);
bool load(const FileName &fileName);
private:
QMap<QString, QVariant> m_valueMap;
......@@ -59,7 +61,7 @@ class QTCREATOR_UTILS_EXPORT PersistentSettingsWriter
public:
PersistentSettingsWriter();
void saveValue(const QString &variable, const QVariant &value);
bool save(const QString &fileName, const QString &docType, QWidget *parent) const;
bool save(const FileName &fileName, const QString &docType, QWidget *parent) const;
private:
QMap<QString, QVariant> m_valueMap;
......
......@@ -83,10 +83,10 @@ namespace {
const QLatin1String jarsignerName("jarsigner");
const QLatin1String changeTimeStamp("ChangeTimeStamp");
static QString settingsFileName()
static Utils::FileName settingsFileName()
{
return QString::fromLatin1("%1/qtcreator/android.xml").arg(
QFileInfo(Core::ICore::settings(QSettings::SystemScope)->fileName()).absolutePath());
return Utils::FileName::fromString(QString::fromLatin1("%1/qtcreator/android.xml")
.arg(QFileInfo(Core::ICore::settings(QSettings::SystemScope)->fileName()).absolutePath()));
}
bool androidDevicesLessThan(const AndroidDeviceInfo &dev1, const AndroidDeviceInfo &dev2)
......@@ -142,8 +142,9 @@ AndroidConfig::AndroidConfig(const QSettings &settings)
// user settings
PersistentSettingsReader reader;
if (reader.load(settingsFileName())
&& settings.value(changeTimeStamp).toInt() != QFileInfo(settingsFileName()).lastModified().toMSecsSinceEpoch() / 1000) {
Utils::FileName fn = settingsFileName();
if (reader.load(fn)
&& settings.value(changeTimeStamp).toInt() != fn.toFileInfo().lastModified().toMSecsSinceEpoch() / 1000) {
// persisten settings
sdkLocation = FileName::fromString(reader.restoreValue(SDKLocationKey).toString());
ndkLocation = FileName::fromString(reader.restoreValue(NDKLocationKey).toString());
......@@ -181,7 +182,7 @@ AndroidConfig::AndroidConfig()
void AndroidConfig::save(QSettings &settings) const
{
QFileInfo fileInfo(settingsFileName());
QFileInfo fileInfo(settingsFileName().toFileInfo());
if (fileInfo.exists())
settings.setValue(changeTimeStamp, fileInfo.lastModified().toMSecsSinceEpoch() / 1000);
......
......@@ -220,9 +220,9 @@ QVariantMap DeviceManager::toMap() const
return map;
}
QString DeviceManager::settingsFilePath(const QString &extension)
Utils::FileName DeviceManager::settingsFilePath(const QString &extension)
{
return QFileInfo(ExtensionSystem::PluginManager::settings()->fileName()).absolutePath() + extension;
return Utils::FileName::fromString(QFileInfo(ExtensionSystem::PluginManager::settings()->fileName()).absolutePath() + extension);
}
void DeviceManager::addDevice(const IDevice::Ptr &_device)
......
......@@ -33,6 +33,7 @@
#include "idevice.h"
#include <projectexplorer/projectexplorer_export.h>
#include <utils/fileutils.h>
#include <QObject>
......@@ -99,7 +100,7 @@ private:
IDevice::Ptr fromRawPointer(IDevice *device) const;
IDevice::ConstPtr fromRawPointer(const IDevice *device) const;
static QString settingsFilePath(const QString &extension);
static Utils::FileName settingsFilePath(const QString &extension);
static void copy(const DeviceManager *source, DeviceManager *target, bool deep);
Internal::DeviceManagerPrivate * const d;
......
......@@ -59,10 +59,10 @@ static const char PROFILE_FILENAME[] = "/qtcreator/profiles.xml";
using Utils::PersistentSettingsWriter;
using Utils::PersistentSettingsReader;
static QString settingsFileName()
static Utils::FileName settingsFileName()
{
QFileInfo settingsLocation(ExtensionSystem::PluginManager::settings()->fileName());
return settingsLocation.absolutePath() + QLatin1String(PROFILE_FILENAME);
return Utils::FileName::fromString(settingsLocation.absolutePath() + QLatin1String(PROFILE_FILENAME));
}
namespace ProjectExplorer {
......@@ -148,7 +148,7 @@ void ProfileManager::restoreProfiles()
// read all profiles from SDK
QFileInfo systemSettingsFile(Core::ICore::settings(QSettings::SystemScope)->fileName());
ProfileList system = restoreProfiles(systemSettingsFile.absolutePath() + QLatin1String(PROFILE_FILENAME));
ProfileList system = restoreProfiles(Utils::FileName::fromString(systemSettingsFile.absolutePath() + QLatin1String(PROFILE_FILENAME)));
QList<Profile *> readProfiles = system.profiles;
// make sure we mark these as autodetected!
foreach (Profile *p, readProfiles)
......@@ -272,7 +272,7 @@ void ProfileManager::deregisterProfileInformation(ProfileInformation *pi)
delete pi;
}
ProfileManager::ProfileList ProfileManager::restoreProfiles(const QString &fileName)
ProfileManager::ProfileList ProfileManager::restoreProfiles(const Utils::FileName &fileName)
{
ProfileList result;
......@@ -300,7 +300,7 @@ ProfileManager::ProfileList ProfileManager::restoreProfiles(const QString &fileN
} else {
delete p;
qWarning("Warning: Unable to restore profiles stored in %s at position %d.",
qPrintable(QDir::toNativeSeparators(fileName)), i);
qPrintable(fileName.toUserOutput()), i);
}
}
const QString defaultId = data.value(QLatin1String(PROFILE_DEFAULT_KEY)).toString();
......
......@@ -151,7 +151,7 @@ private:
Core::Id defaultProfile;
QList<Profile *> profiles;
};
ProfileList restoreProfiles(const QString &fileName);
ProfileList restoreProfiles(const Utils::FileName &fileName);
void notifyAboutUpdate(ProjectExplorer::Profile *p);
void addProfile(Profile *p);
......
......@@ -357,11 +357,11 @@ bool SessionManager::save()
writer.saveValue(QLatin1String("valueKeys"), keys);
QString fileName = sessionNameToFileName(m_sessionName);
Utils::FileName fileName = sessionNameToFileName(m_sessionName);
bool result = writer.save(fileName, QLatin1String("QtCreatorSession"), Core::ICore::mainWindow());
if (!result) {
QMessageBox::warning(0, tr("Error while saving session"),
tr("Could not save session to file %1").arg(fileName));
tr("Could not save session to file %1").arg(fileName.toUserOutput()));
}
if (debug)
......@@ -645,9 +645,9 @@ QStringList SessionManager::sessions() const
return m_sessions;
}
QString SessionManager::sessionNameToFileName(const QString &session) const
Utils::FileName SessionManager::sessionNameToFileName(const QString &session) const
{
return ICore::userResourcePath() + QLatin1Char('/') + session + QLatin1String(".qws");
return Utils::FileName::fromString(ICore::userResourcePath() + QLatin1Char('/') + session + QLatin1String(".qws"));
}
/*!
......@@ -680,7 +680,7 @@ bool SessionManager::deleteSession(const QString &session)
if (!m_sessions.contains(session))
return false;
m_sessions.removeOne(session);
QFile fi(sessionNameToFileName(session));
QFile fi(sessionNameToFileName(session).toString());
if (fi.exists())
return fi.remove();
return false;
......@@ -691,9 +691,9 @@ bool SessionManager::cloneSession(const QString &original, const QString &clone)
if (!m_sessions.contains(original))
return false;
QFile fi(sessionNameToFileName(original));
QFile fi(sessionNameToFileName(original).toString());
// If the file does not exist, we can still clone
if (!fi.exists() || fi.copy(sessionNameToFileName(clone))) {
if (!fi.exists() || fi.copy(sessionNameToFileName(clone).toString())) {
Q_ASSERT(m_sessions.size() > 0);
m_sessions.insert(1, clone);
return true;
......@@ -811,12 +811,12 @@ bool SessionManager::loadSession(const QString &session)
return false;
// Try loading the file
QString fileName = sessionNameToFileName(session);
Utils::FileName fileName = sessionNameToFileName(session);
PersistentSettingsReader reader;
if (QFileInfo(fileName).exists()) {
if (fileName.toFileInfo().exists()) {
if (!reader.load(fileName)) {
QMessageBox::warning(0, tr("Error while restoring session"),
tr("Could not restore session %1").arg(fileName));
tr("Could not restore session %1").arg(fileName.toUserOutput()));
return false;
}
}
......@@ -849,7 +849,7 @@ bool SessionManager::loadSession(const QString &session)
m_sessionName = session;
updateWindowTitle();
if (QFileInfo(fileName).exists()) {
if (fileName.toFileInfo().exists()) {
m_virginSession = false;
ICore::progressManager()->addTask(m_future.future(), tr("Session"),
......@@ -947,11 +947,11 @@ void SessionManager::projectDisplayNameChanged()
QStringList ProjectExplorer::SessionManager::projectsForSessionName(const QString &session) const
{
const QString fileName = sessionNameToFileName(session);
const Utils::FileName fileName = sessionNameToFileName(session);
PersistentSettingsReader reader;
if (QFileInfo(fileName).exists()) {
if (fileName.toFileInfo().exists()) {
if (!reader.load(fileName)) {
qWarning() << "Could not restore session" << fileName;
qWarning() << "Could not restore session" << fileName.toUserOutput();
return QStringList();
}
}
......
......@@ -97,7 +97,7 @@ public:
bool addDependency(Project *project, Project *depProject);
void removeDependency(Project *project, Project *depProject);
QString sessionNameToFileName(const QString &session) const;
Utils::FileName sessionNameToFileName(const QString &session) const;
Project *startupProject() const;
const QList<Project *> &projects() const;
......
......@@ -641,11 +641,11 @@ QVariantMap SettingsAccessor::restoreSettings(Project *project) const
// Do we need to generate a backup?
if (settings.m_version < m_lastVersion + 1 && !settings.m_usingBackup) {
const QString &backupFileName = settings.m_fileName
const QString &backupFileName = settings.m_fileName.toString()
+ QLatin1Char('.')
+ m_handlers.value(settings.m_version)->displayUserFileVersion();
QFile::remove(backupFileName); // Remove because copy doesn't overwrite
QFile::copy(settings.m_fileName, backupFileName);
QFile::copy(settings.m_fileName.toString(), backupFileName);
}
}
......@@ -827,7 +827,7 @@ QString SettingsAccessor::FileAccessor::assembleFileName(const Project *project)
bool SettingsAccessor::FileAccessor::findNewestCompatibleSetting(SettingsData *settings) const
{
const QString baseFileName = settings->m_fileName;
const QString baseFileName = settings->m_fileName.toString();
const int baseVersion = settings->m_version;
settings->m_fileName.clear();
settings->m_version = -1;
......@@ -851,7 +851,7 @@ bool SettingsAccessor::FileAccessor::findNewestCompatibleSetting(SettingsData *s
if (suffix == acessor->m_handlers.value(candidateVersion)->displayUserFileVersion()) {
if (candidateVersion > settings->m_version) {
settings->m_version = candidateVersion;
settings->m_fileName = candidateFileName;
settings->m_fileName = Utils::FileName::fromString(candidateFileName);
}
break;
}
......@@ -863,21 +863,22 @@ bool SettingsAccessor::FileAccessor::findNewestCompatibleSetting(SettingsData *s
settings->m_map = reader.restoreValues();
return true;
}
qWarning() << "Unable to load file" << settings->m_fileName;
qWarning() << "Unable to load file" << settings->m_fileName.toUserOutput();
}
// If we haven't identified a valid file or if it for any reason failed to load, we
// try a more expensive check (which is actually needed to identify our own and newer
// versions as we don't know what extensions will be assigned in the future).
foreach (const QString &candidateFileName, candidates) {
if (settings->m_fileName == candidateFileName)
Utils::FileName fn = Utils::FileName::fromString(candidateFileName);
if (settings->m_fileName == fn)
continue; // This one has already failed to load.
if (reader.load(candidateFileName)) {
if (reader.load(fn)) {
settings->m_map = reader.restoreValues();
int candidateVersion = settings->m_map.value(QLatin1String(VERSION_KEY), 0).toInt();
if (candidateVersion == acessor->m_lastVersion + 1) {
settings->m_version = candidateVersion;
settings->m_fileName = candidateFileName;
settings->m_fileName = fn;
return true;
}
}
......@@ -893,7 +894,7 @@ bool SettingsAccessor::FileAccessor::readFile(Project *project,
SettingsData *settings) const
{
PersistentSettingsReader reader;
settings->m_fileName = assembleFileName(project);
settings->m_fileName = Utils::FileName::fromString(assembleFileName(project));
if (!reader.load(settings->m_fileName))
return false;
......@@ -914,7 +915,7 @@ bool SettingsAccessor::FileAccessor::readFile(Project *project,
return false;
settings->m_usingBackup = true;
project->setProperty(m_id.constData(), settings->m_fileName);
project->setProperty(m_id.constData(), settings->m_fileName.toString());
}
return true;
......@@ -938,7 +939,7 @@ bool SettingsAccessor::FileAccessor::writeFile(const Project *project,
}
const QString &fileName = project->property(m_id).toString();
return writer.save(fileName.isEmpty() ? assembleFileName(project) : fileName,
return writer.save(Utils::FileName::fromString(fileName.isEmpty() ? assembleFileName(project) : fileName),
QLatin1String("QtCreatorProject"),
Core::ICore::mainWindow());
}
......@@ -2534,7 +2535,7 @@ static QString maddeRoot(const QString &qmakePath)
void Version11Handler::parseQtversionFile()
{
QFileInfo settingsLocation(ExtensionSystem::PluginManager::settings()->fileName());
QString fileName = settingsLocation.absolutePath() + QLatin1String("/qtversion.xml");
Utils::FileName fileName = Utils::FileName::fromString(settingsLocation.absolutePath() + QLatin1String("/qtversion.xml"));
Utils::PersistentSettingsReader reader;
if (!reader.load(fileName)) {
qWarning("Failed to open legacy qtversions.xml file.");
......@@ -2578,7 +2579,7 @@ void Version11Handler::parseQtversionFile()
void Version11Handler::parseToolChainFile()
{
QFileInfo settingsLocation(ExtensionSystem::PluginManager::settings()->fileName());
QString fileName = settingsLocation.absolutePath() + QLatin1String("/toolChains.xml");
Utils::FileName fileName = Utils::FileName::fromString(settingsLocation.absolutePath() + QLatin1String("/toolChains.xml"));
Utils::PersistentSettingsReader reader;
if (!reader.load(fileName)) {
qWarning("Failed to open legacy toolChains.xml file.");
......
......@@ -31,8 +31,9 @@
#ifndef PROJECTMANAGER_USERFILEACCESSOR_H
#define PROJECTMANAGER_USERFILEACCESSOR_H
#include <QVariantMap>
#include <utils/fileutils.h>
#include <QVariantMap>
namespace ProjectExplorer {
......@@ -71,7 +72,7 @@ private:
int m_version;
bool m_usingBackup;
QVariantMap m_map;
QString m_fileName;
Utils::FileName m_fileName;
};
// The entity which actually reads/writes to the settings file.
......
......@@ -56,10 +56,10 @@ static const char LEGACY_TOOLCHAIN_FILENAME[] = "/toolChains.xml";
using Utils::PersistentSettingsWriter;
using Utils::PersistentSettingsReader;
static QString settingsFileName(const QString &path)
static Utils::FileName settingsFileName(const QString &path)
{
QFileInfo settingsLocation(ExtensionSystem::PluginManager::settings()->fileName());
return settingsLocation.absolutePath() + path;
return Utils::FileName::fromString(settingsLocation.absolutePath() + path);
}
namespace ProjectExplorer {
......@@ -136,7 +136,7 @@ void ToolChainManager::restoreToolChains()
// read all tool chains from SDK
QFileInfo systemSettingsFile(Core::ICore::settings(QSettings::SystemScope)->fileName());
QList<ToolChain *> readTcs =
restoreToolChains(systemSettingsFile.absolutePath() + QLatin1String(LEGACY_TOOLCHAIN_FILENAME));
restoreToolChains(Utils::FileName::fromString(systemSettingsFile.absolutePath() + QLatin1String(LEGACY_TOOLCHAIN_FILENAME)));
// make sure we mark these as autodetected!
foreach (ToolChain *tc, readTcs)
tc->setAutoDetected(true);
......@@ -146,8 +146,8 @@ void ToolChainManager::restoreToolChains()
// read all tool chains from user file.
// Read legacy settings once and keep them around...
QString fileName = settingsFileName(QLatin1String(TOOLCHAIN_FILENAME));
if (!QFileInfo(fileName).exists())
Utils::FileName fileName = settingsFileName(QLatin1String(TOOLCHAIN_FILENAME));
if (!fileName.toFileInfo().exists())
fileName = settingsFileName(QLatin1String(LEGACY_TOOLCHAIN_FILENAME));
readTcs = restoreToolChains(fileName);
......@@ -222,7 +222,7 @@ void ToolChainManager::saveToolChains()
// Do not save default debuggers! Those are set by the SDK!
}
QList<ToolChain *> ToolChainManager::restoreToolChains(const QString &fileName)
QList<ToolChain *> ToolChainManager::restoreToolChains(const Utils::FileName &fileName)
{
QList<ToolChain *> result;
......@@ -272,7 +272,7 @@ QList<ToolChain *> ToolChainManager::restoreToolChains(const QString &fileName)
if (!restored)
qWarning("Warning: Unable to restore compiler '%s' stored in %s.",
qPrintable(ToolChainFactory::idFromMap(tcMap)),
qPrintable(QDir::toNativeSeparators(fileName)));
qPrintable(fileName.toUserOutput()));
}
return result;
}
......
......@@ -88,7 +88,7 @@ private:
// Make sure the this is only called after all
// Tool chain Factories are registered!
void restoreToolChains();
QList<ToolChain *> restoreToolChains(const QString &fileName);
QList<ToolChain *> restoreToolChains(const Utils::FileName &fileName);
void notifyAboutUpdate(ProjectExplorer::ToolChain *);
......
......@@ -92,18 +92,18 @@ static T *createToolChain(const QString &id)
return 0;
}
static QString globalSettingsFileName()
static Utils::FileName globalSettingsFileName()
{
QSettings *globalSettings = ExtensionSystem::PluginManager::globalSettings();
return QFileInfo(globalSettings->fileName()).absolutePath()
+ QLatin1String(QTVERSION_SDK_FILENAME);
return Utils::FileName::fromString(QFileInfo(globalSettings->fileName()).absolutePath()
+ QLatin1String(QTVERSION_SDK_FILENAME));
}
static QString settingsFileName(const QString &path)
static Utils::FileName settingsFileName(const QString &path)
{
QSettings *settings = ExtensionSystem::PluginManager::settings();
QFileInfo settingsLocation(settings->fileName());
return settingsLocation.absolutePath() + path;
return Utils::FileName::fromString(settingsLocation.absolutePath() + path);
}
......@@ -145,12 +145,12 @@ void QtVersionManager::extensionsInitialized()
saveQtVersions();
const QString configFileName = globalSettingsFileName();
if (QFileInfo(configFileName).exists()) {
const Utils::FileName configFileName = globalSettingsFileName();
if (configFileName.toFileInfo().exists()) {
m_configFileWatcher = new Utils::FileSystemWatcher(this);
connect(m_configFileWatcher, SIGNAL(fileChanged(QString)),
m_fileWatcherTimer, SLOT(start()));
m_configFileWatcher->addFile(configFileName,
m_configFileWatcher->addFile(configFileName.toString(),
Utils::FileSystemWatcher::WatchModifiedDate);
} // exists
}
......@@ -177,10 +177,10 @@ bool QtVersionManager::restoreQtVersions()
QList<QtVersionFactory *> factories = ExtensionSystem::PluginManager::getObjects<QtVersionFactory>();
Utils::PersistentSettingsReader reader;
QString filename = settingsFileName(QLatin1String(QTVERSION_FILENAME));
Utils::FileName filename = settingsFileName(QLatin1String(QTVERSION_FILENAME));
// Read Qt Creator 2.5 qtversions.xml once:
if (!QFileInfo(filename).exists())
if (!filename.toFileInfo().exists())
filename = settingsFileName(QLatin1String(QTVERSION_SDK_FILENAME));
if (!reader.load(filename))
return false;
......@@ -223,7 +223,7 @@ bool QtVersionManager::restoreQtVersions()
if (!restored)
qWarning("Warning: Unable to restore Qt version '%s' stored in %s.",
qPrintable(type),
qPrintable(QDir::toNativeSeparators(filename)));
qPrintable(filename.toUserOutput()));
}
++m_idcount;
return true;
......@@ -234,10 +234,10 @@ void QtVersionManager::updateFromInstaller()
m_fileWatcherTimer->stop();
// Handle overwritting of data:
const Utils::FileName path = globalSettingsFileName();
if (m_configFileWatcher) {
const QString path = globalSettingsFileName();
m_configFileWatcher->removeFile(path);
m_configFileWatcher->addFile(path, Utils::FileSystemWatcher::WatchModifiedDate);
m_configFileWatcher->removeFile(path.toString());
m_configFileWatcher->addFile(path.toString(), Utils::FileSystemWatcher::WatchModifiedDate);
}
QList<int> added;
......@@ -247,7 +247,7 @@ void QtVersionManager::updateFromInstaller()
QList<QtVersionFactory *> factories = ExtensionSystem::PluginManager::getObjects<QtVersionFactory>();
Utils::PersistentSettingsReader reader;
QVariantMap data;
if (reader.load(globalSettingsFileName()))
if (reader.load(path))
data = reader.restoreValues();
if (debug) {
......
......@@ -234,7 +234,7 @@ ICodeStylePreferences *CodeStylePool::loadCodeStyle(const QString &fileName)
{
TextEditor::ICodeStylePreferences *codeStyle = 0;
Utils::PersistentSettingsReader reader;
reader.load(fileName);
reader.load(Utils::FileName::fromString(fileName));
QVariantMap m = reader.restoreValues();
if (m.contains(QLatin1String(codeStyleDataKey))) {
const QString id = QFileInfo(fileName).completeBaseName();
......@@ -287,7 +287,7 @@ void CodeStylePool::exportCodeStyle(const QString &fileName, ICodeStylePreferenc
Utils::PersistentSettingsWriter writer;
writer.saveValue(QLatin1String(displayNameKey), codeStyle->displayName());
writer.saveValue(QLatin1String(codeStyleDataKey), map);
writer.save(fileName, QLatin1String(codeStyleDocKey), 0);
writer.save(Utils::FileName::fromString(fileName), QLatin1String(codeStyleDocKey), 0);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment