mp3splt-gtk
|
00001 /********************************************************** 00002 * 00003 * mp3splt-gtk -- utility based on mp3splt, 00004 * for mp3/ogg splitting without decoding 00005 * 00006 * Copyright: (C) 2005-2011 Alexandru Munteanu 00007 * Contact: io_fx@yahoo.fr 00008 * 00009 * http://mp3splt.sourceforge.net/ 00010 * 00011 *********************************************************/ 00012 00013 /********************************************************** 00014 * 00015 * This program is free software; you can redistribute it and/or 00016 * modify it under the terms of the GNU General Public License 00017 * as published by the Free Software Foundation; either version 2 00018 * of the License, or (at your option) any later version. 00019 * 00020 * This program is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * You should have received a copy of the GNU General Public License 00026 * along with this program; if not, write to the Free Software 00027 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00028 * USA. 00029 * 00030 *********************************************************/ 00031 00032 /*!******************************************************** 00033 * \file 00034 * miscellaneous utilities 00035 * 00036 * Miscellaneous utilities like the check if a string may 00037 * contain a valid file- or directory name. 00038 ********************************************************/ 00039 00040 #include <gtk/gtk.h> 00041 #include <stdlib.h> 00042 #include <string.h> 00043 #include <libmp3splt/mp3splt.h> 00044 #include <glib.h> 00045 #include <glib/gi18n.h> 00046 #include <glib/gstdio.h> 00047 00048 #include "player.h" 00049 #include "preferences_tab.h" 00050 #include "main_win.h" 00051 00053 gint is_filee(const gchar *fname) 00054 { 00055 if (fname == NULL) 00056 { 00057 return FALSE; 00058 } 00059 00060 struct stat buffer; 00061 gint status; 00062 00063 status = g_stat(fname, &buffer); 00064 if (status == 0) 00065 { 00066 //if it is a file 00067 if (S_ISREG(buffer.st_mode) != 0) 00068 { 00069 return TRUE; 00070 } 00071 else 00072 { 00073 return FALSE; 00074 } 00075 } 00076 else 00077 { 00078 return FALSE; 00079 } 00080 } 00081 00086 gint check_if_dir(guchar *fname) 00087 { 00088 struct stat buffer; 00089 00090 g_stat((gchar *)fname, &buffer); 00091 00092 //if it is a directory 00093 if (S_ISDIR(buffer.st_mode) != 0) 00094 return TRUE; 00095 else 00096 return FALSE; 00097 } 00098 00105 gint check_if_file(guchar *fname) 00106 { 00107 struct stat buffer; 00108 00109 g_stat((gchar *)fname, &buffer); 00110 //if it is a file 00111 if (S_ISREG(buffer.st_mode) != 0) 00112 return TRUE; 00113 else 00114 return FALSE; 00115 } 00116 00121 void print_processing_file(gchar *filename) 00122 { 00123 gint fname_status_size = (strlen(filename) + 255); 00124 gchar *fname_status = g_malloc(sizeof(char) * fname_status_size); 00125 g_snprintf(fname_status, fname_status_size, 00126 _("Processing file '%s' ..."), filename); 00127 put_status_message(fname_status); 00128 if (fname_status) 00129 { 00130 free(fname_status); 00131 fname_status = NULL; 00132 } 00133 } 00134 00141 gboolean container_has_child(GtkContainer *container, GtkWidget *my_child) 00142 { 00143 GList *children = gtk_container_get_children(GTK_CONTAINER(container)); 00144 int i = 0; 00145 GtkWidget *child = NULL; 00146 while ((child = g_list_nth_data(children, i)) != NULL) 00147 { 00148 if (child == my_child) 00149 { 00150 return TRUE; 00151 } 00152 i++; 00153 } 00154 00155 return FALSE; 00156 } 00162 void remove_end_slash_n_r_from_filename(char *filename) 00163 { 00164 if (filename == NULL) 00165 { 00166 return; 00167 } 00168 00169 gint index = strlen(filename) - 1; 00170 while (index >= 0) 00171 { 00172 if (filename[index] == '\n' || 00173 filename[index] == '\r') 00174 { 00175 filename[index] = '\0'; 00176 } 00177 else if (filename[index] != '\0') 00178 { 00179 break; 00180 } 00181 00182 index--; 00183 } 00184 } 00185 00196 gchar *transform_to_utf8(gchar *text, gint free_or_not, 00197 gint *must_be_freed) 00198 { 00199 gchar *temp; 00200 00201 gsize bytes_read; 00202 gsize bytes_written; 00203 00204 if(!(g_utf8_validate (text, -1,NULL)) && 00205 (text != NULL)) 00206 { 00207 temp = g_convert(text, -1, "UTF-8", "ISO-8859-1", &bytes_read, &bytes_written, NULL); 00208 if (free_or_not) 00209 g_free(text); 00210 00211 *must_be_freed = TRUE; 00212 00213 return temp; 00214 } 00215 00216 *must_be_freed = FALSE; 00217 00218 return text; 00219 } 00220 00221