~ubuntu-branches/ubuntu/maverick/brasero/maverick

« back to all changes in this revision

Viewing changes to src/burn-session.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Meredith
  • Date: 2006-11-08 05:31:37 UTC
  • mto: (1.4.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20061108053137-fwis69a76eu8rapq
Tags: upstream-0.5.0
Import upstream version 0.5.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *            burn-session.c
 
3
 *
 
4
 *  mer aoû  9 22:22:16 2006
 
5
 *  Copyright  2006  Rouquier Philippe
 
6
 *  brasero-app@wanadoo.fr
 
7
 ***************************************************************************/
 
8
 
 
9
/*
 
10
 *  This program is free software; you can redistribute it and/or modify
 
11
 *  it under the terms of the GNU General Public License as published by
 
12
 *  the Free Software Foundation; either version 2 of the License, or
 
13
 *  (at your option) any later version.
 
14
 *
 
15
 *  This program is distributed in the hope that it will be useful,
 
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 *  GNU Library General Public License for more details.
 
19
 *
 
20
 *  You should have received a copy of the GNU General Public License
 
21
 *  along with this program; if not, write to the Free Software
 
22
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
23
 */
 
24
 
 
25
#include <stdio.h>
 
26
#include <string.h>
 
27
 
 
28
#include <glib.h>
 
29
#include <glib-object.h>
 
30
#include <glib/gstdio.h>
 
31
 
 
32
#include "burn-basics.h"
 
33
#include "burn-session.h"
 
34
 
 
35
static void brasero_burn_session_class_init (BraseroBurnSessionClass *klass);
 
36
static void brasero_burn_session_init (BraseroBurnSession *sp);
 
37
static void brasero_burn_session_finalize (GObject *object);
 
38
 
 
39
struct _BraseroBurnSessionPrivate {
 
40
        FILE *session;
 
41
        gchar *session_path;
 
42
};
 
43
 
 
44
static GObjectClass *parent_class = NULL;
 
45
 
 
46
GType
 
47
brasero_burn_session_get_type ()
 
48
{
 
49
        static GType type = 0;
 
50
 
 
51
        if(type == 0) {
 
52
                static const GTypeInfo our_info = {
 
53
                        sizeof (BraseroBurnSessionClass),
 
54
                        NULL,
 
55
                        NULL,
 
56
                        (GClassInitFunc)brasero_burn_session_class_init,
 
57
                        NULL,
 
58
                        NULL,
 
59
                        sizeof (BraseroBurnSession),
 
60
                        0,
 
61
                        (GInstanceInitFunc)brasero_burn_session_init,
 
62
                };
 
63
 
 
64
                type = g_type_register_static (G_TYPE_OBJECT, 
 
65
                                               "BraseroBurnSession",
 
66
                                                &our_info,
 
67
                                               0);
 
68
        }
 
69
 
 
70
        return type;
 
71
}
 
72
 
 
73
static void
 
74
brasero_burn_session_class_init (BraseroBurnSessionClass *klass)
 
75
{
 
76
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
77
 
 
78
        parent_class = g_type_class_peek_parent(klass);
 
79
        object_class->finalize = brasero_burn_session_finalize;
 
80
}
 
81
 
 
82
static void
 
83
brasero_burn_session_init (BraseroBurnSession *obj)
 
84
{
 
85
        obj->priv = g_new0 (BraseroBurnSessionPrivate, 1);
 
86
}
 
87
 
 
88
static void
 
89
brasero_burn_session_finalize (GObject *object)
 
90
{
 
91
        BraseroBurnSession *cobj;
 
92
 
 
93
        cobj = BRASERO_BURN_SESSION (object);
 
94
 
 
95
        if (cobj->priv->session) {
 
96
                fclose (cobj->priv->session);
 
97
                cobj->priv->session = NULL;
 
98
        }
 
99
 
 
100
        if (cobj->priv->session_path) {
 
101
                g_remove (cobj->priv->session_path);
 
102
                g_free (cobj->priv->session_path);
 
103
                cobj->priv->session_path = NULL;
 
104
        }
 
105
 
 
106
        g_free (cobj->priv);
 
107
        G_OBJECT_CLASS (parent_class)->finalize (object);
 
108
}
 
109
 
 
110
BraseroBurnSession *
 
111
brasero_burn_session_new ()
 
112
{
 
113
        BraseroBurnSession *obj;
 
114
        
 
115
        obj = BRASERO_BURN_SESSION (g_object_new (BRASERO_TYPE_BURN_SESSION, NULL));
 
116
        
 
117
        return obj;
 
118
}
 
119
 
 
120
void
 
121
brasero_burn_session_logv (BraseroBurnSession *session,
 
122
                           const gchar *format,
 
123
                           va_list arg_list)
 
124
{
 
125
        gchar *message;
 
126
        gchar *offending;
 
127
 
 
128
        if (!format)
 
129
                return;
 
130
 
 
131
        if (!session->priv->session)
 
132
                return;
 
133
 
 
134
        message = g_strdup_vprintf (format, arg_list);
 
135
 
 
136
        /* we also need to validate the messages to be in UTF-8 */
 
137
        if (!g_utf8_validate (message, -1, (const gchar**) &offending))
 
138
                *offending = '\0';
 
139
 
 
140
        if (fwrite (message, strlen (message), 1, session->priv->session) != 1)
 
141
                g_warning ("Some log data couldn't be written: %s\n", message);
 
142
 
 
143
        g_free (message);
 
144
 
 
145
        fwrite ("\n", 1, 1, session->priv->session);
 
146
}
 
147
 
 
148
void
 
149
brasero_burn_session_set_log_path (BraseroBurnSession *session,
 
150
                                   const gchar *session_path)
 
151
{
 
152
        if (session->priv->session_path) {
 
153
                g_free (session->priv->session_path);
 
154
                session->priv->session_path = NULL;
 
155
        }
 
156
 
 
157
        if (session_path)
 
158
                session->priv->session_path = g_strdup (session_path);
 
159
}
 
160
 
 
161
const gchar *
 
162
brasero_burn_session_get_log_path (BraseroBurnSession *session)
 
163
{
 
164
        return session->priv->session_path;
 
165
}
 
166
 
 
167
gboolean
 
168
brasero_burn_session_start (BraseroBurnSession *session)
 
169
{
 
170
        if (!session->priv->session_path) {
 
171
                int fd;
 
172
 
 
173
                session->priv->session_path = g_build_path (G_DIR_SEPARATOR_S,
 
174
                                                            g_get_tmp_dir (),
 
175
                                                            BRASERO_BURN_TMP_FILE_NAME,
 
176
                                                            NULL);
 
177
 
 
178
                fd = g_mkstemp (session->priv->session_path);
 
179
                session->priv->session = fdopen (fd, "w");
 
180
        }
 
181
        else
 
182
                session->priv->session = fopen (session->priv->session_path, "w");
 
183
 
 
184
        if (!session->priv->session) {
 
185
                g_warning ("Impossible to open a session file\n");
 
186
                return FALSE;
 
187
        }
 
188
 
 
189
        return TRUE;
 
190
}
 
191
 
 
192
void
 
193
brasero_burn_session_stop (BraseroBurnSession *session)
 
194
{
 
195
        if (session->priv->session) {
 
196
                fclose (session->priv->session);
 
197
                session->priv->session = NULL;
 
198
        }
 
199
}