~ubuntu-branches/ubuntu/karmic/klavaro/karmic

« back to all changes in this revision

Viewing changes to src/support.c

  • Committer: Package Import Robot
  • Author(s): Bart Martens
  • Date: 2009-05-21 11:22:34 UTC
  • mfrom: (1.1.13) (2.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20090521112234-xqwlky67xm6pgifj
Tags: 1.2.0-1
* New upstream release.
* debian/control: Build-Depends: libgtk2.0-dev (>= 2.12.11),
  libgtkdatabox-dev, libsexy-dev.
* debian/copyright: Updated.
* debian/install, debian/klavaro.desktop: Different .desktop file.
* debian/install, debian/menu, debian/rules: Different icon.
* debian/patches/04_initial_keyboard.diff: Removed.
* debian/patches/05_array_size.diff: Removed.
* debian/patches/06_initial_locale.diff: Removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/**************************************************************************/
2
 
/*  Klavaro - a flexible touch typing tutor                               */
3
 
/*  Copyright (C) 2005 - 2008  Felipe Castro                              */
4
 
/*                                                                        */
5
 
/*  This program is free software, licensed under the terms of the GNU    */
6
 
/*  General Public License as published by the Free Software Foundation,  */
7
 
/*  which is also included in this package, in a file named "COPYING".    */
8
 
/**************************************************************************/
9
 
 
10
 
/*
11
 
 * DO NOT EDIT THIS FILE - it is generated by Glade.
12
 
 */
13
 
 
14
 
#ifdef HAVE_CONFIG_H
15
 
#  include <config.h>
16
 
#endif
17
 
 
18
 
#include <sys/types.h>
19
 
#include <sys/stat.h>
20
 
#include <unistd.h>
21
 
#include <string.h>
22
 
#include <stdio.h>
23
 
 
24
 
#include <gtk/gtk.h>
25
 
 
26
 
#include "support.h"
27
 
 
28
 
GtkWidget *
29
 
lookup_widget (GtkWidget * widget, const gchar * widget_name)
30
 
{
31
 
        GtkWidget *parent, *found_widget;
32
 
 
33
 
        for (;;)
34
 
        {
35
 
                if (GTK_IS_MENU (widget))
36
 
                        parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
37
 
                else
38
 
                        parent = widget->parent;
39
 
                if (!parent)
40
 
                        parent = (GtkWidget *) g_object_get_data (G_OBJECT (widget),
41
 
                                                                  "GladeParentKey");
42
 
                if (parent == NULL)
43
 
                        break;
44
 
                widget = parent;
45
 
        }
46
 
 
47
 
        found_widget = (GtkWidget *) g_object_get_data (G_OBJECT (widget), widget_name);
48
 
        if (!found_widget)
49
 
                g_warning ("Widget not found: %s", widget_name);
50
 
        return found_widget;
51
 
}
52
 
 
53
 
static GList *pixmaps_directories = NULL;
54
 
 
55
 
/* Use this function to set the directory containing installed pixmaps. */
56
 
void
57
 
add_pixmap_directory (const gchar * directory)
58
 
{
59
 
        pixmaps_directories = g_list_prepend (pixmaps_directories, g_strdup (directory));
60
 
}
61
 
 
62
 
/* This is an internally used function to find pixmap files. */
63
 
gchar *
64
 
find_pixmap_file (const gchar * filename)
65
 
{
66
 
        GList *elem;
67
 
 
68
 
        /* We step through each of the pixmaps directory to find it. */
69
 
        elem = pixmaps_directories;
70
 
        while (elem)
71
 
        {
72
 
                gchar *pathname = g_strdup_printf ("%s%s%s", (gchar *) elem->data,
73
 
                                                   G_DIR_SEPARATOR_S, filename);
74
 
                if (g_file_test (pathname, G_FILE_TEST_EXISTS))
75
 
                        return pathname;
76
 
                g_free (pathname);
77
 
                elem = elem->next;
78
 
        }
79
 
        return NULL;
80
 
}
81
 
 
82
 
/* This is an internally used function to create pixmaps. */
83
 
GtkWidget *
84
 
create_pixmap (GtkWidget * widget, const gchar * filename)
85
 
{
86
 
        gchar *pathname = NULL;
87
 
        GtkWidget *pixmap;
88
 
 
89
 
        if (!filename || !filename[0])
90
 
                return gtk_image_new ();
91
 
 
92
 
        pathname = find_pixmap_file (filename);
93
 
 
94
 
        if (!pathname)
95
 
        {
96
 
                g_warning (_("Couldn't find pixmap file: %s"), filename);
97
 
                return gtk_image_new ();
98
 
        }
99
 
 
100
 
        pixmap = gtk_image_new_from_file (pathname);
101
 
        g_free (pathname);
102
 
        return pixmap;
103
 
}
104
 
 
105
 
/* This is an internally used function to create pixmaps. */
106
 
GdkPixbuf *
107
 
create_pixbuf (const gchar * filename)
108
 
{
109
 
        gchar *pathname = NULL;
110
 
        GdkPixbuf *pixbuf;
111
 
        GError *error = NULL;
112
 
 
113
 
        if (!filename || !filename[0])
114
 
                return NULL;
115
 
 
116
 
        pathname = find_pixmap_file (filename);
117
 
 
118
 
        if (!pathname)
119
 
        {
120
 
                g_warning (_("Couldn't find pixmap file: %s"), filename);
121
 
                return NULL;
122
 
        }
123
 
 
124
 
        pixbuf = gdk_pixbuf_new_from_file (pathname, &error);
125
 
        if (!pixbuf)
126
 
        {
127
 
                fprintf (stderr, "Failed to load pixbuf file: %s: %s\n", pathname, error->message);
128
 
                g_error_free (error);
129
 
        }
130
 
        g_free (pathname);
131
 
        return pixbuf;
132
 
}
133
 
 
134
 
/* This is used to set ATK action descriptions. */
135
 
void
136
 
glade_set_atk_action_description (AtkAction * action, const gchar * action_name,
137
 
                                  const gchar * description)
138
 
{
139
 
        gint n_actions, i;
140
 
 
141
 
        n_actions = atk_action_get_n_actions (action);
142
 
        for (i = 0; i < n_actions; i++)
143
 
        {
144
 
                if (!strcmp (atk_action_get_name (action, i), action_name))
145
 
                        atk_action_set_description (action, i, description);
146
 
        }
147
 
}