Yattm - unified GTK instant-messaging client logo
   [Generated for version 0.2-17 - Mon Jan 6 19:01:23 GMT+1 2003]

Home - Main Page - Data Structures - File List - Data Fields - Globals

file_select.c

Go to the documentation of this file.
00001 #include "intl.h"
00002 #include <sys/types.h>
00003 #include <sys/stat.h>
00004 #include <unistd.h>
00005 #include <string.h>
00006 
00007 #include <glib.h>
00008 #include <gdk/gdkkeysyms.h>
00009 #include <gtk/gtk.h>
00010 
00011 #include "file_select.h"
00012 
00013 struct eb_file_selector_data {
00014     void (*callback)(char *filename, gpointer data);
00015     gpointer data;
00016 };
00017 
00018 
00019 static void file_selector_cancel_callback(GtkButton *button, gpointer data)
00020 {
00021     struct eb_file_selector_data *efsd = (struct eb_file_selector_data *)data;
00022 
00023     efsd->callback(NULL, efsd->data);
00024 }
00025 
00026 static void file_selector_ok_callback(GtkButton *button, gpointer data)
00027 {
00028     struct eb_file_selector_data *efsd = (struct eb_file_selector_data *)data;
00029     char *filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(gtk_widget_get_toplevel(GTK_WIDGET(button))));
00030 
00031     efsd->callback(filename, efsd->data);
00032 }
00033 
00034 static void do_file_selector(char *default_filename, char *title,
00035         void (*action_ok)(GtkButton *button, gpointer data), 
00036         void (*action_cancel)(GtkButton *button, gpointer data), 
00037         gpointer data)
00038 {
00039     GtkWidget *file_selector;
00040     GtkWidget *ok_button;
00041     GtkWidget *cancel_button;
00042 
00043     file_selector = gtk_file_selection_new(title);
00044     gtk_object_set_data (GTK_OBJECT (file_selector), "file_selector", file_selector);
00045     gtk_container_set_border_width (GTK_CONTAINER (file_selector), 10);
00046     /*gtk_window_set_modal (GTK_WINDOW (file_selector), TRUE);*/
00047 
00048     ok_button = GTK_FILE_SELECTION (file_selector)->ok_button;
00049     gtk_object_set_data (GTK_OBJECT (file_selector), "ok_button", ok_button);
00050     gtk_widget_show (ok_button);
00051     GTK_WIDGET_SET_FLAGS (ok_button, GTK_CAN_DEFAULT);
00052 
00053     cancel_button = GTK_FILE_SELECTION (file_selector)->cancel_button;
00054     gtk_object_set_data (GTK_OBJECT (file_selector), "cancel_button", cancel_button);
00055     gtk_widget_show (cancel_button);
00056     GTK_WIDGET_SET_FLAGS (cancel_button, GTK_CAN_DEFAULT);
00057 
00058     gtk_signal_connect(GTK_OBJECT (ok_button), "clicked",
00059                         GTK_SIGNAL_FUNC (action_ok), data);
00060 
00061     gtk_signal_connect_object(GTK_OBJECT (ok_button), "clicked",
00062                                GTK_SIGNAL_FUNC (gtk_widget_destroy),
00063                                GTK_OBJECT (file_selector));
00064 
00065     gtk_signal_connect(GTK_OBJECT (cancel_button), "clicked",
00066                         GTK_SIGNAL_FUNC (action_cancel), data);
00067 
00068     gtk_signal_connect_object(GTK_OBJECT (cancel_button), "clicked",
00069                                GTK_SIGNAL_FUNC (gtk_widget_destroy),
00070                                GTK_OBJECT (file_selector));
00071 
00072     if(default_filename)
00073         gtk_file_selection_set_filename(GTK_FILE_SELECTION(file_selector), default_filename);
00074 
00075     gtk_widget_show (file_selector);
00076 }
00077 
00078 void eb_do_file_selector(char *default_filename, char *window_title, 
00079         void (*callback)(char *filename, gpointer data), gpointer data)
00080 {
00081     struct eb_file_selector_data *efsd = g_new0(struct eb_file_selector_data, 1);
00082     efsd->callback = callback;
00083     efsd->data = data;
00084 
00085     do_file_selector(default_filename, window_title, 
00086             file_selector_ok_callback, file_selector_cancel_callback, efsd);
00087 }
00088 
00089 

Contact: Andy Maloney     [Documentation generated by doxygen]