2
* * Copyright (C) 2009-2011 Ali <aliov@xfce.org>
4
* Licensed under the GNU General Public License Version 2
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33
#include <taglib/tag_c.h>
36
#include "parole-file.h"
38
#define PAROLE_FILE_GET_PRIVATE(o) \
39
(G_TYPE_INSTANCE_GET_PRIVATE ((o), PAROLE_TYPE_FILE, ParoleFilePrivate))
41
typedef struct _ParoleFilePrivate ParoleFilePrivate;
43
struct _ParoleFilePrivate
63
G_DEFINE_TYPE (ParoleFile, parole_file, G_TYPE_OBJECT)
66
parole_file_finalize (GObject *object)
69
ParoleFilePrivate *priv;
71
file = PAROLE_FILE (object);
72
priv = PAROLE_FILE_GET_PRIVATE (file);
75
g_free (priv->filename);
80
if ( priv->display_name )
81
g_free (priv->display_name);
83
if ( priv->content_type )
84
g_free (priv->content_type);
86
if ( priv->directory )
87
g_free (priv->directory);
89
G_OBJECT_CLASS (parole_file_parent_class)->finalize (object);
93
parole_file_set_property (GObject *object, guint prop_id,
94
const GValue *value, GParamSpec *pspec)
97
file = PAROLE_FILE (object);
102
PAROLE_FILE_GET_PRIVATE (file)->filename = g_value_dup_string (value);
104
case PROP_DISPLAY_NAME:
105
PAROLE_FILE_GET_PRIVATE (file)->display_name = g_value_dup_string (value);
108
PAROLE_FILE_GET_PRIVATE (file)->directory = g_value_dup_string (value);
111
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
117
parole_file_get_property (GObject *object, guint prop_id,
118
GValue *value, GParamSpec *pspec)
122
file = PAROLE_FILE (object);
127
g_value_set_string (value, PAROLE_FILE_GET_PRIVATE (file)->filename);
130
g_value_set_string (value, PAROLE_FILE_GET_PRIVATE (file)->filename);
132
case PROP_CONTENT_TYPE:
133
g_value_set_string (value, PAROLE_FILE_GET_PRIVATE (file)->content_type);
135
case PROP_DISPLAY_NAME:
136
g_value_set_string (value, PAROLE_FILE_GET_PRIVATE (file)->display_name);
139
g_value_set_string (value, PAROLE_FILE_GET_PRIVATE (file)->directory);
142
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
148
parole_file_constructed (GObject *object)
153
ParoleFilePrivate *priv;
154
GError *error = NULL;
156
file = PAROLE_FILE (object);
157
priv = PAROLE_FILE_GET_PRIVATE (file);
159
gfile = g_file_new_for_commandline_arg (priv->filename);
161
info = g_file_query_info (gfile,
168
priv->directory = g_file_get_path (g_file_get_parent( gfile ));
172
if ( G_LIKELY (error->code == G_IO_ERROR_NOT_SUPPORTED) )
174
g_error_free (error);
175
if ( !priv->display_name )
176
priv->display_name = g_file_get_basename (gfile);
180
if ( !priv->display_name )
181
priv->display_name = g_strdup (priv->filename);
182
g_warning ("Unable to read file info %s", error->message);
189
TagLib_File *tag_file;
194
tag_file = taglib_file_new (priv->filename);
198
tag = taglib_file_tag (tag_file);
201
title = taglib_tag_title (tag);
205
title_s = g_strstrip (title);
206
if ( strlen (title_s ) )
208
priv->display_name = g_strdup (title_s);
212
taglib_tag_free_strings ();
214
taglib_file_free (tag_file);
219
if (!priv->display_name)
220
priv->display_name = g_strdup (g_file_info_get_display_name (info));
222
priv->content_type = g_strdup (g_file_info_get_content_type (info));
224
g_object_unref (info);
227
priv->uri = g_file_get_uri (gfile);
228
g_object_unref (gfile);
232
parole_file_class_init (ParoleFileClass *klass)
234
GObjectClass *object_class = G_OBJECT_CLASS (klass);
236
object_class->finalize = parole_file_finalize;
238
object_class->constructed = parole_file_constructed;
239
object_class->set_property = parole_file_set_property;
240
object_class->get_property = parole_file_get_property;
243
* ParoleFile:filename:
245
* The file name of the file.
249
g_object_class_install_property (object_class,
251
g_param_spec_string ("filename",
255
G_PARAM_CONSTRUCT_ONLY|
259
* ParoleFile:display-name:
261
* A UTF-8 name that can be displayed in the UI.
265
g_object_class_install_property (object_class,
267
g_param_spec_string ("display-name",
269
"A UTF-8 name that can be displayed in the UI",
271
G_PARAM_CONSTRUCT_ONLY|
277
* The uri of the file.
281
g_object_class_install_property (object_class,
283
g_param_spec_string ("uri",
285
"The uri of the file",
290
* ParoleFile:content-type:
292
* The content type of the file.
296
g_object_class_install_property (object_class,
298
g_param_spec_string ("content-type",
300
"The content type of the file",
305
* ParoleFile:directory:
307
* The parent directory of the file.
311
g_object_class_install_property (object_class,
313
g_param_spec_string ("directory",
315
"The parent directory of the file",
317
G_PARAM_CONSTRUCT_ONLY|
320
g_type_class_add_private (klass, sizeof (ParoleFilePrivate));
324
parole_file_init (ParoleFile *file)
326
ParoleFilePrivate *priv;
328
priv = PAROLE_FILE_GET_PRIVATE (file);
330
priv->filename = NULL;
331
priv->display_name = NULL;
333
priv->content_type = NULL;
334
priv->directory = NULL;
339
* @filename: filename.
343
* Returns: A new #ParoleFile object.
348
parole_file_new (const gchar *filename)
350
ParoleFile *file = NULL;
351
file = g_object_new (PAROLE_TYPE_FILE, "filename", filename, NULL);
356
* parole_file_new_with_display_name:
357
* @filename: filename.
361
* Returns: A new #ParoleFile object.
366
parole_file_new_with_display_name (const gchar *filename, const gchar *display_name)
368
ParoleFile *file = NULL;
369
file = g_object_new (PAROLE_TYPE_FILE,
370
"filename", filename,
371
"display-name", display_name,
377
* parole_file_get_file_name:
378
* @file: a #ParoleFile.
381
* Returns: A string containing the file name.
386
parole_file_get_file_name (const ParoleFile *file)
388
g_return_val_if_fail (PAROLE_IS_FILE (file), NULL);
390
return PAROLE_FILE_GET_PRIVATE (file)->filename;
394
* parole_file_get_display_name:
395
* @file: a #ParoleFile.
398
* Returns: A string containing the display name.
403
parole_file_get_display_name (const ParoleFile *file)
405
g_return_val_if_fail (PAROLE_IS_FILE (file), NULL);
407
return PAROLE_FILE_GET_PRIVATE (file)->display_name;
411
* parole_file_get_uri:
412
* @file: a #ParoleFile.
415
* Returns: A string containing the file uri.
420
parole_file_get_uri (const ParoleFile *file)
422
g_return_val_if_fail (PAROLE_IS_FILE (file), NULL);
424
return PAROLE_FILE_GET_PRIVATE (file)->uri;
428
* parole_file_get_content_type:
429
* @file: a #ParoleFile.
432
* Returns: A string containing the content type of the file.
437
parole_file_get_content_type (const ParoleFile *file)
439
g_return_val_if_fail (PAROLE_IS_FILE (file), NULL);
441
return PAROLE_FILE_GET_PRIVATE (file)->content_type;
445
* parole_file_get_directory:
446
* @file: a #ParoleFile.
449
* Returns: A string containing the parent directory path.
454
parole_file_get_directory (const ParoleFile *file)
456
g_return_val_if_fail (PAROLE_IS_FILE (file), NULL);
458
return PAROLE_FILE_GET_PRIVATE (file)->directory;