~ubuntu-branches/ubuntu/vivid/liferea/vivid-proposed

« back to all changes in this revision

Viewing changes to src/ui/icons.c

  • Committer: Package Import Robot
  • Author(s): bojo42
  • Date: 2012-03-29 14:17:21 UTC
  • mfrom: (1.3.9) (3.2.5 sid)
  • Revision ID: package-import@ubuntu.com-20120329141721-tbfopcrc5797wxt7
Tags: 1.8.3-0.1ubuntu1
* New upstream release (LP: #290666, #371754, #741543, #716688)
* Merge from Debian unstable (LP: #935147), remaining changes:
* debian/patches:
  - drop gtk-status-icon.patch & notification-append as in upstream
  - drop fix_systray_behavior as mostly upstreamed and rest seems unused
  - 01_ubuntu_feedlists: update & rename, move planets to "Open Source"  
  - add_X-Ubuntu-Gettext-Domain: rebase
  - libunity.patch: rebase, apply before indicator patch (liferea_shell.c)
  - libindicate_increase_version.patch: exclude from libindicate.patch
  - deactivate libindicate.patch, seems partly upstreamed and needs rework
* debian/control: libindicate-dev, libindicate-gtk-dev & libunity-dev
* debian/liferea.indicate & liferea.install: ship indicator desktop file
* debian/rules: enable libindicate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * @file icons.c  Using icons from theme and package pixmaps
 
3
 *
 
4
 * Copyright (C) 2010 Lars Lindner <lars.lindner@gmail.com>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 */
 
20
 
 
21
#include "icons.h"
 
22
 
 
23
#ifdef HAVE_CONFIG_H
 
24
#  include <config.h>
 
25
#endif
 
26
 
 
27
#include "common.h"
 
28
 
 
29
static GdkPixbuf *icons[MAX_ICONS];     /**< list of icon assignments */
 
30
 
 
31
static gchar *
 
32
icon_find_pixmap_file (const gchar *filename)
 
33
{
 
34
        gchar *pathname = g_build_filename (PACKAGE_DATA_DIR G_DIR_SEPARATOR_S PACKAGE G_DIR_SEPARATOR_S "pixmaps", filename, NULL);
 
35
        if (g_file_test (pathname, G_FILE_TEST_EXISTS))
 
36
                return pathname;
 
37
        g_free (pathname);
 
38
        return NULL;
 
39
}
 
40
 
 
41
GdkPixbuf *
 
42
icon_create_from_file (const gchar *filename)
 
43
{
 
44
        gchar *pathname = NULL;
 
45
        GdkPixbuf *pixbuf;
 
46
        GError *error = NULL;
 
47
 
 
48
        if (!filename || !filename[0])
 
49
                return NULL;
 
50
 
 
51
        pathname = icon_find_pixmap_file (filename);
 
52
 
 
53
        if (!pathname) {
 
54
                g_warning (_("Couldn't find pixmap file: %s"), filename);
 
55
                return NULL;
 
56
        }
 
57
 
 
58
        pixbuf = gdk_pixbuf_new_from_file (pathname, &error);
 
59
        if (!pixbuf) {
 
60
                fprintf (stderr, "Failed to load pixbuf file: %s: %s\n",
 
61
                       pathname, error->message);
 
62
                g_error_free (error);
 
63
        }
 
64
        g_free (pathname);
 
65
        return pixbuf;
 
66
}
 
67
 
 
68
static GdkPixbuf *
 
69
icon_get_from_theme (GtkIconTheme *icon_theme, const gchar *name, gint size)
 
70
{
 
71
        GError *error = NULL;
 
72
        GdkPixbuf *pixbuf;
 
73
 
 
74
        pixbuf = gtk_icon_theme_load_icon (icon_theme,
 
75
                                           name, /* icon name */
 
76
                                           size, /* size */
 
77
                                           0,  /* flags */
 
78
                                           &error);
 
79
        if (!pixbuf) {
 
80
                g_warning ("Couldn't load icon: %s", error->message);
 
81
                g_error_free (error);
 
82
        }
 
83
        return pixbuf;
 
84
}
 
85
 
 
86
void
 
87
icons_load (void)
 
88
{
 
89
        GtkIconTheme    *icon_theme;
 
90
        GtkWidget       *widget;
 
91
        gint            i;
 
92
        
 
93
        /* first try to load icons from theme */
 
94
        static const gchar *iconThemeNames[] = {
 
95
                NULL,                   /* ICON_UNREAD */
 
96
                "emblem-important",     /* ICON_FLAG */
 
97
                NULL,                   /* ICON_AVAILABLE */
 
98
                NULL,                   /* ICON_AVAILABLE_OFFLINE */
 
99
                NULL,                   /* ICON_UNAVAILABLE */
 
100
                NULL,                   /* ICON_DEFAULT */
 
101
                "folder",               /* ICON_FOLDER */
 
102
                "folder-saved-search",  /* ICON_VFOLDER */
 
103
                NULL,                   /* ICON_NEWSBIN */
 
104
                NULL,                   /* ICON_EMPTY */
 
105
                NULL,                   /* ICON_EMPTY_OFFLINE */
 
106
                "gtk-connect",          /* ICON_ONLINE */
 
107
                "gtk-disconnect",       /* ICON_OFFLINE */
 
108
                "mail-attachment",      /* ICON_ENCLOSURE */
 
109
                NULL
 
110
        };
 
111
 
 
112
        icon_theme = gtk_icon_theme_get_default ();
 
113
        for (i = 0; i < MAX_ICONS; i++)
 
114
                if (iconThemeNames[i])
 
115
                        icons[i] = icon_get_from_theme (icon_theme, iconThemeNames[i], 16);
 
116
 
 
117
        /* and then load own default icons */
 
118
        static const gchar *iconNames[] = {
 
119
                "unread.png",           /* ICON_UNREAD */
 
120
                "flag.png",             /* ICON_FLAG */
 
121
                "available.png",        /* ICON_AVAILABLE */
 
122
                "available_offline.png",        /* ICON_AVAILABLE_OFFLINE */
 
123
                NULL,                   /* ICON_UNAVAILABLE */
 
124
                "default.png",          /* ICON_DEFAULT */
 
125
                "directory.png",        /* ICON_FOLDER */
 
126
                "vfolder.png",          /* ICON_VFOLDER */
 
127
                "newsbin.png",          /* ICON_NEWSBIN */
 
128
                "empty.png",            /* ICON_EMPTY */
 
129
                "empty_offline.png",    /* ICON_EMPTY_OFFLINE */
 
130
                "online.png",           /* ICON_ONLINE */
 
131
                "offline.png",          /* ICON_OFFLINE */
 
132
                "attachment.png",       /* ICON_ENCLOSURE */
 
133
                NULL
 
134
        };
 
135
 
 
136
        for (i = 0; i < MAX_ICONS; i++)
 
137
                if (!icons[i])
 
138
                        icons[i] = icon_create_from_file (iconNames[i]);
 
139
 
 
140
        /* set up icons that are build from stock */
 
141
        widget = gtk_button_new ();
 
142
        icons[ICON_UNAVAILABLE] = gtk_widget_render_icon (widget, GTK_STOCK_DIALOG_ERROR, GTK_ICON_SIZE_MENU, "");
 
143
        gtk_widget_destroy (widget);
 
144
}
 
145
 
 
146
const GdkPixbuf *
 
147
icon_get (lifereaIcon icon)
 
148
{
 
149
        return icons[icon];
 
150
}
 
151
 
 
152