1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 
3 /*
4  *  Engrampa
5  *
6  *  Copyright (C) 2001-2008 The Free Software Foundation, Inc.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22 
23 #include <config.h>
24 #include "open-file.h"
25 #include "file-utils.h"
26 
27 
28 OpenFile*
open_file_new(const char * path,const char * extracted_path,const char * temp_dir)29 open_file_new (const char *path,
30 	       const char *extracted_path,
31 	       const char *temp_dir)
32 {
33 	OpenFile *ofile;
34 
35 	ofile = g_new0 (OpenFile, 1);
36 	ofile->path = g_strdup (path);
37 	ofile->extracted_uri = g_filename_to_uri (extracted_path, NULL, NULL);
38 	if (! uri_exists (ofile->extracted_uri)) {
39 		open_file_free (ofile);
40 		return NULL;
41 	}
42 	ofile->temp_dir = g_strdup (temp_dir);
43 	ofile->last_modified = get_file_mtime (ofile->extracted_uri);
44 
45 	return ofile;
46 }
47 
48 
49 void
open_file_free(OpenFile * ofile)50 open_file_free (OpenFile *ofile)
51 {
52 	if (ofile == NULL)
53 		return;
54 	if (ofile->monitor != NULL)
55 		g_object_unref (ofile->monitor);
56 	g_free (ofile->path);
57 	g_free (ofile->extracted_uri);
58 	g_free (ofile->temp_dir);
59 	g_free (ofile);
60 }
61 
62 
63 OpenFile *
open_file_copy(OpenFile * src)64 open_file_copy (OpenFile *src)
65 {
66 	OpenFile *ofile;
67 
68 	ofile = g_new0 (OpenFile, 1);
69 	ofile->path = g_strdup (src->path);
70 	ofile->extracted_uri = g_strdup (src->extracted_uri);
71 	ofile->temp_dir = g_strdup (src->temp_dir);
72 	ofile->last_modified = src->last_modified;
73 
74 	return ofile;
75 }
76 
77 
78 GType
open_file_get_type(void)79 open_file_get_type (void)
80 {
81 	static GType type = 0;
82 
83 	if (type == 0)
84 		type = g_boxed_type_register_static ("FROpenFile", (GBoxedCopyFunc) open_file_copy, (GBoxedFreeFunc) open_file_free);
85 
86 	return type;
87 }
88