2
* list-entry.c -- Simple data structure to hold name, data and icon.
4
* Copyright (C) 2007-2008 Johannes H. Jensen <joh@pseudoberries.com>
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (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.
21
* Johannes H. Jensen <joh@pseudoberries.com>
27
#include <libgnomevfs/gnome-vfs.h>
28
#include <libgnomeui/libgnomeui.h>
30
#include "list-entry.h"
34
* Creates a new AlarmListEntry.
37
alarm_list_entry_new (const gchar *name, const gchar *data, const gchar *icon)
39
AlarmListEntry *entry;
41
entry = g_new (AlarmListEntry, 1);
48
entry->name = g_strdup (name);
50
entry->data = g_strdup (data);
52
entry->icon = g_strdup (icon);
58
alarm_list_entry_free (AlarmListEntry *e)
67
alarm_list_entry_new_file (const gchar *uri, GnomeVFSResult *ret, gchar **mime_ret)
69
AlarmListEntry *entry;
70
GnomeVFSResult result;
71
GnomeVFSFileInfo *info;
72
GtkIconTheme *theme = NULL;
74
if (!gnome_vfs_initialized())
77
if (gtk_init_check (NULL, NULL))
78
theme = gtk_icon_theme_get_default ();
80
g_warning ("gtk_init_check failed, icon lookup disabled.");
82
info = gnome_vfs_file_info_new ();
84
result = gnome_vfs_get_file_info (uri, info,
85
GNOME_VFS_FILE_INFO_GET_MIME_TYPE | GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
90
if (result != GNOME_VFS_OK) {
91
g_warning ("Could not open uri: %s", uri);
95
entry = g_new (AlarmListEntry, 1);
96
entry->data = g_strdup (uri);
97
entry->name = to_basename (info->name);
100
entry->icon = gnome_icon_lookup(theme, NULL,
101
entry->data, NULL, info,
102
info->mime_type, 0, 0);
104
if (mime_ret != NULL)
105
*mime_ret = g_strdup (info->mime_type);
107
gnome_vfs_file_info_unref (info);
113
alarm_list_entry_list_new (const gchar *dir_uri, const gchar *supported_types[])
115
GnomeVFSResult result;
116
GnomeVFSFileInfoOptions options;
117
GnomeVFSFileInfo *info;
121
GList *list, *l, *flist;
122
AlarmListEntry *entry;
127
if (!gnome_vfs_initialized())
130
if (gtk_init_check (NULL, NULL))
131
theme = gtk_icon_theme_get_default ();
133
g_warning ("gtk_init_check failed, icon lookup disabled.");
135
options = GNOME_VFS_FILE_INFO_GET_MIME_TYPE | GNOME_VFS_FILE_INFO_FOLLOW_LINKS;
137
result = gnome_vfs_directory_list_load (&list, dir_uri, options);
139
if (result != GNOME_VFS_OK) {
140
g_critical ("Could not open directory: %s", dir_uri);
144
g_debug ("Loading files in %s ...", dir_uri);
148
for (l = list; l; l = l->next) {
150
//g_debug ("-- %s", info->name);
151
if (info->type == GNOME_VFS_FILE_TYPE_REGULAR) {
152
mime = gnome_vfs_file_info_get_mime_type(info);
153
//g_debug (" [ regular file: MIME: %s ]", mime);
156
if (supported_types != NULL) {
158
for (i = 0; supported_types[i] != NULL; i++) {
159
if (strstr (mime, supported_types[i]) != NULL) {
161
//g_debug (" [ MATCH ]");
169
entry = g_new (AlarmListEntry, 1);
170
entry->data = g_strdup_printf ("%s/%s", dir_uri, info->name);
171
entry->name = to_basename (info->name);
175
entry->icon = gnome_icon_lookup(theme, NULL,
176
entry->data, NULL, info,
179
//g_debug ("Icon found: %s", entry->icon);
180
flist = g_list_append (flist, entry);
185
gnome_vfs_file_info_list_free (list);
191
alarm_list_entry_list_free (GList **list)
196
g_debug ("Alarm_file_entry_list_free (%p => %p)", list, *list);
199
for (l = *list; l; l = l->next) {
200
e = (AlarmListEntry *)l->data;
201
alarm_list_entry_free (e);