1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
#include <gtk/gtk.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <linux/sockios.h>
#include <string.h>
#include <math.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
GtkWidget *filew;
GtkWidget *selection_entry;
/* Get the selected filename and print it to the console */
static void file_ok_sel( GtkWidget *w,
GtkFileSelection *fs )
{
char *file;
file=gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs));
g_print ("%s\n",file );
}
static void set_selected(GtkWidget *w,
GtkFileSelection *fs,
GtkEntry *entry)
{
// char *file1;
/* file1=gtk_file_selection_get_filename(GTK_FILE_SELECTION(filew));
if(GTK_FILE_SELECTION (filew)->selection_entry!=NULL)
{ */
// gtk_widget_set_sensitive(G_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),TRUE);
//}
char *file1;
// file1=gtk_file_selection_get_filename(GTK_FILE_SELECTION(fs));
// gtk_entry_set_text (GTK_FILE_SELECTION (filew)->selection_entry,file1);
file1=gtk_entry_get_text (GTK_FILE_SELECTION (fs)->selection_entry);
g_print ("file1 = %s\n",file1 );
}
int main( int argc,
char *argv[] )
{
//GtkWidget *filew;
gtk_init (&argc, &argv);
/* Create a new file selection widget */
filew = gtk_file_selection_new ("File selection");
g_signal_connect (G_OBJECT (filew), "destroy",
G_CALLBACK (gtk_main_quit), NULL);
/* Connect the ok_button to file_ok_sel function */
g_signal_connect (G_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),
"clicked", G_CALLBACK (file_ok_sel), (gpointer) filew);
/* Ensure that the dialog box is destroyed when the user clicks a button. */
g_signal_connect_swapped (GTK_FILE_SELECTION (filew)->ok_button,
"clicked",
G_CALLBACK (gtk_widget_destroy),
(gpointer) filew);
gtk_widget_set_sensitive(G_OBJECT (GTK_FILE_SELECTION (filew)->ok_button),FALSE);
/* Connect the cancel_button to destroy the widget */
g_signal_connect_swapped (G_OBJECT (GTK_FILE_SELECTION (filew)->cancel_button),
"clicked", G_CALLBACK (gtk_widget_destroy),
G_OBJECT (filew));
g_signal_connect(G_OBJECT(GTK_FILE_SELECTION (filew)->selection_entry), "insert_text",
G_CALLBACK(set_selected),
G_OBJECT (filew));
/* Lets set the filename, as if this were a save dialog, and we are giving
a default filename */
gtk_file_selection_set_filename (GTK_FILE_SELECTION(filew),
" ");
// gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(filew));
gtk_widget_show (filew);
gtk_main ();
return 0;
} |