00001
00023 #ifdef HAVE_CONFIG_H
00024 # include <config.h>
00025 #endif
00026
00027 #include <sys/types.h>
00028 #include <sys/stat.h>
00029 #include <unistd.h>
00030 #include <string.h>
00031 #include <stdio.h>
00032 #include <stdlib.h>
00033
00034 #include <gdk/gdkkeysyms.h>
00035 #include <gtk/gtk.h>
00036
00037
00038 #include "../globals.h"
00039 #include "filechooser_dialog.h"
00040
00041
00058 void
00059 on_filechooser_dialog_cancel_button_clicked
00060 (GtkButton *button,
00061 gpointer user_data)
00062 {
00063 GtkWidget *filechooser_dialog = lookup_widget (GTK_WIDGET (button),
00064 "filechooser_dialog");
00065 gtk_widget_destroy (filechooser_dialog);
00066 }
00067
00068
00083 void
00084 on_filechooser_dialog_close (GtkDialog *dialog,
00085 gpointer user_data)
00086 {
00087 GtkWidget *filechooser_dialog = lookup_widget (GTK_WIDGET (dialog),
00088 "filechooser_dialog");
00089 gtk_widget_destroy (filechooser_dialog);
00090 }
00091
00092
00093
00111 void
00112 on_filechooser_dialog_current_folder_changed
00113 (
00114 GtkFileChooser *filechooser,
00115 gpointer user_data
00116 )
00117 {
00118 GtkWidget *filechooser_dialog = lookup_widget (GTK_WIDGET (filechooser),
00119 "filechooser_dialog");
00120 gchar *current_folder = g_strdup (gtk_file_chooser_get_current_folder
00121 (GTK_FILE_CHOOSER (filechooser_dialog)));
00122
00123
00124 if (!current_folder)
00125 {
00126 if (verbose)
00127 g_log ("", G_LOG_LEVEL_WARNING,
00128 _("current folder is not initialised (null pointer)."));
00129 }
00130
00131
00132 else if (!strcmp (current_folder, ""))
00133 {
00134 if (verbose)
00135 g_log ("", G_LOG_LEVEL_WARNING,
00136 _("current folder contains an empty string."));
00137 }
00138
00139
00140 else if (g_file_test (current_folder, G_FILE_TEST_IS_DIR))
00141 {
00142 temp_dir = g_strdup (current_folder);
00143 if (verbose)
00144 g_log ("", G_LOG_LEVEL_INFO, _("Changed cwd to: %s"),
00145 current_folder);
00146 }
00147
00148 g_free (current_folder);
00149 }
00150
00151
00175 void
00176 on_filechooser_dialog_open_button_clicked
00177 (
00178 GtkButton *button,
00179 gpointer user_data
00180 )
00181 {
00182 GtkWidget *filechooser_dialog = lookup_widget (GTK_WIDGET (button),
00183 "filechooser_dialog");
00184 gchar *selected_filename = NULL;
00185 selected_filename = g_strdup (gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser_dialog)));
00186
00187
00188 if (!selected_filename)
00189 {
00190 if (verbose)
00191 g_log ("", G_LOG_LEVEL_WARNING,
00192 _("selected filename is not initialised (NULL pointer)."));
00193 }
00194
00195
00196 else if (!strcmp (selected_filename, ""))
00197 {
00198 if (verbose)
00199 g_log ("", G_LOG_LEVEL_WARNING,
00200 _("selected filename contains an empty string."));
00201 }
00202
00203
00204
00205 else if (g_file_test (selected_filename, G_FILE_TEST_IS_DIR))
00206 {
00207 if (verbose)
00208 g_log ("", G_LOG_LEVEL_WARNING, _("selected filename is a directory."));
00209 }
00210 else
00211 {
00212
00213 gchar *fpw_filename = g_strdup (selected_filename);
00214 if (temp_dir)
00215 work_dir = g_strdup (temp_dir);
00216
00217 if (read_footprintwizard_file (fpw_filename) == EXIT_SUCCESS)
00218 {
00219 if (verbose)
00220 g_log ("", G_LOG_LEVEL_INFO, _("Read footprintwizard file %s."), fpw_filename);
00221
00222 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button));
00223 if (GTK_WIDGET_TOPLEVEL (toplevel))
00224 {
00225 all_entries_need_updated (GTK_WIDGET (toplevel));
00226 }
00227
00228 g_free (toplevel);
00229 }
00230 else
00231 {
00232 GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (button));
00233 if (GTK_WIDGET_TOPLEVEL (toplevel))
00234 {
00235 GtkWidget *dialog = gtk_message_dialog_new
00236 (
00237 GTK_WINDOW (toplevel),
00238 GTK_DIALOG_DESTROY_WITH_PARENT,
00239 GTK_MESSAGE_ERROR,
00240 GTK_BUTTONS_CLOSE,
00241 g_strdup_printf (_("ERROR: Unable to read footprint wizard file %s."), fpw_filename)
00242 );
00243 gtk_dialog_run (GTK_DIALOG (dialog));
00244 gtk_widget_destroy (dialog);
00245 g_free (dialog);
00246 return;
00247 }
00248 g_free (toplevel);
00249 }
00250
00251 g_free (fpw_filename);
00252 }
00253
00254 g_free (selected_filename);
00255 }
00256
00257
00273 void
00274 on_filechooser_dialog_selection_changed
00275 (GtkFileChooser *filechooser,
00276 gpointer user_data)
00277 {
00278
00279 }
00280
00281
00294 void
00295 on_filechooser_dialog_update_preview (GtkFileChooser *filechooser,
00296 gpointer user_data)
00297 {
00298
00299 }
00300
00301
00309 GtkWidget*
00310 create_filechooser_dialog (void)
00311 {
00312 GtkWidget *filechooser_dialog;
00313 GdkPixbuf *filechooser_dialog_icon_pixbuf;
00314 GtkWidget *filechooser_dialog_vbox;
00315 GtkWidget *filechooser_dialog_action_area;
00316 GtkWidget *filechooser_dialog_cancel_button;
00317 GtkWidget *filechooser_dialog_open_button;
00318
00319 filechooser_dialog = gtk_file_chooser_dialog_new (_("pcb-gfpw: choose a .fpw file"), NULL, GTK_FILE_CHOOSER_ACTION_OPEN, NULL);
00320 gtk_widget_set_name (filechooser_dialog, "filechooser_dialog");
00321 filechooser_dialog_icon_pixbuf = create_pixbuf ("gFootprintWizard.xpm");
00322 if (filechooser_dialog_icon_pixbuf)
00323 {
00324 gtk_window_set_icon (GTK_WINDOW (filechooser_dialog), filechooser_dialog_icon_pixbuf);
00325 gdk_pixbuf_unref (filechooser_dialog_icon_pixbuf);
00326 }
00327 gtk_window_set_type_hint (GTK_WINDOW (filechooser_dialog), GDK_WINDOW_TYPE_HINT_DIALOG);
00328
00329 filechooser_dialog_vbox = GTK_DIALOG (filechooser_dialog)->vbox;
00330 gtk_widget_set_name (filechooser_dialog_vbox, "filechooser_dialog_vbox");
00331 gtk_widget_show (filechooser_dialog_vbox);
00332
00333 filechooser_dialog_action_area = GTK_DIALOG (filechooser_dialog)->action_area;
00334 gtk_widget_set_name (filechooser_dialog_action_area, "filechooser_dialog_action_area");
00335 gtk_widget_show (filechooser_dialog_action_area);
00336 gtk_button_box_set_layout (GTK_BUTTON_BOX (filechooser_dialog_action_area), GTK_BUTTONBOX_END);
00337
00338 filechooser_dialog_cancel_button = gtk_button_new_from_stock ("gtk-cancel");
00339 gtk_widget_set_name (filechooser_dialog_cancel_button, "filechooser_dialog_cancel_button");
00340 gtk_widget_show (filechooser_dialog_cancel_button);
00341 gtk_dialog_add_action_widget (GTK_DIALOG (filechooser_dialog), filechooser_dialog_cancel_button, GTK_RESPONSE_CANCEL);
00342 GTK_WIDGET_SET_FLAGS (filechooser_dialog_cancel_button, GTK_CAN_DEFAULT);
00343
00344 filechooser_dialog_open_button = gtk_button_new_from_stock ("gtk-open");
00345 gtk_widget_set_name (filechooser_dialog_open_button, "filechooser_dialog_open_button");
00346 gtk_widget_show (filechooser_dialog_open_button);
00347 gtk_dialog_add_action_widget (GTK_DIALOG (filechooser_dialog), filechooser_dialog_open_button, GTK_RESPONSE_OK);
00348 GTK_WIDGET_SET_FLAGS (filechooser_dialog_open_button, GTK_CAN_DEFAULT);
00349
00350 g_signal_connect
00351 (
00352 (gpointer) filechooser_dialog,
00353 "selection_changed",
00354 G_CALLBACK (on_filechooser_dialog_selection_changed),
00355 NULL
00356 );
00357 g_signal_connect
00358 (
00359 (gpointer) filechooser_dialog,
00360 "close",
00361 G_CALLBACK (on_filechooser_dialog_close),
00362 NULL
00363 );
00364 g_signal_connect
00365 (
00366 (gpointer) filechooser_dialog,
00367 "current_folder_changed",
00368 G_CALLBACK (on_filechooser_dialog_current_folder_changed),
00369 NULL
00370 );
00371 g_signal_connect
00372 (
00373 (gpointer) filechooser_dialog,
00374 "update_preview",
00375 G_CALLBACK (on_filechooser_dialog_update_preview),
00376 NULL
00377 );
00378 g_signal_connect
00379 (
00380 (gpointer) filechooser_dialog_cancel_button,
00381 "clicked",
00382 G_CALLBACK (on_filechooser_dialog_cancel_button_clicked),
00383 NULL
00384 );
00385 g_signal_connect
00386 (
00387 (gpointer) filechooser_dialog_open_button,
00388 "clicked",
00389 G_CALLBACK (on_filechooser_dialog_open_button_clicked),
00390 NULL
00391 );
00392
00393 GLADE_HOOKUP_OBJECT_NO_REF (filechooser_dialog, filechooser_dialog, "filechooser_dialog");
00394 GLADE_HOOKUP_OBJECT_NO_REF (filechooser_dialog, filechooser_dialog_vbox, "filechooser_dialog_vbox");
00395 GLADE_HOOKUP_OBJECT_NO_REF (filechooser_dialog, filechooser_dialog_action_area, "filechooser_dialog_action_area");
00396 GLADE_HOOKUP_OBJECT (filechooser_dialog, filechooser_dialog_cancel_button, "filechooser_dialog_cancel_button");
00397 GLADE_HOOKUP_OBJECT (filechooser_dialog, filechooser_dialog_open_button, "filechooser_dialog_open_button");
00398 gtk_widget_grab_default (filechooser_dialog_open_button);
00399 return filechooser_dialog;
00400 }
00401
00402
00403