Source

dr1000-hackx / ctb / src / filetypes.c

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
/*
 * File Name: filetypes.c
 */

/*
 * This file is part of ctb.
 *
 * ctb is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * ctb is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
 
/**
 * Copyright (C) 2008 iRex Technologies B.V.
 * All rights reserved.
 */

//----------------------------------------------------------------------------
// Include Files
//----------------------------------------------------------------------------

#include "config.h"

#include <gconf/gconf-client.h>
#include <gdk/gdk.h>
#include <glib.h>
#include <string.h>

#include "ctb_log.h"
#include "filetypes.h"
#include "i18n.h"


//----------------------------------------------------------------------------
// Type Declarations
//----------------------------------------------------------------------------

typedef struct
        {
            gchar       *extension;             // file extension excluding the '.'
            gchar       *reference_ext;         // extension from which to use this details
            gboolean    is_directory;           // extension used for directory or file
            gchar       *icon_name;             // name of the icon, also used for bitmap filename
            gchar       *description;           // type description for this extension
            gchar       *viewer_cmd;            // command to start the corresponding viewer application
            GdkPixbuf   *pixbuf_icon    [N_FILEMODEL_THUMB_SIZES];  // cache for bitmaps loaded from icon files
            gboolean    generate_thumbnail;     // set to generate thumbnails for this filetype
        } filetype_info_t;


//----------------------------------------------------------------------------
// Constants
//----------------------------------------------------------------------------

static const gchar      *ICONS_DIRECTORY = DATADIR;
static const gchar      *ICONFILE_PREFIX = "icon-";
static const gchar      *ICONFILE_POSTFIX[ N_FILEMODEL_THUMB_SIZES ] =
                        {
                            "-mini.png",
                            "-small.png",
                            "-medium.png",
                            "-large.png"
                        };

static const gchar      *ICONNAME_APPLICATION = "application";
static const gchar      *ICONNAME_LIBRARY     = "sdcard";

#define CTB_GCONF_PATH  "/apps/er/sys/ctb"
#define REGKEY_SHOW_SDCARD  "show_sdcard"
static const gchar      *REGKEY_FILETYPE_DIR = CTB_GCONF_PATH "/filetypes";
static const gchar      *REGKEY_ALTTYPE_DIR  = CTB_GCONF_PATH "/alternatives";

// known filetypes
static filetype_info_t  g_hardcoded_filetypes[] =
            {
                // ext                      ref   is_dir icon_name  description     viewer_cmd icon thumb
                { ""                      , NULL, TRUE , "folder",  N_("Folder"),   NULL,      {}, FALSE },
                { ""                      , NULL, FALSE, "unknown", N_("Unknown"),  NULL,      {}, FALSE },
                { FILE_EXT_SHORTCUT       , NULL, FALSE, "unknown", N_("Shortcut"), NULL,      {}, FALSE },
                { FILE_EXT_SHORTCUT_TO_DIR, NULL, FALSE, "folder",  N_("Shortcut"), NULL,      {}, FALSE },
                { NULL,                     NULL, FALSE, NULL,      NULL,           NULL,      {}, FALSE },
            };

#define GCONF_BUFFER_SIZE                   128

//----------------------------------------------------------------------------
// Static Variables
//----------------------------------------------------------------------------

static GArray           *g_filetype_info = NULL;    // element: filetype_info_t*
static GArray           *g_alttype_info = NULL;     // element: alttype_info_t*
static GTree            *g_icon_cache = NULL;
static GConfClient      *g_gconfclient = NULL;
static gboolean         g_showdir = FALSE;


//============================================================================
// Local Function Definitions
//============================================================================

static filetype_info_t* find_filetype_info(const gchar    *file_ext,
                                           const gboolean is_directory,
                                           const gboolean with_default );

//============================================================================
// Functions Implementation
//============================================================================

static gchar *read_gconf_value(const gchar *dir,
                               const gchar *key,
                               GConfClient *client)
{
    gchar buffer[GCONF_BUFFER_SIZE];
    gchar* value;
    g_assert(strlen(dir) + 1 + strlen(key) < GCONF_BUFFER_SIZE);
    snprintf(buffer, GCONF_BUFFER_SIZE-1, "%s/%s", dir, key);
    value = gconf_client_get_string(client, buffer, NULL);
    if (value == NULL) {
        ERRORPRINTF("gconf: cannot read %s", buffer);
    }
    return value;
}


static gboolean read_gconf_boolean(const gchar *dir,
                                   const gchar *key,
                                   GConfClient *client)
{
    gboolean value = FALSE;
    gchar buffer[GCONF_BUFFER_SIZE];
    g_assert(strlen(dir) + 1 + strlen(key) < GCONF_BUFFER_SIZE);
    snprintf(buffer, GCONF_BUFFER_SIZE-1, "%s/%s", dir, key);

    value = gconf_client_get_bool(client, buffer, NULL);
    return value;
}


static void add_filetype_from_gconf(const gchar *dir,
        GConfClient *client)
{
    gchar buffer[GCONF_BUFFER_SIZE];
    gchar *descr = NULL;
    gchar *viewer_cmd = NULL;
    gchar *icon_name = NULL;
    gchar *reference_ext = NULL;
    GSList *ext = NULL;
    gboolean generate_thumbnail = FALSE;

    descr = read_gconf_value(dir, "descr", client);
    if (!descr) goto out_error;

    viewer_cmd = read_gconf_value(dir, "viewer_cmd", client);
    if (!viewer_cmd) goto out_error;

    icon_name = read_gconf_value(dir, "icon_name", client);
    if (!icon_name) goto out_error;

    generate_thumbnail = read_gconf_boolean(dir, "generate_thumbnail", client);

    g_assert(strlen(dir) + strlen("/extensions") < GCONF_BUFFER_SIZE);
    snprintf(buffer, GCONF_BUFFER_SIZE-1, "%s/extensions", dir);
    GSList *extensions = gconf_client_get_list(client, buffer, GCONF_VALUE_STRING, NULL);
    if (extensions == NULL) {
        ERRORPRINTF("gconf: cannot read %s", buffer);
        goto out_error;
    }

    for (ext = extensions; ext; ext = g_slist_next(ext)) {
        if (find_filetype_info(ext->data, FALSE, FALSE) != NULL) {
            ERRORPRINTF("gconf: ext %s is already registered, skipping", (gchar*)ext->data);
            continue;
        }

        filetype_info_t newtype;
        memset(&newtype, 0x00, sizeof(newtype));
        newtype.extension          = g_strdup(ext->data);
        newtype.reference_ext      = g_strdup(reference_ext);
        newtype.is_directory       = FALSE;
        newtype.icon_name          = g_strdup(icon_name);
        newtype.description        = g_strdup(descr);
        newtype.viewer_cmd         = g_strdup(viewer_cmd);
        newtype.generate_thumbnail = generate_thumbnail;
        g_array_append_val(g_filetype_info, newtype);

        if (reference_ext == NULL) reference_ext = ext->data;
    }
    g_slist_foreach (extensions, (GFunc)g_free, NULL);
    g_slist_free(extensions);
out_error:
    g_free(icon_name);
    g_free(viewer_cmd);
    g_free(descr);
}


static void add_filetypes_from_gconf()
{
    GSList *types = NULL;
    GConfClient *client = gconf_client_get_default();

    gboolean exists = gconf_client_dir_exists(client, REGKEY_FILETYPE_DIR, NULL);
    if (exists == FALSE) {
        ERRORPRINTF("gconf: %s does not exist", REGKEY_FILETYPE_DIR);
        goto unref;
    }

    types = gconf_client_all_dirs(client, REGKEY_FILETYPE_DIR, NULL);
    if (types == NULL) {
        ERRORPRINTF("gconf: cannot read dir entries of %s", REGKEY_FILETYPE_DIR);
        goto unref;
    }

    g_slist_foreach (types, (GFunc)add_filetype_from_gconf, client);
    g_slist_foreach (types, (GFunc)g_free, NULL);
    g_slist_free(types);
unref:
    g_object_unref(client);
}


static void add_alttype_from_gconf(const gchar *dir,
        GConfClient *client)
{
    gchar buffer[GCONF_BUFFER_SIZE];
    gchar *descr = NULL;
    gchar *viewer_cmd = NULL;
    gchar *icon_name = NULL;
    GSList *ext = NULL;

    descr = read_gconf_value(dir, "descr", client);
    if (!descr) goto out_error;

    viewer_cmd = read_gconf_value(dir, "viewer_cmd", client);
    if (!viewer_cmd) goto out_error;

    icon_name = read_gconf_value(dir, "icon_name", client);
    if (!icon_name) goto out_error;

    g_assert(strlen(dir) + strlen("/extensions") < GCONF_BUFFER_SIZE);
    snprintf(buffer, GCONF_BUFFER_SIZE-1, "%s/extensions", dir);
    GSList *extensions = gconf_client_get_list(client, buffer, GCONF_VALUE_STRING, NULL);
    if (extensions == NULL) {
        ERRORPRINTF("gconf: cannot read %s", buffer);
        goto out_error;
    }

    for (ext = extensions; ext; ext = g_slist_next(ext)) {
        alttype_info_t newtype;
        memset(&newtype, 0x00, sizeof(newtype));
        newtype.extension          = g_strdup(ext->data);
        newtype.icon_name          = g_strdup(icon_name);
        newtype.description        = g_strdup(descr);
        newtype.viewer_cmd         = g_strdup(viewer_cmd);
        newtype.next               = NULL;
        // check if there is already a list for the extension
        alttype_info_t *parent = filetypes_find_alttype_info(newtype.extension);
        
        LOGPRINTF("New item: 0x%x", (int)&newtype);
        if (parent)
        {
            // extension already found, adding to list
            // TODO: add at end, so it is always clear in which order the items appear
            //       or sort on description??

            // need to create a copy
            alttype_info_t *p_newtype = g_memdup(&newtype, sizeof(alttype_info_t) );
            LOGPRINTF("Adding to list[0x%x]:%s-%s", (int)parent, p_newtype->extension, p_newtype->description);
            p_newtype->next = parent->next;
            parent->next = p_newtype;
        }
        else
        {
            LOGPRINTF("Adding to array:%s-%s", newtype.extension, newtype.description);
            g_array_append_val(g_alttype_info, newtype);
        }
    }
    g_slist_foreach (extensions, (GFunc)g_free, NULL);
    g_slist_free(extensions);
out_error:
    g_free(icon_name);
    g_free(viewer_cmd);
    g_free(descr);
}


static void add_alttypes_from_gconf()
{
    GSList *types = NULL;
    GConfClient *client = gconf_client_get_default();

    LOGPRINTF("STARTED");
    gboolean exists = gconf_client_dir_exists(client, REGKEY_ALTTYPE_DIR, NULL);
    if (exists == FALSE) {
        ERRORPRINTF("gconf: %s does not exist", REGKEY_ALTTYPE_DIR);
        goto unref;
    }

    types = gconf_client_all_dirs(client, REGKEY_ALTTYPE_DIR, NULL);
    if (types == NULL) {
        ERRORPRINTF("gconf: cannot read dir entries of %s", REGKEY_ALTTYPE_DIR);
        goto unref;
    }

    g_slist_foreach (types, (GFunc)add_alttype_from_gconf, client);
    g_slist_foreach (types, (GFunc)g_free, NULL);
    g_slist_free(types);
unref:
    g_object_unref(client);
}


static void add_hardcoded_filetypes()
{
    filetype_info_t   *known_type = NULL;
    filetype_info_t   details;

    // fill array with hardcoded filetypes
    for ( known_type = g_hardcoded_filetypes ; known_type->extension ; known_type++ )
    {
        // set details
        memset(&details, 0x00, sizeof(details));
        details.extension       = g_strdup(known_type->extension     );
        details.reference_ext   = g_strdup(known_type->reference_ext );
        details.is_directory    = known_type->is_directory;
        details.icon_name       = g_strdup(known_type->icon_name     );
        details.description     = g_strdup(known_type->description   );
        details.viewer_cmd      = g_strdup(known_type->viewer_cmd    );

        // add to array
        g_array_append_val(g_filetype_info, details);
    }
}


static void on_gconf_key_changed(GConfClient *client,
                                 guint cnxn_id,
                                 GConfEntry *entry,
                                 gpointer user_data)
{
    const gchar* key = gconf_entry_get_key(entry);
    if (strcmp(key, CTB_GCONF_PATH"/"REGKEY_SHOW_SDCARD) == 0) {
        const GConfValue* value = gconf_entry_get_value(entry);
        gboolean show = gconf_value_get_bool(value);
        g_showdir = show;
    }
}


void filetypes_init ( gboolean watch )
{
    g_filetype_info = g_array_new( TRUE, TRUE, sizeof(filetype_info_t) );
    g_assert(g_filetype_info);

    add_hardcoded_filetypes();
    add_filetypes_from_gconf();

    g_alttype_info = g_array_new( TRUE, TRUE, sizeof(alttype_info_t) );
    g_assert(g_alttype_info);

    add_alttypes_from_gconf();

    if (watch) {
        g_gconfclient = gconf_client_get_default();
        g_assert(g_gconfclient);
        g_showdir = read_gconf_boolean(CTB_GCONF_PATH, REGKEY_SHOW_SDCARD, g_gconfclient);

        gconf_client_add_dir(g_gconfclient,
                             CTB_GCONF_PATH,
                             GCONF_CLIENT_PRELOAD_NONE,
                             NULL);

        gconf_client_notify_add(g_gconfclient,
                                CTB_GCONF_PATH,
                                on_gconf_key_changed,
                                NULL,
                                NULL,
                                NULL);
    }
}


gboolean filetypes_showdir()
{
    return g_showdir;
}


static filetype_info_t* find_filetype_info (const gchar *file_ext,
                                            const gboolean is_directory,
                                            const gboolean with_default )
{

    g_assert(g_filetype_info);

//    LOGPRINTF("file_ext [%s] is_dir [%d]", file_ext, is_directory);
    if (file_ext == NULL)
    {
        file_ext = "";
    }

    gboolean done  = FALSE;
    gboolean found = FALSE;
    filetype_info_t *ret = NULL;
    while ( !done )
    {
        filetype_info_t *details = (filetype_info_t*) g_filetype_info->data;
        while (details->extension)
        {
            if (details->is_directory == is_directory 
                 && g_ascii_strcasecmp( details->extension, file_ext ) == 0 )
            {
                ret = details;
                found = TRUE;
                break;
            }
            else
            {
                details++;
            }
        }

        if ( found )
        {
            gchar *ref_ext = details->reference_ext;
//            LOGPRINTF( "found filetype [%s] ref [%s] icon_name [%s] descr [%s]",
//                    file_ext, ref_ext, details->icon_name, details->description );
            if (ref_ext)
            {
                return find_filetype_info( ref_ext, is_directory, with_default );
            }
            done = TRUE;
        }
        else if (*file_ext)
        {
            LOGPRINTF("unkown filetype [%s] is_dir [%d]", file_ext, is_directory);
            if (with_default)
            {
                file_ext = "";
            }
            else
            {
                done = TRUE;
            }
        }
        else
        {
            ERRORPRINTF("no default fileinfo for is_dir [%d]", is_directory);
            done = TRUE;
        }
    }

    return ret;
}


alttype_info_t* filetypes_find_alttype_info (const gchar *file_ext )
{

    g_assert(g_alttype_info);

    LOGPRINTF("file_ext [%s]", file_ext);
    if (file_ext == NULL)
    {
        file_ext = "";
    }

    alttype_info_t *ret = NULL;
    alttype_info_t *details = (alttype_info_t*) g_alttype_info->data;
    while (details->extension)
    {
        if (g_ascii_strcasecmp( details->extension, file_ext ) == 0 )
        {
            ret = details;
            break;
        }
        else
        {
            details++;
        }
    }

    return ret;
}


GdkPixbuf* get_icon_from_file_extension (const gchar                *file_ext,
                                         const gboolean              is_directory,
                                         const filemodel_thumbsize_t icon_size     )
{
    GdkPixbuf *icon               = NULL;

    filetype_info_t *details = find_filetype_info(file_ext, is_directory, TRUE);
    if (details)
    {
        // get normal icon
        GdkPixbuf **p_pixbuf_icon = &(details->pixbuf_icon[icon_size]);
        icon = *p_pixbuf_icon;
        if (icon == NULL)
        {
            // load filetype icon from file
            gchar* icon_file = g_strdup_printf( "%s/%s%s%s",
                    ICONS_DIRECTORY,
                    ICONFILE_PREFIX,
                    details->icon_name,
                    ICONFILE_POSTFIX[icon_size] );
            GError *err = NULL;
            icon = gdk_pixbuf_new_from_file( icon_file, &err );
            if (icon) *p_pixbuf_icon = icon;
            else
            {
                ERRORPRINTF("cannot load iconfile [%s] error [%s]", icon_file, err->message);
                g_clear_error(&err);
            }
            g_free(icon_file);
        }
    }
    return icon;
}


GdkPixbuf* get_icon_application ( const filemodel_thumbsize_t icon_size)
{
    return get_icon_from_file(ICONNAME_APPLICATION, icon_size);
}


GdkPixbuf* get_icon_library ( const filemodel_thumbsize_t icon_size)
{
    return get_icon_from_file(ICONNAME_LIBRARY, icon_size);
}


GdkPixbuf* get_icon_delete_toggle(gboolean toggled, filemodel_thumbsize_t icon_size)
{
    if (toggled) {
        return get_icon_from_file("delete-toggled", icon_size);
    } else {
        return get_icon_from_file("delete-untoggled", icon_size);
    }
}

gint compareString(gconstpointer a, gconstpointer b) {
    return strcmp((const gchar*)a, (const gchar*)b);
}


GdkPixbuf* get_icon_from_file(const gchar* icon_name, filemodel_thumbsize_t icon_size)
{
    if (g_icon_cache == NULL) g_icon_cache = g_tree_new(compareString);

    g_assert(icon_name && *icon_name);
    gchar icon_file[256];
    snprintf(icon_file, 255, "%s/%s%s%s",
                                 ICONS_DIRECTORY,
                                 ICONFILE_PREFIX,
                                 icon_name,
                                 ICONFILE_POSTFIX[icon_size]);
    int len = strlen(ICONS_DIRECTORY) + strlen(ICONFILE_PREFIX) + 1;
    gchar* short_name = icon_file + len;
    gpointer cache = g_tree_lookup(g_icon_cache, short_name);
    GdkPixbuf *icon = NULL;
    if (cache) {
        icon = (GdkPixbuf *)cache;
    } else {
        GError *err = NULL;
        icon = gdk_pixbuf_new_from_file(icon_file, &err);
        if (icon) {
            g_tree_insert(g_icon_cache, g_strdup(short_name), icon);
        } else  {
            ERRORPRINTF("cannot load iconfile [%s] error [%s]", icon_file, err->message);
            g_clear_error(&err);
        }
    }
    return icon;
}


static void apply_icon_overlay ( const filemodel_thumbsize_t icon_size,
                                 GdkPixbuf *icon,
                                 const gchar *overlay_name)
{
    if (icon == NULL) return;

    GdkPixbuf *overlay = get_icon_from_file(overlay_name, icon_size);

    // apply overlay to icon bitmap
    if (overlay)
    {
        gdk_pixbuf_composite( overlay,                      // src
                              icon,                         // dest
                              0, 0,                         // dest x, y
                              gdk_pixbuf_get_width(icon),   // dest width
                              gdk_pixbuf_get_height(icon),  // dest height
                              0.0, 0.0,                     // offset x, y
                              1.0, 1.0,                     // scale  x, y
                              GDK_INTERP_NEAREST,           // interpolation type: not needed, take the fastest
                              0xFF );                       // overall_alpha
    }
}


void apply_icon_overlay_shortcut ( const filemodel_thumbsize_t icon_size,
                                         GdkPixbuf             *icon     )
{
    apply_icon_overlay( icon_size, icon, "overlay-shortcut");
}


void apply_icon_overlay_delete ( const filemodel_thumbsize_t icon_size,
                                 GdkPixbuf             *icon,
                                 gboolean toggled)
{
    if (toggled)
        apply_icon_overlay( icon_size, icon, "overlay-delete-toggled");
    else
        apply_icon_overlay( icon_size, icon, "overlay-delete-untoggled");
}


const gchar* get_type_descr_from_file_extension ( const gchar    *file_ext,
                                                  const gboolean is_directory)
{
    filetype_info_t *details = find_filetype_info(file_ext, is_directory, TRUE);

    const gchar *description = "";
    if (details)
    {
        if (details->description)
        {
            description = _( details->description );
        }
        else
        {
            ERRORPRINTF( "filetype [%s] is_dir [%d] has no description",
                         details->description, is_directory);
        }
    }

    return description;
}


gboolean is_drz_file_extension(const gchar *file_ext)
{
    if ( strcmp( file_ext, FILE_EXT_DRZ ) == 0 )
    {
        return TRUE;
    }
    return FALSE;
}


gboolean is_shortcut_file_extension(const gchar *file_ext)
{
    if (   strcmp( file_ext, FILE_EXT_SHORTCUT       ) == 0
        || strcmp( file_ext, FILE_EXT_SHORTCUT_TO_DIR) == 0 )
    {
        return TRUE;
    }
    return FALSE;
}


gboolean is_shortcut_file(const char* filename)
{
    const char* ext = g_extension_pointer(filename);
    return is_shortcut_file_extension(ext);
}


// get viewer command for specified file extension
const gchar* get_viewer_from_file_extension ( const gchar *file_ext )
{
    filetype_info_t *details = find_filetype_info(file_ext, FALSE, FALSE);

    const gchar *viewer_cmd = (details) ?  details->viewer_cmd : NULL;
    return viewer_cmd;
}


gboolean get_generate_thumbnail ( const gchar *file_ext )
{
    filetype_info_t *details = find_filetype_info(file_ext, FALSE, FALSE);
    return details->generate_thumbnail;
}



// copied from libgnome-2.6.1.1 gnome-util.c:
/**
 * g_extension_pointer:
 * @path: A filename or file path.
 *
 * Extracts the extension from the end of a filename (the part after the final
 * '.' in the filename).
 *
 * Returns: A pointer to the extension part of the filename, or a
 * pointer to the end of the string if the filename does not
 * have an extension.
 */
const char *
g_extension_pointer (const char * path)
{
	char * s;

	g_return_val_if_fail(path != NULL, NULL);

	/* get the dot in the last element of the path */
	char *t = strrchr(path, G_DIR_SEPARATOR);
	if (t != NULL)
		s = strrchr(t, '.');
	else
		s = strrchr(path, '.');

	if (s == NULL)
		return path + strlen(path); /* There is no extension. */
	else {
		++s;      /* pass the . */
		return s;
	}
}