/* $Id: set.c,v 1.1.1.1 2000/01/30 16:39:22 benediktroth Exp $ */ #include #include #include #include #include #include #include #include #include "yamt.h" #include "misc.h" GtkWidget *misc_box_new( ) { GtkWidget *box; GtkWidget *misc_directory_frame; GtkWidget *misc_directory_table; GtkWidget *misc_buttons_select; GtkWidget *misc_directory_label; GtkWidget *misc_task_frame; GtkWidget *misc_task_table; GtkWidget *misc_task_replace_box; GtkWidget *misc_task_replace_string1_label; GtkWidget *misc_task_replace_string2_label; GtkWidget *misc_buttons_box; GtkWidget *misc_buttons_start; GtkWidget *misc_buttons_quit; /* The box it which everything is put */ box = gtk_vbox_new( FALSE, 0); /* Frame for directory */ misc_directory_frame = gtk_frame_new( NULL ); gtk_box_pack_start( GTK_BOX(box), misc_directory_frame, TRUE, FALSE, 0 ); gtk_widget_show( misc_directory_frame ); /* Table for directory */ misc_directory_table = gtk_table_new( 1, 1, TRUE); gtk_container_set_border_width( GTK_CONTAINER (misc_directory_table), 5); gtk_container_add( GTK_CONTAINER (misc_directory_frame), misc_directory_table ); gtk_widget_show( misc_directory_table ); /* Directory */ misc_directory_label=gtk_label_new( _("Directory: ") ); gtk_table_attach_defaults( GTK_TABLE(misc_directory_table), misc_directory_label, 0, 1, 0, 1); gtk_widget_show( misc_directory_label ); misc_directory=gtk_label_new( _("[no dir selected]") ); gtk_table_attach_defaults( GTK_TABLE(misc_directory_table), misc_directory, 1, 2, 0, 1); gtk_widget_show( misc_directory ); /* The select button */ misc_buttons_select = gnome_stock_or_ordinary_button( GNOME_STOCK_PIXMAP_OPEN ); gtk_signal_connect( GTK_OBJECT (misc_buttons_select), "clicked", GTK_SIGNAL_FUNC (misc_directory_select), NULL ); gtk_table_attach_defaults( GTK_TABLE(misc_directory_table), misc_buttons_select, 2, 3, 0, 1); gtk_widget_show( misc_buttons_select ); /* The recursive button */ misc_buttons_recursive = gtk_check_button_new_with_label( _("Recurse Subdirs") ); gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON (misc_buttons_recursive), FALSE ); gtk_table_attach_defaults( GTK_TABLE(misc_directory_table), misc_buttons_recursive, 1, 2, 1, 2); gtk_widget_show( misc_buttons_recursive ); /******************************** START ********************************/ /* The task frame */ misc_task_frame = gtk_frame_new( NULL ); gtk_box_pack_start( GTK_BOX(box), misc_task_frame, TRUE, FALSE, 5 ); gtk_widget_show( misc_task_frame ); /* Table */ misc_task_table = gtk_table_new( 4, 3, TRUE); gtk_container_add( GTK_CONTAINER (misc_task_frame), misc_task_table ); gtk_widget_show( misc_task_table ); /* Replace */ /* ------------------- */ misc_task_replace_box = gtk_hbox_new( FALSE, 0); gtk_table_attach_defaults( GTK_TABLE(misc_task_table), misc_task_replace_box, 0, 4, 1, 2); gtk_widget_show( misc_task_replace_box ); misc_task_replace = gtk_radio_button_new_with_label( NULL, _("Filename Fix: ") ); gtk_box_pack_start( GTK_BOX(misc_task_replace_box), misc_task_replace, FALSE, FALSE, 20 ); gtk_widget_show(misc_task_replace); misc_task_replace_string1_label = gtk_label_new( _("Replace every ") ); gtk_box_pack_start( GTK_BOX(misc_task_replace_box), misc_task_replace_string1_label, FALSE, FALSE, 0 ); gtk_widget_show( misc_task_replace_string1_label); /* Create a new combo box */ misc_task_replace_string1 = gtk_combo_new(); gtk_entry_set_editable( GTK_ENTRY (GTK_COMBO(misc_task_replace_string1)->entry), FALSE); /* Create the CList */ if ( !misc_task_replace_string1_list ) { misc_task_replace_string1_list = g_list_append( misc_task_replace_string1_list, _("%20") ); misc_task_replace_string1_list = g_list_append( misc_task_replace_string1_list, _("_") ); misc_task_replace_string1_list = g_list_append( misc_task_replace_string1_list, _(" ") ); } /* Connect the combo and the list */ gtk_combo_set_popdown_strings( GTK_COMBO(misc_task_replace_string1), misc_task_replace_string1_list); gtk_box_pack_start( GTK_BOX(misc_task_replace_box), misc_task_replace_string1, FALSE, FALSE, 0 ); gtk_widget_show( misc_task_replace_string1 ); /* Label for string 2 */ misc_task_replace_string2_label = gtk_label_new( _(" in filenames with ") ); gtk_box_pack_start( GTK_BOX(misc_task_replace_box), misc_task_replace_string2_label, FALSE, FALSE, 0 ); gtk_widget_show( misc_task_replace_string2_label ); /* Create a new combo box */ misc_task_replace_string2 = gtk_combo_new(); gtk_entry_set_editable( GTK_ENTRY (GTK_COMBO(misc_task_replace_string2)->entry), FALSE); /* Create the CList */ if ( !misc_task_replace_string2_list ) { misc_task_replace_string2_list = g_list_append( misc_task_replace_string2_list, _(" ") ); misc_task_replace_string2_list = g_list_append( misc_task_replace_string2_list, _("_") ); misc_task_replace_string2_list = g_list_append( misc_task_replace_string2_list, _("%20") ); } /* Connect the combo and the list */ gtk_combo_set_popdown_strings( GTK_COMBO(misc_task_replace_string2), misc_task_replace_string2_list); gtk_box_pack_start( GTK_BOX(misc_task_replace_box), misc_task_replace_string2, FALSE, FALSE, 0 ); gtk_widget_show( misc_task_replace_string2 ); /******************************** END ********************************/ /* The Box for the buttons */ misc_buttons_box = gtk_hbox_new( TRUE, 10); gtk_container_set_border_width( GTK_CONTAINER (misc_buttons_box), 5); gtk_box_pack_start( GTK_BOX(box), misc_buttons_box, TRUE, FALSE, 0 ); gtk_widget_show( misc_buttons_box ); /* The Buttons */ misc_buttons_start = gnome_stock_or_ordinary_button( GNOME_STOCK_PIXMAP_EXEC ); gtk_signal_connect( GTK_OBJECT (misc_buttons_start), "clicked", GTK_SIGNAL_FUNC (misc_start), NULL ); gtk_box_pack_start( GTK_BOX(misc_buttons_box), misc_buttons_start, TRUE, TRUE, 0 ); gtk_widget_show( misc_buttons_start ); misc_buttons_quit = gnome_stock_or_ordinary_button( GNOME_STOCK_PIXMAP_QUIT ); gtk_signal_connect( GTK_OBJECT (misc_buttons_quit), "clicked", GTK_SIGNAL_FUNC (gtk_exit), NULL ); gtk_box_pack_start( GTK_BOX(misc_buttons_box), misc_buttons_quit, TRUE, TRUE, 0 ); gtk_widget_show( misc_buttons_quit ); return(box); } void misc_load_properties( void ) { gtk_label_set_text( GTK_LABEL (misc_directory), prop_mp3_dir ); } void misc_directory_select( void ) { GtkWidget *filew; gchar *buffer; gtk_label_get( GTK_LABEL (misc_directory), &buffer ); filew = gtk_file_selection_new( _("Select a Directory") ); gtk_file_selection_set_filename( GTK_FILE_SELECTION (filew), buffer ); gtk_signal_connect( GTK_OBJECT (filew), "destroy", GTK_SIGNAL_FUNC (gtk_widget_destroy), filew); /* Connect the ok buton to load_file */ gtk_signal_connect( GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button), "clicked", GTK_SIGNAL_FUNC (misc_lf), filew); gtk_signal_connect( GTK_OBJECT (GTK_FILE_SELECTION (filew)->ok_button), "clicked", GTK_SIGNAL_FUNC (destroy), filew); /* Connect the cancel buton to destroy */ gtk_signal_connect( GTK_OBJECT (GTK_FILE_SELECTION (filew)->cancel_button), "clicked", GTK_SIGNAL_FUNC (destroy), filew); gtk_widget_show(filew); } /* I don't know how to pass the filename directly to load_file so I use this function */ void misc_lf( GtkWidget *widget, GtkFileSelection *file_selection ) { gchar *filename=gtk_file_selection_get_filename( GTK_FILE_SELECTION (file_selection)); misc_directory_load( filename ); } void misc_directory_load( gchar *dirname ) { gtk_label_set_text( GTK_LABEL (misc_directory),dirname); /* g_print("dir: %s\n", dirname ); */ } void misc_start( ) { gchar *directory; gboolean recursive; gchar *string1; gchar *string2; gtk_label_get( GTK_LABEL (misc_directory), &directory ); yamtlog("%s %s", _("Misc-Directory: "), directory ); recursive = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON (misc_buttons_recursive) ); yamtlog("%s %s", _("Misc-Recursive: "), recursive ? "TRUE" : "FALSE" ); string1 = gtk_entry_get_text( GTK_ENTRY (GTK_COMBO(misc_task_replace_string1)->entry) ); yamtlog("%s %s", "Misc-String Level1: ", string1); string2 = gtk_entry_get_text( GTK_ENTRY (GTK_COMBO(misc_task_replace_string2)->entry) ); yamtlog("%s %s", "Misc-String Level2: ", string2); misc_go( directory, 0, recursive, string1, string2 ); } void misc_go( gchar *dir, gint depth, gboolean recursive, gchar *string1, gchar *string2) { DIR *dp; struct dirent *entry; struct stat statbuf; /* struct mpegformat_t *header; */ gchar new_filename[BUFFERSIZE]=""; gchar command[BUFFERSIZE]; gchar buffer[BUFFERSIZE]=""; gint i; gint i2; gint i3; if( (dp = opendir(dir))==NULL ) { yamtlog("%s %s", _("ERROR while opening "), dir); /* gnome_error_dialog( _("Could not open directory!") ); */ return; } chdir(dir); if(dir[strlen(dir)-1]=='/') dir[strlen(dir)-1]=0; while( (entry = readdir(dp)) != NULL ) { update_progress_bar(); stat( entry->d_name, &statbuf); if( S_ISDIR(statbuf.st_mode)) { /* Shall it be recursive ? */ if( recursive == 0 ) continue; /* Found a directory, ignore "." and ".." */ if( strcmp(".", entry->d_name) == 0 || strcmp("..", entry->d_name) == 0 ) continue; /* printf("%*s%s/\n", depth, " ", entry->d_name ); */ /* Recurse but increase the indent level */ misc_go( entry->d_name, depth+4, recursive, string1, string2 ); } else { /* printf("%*s%s", depth, " ", entry->d_name ); */ /* Only real mp3s ! */ /* if( get_header_data( entry->d_name, &header) == 0 ) */ /* { */ /* g_print(" NO!\n"); */ /* continue; */ /* } */ for( i=0; id_name); ) { if( entry->d_name[i] == string1[0] ) { if( strlen(string1) > 1 ) { for( i3=i; i3-id_name[i3]; buffer[i3-i]='\0'; if( !strcmp( buffer, string1 ) ) { strcat( new_filename, string2 ); i = i + strlen(string1); i2 = i2 + strlen(string2); } else i++; } else { if( strlen(string2) > 1 ) strcat( new_filename, string2 ); else new_filename[i2] = string2[0]; i = i + strlen(string1); i2 = i2 + strlen(string2); } } else { new_filename[i2] = entry->d_name[i]; i++; i2++; } } if( strcmp( new_filename, entry->d_name) ) { sprintf( command, "mv \"%s\" \"%s\"", entry->d_name, new_filename ); system( command ); yamtlog("%s %s %s", entry->d_name, " moved to ", new_filename ); /* g_print(" moved to \"%s\".\n", new_filename ); */ } else yamtlog("%s %s", entry->d_name, " not changed" ); /* g_print(" ok!\n"); */ } } chdir(".."); closedir(dp); }