~ubuntu-branches/ubuntu/maverick/gwhere/maverick

« back to all changes in this revision

Viewing changes to src/db/gwdbcatalog.c

  • Committer: Bazaar Package Importer
  • Author(s): Bart Martens
  • Date: 2007-01-27 16:01:01 UTC
  • mfrom: (2.1.1 feisty)
  • Revision ID: james.westby@ubuntu.com-20070127160101-u673yo4vke03jg26
Tags: 0.2.3.dfsg.1-2
* debian/rules: Convert gwhere.desktop to UTF-8.  Closes: #405137.
* debian/rules: Replace all "extraibles" with "extraíbles" in
  gwhere.desktop.  Closes: #405138.
* debian/copyright: Updated for year 2007.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  GWhere
 
2
 *  Copyright (C) 2000  S�bastien LECACHEUR
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 */
 
18
 
 
19
 
 
20
#include <string.h> /* strcmp */
 
21
#include "gwsupport.h"
 
22
#include "gwdbcatalog.h"
 
23
 
 
24
 
 
25
typedef struct gw_db_catalog_s {
 
26
        gchar* name;
 
27
        gchar* short_db_name;
 
28
        gchar* db_name;
 
29
        gchar* version;
 
30
        gchar* program_builder;
 
31
        gchar* description;
 
32
        gboolean is_modified;
 
33
        gulong size;
 
34
}_GWDBCatalog;
 
35
 
 
36
 
 
37
GWDBCatalog * gw_db_catalog_new ( void) {
 
38
        GWDBCatalog *catalog = NULL;
 
39
 
 
40
 
 
41
        if ( (catalog = (GWDBCatalog*)g_malloc0 ( sizeof ( GWDBCatalog))) != NULL ) {
 
42
                catalog->name = NULL;
 
43
                catalog->short_db_name = NULL;
 
44
                catalog->db_name = NULL;
 
45
                catalog->version = NULL;
 
46
                catalog->program_builder = NULL;
 
47
                catalog->description = NULL;
 
48
                catalog->is_modified = FALSE;
 
49
                catalog->size = 0;
 
50
        }
 
51
 
 
52
        return catalog;
 
53
}
 
54
 
 
55
 
 
56
gint gw_db_catalog_set_name ( GWDBCatalog *catalog, gchar *name) {
 
57
        if ( catalog != NULL ) {
 
58
                if ( catalog->name != NULL ) {
 
59
                        g_free ( catalog->name);
 
60
                }
 
61
 
 
62
                catalog->name = name;
 
63
 
 
64
                return 0;
 
65
        }
 
66
 
 
67
        return -1;
 
68
}
 
69
 
 
70
 
 
71
gint gw_db_catalog_set_short_db_name ( GWDBCatalog *catalog, gchar *short_db_name) {
 
72
        if ( catalog != NULL ) {
 
73
                if ( catalog->short_db_name != NULL ) {
 
74
                        g_free ( catalog->short_db_name);
 
75
                }
 
76
 
 
77
                catalog->short_db_name = short_db_name;
 
78
 
 
79
                return 0;
 
80
        }
 
81
 
 
82
        return -1;
 
83
}
 
84
 
 
85
 
 
86
gint gw_db_catalog_set_db_name ( GWDBCatalog *catalog, gchar *db_name) {
 
87
        if ( catalog != NULL ) {
 
88
                if ( catalog->db_name != NULL ) {
 
89
                        g_free ( catalog->db_name);
 
90
                }
 
91
 
 
92
                catalog->db_name = db_name;
 
93
 
 
94
                return 0;
 
95
        }
 
96
 
 
97
        return -1;
 
98
}
 
99
 
 
100
 
 
101
gint gw_db_catalog_set_version ( GWDBCatalog *catalog, gchar *version) {
 
102
        if ( catalog != NULL ) {
 
103
                if ( catalog->version != NULL ) {
 
104
                        g_free ( catalog->version);
 
105
                }
 
106
 
 
107
                catalog->version = version;
 
108
 
 
109
                return 0;
 
110
        }
 
111
 
 
112
        return -1;
 
113
}
 
114
 
 
115
 
 
116
gint gw_db_catalog_set_program_builder ( GWDBCatalog *catalog, gchar *program_builder) {
 
117
        if ( catalog != NULL ) {
 
118
                if ( catalog->program_builder != NULL ) {
 
119
                        g_free ( catalog->program_builder);
 
120
                }
 
121
 
 
122
                catalog->program_builder = program_builder;
 
123
 
 
124
                return 0;
 
125
        }
 
126
 
 
127
        return -1;
 
128
}
 
129
 
 
130
 
 
131
gint gw_db_catalog_set_description ( GWDBCatalog *catalog, gchar *description) {
 
132
        if ( catalog != NULL ) {
 
133
                if ( catalog->description != NULL ) {
 
134
                        g_free ( catalog->description);
 
135
                }
 
136
 
 
137
                catalog->description = description;
 
138
 
 
139
                return 0;
 
140
        }
 
141
 
 
142
        return -1;
 
143
}
 
144
 
 
145
 
 
146
gint gw_db_catalog_set_size ( GWDBCatalog *catalog, gulong size) {
 
147
        if ( catalog != NULL ) {
 
148
                catalog->size = size;
 
149
 
 
150
                return 0;
 
151
        }
 
152
 
 
153
        return -1;
 
154
}
 
155
 
 
156
 
 
157
gint gw_db_catalog_set_ismodified ( GWDBCatalog *catalog, gboolean modified) {
 
158
        if ( catalog != NULL ) {
 
159
                catalog->is_modified = modified;
 
160
 
 
161
                return 0;
 
162
        }
 
163
 
 
164
        return -1;
 
165
}
 
166
 
 
167
 
 
168
gchar * gw_db_catalog_get_name ( GWDBCatalog *catalog) {
 
169
        if ( catalog != NULL ) {
 
170
                return catalog->name;
 
171
        }
 
172
 
 
173
        return NULL;
 
174
}
 
175
 
 
176
 
 
177
gchar * gw_db_catalog_get_short_db_name ( GWDBCatalog *catalog) {
 
178
        if ( catalog != NULL ) {
 
179
                return catalog->short_db_name;
 
180
        }
 
181
 
 
182
        return NULL;
 
183
}
 
184
 
 
185
 
 
186
gchar * gw_db_catalog_get_db_name ( GWDBCatalog *catalog) {
 
187
        if ( catalog != NULL ) {
 
188
                return catalog->db_name;
 
189
        }
 
190
 
 
191
        return NULL;
 
192
}
 
193
 
 
194
 
 
195
gchar * gw_db_catalog_get_version ( GWDBCatalog *catalog) {
 
196
        if ( catalog != NULL ) {
 
197
                return catalog->version;
 
198
        }
 
199
 
 
200
        return NULL;
 
201
}
 
202
 
 
203
 
 
204
gchar * gw_db_catalog_get_program_builder ( GWDBCatalog *catalog) {
 
205
        if ( catalog != NULL ) {
 
206
                return catalog->program_builder;
 
207
        }
 
208
 
 
209
        return NULL;
 
210
}
 
211
 
 
212
 
 
213
gchar * gw_db_catalog_get_description ( GWDBCatalog *catalog) {
 
214
        if ( catalog != NULL ) {
 
215
                return catalog->description;
 
216
        }
 
217
 
 
218
        return NULL;
 
219
}
 
220
 
 
221
 
 
222
gulong gw_db_catalog_get_size ( GWDBCatalog *catalog) {
 
223
        if ( catalog != NULL ) {
 
224
                return catalog->size;
 
225
        }
 
226
 
 
227
        return 0;
 
228
}
 
229
 
 
230
 
 
231
gboolean gw_db_catalog_is_modified ( GWDBCatalog *catalog) {
 
232
        if ( catalog != NULL ) {
 
233
                return catalog->is_modified;
 
234
        }
 
235
 
 
236
        /* If catalog doesn't exist, it may not be modified. */
 
237
        return FALSE;
 
238
}
 
239
 
 
240
 
 
241
GWDBCatalog * gw_db_catalog_dup ( GWDBCatalog *catalog, GWDBCatalog **dup) {
 
242
        GWDBCatalog *dup_catalog = NULL;
 
243
 
 
244
 
 
245
        if ( catalog != NULL ) {
 
246
                dup_catalog = *dup;
 
247
                if ( dup_catalog == NULL ) {
 
248
                        /* Don't check if gw_db_catalog_new return NULL because all following functions check it too. */
 
249
                        (*dup) = dup_catalog = gw_db_catalog_new ( );
 
250
                }
 
251
 
 
252
                if ( gw_db_catalog_get_name ( catalog) != NULL ) {
 
253
                        gw_db_catalog_set_name ( dup_catalog, g_strdup ( gw_db_catalog_get_name ( catalog)));
 
254
                } else {
 
255
                        gw_db_catalog_set_name ( dup_catalog, NULL);
 
256
                }
 
257
                if ( gw_db_catalog_get_short_db_name ( catalog) != NULL ) {
 
258
                        gw_db_catalog_set_short_db_name ( dup_catalog, g_strdup ( gw_db_catalog_get_short_db_name ( catalog)));
 
259
                } else {
 
260
                        gw_db_catalog_set_short_db_name ( dup_catalog, NULL);
 
261
                }
 
262
                if ( gw_db_catalog_get_db_name ( catalog) != NULL ) {
 
263
                        gw_db_catalog_set_db_name ( dup_catalog, g_strdup ( gw_db_catalog_get_db_name ( catalog)));
 
264
                } else {
 
265
                        gw_db_catalog_set_db_name ( dup_catalog, NULL);
 
266
                }
 
267
                if ( gw_db_catalog_get_version ( catalog) != NULL ) {
 
268
                        gw_db_catalog_set_version ( dup_catalog, g_strdup ( gw_db_catalog_get_version ( catalog)));
 
269
                } else {
 
270
                        gw_db_catalog_set_version ( dup_catalog, NULL);
 
271
                }
 
272
                if ( gw_db_catalog_get_program_builder ( catalog) != NULL ) {
 
273
                        gw_db_catalog_set_program_builder ( dup_catalog, g_strdup ( gw_db_catalog_get_program_builder ( catalog)));
 
274
                } else {
 
275
                        gw_db_catalog_set_program_builder ( dup_catalog, NULL);
 
276
                }
 
277
                if ( gw_db_catalog_get_description ( catalog) != NULL ) {
 
278
                        gw_db_catalog_set_description ( dup_catalog, g_strdup ( gw_db_catalog_get_description ( catalog)));
 
279
                } else {
 
280
                        gw_db_catalog_set_description ( dup_catalog, NULL);
 
281
                }
 
282
                gw_db_catalog_set_size ( dup_catalog, gw_db_catalog_get_size ( catalog));
 
283
                gw_db_catalog_set_ismodified ( dup_catalog, gw_db_catalog_is_modified ( catalog));
 
284
        }
 
285
 
 
286
        return dup_catalog;
 
287
}
 
288
 
 
289
 
 
290
gint gw_db_catalog_free ( GWDBCatalog *catalog) {
 
291
        if ( catalog != NULL ) {
 
292
                gw_db_catalog_set_name ( catalog, NULL);
 
293
                gw_db_catalog_set_short_db_name ( catalog, NULL);
 
294
                gw_db_catalog_set_db_name ( catalog, NULL);
 
295
                gw_db_catalog_set_version ( catalog, NULL);
 
296
                gw_db_catalog_set_program_builder ( catalog, NULL);
 
297
                gw_db_catalog_set_description ( catalog, NULL);
 
298
 
 
299
                g_free ( catalog);
 
300
 
 
301
                return 0;
 
302
        }
 
303
 
 
304
        return -1;
 
305
}
 
306
 
 
307
 
 
308
gboolean gw_db_catalog_equals ( GWDBCatalog *catalog, GWDBCatalog *to) {
 
309
        gboolean equals = FALSE;
 
310
 
 
311
 
 
312
        if ( catalog != NULL && to != NULL) {
 
313
                if ( str_equals ( gw_db_catalog_get_name ( catalog), gw_db_catalog_get_name ( to))
 
314
                        && str_equals ( gw_db_catalog_get_short_db_name ( catalog), gw_db_catalog_get_short_db_name ( to))
 
315
                        && str_equals ( gw_db_catalog_get_db_name ( catalog), gw_db_catalog_get_db_name ( to))
 
316
                        && str_equals ( gw_db_catalog_get_version ( catalog), gw_db_catalog_get_version ( to))
 
317
                        && str_equals ( gw_db_catalog_get_program_builder ( catalog), gw_db_catalog_get_program_builder ( to))
 
318
                        && str_equals ( gw_db_catalog_get_description ( catalog), gw_db_catalog_get_description ( to))
 
319
                        && gw_db_catalog_is_modified ( catalog) == gw_db_catalog_is_modified ( to)
 
320
                        && gw_db_catalog_get_size ( catalog) == gw_db_catalog_get_size ( to) ) {
 
321
                        equals = TRUE;
 
322
                }
 
323
        }
 
324
 
 
325
        return equals;
 
326
}