summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-10-07 11:58:02 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-10-07 15:56:43 (GMT)
commitdb182f75b69cd47ce8abbcc5acb2551306919a05 (patch)
tree726e5731b1f923cac6527b77c043874b27c256c0 /src/gui
parent3cad63946965416c89703fbf3d9730e856283c06 (diff)
downloadQt-db182f75b69cd47ce8abbcc5acb2551306919a05.zip
Qt-db182f75b69cd47ce8abbcc5acb2551306919a05.tar.gz
Qt-db182f75b69cd47ce8abbcc5acb2551306919a05.tar.bz2
QGuiPlatformPlugin: QFileIconProvider and QIcon backend.
Add a backend for QFileIconProvider in the platform plugin Also change the QIcon::fromTheme backend in the platform plugin: On KDE, we unfortunately can't use KIcon as backend, as the current API doesn't let us know easily (and quickly) wether we should use the fallback or not (KDE always fallback to the question mark "unknown" icon) So we will use the QIconLoader even on KDE. But we need to make sure that the theme name and the icon search paths are correct. Ask that to the platform plugin Reviewed-by: Jens Bache-Wiig
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/image/qicon.cpp5
-rw-r--r--src/gui/image/qiconloader.cpp88
-rw-r--r--src/gui/itemviews/qfileiconprovider.cpp5
-rw-r--r--src/gui/kernel/qguiplatformplugin.cpp68
-rw-r--r--src/gui/kernel/qguiplatformplugin_p.h6
5 files changed, 87 insertions, 85 deletions
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp
index 3448459..e0779a0 100644
--- a/src/gui/image/qicon.cpp
+++ b/src/gui/image/qicon.cpp
@@ -962,15 +962,10 @@ QString QIcon::themeName()
*/
QIcon QIcon::fromTheme(const QString &name, const QIcon &fallback)
{
-
static QCache <QString, QIcon> iconCache;
QIcon icon;
- icon = qt_guiPlatformPlugin()->loadIcon(name);
- if (!icon.isNull())
- return icon;
-
if (iconCache.contains(name)) {
icon = *iconCache.object(name);
} else {
diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp
index adc2967..5412e11 100644
--- a/src/gui/image/qiconloader.cpp
+++ b/src/gui/image/qiconloader.cpp
@@ -43,7 +43,7 @@
#include <private/qapplication_p.h>
#include <private/qicon_p.h>
-#include <private/qkde_p.h>
+#include <private/qguiplatformplugin_p.h>
#include <QtGui/QIconEnginePlugin>
#include <QtGui/QPixmapCache>
@@ -68,47 +68,25 @@ QT_BEGIN_NAMESPACE
Q_GLOBAL_STATIC(QIconLoader, iconLoaderInstance)
+/* Theme to use in last resort, if the theme does not have the icon, neither the parents */
static QString fallbackTheme()
{
- QString defaultTheme;
-#ifdef Q_WS_X11
- if (X11->desktopEnvironment == DE_GNOME)
- defaultTheme = QLatin1String("gnome");
- else if (X11->desktopEnvironment == DE_KDE)
- defaultTheme = X11->desktopVersion >= 4 ?
- QString::fromLatin1("oxygen") :
- QString::fromLatin1("crystalsvg");
-#endif
- return defaultTheme;
-}
-
-static QString systemThemeName()
-{
- QString result = fallbackTheme();
#ifdef Q_WS_X11
if (X11->desktopEnvironment == DE_GNOME) {
-#ifndef QT_NO_STYLE_GTK
- result = QGtk::getGConfString(QLatin1String("/desktop/gnome/interface/icon_theme"),
- result);
-#endif
+ return QLatin1String("gnome");
} else if (X11->desktopEnvironment == DE_KDE) {
- QSettings settings(QKde::kdeHome() +
- QLatin1String("/share/config/kdeglobals"),
- QSettings::IniFormat);
-
- settings.beginGroup(QLatin1String("Icons"));
-
- result = settings.value(QLatin1String("Theme"), result).toString();
+ return X11->desktopVersion >= 4
+ ? QString::fromLatin1("oxygen")
+ : QString::fromLatin1("crystalsvg");
}
#endif
- return result;
+ return QString();
}
-
QIconLoader::QIconLoader() :
m_themeKey(1), m_supportsSvg(false)
{
- m_systemTheme = systemThemeName();
+ m_systemTheme = qt_guiPlatformPlugin()->systemIconThemeName();
QFactoryLoader iconFactoryLoader(QIconEngineFactoryInterfaceV2_iid,
QLatin1String("/iconengines"),
@@ -128,7 +106,7 @@ void QIconLoader::updateSystemTheme()
{
// Only change if this is not explicitly set by the user
if (m_userTheme.isEmpty()) {
- QString theme = systemThemeName();
+ QString theme = qt_guiPlatformPlugin()->systemIconThemeName();
if (theme != m_systemTheme) {
m_systemTheme = theme;
invalidateKey();
@@ -152,51 +130,7 @@ void QIconLoader::setThemeSearchPath(const QStringList &searchPaths)
QStringList QIconLoader::themeSearchPaths() const
{
if (m_iconDirs.isEmpty()) {
-
-#if defined(Q_WS_X11)
-
- QString xdgDirString = QFile::decodeName(getenv("XDG_DATA_DIRS"));
- if (xdgDirString.isEmpty())
- xdgDirString = QLatin1String("/usr/local/share/:/usr/share/");
-
- QStringList xdgDirs = xdgDirString.split(QLatin1Char(':'));
-
- for (int i = 0 ; i < xdgDirs.size() ; ++i) {
- QDir dir(xdgDirs[i]);
- if (dir.exists())
- m_iconDirs.append(dir.path() +
- QLatin1String("/icons"));
- }
-
- if (X11->desktopEnvironment == DE_KDE) {
-
- m_iconDirs << QLatin1Char(':') +
- QKde::kdeHome() +
- QLatin1String("/share/icons");
- QStringList kdeDirs =
- QFile::decodeName(getenv("KDEDIRS")).split(QLatin1Char(':'));
-
- for (int i = 0 ; i< kdeDirs.count() ; ++i) {
- QDir dir(QLatin1Char(':') + kdeDirs.at(i) +
- QLatin1String("/share/icons"));
- if (dir.exists())
- m_iconDirs.append(dir.path());
- }
- }
-
- // Add home directory first in search path
- QDir homeDir(QDir::homePath() + QLatin1String("/.icons"));
- if (homeDir.exists())
- m_iconDirs.prepend(homeDir.path());
-#endif
-
-#if defined(Q_WS_WIN)
- m_iconDirs.append(qApp->applicationDirPath() +
- QLatin1String("/icons"));
-#elif defined(Q_WS_MAC)
- m_iconDirs.append(qApp->applicationDirPath() +
- QLatin1String("/../Resources/icons"));
-#endif
+ m_iconDirs = qt_guiPlatformPlugin()->iconThemeSearchPaths();
// Allways add resource directory as search path
m_iconDirs.append(QLatin1String(":/icons"));
}
@@ -291,7 +225,7 @@ QThemeIconEntries QIconLoader::findIconHelper(const QString &themeName,
if (!theme.isValid()) {
theme = QIconTheme(themeName);
if (!theme.isValid())
- theme = fallbackTheme();
+ theme = QIconTheme(fallbackTheme());
themeList.insert(themeName, theme);
}
diff --git a/src/gui/itemviews/qfileiconprovider.cpp b/src/gui/itemviews/qfileiconprovider.cpp
index c78a49b..e3d17ad 100644
--- a/src/gui/itemviews/qfileiconprovider.cpp
+++ b/src/gui/itemviews/qfileiconprovider.cpp
@@ -61,6 +61,7 @@
#endif
#include <private/qfunctions_p.h>
+#include <private/qguiplatformplugin_p.h>
#ifndef SHGFI_ADDOVERLAYS
#define SHGFI_ADDOVERLAYS 0x000000020
@@ -385,6 +386,10 @@ QIcon QFileIconProvider::icon(const QFileInfo &info) const
{
Q_D(const QFileIconProvider);
+ QIcon platformIcon = qt_guiPlatformPlugin()->fileSystemIcon(info);
+ if (!platformIcon.isNull())
+ return platformIcon;
+
#if defined(Q_WS_X11) && !defined(QT_NO_STYLE_GTK)
if (X11->desktopEnvironment == DE_GNOME) {
QIcon gtkIcon = QGtk::getFilesystemIcon(info);
diff --git a/src/gui/kernel/qguiplatformplugin.cpp b/src/gui/kernel/qguiplatformplugin.cpp
index c48b8f6..6e074a1 100644
--- a/src/gui/kernel/qguiplatformplugin.cpp
+++ b/src/gui/kernel/qguiplatformplugin.cpp
@@ -41,6 +41,9 @@
#include "qguiplatformplugin_p.h"
#include <qdebug.h>
+#include <qfile.h>
+#include <qdir.h>
+#include <qsettings.h>
#include "private/qfactoryloader_p.h"
#include "qstylefactory.h"
#include "qapplication.h"
@@ -58,6 +61,7 @@ extern bool qt_wince_is_pocket_pc(); //qguifunctions_wince.cpp
#if defined(Q_WS_X11)
#include "qkde_p.h"
#include "qt_x11_p.h"
+#include <private/gtksymbols_p.h>
#endif
@@ -194,8 +198,68 @@ QPalette QGuiPlatformPlugin::palette()
return QPalette();
}
-/* backend for QIcon::fromTheme. A null icon means it uses the default backend */
-QIcon QGuiPlatformPlugin::loadIcon(const QString &name)
+/* the default icon theme name for QIcon::fromTheme. */
+QString QGuiPlatformPlugin::systemIconThemeName()
+{
+ QString result;
+#ifdef Q_WS_X11
+ if (X11->desktopEnvironment == DE_GNOME) {
+ result = QString::fromLatin1("gnome");
+#ifndef QT_NO_STYLE_GTK
+ result = QGtk::getGConfString(QLatin1String("/desktop/gnome/interface/icon_theme"), result);
+#endif
+ } else if (X11->desktopEnvironment == DE_KDE) {
+ result = X11->desktopVersion >= 4 ? QString::fromLatin1("oxygen") : QString::fromLatin1("crystalsvg");
+ QSettings settings(QKde::kdeHome() + QLatin1String("/share/config/kdeglobals"), QSettings::IniFormat);
+ settings.beginGroup(QLatin1String("Icons"));
+ result = settings.value(QLatin1String("Theme"), result).toString();
+ }
+#endif
+ return result;
+}
+
+
+QStringList QGuiPlatformPlugin::iconThemeSearchPaths()
+{
+ QStringList paths;
+#if defined(Q_WS_X11)
+ QString xdgDirString = QFile::decodeName(getenv("XDG_DATA_DIRS"));
+ if (xdgDirString.isEmpty())
+ xdgDirString = QLatin1String("/usr/local/share/:/usr/share/");
+
+ QStringList xdgDirs = xdgDirString.split(QLatin1Char(':'));
+
+ for (int i = 0 ; i < xdgDirs.size() ; ++i) {
+ QDir dir(xdgDirs[i]);
+ if (dir.exists())
+ paths.append(dir.path() + QLatin1String("/icons"));
+ }
+ if (X11->desktopEnvironment == DE_KDE) {
+ paths << QLatin1Char(':') + QKde::kdeHome() + QLatin1String("/share/icons");
+ QStringList kdeDirs = QFile::decodeName(getenv("KDEDIRS")).split(QLatin1Char(':'));
+ for (int i = 0 ; i< kdeDirs.count() ; ++i) {
+ QDir dir(QLatin1Char(':') + kdeDirs.at(i) + QLatin1String("/share/icons"));
+ if (dir.exists())
+ paths.append(dir.path());
+ }
+ }
+
+ // Add home directory first in search path
+ QDir homeDir(QDir::homePath() + QLatin1String("/.icons"));
+ if (homeDir.exists())
+ paths.prepend(homeDir.path());
+#endif
+
+#if defined(Q_WS_WIN)
+ paths.append(qApp->applicationDirPath() + QLatin1String("/icons"));
+#elif defined(Q_WS_MAC)
+ paths.append(qApp->applicationDirPath() + QLatin1String("/../Resources/icons"));
+#endif
+ return paths;
+}
+
+/* backend for QFileIconProvider, null icon means default */
+QIcon QGuiPlatformPlugin::fileSystemIcon(const QFileInfo &)
{
return QIcon();
}
diff --git a/src/gui/kernel/qguiplatformplugin_p.h b/src/gui/kernel/qguiplatformplugin_p.h
index 57ea8af..f7d4b92 100644
--- a/src/gui/kernel/qguiplatformplugin_p.h
+++ b/src/gui/kernel/qguiplatformplugin_p.h
@@ -68,6 +68,7 @@ class QPalette;
class QIcon;
class QFileDialog;
class QColorDialog;
+class QFileInfo;
struct Q_GUI_EXPORT QGuiPlatformPluginInterface : public QFactoryInterface
{
@@ -89,7 +90,10 @@ class Q_GUI_EXPORT QGuiPlatformPlugin : public QObject, public QGuiPlatformPlugi
virtual QString styleName();
virtual QPalette palette();
- virtual QIcon loadIcon(const QString &name);
+ virtual QString systemIconThemeName();
+ virtual QStringList iconThemeSearchPaths();
+ virtual QIcon fileSystemIcon(const QFileInfo &);
+
enum PlatformHint { PH_ToolButtonStyle, PH_ToolBarIconSize };
virtual int platformHint(PlatformHint hint);