/*- * Copyright (c) 1999-2000 Robin Ericsson * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $Id: callback.c,v 1.7 2000/03/25 10:36:06 lobbin Exp $ */ #include "config.h" #include #include #include "gsfv.h" #include "callback.h" #include "dirtree.h" extern GtkWidget *info_window; void destroy_cb (GtkWidget *widget, gpointer data) { gtk_main_quit (); } void destroy_about (GtkWidget *widget) { gtk_grab_remove (widget); gtk_widget_destroy (widget); } void menu_about_cb (GtkWidget *widget, gpointer data) { GtkWidget *popup; GtkWidget *frame; GtkWidget *label; GtkWidget *vbox; GtkRequisition requisition; char buf[2047]; popup = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_signal_connect_object (GTK_OBJECT (popup), "delete_event", GTK_SIGNAL_FUNC (destroy_about), GTK_OBJECT (popup)); gtk_container_border_width (GTK_CONTAINER (popup), 10); gtk_window_set_title (GTK_WINDOW (popup), "About GSFV"); gtk_widget_size_request (popup, &requisition); gtk_widget_set_uposition (popup, (gdk_screen_width () - requisition.width) / 2, (gdk_screen_height() - requisition.height) / 2); gtk_grab_add (popup); frame = gtk_frame_new (" GTK+ Simple File Verification v" VERSION " "); gtk_container_add (GTK_CONTAINER (popup), frame); gtk_widget_show (frame); vbox = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (frame), vbox); gtk_container_border_width (GTK_CONTAINER (vbox), 6); gtk_widget_show (vbox); label = gtk_label_new (get_version_info (buf)); gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT); gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0); gtk_widget_show (label); gtk_widget_show (popup); } void main_next_button_cb (GtkWidget *widget, gpointer data) { if (GTK_TOGGLE_BUTTON (data)->active) { gsfv_create_sfvfile (); } else { gsfv_verify_files (); } } void file_selection_ok_cb (GtkWidget *widget, GtkFileSelection *fs) { gtk_entry_set_text (GTK_ENTRY (crc_entry), gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs))); gtk_widget_destroy (GTK_WIDGET (fs)); gtk_entry_set_position (GTK_ENTRY (crc_entry), strlen (gtk_entry_get_text (GTK_ENTRY (crc_entry)))); } void file_selection2_ok_cb (GtkWidget *widget, GtkFileSelection *fs) { gtk_entry_set_text (GTK_ENTRY (entry2), gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs))); gtk_widget_destroy (GTK_WIDGET (fs)); gtk_entry_set_position (GTK_ENTRY (entry2), strlen (gtk_entry_get_text (GTK_ENTRY (entry2)))); } void comment_file_selection_clicked (GtkWidget *widget, GtkFileSelection *fs) { gtk_entry_set_text (GTK_ENTRY (entry_commentfile), gtk_file_selection_get_filename (GTK_FILE_SELECTION (fs))); gtk_widget_destroy (GTK_WIDGET (fs)); gtk_entry_set_position (GTK_ENTRY (entry_commentfile), strlen (gtk_entry_get_text (GTK_ENTRY (entry_commentfile)))); } void select_file_button_cb (GtkWidget *widget, gpointer data) { GtkWidget *fsd; gchar *temp; gint len; fsd = gtk_file_selection_new ("Sfv-File Select"); gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (fsd)->ok_button), "clicked", GTK_SIGNAL_FUNC (file_selection_ok_cb), fsd); gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (fsd)->cancel_button), "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT (fsd)); len = strlen (dirtree_get_dir (DIRTREE (tree))); temp = g_malloc0 ( len * sizeof (gchar) + 10); g_snprintf (temp, len + 10, "%s%s", dirtree_get_dir (DIRTREE (tree)), "/"); gtk_file_selection_set_filename (GTK_FILE_SELECTION (fsd), temp); gtk_widget_show (fsd); g_free (temp); } void button_comment_clicked (GtkWidget *widget, gpointer data) { GtkWidget *fsd; gchar *temp; gint len; fsd = gtk_file_selection_new ("Find Comment-file"); gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (fsd)->ok_button), "clicked", GTK_SIGNAL_FUNC (comment_file_selection_clicked), fsd); gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (fsd)->cancel_button), "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT (fsd)); len = strlen (dirtree_get_dir (DIRTREE (tree))); temp = g_malloc0 ( len * sizeof (gchar) + 10); g_snprintf (temp, len + 10, "%s%s", dirtree_get_dir (DIRTREE (tree)), "/"); gtk_file_selection_set_filename (GTK_FILE_SELECTION (fsd), temp); gtk_widget_show (fsd); g_free (temp); } void create_button_next_cb (GtkWidget *widget, gpointer data) { if ( !g_strncasecmp (gtk_entry_get_text (GTK_ENTRY (entry2)), "", 5)) { popup_window ("You must choose a file where the SFV-information should be."); return; } else if (GTK_TOGGLE_BUTTON (check_addcomment)->active && !g_strncasecmp (gtk_entry_get_text (GTK_ENTRY (entry_commentfile)), "", 5)) { popup_window ("You must locate the comment file."); return; } else { gboolean add = FALSE; gboolean comment = FALSE; if (GTK_TOGGLE_BUTTON (check_addfileinfos)->active) add = TRUE; if (GTK_TOGGLE_BUTTON (check_addcomment)->active) comment = TRUE; gsfv_do (GSFV_CREATE, (gpointer) add, (gpointer) comment, create_files); } } void verify_button_next_cb (GtkWidget *widget, gpointer data) { if ( !g_strncasecmp (gtk_entry_get_text (GTK_ENTRY (crc_entry)), "", 5)) { popup_window ("You must choose a file where the SFV-information is."); return; } else { GList *file_list; if ( (file_list = parse_sfvfile(gtk_entry_get_text (GTK_ENTRY (crc_entry))) ) == NULL ) { popup_window ("Error Parsing SFV-File!"); } else { gboolean log = FALSE; gboolean del = FALSE; if (GTK_TOGGLE_BUTTON (check_button_log)->active) log = TRUE; if (GTK_TOGGLE_BUTTON (check_button_delete)->active) del = TRUE; gsfv_do (GSFV_VERIFY, (gpointer) log, (gpointer) del, file_list); } } } void status_button_skip_cb (GtkWidget *widget, gpointer data) { skip_file = TRUE; } void status_button_abort_cb (GtkWidget *widget, gpointer data) { if (status_done == TRUE) gtk_widget_destroy (info_window); else aborted = TRUE; } void create_check_addcomment_cb (GtkWidget *widget, gpointer data) { if (GTK_TOGGLE_BUTTON (check_addcomment)->active) { gtk_widget_set_sensitive (create_label_comment, TRUE); gtk_widget_set_sensitive (button_comment, TRUE); gtk_widget_set_sensitive (entry_commentfile, TRUE); } else { gtk_widget_set_sensitive (create_label_comment, FALSE); gtk_widget_set_sensitive (entry_commentfile, FALSE); gtk_widget_set_sensitive (button_comment, FALSE); } } void create_button_sfvfile_cb (GtkWidget *widget, gpointer data) { GtkWidget *fsd; gchar *temp; gint len; fsd = gtk_file_selection_new ("Sfv-File Select"); gtk_signal_connect (GTK_OBJECT (GTK_FILE_SELECTION (fsd)->ok_button), "clicked", GTK_SIGNAL_FUNC (file_selection2_ok_cb), fsd); gtk_signal_connect_object (GTK_OBJECT (GTK_FILE_SELECTION (fsd)->cancel_button), "clicked", GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT (fsd)); len = strlen (dirtree_get_dir (DIRTREE (tree))); temp = g_malloc0 ( len * sizeof (gchar) + 10); g_snprintf (temp, len + 10, "%s%s", dirtree_get_dir (DIRTREE (tree)), "/"); gtk_file_selection_set_filename (GTK_FILE_SELECTION (fsd), temp); gtk_widget_show (fsd); g_free (temp); } void create_clist_special (GtkWidget *clist, gint row, gint column, gboolean select) { GList *tmp; gchar *text; gtk_clist_get_text (GTK_CLIST (clist), row, column, &text); for (tmp = create_files; tmp != NULL; tmp = tmp->next) { FILE_DATA *fd; if (tmp->data != NULL) { fd = (FILE_DATA *) tmp->data; if (fd && !g_strcasecmp (fd->filename, text)) { if (select) { fd->selected = TRUE; } else { fd->selected = FALSE; } return; } } } } void create_clist_select_row (GtkWidget *clist, gint row, gint column, GdkEventButton *event, gpointer data) { create_clist_special (clist, row, column, TRUE); } void create_clist_unselect_row (GtkWidget *clist, gint row, gint column, GdkEventButton *event, gpointer data) { create_clist_special (clist, row, column, FALSE); }