summaryrefslogtreecommitdiff
path: root/capplets/appearance/mate-wp-info.c
blob: 58145fd0eb0ceef005977a5d4100f9d7ce199b80 (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
/*
 *  Authors: Rodney Dawes <dobey@ximian.com>
 *
 *  Copyright 2003-2006 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 <string.h>
#include <glib/gi18n.h>
#include <gio/gio.h>
#include "mate-wp-info.h"

MateWPInfo* mate_wp_info_new(const char* uri, MateDesktopThumbnailFactory* thumbs)
{
	MateWPInfo* wp;

	GFile* file = g_file_new_for_commandline_arg(uri);

	GFileInfo* info = g_file_query_info(file,
		G_FILE_ATTRIBUTE_STANDARD_NAME ","
		G_FILE_ATTRIBUTE_STANDARD_SIZE ","
		G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE ","
		G_FILE_ATTRIBUTE_TIME_MODIFIED,
		G_FILE_QUERY_INFO_NONE,
		NULL, NULL);

	g_object_unref(file);

	if (info == NULL || g_file_info_get_content_type (info) == NULL)
	{
		if (!strcmp (uri, "(none)"))
		{
		  wp = g_new0(MateWPInfo, 1);

		  wp->mime_type = g_strdup("image/x-no-data");
		  wp->uri = g_strdup(uri);
		  wp->name = g_strdup(_("No Desktop Background"));
		  wp->size = 0;
		}
		else
		{
			wp = NULL;
		}
	}
	else
	{
		wp = g_new0 (MateWPInfo, 1);

		wp->uri = g_strdup(uri);

		wp->name = g_strdup(g_file_info_get_name(info));

		if (g_file_info_get_content_type(info) != NULL)
		{
			wp->mime_type = g_strdup(g_file_info_get_content_type(info));
		}

		wp->size = g_file_info_get_size(info);
		wp->mtime = g_file_info_get_attribute_uint64(info, G_FILE_ATTRIBUTE_TIME_MODIFIED);

		wp->thumburi = mate_desktop_thumbnail_factory_lookup(thumbs, uri, wp->mtime);
	}

	if (info != NULL)
	{
		g_object_unref(info);
	}

	return wp;
}

void mate_wp_info_free(MateWPInfo* info)
{
	if (info == NULL)
	{
		return;
	}

	g_free(info->uri);
	g_free(info->thumburi);
	g_free(info->name);
	g_free(info->mime_type);
}