1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
3 /*
4 * File-Roller
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, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include <config.h>
23 #include "open-file.h"
24 #include "file-utils.h"
25 #include "glib-utils.h"
26
27
28 OpenFile *
open_file_new(const char * original_path,GFile * extracted_file,GFile * temp_dir)29 open_file_new (const char *original_path,
30 GFile *extracted_file,
31 GFile *temp_dir)
32 {
33 OpenFile *ofile;
34
35 ofile = g_new0 (OpenFile, 1);
36 ofile->extracted_file = g_object_ref (extracted_file);
37 if (! g_file_query_exists (ofile->extracted_file, NULL)) {
38 open_file_free (ofile);
39 return NULL;
40 }
41 ofile->temp_dir = g_object_ref (temp_dir);
42 ofile->last_modified = _g_file_get_file_mtime (ofile->extracted_file);
43
44 return ofile;
45 }
46
47
48 void
open_file_free(OpenFile * ofile)49 open_file_free (OpenFile *ofile)
50 {
51 if (ofile == NULL)
52 return;
53 if (ofile->monitor != NULL)
54 g_object_unref (ofile->monitor);
55 _g_object_unref (ofile->extracted_file);
56 _g_object_unref (ofile->temp_dir);
57 g_free (ofile);
58 }
59
60
61 OpenFile *
open_file_copy(OpenFile * src)62 open_file_copy (OpenFile *src)
63 {
64 OpenFile *ofile;
65
66 ofile = g_new0 (OpenFile, 1);
67 ofile->extracted_file = g_object_ref (src->extracted_file);
68 ofile->temp_dir = g_object_ref (src->temp_dir);
69 ofile->last_modified = src->last_modified;
70
71 return ofile;
72 }
73
74
75 G_DEFINE_BOXED_TYPE (OpenFile, open_file, open_file_copy, open_file_free)
76