2
* Copyright (C) 2000 S�bastien LECACHEUR
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
#include "../gwsupport.h"
21
#include "gwcatalogfileinfo.h"
23
#include <string.h> /* strcmp */
24
#include <sys/stat.h> /* stats */
27
typedef struct catalog_file_info
29
gchar *title; /* Catalog name */
30
gchar *name; /* Catalog file name */
31
gchar *full_name; /* Catalog full path name */
32
gchar *version; /* Catalog version */
33
gchar *program_maker; /* Catalog maker name */
34
GList *categories; /* Categories list */
35
gchar *description; /* Catalog description */
36
gboolean ismodified; /* If the catalog is modified */
40
struct catalog_file_info * catalog_file_info_new ( void)
42
struct catalog_file_info *p = NULL;
43
struct category *category = NULL;
46
#ifdef GW_DEBUG_DATA_COMPONENT
52
g_print ( "*** GW - %s (%d) :: %s() : %d calls\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, i);
55
if ( (p = (struct catalog_file_info*)g_malloc0 ( sizeof ( struct catalog_file_info))) != NULL )
61
p->program_maker = NULL;
63
p->description = NULL;
64
p->ismodified = FALSE;
67
/* Warning it's a dirty code!! */
68
category = category_new ( );
69
category_set_name ( category, g_strdup ( _( "none")));
70
catalog_file_info_append_category ( p, category);
76
gint catalog_file_info_set_title ( struct catalog_file_info *p, gchar *title)
78
#ifdef GW_DEBUG_DATA_COMPONENT
79
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
84
if ( p->title != NULL )
98
gint catalog_file_info_set_name ( struct catalog_file_info *p, gchar *name)
100
#ifdef GW_DEBUG_DATA_COMPONENT
101
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
106
if ( p->name != NULL )
120
gint catalog_file_info_set_full_name ( struct catalog_file_info *p, gchar *full_name)
122
#ifdef GW_DEBUG_DATA_COMPONENT
123
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
128
if ( p->full_name != NULL )
130
g_free ( p->full_name);
133
p->full_name = full_name;
142
gint catalog_file_info_set_version ( struct catalog_file_info *p, gchar *version)
144
#ifdef GW_DEBUG_DATA_COMPONENT
145
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
150
if ( p->version != NULL )
152
g_free ( p->version);
155
p->version = version;
164
gint catalog_file_info_set_program_maker ( struct catalog_file_info *p, gchar *program_maker)
166
#ifdef GW_DEBUG_DATA_COMPONENT
167
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
172
if ( p->program_maker != NULL )
174
g_free ( p->program_maker);
177
p->program_maker = program_maker;
186
gint catalog_file_info_set_categories ( struct catalog_file_info *p, GList *categories)
188
#ifdef GW_DEBUG_DATA_COMPONENT
189
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
194
if ( p->categories != NULL )
196
g_list_foreach ( p->categories, (GFunc)g_free, NULL);
197
g_free ( p->categories);
200
p->categories = g_list_first ( categories);
209
gint catalog_file_info_append_category ( struct catalog_file_info *p, struct category *category)
211
#ifdef GW_DEBUG_DATA_COMPONENT
212
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
217
if ( category != NULL )
219
p->categories = g_list_append ( p->categories, category);
220
// category_set_index ( category, g_list_position ( g_list_first ( p->categories), p->categories));
221
category_set_index ( category, g_list_length ( g_list_first ( p->categories)) - 1);
235
gint catalog_file_info_remove_category ( struct catalog_file_info *p, struct category *category)
238
GList *categories = NULL;
241
#ifdef GW_DEBUG_DATA_COMPONENT
242
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
247
if ( category != NULL )
249
categories = catalog_file_info_get_categories ( p);
250
size = g_list_length ( g_list_first ( categories)) - 1;
251
index = category_get_index ( category);
253
categories = g_list_remove ( categories, category);
254
categories = g_list_first ( categories);
255
p->categories = g_list_first ( categories);
257
categories = g_list_nth ( categories, index);
259
for ( i = index; i < size; i++)
261
category_set_index ( categories->data, category_get_index ( categories->data) - 1);
262
categories = g_list_next ( categories);
277
gint catalog_file_info_set_description ( struct catalog_file_info *p, gchar *description)
279
#ifdef GW_DEBUG_DATA_COMPONENT
280
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
285
if ( p->description != NULL )
287
g_free ( p->description);
290
p->description = description;
299
gint catalog_file_info_set_ismodified ( struct catalog_file_info *p, gboolean b)
301
#ifdef GW_DEBUG_DATA_COMPONENT
302
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
316
gchar * catalog_file_info_get_title ( struct catalog_file_info *p)
318
#ifdef GW_DEBUG_DATA_COMPONENT
319
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
324
if ( p->title != NULL )
338
gchar * catalog_file_info_get_name ( struct catalog_file_info *p)
340
#ifdef GW_DEBUG_DATA_COMPONENT
341
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
346
if ( p->name != NULL )
360
gchar * catalog_file_info_get_full_name ( struct catalog_file_info *p)
362
#ifdef GW_DEBUG_DATA_COMPONENT
363
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
368
if ( p->full_name != NULL )
382
gchar * catalog_file_info_get_version ( struct catalog_file_info *p)
384
#ifdef GW_DEBUG_DATA_COMPONENT
385
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
390
if ( p->version != NULL )
404
gchar * catalog_file_info_get_program_maker ( struct catalog_file_info *p)
406
#ifdef GW_DEBUG_DATA_COMPONENT
407
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
412
if ( p->program_maker != NULL )
414
return p->program_maker;
426
GList * catalog_file_info_get_categories ( struct catalog_file_info *p)
428
#ifdef GW_DEBUG_DATA_COMPONENT
429
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
434
#ifdef GW_DEBUG_DATA_COMPONENT
435
g_print ( "*** GW - %s (%d) :: %s() : categories list isn't null.\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
438
return p->categories;
441
#ifdef GW_DEBUG_DATA_COMPONENT
442
g_print ( "*** GW - %s (%d) :: %s() : categories list is null!!\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
448
struct category * catalog_file_info_get_category ( struct catalog_file_info *p, gchar *category)
451
GList *categories = NULL;
454
#ifdef GW_DEBUG_DATA_COMPONENT
455
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
458
categories = catalog_file_info_get_categories ( p);
459
categories = g_list_first ( categories);
460
size = g_list_length ( categories);
462
for ( i = 0; i < size; i++)
464
if ( strcmp ( category, category_get_name ( categories->data)) == 0 )
466
return categories->data;
469
categories = g_list_next ( categories);
472
return catalog_file_info_get_category ( p, "none");
476
struct category * catalog_file_info_get_category_by_index ( struct catalog_file_info *p, guint index)
478
GList *categories = NULL;
481
#ifdef GW_DEBUG_DATA_COMPONENT
482
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
485
categories = catalog_file_info_get_categories ( p);
487
if ( index > g_list_length ( categories) )
489
return catalog_file_info_get_category_by_index ( p, 0);
492
categories = g_list_nth ( categories, index);
494
return categories->data;
498
gchar * catalog_file_info_get_description ( struct catalog_file_info *p)
500
#ifdef GW_DEBUG_DATA_COMPONENT
501
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
506
if ( p->description != NULL )
508
return p->description;
520
gulong catalog_file_info_get_size ( struct catalog_file_info *p)
525
#ifdef GW_DEBUG_DATA_COMPONENT
526
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
531
if ( stat( catalog_file_info_get_full_name ( p), &f_info) != -1 )
533
return f_info.st_size;
541
gboolean catalog_file_info_get_ismodified ( struct catalog_file_info *p)
543
#ifdef GW_DEBUG_DATA_COMPONENT
544
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
549
return p->ismodified;
552
/* p doesn't exists, it may not be modified.*/
557
gint catalog_file_info_category_free ( struct category *category, gpointer data)
562
#ifdef GW_DEBUG_DATA_COMPONENT
563
g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
566
if ( category != NULL )
568
category_free ( category);
577
gboolean catalog_file_info_free ( struct catalog_file_info *p)
579
#ifdef GW_DEBUG_DATA_COMPONENT
585
g_print ( "*** GW - %s (%d) :: %s() : %d calls\n", __FILE__, __LINE__, __PRETTY_FUNCTION__, i);
590
catalog_file_info_set_name ( p, NULL);
591
catalog_file_info_set_title ( p, NULL);
592
catalog_file_info_set_full_name ( p, NULL);
593
catalog_file_info_set_version ( p, NULL);
594
catalog_file_info_set_program_maker ( p, NULL);
596
if ( p->categories != NULL )
598
g_list_foreach ( p->categories, (GFunc)catalog_file_info_category_free, NULL);
599
g_list_free ( p->categories);
602
catalog_file_info_set_description ( p, NULL);