diff options
author | Eike Ziller <eike.ziller@theqtcompany.com> | 2015-10-27 08:46:02 +0100 |
---|---|---|
committer | Eike Ziller <eike.ziller@theqtcompany.com> | 2015-11-06 19:37:16 +0000 |
commit | 11f6162739fb85929cf6c359a0e3b5d7f8fdb87a (patch) | |
tree | 9d90db29b1e526d446bdedbde1e50b80e43a58bb /src/plugins/coreplugin/coreplugin.cpp | |
parent | 1bf1f58a9c6b22ec22e71fada4ba83f79b3095ec (diff) | |
download | qt-creator-11f6162739fb85929cf6c359a0e3b5d7f8fdb87a.tar.gz |
Themes: Fix issues with restoring themes.
Themes from the user config where not restored correctly.
Improve error handling when no themes are found
in case of broken installations.
Cleanly differentiate between theme "id" (currently complete basename of
theme file) and theme "displayName" (as specified as a property in the
theme file).
Remove convoluted broken code that tried to allow using an absolute file
path for a theme on the command line and require themes to be installed
either in Qt Creator globally or in the user settings path.
In general stream line the code.
Task-number: QTCREATORBUG-15113
Task-number: QTCREATORBUG-15233
Change-Id: I014a4314e8bea27422ed4c42462cf16f4220698b
Reviewed-by: Alessandro Portale <alessandro.portale@theqtcompany.com>
Diffstat (limited to 'src/plugins/coreplugin/coreplugin.cpp')
-rw-r--r-- | src/plugins/coreplugin/coreplugin.cpp | 72 |
1 files changed, 26 insertions, 46 deletions
diff --git a/src/plugins/coreplugin/coreplugin.cpp b/src/plugins/coreplugin/coreplugin.cpp index f52fd82849..a2e62bc7d2 100644 --- a/src/plugins/coreplugin/coreplugin.cpp +++ b/src/plugins/coreplugin/coreplugin.cpp @@ -37,6 +37,7 @@ #include "modemanager.h" #include "infobar.h" #include "iwizardfactory.h" +#include "themesettings.h" #include <coreplugin/actionmanager/actionmanager.h> #include <coreplugin/documentmanager.h> @@ -48,6 +49,7 @@ #include <extensionsystem/pluginerroroverview.h> #include <extensionsystem/pluginmanager.h> +#include <utils/algorithm.h> #include <utils/pathchooser.h> #include <utils/macroexpander.h> #include <utils/savefile.h> @@ -58,7 +60,6 @@ #include <QtPlugin> #include <QDebug> #include <QDateTime> -#include <QDir> #include <QMenu> using namespace Core; @@ -97,36 +98,11 @@ CorePlugin::~CorePlugin() setCreatorTheme(0); } -static QString absoluteThemePath(const QString &themeName, bool userProvidedTheme) -{ - if (themeName.isEmpty()) - return themeName; - QString res = QDir::fromNativeSeparators(themeName); - QFileInfo fi(res); - bool tryRawName = userProvidedTheme || fi.isAbsolute(); - // Try the given name - if (tryRawName && fi.exists()) - return fi.absoluteFilePath(); - const QString suffix = QLatin1String("creatortheme"); - // Try name.creatortheme - if (fi.suffix() != suffix) { - res = themeName + QLatin1Char('.') + suffix; - fi.setFile(res); - if (tryRawName && fi.exists()) - return fi.absoluteFilePath(); - } - if (fi.path().isEmpty()) - return QString(); // absolute/relative path, but not found - // If only name was given, look it up in qtcreator/themes - res.prepend(ICore::resourcePath() + QLatin1String("/themes/")); - return QFileInfo::exists(res) ? res : QString(); -} - void CorePlugin::parseArguments(const QStringList &arguments) { - const QString defaultTheme = QLatin1String("default"); - QString themeName = ICore::settings()->value( - QLatin1String(Constants::SETTINGS_THEME), defaultTheme).toString(); + const Id settingsThemeId = Id::fromSetting(ICore::settings()->value( + QLatin1String(Constants::SETTINGS_THEME), QLatin1String("default"))); + Id themeId = settingsThemeId; QColor overrideColor; bool presentationMode = false; bool userProvidedTheme = false; @@ -140,28 +116,28 @@ void CorePlugin::parseArguments(const QStringList &arguments) if (arguments.at(i) == QLatin1String("-presentationMode")) presentationMode = true; if (arguments.at(i) == QLatin1String("-theme")) { - themeName = arguments.at(i + 1); + themeId = Id::fromString(arguments.at(i + 1)); userProvidedTheme = true; i++; } } - - QString themeURI = absoluteThemePath(themeName, userProvidedTheme); - if (themeURI.isEmpty()) { - themeName = defaultTheme; - themeURI = QStringLiteral("%1/themes/%2.creatortheme").arg(ICore::resourcePath()).arg(themeName); - if (themeURI.isEmpty()) { - qCritical("%s", qPrintable(QCoreApplication::translate("Application", "No valid theme \"%1\"") - .arg(themeName))); - } + const QList<ThemeEntry> availableThemes = ThemeSettings::availableThemes(); + int themeIndex = Utils::indexOf(availableThemes, Utils::equal(&ThemeEntry::id, themeId)); + if (themeIndex < 0) { + themeIndex = Utils::indexOf(availableThemes, + Utils::equal(&ThemeEntry::id, settingsThemeId)); + } + if (themeIndex < 0) + themeIndex = 0; + if (themeIndex < availableThemes.size()) { + const ThemeEntry themeEntry = availableThemes.at(themeIndex); + QSettings themeSettings(themeEntry.filePath(), QSettings::IniFormat); + Theme *theme = new Theme(themeEntry.id().toString(), qApp); + theme->readSettings(themeSettings); + if (theme->flag(Theme::ApplyThemePaletteGlobally)) + QApplication::setPalette(theme->palette()); + setCreatorTheme(theme); } - - QSettings themeSettings(themeURI, QSettings::IniFormat); - Theme *theme = new Theme(themeName, qApp); - theme->readSettings(themeSettings); - if (theme->flag(Theme::ApplyThemePaletteGlobally)) - QApplication::setPalette(theme->palette()); - setCreatorTheme(theme); // defer creation of these widgets until here, // because they need a valid theme set @@ -176,6 +152,10 @@ void CorePlugin::parseArguments(const QStringList &arguments) bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage) { + if (ThemeSettings::availableThemes().isEmpty()) { + *errorMessage = tr("No themes found in installation."); + return false; + } new ActionManager(this); Theme::initialPalette(); // Initialize palette before setting it qsrand(QDateTime::currentDateTime().toTime_t()); |