]> www.fi.muni.cz Git - evince.git/blob - libview/ev-stock-icons.c
Move stock icons from libmisc to libview and make the API public
[evince.git] / libview / ev-stock-icons.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* Stock icons for Evince
3  *
4  * Copyright (C) 2003 Martin Kretzschmar
5  *
6  * Author:
7  *   Martin Kretzschmar <Martin.Kretzschmar@inf.tu-dresden.de>
8  *
9  * Evince is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Evince is distributed in the hope that it will be useful, but WITHOUT
15  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  */
23
24 #include <config.h>
25
26 #include <gtk/gtk.h>
27
28 #include "ev-stock-icons.h"
29
30 typedef struct {
31         char *stock_id;
32         char *icon;
33 } EvStockIcon;
34
35 /* Evince stock icons */
36 static const EvStockIcon stock_icons [] = {
37         { EV_STOCK_ZOOM,             "zoom" },
38         { EV_STOCK_ZOOM_PAGE,        "zoom-fit-page" },
39         { EV_STOCK_ZOOM_WIDTH,       "zoom-fit-width" },
40         { EV_STOCK_VIEW_DUAL,        "view-page-facing" },
41         { EV_STOCK_VIEW_CONTINUOUS,  "view-page-continuous" },
42         { EV_STOCK_ROTATE_LEFT,      "object-rotate-left"},
43         { EV_STOCK_ROTATE_RIGHT,     "object-rotate-right"},
44         { EV_STOCK_RUN_PRESENTATION, "x-office-presentation"},
45         { EV_STOCK_VISIBLE,          "eye"}
46 };
47
48 static gchar *ev_icons_path;
49
50 static void
51 ev_stock_icons_add_icons_path_for_screen (GdkScreen *screen)
52 {
53         GtkIconTheme *icon_theme;
54
55         g_return_if_fail (ev_icons_path != NULL);
56
57         icon_theme = screen ? gtk_icon_theme_get_for_screen (screen) : gtk_icon_theme_get_default ();
58         if (icon_theme) {
59                 gchar **path = NULL;
60                 gint    n_paths;
61                 gint    i;
62
63                 /* GtkIconTheme will then look in Evince custom hicolor dir
64                  * for icons as well as the standard search paths
65                  */
66                 gtk_icon_theme_get_search_path (icon_theme, &path, &n_paths);
67                 for (i = n_paths - 1; i >= 0; i--) {
68                         if (g_ascii_strcasecmp (ev_icons_path, path[i]) == 0)
69                                 break;
70                 }
71
72                 if (i < 0)
73                         gtk_icon_theme_append_search_path (icon_theme,
74                                                            ev_icons_path);
75
76                 g_strfreev (path);
77         }
78 }
79
80 /**
81  * ev_stock_icons_init:
82  *
83  * Creates a new icon factory, adding the base stock icons to it.
84  */
85 void
86 ev_stock_icons_init (void)
87 {
88         GtkIconFactory *factory;
89         GtkIconSource *source;
90         gint i;
91
92         ev_icons_path = g_build_filename (DATADIR, "icons", NULL);
93
94         factory = gtk_icon_factory_new ();
95         gtk_icon_factory_add_default (factory);
96
97         source = gtk_icon_source_new ();
98
99         for (i = 0; i < G_N_ELEMENTS (stock_icons); i++) {
100                 GtkIconSet *set;
101
102                 gtk_icon_source_set_icon_name (source, stock_icons [i].icon);
103
104                 set = gtk_icon_set_new ();
105                 gtk_icon_set_add_source (set, source);
106
107                 gtk_icon_factory_add (factory, stock_icons [i].stock_id, set);
108                 gtk_icon_set_unref (set);
109         }
110
111         gtk_icon_source_free (source);
112
113         g_object_unref (G_OBJECT (factory));
114
115         ev_stock_icons_add_icons_path_for_screen (gdk_screen_get_default ());
116 }
117
118 void
119 ev_stock_icons_set_screen (GdkScreen *screen)
120 {
121         g_return_if_fail (GDK_IS_SCREEN (screen));
122
123         ev_stock_icons_add_icons_path_for_screen (screen);
124 }
125
126 void
127 ev_stock_icons_shutdown (void)
128 {
129         g_free (ev_icons_path);
130 }
131
132 void
133 ev_stock_icons_add_icons_path (void)
134 {
135         ev_stock_icons_add_icons_path_for_screen (gdk_screen_get_default ());
136 }