Retreives images/data from URI using Gnome Virtual File System.
[gpiv.git] / src / support.c
blob64ddbf19dbdf5905a641cfb0c0373586eced8a5f
1 /*----------------------------------------------------------------------
3 gpiv - Graphic program for Particle Image Velocimetry, based on gtk/gnome
4 libraries.
6 Copyright (C) 2002 Gerber van der Graaf
8 This file is part of gpiv.
10 Gpiv is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software Foundation,
22 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 ----------------------------------------------------------------------*/
27 * $Log: support.c,v $
28 * Revision 1.3 2007-06-06 17:00:48 gerber
29 * Retreives images/data from URI using Gnome Virtual File System.
31 * Revision 1.2 2006/01/31 14:28:13 gerber
32 * version 0.3.0
34 * Revision 1.1.1.1 2003/06/17 17:10:52 gerber
35 * Imported gpiv
39 #ifdef HAVE_CONFIG_H
40 # include <config.h>
41 #endif
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <unistd.h>
46 #include <string.h>
47 #include <stdio.h>
49 #include <gnome.h>
51 #include "support.h"
52 #include "gpiv_gui.h"
54 GtkWidget*
55 lookup_widget (GtkWidget *widget,
56 const gchar *widget_name)
58 GtkWidget *parent, *found_widget;
60 for (;;)
62 if (GTK_IS_MENU (widget))
63 parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
64 else
65 parent = widget->parent;
66 if (!parent)
67 parent = (GtkWidget*) g_object_get_data (G_OBJECT (widget), "GladeParentKey");
68 if (parent == NULL)
69 break;
70 widget = parent;
73 found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget),
74 widget_name);
75 if (!found_widget)
76 g_warning ("Widget not found: %s", widget_name);
77 return found_widget;
80 /* This is an internally used function to create pixmaps. */
81 GtkWidget*
82 create_pixmap (GtkWidget *widget,
83 const gchar *filename)
85 GtkWidget *pixmap;
86 gchar *pathname;
88 if (!filename || !filename[0])
89 return gtk_image_new ();
91 pathname = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_PIXMAP,
92 filename, TRUE, NULL);
93 if (!pathname)
95 g_warning (_("Couldn't find pixmap file: %s"), filename);
96 return gtk_image_new ();
99 pixmap = gtk_image_new_from_file (pathname);
100 g_free (pathname);
101 return pixmap;
104 /* This is an internally used function to create pixmaps. */
105 GdkPixbuf*
106 create_pixbuf (const gchar *filename)
108 gchar *pathname = NULL;
109 GdkPixbuf *pixbuf;
110 GError *error = NULL;
112 if (!filename || !filename[0])
113 return NULL;
115 pathname = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_PIXMAP,
116 filename, TRUE, NULL);
118 if (!pathname)
120 g_warning (_("Couldn't find pixmap file: %s"), filename);
121 return NULL;
124 pixbuf = gdk_pixbuf_new_from_file (pathname, &error);
125 if (!pixbuf)
127 fprintf (stderr, "Failed to load pixbuf file: %s: %s\n",
128 pathname, error->message);
129 g_error_free (error);
131 g_free (pathname);
132 return pixbuf;
135 /* This is used to set ATK action descriptions. */
136 void
137 glade_set_atk_action_description (AtkAction *action,
138 const gchar *action_name,
139 const gchar *description)
141 gint n_actions, i;
143 n_actions = atk_action_get_n_actions (action);
144 for (i = 0; i < n_actions; i++)
146 if (!strcmp (atk_action_get_name (action, i), action_name))
147 atk_action_set_description (action, i, description);