File: platform_gnome_util.cpp

package info (click to toggle)
launchy 2.5-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 4,532 kB
  • sloc: cpp: 11,735; sh: 162; makefile: 45
file content (53 lines) | stat: -rw-r--r-- 1,699 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

#include <libgnomeui/libgnomeui.h>
#include "platform_gnome_util.h"
#include <gtk/gtk.h>


#include <QPixmap>
#include <QIcon>
#include <QDebug>
#include <QPainter>

#include <QX11Info>

QIcon GnomeIconProvider::icon(const QFileInfo& info) const
{
    if (info.fileName().endsWith(".png", Qt::CaseInsensitive))
        {
            return QIcon(info.absoluteFilePath());
        }
    if (info.fileName().endsWith(".ico", Qt::CaseInsensitive))
	return QIcon(info.absoluteFilePath());

    gdk_threads_enter();
    GnomeIconLookupResultFlags resultFlags;
    char* file = gnome_icon_lookup_sync(gtk_icon_theme_get_default(),
                                        NULL,
                                        info.absoluteFilePath().toLocal8Bit().data(),
                                        NULL,
                                        GNOME_ICON_LOOKUP_FLAGS_NONE,
                                        &resultFlags);
    GtkIconInfo* icinfo = gtk_icon_theme_lookup_icon(gtk_icon_theme_get_default(),
                                                     file,
                                                     32,
                                                     GTK_ICON_LOOKUP_NO_SVG);
    
    GdkPixbuf* buff = gtk_icon_info_load_icon(icinfo, NULL);
    gchar* pixmap;
    gsize buflen;
    
    gdk_pixbuf_save_to_buffer (buff,
                               &pixmap,
                               &buflen,
                               "png",
                               NULL, NULL);
    QPixmap qp;
    qp.loadFromData((const uchar*) pixmap, buflen, "png");
    QIcon qico(qp);
    free(pixmap);
    g_object_unref(buff);
    gdk_threads_leave();
    
    return qp;
}