summaryrefslogtreecommitdiff
path: root/src/open-file.c
blob: 35280ac9f2afab804f37e0f1d44940e3ab9af201 (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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */

/*
 *  Engrampa
 *
 *  Copyright (C) 2001-2008 The Free Software Foundation, Inc.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <config.h>
#include "open-file.h"
#include "file-utils.h"


OpenFile*
open_file_new (const char *path,
	       const char *extracted_path,
	       const char *temp_dir)
{
	OpenFile *ofile;
	
	ofile = g_new0 (OpenFile, 1);
	ofile->path = g_strdup (path);
	ofile->extracted_uri = g_filename_to_uri (extracted_path, NULL, NULL);
	if (! uri_exists (ofile->extracted_uri)) {
		open_file_free (ofile);
		return NULL;
	} 
	ofile->temp_dir = g_strdup (temp_dir);
	ofile->last_modified = get_file_mtime (ofile->extracted_uri);
	
	return ofile;
}


void
open_file_free (OpenFile *ofile)
{
	if (ofile == NULL)
		return;
	if (ofile->monitor != NULL)
		g_object_unref (ofile->monitor);
	g_free (ofile->path);
	g_free (ofile->extracted_uri);
	g_free (ofile->temp_dir);
	g_free (ofile);
}


OpenFile *
open_file_copy (OpenFile *src)
{
	OpenFile *ofile;

	ofile = g_new0 (OpenFile, 1);
	ofile->path = g_strdup (src->path);
	ofile->extracted_uri = g_strdup (src->extracted_uri);
	ofile->temp_dir = g_strdup (src->temp_dir);
	ofile->last_modified = src->last_modified;

	return ofile;
}


GType
open_file_get_type (void)
{
	static GType type = 0;
  
	if (type == 0)
		type = g_boxed_type_register_static ("FROpenFile", (GBoxedCopyFunc) open_file_copy, (GBoxedFreeFunc) open_file_free);
  
	return type;
}