~ubuntu-branches/ubuntu/warty/file-roller/warty

« back to all changes in this revision

Viewing changes to src/fr-command-lha.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2004-10-11 22:01:33 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041011220133-nu4i31tvi82v0685
Tags: 2.8.2-0ubuntu1
* New upstream release:
  - void opening remote files in nautilus.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <string.h>
25
25
#include <time.h>
26
26
 
27
 
#include <gtk/gtk.h>
 
27
#include <glib.h>
28
28
#include <libgnomevfs/gnome-vfs-types.h>
29
29
#include <libgnomevfs/gnome-vfs-mime.h>
30
30
 
33
33
#include "fr-command.h"
34
34
#include "fr-command-lha.h"
35
35
 
36
 
 
37
36
static void fr_command_lha_class_init  (FRCommandLhaClass *class);
38
 
 
39
 
static void fr_command_lha_init        (FRCommand *afile);
40
 
 
41
 
static void fr_command_lha_destroy     (GtkObject *object);
42
 
 
 
37
static void fr_command_lha_init        (FRCommand         *afile);
 
38
static void fr_command_lha_finalize    (GObject           *object);
43
39
 
44
40
/* Parent Class */
45
41
 
49
45
/* -- list -- */
50
46
 
51
47
static time_t
52
 
mktime_from_string (char *month, char *mday, char *time_or_year)
 
48
mktime_from_string (char *month, 
 
49
                    char *mday, 
 
50
                    char *time_or_year)
53
51
{
54
 
        static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", 
55
 
                                  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
56
 
        struct tm tm = {0, };
57
 
        char **fields;
 
52
        static char  *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", 
 
53
                                   "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
 
54
        struct tm     tm = {0, };
 
55
        char        **fields;
58
56
 
59
57
        /* date */
60
58
 
70
68
        if (strchr (time_or_year, ':') == NULL)
71
69
                tm.tm_year = atoi (time_or_year) - 1900;
72
70
        else {
73
 
                time_t now;
74
 
                struct tm * tm_now;
 
71
                time_t     now;
 
72
                struct tm *tm_now;
75
73
 
76
74
                now = time (NULL);
77
75
                tm_now = localtime (&now);
93
91
}
94
92
 
95
93
 
96
 
static char *
97
 
eat_spaces (char *line)
98
 
{
99
 
        while ((*line == ' ') && (*line != 0))
100
 
                line++;
101
 
        return line;
102
 
}
103
 
 
104
 
 
105
94
static char **
106
 
split_line (char *line, int n_fields)
 
95
split_line_lha (char *line)
107
96
{
108
 
        char **fields;
109
 
        char *scan, *field_end;
110
 
        int i;
 
97
        char       **fields;
 
98
        int          n_fields = 7;
 
99
        const char  *scan, *field_end;
 
100
        int          i;
111
101
 
112
102
        fields = g_new0 (char *, n_fields + 1);
113
 
        fields[n_fields + 1] = NULL;
 
103
        fields[n_fields] = NULL;
 
104
 
 
105
        i = 0;
 
106
 
 
107
        if (strncmp (line, "[MS-DOS]", 8) == 0) {
 
108
                fields[i++] = g_strdup ("");
 
109
                fields[i++] = g_strdup ("");
 
110
                line += strlen ("[MS-DOS]");
 
111
 
 
112
        } else if (strncmp (line, "[generic]", 9) == 0) {
 
113
                fields[i++] = g_strdup ("");
 
114
                fields[i++] = g_strdup ("");
 
115
                line += strlen ("[generic]");
 
116
        }
114
117
 
115
118
        scan = eat_spaces (line);
116
 
        for (i = 0; i < n_fields; i++) {
 
119
        for (; i < n_fields; i++) {
117
120
                field_end = strchr (scan, ' ');
118
 
                fields[i] = g_strndup (scan, field_end - scan);
119
 
                scan = eat_spaces (field_end);
 
121
                if (field_end != NULL) {
 
122
                        fields[i] = g_strndup (scan, field_end - scan);
 
123
                        scan = eat_spaces (field_end);
 
124
                }
120
125
        }
121
126
 
122
127
        return fields;
123
128
}
124
129
 
125
130
 
126
 
static char *
127
 
get_last_field (char *line)
 
131
static const char *
 
132
get_last_field_lha (char *line)
128
133
{
129
 
        int i;
130
 
        char *field;
131
 
        int n = 8;
132
 
 
133
 
        n--;
 
134
        int         i;
 
135
        const char *field;
 
136
        int         n = 7;
 
137
 
 
138
        if (strncmp (line, "[MS-DOS]", 8) == 0) 
 
139
                n--;
 
140
 
 
141
        if (strncmp (line, "[generic]", 9) == 0) 
 
142
                n--;
 
143
 
134
144
        field = eat_spaces (line);
135
145
        for (i = 0; i < n; i++) {
136
146
                field = strchr (field, ' ');
142
152
 
143
153
 
144
154
static void
145
 
process_line (char *line, gpointer data)
 
155
process_line (char     *line, 
 
156
              gpointer  data)
146
157
{
147
 
        FileData *fdata;
148
 
        FRCommand *comm = FR_COMMAND (data);
149
 
        char **fields;
150
 
        char *name_field;
 
158
        FileData    *fdata;
 
159
        FRCommand   *comm = FR_COMMAND (data);
 
160
        char       **fields;
 
161
        const char  *name_field;
151
162
 
152
163
        g_return_if_fail (line != NULL);
153
164
 
154
165
        fdata = file_data_new ();
155
166
 
156
 
        fields = split_line (line, 7);
 
167
        fields = split_line_lha (line);
157
168
        fdata->size = atol (fields[2]);
158
169
        fdata->modified = mktime_from_string (fields[4], 
159
170
                                              fields[5], 
162
173
 
163
174
        /* Full path */
164
175
 
165
 
        name_field = get_last_field (line);
 
176
        name_field = get_last_field_lha (line);
166
177
 
167
178
        if (*name_field == '/') {
168
179
                fdata->full_path = g_strdup (name_field);
188
199
static void
189
200
fr_command_lha_list (FRCommand *comm)
190
201
{
191
 
        fr_process_clear (comm->process);
 
202
        fr_process_set_out_line_func (FR_COMMAND (comm)->process, 
 
203
                                      process_line,
 
204
                                      comm);
 
205
 
192
206
        fr_process_begin_command (comm->process, "lha");
193
207
        fr_process_add_arg (comm->process, "lq");
194
208
        fr_process_add_arg (comm->process, comm->e_filename);
195
209
        fr_process_end_command (comm->process);
196
 
        fr_process_start (comm->process, TRUE);
 
210
        fr_process_start (comm->process);
197
211
}
198
212
 
199
213
 
200
214
static void
201
 
fr_command_lha_add (FRCommand *comm,
202
 
                    GList *file_list,
203
 
                    gchar *base_dir,
204
 
                    gboolean update)
 
215
fr_command_lha_add (FRCommand     *comm,
 
216
                    GList         *file_list,
 
217
                    const char    *base_dir,
 
218
                    gboolean       update,
 
219
                    const char    *password,
 
220
                    FRCompression  compression)
205
221
{
206
222
        GList *scan;
207
223
 
208
224
        fr_process_begin_command (comm->process, "lha");
209
 
 
210
225
        if (base_dir != NULL) 
211
226
                fr_process_set_working_dir (comm->process, base_dir);
212
 
 
213
227
        if (update)
214
228
                fr_process_add_arg (comm->process, "u");
215
229
        else
216
230
                fr_process_add_arg (comm->process, "a");
217
 
 
218
231
        fr_process_add_arg (comm->process, comm->e_filename);
219
 
 
220
232
        for (scan = file_list; scan; scan = scan->next) 
221
233
                fr_process_add_arg (comm->process, (gchar*) scan->data);
222
 
 
223
234
        fr_process_end_command (comm->process);
224
235
}
225
236
 
226
237
 
227
238
static void
228
239
fr_command_lha_delete (FRCommand *comm,
229
 
                       GList *file_list)
 
240
                       GList     *file_list)
230
241
{
231
242
        GList *scan;
232
243
 
241
252
 
242
253
 
243
254
static void
244
 
fr_command_lha_extract (FRCommand *comm,
245
 
                        GList *file_list,
246
 
                        char *dest_dir,
247
 
                        gboolean overwrite,
248
 
                        gboolean skip_older,
249
 
                        gboolean junk_paths)
 
255
fr_command_lha_extract (FRCommand  *comm,
 
256
                        GList      *file_list,
 
257
                        const char *dest_dir,
 
258
                        gboolean    overwrite,
 
259
                        gboolean    skip_older,
 
260
                        gboolean    junk_paths,
 
261
                        const char *password)
250
262
{
251
263
        GList *scan;
252
 
        char options[5];
253
 
        int i = 0;
 
264
        char   options[5];
 
265
        int    i = 0;
254
266
 
255
267
        fr_process_begin_command (comm->process, "lha");
256
268
        
281
293
static void 
282
294
fr_command_lha_class_init (FRCommandLhaClass *class)
283
295
{
 
296
        GObjectClass   *gobject_class = G_OBJECT_CLASS (class);
284
297
        FRCommandClass *afc;
285
 
        GtkObjectClass *object_class;
286
298
 
287
 
        parent_class = gtk_type_class (FR_COMMAND_TYPE);
288
 
        object_class = (GtkObjectClass*) class;
 
299
        parent_class = g_type_class_peek_parent (class);
289
300
        afc = (FRCommandClass*) class;
290
301
 
291
 
        object_class->destroy = fr_command_lha_destroy;
 
302
        gobject_class->finalize = fr_command_lha_finalize;
292
303
 
293
304
        afc->list         = fr_command_lha_list;
294
305
        afc->add          = fr_command_lha_add;
305
316
        comm->propExtractCanAvoidOverwrite = FALSE;
306
317
        comm->propExtractCanSkipOlder      = FALSE;
307
318
        comm->propExtractCanJunkPaths      = TRUE;
 
319
        comm->propPassword                 = FALSE;
 
320
        comm->propTest                     = FALSE;
308
321
}
309
322
 
310
323
 
311
324
static void 
312
 
fr_command_lha_destroy (GtkObject *object)
 
325
fr_command_lha_finalize (GObject *object)
313
326
{
314
327
        g_return_if_fail (object != NULL);
315
 
        g_return_if_fail (IS_FR_COMMAND_LHA (object));
 
328
        g_return_if_fail (FR_IS_COMMAND_LHA (object));
316
329
 
317
330
         /* Chain up */
318
 
        if (GTK_OBJECT_CLASS (parent_class)->destroy)
319
 
                (* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
 
331
        if (G_OBJECT_CLASS (parent_class)->finalize)
 
332
                G_OBJECT_CLASS (parent_class)->finalize (object);
320
333
}
321
334
 
322
335
 
323
 
GtkType
 
336
GType
324
337
fr_command_lha_get_type ()
325
338
{
326
 
        static guint fr_command_lha_type = 0;
327
 
 
328
 
        if (!fr_command_lha_type) {
329
 
                GtkTypeInfo fr_command_lha_info = {
330
 
                        "FRCommandLha",
331
 
                        sizeof (FRCommandLha),
332
 
                        sizeof (FRCommandLhaClass),
333
 
                        (GtkClassInitFunc) fr_command_lha_class_init,
334
 
                        (GtkObjectInitFunc) fr_command_lha_init,
335
 
                        /* reserved_1 */ NULL,
336
 
                        /* reserved_2 */ NULL,
337
 
                        (GtkClassInitFunc) NULL,
338
 
                };
339
 
                fr_command_lha_type = gtk_type_unique (fr_command_get_type(), 
340
 
                                                       &fr_command_lha_info);
 
339
        static GType type = 0;
 
340
 
 
341
        if (! type) {
 
342
                GTypeInfo type_info = {
 
343
                        sizeof (FRCommandLhaClass),
 
344
                        NULL,
 
345
                        NULL,
 
346
                        (GClassInitFunc) fr_command_lha_class_init,
 
347
                        NULL,
 
348
                        NULL,
 
349
                        sizeof (FRCommandLha),
 
350
                        0,
 
351
                        (GInstanceInitFunc) fr_command_lha_init
 
352
                };
 
353
 
 
354
                type = g_type_register_static (FR_TYPE_COMMAND,
 
355
                                               "FRCommandLha",
 
356
                                               &type_info,
 
357
                                               0);
341
358
        }
342
359
 
343
 
        return fr_command_lha_type;
 
360
        return type;
344
361
}
345
362
 
346
363
 
347
364
FRCommand *
348
 
fr_command_lha_new (FRProcess *process,
349
 
                    char *filename)
 
365
fr_command_lha_new (FRProcess  *process,
 
366
                    const char *filename)
350
367
{
351
368
        FRCommand *comm;
352
369
 
353
 
        comm = FR_COMMAND (gtk_type_new (fr_command_lha_get_type ()));
 
370
        comm = FR_COMMAND (g_object_new (FR_TYPE_COMMAND_LHA, NULL));
354
371
        fr_command_construct (comm, process, filename);
355
 
        fr_process_set_proc_line_func (FR_COMMAND (comm)->process, 
356
 
                                       process_line,
357
 
                                       comm);
358
372
 
359
373
        return comm;
360
374
}