~ubuntu-branches/ubuntu/maverick/conglomerate/maverick

« back to all changes in this revision

Viewing changes to src/cong-file-properties.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2005-11-08 05:07:06 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051108050706-bcg60nwqf1z3w0d6
Tags: 0.9.1-1ubuntu1
* Resynchronise with Debian (Closes: #4397).
  - Thanks, Jordan Mantha.

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
                const gchar *new_url,
71
71
                gpointer user_data);
72
72
 
 
73
static guint 
 
74
count_words (PangoLanguage *language,
 
75
             const gchar *text)
 
76
{
 
77
        int n_chars;
 
78
        int len_bytes;
 
79
        PangoLogAttr *log_attrs;
 
80
        guint num_words;
 
81
        int i;
 
82
 
 
83
        g_return_val_if_fail (text, 0);
 
84
 
 
85
        len_bytes = strlen (text);
 
86
 
 
87
        n_chars = g_utf8_strlen (text, len_bytes);
 
88
 
 
89
        log_attrs = g_new0 (PangoLogAttr, n_chars+1);
 
90
 
 
91
        pango_get_log_attrs (text,
 
92
                             len_bytes,
 
93
                             -1,
 
94
                             language,
 
95
                             log_attrs,
 
96
                             n_chars+1);
 
97
 
 
98
        num_words = 0;
 
99
 
 
100
        for (i=0;i<n_chars;i++) {
 
101
                if (log_attrs[i].is_word_start) {
 
102
                        num_words++;
 
103
                }
 
104
        }
 
105
 
 
106
        g_free (log_attrs);
 
107
 
 
108
        return num_words;
 
109
}
 
110
 
 
111
typedef struct CongDocumentStatistics CongDocumentStatistics;
 
112
struct CongDocumentStatistics
 
113
{
 
114
        guint num_nodes;
 
115
        guint num_elements;
 
116
        guint num_words;
 
117
};
 
118
 
 
119
gboolean
 
120
refresh_statistics_node_cb (CongDocument *doc,
 
121
                            CongNodePtr node,
 
122
                            gpointer data,
 
123
                            guint recursion_level)
 
124
{
 
125
        CongDocumentStatistics *stats = (CongDocumentStatistics*)data;
 
126
        PangoLanguage* language;
 
127
 
 
128
        stats->num_nodes++;
 
129
 
 
130
        switch (cong_node_type (node)) {
 
131
        default: 
 
132
                break;
 
133
        case CONG_NODE_TYPE_TEXT:
 
134
                language = cong_document_get_language_for_node (doc, node);
 
135
                stats->num_words += count_words (language, (const gchar*)node->content);
 
136
                break;
 
137
        case CONG_NODE_TYPE_ELEMENT:
 
138
                stats->num_elements++;
 
139
                break;
 
140
        }
 
141
 
 
142
        return FALSE;
 
143
}
 
144
 
 
145
static void
 
146
refresh_statistics (CongFilePropertiesDialogDetails *dialog_details,
 
147
                    CongDocument *doc)
 
148
{
 
149
        struct CongDocumentStatistics stats;
 
150
        gchar *text;
 
151
        
 
152
        stats.num_nodes = 0;
 
153
        stats.num_elements = 0;
 
154
        stats.num_words = 0;
 
155
        
 
156
        cong_document_for_each_node (doc, refresh_statistics_node_cb, &stats);
 
157
 
 
158
        text = g_strdup_printf ("%i", stats.num_words);
 
159
        gtk_label_set_text ( GTK_LABEL (glade_xml_get_widget (dialog_details->xml,"label_words")), 
 
160
                             text);
 
161
        g_free (text);
 
162
 
 
163
        text = g_strdup_printf ("%i", stats.num_elements);
 
164
        gtk_label_set_text ( GTK_LABEL (glade_xml_get_widget (dialog_details->xml,"label_elements")), 
 
165
                             text);
 
166
        g_free (text);  
 
167
}
73
168
 
74
169
static void
75
170
refresh_filename_and_location (CongFilePropertiesDialogDetails *dialog_details,
165
260
                                      _("_Remove this DTD"));
166
261
                
167
262
                set_dtd_info (dialog_details->xml,
168
 
                              xml_doc->extSubset->ExternalID,
169
 
                              xml_doc->extSubset->SystemID);    
 
263
                              (const gchar*)xml_doc->extSubset->ExternalID,
 
264
                              (const gchar*)xml_doc->extSubset->SystemID);      
170
265
 
171
266
                gtk_label_set_text ( label_dtd_notes, 
172
267
                                     "");
248
343
 
249
344
        dialog = glade_xml_get_widget(dialog_details->xml, "common_dialog");
250
345
 
 
346
        /* Statistics*/
 
347
        refresh_statistics (dialog_details, doc);
 
348
 
251
349
        /* Filename & Location: */
252
350
        refresh_filename_and_location (dialog_details, doc);
253
351
        
280
378
        /* XML Header: */
281
379
        {
282
380
                gtk_label_set_text ( GTK_LABEL (glade_xml_get_widget (dialog_details->xml,"label_xml_version")), 
283
 
                                     xml_doc->version);
 
381
                                     (const gchar*)xml_doc->version);
284
382
                
285
383
                {
286
 
                        const gchar *encoding_text = xml_doc->encoding;
 
384
                        const gchar *encoding_text = (const gchar*)xml_doc->encoding;
287
385
                        if (NULL==encoding_text) {
288
386
                                encoding_text = _("Unspecified");
289
387
                        }
380
478
                                                                        _("Associate with DTD"),
381
479
                                                                        NULL);
382
480
                        cong_command_add_set_external_dtd (cmd,
383
 
                                                           cong_document_get_root_element (doc)->name,
 
481
                                                           (const gchar*)cong_document_get_root_element (doc)->name,
384
482
                                                           cong_external_document_model_get_public_id (model_dtd),
385
483
                                                           cong_external_document_model_get_system_id (model_dtd));
386
484
                        cong_document_end_command (doc,
403
501
 
404
502
        refresh_modified (dialog_details, 
405
503
                          doc);
 
504
 
 
505
        refresh_statistics (dialog_details,
 
506
                            doc);
406
507
}
407
508
 
408
509