~ubuntu-branches/ubuntu/breezy/mlview/breezy

« back to all changes in this revision

Viewing changes to src/mlview-validator-window.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2004-11-07 17:40:18 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20041107174018-863hs1azanfkrsem
Tags: 0.7.1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8-*- */
 
2
 
 
3
/*This file is part of GNU MlView
 
4
 *
 
5
 *GNU MlView is free software; 
 
6
 *you can redistribute it and/or modify it under the terms of 
 
7
 *the GNU General Public License as 
 
8
 *published by the Free Software Foundation; either version 2, 
 
9
 *or (at your option) any later version.
 
10
 *
 
11
 *GNU MlView is distributed in the hope 
 
12
 *that it will be useful, but WITHOUT ANY WARRANTY; 
 
13
 *without even the implied warranty of 
 
14
 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
15
 *See the GNU General Public License for more details.
 
16
 *
 
17
 *You should have received a copy of the 
 
18
 *GNU General Public License along with MlView; 
 
19
 *see the file COPYING. 
 
20
 *If not, write to the Free Software Foundation, 
 
21
 *Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
22
 *
 
23
 *See COPYRIGHT file for copyright information.
 
24
 */
 
25
#include <string.h>
 
26
 
 
27
#include <glade/glade.h>
 
28
 
 
29
#include "mlview-validator-window.h"
 
30
#include "mlview-validator.h"
 
31
 
 
32
struct _MlViewValidatorWindow {
 
33
        MlViewXMLDocument *document;
 
34
        
 
35
        GtkWidget *validation_report;
 
36
        GtkWidget *document_label;
 
37
        GtkWidget *status_label;
 
38
 
 
39
        struct {
 
40
                GtkWidget *view;
 
41
                GtkListStore *store;
 
42
                MlViewValidationOutput *data;
 
43
                struct MlViewTypeIcons *icons;
 
44
        } output;
 
45
        
 
46
        struct {
 
47
                GtkWidget *combo;
 
48
                GtkListStore *store;
 
49
                GHashTable *references;
 
50
        } schemas;
 
51
};
 
52
 
 
53
typedef struct _MlViewValidatorWindow MlViewValidatorWindow;
 
54
 
 
55
enum SchemasModelColumns {
 
56
        URL_COLUMN = 0,
 
57
        TYPE_COLUMN,
 
58
        SCHEMA_COLUMN,
 
59
        SCHEMAS_MODEL_NB_COLUMNS
 
60
};
 
61
 
 
62
enum OutputModelColumns {
 
63
        ICON_COLUMN = 0,
 
64
        NODE_COLUMN,
 
65
        LEVEL_COLUMN,
 
66
        ERROR_COLUMN,
 
67
        MESSAGE_COLUMN,
 
68
        OUTPUT_MODEL_NB_COLUMNS
 
69
};
 
70
 
 
71
static void
 
72
add_schema_to_list_store_func (MlViewSchema *a_schema,
 
73
                               MlViewValidatorWindow *a_window)
 
74
{
 
75
        GtkTreeIter iter = { 0 };
 
76
        gchar *url = NULL, *type = NULL;
 
77
        GtkTreePath *path = NULL;
 
78
        GtkTreeRowReference *ref = NULL;
 
79
        enum MlViewSchemaType schema_type = SCHEMA_TYPE_UNDEF ;
 
80
        enum MlViewStatus status = MLVIEW_OK ;
 
81
 
 
82
        g_return_if_fail (a_schema);
 
83
        g_return_if_fail (a_window);
 
84
        g_return_if_fail (a_window->schemas.store);
 
85
        g_return_if_fail (a_window->schemas.references);
 
86
 
 
87
        url = mlview_schema_get_url (a_schema);
 
88
 
 
89
        g_return_if_fail (url);
 
90
 
 
91
        gtk_list_store_append (a_window->schemas.store, &iter);
 
92
 
 
93
        path = gtk_tree_model_get_path
 
94
                (GTK_TREE_MODEL (a_window->schemas.store), &iter);
 
95
 
 
96
        if (!path) {
 
97
                gtk_list_store_remove (a_window->schemas.store, &iter);
 
98
                
 
99
                return;
 
100
        }
 
101
 
 
102
        ref = gtk_tree_row_reference_new
 
103
                (GTK_TREE_MODEL (a_window->schemas.store), path);
 
104
 
 
105
        gtk_tree_path_free (path);
 
106
        path = NULL;
 
107
 
 
108
        if (!ref) {
 
109
                gtk_list_store_remove (a_window->schemas.store, &iter);
 
110
 
 
111
                return;
 
112
        }
 
113
 
 
114
        g_hash_table_insert (a_window->schemas.references, url, ref);
 
115
 
 
116
        status = mlview_schema_get_type (a_schema, &schema_type) ;
 
117
        g_return_if_fail (status == MLVIEW_OK 
 
118
                          && schema_type != SCHEMA_TYPE_UNDEF) ;
 
119
        switch (schema_type) {
 
120
        case SCHEMA_TYPE_DTD:
 
121
                type = (gchar*) "(DTD)";
 
122
                break;
 
123
        case SCHEMA_TYPE_RNG:
 
124
                type = (gchar*) "(RNG)";
 
125
                break;
 
126
        case SCHEMA_TYPE_XSD:
 
127
                type = (gchar*) "(XSD)";
 
128
                break;
 
129
        default:
 
130
                g_assert_not_reached () ;
 
131
        }
 
132
 
 
133
        gtk_list_store_set (a_window->schemas.store, &iter, URL_COLUMN, url, 
 
134
                            TYPE_COLUMN, type, SCHEMA_COLUMN, a_schema, -1); 
 
135
}
 
136
 
 
137
static void
 
138
document_changed_cb (MlViewValidatorWindow *a_window)
 
139
{
 
140
        g_return_if_fail (a_window);
 
141
        g_return_if_fail (a_window->status_label);
 
142
 
 
143
        gtk_label_set_text (GTK_LABEL (a_window->status_label),
 
144
                            _("Document changed ; press 'Refresh'"));
 
145
}
 
146
 
 
147
static void
 
148
schema_associated_cb (MlViewSchemaList *a_list, MlViewSchema *a_schema,
 
149
                      MlViewValidatorWindow *a_window)
 
150
{
 
151
        gint active = -1;
 
152
 
 
153
        g_return_if_fail (a_schema);
 
154
        g_return_if_fail (a_window);
 
155
        g_return_if_fail (a_window->schemas.combo);
 
156
 
 
157
        add_schema_to_list_store_func (a_schema, a_window);
 
158
        
 
159
        active = gtk_combo_box_get_active (GTK_COMBO_BOX 
 
160
                                           (a_window->schemas.combo));
 
161
 
 
162
        if (active == -1) 
 
163
                gtk_combo_box_set_active (GTK_COMBO_BOX 
 
164
                                          (a_window->schemas.combo), 0);
 
165
}
 
166
 
 
167
static void
 
168
schema_unassociated_cb (MlViewSchemaList *a_list, MlViewSchema *a_schema,
 
169
                        MlViewValidatorWindow *a_window)
 
170
{
 
171
        GtkTreeRowReference *ref = NULL;
 
172
        gchar *url = NULL;
 
173
        GtkTreePath *path = NULL;
 
174
        gboolean res = FALSE;
 
175
        GtkTreeIter iter = { 0 };
 
176
 
 
177
        g_return_if_fail (a_schema);
 
178
        g_return_if_fail (a_window);
 
179
        g_return_if_fail (a_window->schemas.references);
 
180
        g_return_if_fail (a_window->schemas.store);
 
181
 
 
182
        url = mlview_schema_get_url (a_schema);
 
183
 
 
184
        g_return_if_fail (url);
 
185
 
 
186
        ref = g_hash_table_lookup (a_window->schemas.references,
 
187
                                   url);
 
188
 
 
189
        g_return_if_fail (ref);
 
190
 
 
191
        path = gtk_tree_row_reference_get_path (ref);
 
192
 
 
193
        g_return_if_fail (path);
 
194
 
 
195
        res = gtk_tree_model_get_iter 
 
196
                (GTK_TREE_MODEL (a_window->schemas.store), &iter, path);
 
197
 
 
198
        gtk_tree_path_free (path);
 
199
        path = NULL;
 
200
 
 
201
        g_return_if_fail (res);
 
202
 
 
203
        res = g_hash_table_remove (a_window->schemas.references, url);
 
204
 
 
205
        g_return_if_fail (res);
 
206
 
 
207
        gtk_list_store_remove (a_window->schemas.store, &iter);
 
208
}
 
209
 
 
210
static void
 
211
validation_report_destroy_cb (GtkWidget *a_validation_report,
 
212
                              MlViewValidatorWindow *a_window)
 
213
{
 
214
        MlViewSchemaList *list = NULL;
 
215
        MlViewAppContext *ctxt = NULL;
 
216
 
 
217
        g_return_if_fail (a_window);
 
218
        
 
219
        if (a_window->document) {
 
220
                if (a_window->output.icons) {
 
221
                        ctxt = mlview_xml_document_get_app_context 
 
222
                                (a_window->document);
 
223
 
 
224
                        if (ctxt) 
 
225
                                mlview_app_context_type_icons_unref 
 
226
                                        (ctxt);
 
227
                }
 
228
 
 
229
                g_signal_handlers_disconnect_by_func 
 
230
                        (G_OBJECT (a_window->document),
 
231
                         G_CALLBACK (document_changed_cb),
 
232
                         a_window);
 
233
 
 
234
                list = mlview_xml_document_get_schema_list 
 
235
                        (a_window->document);
 
236
 
 
237
                if (list) {
 
238
                        g_signal_handlers_disconnect_by_func
 
239
                                (G_OBJECT (list),
 
240
                                 G_CALLBACK (schema_associated_cb),
 
241
                                 a_window);
 
242
 
 
243
                        g_signal_handlers_disconnect_by_func 
 
244
                                (G_OBJECT (list),
 
245
                                 G_CALLBACK (schema_unassociated_cb),
 
246
                                 a_window);
 
247
                }
 
248
        }
 
249
        
 
250
        if (a_window->schemas.references)
 
251
                g_hash_table_destroy (a_window->schemas.references);
 
252
 
 
253
        if (a_window->output.data) 
 
254
                mlview_validation_output_free (a_window->output.data);
 
255
        
 
256
        memset (a_window, 0, sizeof (MlViewValidatorWindow));
 
257
        
 
258
        g_free (a_window);
 
259
        a_window = NULL;
 
260
}
 
261
 
 
262
static void 
 
263
close_button_clicked_cb (GtkWidget *a_button, 
 
264
                         MlViewValidatorWindow *a_window)
 
265
{
 
266
        g_return_if_fail (a_window);
 
267
        g_return_if_fail (a_window->validation_report);
 
268
 
 
269
        gtk_widget_destroy (a_window->validation_report);
 
270
}
 
271
 
 
272
static void
 
273
validate_button_clicked_cb (GtkWidget *a_button,
 
274
                            MlViewValidatorWindow *a_window)
 
275
{
 
276
        GtkTreeIter iter = { 0 };
 
277
        gboolean res = FALSE;
 
278
        GtkWidget *dialog = NULL,
 
279
                *label = NULL;
 
280
        MlViewSchema *schema = NULL;
 
281
        MlViewValidatorStatus status = VALIDATOR_ERROR;
 
282
        gint i = 0;
 
283
        MlViewValidationMessage *message = NULL;
 
284
        MlViewAppContext *ctxt = NULL;
 
285
        GdkPixbuf *pix = NULL;
 
286
        gchar *priority = NULL;
 
287
 
 
288
        g_return_if_fail (a_window);
 
289
        g_return_if_fail (a_window->document);
 
290
        g_return_if_fail (a_window->schemas.combo);
 
291
        g_return_if_fail (a_window->schemas.store);
 
292
        g_return_if_fail (a_window->output.view);
 
293
        g_return_if_fail (a_window->validation_report);
 
294
        g_return_if_fail (a_window->status_label);
 
295
        
 
296
        res = gtk_combo_box_get_active_iter 
 
297
                (GTK_COMBO_BOX (a_window->schemas.combo), &iter);
 
298
 
 
299
        if (!res) {
 
300
                dialog = gtk_dialog_new_with_buttons (_("No schema selected"),
 
301
                                                      GTK_WINDOW (a_window->validation_report),
 
302
                                                      GTK_DIALOG_MODAL,
 
303
                                                      GTK_STOCK_OK,
 
304
                                                      GTK_RESPONSE_NONE,
 
305
                                                      NULL);
 
306
                
 
307
                if (!dialog)
 
308
                        goto cleanup;
 
309
                
 
310
                label = gtk_label_new 
 
311
                        (_("You must associate a schema with your document in order to validate it."));
 
312
                
 
313
                if (!label)
 
314
                        goto cleanup;
 
315
 
 
316
                gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), label);
 
317
 
 
318
                g_signal_connect (G_OBJECT (dialog), "response",
 
319
                                  G_CALLBACK (gtk_widget_destroy), NULL);
 
320
 
 
321
                gtk_widget_show_all (dialog);
 
322
 
 
323
                dialog = NULL;
 
324
                label = NULL;
 
325
 
 
326
                return;
 
327
        }
 
328
 
 
329
        if (!a_window->output.icons) {
 
330
                ctxt = mlview_xml_document_get_app_context (a_window->document);
 
331
 
 
332
                g_return_if_fail (ctxt);
 
333
 
 
334
                a_window->output.icons = mlview_app_context_type_icons_ref (ctxt);
 
335
        }
 
336
 
 
337
        gtk_tree_model_get (GTK_TREE_MODEL (a_window->schemas.store), &iter,
 
338
                            SCHEMA_COLUMN, &schema, -1);
 
339
 
 
340
        g_return_if_fail (schema);
 
341
 
 
342
        if (a_window->output.data) {
 
343
                mlview_validation_output_free (a_window->output.data);
 
344
                a_window->output.data = NULL;
 
345
        }
 
346
 
 
347
        a_window->output.data = mlview_validator_validate_with_schema
 
348
                (a_window->document, schema, &status);
 
349
       
 
350
        g_return_if_fail (a_window->output.data);
 
351
 
 
352
        switch (status) {
 
353
        case VALIDATOR_ERROR:
 
354
                gtk_label_set_text (GTK_LABEL (a_window->status_label),
 
355
                                    _("Validation error"));
 
356
                break;
 
357
        case VALIDATOR_VALID_DOC:
 
358
                gtk_label_set_text (GTK_LABEL (a_window->status_label),
 
359
                                    _("Valid document"));
 
360
                break;
 
361
        case VALIDATOR_INVALID_DOC:
 
362
                gtk_label_set_text (GTK_LABEL (a_window->status_label),
 
363
                                    _("Invalid document"));
 
364
                break;
 
365
        }
 
366
        
 
367
        a_window->output.store = gtk_list_store_new 
 
368
                (OUTPUT_MODEL_NB_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING,
 
369
                 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
 
370
 
 
371
        g_return_if_fail (a_window->output.store);
 
372
 
 
373
        for (i = 0 ; i < a_window->output.data->messages->len ; i++) {
 
374
                message = g_array_index (a_window->output.data->messages,
 
375
                                         MlViewValidationMessage*, i);
 
376
                
 
377
                if (!message) {
 
378
                        g_object_unref (G_OBJECT (a_window->output.store));
 
379
                        a_window->output.store = NULL;
 
380
                        
 
381
                        mlview_utils_trace_info ("validate_button_clicked_cb failed.");
 
382
 
 
383
                        return;
 
384
                }
 
385
 
 
386
                gtk_list_store_append (a_window->output.store, &iter);
 
387
 
 
388
                if (a_window->output.icons) 
 
389
                        switch (message->type) {
 
390
                        case XML_ELEMENT_NODE:
 
391
                                pix = a_window->output.icons->element;
 
392
                                break;
 
393
                        case XML_TEXT_NODE:
 
394
                                pix = a_window->output.icons->text;
 
395
                                break;
 
396
                        case XML_COMMENT_NODE:
 
397
                                pix = a_window->output.icons->comment;
 
398
                                break;
 
399
                        case XML_PI_NODE:
 
400
                                pix = a_window->output.icons->pi;
 
401
                                break;
 
402
                        case XML_ENTITY_REF_NODE:
 
403
                                pix = a_window->output.icons->entity_ref;
 
404
                                break;
 
405
                        default:
 
406
                                pix = NULL;
 
407
                                break;
 
408
                        }
 
409
 
 
410
                switch (message->priority) {
 
411
                case XML_ERR_NONE:
 
412
                        priority = _("Message");
 
413
                        break;
 
414
                case XML_ERR_WARNING:
 
415
                        priority = _("Warning");
 
416
                        break;
 
417
                case XML_ERR_ERROR:
 
418
                        priority = _("Error");
 
419
                        break;
 
420
                case XML_ERR_FATAL:
 
421
                        priority = _("Fatal");
 
422
                        break;
 
423
                default:
 
424
                        priority = NULL;
 
425
                        break;
 
426
                }
 
427
                
 
428
                gtk_list_store_set (a_window->output.store, &iter,
 
429
                                    ICON_COLUMN, pix,
 
430
                                    LEVEL_COLUMN, priority,
 
431
                                    NODE_COLUMN, message->node->name,
 
432
                                    ERROR_COLUMN, message->message,
 
433
                                    MESSAGE_COLUMN, message, -1);
 
434
        }
 
435
 
 
436
        gtk_tree_view_set_model (GTK_TREE_VIEW (a_window->output.view),
 
437
                                 GTK_TREE_MODEL (a_window->output.store));
 
438
 
 
439
        return;
 
440
        
 
441
 cleanup:
 
442
        if (label) {
 
443
                gtk_widget_destroy (label);
 
444
                label = NULL;
 
445
        }
 
446
 
 
447
        if (dialog) {
 
448
                gtk_widget_destroy (dialog);
 
449
                dialog = NULL;
 
450
        }
 
451
 
 
452
        mlview_utils_trace_info ("validate_button_clicked_cb failed.");
 
453
}
 
454
 
 
455
static void
 
456
row_activated_cb (GtkTreeView *a_view, 
 
457
                  GtkTreePath *a_path,
 
458
                  GtkTreeViewColumn *a_column,
 
459
                  MlViewValidatorWindow *a_win)
 
460
{
 
461
        GtkTreeIter iter = { 0 };
 
462
        gboolean res = FALSE;
 
463
        MlViewValidationMessage *message = NULL;
 
464
        GtkWidget *dialog = NULL, *label = NULL;
 
465
 
 
466
        g_return_if_fail (a_win);
 
467
        g_return_if_fail (a_path);
 
468
        g_return_if_fail (a_win->output.store);
 
469
        g_return_if_fail (GTK_IS_TREE_MODEL (a_win->output.store));
 
470
        g_return_if_fail (a_win->document);
 
471
        g_return_if_fail (a_win->validation_report);
 
472
 
 
473
        res = gtk_tree_model_get_iter (GTK_TREE_MODEL (a_win->output.store),
 
474
                                       &iter, a_path);
 
475
 
 
476
        g_return_if_fail (res);
 
477
 
 
478
        gtk_tree_model_get (GTK_TREE_MODEL (a_win->output.store), &iter,
 
479
                            MESSAGE_COLUMN, &message, -1);
 
480
 
 
481
        g_return_if_fail (message);
 
482
 
 
483
        if (message->node) 
 
484
                mlview_xml_document_select_node (a_win->document, 
 
485
                                                 message->node);
 
486
        else {
 
487
                dialog = gtk_dialog_new_with_buttons 
 
488
                        (_("No node for message"),
 
489
                         GTK_WINDOW (a_win->validation_report),
 
490
                         GTK_DIALOG_MODAL,
 
491
                         GTK_STOCK_OK,
 
492
                         GTK_RESPONSE_ACCEPT,
 
493
                         NULL);
 
494
 
 
495
                g_return_if_fail (dialog);
 
496
                
 
497
                label = gtk_label_new 
 
498
                        (_("No existing node is associated with this message."));
 
499
 
 
500
                if (!label)
 
501
                        goto cleanup;
 
502
 
 
503
                gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox),
 
504
                                   label);
 
505
 
 
506
                gtk_widget_show (label);
 
507
 
 
508
                gtk_dialog_run (GTK_DIALOG (dialog));
 
509
                
 
510
        cleanup:
 
511
                if (dialog) {
 
512
                        gtk_widget_destroy (dialog);
 
513
                        dialog = NULL;
 
514
                }
 
515
        }
 
516
}
 
517
 
 
518
GtkWidget *
 
519
mlview_validator_window_new (MlViewXMLDocument *a_doc)
 
520
{
 
521
        gchar *file = NULL, *uri = NULL;
 
522
        GladeXML *xml = NULL;
 
523
        MlViewValidatorWindow *win = NULL;
 
524
        MlViewSchemaList *list = NULL;
 
525
        GtkCellRenderer *renderer = NULL;
 
526
        GtkTreeIter iter = { 0 };
 
527
        gboolean res = FALSE;
 
528
        GtkTreeViewColumn *column = NULL;
 
529
 
 
530
        g_return_val_if_fail (a_doc && MLVIEW_IS_XML_DOCUMENT (a_doc), NULL);
 
531
 
 
532
        list = mlview_xml_document_get_schema_list (a_doc);
 
533
 
 
534
        g_return_val_if_fail (list, NULL);
 
535
 
 
536
        /* Allocation */ 
 
537
 
 
538
        win = g_try_malloc (sizeof (MlViewValidatorWindow));
 
539
        
 
540
        if (!win)
 
541
                goto cleanup;
 
542
        
 
543
        memset (win, 0, sizeof (MlViewValidatorWindow));
 
544
        
 
545
        win->document = a_doc;
 
546
 
 
547
        /* Glade */ 
 
548
 
 
549
        file = gnome_program_locate_file (NULL, GNOME_FILE_DOMAIN_APP_DATADIR,
 
550
                                          PACKAGE "/mlview-validation-report.glade",
 
551
                                          TRUE, NULL);
 
552
        
 
553
        if (!file)
 
554
                goto cleanup;
 
555
        
 
556
        xml = glade_xml_new (file, NULL, NULL);
 
557
        
 
558
        g_free (file);
 
559
        file = NULL;
 
560
        
 
561
        if (!xml)
 
562
                goto cleanup;
 
563
 
 
564
        /* Misc widgets */ 
 
565
        
 
566
        win->validation_report = glade_xml_get_widget (xml, "ValidationReport");
 
567
        
 
568
        if (!(win->validation_report && GTK_IS_WINDOW (win->validation_report)))
 
569
                goto cleanup;
 
570
        
 
571
        win->document_label = glade_xml_get_widget (xml, "DocumentLabel");
 
572
        
 
573
        if (!(win->document_label && GTK_IS_LABEL (win->document_label)))
 
574
                goto cleanup;
 
575
 
 
576
        uri = mlview_xml_document_get_uri (a_doc);
 
577
 
 
578
        if (uri) {
 
579
                gtk_label_set_text (GTK_LABEL (win->document_label), uri);
 
580
 
 
581
                uri = NULL;
 
582
        }
 
583
        
 
584
        win->schemas.combo = glade_xml_get_widget (xml, "SchemasCombo");
 
585
        
 
586
        if (!(win->schemas.combo && GTK_IS_COMBO_BOX (win->schemas.combo)))
 
587
                goto cleanup;
 
588
        
 
589
        win->status_label = glade_xml_get_widget (xml, "StatusLabel");
 
590
        
 
591
        if (!(win->status_label && GTK_IS_LABEL (win->status_label)))
 
592
                goto cleanup;
 
593
 
 
594
        /* Output view */ 
 
595
 
 
596
        win->output.view = glade_xml_get_widget (xml, "OutputView");
 
597
 
 
598
        if (!(win->output.view && GTK_IS_TREE_VIEW (win->output.view)))
 
599
                goto cleanup;
 
600
 
 
601
        g_signal_connect (G_OBJECT (win->output.view), "row-activated",
 
602
                          G_CALLBACK (row_activated_cb), win);
 
603
 
 
604
        win->output.store = gtk_list_store_new 
 
605
                (OUTPUT_MODEL_NB_COLUMNS, GDK_TYPE_PIXBUF, G_TYPE_STRING,
 
606
                 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
 
607
 
 
608
        if (!win->output.store)
 
609
                goto cleanup;
 
610
 
 
611
        gtk_tree_view_set_model (GTK_TREE_VIEW (win->output.view),
 
612
                                 GTK_TREE_MODEL (win->output.store));
 
613
 
 
614
        g_object_unref (G_OBJECT (win->output.store));
 
615
 
 
616
        column = gtk_tree_view_column_new ();
 
617
 
 
618
        if (!column)
 
619
                goto cleanup;
 
620
 
 
621
        gtk_tree_view_column_set_title (column, _("Node"));
 
622
 
 
623
        renderer = gtk_cell_renderer_pixbuf_new ();
 
624
 
 
625
        if (!renderer)
 
626
                goto cleanup;
 
627
 
 
628
        gtk_tree_view_column_pack_start (column, renderer, FALSE);
 
629
 
 
630
        gtk_tree_view_column_set_attributes (column, renderer, "pixbuf",
 
631
                                             ICON_COLUMN, NULL);
 
632
 
 
633
        renderer = NULL;
 
634
 
 
635
        renderer = gtk_cell_renderer_text_new ();
 
636
 
 
637
        gtk_tree_view_column_pack_start (column, renderer, FALSE);
 
638
 
 
639
        gtk_tree_view_column_set_attributes (column, renderer, "text",
 
640
                                             NODE_COLUMN, NULL);
 
641
 
 
642
        renderer = NULL;
 
643
        
 
644
        gtk_tree_view_append_column (GTK_TREE_VIEW (win->output.view),
 
645
                                     column);
 
646
 
 
647
        column = NULL;
 
648
 
 
649
        column = gtk_tree_view_column_new ();
 
650
 
 
651
        if (!column)
 
652
                goto cleanup;
 
653
        
 
654
        gtk_tree_view_column_set_title (column, _("Priority"));
 
655
 
 
656
        renderer = gtk_cell_renderer_text_new ();
 
657
 
 
658
        if (!renderer)
 
659
                goto cleanup;
 
660
 
 
661
        gtk_tree_view_column_pack_start (column, renderer, FALSE);
 
662
 
 
663
        gtk_tree_view_column_set_attributes (column, renderer, "text",
 
664
                                             LEVEL_COLUMN, NULL);
 
665
 
 
666
        renderer = NULL;
 
667
 
 
668
        gtk_tree_view_append_column (GTK_TREE_VIEW (win->output.view),
 
669
                                     column);
 
670
 
 
671
        column = NULL;
 
672
 
 
673
        column = gtk_tree_view_column_new ();
 
674
 
 
675
        if (!column)
 
676
                goto cleanup;
 
677
 
 
678
        gtk_tree_view_column_set_title (column, _("Message"));
 
679
 
 
680
        renderer = gtk_cell_renderer_text_new ();
 
681
 
 
682
        if (!renderer)
 
683
                goto cleanup;
 
684
 
 
685
        gtk_tree_view_column_pack_start (column, renderer, FALSE);
 
686
 
 
687
        gtk_tree_view_column_set_attributes (column, renderer, "text",
 
688
                                             ERROR_COLUMN, NULL);
 
689
        
 
690
        renderer = NULL;
 
691
 
 
692
        gtk_tree_view_append_column (GTK_TREE_VIEW (win->output.view),
 
693
                                     column);
 
694
 
 
695
        column = NULL;
 
696
 
 
697
        /* Signals */
 
698
        
 
699
        glade_xml_signal_connect_data (xml, "validate_button_clicked_cb",
 
700
                                       G_CALLBACK (validate_button_clicked_cb),
 
701
                                       win);
 
702
          
 
703
        glade_xml_signal_connect_data (xml, "close_button_clicked_cb",
 
704
                                       G_CALLBACK (close_button_clicked_cb),
 
705
                                       win);
 
706
        
 
707
        g_signal_connect (G_OBJECT (win->validation_report), "destroy",
 
708
                          G_CALLBACK (validation_report_destroy_cb), win);
 
709
        
 
710
        /* Schema list */
 
711
        
 
712
        win->schemas.references = g_hash_table_new_full 
 
713
                (g_str_hash, g_str_equal, NULL, (GDestroyNotify) gtk_tree_row_reference_free);
 
714
 
 
715
        if (!win->schemas.references)
 
716
                goto cleanup;
 
717
 
 
718
        win->schemas.store = gtk_list_store_new (SCHEMAS_MODEL_NB_COLUMNS, G_TYPE_STRING, 
 
719
                                                 G_TYPE_STRING, G_TYPE_POINTER);
 
720
 
 
721
        if (!win->schemas.store)
 
722
                goto cleanup;
 
723
 
 
724
        mlview_schema_list_foreach (list, (MlViewSchemaListFunc) add_schema_to_list_store_func,
 
725
                                    win);
 
726
 
 
727
        gtk_combo_box_set_model (GTK_COMBO_BOX (win->schemas.combo), 
 
728
                                 GTK_TREE_MODEL (win->schemas.store));
 
729
 
 
730
        g_object_unref (G_OBJECT (win->schemas.store));
 
731
 
 
732
        res = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (win->schemas.store), &iter);
 
733
 
 
734
        if (res)
 
735
                gtk_combo_box_set_active_iter (GTK_COMBO_BOX (win->schemas.combo), &iter);
 
736
 
 
737
        renderer = gtk_cell_renderer_text_new ();
 
738
        
 
739
        if (!renderer)
 
740
                goto cleanup;
 
741
        
 
742
        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (win->schemas.combo), renderer, TRUE);
 
743
 
 
744
        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (win->schemas.combo), renderer,
 
745
                                        "text", URL_COLUMN, NULL);
 
746
        
 
747
        renderer = gtk_cell_renderer_text_new ();
 
748
 
 
749
        if (!renderer)
 
750
                goto cleanup;
 
751
 
 
752
        gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (win->schemas.combo), renderer, FALSE);
 
753
        
 
754
        gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (win->schemas.combo), renderer,
 
755
                                        "text", TYPE_COLUMN, NULL);
 
756
 
 
757
        renderer = NULL;
 
758
 
 
759
        g_signal_connect (G_OBJECT (list), "schema-associated",
 
760
                          G_CALLBACK (schema_associated_cb), win);
 
761
 
 
762
        g_signal_connect (G_OBJECT (list), "schema-unassociated",
 
763
                          G_CALLBACK (schema_unassociated_cb), win);
 
764
 
 
765
        /* Document */
 
766
 
 
767
        g_signal_connect_swapped (G_OBJECT (a_doc), "node-changed",
 
768
                                  G_CALLBACK (document_changed_cb), win);
 
769
 
 
770
        g_signal_connect_swapped (G_OBJECT (a_doc), "document-changed",
 
771
                                  G_CALLBACK (document_changed_cb), win);
 
772
        
 
773
        /* Return, cleanup */
 
774
 
 
775
        return win->validation_report;
 
776
        
 
777
 cleanup:
 
778
        if (renderer) {
 
779
                gtk_object_destroy (GTK_OBJECT (renderer));
 
780
                renderer = NULL;
 
781
        }
 
782
        
 
783
        if (column) {
 
784
                gtk_object_destroy (GTK_OBJECT (column));
 
785
                column = NULL;
 
786
        }
 
787
 
 
788
        if (file) {
 
789
                g_free (file);
 
790
                file = NULL;
 
791
        }
 
792
        
 
793
        if (xml) {
 
794
                g_object_unref (xml);
 
795
                xml = NULL;
 
796
        }
 
797
 
 
798
        if (win) {
 
799
                if (win->validation_report) {
 
800
                        gtk_widget_destroy (win->validation_report);
 
801
                        
 
802
                        memset (win, 0, sizeof (MlViewValidatorWindow));
 
803
                }
 
804
 
 
805
                if (win->schemas.references) {
 
806
                        g_hash_table_destroy (win->schemas.references);
 
807
                        win->schemas.references = NULL;
 
808
                }
 
809
                
 
810
                g_free (win);
 
811
                win = NULL;
 
812
        }
 
813
        
 
814
        return NULL;
 
815
}