source: trunk/src/gui/kernel/qguiplatformplugin.cpp@ 564

Last change on this file since 564 was 561, checked in by Dmitry A. Kuminov, 16 years ago

trunk: Merged in qt 4.6.1 sources.

  • Property svn:eol-style set to native
File size: 10.0 KB
Line 
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"
55extern bool qt_wince_is_smartphone(); //qguifunctions_wince.cpp
56extern bool qt_wince_is_mobile(); //qguifunctions_wince.cpp
57extern 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
68QT_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 */
79QGuiPlatformPlugin *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 */
126QGuiPlatformPlugin::QGuiPlatformPlugin(QObject *parent) : QObject(parent) {}
127QGuiPlatformPlugin::~QGuiPlatformPlugin() {}
128
129
130/* return the string key to be used by default the application */
131QString 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
153#elif defined(Q_WS_X11) && defined(Q_OS_IRIX)
154 return QLatin1String("SGI"); // default style for X11 on IRIX
155#elif defined(Q_WS_QWS)
156 return QLatin1String("Plastique"); // default style for X11 and small devices
157#elif defined(Q_WS_MAC)
158 return QLatin1String("Macintosh"); // default style for all Mac's
159#elif defined(Q_WS_X11)
160 QString stylename;
161 switch(X11->desktopEnvironment) {
162 case DE_KDE:
163 stylename = QKde::kdeStyle();
164 break;
165 case DE_GNOME: {
166 QStringList availableStyles = QStyleFactory::keys();
167 // Set QGtkStyle for GNOME if available
168 QString gtkStyleKey = QString::fromLatin1("GTK+");
169 if (availableStyles.contains(gtkStyleKey)) {
170 stylename = gtkStyleKey;
171 break;
172 }
173 if (X11->use_xrender)
174 stylename = QLatin1String("cleanlooks");
175 else
176 stylename = QLatin1String("windows");
177 break;
178 }
179 case DE_CDE:
180 stylename = QLatin1String("cde");
181 break;
182 default:
183 // Don't do anything
184 break;
185 }
186 return stylename;
187#endif
188}
189
190/* return an aditional default palette (only work on X11) */
191QPalette QGuiPlatformPlugin::palette()
192{
193#ifdef Q_WS_X11
194 if (QApplication::desktopSettingsAware() && X11->desktopEnvironment == DE_KDE)
195 return QKde::kdePalette();
196#endif
197
198 return QPalette();
199}
200
201/* the default icon theme name for QIcon::fromTheme. */
202QString QGuiPlatformPlugin::systemIconThemeName()
203{
204 QString result;
205#ifdef Q_WS_X11
206 if (X11->desktopEnvironment == DE_GNOME) {
207 result = QString::fromLatin1("gnome");
208#ifndef QT_NO_STYLE_GTK
209 result = QGtkStylePrivate::getGConfString(QLatin1String("/desktop/gnome/interface/icon_theme"), result);
210#endif
211 } else if (X11->desktopEnvironment == DE_KDE) {
212 result = X11->desktopVersion >= 4 ? QString::fromLatin1("oxygen") : QString::fromLatin1("crystalsvg");
213 QSettings settings(QKde::kdeHome() + QLatin1String("/share/config/kdeglobals"), QSettings::IniFormat);
214 settings.beginGroup(QLatin1String("Icons"));
215 result = settings.value(QLatin1String("Theme"), result).toString();
216 }
217#endif
218 return result;
219}
220
221
222QStringList QGuiPlatformPlugin::iconThemeSearchPaths()
223{
224 QStringList paths;
225#if defined(Q_WS_X11)
226 QString xdgDirString = QFile::decodeName(getenv("XDG_DATA_DIRS"));
227 if (xdgDirString.isEmpty())
228 xdgDirString = QLatin1String("/usr/local/share/:/usr/share/");
229
230 QStringList xdgDirs = xdgDirString.split(QLatin1Char(':'));
231
232 for (int i = 0 ; i < xdgDirs.size() ; ++i) {
233 QDir dir(xdgDirs[i]);
234 if (dir.exists())
235 paths.append(dir.path() + QLatin1String("/icons"));
236 }
237 if (X11->desktopEnvironment == DE_KDE) {
238 paths << QLatin1Char(':') + QKde::kdeHome() + QLatin1String("/share/icons");
239 QStringList kdeDirs = QFile::decodeName(getenv("KDEDIRS")).split(QLatin1Char(':'));
240 for (int i = 0 ; i< kdeDirs.count() ; ++i) {
241 QDir dir(QLatin1Char(':') + kdeDirs.at(i) + QLatin1String("/share/icons"));
242 if (dir.exists())
243 paths.append(dir.path());
244 }
245 }
246
247 // Add home directory first in search path
248 QDir homeDir(QDir::homePath() + QLatin1String("/.icons"));
249 if (homeDir.exists())
250 paths.prepend(homeDir.path());
251#endif
252
253#if defined(Q_WS_WIN)
254 paths.append(qApp->applicationDirPath() + QLatin1String("/icons"));
255#elif defined(Q_WS_MAC)
256 paths.append(qApp->applicationDirPath() + QLatin1String("/../Resources/icons"));
257#endif
258 return paths;
259}
260
261/* backend for QFileIconProvider, null icon means default */
262QIcon QGuiPlatformPlugin::fileSystemIcon(const QFileInfo &)
263{
264 return QIcon();
265}
266
267/* Like QStyle::styleHint */
268int QGuiPlatformPlugin::platformHint(PlatformHint hint)
269{
270 int ret = 0;
271 switch(hint)
272 {
273 case PH_ToolButtonStyle:
274 ret = Qt::ToolButtonIconOnly;
275#ifdef Q_WS_X11
276 if (X11->desktopEnvironment == DE_KDE && X11->desktopVersion >= 4
277 && QApplication::desktopSettingsAware()) {
278 ret = QKde::kdeToolButtonStyle();
279 }
280#endif
281 break;
282 case PH_ToolBarIconSize:
283#ifdef Q_WS_X11
284 if (X11->desktopEnvironment == DE_KDE && X11->desktopVersion >= 4
285 && QApplication::desktopSettingsAware()) {
286 ret = QKde::kdeToolBarIconSize();
287 }
288#endif
289 //by default keep ret = 0 so QCommonStyle will use the style default
290 break;
291 default:
292 break;
293 }
294 return ret;
295}
296
297
298QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.