summaryrefslogtreecommitdiff
path: root/capplets/background/gnome-wp-info.c
blob: ba6afb6180829a77362ab6bee8ef4f96400217e2 (plain)
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
/*
 *  Authors: Rodney Dawes <dobey@ximian.com>
 *
 *  Copyright 2003-2005 Novell, Inc. (www.novell.com)
 *
 *  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;

  gchar *escaped_uri = gnome_vfs_escape_path_string (uri);

  info = gnome_vfs_file_info_new ();
  result = gnome_vfs_get_file_info (escaped_uri, info,
				    GNOME_VFS_FILE_INFO_DEFAULT |
				    GNOME_VFS_FILE_INFO_GET_MIME_TYPE |
				    GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
  g_free (escaped_uri);

  if (info == NULL || info->mime_type == NULL || result != GNOME_VFS_OK) {
    if (!strcmp (uri, "(none)")) {
      new = g_new0 (GnomeWPInfo, 1);

      new->mime_type = g_strdup ("image/x-no-data");
      new->uri = g_strdup (uri);

      new->thumburi = g_strconcat (g_get_home_dir (),
				   "/.thumbnails/normal/",
				   gnome_thumbnail_md5 (gnome_vfs_escape_path_string (uri)),
				   ".png",
				   NULL);

      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,
						    gnome_vfs_escape_path_string (new->uri),
						    info->mtime);
    if (new->thumburi == NULL) {
      new->thumburi = g_strconcat (g_get_home_dir (),
				   "/.thumbnails/normal/",
				   gnome_thumbnail_md5 (gnome_vfs_escape_path_string (uri)),
				   ".png",
				   NULL);
    }
    new->name = g_strdup (info->name);
    new->mime_type = g_strdup (info->mime_type);

    new->size = info->size;
    new->mtime = info->mtime;
  }
  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;
}