~ubuntu-branches/ubuntu/saucy/parole/saucy

« back to all changes in this revision

Viewing changes to src/misc/parole-file.c

  • Committer: Package Import Robot
  • Author(s): Lionel Le Folgoc
  • Date: 2012-08-15 13:56:10 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20120815135610-xkgrhm52dq81czhe
Tags: 0.3.0-0ubuntu1
* New upstream release.
* debian/patches:
  - 01_fix-implicit-dso-linking.patch: dropped, included upstream.
  - 01_fix-plugin-install-dir.patch, 02_fix-ftbfs-enable-debug.patch,
    03_fix-ftbfs-built-twice.patch: added, fix wrong install path and build
    failures.
* debian/control:
  - replace b-dep on libxfcegui4-dev with libxfce4ui-1-dev and bump
    libgtk2.0-dev to >= 2.20.
* debian/rules:
  - create empty m4 directory if missing.
  - clean up autogenerated files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * * Copyright (C) 2009-2011 Ali <aliov@xfce.org>
 
3
 *
 
4
 * Licensed under the GNU General Public License Version 2
 
5
 *
 
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.
 
10
 *
 
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.
 
15
 *
 
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
 
19
 */
 
20
 
 
21
#ifdef HAVE_CONFIG_H
 
22
#include <config.h>
 
23
#endif
 
24
 
 
25
#include <stdio.h>
 
26
#include <stdlib.h>
 
27
#include <string.h>
 
28
 
 
29
#include <glib.h>
 
30
#include <gio/gio.h>
 
31
 
 
32
#ifdef HAVE_TAGLIBC
 
33
#include <taglib/tag_c.h>
 
34
#endif
 
35
 
 
36
#include "parole-file.h"
 
37
 
 
38
#define PAROLE_FILE_GET_PRIVATE(o) \
 
39
(G_TYPE_INSTANCE_GET_PRIVATE ((o), PAROLE_TYPE_FILE, ParoleFilePrivate))
 
40
 
 
41
typedef struct _ParoleFilePrivate ParoleFilePrivate;
 
42
 
 
43
struct _ParoleFilePrivate
 
44
{
 
45
    gchar       *filename;
 
46
    gchar       *display_name;
 
47
    gchar       *uri;
 
48
    gchar       *content_type;
 
49
        gchar   *directory;
 
50
    
 
51
};
 
52
 
 
53
enum
 
54
{
 
55
    PROP_0,
 
56
    PROP_PATH,
 
57
    PROP_DISPLAY_NAME,
 
58
    PROP_URI,
 
59
    PROP_CONTENT_TYPE,
 
60
        PROP_DIRECTORY
 
61
};
 
62
 
 
63
G_DEFINE_TYPE (ParoleFile, parole_file, G_TYPE_OBJECT)
 
64
 
 
65
static void
 
66
parole_file_finalize (GObject *object)
 
67
{
 
68
    ParoleFile *file;
 
69
    ParoleFilePrivate *priv;
 
70
 
 
71
    file = PAROLE_FILE (object);
 
72
    priv = PAROLE_FILE_GET_PRIVATE (file);
 
73
    
 
74
    if ( priv->filename )
 
75
        g_free (priv->filename);
 
76
 
 
77
    if ( priv->uri )
 
78
        g_free (priv->uri);
 
79
        
 
80
    if ( priv->display_name )
 
81
        g_free (priv->display_name);
 
82
        
 
83
    if ( priv->content_type )
 
84
        g_free (priv->content_type);
 
85
        
 
86
        if ( priv->directory )
 
87
        g_free (priv->directory);
 
88
    
 
89
    G_OBJECT_CLASS (parole_file_parent_class)->finalize (object);
 
90
}
 
91
 
 
92
static void
 
93
parole_file_set_property (GObject *object, guint prop_id, 
 
94
                              const GValue *value, GParamSpec *pspec)
 
95
{
 
96
    ParoleFile *file;
 
97
    file = PAROLE_FILE (object);
 
98
    
 
99
    switch (prop_id)
 
100
    {
 
101
        case PROP_PATH:
 
102
            PAROLE_FILE_GET_PRIVATE (file)->filename = g_value_dup_string (value);
 
103
            break;
 
104
        case PROP_DISPLAY_NAME:
 
105
            PAROLE_FILE_GET_PRIVATE (file)->display_name = g_value_dup_string (value);
 
106
            break;
 
107
        case PROP_DIRECTORY:
 
108
                PAROLE_FILE_GET_PRIVATE (file)->directory = g_value_dup_string (value);
 
109
                break;
 
110
        default:
 
111
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
112
            break;
 
113
    }
 
114
}
 
115
 
 
116
static void
 
117
parole_file_get_property (GObject *object, guint prop_id, 
 
118
                              GValue *value, GParamSpec *pspec)
 
119
{
 
120
    ParoleFile *file;
 
121
 
 
122
    file = PAROLE_FILE (object);
 
123
    
 
124
    switch (prop_id)
 
125
    {
 
126
        case PROP_PATH:
 
127
            g_value_set_string (value, PAROLE_FILE_GET_PRIVATE (file)->filename);
 
128
            break;
 
129
        case PROP_URI:
 
130
            g_value_set_string (value, PAROLE_FILE_GET_PRIVATE (file)->filename);
 
131
            break;
 
132
        case PROP_CONTENT_TYPE:
 
133
            g_value_set_string (value, PAROLE_FILE_GET_PRIVATE (file)->content_type);
 
134
            break;
 
135
        case PROP_DISPLAY_NAME:
 
136
            g_value_set_string (value, PAROLE_FILE_GET_PRIVATE (file)->display_name);
 
137
            break;
 
138
        case PROP_DIRECTORY:
 
139
            g_value_set_string (value, PAROLE_FILE_GET_PRIVATE (file)->directory);
 
140
            break;
 
141
        default:
 
142
            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
143
            break;
 
144
    }
 
145
}
 
146
 
 
147
static void
 
148
parole_file_constructed (GObject *object)
 
149
{
 
150
    GFile *gfile;
 
151
    GFileInfo *info;
 
152
    ParoleFile *file;
 
153
    ParoleFilePrivate *priv;
 
154
    GError *error = NULL;
 
155
    
 
156
    file = PAROLE_FILE (object);
 
157
    priv = PAROLE_FILE_GET_PRIVATE (file);
 
158
    
 
159
    gfile = g_file_new_for_commandline_arg (priv->filename);
 
160
 
 
161
    info = g_file_query_info (gfile, 
 
162
                              "standard::*,",
 
163
                              0,
 
164
                              NULL,
 
165
                              &error);
 
166
                                  
 
167
                
 
168
        priv->directory = g_file_get_path (g_file_get_parent( gfile ));
 
169
 
 
170
    if ( error )
 
171
    {
 
172
        if ( G_LIKELY (error->code == G_IO_ERROR_NOT_SUPPORTED) )
 
173
        {
 
174
            g_error_free (error);
 
175
            if ( !priv->display_name )
 
176
                priv->display_name = g_file_get_basename (gfile);
 
177
        }
 
178
        else
 
179
        {
 
180
            if ( !priv->display_name )
 
181
                priv->display_name = g_strdup (priv->filename);
 
182
            g_warning ("Unable to read file info %s", error->message);
 
183
        }
 
184
        goto out;
 
185
    }
 
186
#ifdef HAVE_TAGLIBC
 
187
    else
 
188
    {
 
189
        TagLib_File *tag_file;
 
190
        TagLib_Tag *tag;
 
191
        gchar *title;
 
192
        gchar *title_s;
 
193
        
 
194
        tag_file = taglib_file_new (priv->filename);
 
195
        
 
196
        if ( tag_file )
 
197
        {
 
198
            tag = taglib_file_tag (tag_file);
 
199
            if ( tag )
 
200
            {
 
201
                title = taglib_tag_title (tag);
 
202
            
 
203
                if ( title )
 
204
                {
 
205
                    title_s = g_strstrip (title);
 
206
                    if ( strlen (title_s ) )
 
207
                    {
 
208
                        priv->display_name = g_strdup (title_s);
 
209
                    }
 
210
                }
 
211
                    
 
212
                taglib_tag_free_strings ();
 
213
            }
 
214
            taglib_file_free (tag_file);
 
215
        }
 
216
    }
 
217
#endif
 
218
 
 
219
    if (!priv->display_name)
 
220
        priv->display_name = g_strdup (g_file_info_get_display_name (info));
 
221
 
 
222
    priv->content_type = g_strdup (g_file_info_get_content_type (info));
 
223
    
 
224
    g_object_unref (info);
 
225
    
 
226
out:
 
227
    priv->uri = g_file_get_uri (gfile);
 
228
    g_object_unref (gfile);
 
229
}
 
230
 
 
231
static void
 
232
parole_file_class_init (ParoleFileClass *klass)
 
233
{
 
234
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
235
 
 
236
    object_class->finalize = parole_file_finalize;
 
237
    
 
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;
 
241
 
 
242
    /**
 
243
     * ParoleFile:filename:
 
244
     * 
 
245
     * The file name of the file.
 
246
     * 
 
247
     * Since: 0.2 
 
248
     **/
 
249
    g_object_class_install_property (object_class,
 
250
                                     PROP_PATH,
 
251
                                     g_param_spec_string ("filename",
 
252
                                                          "File name", 
 
253
                                                          "The file name",
 
254
                                                          NULL,
 
255
                                                          G_PARAM_CONSTRUCT_ONLY|
 
256
                                                          G_PARAM_READWRITE));
 
257
 
 
258
    /**
 
259
     * ParoleFile:display-name:
 
260
     * 
 
261
     * A UTF-8 name that can be displayed in the UI.
 
262
     * 
 
263
     * Since: 0.2 
 
264
     **/
 
265
    g_object_class_install_property (object_class,
 
266
                                     PROP_DISPLAY_NAME,
 
267
                                     g_param_spec_string ("display-name",
 
268
                                                          "Display name", 
 
269
                                                          "A UTF-8 name that can be displayed in the UI",
 
270
                                                          NULL,
 
271
                                                          G_PARAM_CONSTRUCT_ONLY|
 
272
                                                          G_PARAM_READWRITE));
 
273
 
 
274
    /**
 
275
     * ParoleFile:uri:
 
276
     * 
 
277
     * The uri of the file.
 
278
     * 
 
279
     * Since: 0.2 
 
280
     **/
 
281
    g_object_class_install_property (object_class,
 
282
                                     PROP_URI,
 
283
                                     g_param_spec_string ("uri",
 
284
                                                          "Uri", 
 
285
                                                          "The uri of the file",
 
286
                                                          NULL,
 
287
                                                          G_PARAM_READABLE));
 
288
 
 
289
    /**
 
290
     * ParoleFile:content-type:
 
291
     * 
 
292
     * The content type of the file.
 
293
     * 
 
294
     * Since: 0.2 
 
295
     **/
 
296
    g_object_class_install_property (object_class,
 
297
                                     PROP_CONTENT_TYPE,
 
298
                                     g_param_spec_string ("content-type",
 
299
                                                          "Content type", 
 
300
                                                          "The content type of the file",
 
301
                                                          NULL,
 
302
                                                          G_PARAM_READABLE));
 
303
                                                          
 
304
        /**
 
305
     * ParoleFile:directory:
 
306
     * 
 
307
     * The parent directory of the file.
 
308
     * 
 
309
     * Since: 0.2 
 
310
     **/
 
311
    g_object_class_install_property (object_class,
 
312
                                     PROP_DIRECTORY,
 
313
                                     g_param_spec_string ("directory",
 
314
                                                          "Parent directory", 
 
315
                                                          "The parent directory of the file",
 
316
                                                          NULL,
 
317
                                                          G_PARAM_CONSTRUCT_ONLY|
 
318
                                                          G_PARAM_READWRITE));
 
319
 
 
320
    g_type_class_add_private (klass, sizeof (ParoleFilePrivate));
 
321
}
 
322
 
 
323
static void
 
324
parole_file_init (ParoleFile *file)
 
325
{
 
326
    ParoleFilePrivate *priv;
 
327
    
 
328
    priv = PAROLE_FILE_GET_PRIVATE (file);
 
329
 
 
330
    priv->filename         = NULL;
 
331
    priv->display_name = NULL;
 
332
    priv->uri          = NULL;
 
333
    priv->content_type    = NULL;
 
334
        priv->directory                 = NULL;
 
335
}
 
336
 
 
337
/**
 
338
 * parole_file_new:
 
339
 * @filename: filename.
 
340
 * 
 
341
 * 
 
342
 * 
 
343
 * Returns: A new #ParoleFile object.
 
344
 * 
 
345
 * Since: 0.2
 
346
 **/
 
347
ParoleFile *
 
348
parole_file_new (const gchar *filename)
 
349
{
 
350
    ParoleFile *file = NULL;
 
351
    file = g_object_new (PAROLE_TYPE_FILE, "filename", filename, NULL);
 
352
    return file;
 
353
}
 
354
 
 
355
/**
 
356
 * parole_file_new_with_display_name:
 
357
 * @filename: filename.
 
358
 * 
 
359
 * 
 
360
 * 
 
361
 * Returns: A new #ParoleFile object.
 
362
 * 
 
363
 * Since: 0.2
 
364
 **/
 
365
ParoleFile *
 
366
parole_file_new_with_display_name (const gchar *filename, const gchar *display_name)
 
367
{
 
368
    ParoleFile *file = NULL;
 
369
    file = g_object_new (PAROLE_TYPE_FILE, 
 
370
                         "filename", filename, 
 
371
                         "display-name", display_name, 
 
372
                         NULL);
 
373
    return file;
 
374
}
 
375
 
 
376
/**
 
377
 * parole_file_get_file_name:
 
378
 * @file: a #ParoleFile.
 
379
 *  
 
380
 * 
 
381
 * Returns: A string containing the file name.
 
382
 * 
 
383
 * Since: 0.2
 
384
 **/
 
385
const gchar *
 
386
parole_file_get_file_name (const ParoleFile *file)
 
387
{
 
388
    g_return_val_if_fail (PAROLE_IS_FILE (file), NULL);
 
389
    
 
390
    return PAROLE_FILE_GET_PRIVATE (file)->filename;
 
391
}
 
392
 
 
393
/**
 
394
 * parole_file_get_display_name:
 
395
 * @file: a #ParoleFile.
 
396
 *  
 
397
 * 
 
398
 * Returns: A string containing the display name.
 
399
 * 
 
400
 * Since: 0.2
 
401
 **/
 
402
const gchar *
 
403
parole_file_get_display_name (const ParoleFile *file)
 
404
{
 
405
    g_return_val_if_fail (PAROLE_IS_FILE (file), NULL);
 
406
    
 
407
    return PAROLE_FILE_GET_PRIVATE (file)->display_name;
 
408
}
 
409
 
 
410
/**
 
411
 * parole_file_get_uri:
 
412
 * @file: a #ParoleFile.
 
413
 *  
 
414
 * 
 
415
 * Returns: A string containing the file uri.
 
416
 * 
 
417
 * Since: 0.2
 
418
 **/
 
419
const gchar *
 
420
parole_file_get_uri (const ParoleFile *file)
 
421
{
 
422
    g_return_val_if_fail (PAROLE_IS_FILE (file), NULL);
 
423
    
 
424
    return PAROLE_FILE_GET_PRIVATE (file)->uri;
 
425
}
 
426
 
 
427
/**
 
428
 * parole_file_get_content_type:
 
429
 * @file: a #ParoleFile.
 
430
 *  
 
431
 * 
 
432
 * Returns: A string containing the content type of the file.
 
433
 * 
 
434
 * Since: 0.2
 
435
 **/
 
436
const gchar *
 
437
parole_file_get_content_type (const ParoleFile *file) 
 
438
{
 
439
    g_return_val_if_fail (PAROLE_IS_FILE (file), NULL);
 
440
    
 
441
    return PAROLE_FILE_GET_PRIVATE (file)->content_type;
 
442
}
 
443
 
 
444
/**
 
445
 * parole_file_get_directory:
 
446
 * @file: a #ParoleFile.
 
447
 *  
 
448
 * 
 
449
 * Returns: A string containing the parent directory path.
 
450
 * 
 
451
 * Since: 0.2
 
452
 **/
 
453
const gchar *
 
454
parole_file_get_directory (const ParoleFile *file)
 
455
{
 
456
    g_return_val_if_fail (PAROLE_IS_FILE (file), NULL);
 
457
    
 
458
    return PAROLE_FILE_GET_PRIVATE (file)->directory;
 
459
}