2
* This program is free software; you can redistribute it and/or modify
3
* it under the terms of the GNU General Public License as published by
4
* the Free Software Foundation; either version 2 of the License, or
5
* (at your option) any later version.
7
* This program is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
* GNU Library General Public License for more details.
12
* You should have received a copy of the GNU General Public License
13
* along with this program; if not, write to the Free Software
14
* Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA
19
#include "awn-icons.h"
24
#include <glib/gstdio.h>
27
G_DEFINE_TYPE (AwnIcons, awn_icons, G_TYPE_OBJECT)
29
#define AWN_ICONS_THEME_NAME "awn-theme"
31
#define GET_PRIVATE(o) \
32
(G_TYPE_INSTANCE_GET_PRIVATE ((o), LIBAWN_TYPE_AWN_ICONS, AwnIconsPrivate))
34
typedef struct _AwnIconsPrivate AwnIconsPrivate;
36
struct _AwnIconsPrivate {
37
GtkWidget * icon_widget; //used if Non-NULL for drag and drop support
39
GtkIconTheme * awn_theme;
51
void awn_icons_set_icons_info(AwnIcons * icons,GtkWidget * applet,
52
gchar * applet_name,gchar * uid,gint height,
53
gchar **states,gchar **icon_names)
55
g_return_if_fail(icons);
56
g_return_if_fail(applet_name);
57
g_return_if_fail(uid);
58
g_return_if_fail(states);
59
g_return_if_fail(icon_names);
62
AwnIconsPrivate *priv=GET_PRIVATE(icons);
66
priv->icon_widget = GTK_WIDGET(applet);
68
for (count=0;states[count];count++);
71
for (count=0;icon_names[count];count++);
72
g_return_if_fail(count == priv->count);
76
for(count=0;icon_names[count];count++)
78
g_free(icon_names[count]);
79
g_free(states[count]);
82
g_free(priv->icon_names);
85
priv->states = g_malloc( sizeof(gchar *) * count);
86
priv->icon_names = g_malloc( sizeof(gchar *) * count);
88
for (count=0; count < priv->count; count ++)
90
priv->states[count] = g_strdup(states[count]);
91
priv->icon_names[count] = g_strdup(icon_names[count]);
93
priv->states[count] = NULL;
94
priv->icon_names[count] = NULL;
96
if (priv->applet_name)
98
g_free(priv->applet_name);
100
priv->applet_name = g_strdup(applet_name);
106
priv->uid = g_strdup(uid);
107
priv->height = height;
109
gtk_icon_theme_rescan_if_needed(priv->awn_theme);
112
void awn_icons_set_icon_info(AwnIcons * icons,
119
g_return_if_fail(icons);
120
gchar *states[] = {"__SINGULAR__",NULL};
121
gchar *icon_names[] = {NULL,NULL};
122
icon_names[0] = icon_name;
123
awn_icons_set_icons_info(icons,applet,applet_name,
124
uid,height,states,icon_names);
128
GdkPixbuf * awn_icons_get_icon(AwnIcons * icons, gchar * state)
130
g_return_val_if_fail(icons,NULL);
131
g_return_val_if_fail(state,NULL);
134
GdkPixbuf * pixbuf = NULL;
135
AwnIconsPrivate *priv=GET_PRIVATE(icons);
137
for (count = 0; priv->states[count]; count++)
139
if ( strcmp(state,priv->states[count]) == 0 )
150
name = g_strdup_printf("%s-%s-%s",
151
priv->icon_names[count],
154
pixbuf = gtk_icon_theme_load_icon(priv->awn_theme, name ,
155
priv->height, 0, NULL);
158
name = g_strdup_printf("%s-%s",
159
priv->icon_names[count],
161
pixbuf = gtk_icon_theme_load_icon(priv->awn_theme, name ,
162
priv->height, 0, NULL);
165
pixbuf = gtk_icon_theme_load_icon(priv->awn_theme,
166
priv->icon_names[count],priv->height,
170
pixbuf = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(),
171
priv->icon_names[count],priv->height,
175
pixbuf = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(),
176
"stock_stop",priv->height, 0, NULL);
179
pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8,
180
priv->height,priv->height);
181
gdk_pixbuf_fill(pixbuf, 0xee221155);
188
if (gdk_pixbuf_get_height(pixbuf) != priv->height)
190
GdkPixbuf * new_pixbuf = gdk_pixbuf_scale_simple(pixbuf,
191
gdk_pixbuf_get_width(pixbuf)*
192
priv->height/gdk_pixbuf_get_height(pixbuf),
196
g_object_unref(pixbuf);
209
GdkPixbuf * awn_icons_get_icon_simple(AwnIcons * icons)
211
g_return_val_if_fail(icons,NULL);
213
return awn_icons_get_icon(icons,"__SINGULAR__");
217
awn_icons_get_property (GObject *object, guint property_id,
218
GValue *value, GParamSpec *pspec)
220
switch (property_id) {
222
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
227
awn_icons_set_property (GObject *object, guint property_id,
228
const GValue *value, GParamSpec *pspec)
230
switch (property_id) {
232
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
237
awn_icons_dispose (GObject *object)
239
if (G_OBJECT_CLASS (awn_icons_parent_class)->dispose)
240
G_OBJECT_CLASS (awn_icons_parent_class)->dispose (object);
244
awn_icons_finalize (GObject *object)
246
if (G_OBJECT_CLASS (awn_icons_parent_class)->finalize)
247
G_OBJECT_CLASS (awn_icons_parent_class)->finalize (object);
251
awn_icons_class_init (AwnIconsClass *klass)
253
GObjectClass *object_class = G_OBJECT_CLASS (klass);
255
g_type_class_add_private (klass, sizeof (AwnIconsPrivate));
257
object_class->get_property = awn_icons_get_property;
258
object_class->set_property = awn_icons_set_property;
259
object_class->dispose = awn_icons_dispose;
260
object_class->finalize = awn_icons_finalize;
264
awn_icons_init (AwnIcons *self)
266
AwnIconsPrivate *priv=GET_PRIVATE(self);
267
priv->icon_widget = NULL;
269
priv->icon_names = NULL;
275
//do we have our dirs....
276
const gchar * home = g_getenv("HOME");
278
gchar * icon_dir = g_strdup_printf("%s/.icons",home);
279
if ( !g_file_test(icon_dir,G_FILE_TEST_IS_DIR) )
281
g_mkdir(icon_dir,0775);
284
gchar * awn_theme_dir = g_strdup_printf("%s/%s",icon_dir,AWN_ICONS_THEME_NAME);
286
if ( !g_file_test(awn_theme_dir,G_FILE_TEST_IS_DIR) )
288
g_mkdir(awn_theme_dir,0775);
291
gchar * awn_scalable_dir = g_strdup_printf("%s/scalable",awn_theme_dir);
292
g_free(awn_theme_dir);
293
if ( !g_file_test(awn_scalable_dir,G_FILE_TEST_IS_DIR) )
295
g_mkdir(awn_scalable_dir,0775);
298
g_free(awn_scalable_dir);
301
priv->awn_theme = gtk_icon_theme_new();
302
gtk_icon_theme_set_custom_theme(priv->awn_theme,AWN_ICONS_THEME_NAME);
308
return g_object_new (LIBAWN_TYPE_AWN_ICONS, NULL);