mp3splt-gtk
utilities.c
Go to the documentation of this file.
1 /**********************************************************
2  *
3  * mp3splt-gtk -- utility based on mp3splt,
4  * for mp3/ogg splitting without decoding
5  *
6  * Copyright: (C) 2005-2012 Alexandru Munteanu
7  * Contact: io_fx@yahoo.fr
8  *
9  * http://mp3splt.sourceforge.net/
10  *
11  *********************************************************/
12 
13 /**********************************************************
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * as published by the Free Software Foundation; either version 2
18  * of the License, or (at your option) any later version.
19  *
20  * This program is distributed in the hope that it will be useful,
21  * but WITHOUT ANY WARRANTY; without even the implied warranty of
22  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  * GNU General Public License for more details.
24  *
25  * You should have received a copy of the GNU General Public License
26  * along with this program; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28  * USA.
29  *
30  *********************************************************/
31 
32 /*!********************************************************
33  * \file
34  * miscellaneous utilities
35  *
36  * Miscellaneous utilities like the check if a string may
37  * contain a valid file- or directory name.
38  ********************************************************/
39 
40 #include <gtk/gtk.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include <libmp3splt/mp3splt.h>
44 #include <glib.h>
45 #include <glib/gi18n.h>
46 #include <glib/gstdio.h>
47 
48 #include "player.h"
49 #include "preferences_tab.h"
50 #include "main_win.h"
51 
53 gint is_filee(const gchar *fname)
54 {
55  if (fname == NULL)
56  {
57  return FALSE;
58  }
59 
60  struct stat buffer;
61  gint status;
62 
63  status = g_stat(fname, &buffer);
64  if (status == 0)
65  {
66  //if it is a file
67  if (S_ISREG(buffer.st_mode) != 0)
68  {
69  return TRUE;
70  }
71  else
72  {
73  return FALSE;
74  }
75  }
76  else
77  {
78  return FALSE;
79  }
80 }
81 
86 gint check_if_dir(guchar *fname)
87 {
88  struct stat buffer;
89 
90  g_stat((gchar *)fname, &buffer);
91 
92  //if it is a directory
93  if (S_ISDIR(buffer.st_mode) != 0)
94  return TRUE;
95  else
96  return FALSE;
97 }
98 
105 gint check_if_file(guchar *fname)
106 {
107  struct stat buffer;
108 
109  g_stat((gchar *)fname, &buffer);
110  //if it is a file
111  if (S_ISREG(buffer.st_mode) != 0)
112  return TRUE;
113  else
114  return FALSE;
115 }
116 
121 void print_processing_file(gchar *filename)
122 {
123  gint fname_status_size = (strlen(filename) + 255);
124  gchar *fname_status = g_malloc(sizeof(char) * fname_status_size);
125  g_snprintf(fname_status, fname_status_size,
126  _("Processing file '%s' ..."), filename);
127  put_status_message(fname_status);
128  if (fname_status)
129  {
130  free(fname_status);
131  fname_status = NULL;
132  }
133 }
134 
141 gboolean container_has_child(GtkContainer *container, GtkWidget *my_child)
142 {
143  GList *children = gtk_container_get_children(GTK_CONTAINER(container));
144  int i = 0;
145  GtkWidget *child = NULL;
146  while ((child = g_list_nth_data(children, i)) != NULL)
147  {
148  if (child == my_child)
149  {
150  return TRUE;
151  }
152  i++;
153  }
154 
155  return FALSE;
156 }
163 {
164  if (filename == NULL)
165  {
166  return;
167  }
168 
169  gint index = strlen(filename) - 1;
170  while (index >= 0)
171  {
172  if (filename[index] == '\n' ||
173  filename[index] == '\r')
174  {
175  filename[index] = '\0';
176  }
177  else if (filename[index] != '\0')
178  {
179  break;
180  }
181 
182  index--;
183  }
184 }
185 
196 gchar *transform_to_utf8(gchar *text, gint free_or_not,
197  gint *must_be_freed)
198 {
199  gchar *temp;
200 
201  gsize bytes_read;
202  gsize bytes_written;
203 
204  if(!(g_utf8_validate (text, -1,NULL)) &&
205  (text != NULL))
206  {
207  temp = g_convert(text, -1, "UTF-8", "ISO-8859-1", &bytes_read, &bytes_written, NULL);
208  if (free_or_not)
209  g_free(text);
210 
211  *must_be_freed = TRUE;
212 
213  return temp;
214  }
215 
216  *must_be_freed = FALSE;
217 
218  return text;
219 }
220 
221