Qt 4.8
qguiplatformplugin.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
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 
69 
70 
83 {
84  static QGuiPlatformPlugin *plugin;
85  if (!plugin)
86  {
87 #ifndef QT_NO_LIBRARY
88 
89  QString key = QString::fromLocal8Bit(qgetenv("QT_PLATFORM_PLUGIN"));
90 #ifdef Q_WS_X11
91  if (key.isEmpty()) {
92  switch(X11->desktopEnvironment) {
93  case DE_KDE:
94  key = QString::fromLatin1("kde");
95  break;
96  default:
97  key = QString::fromLocal8Bit(qgetenv("DESKTOP_SESSION"));
98  break;
99  }
100  }
101 #endif
102 
105  plugin = qobject_cast<QGuiPlatformPlugin *>(loader.instance(key));
106  }
107 #endif // QT_NO_LIBRARY
108 
109  if(!plugin) {
110  static QGuiPlatformPlugin def;
111  plugin = &def;
112  }
113  }
114  return plugin;
115 }
116 
117 
118 /* \class QPlatformPlugin
119  QGuiPlatformPlugin can be used to integrate Qt applications in a platform built on top of Qt.
120  The application developer should not know or use the plugin, it is only used by Qt internaly.
121 
122  But full platform that are built on top of Qt may provide a plugin so 3rd party Qt application
123  running in the platform are integrated.
124  */
125 
126 /*
127  The constructor can be used to install hooks in Qt
128  */
131 
132 
133 /* return the string key to be used by default the application */
135 {
136 #if defined(Q_WS_WIN) && defined(Q_WS_WINCE)
138  return QLatin1String("WindowsMobile");
139  else
140  return QLatin1String("WindowsCE");
141 #elif defined(Q_WS_WIN)
144  return QLatin1String("WindowsVista");
146  && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based)))
147  return QLatin1String("WindowsXP");
148  else
149  return QLatin1String("Windows"); // default styles for Windows
150 #elif defined(Q_WS_X11) && defined(Q_OS_SOLARIS)
151  return QLatin1String("CDE"); // default style for X11 on Solaris
152 #elif defined(Q_WS_S60)
153  return QLatin1String("S60"); // default style for Symbian with S60
154 #elif defined(Q_OS_SYMBIAN)
155  return QLatin1String("Windows"); // default style for Symbian without S60
156 #elif defined(Q_WS_X11) && defined(Q_OS_IRIX)
157  return QLatin1String("SGI"); // default style for X11 on IRIX
158 #elif defined(Q_WS_QWS) || defined(Q_WS_QPA)
159  return QLatin1String("Plastique"); // default style for X11 and small devices
160 #elif defined(Q_WS_MAC)
161  return QLatin1String("Macintosh"); // default style for all Mac's
162 #elif defined(Q_WS_X11)
163  QString stylename;
164  switch(X11->desktopEnvironment) {
165  case DE_KDE:
166  stylename = QKde::kdeStyle();
167  break;
168  case DE_GNOME: {
169  QStringList availableStyles = QStyleFactory::keys();
170  // Set QGtkStyle for GNOME if available
171  QString gtkStyleKey = QString::fromLatin1("GTK+");
172  if (availableStyles.contains(gtkStyleKey)) {
173  stylename = gtkStyleKey;
174  break;
175  }
176  if (X11->use_xrender)
177  stylename = QLatin1String("cleanlooks");
178  else
179  stylename = QLatin1String("windows");
180  break;
181  }
182  case DE_CDE:
183  stylename = QLatin1String("cde");
184  break;
185  default:
186  // Don't do anything
187  break;
188  }
189  return stylename;
190 #endif
191 }
192 
193 /* return an additional default palette (only work on X11) */
195 {
196 #ifdef Q_WS_X11
197  if (QApplication::desktopSettingsAware() && X11->desktopEnvironment == DE_KDE)
198  return QKde::kdePalette();
199 #endif
200 
201  return QPalette();
202 }
203 
204 /* the default icon theme name for QIcon::fromTheme. */
206 {
207  QString result;
208 #ifdef Q_WS_X11
209  if (X11->desktopEnvironment == DE_GNOME) {
210 #ifndef QT_NO_STYLE_GTK
212 #endif
213  if (result.isEmpty()) {
214  result = QString::fromLatin1("gnome");
215  }
216  } else if (X11->desktopEnvironment == DE_KDE) {
217  result = X11->desktopVersion >= 4 ? QString::fromLatin1("oxygen") : QString::fromLatin1("crystalsvg");
218  QSettings settings(QKde::kdeHome() + QLatin1String("/share/config/kdeglobals"), QSettings::IniFormat);
219  settings.beginGroup(QLatin1String("Icons"));
220  result = settings.value(QLatin1String("Theme"), result).toString();
221  }
222 #endif
223  return result;
224 }
225 
226 
228 {
229  QStringList paths;
230 #if defined(Q_WS_X11)
231  QString xdgDirString = QFile::decodeName(getenv("XDG_DATA_DIRS"));
232  if (xdgDirString.isEmpty())
233  xdgDirString = QLatin1String("/usr/local/share/:/usr/share/");
234 
235  QStringList xdgDirs = xdgDirString.split(QLatin1Char(':'));
236 
237  for (int i = 0 ; i < xdgDirs.size() ; ++i) {
238  QDir dir(xdgDirs[i]);
239  if (dir.exists())
240  paths.append(dir.path() + QLatin1String("/icons"));
241  }
242  if (X11->desktopEnvironment == DE_KDE) {
243  paths << QLatin1Char(':') + QKde::kdeHome() + QLatin1String("/share/icons");
244  QStringList kdeDirs = QFile::decodeName(getenv("KDEDIRS")).split(QLatin1Char(':'));
245  for (int i = 0 ; i< kdeDirs.count() ; ++i) {
246  QDir dir(QLatin1Char(':') + kdeDirs.at(i) + QLatin1String("/share/icons"));
247  if (dir.exists())
248  paths.append(dir.path());
249  }
250  }
251 
252  // Add home directory first in search path
253  QDir homeDir(QDir::homePath() + QLatin1String("/.icons"));
254  if (homeDir.exists())
255  paths.prepend(homeDir.path());
256 #endif
257 
258 #if defined(Q_WS_WIN)
259  paths.append(qApp->applicationDirPath() + QLatin1String("/icons"));
260 #elif defined(Q_WS_MAC)
261  paths.append(qApp->applicationDirPath() + QLatin1String("/../Resources/icons"));
262 #endif
263  return paths;
264 }
265 
266 /* backend for QFileIconProvider, null icon means default */
268 {
269  return QIcon();
270 }
271 
272 /* Like QStyle::styleHint */
274 {
275  int ret = 0;
276  switch(hint)
277  {
278  case PH_ToolButtonStyle:
280 #ifdef Q_WS_X11
281  if (X11->desktopEnvironment == DE_KDE && X11->desktopVersion >= 4
283  ret = QKde::kdeToolButtonStyle();
284  }
285 #endif
286  break;
287  case PH_ToolBarIconSize:
288 #ifdef Q_WS_X11
289  if (X11->desktopEnvironment == DE_KDE && X11->desktopVersion >= 4
291  ret = QKde::kdeToolBarIconSize();
292  }
293 #endif
294  //by default keep ret = 0 so QCommonStyle will use the style default
295  break;
296  default:
297  break;
298  }
299  return ret;
300 }
301 
302 
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
virtual QPalette palette()
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
Definition: qstring.cpp:4245
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Returns the value for setting key.
Definition: qsettings.cpp:3460
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool qt_wince_is_pocket_pc()
#define QGuiPlatformPluginInterface_iid
The QSettings class provides persistent platform-independent application settings.
Definition: qsettings.h:73
virtual QStringList iconThemeSearchPaths()
void beginGroup(const QString &prefix)
Appends prefix to the current group.
Definition: qsettings.cpp:3073
QString kdeStyle()
Definition: qkde.cpp:127
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QGuiPlatformPlugin * qt_guiPlatformPlugin()
Return (an construct if necesseray) the Gui Platform plugin.
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
static const WinVersion WindowsVersion
the version of the Windows operating system on which the application is run (Windows only) ...
Definition: qglobal.h:1613
The QString class provides a Unicode character string.
Definition: qstring.h:83
T * qobject_cast(QObject *object)
Definition: qobject.h:375
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
#define X11
Definition: qt_x11_p.h:724
bool exists() const
Returns true if the directory exists; otherwise returns false.
Definition: qdir.cpp:1560
QGuiPlatformPlugin(QObject *parent=0)
static QString getIconThemeName()
static QString decodeName(const QByteArray &localFileName)
This does the reverse of QFile::encodeName() using localFileName.
Definition: qfile.cpp:552
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
virtual int platformHint(PlatformHint hint)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
static QStringList keys()
Returns the list of valid keys, i.e.
virtual QString systemIconThemeName()
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
#define qApp
void prepend(const T &t)
Inserts value at the beginning of the list.
Definition: qlist.h:541
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
QPalette kdePalette()
Definition: qkde.cpp:100
int kdeToolButtonStyle()
Definition: qkde.cpp:145
bool qt_wince_is_mobile()
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
QObject * instance(const QString &key) const
bool qt_wince_is_smartphone()
int key
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static bool desktopSettingsAware()
Returns true if Qt is set to use the system&#39;s standard colors, fonts, etc.
QString kdeHome()
Definition: qkde.cpp:59
virtual QString styleName()
int kdeToolBarIconSize()
Definition: qkde.cpp:161
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
QString path() const
Returns the path.
Definition: qdir.cpp:605
virtual QIcon fileSystemIcon(const QFileInfo &)
The QFileInfo class provides system-independent file information.
Definition: qfileinfo.h:60
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
static QString homePath()
Returns the absolute path of the user&#39;s home directory.
Definition: qdir.cpp:1942
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60