[556] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
| 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
| 6 | **
|
---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
| 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
| 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #include "qguiplatformplugin_p.h"
|
---|
| 43 | #include <qdebug.h>
|
---|
| 44 | #include <qfile.h>
|
---|
| 45 | #include <qdir.h>
|
---|
| 46 | #include <qsettings.h>
|
---|
| 47 | #include "private/qfactoryloader_p.h"
|
---|
| 48 | #include "qstylefactory.h"
|
---|
| 49 | #include "qapplication.h"
|
---|
| 50 | #include "qplatformdefs.h"
|
---|
| 51 | #include "qicon.h"
|
---|
| 52 |
|
---|
| 53 | #ifdef Q_WS_WINCE
|
---|
| 54 | #include "qguifunctions_wince.h"
|
---|
| 55 | extern bool qt_wince_is_smartphone(); //qguifunctions_wince.cpp
|
---|
| 56 | extern bool qt_wince_is_mobile(); //qguifunctions_wince.cpp
|
---|
| 57 | extern bool qt_wince_is_pocket_pc(); //qguifunctions_wince.cpp
|
---|
| 58 | #endif
|
---|
| 59 |
|
---|
| 60 |
|
---|
| 61 | #if defined(Q_WS_X11)
|
---|
| 62 | #include <private/qkde_p.h>
|
---|
| 63 | #include <private/qgtkstyle_p.h>
|
---|
| 64 | #include <private/qt_x11_p.h>
|
---|
| 65 | #endif
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 | QT_BEGIN_NAMESPACE
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 | /*! \internal
|
---|
| 72 | Return (an construct if necesseray) the Gui Platform plugin.
|
---|
| 73 |
|
---|
| 74 | The plugin key to be loaded is inside the QT_PLATFORM_PLUGIN environment variable.
|
---|
| 75 | If it is not set, it will be the DESKTOP_SESSION on X11.
|
---|
| 76 |
|
---|
| 77 | If no plugin can be loaded, the default one is returned.
|
---|
| 78 | */
|
---|
| 79 | QGuiPlatformPlugin *qt_guiPlatformPlugin()
|
---|
| 80 | {
|
---|
| 81 | static QGuiPlatformPlugin *plugin;
|
---|
| 82 | if (!plugin)
|
---|
| 83 | {
|
---|
| 84 | #if !defined(QT_NO_LIBRARY) && !defined(QT_NO_SETTINGS)
|
---|
| 85 |
|
---|
| 86 | QString key = QString::fromLocal8Bit(qgetenv("QT_PLATFORM_PLUGIN"));
|
---|
| 87 | #ifdef Q_WS_X11
|
---|
| 88 | if (key.isEmpty()) {
|
---|
| 89 | switch(X11->desktopEnvironment) {
|
---|
| 90 | case DE_KDE:
|
---|
| 91 | key = QString::fromLatin1("kde");
|
---|
| 92 | break;
|
---|
| 93 | default:
|
---|
| 94 | key = QString::fromLocal8Bit(qgetenv("DESKTOP_SESSION"));
|
---|
| 95 | break;
|
---|
| 96 | }
|
---|
| 97 | }
|
---|
| 98 | #endif
|
---|
| 99 |
|
---|
| 100 | if (!key.isEmpty() && QApplication::desktopSettingsAware()) {
|
---|
| 101 | QFactoryLoader loader(QGuiPlatformPluginInterface_iid, QLatin1String("/gui_platform"));
|
---|
| 102 | plugin = qobject_cast<QGuiPlatformPlugin *>(loader.instance(key));
|
---|
| 103 | }
|
---|
| 104 | #endif // QT_NO_LIBRARY
|
---|
| 105 |
|
---|
| 106 | if(!plugin) {
|
---|
| 107 | static QGuiPlatformPlugin def;
|
---|
| 108 | plugin = &def;
|
---|
| 109 | }
|
---|
| 110 | }
|
---|
| 111 | return plugin;
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 |
|
---|
| 115 | /* \class QPlatformPlugin
|
---|
| 116 | QGuiPlatformPlugin can be used to integrate Qt applications in a platform built on top of Qt.
|
---|
| 117 | The application developer should not know or use the plugin, it is only used by Qt internaly.
|
---|
| 118 |
|
---|
| 119 | But full platform that are built on top of Qt may provide a plugin so 3rd party Qt application
|
---|
| 120 | running in the platform are integrated.
|
---|
| 121 | */
|
---|
| 122 |
|
---|
| 123 | /*
|
---|
| 124 | The constructor can be used to install hooks in Qt
|
---|
| 125 | */
|
---|
| 126 | QGuiPlatformPlugin::QGuiPlatformPlugin(QObject *parent) : QObject(parent) {}
|
---|
| 127 | QGuiPlatformPlugin::~QGuiPlatformPlugin() {}
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 | /* return the string key to be used by default the application */
|
---|
| 131 | QString QGuiPlatformPlugin::styleName()
|
---|
| 132 | {
|
---|
| 133 | #if defined(Q_WS_WIN) && defined(Q_WS_WINCE)
|
---|
| 134 | if (qt_wince_is_smartphone() || qt_wince_is_pocket_pc())
|
---|
| 135 | return QLatin1String("WindowsMobile");
|
---|
| 136 | else
|
---|
| 137 | return QLatin1String("WindowsCE");
|
---|
| 138 | #elif defined(Q_WS_WIN)
|
---|
| 139 | if ((QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA
|
---|
| 140 | && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based))
|
---|
| 141 | return QLatin1String("WindowsVista");
|
---|
| 142 | else if ((QSysInfo::WindowsVersion >= QSysInfo::WV_XP
|
---|
| 143 | && QSysInfo::WindowsVersion < QSysInfo::WV_NT_based))
|
---|
| 144 | return QLatin1String("WindowsXP");
|
---|
| 145 | else
|
---|
| 146 | return QLatin1String("Windows"); // default styles for Windows
|
---|
| 147 | #elif defined(Q_WS_X11) && defined(Q_OS_SOLARIS)
|
---|
| 148 | return QLatin1String("CDE"); // default style for X11 on Solaris
|
---|
| 149 | #elif defined(Q_WS_S60)
|
---|
| 150 | return QLatin1String("S60"); // default style for Symbian with S60
|
---|
| 151 | #elif defined(Q_OS_SYMBIAN)
|
---|
| 152 | return QLatin1String("Windows"); // default style for Symbian without S60
|
---|
[569] | 153 | #elif defined(Q_OS_OS2)
|
---|
| 154 | return QLatin1String("Windows"); // default style for OS/2
|
---|
[556] | 155 | #elif defined(Q_WS_X11) && defined(Q_OS_IRIX)
|
---|
| 156 | return QLatin1String("SGI"); // default style for X11 on IRIX
|
---|
| 157 | #elif defined(Q_WS_QWS)
|
---|
| 158 | return QLatin1String("Plastique"); // default style for X11 and small devices
|
---|
| 159 | #elif defined(Q_WS_MAC)
|
---|
| 160 | return QLatin1String("Macintosh"); // default style for all Mac's
|
---|
| 161 | #elif defined(Q_WS_X11)
|
---|
| 162 | QString stylename;
|
---|
| 163 | switch(X11->desktopEnvironment) {
|
---|
| 164 | case DE_KDE:
|
---|
| 165 | stylename = QKde::kdeStyle();
|
---|
| 166 | break;
|
---|
| 167 | case DE_GNOME: {
|
---|
| 168 | QStringList availableStyles = QStyleFactory::keys();
|
---|
| 169 | // Set QGtkStyle for GNOME if available
|
---|
| 170 | QString gtkStyleKey = QString::fromLatin1("GTK+");
|
---|
| 171 | if (availableStyles.contains(gtkStyleKey)) {
|
---|
| 172 | stylename = gtkStyleKey;
|
---|
| 173 | break;
|
---|
| 174 | }
|
---|
| 175 | if (X11->use_xrender)
|
---|
| 176 | stylename = QLatin1String("cleanlooks");
|
---|
| 177 | else
|
---|
| 178 | stylename = QLatin1String("windows");
|
---|
| 179 | break;
|
---|
| 180 | }
|
---|
| 181 | case DE_CDE:
|
---|
| 182 | stylename = QLatin1String("cde");
|
---|
| 183 | break;
|
---|
| 184 | default:
|
---|
| 185 | // Don't do anything
|
---|
| 186 | break;
|
---|
| 187 | }
|
---|
| 188 | return stylename;
|
---|
| 189 | #endif
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 | /* return an aditional default palette (only work on X11) */
|
---|
| 193 | QPalette QGuiPlatformPlugin::palette()
|
---|
| 194 | {
|
---|
| 195 | #ifdef Q_WS_X11
|
---|
| 196 | if (QApplication::desktopSettingsAware() && X11->desktopEnvironment == DE_KDE)
|
---|
| 197 | return QKde::kdePalette();
|
---|
| 198 | #endif
|
---|
| 199 |
|
---|
| 200 | return QPalette();
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | /* the default icon theme name for QIcon::fromTheme. */
|
---|
| 204 | QString QGuiPlatformPlugin::systemIconThemeName()
|
---|
| 205 | {
|
---|
| 206 | QString result;
|
---|
| 207 | #ifdef Q_WS_X11
|
---|
| 208 | if (X11->desktopEnvironment == DE_GNOME) {
|
---|
| 209 | result = QString::fromLatin1("gnome");
|
---|
| 210 | #ifndef QT_NO_STYLE_GTK
|
---|
| 211 | result = QGtkStylePrivate::getGConfString(QLatin1String("/desktop/gnome/interface/icon_theme"), result);
|
---|
| 212 | #endif
|
---|
| 213 | } else if (X11->desktopEnvironment == DE_KDE) {
|
---|
| 214 | result = X11->desktopVersion >= 4 ? QString::fromLatin1("oxygen") : QString::fromLatin1("crystalsvg");
|
---|
| 215 | QSettings settings(QKde::kdeHome() + QLatin1String("/share/config/kdeglobals"), QSettings::IniFormat);
|
---|
| 216 | settings.beginGroup(QLatin1String("Icons"));
|
---|
| 217 | result = settings.value(QLatin1String("Theme"), result).toString();
|
---|
| 218 | }
|
---|
| 219 | #endif
|
---|
| 220 | return result;
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 |
|
---|
| 224 | QStringList QGuiPlatformPlugin::iconThemeSearchPaths()
|
---|
| 225 | {
|
---|
| 226 | QStringList paths;
|
---|
| 227 | #if defined(Q_WS_X11)
|
---|
| 228 | QString xdgDirString = QFile::decodeName(getenv("XDG_DATA_DIRS"));
|
---|
| 229 | if (xdgDirString.isEmpty())
|
---|
| 230 | xdgDirString = QLatin1String("/usr/local/share/:/usr/share/");
|
---|
| 231 |
|
---|
| 232 | QStringList xdgDirs = xdgDirString.split(QLatin1Char(':'));
|
---|
| 233 |
|
---|
| 234 | for (int i = 0 ; i < xdgDirs.size() ; ++i) {
|
---|
| 235 | QDir dir(xdgDirs[i]);
|
---|
| 236 | if (dir.exists())
|
---|
| 237 | paths.append(dir.path() + QLatin1String("/icons"));
|
---|
| 238 | }
|
---|
| 239 | if (X11->desktopEnvironment == DE_KDE) {
|
---|
| 240 | paths << QLatin1Char(':') + QKde::kdeHome() + QLatin1String("/share/icons");
|
---|
| 241 | QStringList kdeDirs = QFile::decodeName(getenv("KDEDIRS")).split(QLatin1Char(':'));
|
---|
| 242 | for (int i = 0 ; i< kdeDirs.count() ; ++i) {
|
---|
| 243 | QDir dir(QLatin1Char(':') + kdeDirs.at(i) + QLatin1String("/share/icons"));
|
---|
| 244 | if (dir.exists())
|
---|
| 245 | paths.append(dir.path());
|
---|
| 246 | }
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | // Add home directory first in search path
|
---|
| 250 | QDir homeDir(QDir::homePath() + QLatin1String("/.icons"));
|
---|
| 251 | if (homeDir.exists())
|
---|
| 252 | paths.prepend(homeDir.path());
|
---|
| 253 | #endif
|
---|
| 254 |
|
---|
| 255 | #if defined(Q_WS_WIN)
|
---|
| 256 | paths.append(qApp->applicationDirPath() + QLatin1String("/icons"));
|
---|
| 257 | #elif defined(Q_WS_MAC)
|
---|
| 258 | paths.append(qApp->applicationDirPath() + QLatin1String("/../Resources/icons"));
|
---|
| 259 | #endif
|
---|
| 260 | return paths;
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 | /* backend for QFileIconProvider, null icon means default */
|
---|
| 264 | QIcon QGuiPlatformPlugin::fileSystemIcon(const QFileInfo &)
|
---|
| 265 | {
|
---|
| 266 | return QIcon();
|
---|
| 267 | }
|
---|
| 268 |
|
---|
| 269 | /* Like QStyle::styleHint */
|
---|
| 270 | int QGuiPlatformPlugin::platformHint(PlatformHint hint)
|
---|
| 271 | {
|
---|
| 272 | int ret = 0;
|
---|
| 273 | switch(hint)
|
---|
| 274 | {
|
---|
| 275 | case PH_ToolButtonStyle:
|
---|
| 276 | ret = Qt::ToolButtonIconOnly;
|
---|
| 277 | #ifdef Q_WS_X11
|
---|
| 278 | if (X11->desktopEnvironment == DE_KDE && X11->desktopVersion >= 4
|
---|
| 279 | && QApplication::desktopSettingsAware()) {
|
---|
| 280 | ret = QKde::kdeToolButtonStyle();
|
---|
| 281 | }
|
---|
| 282 | #endif
|
---|
| 283 | break;
|
---|
| 284 | case PH_ToolBarIconSize:
|
---|
| 285 | #ifdef Q_WS_X11
|
---|
| 286 | if (X11->desktopEnvironment == DE_KDE && X11->desktopVersion >= 4
|
---|
| 287 | && QApplication::desktopSettingsAware()) {
|
---|
| 288 | ret = QKde::kdeToolBarIconSize();
|
---|
| 289 | }
|
---|
| 290 | #endif
|
---|
| 291 | //by default keep ret = 0 so QCommonStyle will use the style default
|
---|
| 292 | break;
|
---|
| 293 | default:
|
---|
| 294 | break;
|
---|
| 295 | }
|
---|
| 296 | return ret;
|
---|
| 297 | }
|
---|
| 298 |
|
---|
| 299 |
|
---|
| 300 | QT_END_NAMESPACE
|
---|