Glavna stranica | Popis datoteka | Članovi klasa u datoteci

/home/srle/Projects/sisadmin/src/support.c

Dokumenacija za ovu datoteku.
00001 /********************************************************************************
00002  *      Studentski Informacijski servis, 2004                                                                           *
00003  ********************************************************************************
00004  *  SiS.Admin                                                                                                                                   *
00005  *  support.c                                                                                                                                   *
00006  *      File za support funkcije programa                                                                                       *
00007  *                                                                                                                                                              *
00008  *  Srdjan Segvic - srle                                                                                                                *
00009  ********************************************************************************
00010  ********************************************************************************
00011  *  This program is free software; you can redistribute it and/or modify                *
00012  *  it under the terms of the GNU General Public License as published by                *
00013  *  the Free Software Foundation; either version 2 of the License, or                   *
00014  *  (at your option) any later version.                                                                                 *
00015  *                                                                                                                                                              *
00016  *  This program is distributed in the hope that it will be useful,                             *
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of                              *
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                               *
00019  *  GNU Library General Public License for more details.                                                *
00020  *                                                                                                                                                              *
00021  *  You should have received a copy of the GNU General Public License                   *
00022  *  along with this program; if not, write to the Free Software                                 *
00023  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  *
00024  ********************************************************************************/
00025 
00026 #ifdef HAVE_CONFIG_H
00027 #  include <config.h>
00028 #endif
00029 
00030 #include <sys/types.h>
00031 #include <sys/stat.h>
00032 #include <unistd.h>
00033 #include <string.h>
00034 #include <stdio.h>
00035 
00036 #include <gtk/gtk.h>
00037 
00038 #include "support.h"
00039 
00040 GtkWidget*
00041 lookup_widget                          (GtkWidget       *widget,
00042                                         const gchar     *widget_name)
00043 {
00044   GtkWidget *parent, *found_widget;
00045 
00046   for (;;)
00047     {
00048       if (GTK_IS_MENU (widget))
00049         parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
00050       else
00051         parent = widget->parent;
00052       if (!parent)
00053         parent = (GtkWidget*) g_object_get_data (G_OBJECT (widget), "GladeParentKey");
00054       if (parent == NULL)
00055         break;
00056       widget = parent;
00057     }
00058 
00059   found_widget = (GtkWidget*) g_object_get_data (G_OBJECT (widget),
00060                                                  widget_name);
00061   if (!found_widget)
00062     g_warning ("Widget not found: %s", widget_name);
00063   return found_widget;
00064 }
00065 
00066 static GList *pixmaps_directories = NULL;
00067 
00068 /* Use this function to set the directory containing installed pixmaps. */
00069 void
00070 add_pixmap_directory                   (const gchar     *directory)
00071 {
00072   pixmaps_directories = g_list_prepend (pixmaps_directories,
00073                                         g_strdup (directory));
00074 }
00075 
00076 /* This is an internally used function to find pixmap files. */
00077 static gchar*
00078 find_pixmap_file                       (const gchar     *filename)
00079 {
00080   GList *elem;
00081 
00082   /* We step through each of the pixmaps directory to find it. */
00083   elem = pixmaps_directories;
00084   while (elem)
00085     {
00086       gchar *pathname = g_strdup_printf ("%s%s%s", (gchar*)elem->data,
00087                                          G_DIR_SEPARATOR_S, filename);
00088       if (g_file_test (pathname, G_FILE_TEST_EXISTS))
00089         return pathname;
00090       g_free (pathname);
00091       elem = elem->next;
00092     }
00093   return NULL;
00094 }
00095 
00096 /* This is an internally used function to create pixmaps. */
00097 GtkWidget*
00098 create_pixmap                          (GtkWidget       *widget,
00099                                         const gchar     *filename)
00100 {
00101   gchar *pathname = NULL;
00102   GtkWidget *pixmap;
00103 
00104   if (!filename || !filename[0])
00105       return gtk_image_new ();
00106 
00107   pathname = find_pixmap_file (filename);
00108 
00109   if (!pathname)
00110     {
00111       g_warning (_("Couldn't find pixmap file: %s"), filename);
00112       return gtk_image_new ();
00113     }
00114 
00115   pixmap = gtk_image_new_from_file (pathname);
00116   g_free (pathname);
00117   return pixmap;
00118 }
00119 
00120 /* This is an internally used function to create pixmaps. */
00121 GdkPixbuf*
00122 create_pixbuf                          (const gchar     *filename)
00123 {
00124   gchar *pathname = NULL;
00125   GdkPixbuf *pixbuf;
00126   GError *error = NULL;
00127 
00128   if (!filename || !filename[0])
00129       return NULL;
00130 
00131   pathname = find_pixmap_file (filename);
00132 
00133   if (!pathname)
00134     {
00135       g_warning (_("Couldn't find pixmap file: %s"), filename);
00136       return NULL;
00137     }
00138 
00139   pixbuf = gdk_pixbuf_new_from_file (pathname, &error);
00140   if (!pixbuf)
00141     {
00142       fprintf (stderr, "Failed to load pixbuf file: %s: %s\n",
00143                pathname, error->message);
00144       g_error_free (error);
00145     }
00146   g_free (pathname);
00147   return pixbuf;
00148 }
00149 
00150 /* This is used to set ATK action descriptions. */
00151 void
00152 glade_set_atk_action_description       (AtkAction       *action,
00153                                         const gchar     *action_name,
00154                                         const gchar     *description)
00155 {
00156   gint n_actions, i;
00157 
00158   n_actions = atk_action_get_n_actions (action);
00159   for (i = 0; i < n_actions; i++)
00160     {
00161       if (!strcmp (atk_action_get_name (action, i), action_name))
00162         atk_action_set_description (action, i, description);
00163     }
00164 }
00165 

Generirano Thu Sep 16 17:26:20 2004 projekt: SiS.Admin generator: doxygen 1.3.2