2004-01-12 05:10:40 +00:00
|
|
|
/*
|
|
|
|
* Authors: Rodney Dawes <dobey@ximian.com>
|
|
|
|
*
|
2005-02-26 19:15:58 +00:00
|
|
|
* Copyright 2003-2005 Novell, Inc. (www.novell.com)
|
2004-01-12 05:10:40 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of version 2 of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation
|
|
|
|
*
|
|
|
|
* This program 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, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#include <gnome.h>
|
|
|
|
#include "gnome-wp-info.h"
|
|
|
|
|
|
|
|
GnomeWPInfo * gnome_wp_info_new (const gchar * uri,
|
|
|
|
GnomeThumbnailFactory * thumbs) {
|
|
|
|
GnomeWPInfo * new;
|
|
|
|
GnomeVFSFileInfo * info;
|
|
|
|
GnomeVFSResult result;
|
2005-07-10 15:58:14 +00:00
|
|
|
gchar * escaped_path;
|
2004-01-12 05:10:40 +00:00
|
|
|
|
|
|
|
info = gnome_vfs_file_info_new ();
|
2005-07-10 15:58:14 +00:00
|
|
|
escaped_path = gnome_vfs_escape_path_string (uri);
|
|
|
|
|
|
|
|
result = gnome_vfs_get_file_info (escaped_path, info,
|
2004-01-12 05:10:40 +00:00
|
|
|
GNOME_VFS_FILE_INFO_DEFAULT |
|
|
|
|
GNOME_VFS_FILE_INFO_GET_MIME_TYPE |
|
|
|
|
GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
|
|
|
|
if (info == NULL || info->mime_type == NULL || result != GNOME_VFS_OK) {
|
|
|
|
if (!strcmp (uri, "(none)")) {
|
2005-07-10 15:58:14 +00:00
|
|
|
gchar * md5sum;
|
|
|
|
|
2004-01-12 05:10:40 +00:00
|
|
|
new = g_new0 (GnomeWPInfo, 1);
|
|
|
|
|
|
|
|
new->mime_type = g_strdup ("image/x-no-data");
|
|
|
|
new->uri = g_strdup (uri);
|
|
|
|
|
2005-07-10 15:58:14 +00:00
|
|
|
md5sum = gnome_thumbnail_md5 (escaped_path);
|
|
|
|
|
2004-02-24 20:51:35 +00:00
|
|
|
new->thumburi = g_strconcat (g_get_home_dir (),
|
|
|
|
"/.thumbnails/normal/",
|
2005-07-10 15:58:14 +00:00
|
|
|
md5sum,
|
2004-02-24 20:51:35 +00:00
|
|
|
".png",
|
|
|
|
NULL);
|
2005-07-10 15:58:14 +00:00
|
|
|
g_free (md5sum);
|
2004-01-12 05:10:40 +00:00
|
|
|
|
|
|
|
new->name = g_strdup (_("No Wallpaper"));
|
|
|
|
|
|
|
|
new->size = 0;
|
|
|
|
} else {
|
|
|
|
new = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
new = g_new0 (GnomeWPInfo, 1);
|
|
|
|
|
|
|
|
new->uri = g_strdup (uri);
|
|
|
|
|
|
|
|
new->thumburi = gnome_thumbnail_factory_lookup (thumbs,
|
2005-07-10 15:58:14 +00:00
|
|
|
escaped_path,
|
2004-02-24 20:51:35 +00:00
|
|
|
info->mtime);
|
2004-01-12 05:10:40 +00:00
|
|
|
if (new->thumburi == NULL) {
|
2005-07-14 03:06:24 +00:00
|
|
|
gchar * md5sum;
|
|
|
|
|
|
|
|
md5sum = gnome_thumbnail_md5 (escaped_path);
|
|
|
|
|
2004-02-24 20:51:35 +00:00
|
|
|
new->thumburi = g_strconcat (g_get_home_dir (),
|
|
|
|
"/.thumbnails/normal/",
|
2005-07-14 03:06:24 +00:00
|
|
|
md5sum,
|
2004-02-24 20:51:35 +00:00
|
|
|
".png",
|
|
|
|
NULL);
|
2005-07-14 03:06:24 +00:00
|
|
|
|
|
|
|
g_free (md5sum);
|
2004-01-12 05:10:40 +00:00
|
|
|
}
|
|
|
|
new->name = g_strdup (info->name);
|
|
|
|
new->mime_type = g_strdup (info->mime_type);
|
|
|
|
|
|
|
|
new->size = info->size;
|
|
|
|
new->mtime = info->mtime;
|
|
|
|
}
|
2005-07-10 15:58:14 +00:00
|
|
|
g_free (escaped_path);
|
2004-01-12 05:10:40 +00:00
|
|
|
gnome_vfs_file_info_unref (info);
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
GnomeWPInfo * gnome_wp_info_dup (const GnomeWPInfo * info) {
|
|
|
|
GnomeWPInfo * new;
|
|
|
|
|
|
|
|
new = g_new0 (GnomeWPInfo, 1);
|
|
|
|
|
|
|
|
new->uri = g_strdup (info->uri);
|
|
|
|
new->thumburi = g_strdup (info->uri);
|
|
|
|
|
|
|
|
new->name = g_strdup (info->name);
|
|
|
|
new->mime_type = g_strdup (info->mime_type);
|
|
|
|
|
|
|
|
new->size = info->size;
|
|
|
|
new->mtime = info->mtime;
|
|
|
|
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gnome_wp_info_free (GnomeWPInfo * info) {
|
|
|
|
if (info == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (info->uri);
|
|
|
|
g_free (info->thumburi);
|
|
|
|
g_free (info->name);
|
|
|
|
g_free (info->mime_type);
|
|
|
|
|
|
|
|
info = NULL;
|
|
|
|
}
|
|
|
|
|