src/gui/styles/qgtkstyle_p.cpp
changeset 3 41300fa6a67c
child 4 3b1da2848fc7
child 7 f7bc934e204c
equal deleted inserted replaced
2:56cd8111b7f7 3:41300fa6a67c
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtGui module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    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 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #include "qgtkstyle_p.h"
       
    43 
       
    44 // This file is responsible for resolving all GTK functions we use
       
    45 // dynamically. This is done to avoid link-time dependancy on GTK
       
    46 // as well as crashes occurring due to usage of the GTK_QT engines
       
    47 //
       
    48 // Additionally we create a map of common GTK widgets that we can pass
       
    49 // to the GTK theme engine as many engines resort to querying the
       
    50 // actual widget pointers for details that are not covered by the
       
    51 // state flags
       
    52 
       
    53 #include <QtCore/qglobal.h>
       
    54 #if !defined(QT_NO_STYLE_GTK)
       
    55 
       
    56 #include <QtCore/QEvent>
       
    57 #include <QtCore/QFile>
       
    58 #include <QtCore/QStringList>
       
    59 #include <QtCore/QTextStream>
       
    60 #include <QtCore/QHash>
       
    61 #include <QtCore/QUrl>
       
    62 #include <QtCore/QLibrary>
       
    63 
       
    64 #include <private/qapplication_p.h>
       
    65 #include <private/qiconloader_p.h>
       
    66 
       
    67 #include <QtGui/QMenu>
       
    68 #include <QtGui/QStyle>
       
    69 #include <QtGui/QApplication>
       
    70 #include <QtGui/QPixmapCache>
       
    71 #include <QtGui/QStatusBar>
       
    72 #include <QtGui/QMenuBar>
       
    73 #include <QtGui/QToolBar>
       
    74 #include <QtGui/QToolButton>
       
    75 #include <QtGui/QX11Info>
       
    76 
       
    77 #include <private/qt_x11_p.h>
       
    78 
       
    79 QT_BEGIN_NAMESPACE
       
    80 
       
    81 static bool displayDepth  =  -1;
       
    82 Q_GLOBAL_STATIC(QGtkStyleUpdateScheduler, styleScheduler)
       
    83 
       
    84 Ptr_gtk_container_forall QGtkStylePrivate::gtk_container_forall = 0;
       
    85 Ptr_gtk_init QGtkStylePrivate::gtk_init = 0;
       
    86 Ptr_gtk_style_attach QGtkStylePrivate::gtk_style_attach = 0;
       
    87 Ptr_gtk_window_new QGtkStylePrivate::gtk_window_new = 0;
       
    88 Ptr_gtk_widget_destroy QGtkStylePrivate::gtk_widget_destroy = 0;
       
    89 Ptr_gtk_widget_realize QGtkStylePrivate::gtk_widget_realize = 0;
       
    90 Ptr_gtk_widget_set_default_direction QGtkStylePrivate::gtk_widget_set_default_direction = 0;
       
    91 Ptr_gtk_widget_modify_color QGtkStylePrivate::gtk_widget_modify_fg = 0;
       
    92 Ptr_gtk_widget_modify_color QGtkStylePrivate::gtk_widget_modify_bg = 0;
       
    93 Ptr_gtk_arrow_new QGtkStylePrivate::gtk_arrow_new = 0;
       
    94 Ptr_gtk_menu_item_new QGtkStylePrivate::gtk_menu_item_new = 0;
       
    95 Ptr_gtk_check_menu_item_new QGtkStylePrivate::gtk_check_menu_item_new = 0;
       
    96 Ptr_gtk_menu_bar_new QGtkStylePrivate::gtk_menu_bar_new = 0;
       
    97 Ptr_gtk_menu_new QGtkStylePrivate::gtk_menu_new = 0;
       
    98 Ptr_gtk_button_new QGtkStylePrivate::gtk_button_new = 0;
       
    99 Ptr_gtk_tool_button_new QGtkStylePrivate::gtk_tool_button_new = 0;
       
   100 Ptr_gtk_hbutton_box_new QGtkStylePrivate::gtk_hbutton_box_new = 0;
       
   101 Ptr_gtk_check_button_new QGtkStylePrivate::gtk_check_button_new = 0;
       
   102 Ptr_gtk_radio_button_new QGtkStylePrivate::gtk_radio_button_new = 0;
       
   103 Ptr_gtk_spin_button_new QGtkStylePrivate::gtk_spin_button_new = 0;
       
   104 Ptr_gtk_frame_new QGtkStylePrivate::gtk_frame_new = 0;
       
   105 Ptr_gtk_expander_new QGtkStylePrivate::gtk_expander_new = 0;
       
   106 Ptr_gtk_statusbar_new QGtkStylePrivate::gtk_statusbar_new = 0;
       
   107 Ptr_gtk_entry_new QGtkStylePrivate::gtk_entry_new = 0;
       
   108 Ptr_gtk_hscale_new QGtkStylePrivate::gtk_hscale_new = 0;
       
   109 Ptr_gtk_vscale_new QGtkStylePrivate::gtk_vscale_new = 0;
       
   110 Ptr_gtk_hscrollbar_new QGtkStylePrivate::gtk_hscrollbar_new = 0;
       
   111 Ptr_gtk_vscrollbar_new QGtkStylePrivate::gtk_vscrollbar_new = 0;
       
   112 Ptr_gtk_scrolled_window_new QGtkStylePrivate::gtk_scrolled_window_new = 0;
       
   113 Ptr_gtk_notebook_new QGtkStylePrivate::gtk_notebook_new = 0;
       
   114 Ptr_gtk_toolbar_new QGtkStylePrivate::gtk_toolbar_new = 0;
       
   115 Ptr_gtk_toolbar_insert QGtkStylePrivate::gtk_toolbar_insert = 0;
       
   116 Ptr_gtk_separator_tool_item_new QGtkStylePrivate::gtk_separator_tool_item_new = 0;
       
   117 Ptr_gtk_tree_view_new QGtkStylePrivate::gtk_tree_view_new = 0;
       
   118 Ptr_gtk_combo_box_new QGtkStylePrivate::gtk_combo_box_new = 0;
       
   119 Ptr_gtk_combo_box_entry_new QGtkStylePrivate::gtk_combo_box_entry_new = 0;
       
   120 Ptr_gtk_progress_bar_new QGtkStylePrivate::gtk_progress_bar_new = 0;
       
   121 Ptr_gtk_container_add QGtkStylePrivate::gtk_container_add = 0;
       
   122 Ptr_gtk_menu_shell_append QGtkStylePrivate::gtk_menu_shell_append = 0;
       
   123 Ptr_gtk_progress_set_adjustment QGtkStylePrivate::gtk_progress_set_adjustment = 0;
       
   124 Ptr_gtk_range_set_adjustment QGtkStylePrivate::gtk_range_set_adjustment = 0;
       
   125 Ptr_gtk_range_set_inverted QGtkStylePrivate::gtk_range_set_inverted = 0;
       
   126 Ptr_gtk_icon_factory_lookup_default QGtkStylePrivate::gtk_icon_factory_lookup_default = 0;
       
   127 Ptr_gtk_icon_theme_get_default QGtkStylePrivate::gtk_icon_theme_get_default = 0;
       
   128 Ptr_gtk_widget_style_get QGtkStylePrivate::gtk_widget_style_get = 0;
       
   129 Ptr_gtk_icon_set_render_icon QGtkStylePrivate::gtk_icon_set_render_icon = 0;
       
   130 Ptr_gtk_fixed_new QGtkStylePrivate::gtk_fixed_new = 0;
       
   131 Ptr_gtk_tree_view_column_new QGtkStylePrivate::gtk_tree_view_column_new = 0;
       
   132 Ptr_gtk_tree_view_get_column QGtkStylePrivate::gtk_tree_view_get_column = 0;
       
   133 Ptr_gtk_tree_view_append_column QGtkStylePrivate::gtk_tree_view_append_column = 0;
       
   134 Ptr_gtk_paint_check QGtkStylePrivate::gtk_paint_check = 0;
       
   135 Ptr_gtk_paint_box QGtkStylePrivate::gtk_paint_box = 0;
       
   136 Ptr_gtk_paint_box_gap QGtkStylePrivate::gtk_paint_box_gap = 0;
       
   137 Ptr_gtk_paint_flat_box QGtkStylePrivate::gtk_paint_flat_box = 0;
       
   138 Ptr_gtk_paint_option QGtkStylePrivate::gtk_paint_option = 0;
       
   139 Ptr_gtk_paint_extension QGtkStylePrivate::gtk_paint_extension = 0;
       
   140 Ptr_gtk_paint_slider QGtkStylePrivate::gtk_paint_slider = 0;
       
   141 Ptr_gtk_paint_shadow QGtkStylePrivate::gtk_paint_shadow = 0;
       
   142 Ptr_gtk_paint_resize_grip QGtkStylePrivate::gtk_paint_resize_grip = 0;
       
   143 Ptr_gtk_paint_focus QGtkStylePrivate::gtk_paint_focus = 0;
       
   144 Ptr_gtk_paint_arrow QGtkStylePrivate::gtk_paint_arrow = 0;
       
   145 Ptr_gtk_paint_handle QGtkStylePrivate::gtk_paint_handle = 0;
       
   146 Ptr_gtk_paint_expander QGtkStylePrivate::gtk_paint_expander = 0;
       
   147 Ptr_gtk_adjustment_new QGtkStylePrivate::gtk_adjustment_new = 0;
       
   148 Ptr_gtk_paint_hline QGtkStylePrivate::gtk_paint_hline = 0;
       
   149 Ptr_gtk_paint_vline QGtkStylePrivate::gtk_paint_vline = 0;
       
   150 Ptr_gtk_menu_item_set_submenu QGtkStylePrivate::gtk_menu_item_set_submenu = 0;
       
   151 Ptr_gtk_settings_get_default QGtkStylePrivate::gtk_settings_get_default = 0;
       
   152 Ptr_gtk_separator_menu_item_new QGtkStylePrivate::gtk_separator_menu_item_new = 0;
       
   153 Ptr_gtk_widget_size_allocate QGtkStylePrivate::gtk_widget_size_allocate = 0;
       
   154 Ptr_gtk_widget_set_direction QGtkStylePrivate::gtk_widget_set_direction = 0;
       
   155 Ptr_gtk_widget_path QGtkStylePrivate::gtk_widget_path = 0;
       
   156 Ptr_gtk_container_get_type QGtkStylePrivate::gtk_container_get_type = 0;
       
   157 Ptr_gtk_window_get_type QGtkStylePrivate::gtk_window_get_type = 0;
       
   158 Ptr_gtk_widget_get_type QGtkStylePrivate::gtk_widget_get_type = 0;
       
   159 Ptr_gtk_rc_get_style_by_paths QGtkStylePrivate::gtk_rc_get_style_by_paths = 0;
       
   160 Ptr_gtk_check_version QGtkStylePrivate::gtk_check_version = 0;
       
   161 Ptr_gtk_border_free QGtkStylePrivate::gtk_border_free = 0;
       
   162 
       
   163 Ptr_pango_font_description_get_size QGtkStylePrivate::pango_font_description_get_size = 0;
       
   164 Ptr_pango_font_description_get_weight QGtkStylePrivate::pango_font_description_get_weight = 0;
       
   165 Ptr_pango_font_description_get_family QGtkStylePrivate::pango_font_description_get_family = 0;
       
   166 Ptr_pango_font_description_get_style QGtkStylePrivate::pango_font_description_get_style = 0;
       
   167 
       
   168 Ptr_gtk_file_filter_new QGtkStylePrivate::gtk_file_filter_new = 0;
       
   169 Ptr_gtk_file_filter_set_name QGtkStylePrivate::gtk_file_filter_set_name = 0;
       
   170 Ptr_gtk_file_filter_add_pattern QGtkStylePrivate::gtk_file_filter_add_pattern = 0;
       
   171 Ptr_gtk_file_chooser_add_filter QGtkStylePrivate::gtk_file_chooser_add_filter = 0;
       
   172 Ptr_gtk_file_chooser_set_filter QGtkStylePrivate::gtk_file_chooser_set_filter = 0;
       
   173 Ptr_gtk_file_chooser_get_filter QGtkStylePrivate::gtk_file_chooser_get_filter = 0;
       
   174 Ptr_gtk_file_chooser_dialog_new QGtkStylePrivate::gtk_file_chooser_dialog_new = 0;
       
   175 Ptr_gtk_file_chooser_set_current_folder QGtkStylePrivate::gtk_file_chooser_set_current_folder = 0;
       
   176 Ptr_gtk_file_chooser_get_filename QGtkStylePrivate::gtk_file_chooser_get_filename = 0;
       
   177 Ptr_gtk_file_chooser_get_filenames QGtkStylePrivate::gtk_file_chooser_get_filenames = 0;
       
   178 Ptr_gtk_file_chooser_set_current_name QGtkStylePrivate::gtk_file_chooser_set_current_name = 0;
       
   179 Ptr_gtk_dialog_run QGtkStylePrivate::gtk_dialog_run = 0;
       
   180 Ptr_gtk_file_chooser_set_filename QGtkStylePrivate::gtk_file_chooser_set_filename = 0;
       
   181 
       
   182 Ptr_gdk_pixbuf_get_pixels QGtkStylePrivate::gdk_pixbuf_get_pixels = 0;
       
   183 Ptr_gdk_pixbuf_get_width QGtkStylePrivate::gdk_pixbuf_get_width = 0;
       
   184 Ptr_gdk_pixbuf_get_height QGtkStylePrivate::gdk_pixbuf_get_height = 0;
       
   185 Ptr_gdk_pixmap_new QGtkStylePrivate::gdk_pixmap_new = 0;
       
   186 Ptr_gdk_pixbuf_new QGtkStylePrivate::gdk_pixbuf_new = 0;
       
   187 Ptr_gdk_pixbuf_get_from_drawable QGtkStylePrivate::gdk_pixbuf_get_from_drawable = 0;
       
   188 Ptr_gdk_draw_rectangle QGtkStylePrivate::gdk_draw_rectangle = 0;
       
   189 Ptr_gdk_pixbuf_unref QGtkStylePrivate::gdk_pixbuf_unref = 0;
       
   190 Ptr_gdk_drawable_unref QGtkStylePrivate::gdk_drawable_unref = 0;
       
   191 Ptr_gdk_drawable_get_depth QGtkStylePrivate::gdk_drawable_get_depth = 0;
       
   192 Ptr_gdk_color_free QGtkStylePrivate::gdk_color_free = 0;
       
   193 Ptr_gdk_x11_window_set_user_time QGtkStylePrivate::gdk_x11_window_set_user_time = 0;
       
   194 Ptr_gdk_x11_drawable_get_xid QGtkStylePrivate::gdk_x11_drawable_get_xid = 0;
       
   195 Ptr_gdk_x11_drawable_get_xdisplay QGtkStylePrivate::gdk_x11_drawable_get_xdisplay = 0;
       
   196 
       
   197 Ptr_gconf_client_get_default QGtkStylePrivate::gconf_client_get_default = 0;
       
   198 Ptr_gconf_client_get_string QGtkStylePrivate::gconf_client_get_string = 0;
       
   199 Ptr_gconf_client_get_bool QGtkStylePrivate::gconf_client_get_bool = 0;
       
   200 
       
   201 Ptr_gnome_icon_lookup_sync QGtkStylePrivate::gnome_icon_lookup_sync = 0;
       
   202 Ptr_gnome_vfs_init QGtkStylePrivate::gnome_vfs_init = 0;
       
   203 
       
   204 typedef int (*x11ErrorHandler)(Display*, XErrorEvent*);
       
   205 
       
   206 QT_END_NAMESPACE
       
   207 
       
   208 Q_DECLARE_METATYPE(QGtkStylePrivate*);
       
   209 
       
   210 QT_BEGIN_NAMESPACE
       
   211 
       
   212 static void gtkStyleSetCallback(GtkWidget*)
       
   213 {
       
   214     qRegisterMetaType<QGtkStylePrivate *>();
       
   215 
       
   216     // We have to let this function return and complete the event
       
   217     // loop to ensure that all gtk widgets have been styled before
       
   218     // updating
       
   219     QMetaObject::invokeMethod(styleScheduler(), "updateTheme", Qt::QueuedConnection);
       
   220 }
       
   221 
       
   222 static void update_toolbar_style(GtkWidget *gtkToolBar, GParamSpec *, gpointer)
       
   223 {
       
   224     GtkToolbarStyle toolbar_style = GTK_TOOLBAR_ICONS;
       
   225     g_object_get(gtkToolBar, "toolbar-style", &toolbar_style, NULL);
       
   226     QWidgetList widgets = QApplication::allWidgets();
       
   227     for (int i = 0; i < widgets.size(); ++i) {
       
   228         QWidget *widget = widgets.at(i);
       
   229         if (qobject_cast<QToolButton*>(widget)) {
       
   230             QEvent event(QEvent::StyleChange);
       
   231             QApplication::sendEvent(widget, &event);
       
   232         }
       
   233     }
       
   234 }
       
   235 
       
   236 static QString classPath(GtkWidget *widget)
       
   237 {
       
   238     char* class_path;
       
   239     QGtkStylePrivate::gtk_widget_path (widget, NULL, &class_path, NULL);
       
   240     QString path = QLS(class_path);
       
   241     g_free(class_path);
       
   242 
       
   243     // Remove the prefixes
       
   244     path.remove(QLS("GtkWindow."));
       
   245     path.remove(QLS("GtkFixed."));
       
   246     return path;
       
   247 }
       
   248 
       
   249 
       
   250 
       
   251 bool QGtkStyleFilter::eventFilter(QObject *obj, QEvent *e)
       
   252 {
       
   253     if (e->type() == QEvent::ApplicationPaletteChange) {
       
   254         // Only do this the first time since this will also
       
   255         // generate applicationPaletteChange events
       
   256         if (!qt_app_palettes_hash() ||  qt_app_palettes_hash()->isEmpty()) {
       
   257             stylePrivate->applyCustomPaletteHash();
       
   258         }
       
   259     }
       
   260     return QObject::eventFilter(obj, e);
       
   261 }
       
   262 
       
   263 QList<QGtkStylePrivate *> QGtkStylePrivate::instances;
       
   264 
       
   265 QGtkStylePrivate::QGtkStylePrivate()
       
   266   : QCleanlooksStylePrivate()
       
   267   , filter(this)
       
   268 {
       
   269     instances.append(this);
       
   270 }
       
   271 
       
   272 QGtkStylePrivate::~QGtkStylePrivate()
       
   273 {
       
   274     instances.removeOne(this);
       
   275 }
       
   276 
       
   277 void QGtkStylePrivate::init()
       
   278 {
       
   279     resolveGtk();
       
   280     initGtkWidgets();
       
   281     if (isThemeAvailable())
       
   282         qApp->installEventFilter(&filter);
       
   283 }
       
   284 
       
   285 GtkWidget* QGtkStylePrivate::gtkWidget(const QString &path)
       
   286 {
       
   287     GtkWidget *widget = gtkWidgetMap()->value(path);
       
   288     if (!widget) {
       
   289         // Theme might have rearranged widget internals
       
   290         widget = gtkWidgetMap()->value(path);
       
   291     }
       
   292     return widget;
       
   293 }
       
   294 
       
   295 GtkStyle* QGtkStylePrivate::gtkStyle(const QString &path)
       
   296 {
       
   297     if (gtkWidgetMap()->contains(path))
       
   298         return gtkWidgetMap()->value(path)->style;
       
   299     return 0;
       
   300 }
       
   301 
       
   302 /*! \internal
       
   303  *  Get references to gtk functions after we dynamically load the library.
       
   304  */
       
   305 void QGtkStylePrivate::resolveGtk() const
       
   306 {
       
   307     // enforce the "0" suffix, so we'll open libgtk-x11-2.0.so.0
       
   308     QLibrary libgtk(QLS("gtk-x11-2.0"), 0, 0);
       
   309 
       
   310     gtk_init = (Ptr_gtk_init)libgtk.resolve("gtk_init");
       
   311     gtk_window_new = (Ptr_gtk_window_new)libgtk.resolve("gtk_window_new");
       
   312     gtk_style_attach = (Ptr_gtk_style_attach)libgtk.resolve("gtk_style_attach");
       
   313     gtk_widget_destroy = (Ptr_gtk_widget_destroy)libgtk.resolve("gtk_widget_destroy");
       
   314     gtk_widget_realize = (Ptr_gtk_widget_realize)libgtk.resolve("gtk_widget_realize");
       
   315 
       
   316     gtk_file_chooser_set_current_folder = (Ptr_gtk_file_chooser_set_current_folder)libgtk.resolve("gtk_file_chooser_set_current_folder");
       
   317     gtk_file_filter_new = (Ptr_gtk_file_filter_new)libgtk.resolve("gtk_file_filter_new");
       
   318     gtk_file_filter_set_name = (Ptr_gtk_file_filter_set_name)libgtk.resolve("gtk_file_filter_set_name");
       
   319     gtk_file_filter_add_pattern = (Ptr_gtk_file_filter_add_pattern)libgtk.resolve("gtk_file_filter_add_pattern");
       
   320     gtk_file_chooser_add_filter = (Ptr_gtk_file_chooser_add_filter)libgtk.resolve("gtk_file_chooser_add_filter");
       
   321     gtk_file_chooser_set_filter = (Ptr_gtk_file_chooser_set_filter)libgtk.resolve("gtk_file_chooser_set_filter");
       
   322     gtk_file_chooser_get_filter = (Ptr_gtk_file_chooser_get_filter)libgtk.resolve("gtk_file_chooser_get_filter");
       
   323     gtk_file_chooser_dialog_new = (Ptr_gtk_file_chooser_dialog_new)libgtk.resolve("gtk_file_chooser_dialog_new");
       
   324     gtk_file_chooser_set_current_folder = (Ptr_gtk_file_chooser_set_current_folder)libgtk.resolve("gtk_file_chooser_set_current_folder");
       
   325     gtk_file_chooser_get_filename = (Ptr_gtk_file_chooser_get_filename)libgtk.resolve("gtk_file_chooser_get_filename");
       
   326     gtk_file_chooser_get_filenames = (Ptr_gtk_file_chooser_get_filenames)libgtk.resolve("gtk_file_chooser_get_filenames");
       
   327     gtk_file_chooser_set_current_name = (Ptr_gtk_file_chooser_set_current_name)libgtk.resolve("gtk_file_chooser_set_current_name");
       
   328     gtk_dialog_run = (Ptr_gtk_dialog_run)libgtk.resolve("gtk_dialog_run");
       
   329     gtk_file_chooser_set_filename = (Ptr_gtk_file_chooser_set_filename)libgtk.resolve("gtk_file_chooser_set_filename");
       
   330 
       
   331     gdk_pixbuf_get_pixels = (Ptr_gdk_pixbuf_get_pixels)libgtk.resolve("gdk_pixbuf_get_pixels");
       
   332     gdk_pixbuf_get_width = (Ptr_gdk_pixbuf_get_width)libgtk.resolve("gdk_pixbuf_get_width");
       
   333     gdk_pixbuf_get_height = (Ptr_gdk_pixbuf_get_height)libgtk.resolve("gdk_pixbuf_get_height");
       
   334     gdk_pixmap_new = (Ptr_gdk_pixmap_new)libgtk.resolve("gdk_pixmap_new");
       
   335     gdk_pixbuf_new = (Ptr_gdk_pixbuf_new)libgtk.resolve("gdk_pixbuf_new");
       
   336     gdk_pixbuf_get_from_drawable = (Ptr_gdk_pixbuf_get_from_drawable)libgtk.resolve("gdk_pixbuf_get_from_drawable");
       
   337     gdk_draw_rectangle = (Ptr_gdk_draw_rectangle)libgtk.resolve("gdk_draw_rectangle");
       
   338     gdk_pixbuf_unref = (Ptr_gdk_pixbuf_unref)libgtk.resolve("gdk_pixbuf_unref");
       
   339     gdk_drawable_unref = (Ptr_gdk_drawable_unref)libgtk.resolve("gdk_drawable_unref");
       
   340     gdk_drawable_get_depth = (Ptr_gdk_drawable_get_depth)libgtk.resolve("gdk_drawable_get_depth");
       
   341     gdk_color_free = (Ptr_gdk_color_free)libgtk.resolve("gdk_color_free");
       
   342     gdk_x11_window_set_user_time = (Ptr_gdk_x11_window_set_user_time)libgtk.resolve("gdk_x11_window_set_user_time");
       
   343     gdk_x11_drawable_get_xid = (Ptr_gdk_x11_drawable_get_xid)libgtk.resolve("gdk_x11_drawable_get_xid");
       
   344     gdk_x11_drawable_get_xdisplay = (Ptr_gdk_x11_drawable_get_xdisplay)libgtk.resolve("gdk_x11_drawable_get_xdisplay");
       
   345 
       
   346     gtk_widget_set_default_direction = (Ptr_gtk_widget_set_default_direction)libgtk.resolve("gtk_widget_set_default_direction");
       
   347     gtk_widget_modify_fg = (Ptr_gtk_widget_modify_color)libgtk.resolve("gtk_widget_modify_fg");
       
   348     gtk_widget_modify_bg = (Ptr_gtk_widget_modify_color)libgtk.resolve("gtk_widget_modify_bg");
       
   349     gtk_arrow_new = (Ptr_gtk_arrow_new)libgtk.resolve("gtk_arrow_new");
       
   350     gtk_menu_item_new = (Ptr_gtk_menu_item_new)libgtk.resolve("gtk_menu_item_new");
       
   351     gtk_check_menu_item_new = (Ptr_gtk_check_menu_item_new)libgtk.resolve("gtk_check_menu_item_new");
       
   352     gtk_menu_bar_new = (Ptr_gtk_menu_bar_new)libgtk.resolve("gtk_menu_bar_new");
       
   353     gtk_menu_new = (Ptr_gtk_menu_new)libgtk.resolve("gtk_menu_new");
       
   354     gtk_toolbar_new = (Ptr_gtk_toolbar_new)libgtk.resolve("gtk_toolbar_new");
       
   355     gtk_separator_tool_item_new = (Ptr_gtk_separator_tool_item_new)libgtk.resolve("gtk_separator_tool_item_new");
       
   356     gtk_toolbar_insert = (Ptr_gtk_toolbar_insert)libgtk.resolve("gtk_toolbar_insert");
       
   357     gtk_button_new = (Ptr_gtk_button_new)libgtk.resolve("gtk_button_new");
       
   358     gtk_tool_button_new = (Ptr_gtk_tool_button_new)libgtk.resolve("gtk_tool_button_new");
       
   359     gtk_hbutton_box_new = (Ptr_gtk_hbutton_box_new)libgtk.resolve("gtk_hbutton_box_new");
       
   360     gtk_check_button_new = (Ptr_gtk_check_button_new)libgtk.resolve("gtk_check_button_new");
       
   361     gtk_radio_button_new = (Ptr_gtk_radio_button_new)libgtk.resolve("gtk_radio_button_new");
       
   362     gtk_notebook_new = (Ptr_gtk_notebook_new)libgtk.resolve("gtk_notebook_new");
       
   363     gtk_progress_bar_new = (Ptr_gtk_progress_bar_new)libgtk.resolve("gtk_progress_bar_new");
       
   364     gtk_spin_button_new = (Ptr_gtk_spin_button_new)libgtk.resolve("gtk_spin_button_new");
       
   365     gtk_hscale_new = (Ptr_gtk_hscale_new)libgtk.resolve("gtk_hscale_new");
       
   366     gtk_vscale_new = (Ptr_gtk_vscale_new)libgtk.resolve("gtk_vscale_new");
       
   367     gtk_hscrollbar_new = (Ptr_gtk_hscrollbar_new)libgtk.resolve("gtk_hscrollbar_new");
       
   368     gtk_vscrollbar_new = (Ptr_gtk_vscrollbar_new)libgtk.resolve("gtk_vscrollbar_new");
       
   369     gtk_scrolled_window_new = (Ptr_gtk_scrolled_window_new)libgtk.resolve("gtk_scrolled_window_new");
       
   370     gtk_menu_shell_append = (Ptr_gtk_menu_shell_append)libgtk.resolve("gtk_menu_shell_append");
       
   371     gtk_entry_new = (Ptr_gtk_entry_new)libgtk.resolve("gtk_entry_new");
       
   372     gtk_tree_view_new = (Ptr_gtk_tree_view_new)libgtk.resolve("gtk_tree_view_new");
       
   373     gtk_combo_box_new = (Ptr_gtk_combo_box_new)libgtk.resolve("gtk_combo_box_new");
       
   374     gtk_progress_set_adjustment = (Ptr_gtk_progress_set_adjustment)libgtk.resolve("gtk_progress_set_adjustment");
       
   375     gtk_range_set_adjustment = (Ptr_gtk_range_set_adjustment)libgtk.resolve("gtk_range_set_adjustment");
       
   376     gtk_range_set_inverted = (Ptr_gtk_range_set_inverted)libgtk.resolve("gtk_range_set_inverted");
       
   377     gtk_container_add = (Ptr_gtk_container_add)libgtk.resolve("gtk_container_add");
       
   378     gtk_icon_factory_lookup_default = (Ptr_gtk_icon_factory_lookup_default)libgtk.resolve("gtk_icon_factory_lookup_default");
       
   379     gtk_icon_theme_get_default = (Ptr_gtk_icon_theme_get_default)libgtk.resolve("gtk_icon_theme_get_default");
       
   380     gtk_widget_style_get = (Ptr_gtk_widget_style_get)libgtk.resolve("gtk_widget_style_get");
       
   381     gtk_icon_set_render_icon = (Ptr_gtk_icon_set_render_icon)libgtk.resolve("gtk_icon_set_render_icon");
       
   382     gtk_fixed_new = (Ptr_gtk_fixed_new)libgtk.resolve("gtk_fixed_new");
       
   383     gtk_tree_view_column_new = (Ptr_gtk_tree_view_column_new)libgtk.resolve("gtk_tree_view_column_new");
       
   384     gtk_tree_view_append_column= (Ptr_gtk_tree_view_append_column )libgtk.resolve("gtk_tree_view_append_column");
       
   385     gtk_tree_view_get_column = (Ptr_gtk_tree_view_get_column )libgtk.resolve("gtk_tree_view_get_column");
       
   386     gtk_paint_check = (Ptr_gtk_paint_check)libgtk.resolve("gtk_paint_check");
       
   387     gtk_paint_box = (Ptr_gtk_paint_box)libgtk.resolve("gtk_paint_box");
       
   388     gtk_paint_flat_box = (Ptr_gtk_paint_flat_box)libgtk.resolve("gtk_paint_flat_box");
       
   389     gtk_paint_check = (Ptr_gtk_paint_check)libgtk.resolve("gtk_paint_check");
       
   390     gtk_paint_box = (Ptr_gtk_paint_box)libgtk.resolve("gtk_paint_box");
       
   391     gtk_paint_resize_grip = (Ptr_gtk_paint_resize_grip)libgtk.resolve("gtk_paint_resize_grip");
       
   392     gtk_paint_focus = (Ptr_gtk_paint_focus)libgtk.resolve("gtk_paint_focus");
       
   393     gtk_paint_shadow = (Ptr_gtk_paint_shadow)libgtk.resolve("gtk_paint_shadow");
       
   394     gtk_paint_slider = (Ptr_gtk_paint_slider)libgtk.resolve("gtk_paint_slider");
       
   395     gtk_paint_expander = (Ptr_gtk_paint_expander)libgtk.resolve("gtk_paint_expander");
       
   396     gtk_paint_handle = (Ptr_gtk_paint_handle)libgtk.resolve("gtk_paint_handle");
       
   397     gtk_paint_option = (Ptr_gtk_paint_option)libgtk.resolve("gtk_paint_option");
       
   398     gtk_paint_arrow = (Ptr_gtk_paint_arrow)libgtk.resolve("gtk_paint_arrow");
       
   399     gtk_paint_box_gap = (Ptr_gtk_paint_box_gap)libgtk.resolve("gtk_paint_box_gap");
       
   400     gtk_paint_extension = (Ptr_gtk_paint_extension)libgtk.resolve("gtk_paint_extension");
       
   401     gtk_paint_hline = (Ptr_gtk_paint_hline)libgtk.resolve("gtk_paint_hline");
       
   402     gtk_paint_vline = (Ptr_gtk_paint_vline)libgtk.resolve("gtk_paint_vline");
       
   403     gtk_adjustment_new = (Ptr_gtk_adjustment_new)libgtk.resolve("gtk_adjustment_new");
       
   404     gtk_menu_item_set_submenu = (Ptr_gtk_menu_item_set_submenu)libgtk.resolve("gtk_menu_item_set_submenu");
       
   405     gtk_settings_get_default = (Ptr_gtk_settings_get_default)libgtk.resolve("gtk_settings_get_default");
       
   406     gtk_separator_menu_item_new = (Ptr_gtk_separator_menu_item_new)libgtk.resolve("gtk_separator_menu_item_new");
       
   407     gtk_frame_new = (Ptr_gtk_frame_new)libgtk.resolve("gtk_frame_new");
       
   408     gtk_expander_new = (Ptr_gtk_expander_new)libgtk.resolve("gtk_expander_new");
       
   409     gtk_statusbar_new = (Ptr_gtk_statusbar_new)libgtk.resolve("gtk_statusbar_new");
       
   410     gtk_combo_box_entry_new = (Ptr_gtk_combo_box_entry_new)libgtk.resolve("gtk_combo_box_entry_new");
       
   411     gtk_container_forall = (Ptr_gtk_container_forall)libgtk.resolve("gtk_container_forall");
       
   412     gtk_widget_size_allocate =(Ptr_gtk_widget_size_allocate)libgtk.resolve("gtk_widget_size_allocate");
       
   413     gtk_widget_set_direction =(Ptr_gtk_widget_set_direction)libgtk.resolve("gtk_widget_set_direction");
       
   414     gtk_widget_path =(Ptr_gtk_widget_path)libgtk.resolve("gtk_widget_path");
       
   415     gtk_container_get_type =(Ptr_gtk_container_get_type)libgtk.resolve("gtk_container_get_type");
       
   416     gtk_window_get_type =(Ptr_gtk_window_get_type)libgtk.resolve("gtk_window_get_type");
       
   417     gtk_widget_get_type =(Ptr_gtk_widget_get_type)libgtk.resolve("gtk_widget_get_type");
       
   418     gtk_rc_get_style_by_paths =(Ptr_gtk_rc_get_style_by_paths)libgtk.resolve("gtk_rc_get_style_by_paths");
       
   419     gtk_check_version =(Ptr_gtk_check_version)libgtk.resolve("gtk_check_version");
       
   420     gtk_border_free =(Ptr_gtk_border_free)libgtk.resolve("gtk_border_free");
       
   421     pango_font_description_get_size = (Ptr_pango_font_description_get_size)libgtk.resolve("pango_font_description_get_size");
       
   422     pango_font_description_get_weight = (Ptr_pango_font_description_get_weight)libgtk.resolve("pango_font_description_get_weight");
       
   423     pango_font_description_get_family = (Ptr_pango_font_description_get_family)libgtk.resolve("pango_font_description_get_family");
       
   424     pango_font_description_get_style = (Ptr_pango_font_description_get_style)libgtk.resolve("pango_font_description_get_style");
       
   425 
       
   426     gnome_icon_lookup_sync = (Ptr_gnome_icon_lookup_sync)QLibrary::resolve(QLS("gnomeui-2"), 0, "gnome_icon_lookup_sync");
       
   427     gnome_vfs_init= (Ptr_gnome_vfs_init)QLibrary::resolve(QLS("gnomevfs-2"), 0, "gnome_vfs_init");
       
   428 }
       
   429 
       
   430 /* \internal
       
   431  * Initializes a number of gtk menu widgets.
       
   432  * The widgets are cached.
       
   433  */
       
   434 void QGtkStylePrivate::initGtkMenu() const
       
   435 {
       
   436     // Create menubar
       
   437     GtkWidget *gtkMenuBar = QGtkStylePrivate::gtk_menu_bar_new();
       
   438     setupGtkWidget(gtkMenuBar);
       
   439 
       
   440     GtkWidget *gtkMenuBarItem = QGtkStylePrivate::gtk_menu_item_new();
       
   441     gtk_menu_shell_append((GtkMenuShell*)(gtkMenuBar), gtkMenuBarItem);
       
   442     gtk_widget_realize(gtkMenuBarItem);
       
   443 
       
   444     // Create menu
       
   445     GtkWidget *gtkMenu = QGtkStylePrivate::gtk_menu_new();
       
   446     gtk_menu_item_set_submenu((GtkMenuItem*)(gtkMenuBarItem), gtkMenu);
       
   447     gtk_widget_realize(gtkMenu);
       
   448 
       
   449     GtkWidget *gtkMenuItem = QGtkStylePrivate::gtk_menu_item_new();
       
   450     gtk_menu_shell_append((GtkMenuShell*)gtkMenu, gtkMenuItem);
       
   451     gtk_widget_realize(gtkMenuItem);
       
   452 
       
   453     GtkWidget *gtkCheckMenuItem = QGtkStylePrivate::gtk_check_menu_item_new();
       
   454     gtk_menu_shell_append((GtkMenuShell*)gtkMenu, gtkCheckMenuItem);
       
   455     gtk_widget_realize(gtkCheckMenuItem);
       
   456 
       
   457     GtkWidget *gtkMenuSeparator = QGtkStylePrivate::gtk_separator_menu_item_new();
       
   458     gtk_menu_shell_append((GtkMenuShell*)gtkMenu, gtkMenuSeparator);
       
   459 
       
   460     addAllSubWidgets(gtkMenuBar);
       
   461     addAllSubWidgets(gtkMenu);
       
   462 }
       
   463 
       
   464 
       
   465 void QGtkStylePrivate::initGtkTreeview() const
       
   466 {
       
   467     GtkWidget *gtkTreeView = gtk_tree_view_new();
       
   468     gtk_tree_view_append_column((GtkTreeView*)gtkTreeView, gtk_tree_view_column_new());
       
   469     gtk_tree_view_append_column((GtkTreeView*)gtkTreeView, gtk_tree_view_column_new());
       
   470     gtk_tree_view_append_column((GtkTreeView*)gtkTreeView, gtk_tree_view_column_new());
       
   471     addWidget(gtkTreeView);
       
   472 }
       
   473 
       
   474 
       
   475 /* \internal
       
   476  * Initializes a number of gtk widgets that we can later on use to determine some of our styles.
       
   477  * The widgets are cached.
       
   478  */
       
   479 void QGtkStylePrivate::initGtkWidgets() const
       
   480 {
       
   481     // From gtkmain.c
       
   482     uid_t ruid = getuid ();
       
   483     uid_t rgid = getgid ();
       
   484     uid_t euid = geteuid ();
       
   485     uid_t egid = getegid ();
       
   486     if (ruid != euid || rgid != egid) {
       
   487         qWarning("\nThis process is currently running setuid or setgid.\nGTK+ does not allow this "
       
   488                  "therefore Qt cannot use the GTK+ integration.\nTry launching your app using \'gksudo\', "
       
   489                  "\'kdesudo\' or a similar tool.\n\n"
       
   490                  "See http://www.gtk.org/setuid.html for more information.\n");
       
   491         return;
       
   492     }
       
   493 
       
   494     static QString themeName;
       
   495     if (!gtkWidgetMap()->contains(QLS("GtkWindow")) && themeName.isEmpty()) {
       
   496         themeName = getThemeName();
       
   497 
       
   498         if (themeName.isEmpty()) {
       
   499             qWarning("QGtkStyle was unable to detect the current GTK+ theme.");
       
   500             return;
       
   501         } else if (themeName == QLS("Qt") || themeName == QLS("Qt4")) {
       
   502             // Due to namespace conflicts with Qt3 and obvious recursion with Qt4,
       
   503             // we cannot support the GTK_Qt Gtk engine
       
   504             qWarning("QGtkStyle cannot be used together with the GTK_Qt engine.");
       
   505             return;
       
   506         }
       
   507     }
       
   508 
       
   509     if (QGtkStylePrivate::gtk_init) {
       
   510         // Gtk will set the Qt error handler so we have to reset it afterwards
       
   511         x11ErrorHandler qt_x_errhandler = XSetErrorHandler(0);
       
   512         QGtkStylePrivate::gtk_init (NULL, NULL);
       
   513         XSetErrorHandler(qt_x_errhandler);
       
   514 
       
   515         // make a window
       
   516         GtkWidget* gtkWindow = QGtkStylePrivate::gtk_window_new(GTK_WINDOW_POPUP);
       
   517         QGtkStylePrivate::gtk_widget_realize(gtkWindow);
       
   518         if (displayDepth == -1)
       
   519             displayDepth = QGtkStylePrivate::gdk_drawable_get_depth(gtkWindow->window);
       
   520         gtkWidgetMap()->insert(QLS("GtkWindow"), gtkWindow);
       
   521 
       
   522 
       
   523         // Make all other widgets. respect the text direction
       
   524         if (qApp->layoutDirection() == Qt::RightToLeft)
       
   525             QGtkStylePrivate::gtk_widget_set_default_direction(GTK_TEXT_DIR_RTL);
       
   526 
       
   527         if (!gtkWidgetMap()->contains(QLS("GtkButton"))) {
       
   528             GtkWidget *gtkButton = QGtkStylePrivate::gtk_button_new();
       
   529             addWidget(gtkButton);
       
   530             g_signal_connect(gtkButton, "style-set", G_CALLBACK(gtkStyleSetCallback), 0);
       
   531             addWidget(QGtkStylePrivate::gtk_tool_button_new(NULL, NULL));
       
   532             addWidget(QGtkStylePrivate::gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE));
       
   533             addWidget(QGtkStylePrivate::gtk_hbutton_box_new());
       
   534             addWidget(QGtkStylePrivate::gtk_check_button_new());
       
   535             addWidget(QGtkStylePrivate::gtk_radio_button_new(NULL));
       
   536             addWidget(QGtkStylePrivate::gtk_combo_box_new());
       
   537             addWidget(QGtkStylePrivate::gtk_combo_box_entry_new());
       
   538             addWidget(QGtkStylePrivate::gtk_entry_new());
       
   539             addWidget(QGtkStylePrivate::gtk_frame_new(NULL));
       
   540             addWidget(QGtkStylePrivate::gtk_expander_new(""));
       
   541             addWidget(QGtkStylePrivate::gtk_statusbar_new());
       
   542             addWidget(QGtkStylePrivate::gtk_hscale_new((GtkAdjustment*)(QGtkStylePrivate::gtk_adjustment_new(1, 0, 1, 0, 0, 0))));
       
   543             addWidget(QGtkStylePrivate::gtk_hscrollbar_new(NULL));
       
   544             addWidget(QGtkStylePrivate::gtk_scrolled_window_new(NULL, NULL));
       
   545 
       
   546             initGtkMenu();
       
   547             addWidget(QGtkStylePrivate::gtk_notebook_new());
       
   548             addWidget(QGtkStylePrivate::gtk_progress_bar_new());
       
   549             addWidget(QGtkStylePrivate::gtk_spin_button_new((GtkAdjustment*)
       
   550                                              (QGtkStylePrivate::gtk_adjustment_new(1, 0, 1, 0, 0, 0)), 0.1, 3));
       
   551             GtkWidget *toolbar = gtk_toolbar_new();
       
   552             g_signal_connect (toolbar, "notify::toolbar-style", G_CALLBACK (update_toolbar_style), toolbar);
       
   553             gtk_toolbar_insert((GtkToolbar*)toolbar, gtk_separator_tool_item_new(), -1);
       
   554             addWidget(toolbar);
       
   555             initGtkTreeview();
       
   556             addWidget(gtk_vscale_new((GtkAdjustment*)(QGtkStylePrivate::gtk_adjustment_new(1, 0, 1, 0, 0, 0))));
       
   557             addWidget(gtk_vscrollbar_new(NULL));
       
   558         }
       
   559         else // Rebuild map
       
   560         {
       
   561             // When styles change subwidgets can get rearranged
       
   562             // as with the combo box. We need to update the widget map
       
   563             // to reflect this;
       
   564             QHash<QString, GtkWidget*> oldMap = *gtkWidgetMap();
       
   565             gtkWidgetMap()->clear();
       
   566             QHashIterator<QString, GtkWidget*> it(oldMap);
       
   567             while (it.hasNext()) {
       
   568                 it.next();
       
   569                 if (!it.key().contains(QLatin1Char('.'))) {
       
   570                     addAllSubWidgets(it.value());
       
   571                 }
       
   572             }
       
   573         }
       
   574     } else {
       
   575         qWarning("QGtkStyle could not resolve GTK. Make sure you have installed the proper libraries.");
       
   576     }
       
   577 }
       
   578 
       
   579 /*! \internal
       
   580  * destroys all previously buffered widgets.
       
   581  */
       
   582 void QGtkStylePrivate::cleanupGtkWidgets()
       
   583 {
       
   584     if (gtkWidgetMap()->contains(QLS("GtkWindow"))) // Gtk will destroy all children
       
   585         gtk_widget_destroy(gtkWidgetMap()->value(QLS("GtkWindow")));
       
   586 }
       
   587 
       
   588 static bool resolveGConf()
       
   589 {
       
   590     if (!QGtkStylePrivate::gconf_client_get_default) {
       
   591         QGtkStylePrivate::gconf_client_get_default = (Ptr_gconf_client_get_default)QLibrary::resolve(QLS("gconf-2"), 4, "gconf_client_get_default");
       
   592         QGtkStylePrivate::gconf_client_get_string =  (Ptr_gconf_client_get_string)QLibrary::resolve(QLS("gconf-2"), 4, "gconf_client_get_string");
       
   593         QGtkStylePrivate::gconf_client_get_bool =  (Ptr_gconf_client_get_bool)QLibrary::resolve(QLS("gconf-2"), 4, "gconf_client_get_bool");
       
   594     }
       
   595     return (QGtkStylePrivate::gconf_client_get_default !=0);
       
   596 }
       
   597 
       
   598 QString QGtkStylePrivate::getGConfString(const QString &value, const QString &fallback)
       
   599 {
       
   600     QString retVal = fallback;
       
   601     if (resolveGConf()) {
       
   602         g_type_init();
       
   603         GConfClient* client = gconf_client_get_default();
       
   604         GError *err = 0;
       
   605         char *str = gconf_client_get_string(client, qPrintable(value), &err);
       
   606         if (!err) {
       
   607             retVal = QString::fromUtf8(str);
       
   608             g_free(str);
       
   609         }
       
   610         g_object_unref(client);
       
   611         if (err)
       
   612             g_error_free (err);
       
   613     }
       
   614     return retVal;
       
   615 }
       
   616 
       
   617 bool QGtkStylePrivate::getGConfBool(const QString &key, bool fallback)
       
   618 {
       
   619     bool retVal = fallback;
       
   620     if (resolveGConf()) {
       
   621         g_type_init();
       
   622         GConfClient* client = gconf_client_get_default();
       
   623         GError *err = 0;
       
   624         bool result = gconf_client_get_bool(client, qPrintable(key), &err);
       
   625         g_object_unref(client);
       
   626         if (!err)
       
   627             retVal = result;
       
   628         else
       
   629             g_error_free (err);
       
   630     }
       
   631     return retVal;
       
   632 }
       
   633 
       
   634 QString QGtkStylePrivate::getThemeName()
       
   635 {
       
   636     QString themeName;
       
   637     // We try to parse the gtkrc file first
       
   638     // primarily to avoid resolving Gtk functions if
       
   639     // the KDE 3 "Qt" style is currently in use
       
   640     QString rcPaths = QString::fromLocal8Bit(qgetenv("GTK2_RC_FILES"));
       
   641     if (!rcPaths.isEmpty()) {
       
   642         QStringList paths = rcPaths.split(QLS(":"));
       
   643         foreach (const QString &rcPath, paths) {
       
   644             if (!rcPath.isEmpty()) {
       
   645                 QFile rcFile(rcPath);
       
   646                 if (rcFile.exists() && rcFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
       
   647                     QTextStream in(&rcFile);
       
   648                     while(!in.atEnd()) {
       
   649                         QString line = in.readLine();
       
   650                         if (line.contains(QLS("gtk-theme-name"))) {
       
   651                             line = line.right(line.length() - line.indexOf(QLatin1Char('=')) - 1);
       
   652                             line.remove(QLatin1Char('\"'));
       
   653                             line = line.trimmed();
       
   654                             themeName = line;
       
   655                             break;
       
   656                         }
       
   657                     }
       
   658                 }
       
   659             }
       
   660             if (!themeName.isEmpty())
       
   661                 break;
       
   662         }
       
   663     }
       
   664 
       
   665     // Fall back to gconf
       
   666     if (themeName.isEmpty() && resolveGConf())
       
   667         themeName = getGConfString(QLS("/desktop/gnome/interface/gtk_theme"));
       
   668 
       
   669     return themeName;
       
   670 }
       
   671 
       
   672 // Get size of the arrow controls in a GtkSpinButton
       
   673 int QGtkStylePrivate::getSpinboxArrowSize() const
       
   674 {
       
   675     const int MIN_ARROW_WIDTH = 6;
       
   676     GtkWidget *spinButton = gtkWidget(QLS("GtkSpinButton"));
       
   677     GtkStyle *style = spinButton->style;
       
   678     gint size = pango_font_description_get_size (style->font_desc);
       
   679     gint arrow_size;
       
   680     arrow_size = qMax(PANGO_PIXELS (size), MIN_ARROW_WIDTH) + style->xthickness;
       
   681     arrow_size += arrow_size%2 + 1;
       
   682     return arrow_size;
       
   683 }
       
   684 
       
   685 
       
   686 bool QGtkStylePrivate::isKDE4Session()
       
   687 {
       
   688     static int version = -1;
       
   689     if (version == -1)
       
   690         version = qgetenv("KDE_SESSION_VERSION").toInt();
       
   691     return (version == 4);
       
   692 }
       
   693 
       
   694 void QGtkStylePrivate::applyCustomPaletteHash()
       
   695 {
       
   696     QPalette menuPal = gtkWidgetPalette(QLS("GtkMenu"));
       
   697     GdkColor gdkBg = gtkWidget(QLS("GtkMenu"))->style->bg[GTK_STATE_NORMAL];
       
   698     QColor bgColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8);
       
   699     menuPal.setBrush(QPalette::Base, bgColor);
       
   700     menuPal.setBrush(QPalette::Window, bgColor);
       
   701     qApp->setPalette(menuPal, "QMenu");
       
   702 
       
   703     QPalette toolbarPal = gtkWidgetPalette(QLS("GtkToolbar"));
       
   704     qApp->setPalette(toolbarPal, "QToolBar");
       
   705 
       
   706     QPalette menuBarPal = gtkWidgetPalette(QLS("GtkMenuBar"));
       
   707     qApp->setPalette(menuBarPal, "QMenuBar");
       
   708 }
       
   709 
       
   710 /*! \internal
       
   711  *  Returns the gtk Widget that should be used to determine text foreground and background colors.
       
   712 */
       
   713 GtkWidget* QGtkStylePrivate::getTextColorWidget() const
       
   714 {
       
   715     return  gtkWidget(QLS("GtkEntry"));
       
   716 }
       
   717 
       
   718 void QGtkStylePrivate::setupGtkWidget(GtkWidget* widget)
       
   719 {
       
   720     if (Q_GTK_IS_WIDGET(widget)) {
       
   721         static GtkWidget* protoLayout = 0;
       
   722         if (!protoLayout) {
       
   723             protoLayout = QGtkStylePrivate::gtk_fixed_new();
       
   724             QGtkStylePrivate::gtk_container_add((GtkContainer*)(gtkWidgetMap()->value(QLS("GtkWindow"))), protoLayout);
       
   725         }
       
   726         Q_ASSERT(protoLayout);
       
   727 
       
   728         if (!widget->parent && !GTK_WIDGET_TOPLEVEL(widget))
       
   729             QGtkStylePrivate::gtk_container_add((GtkContainer*)(protoLayout), widget);
       
   730         QGtkStylePrivate::gtk_widget_realize(widget);
       
   731     }
       
   732 }
       
   733 
       
   734 void QGtkStylePrivate::addWidgetToMap(GtkWidget *widget)
       
   735 {
       
   736     if (Q_GTK_IS_WIDGET(widget)) {
       
   737        gtk_widget_realize(widget);
       
   738        gtkWidgetMap()->insert(classPath(widget), widget);
       
   739     }
       
   740  }
       
   741 
       
   742 void QGtkStylePrivate::addAllSubWidgets(GtkWidget *widget, gpointer v)
       
   743 {
       
   744     Q_UNUSED(v);
       
   745     addWidgetToMap(widget);
       
   746     if (GTK_CHECK_TYPE ((widget), gtk_container_get_type()))
       
   747         gtk_container_forall((GtkContainer*)widget, addAllSubWidgets, NULL);
       
   748 }
       
   749 
       
   750 // Updates window/windowtext palette based on the indicated gtk widget
       
   751 QPalette QGtkStylePrivate::gtkWidgetPalette(const QString &gtkWidgetName) const
       
   752 {
       
   753     GtkWidget *gtkWidget = QGtkStylePrivate::gtkWidget(gtkWidgetName);
       
   754     Q_ASSERT(gtkWidget);
       
   755     QPalette pal = QApplication::palette();
       
   756     GdkColor gdkBg = gtkWidget->style->bg[GTK_STATE_NORMAL];
       
   757     GdkColor gdkText = gtkWidget->style->fg[GTK_STATE_NORMAL];
       
   758     GdkColor gdkDisabledText = gtkWidget->style->fg[GTK_STATE_INSENSITIVE];
       
   759     QColor bgColor(gdkBg.red>>8, gdkBg.green>>8, gdkBg.blue>>8);
       
   760     QColor textColor(gdkText.red>>8, gdkText.green>>8, gdkText.blue>>8);
       
   761     QColor disabledTextColor(gdkDisabledText.red>>8, gdkDisabledText.green>>8, gdkDisabledText.blue>>8);
       
   762     pal.setBrush(QPalette::Window, bgColor);
       
   763     pal.setBrush(QPalette::Button, bgColor);
       
   764     pal.setBrush(QPalette::All, QPalette::WindowText, textColor);
       
   765     pal.setBrush(QPalette::Disabled, QPalette::WindowText, disabledTextColor);
       
   766     pal.setBrush(QPalette::All, QPalette::ButtonText, textColor);
       
   767     pal.setBrush(QPalette::Disabled, QPalette::ButtonText, disabledTextColor);
       
   768     return pal;
       
   769 }
       
   770 
       
   771 
       
   772 void QGtkStyleUpdateScheduler::updateTheme()
       
   773 {
       
   774     static QString oldTheme(QLS("qt_not_set"));
       
   775     QPixmapCache::clear();
       
   776 
       
   777     QFont font = QGtkStylePrivate::getThemeFont();
       
   778     if (QApplication::font() != font)
       
   779         qApp->setFont(font);
       
   780 
       
   781       if (oldTheme != QGtkStylePrivate::getThemeName()) {
       
   782           oldTheme = QGtkStylePrivate::getThemeName();
       
   783           QPalette newPalette = qApp->style()->standardPalette();
       
   784           QApplicationPrivate::setSystemPalette(newPalette);
       
   785           QApplication::setPalette(newPalette);
       
   786           if (!QGtkStylePrivate::instances.isEmpty()) {
       
   787               QGtkStylePrivate::instances.last()->initGtkWidgets();
       
   788               QGtkStylePrivate::instances.last()->applyCustomPaletteHash();
       
   789           }
       
   790           QList<QWidget*> widgets = QApplication::allWidgets();
       
   791           // Notify all widgets that size metrics might have changed
       
   792           foreach (QWidget *widget, widgets) {
       
   793               QEvent e(QEvent::StyleChange);
       
   794               QApplication::sendEvent(widget, &e);
       
   795           }
       
   796       }
       
   797     QIconLoader::instance()->updateSystemTheme();
       
   798 }
       
   799 
       
   800 void QGtkStylePrivate::addWidget(GtkWidget *widget)
       
   801 {
       
   802     if (widget) {
       
   803         setupGtkWidget(widget);
       
   804         addAllSubWidgets(widget);
       
   805     }
       
   806 }
       
   807 
       
   808 
       
   809 // Fetch the application font from the pango font description
       
   810 // contained in the theme.
       
   811 QFont QGtkStylePrivate::getThemeFont()
       
   812 {
       
   813     QFont font;
       
   814     GtkStyle *style = gtkStyle();
       
   815     if (style && qApp->desktopSettingsAware())
       
   816     {
       
   817         PangoFontDescription *gtk_font = style->font_desc;
       
   818         font.setPointSizeF((float)(pango_font_description_get_size(gtk_font))/PANGO_SCALE);
       
   819 
       
   820         QString family = QString::fromLatin1(pango_font_description_get_family(gtk_font));
       
   821         if (!family.isEmpty())
       
   822             font.setFamily(family);
       
   823 
       
   824         int weight = pango_font_description_get_weight(gtk_font);
       
   825         if (weight >= PANGO_WEIGHT_HEAVY)
       
   826             font.setWeight(QFont::Black);
       
   827         else if (weight >= PANGO_WEIGHT_BOLD)
       
   828             font.setWeight(QFont::Bold);
       
   829         else if (weight >= PANGO_WEIGHT_SEMIBOLD)
       
   830             font.setWeight(QFont::DemiBold);
       
   831         else if (weight >= PANGO_WEIGHT_NORMAL)
       
   832             font.setWeight(QFont::Normal);
       
   833         else
       
   834             font.setWeight(QFont::Light);
       
   835 
       
   836         PangoStyle fontstyle = pango_font_description_get_style(gtk_font);
       
   837         if (fontstyle == PANGO_STYLE_ITALIC)
       
   838             font.setStyle(QFont::StyleItalic);
       
   839         else if (fontstyle == PANGO_STYLE_OBLIQUE)
       
   840             font.setStyle(QFont::StyleOblique);
       
   841         else
       
   842             font.setStyle(QFont::StyleNormal);
       
   843     }
       
   844     return font;
       
   845 }
       
   846 
       
   847 
       
   848 // ----------- Native file dialogs -----------
       
   849 
       
   850 // Extract filter list from expressions of type: foo (*.a *.b *.c)"
       
   851 QStringList QGtkStylePrivate::extract_filter(const QString &rawFilter)
       
   852 {
       
   853     QString result = rawFilter;
       
   854     QRegExp r(QString::fromLatin1("^([^()]*)\\(([a-zA-Z0-9_.*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$"));
       
   855     int index = r.indexIn(result);
       
   856     if (index >= 0)
       
   857         result = r.cap(2);
       
   858     return result.split(QLatin1Char(' '));
       
   859 }
       
   860 
       
   861 extern QStringList qt_make_filter_list(const QString &filter);
       
   862 
       
   863 void QGtkStylePrivate::setupGtkFileChooser(GtkWidget* gtkFileChooser, QWidget *parent,
       
   864                                 const QString &dir, const QString &filter, QString *selectedFilter,
       
   865                                 QFileDialog::Options options, bool isSaveDialog,
       
   866                                 QMap<GtkFileFilter *, QString> *filterMap)
       
   867 {
       
   868     g_object_set(gtkFileChooser, "do-overwrite-confirmation", gboolean(!(options & QFileDialog::DontConfirmOverwrite)), NULL);
       
   869     g_object_set(gtkFileChooser, "local_only", gboolean(true), NULL);
       
   870     if (!filter.isEmpty()) {
       
   871         QStringList filters = qt_make_filter_list(filter);
       
   872         foreach (const QString &rawfilter, filters) {
       
   873             GtkFileFilter *gtkFilter = QGtkStylePrivate::gtk_file_filter_new ();
       
   874             QString name = rawfilter.left(rawfilter.indexOf(QLatin1Char('(')));
       
   875             QStringList extensions = extract_filter(rawfilter);
       
   876             QGtkStylePrivate::gtk_file_filter_set_name(gtkFilter, qPrintable(name.isEmpty() ? extensions.join(QLS(", ")) : name));
       
   877 
       
   878             foreach (const QString &fileExtension, extensions) {
       
   879                 // Note Gtk file dialogs are by default case sensitive
       
   880                 // and only supports basic glob syntax so we
       
   881                 // rewrite .xyz to .[xX][yY][zZ]
       
   882                 QString caseInsensitive;
       
   883                 for (int i = 0 ; i < fileExtension.length() ; ++i) {
       
   884                     QChar ch = fileExtension.at(i);
       
   885                     if (ch.isLetter()) {
       
   886                         caseInsensitive.append(
       
   887                                 QLatin1Char('[') +
       
   888                                 ch.toLower() +
       
   889                                 ch.toUpper() +
       
   890                                 QLatin1Char(']'));
       
   891                     } else {
       
   892                         caseInsensitive.append(ch);
       
   893                     }
       
   894                 }
       
   895                 QGtkStylePrivate::gtk_file_filter_add_pattern (gtkFilter, qPrintable(caseInsensitive));
       
   896 
       
   897             }
       
   898             if (filterMap)
       
   899                 filterMap->insert(gtkFilter, rawfilter);
       
   900             QGtkStylePrivate::gtk_file_chooser_add_filter((GtkFileChooser*)gtkFileChooser, gtkFilter);
       
   901             if (selectedFilter && (rawfilter == *selectedFilter))
       
   902                 QGtkStylePrivate::gtk_file_chooser_set_filter((GtkFileChooser*)gtkFileChooser, gtkFilter);
       
   903         }
       
   904     }
       
   905 
       
   906     // Using the currently active window is not entirely correct, however
       
   907     // it gives more sensible behavior for applications that do not provide a
       
   908     // parent
       
   909     QWidget *modalFor = parent ? parent->window() : qApp->activeWindow();
       
   910     if (modalFor) {
       
   911         QGtkStylePrivate::gtk_widget_realize(gtkFileChooser); // Creates X window
       
   912         XSetTransientForHint(QGtkStylePrivate::gdk_x11_drawable_get_xdisplay(gtkFileChooser->window),
       
   913                              QGtkStylePrivate::gdk_x11_drawable_get_xid(gtkFileChooser->window),
       
   914                              modalFor->winId());
       
   915         QGtkStylePrivate::gdk_x11_window_set_user_time (gtkFileChooser->window, QX11Info::appUserTime());
       
   916 
       
   917     }
       
   918 
       
   919     QFileInfo fileinfo(dir);
       
   920     if (dir.isEmpty())
       
   921         fileinfo.setFile(QDir::currentPath());
       
   922     fileinfo.makeAbsolute();
       
   923     if (fileinfo.isDir()) {
       
   924         QGtkStylePrivate::gtk_file_chooser_set_current_folder((GtkFileChooser*)gtkFileChooser, qPrintable(dir));
       
   925     } else if (isSaveDialog) {
       
   926         QGtkStylePrivate::gtk_file_chooser_set_current_folder((GtkFileChooser*)gtkFileChooser, qPrintable(fileinfo.absolutePath()));
       
   927         QGtkStylePrivate::gtk_file_chooser_set_current_name((GtkFileChooser*)gtkFileChooser, qPrintable(fileinfo.fileName()));
       
   928     } else {
       
   929         QGtkStylePrivate::gtk_file_chooser_set_filename((GtkFileChooser*)gtkFileChooser, qPrintable(dir));
       
   930     }
       
   931 }
       
   932 
       
   933 QString QGtkStylePrivate::openFilename(QWidget *parent, const QString &caption, const QString &dir, const QString &filter,
       
   934                             QString *selectedFilter, QFileDialog::Options options)
       
   935 {
       
   936     QMap<GtkFileFilter *, QString> filterMap;
       
   937     GtkWidget *gtkFileChooser = QGtkStylePrivate::gtk_file_chooser_dialog_new (qPrintable(caption),
       
   938                                                              NULL,
       
   939                                                              GTK_FILE_CHOOSER_ACTION_OPEN,
       
   940                                                              GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
       
   941                                                              GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
       
   942                                                              NULL);
       
   943 
       
   944     setupGtkFileChooser(gtkFileChooser, parent, dir, filter, selectedFilter, options, false, &filterMap);
       
   945 
       
   946     QWidget modal_widget;
       
   947     modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true);
       
   948     modal_widget.setParent(parent, Qt::Window);
       
   949     QApplicationPrivate::enterModal(&modal_widget);
       
   950 
       
   951     QString filename;
       
   952     if (QGtkStylePrivate::gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) {
       
   953         char *gtk_filename = QGtkStylePrivate::gtk_file_chooser_get_filename ((GtkFileChooser*)gtkFileChooser);
       
   954         filename = QString::fromUtf8(gtk_filename);
       
   955         g_free (gtk_filename);
       
   956         if (selectedFilter) {
       
   957             GtkFileFilter *gtkFilter = QGtkStylePrivate::gtk_file_chooser_get_filter ((GtkFileChooser*)gtkFileChooser);
       
   958             *selectedFilter = filterMap.value(gtkFilter);
       
   959         }
       
   960     }
       
   961 
       
   962     QApplicationPrivate::leaveModal(&modal_widget);
       
   963     gtk_widget_destroy (gtkFileChooser);
       
   964     return filename;
       
   965 }
       
   966 
       
   967 
       
   968 QString QGtkStylePrivate::openDirectory(QWidget *parent, const QString &caption, const QString &dir, QFileDialog::Options options)
       
   969 {
       
   970     QMap<GtkFileFilter *, QString> filterMap;
       
   971     GtkWidget *gtkFileChooser = QGtkStylePrivate::gtk_file_chooser_dialog_new (qPrintable(caption),
       
   972                                                              NULL,
       
   973                                                              GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
       
   974                                                              GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
       
   975                                                              GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
       
   976                                                              NULL);
       
   977 
       
   978     setupGtkFileChooser(gtkFileChooser, parent, dir, QString(), 0, options);
       
   979     QWidget modal_widget;
       
   980     modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true);
       
   981     modal_widget.setParent(parent, Qt::Window);
       
   982     QApplicationPrivate::enterModal(&modal_widget);
       
   983 
       
   984     QString filename;
       
   985     if (QGtkStylePrivate::gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) {
       
   986         char *gtk_filename = QGtkStylePrivate::gtk_file_chooser_get_filename ((GtkFileChooser*)gtkFileChooser);
       
   987         filename = QString::fromUtf8(gtk_filename);
       
   988         g_free (gtk_filename);
       
   989     }
       
   990 
       
   991     QApplicationPrivate::leaveModal(&modal_widget);
       
   992     gtk_widget_destroy (gtkFileChooser);
       
   993     return filename;
       
   994 }
       
   995 
       
   996 QStringList QGtkStylePrivate::openFilenames(QWidget *parent, const QString &caption, const QString &dir, const QString &filter,
       
   997                                  QString *selectedFilter, QFileDialog::Options options)
       
   998 {
       
   999     QStringList filenames;
       
  1000     QMap<GtkFileFilter *, QString> filterMap;
       
  1001     GtkWidget *gtkFileChooser = QGtkStylePrivate::gtk_file_chooser_dialog_new (qPrintable(caption),
       
  1002                                                              NULL,
       
  1003                                                              GTK_FILE_CHOOSER_ACTION_OPEN,
       
  1004                                                              GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
       
  1005                                                              GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
       
  1006                                                              NULL);
       
  1007 
       
  1008     setupGtkFileChooser(gtkFileChooser, parent, dir, filter, selectedFilter, options, false, &filterMap);
       
  1009     g_object_set(gtkFileChooser, "select-multiple", gboolean(true), NULL);
       
  1010 
       
  1011     QWidget modal_widget;
       
  1012     modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true);
       
  1013     modal_widget.setParent(parent, Qt::Window);
       
  1014     QApplicationPrivate::enterModal(&modal_widget);
       
  1015 
       
  1016     if (gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) {
       
  1017         GSList *gtk_file_names = QGtkStylePrivate::gtk_file_chooser_get_filenames((GtkFileChooser*)gtkFileChooser);
       
  1018         for (GSList *iterator  = gtk_file_names ; iterator; iterator = iterator->next)
       
  1019             filenames << QString::fromUtf8((const char*)iterator->data);
       
  1020         g_slist_free(gtk_file_names);
       
  1021         if (selectedFilter) {
       
  1022             GtkFileFilter *gtkFilter = QGtkStylePrivate::gtk_file_chooser_get_filter ((GtkFileChooser*)gtkFileChooser);
       
  1023             *selectedFilter = filterMap.value(gtkFilter);
       
  1024         }
       
  1025     }
       
  1026 
       
  1027     QApplicationPrivate::leaveModal(&modal_widget);
       
  1028     gtk_widget_destroy (gtkFileChooser);
       
  1029     return filenames;
       
  1030 }
       
  1031 
       
  1032 QString QGtkStylePrivate::saveFilename(QWidget *parent, const QString &caption, const QString &dir, const QString &filter,
       
  1033                            QString *selectedFilter, QFileDialog::Options options)
       
  1034 {
       
  1035     QMap<GtkFileFilter *, QString> filterMap;
       
  1036     GtkWidget *gtkFileChooser = QGtkStylePrivate::gtk_file_chooser_dialog_new (qPrintable(caption),
       
  1037                                                              NULL,
       
  1038                                                              GTK_FILE_CHOOSER_ACTION_SAVE,
       
  1039                                                              GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
       
  1040                                                              GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
       
  1041                                                              NULL);
       
  1042     setupGtkFileChooser(gtkFileChooser, parent, dir, filter, selectedFilter, options, true, &filterMap);
       
  1043 
       
  1044     QWidget modal_widget;
       
  1045     modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true);
       
  1046     modal_widget.setParent(parent, Qt::Window);
       
  1047     QApplicationPrivate::enterModal(&modal_widget);
       
  1048 
       
  1049     QString filename;
       
  1050     if (QGtkStylePrivate::gtk_dialog_run ((GtkDialog*)gtkFileChooser) == GTK_RESPONSE_ACCEPT) {
       
  1051         char *gtk_filename = QGtkStylePrivate::gtk_file_chooser_get_filename ((GtkFileChooser*)gtkFileChooser);
       
  1052         filename = QString::fromUtf8(gtk_filename);
       
  1053         g_free (gtk_filename);
       
  1054         if (selectedFilter) {
       
  1055             GtkFileFilter *gtkFilter = QGtkStylePrivate::gtk_file_chooser_get_filter ((GtkFileChooser*)gtkFileChooser);
       
  1056             *selectedFilter = filterMap.value(gtkFilter);
       
  1057         }
       
  1058     }
       
  1059 
       
  1060     QApplicationPrivate::leaveModal(&modal_widget);
       
  1061     gtk_widget_destroy (gtkFileChooser);
       
  1062     return filename;
       
  1063 }
       
  1064 
       
  1065 QIcon QGtkStylePrivate::getFilesystemIcon(const QFileInfo &info)
       
  1066 {
       
  1067     QIcon icon;
       
  1068     if (gnome_vfs_init && gnome_icon_lookup_sync) {
       
  1069         gnome_vfs_init();
       
  1070         GtkIconTheme *theme = gtk_icon_theme_get_default();
       
  1071         QByteArray fileurl = QUrl::fromLocalFile(info.absoluteFilePath()).toEncoded();
       
  1072         char * icon_name = gnome_icon_lookup_sync(theme,
       
  1073                                                   NULL,
       
  1074                                                   fileurl.data(),
       
  1075                                                   NULL,
       
  1076                                                   GNOME_ICON_LOOKUP_FLAGS_NONE,
       
  1077                                                   NULL);
       
  1078         QString iconName = QString::fromUtf8(icon_name);
       
  1079         g_free(icon_name);
       
  1080         if (iconName.startsWith(QLatin1Char('/')))
       
  1081             return QIcon(iconName);
       
  1082         return QIcon::fromTheme(iconName);
       
  1083     }
       
  1084     return icon;
       
  1085 }
       
  1086 
       
  1087 QT_END_NAMESPACE
       
  1088 
       
  1089 #endif // !defined(QT_NO_STYLE_GTK)