[473884]: src / icon_source_gicon.c Maximize Restore History

Download this file

icon_source_gicon.c    155 lines (127 with data), 4.5 kB

  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
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
rox-media (Media) - DeviceKit-disks utility for ROX
Copyright (C) 2009 Tony Houghton <h@realh.co.uk>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <gdk-pixbuf/gdk-pixbuf.h>
#include "i18n.h"
#include "icon_source.h"
#include "icon_source_gicon.h"
#include "icon_source_gicon_priv.h"
#define H_ICON_SOURCE_GICON_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), \
H_TYPE_ICON_SOURCE_GICON, HIconSourceGIconPrivate))
static GdkPixbuf *
get_pixbuf(HIconSource *iself, int width, int height)
{
HIconSourceGIcon *self = H_ICON_SOURCE_GICON(iself);
HIconSourceGIconPrivate *priv = self->priv;
GError *error = NULL;
GdkPixbuf *pixbuf;
GtkIconInfo *iinfo;
g_return_val_if_fail(self->gicon && priv->theme, NULL);
height = MAX(width, height);
iinfo = gtk_icon_theme_lookup_by_gicon(priv->theme, self->gicon, height,
GTK_ICON_LOOKUP_FORCE_SIZE);
if (iinfo)
pixbuf = gtk_icon_info_load_icon(iinfo, &error);
if (!pixbuf)
{
char *gi_name = g_icon_to_string(self->gicon);
g_warning(_("Unable to generate pixbuf from gicon '%s': %s"),
gi_name, error->message);
g_free(gi_name);
g_error_free(error);
}
gtk_icon_info_free(iinfo);
return pixbuf;
}
static void
h_icon_source_gicon_init_h_icon_source(HIconSourceInterface *iface)
{
iface->get_pixbuf = get_pixbuf;
}
G_DEFINE_TYPE_WITH_CODE(HIconSourceGIcon, h_icon_source_gicon,
G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE(H_TYPE_ICON_SOURCE,
h_icon_source_gicon_init_h_icon_source));
static void
h_icon_source_gicon_init(HIconSourceGIcon *self)
{
self->priv = H_ICON_SOURCE_GICON_GET_PRIVATE(self);
self->gicon = NULL;;
self->priv->theme = NULL;
}
static void
h_icon_source_gicon_dispose(GObject *gobj)
{
HIconSourceGIcon *self = H_ICON_SOURCE_GICON(gobj);
HIconSourceGIconPrivate *priv = self->priv;
if (priv->theme)
{
g_object_unref(priv->theme);
priv->theme = NULL;
}
if (self->gicon)
{
g_object_unref(self->gicon);
self->gicon = NULL;
}
G_OBJECT_CLASS(h_icon_source_gicon_parent_class)->dispose(gobj);
}
static void
h_icon_source_gicon_finalize(GObject *gobj)
{
G_OBJECT_CLASS(h_icon_source_gicon_parent_class)->finalize(gobj);
}
static void
h_icon_source_gicon_class_init(HIconSourceGIconClass *klass)
{
GObjectClass *gclass;
g_type_class_add_private(klass, sizeof(HIconSourceGIconPrivate));
gclass = G_OBJECT_CLASS(klass);
gclass->dispose = h_icon_source_gicon_dispose;
gclass->finalize = h_icon_source_gicon_finalize;
}
HIconSourceGIcon *
h_icon_source_gicon_new(GdkScreen *screen, GIcon *gicon)
{
HIconSourceGIcon *self = H_ICON_SOURCE_GICON(
g_object_new(H_TYPE_ICON_SOURCE_GICON, NULL));
if (screen)
h_icon_source_gicon_set_screen(self, screen);
if (gicon)
h_icon_source_gicon_set_gicon(self, gicon);
return self;
}
void
h_icon_source_gicon_set_screen(HIconSourceGIcon *self, GdkScreen *screen)
{
HIconSourceGIconPrivate *priv = self->priv;
g_return_if_fail(H_IS_ICON_SOURCE_GICON(self));
if (priv->theme)
gtk_icon_theme_set_screen(priv->theme, screen);
else
priv->theme = gtk_icon_theme_get_for_screen(screen);
g_signal_emit(self, h_icon_source_signals[H_ICON_SOURCE_SIGNAL_CHANGED], 0);
}
void
h_icon_source_gicon_set_gicon(HIconSourceGIcon *self, GIcon *gicon)
{
g_return_if_fail(H_IS_ICON_SOURCE_GICON(self));
if (self->gicon)
g_object_unref(self->gicon);
self->gicon = gicon;
g_object_ref(gicon);
g_signal_emit(self, h_icon_source_signals[H_ICON_SOURCE_SIGNAL_CHANGED], 0);
}