~ubuntu-branches/ubuntu/vivid/alarm-clock-applet/vivid

« back to all changes in this revision

Viewing changes to src/list-entry.c

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2010-03-17 09:02:44 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100317090244-ni0ye04mva2hxe10
Tags: 0.3.0-1
* New upstream release
* debian/control:
  + No change bump of Standards-Version to 3.8.4
  + Update build-deps:
    - Drop libglade, libpanel-applet, libgnomevfs2, libgnome{2,ui}
    - Add libxml2-dev and libunique-dev, intltool
* debian/patches/01_update-alarms-eta,patch:
  + Dropped, applied upstream
* debian/(alarm-clock-applet.1, alarm-clock-applet.manpages):
  + Add manpage for alarm-clock-applet, now that the binary is moved to
    /usr/bin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <string.h>
25
25
#include <glib.h>
26
26
#include <gtk/gtk.h>
27
 
#include <libgnomevfs/gnome-vfs.h>
28
 
#include <libgnomeui/libgnomeui.h>
29
27
 
30
28
#include "list-entry.h"
31
29
#include "util.h"
64
62
}
65
63
 
66
64
AlarmListEntry *
67
 
alarm_list_entry_new_file (const gchar *uri, GnomeVFSResult *ret, gchar **mime_ret)
 
65
alarm_list_entry_new_file (const gchar *uri, gchar **mime_ret, GError **error)
68
66
{
69
67
        AlarmListEntry *entry;
70
 
        GnomeVFSResult result;
71
 
        GnomeVFSFileInfo *info;
72
 
        GtkIconTheme *theme = NULL;
73
 
        
74
 
        if (!gnome_vfs_initialized())
75
 
                gnome_vfs_init();
76
 
        
77
 
        if (gtk_init_check (NULL, NULL))
78
 
                theme = gtk_icon_theme_get_default ();
79
 
        else
80
 
                g_warning ("gtk_init_check failed, icon lookup disabled.");
81
 
                
82
 
        info = gnome_vfs_file_info_new ();
83
 
        
84
 
        result = gnome_vfs_get_file_info (uri, info, 
85
 
                                GNOME_VFS_FILE_INFO_GET_MIME_TYPE | GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
86
 
        
87
 
        if (ret != NULL)
88
 
                *ret = result;
89
 
        
90
 
        if (result != GNOME_VFS_OK) {
91
 
                g_warning ("Could not open uri: %s", uri);
 
68
        GError *new_error = NULL;
 
69
        GFileInfo *info;
 
70
        GFile *file;
 
71
        
 
72
        file = g_file_new_for_uri (uri);
 
73
        info = g_file_query_info (file, "standard::content-type,standard::icon",
 
74
                                                          G_FILE_QUERY_INFO_NONE, NULL, &new_error);
 
75
        
 
76
        if (new_error != NULL) {
 
77
                //g_warning ("Could not open uri: %s", uri);
 
78
                if (error)
 
79
                        *error = new_error;
 
80
                else
 
81
                        g_error_free (new_error);
92
82
                return NULL;
93
83
        }
94
84
        
95
85
        entry = g_new (AlarmListEntry, 1);
96
86
        entry->data = g_strdup (uri);
97
 
        entry->name = to_basename (info->name);
98
 
        
99
 
        if (theme != NULL)
100
 
                entry->icon = gnome_icon_lookup(theme, NULL,
101
 
                                                                                entry->data, NULL, info,
102
 
                                                                                info->mime_type, 0, 0);
 
87
        entry->name = g_file_get_basename (file);
 
88
        entry->icon = g_icon_to_string (g_file_info_get_icon (info));
103
89
        
104
90
        if (mime_ret != NULL)
105
 
                *mime_ret = g_strdup (info->mime_type);
 
91
                *mime_ret = g_strdup (g_file_info_get_content_type (info));
106
92
        
107
 
        gnome_vfs_file_info_unref (info);
 
93
        g_object_unref (info);
 
94
        g_object_unref (file);
108
95
        
109
96
        return entry;
110
97
}
112
99
GList *
113
100
alarm_list_entry_list_new (const gchar *dir_uri, const gchar *supported_types[])
114
101
{
115
 
        GnomeVFSResult result;
116
 
        GnomeVFSFileInfoOptions options;
117
 
        GnomeVFSFileInfo *info;
118
 
        
119
 
        GtkIconTheme *theme;
120
 
        
121
 
        GList *list, *l, *flist;
 
102
        GError *error = NULL;
 
103
        GFile *dir;
 
104
        GFileEnumerator *result;
 
105
        GFileInfo *info;
 
106
        
 
107
        GList *flist;
122
108
        AlarmListEntry *entry;
123
109
        const gchar *mime;
124
110
        gboolean valid;
125
111
        gint i;
126
112
        
127
 
        if (!gnome_vfs_initialized())
128
 
                gnome_vfs_init();
129
 
        
130
 
        if (gtk_init_check (NULL, NULL))
131
 
                theme = gtk_icon_theme_get_default ();
132
 
        else
133
 
                g_warning ("gtk_init_check failed, icon lookup disabled.");
134
 
        
135
 
        options = GNOME_VFS_FILE_INFO_GET_MIME_TYPE | GNOME_VFS_FILE_INFO_FOLLOW_LINKS;
136
 
        
137
 
        result = gnome_vfs_directory_list_load (&list, dir_uri, options);
138
 
        
139
 
        if (result != GNOME_VFS_OK) {
 
113
        dir = g_file_new_for_uri (dir_uri);
 
114
        result = g_file_enumerate_children (dir,
 
115
                                                                                "standard::type,standard::content-type,"
 
116
                                                                                "standard::icon,standard::name",
 
117
                                                                                G_FILE_QUERY_INFO_NONE, NULL, &error);
 
118
        
 
119
        if (error) {
140
120
                g_critical ("Could not open directory: %s", dir_uri);
 
121
                g_error_free (error);
141
122
                return NULL;
142
123
        }
143
124
        
145
126
        
146
127
        flist = NULL;
147
128
        
148
 
        for (l = list; l; l = l->next) {
149
 
                info = l->data;
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);
 
129
        while ((info = g_file_enumerator_next_file (result, NULL, NULL))) {
 
130
                //g_debug ("-- %s", g_file_info_get_name (info));
 
131
                if (g_file_info_get_file_type (info) == G_FILE_TYPE_REGULAR) {
 
132
                        mime = g_file_info_get_content_type (info);
153
133
                        //g_debug (" [ regular file: MIME: %s ]", mime);
154
134
                        
155
135
                        valid = TRUE;
167
147
                        
168
148
                        if (valid) {
169
149
                                entry = g_new (AlarmListEntry, 1);
170
 
                                entry->data = g_strdup_printf ("%s/%s", dir_uri, info->name);
171
 
                                entry->name = to_basename (info->name);
172
 
                                
173
 
                                entry->icon = NULL;
174
 
                                if (theme != NULL)
175
 
                                        entry->icon = gnome_icon_lookup(theme, NULL,
176
 
                                                                                                        entry->data, NULL, info,
177
 
                                                                                                        mime, 0, 0);
 
150
                                entry->name = g_strdup (g_file_info_get_name (info));
 
151
                                entry->data = g_strdup_printf ("%s/%s", dir_uri, entry->name);
 
152
                                entry->icon = g_icon_to_string (g_file_info_get_icon (info));
178
153
                                
179
154
                                //g_debug ("Icon found: %s", entry->icon);
180
155
                                flist = g_list_append (flist, entry);
182
157
                }
183
158
        }
184
159
        
185
 
        gnome_vfs_file_info_list_free (list);
 
160
        g_file_enumerator_close (result, NULL, NULL);
186
161
        
187
162
        return flist;
188
163
}