support.c

Go to the documentation of this file.
00001 /*
00002 lkmonitor (Linux Kernel Monitor)
00003 
00004 Application for monitoring and tuning a Linux kernel.
00005 
00006 Copyright (C) 2005-2006  Fernando ApesteguĂ­a
00007 
00008 This program is free software; you can redistribute it and/or
00009 modify it under the terms of the GNU General Public License
00010 as published by the Free Software Foundation; either version 2
00011 of the License, or (at your option) any later version.
00012 
00013 This program is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with this program; if not, write to the Free Software
00020 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00021 */
00022 #ifdef HAVE_CONFIG_H
00023 #  include <config.h>
00024 #endif
00025 
00026 #include <sys/types.h>
00027 #include <sys/stat.h>
00028 #include <unistd.h>
00029 #include <string.h>
00030 #include <stdio.h>
00031 
00032 #include <gnome.h>
00033 
00034 #include "support.h"
00035 
00036 GtkWidget*
00037 lookup_widget                          (GtkWidget       *widget,
00038                                         const gchar     *widget_name)
00039 {
00040   GtkWidget *parent, *found_widget;
00041 
00042   for (;;)
00043     {
00044       if (GTK_IS_MENU (widget))
00045         parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
00046       else
00047         parent = widget->parent;
00048       if (!parent)
00049         parent = (GtkWidget*) g_object_get_data (G_OBJECT (widget), "GladeParentKey");
00050       if (parent == NULL)
00051         break;
00052       widget = parent;
00053     }
00054 
00055   found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget),
00056                                                  widget_name);
00057   if (!found_widget)
00058     g_warning ("Widget not found: %s", widget_name);
00059   return found_widget;
00060 }
00061 
00062 /* This is an internally used function to create pixmaps. */
00063 GtkWidget*
00064 create_pixmap                          (GtkWidget       *widget,
00065                                         const gchar     *filename)
00066 {
00067   GtkWidget *pixmap;
00068   gchar *pathname;
00069 
00070   if (!filename || !filename[0])
00071       return gtk_image_new ();
00072 
00073   pathname = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_PIXMAP,
00074                                         filename, TRUE, NULL);
00075   if (!pathname)
00076     {
00077       g_warning (_("Couldn't find pixmap file: %s"), filename);
00078       return gtk_image_new ();
00079     }
00080 
00081   pixmap = gtk_image_new_from_file (pathname);
00082   g_free (pathname);
00083   return pixmap;
00084 }
00085 
00086 /* This is an internally used function to create pixmaps. */
00087 GdkPixbuf*
00088 create_pixbuf                          (const gchar     *filename)
00089 {
00090   gchar *pathname = NULL;
00091   GdkPixbuf *pixbuf;
00092   GError *error = NULL;
00093 
00094   if (!filename || !filename[0])
00095       return NULL;
00096 
00097   pathname = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_PIXMAP,
00098                                         filename, TRUE, NULL);
00099 
00100   if (!pathname)
00101     {
00102       g_warning (_("Couldn't find pixmap file: %s"), filename);
00103       return NULL;
00104     }
00105 
00106   pixbuf = gdk_pixbuf_new_from_file (pathname, &error);
00107   if (!pixbuf)
00108     {
00109       fprintf (stderr, "Failed to load pixbuf file: %s: %s\n",
00110                pathname, error->message);
00111       g_error_free (error);
00112     }
00113   g_free (pathname);
00114   return pixbuf;
00115 }
00116 
00117 /* This is used to set ATK action descriptions. */
00118 void
00119 glade_set_atk_action_description       (AtkAction       *action,
00120                                         const gchar     *action_name,
00121                                         const gchar     *description)
00122 {
00123   gint n_actions, i;
00124 
00125   n_actions = atk_action_get_n_actions (action);
00126   for (i = 0; i < n_actions; i++)
00127     {
00128       if (!strcmp (atk_action_get_name (action, i), action_name))
00129         atk_action_set_description (action, i, description);
00130     }
00131 }

Generated on Sat Dec 2 11:27:51 2006 for lkmonitor by  doxygen 1.5.1