source: trunk/third/yelp/src/yelp-view-toc.c @ 18397

Revision 18397, 22.2 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18396, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2/*
3 * Copyright (C) 2001-2002 Mikael Hallendal <micke@codefactory.se>
4 * Copyright (C) 2002 Red Hat Inc.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 *
21 * Author: Mikael Hallendal <micke@codefactory.se>
22 */
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <libgnomevfs/gnome-vfs.h>
29#include <libgnome/gnome-i18n.h>
30#include <libxml/parser.h>
31
32#include <stdio.h>
33#include <string.h>
34#include <stdarg.h>
35
36#include "yelp-view-toc.h"
37#include "yelp-marshal.h"
38#include "yelp-util.h"
39#include "yelp-html.h"
40#include "yelp-scrollkeeper.h"
41
42#define d(x)
43
44static void   toc_init                      (YelpViewTOC      *html);
45static void   toc_class_init                (YelpViewTOCClass *klass);
46static void   toc_man_1                     (YelpViewTOC      *view);
47static void   toc_man_2                     (YelpViewTOC      *view,
48                                             GNode            *root);
49static void   toc_read_important_docs       (YelpViewTOC      *view);
50static void   toc_uri_selected_cb           (YelpHtml         *html,
51                                             YelpURI          *uri,
52                                             gboolean          handled,
53                                             YelpViewTOC      *view);
54static void   toc_html_title_changed_cb     (YelpHtml         *html,
55                                             const gchar      *title,
56                                             YelpViewTOC      *view);
57static void   toc_page_start                (YelpViewTOC      *view,
58                                             const gchar      *title,
59                                             const gchar      *heading);
60static void   toc_page_end                  (YelpViewTOC      *view);
61
62enum {
63        URI_SELECTED,
64        TITLE_CHANGED,
65        LAST_SIGNAL
66};
67
68static gint signals[LAST_SIGNAL] = { 0 };
69
70typedef struct {
71        char  *title;
72        GList *seriesids;
73} YelpImportantDocsSection;
74
75#define BUFFER_SIZE 4096
76
77struct _YelpViewTOCPriv {
78        YelpHtml  *html_view;
79        GtkWidget *html_widget;
80       
81        GNode     *doc_tree;
82        GList     *important_sections;
83};
84
85GType
86yelp_view_toc_get_type (void)
87{
88        static GType view_type = 0;
89
90        if (!view_type) {
91                static const GTypeInfo view_info =
92                        {
93                                sizeof (YelpViewTOCClass),
94                                NULL,
95                                NULL,
96                                (GClassInitFunc) toc_class_init,
97                                NULL,
98                                NULL,
99                                sizeof (YelpViewTOC),
100                                0,
101                                (GInstanceInitFunc) toc_init,
102                        };
103               
104                view_type = g_type_register_static (G_TYPE_OBJECT,
105                                                    "YelpViewTOC",
106                                                    &view_info, 0);
107        }
108       
109        return view_type;
110}
111
112static void
113toc_init (YelpViewTOC *view)
114{
115        YelpViewTOCPriv *priv;
116       
117        priv = g_new0 (YelpViewTOCPriv, 1);
118        view->priv = priv;
119       
120        toc_read_important_docs (view);
121
122        priv->html_view   = yelp_html_new ();
123        priv->html_widget = yelp_html_get_widget (priv->html_view);
124
125        g_signal_connect (priv->html_view, "uri_selected",
126                          G_CALLBACK (toc_uri_selected_cb),
127                          view);
128
129        g_signal_connect (priv->html_view, "title_changed",
130                          G_CALLBACK (toc_html_title_changed_cb),
131                          view);
132}
133
134static void
135toc_class_init (YelpViewTOCClass *klass)
136{
137        signals[URI_SELECTED] =
138                g_signal_new ("uri_selected",
139                              G_TYPE_FROM_CLASS (klass),
140                              G_SIGNAL_RUN_LAST,
141                              G_STRUCT_OFFSET (YelpViewTOCClass,
142                                               uri_selected),
143                              NULL, NULL,
144                              yelp_marshal_VOID__POINTER_BOOLEAN,
145                              G_TYPE_NONE,
146                              2, G_TYPE_POINTER, G_TYPE_BOOLEAN);
147
148        signals[TITLE_CHANGED] =
149                g_signal_new ("title_changed",
150                              G_TYPE_FROM_CLASS (klass),
151                              G_SIGNAL_RUN_LAST,
152                              G_STRUCT_OFFSET (YelpViewTOCClass,
153                                               title_changed),
154                              NULL, NULL,
155                              yelp_marshal_VOID__STRING,
156                              G_TYPE_NONE,
157                              1, G_TYPE_STRING);
158}
159
160#if 0
161static void
162toc_write_footer (YelpViewTOC *view)
163{
164        char *footer="\n"
165                "  </body>\n"
166                "</html>\n";
167
168        yelp_html_write (view->priv->html_view, footer, -1);
169}
170#endif
171
172static void
173toc_start (YelpViewTOC *view)
174{
175        YelpViewTOCPriv *priv;
176        GNode           *node;
177        YelpSection     *section;
178/*      char            *seriesid; */
179        GNode           *root;
180        char            *path;
181        GList           *sections;
182/*      GList           *seriesids; */
183        gchar           *page_title = _("Help Contents");
184        gchar           *section_gnome = _("GNOME - Desktop");
185        gchar           *section_additional = _("Additional documents");
186        gchar           *man_string = _("Manual Pages");
187        gchar           *info_string = _("Info Pages");
188/*      YelpImportantDocsSection *important_section; */
189/*      gboolean         important_doc_installed = FALSE; */
190       
191        priv = view->priv;
192
193        if (!g_node_first_child (priv->doc_tree)) {
194                g_warning ("No nodes in tree");
195        }
196       
197        yelp_html_clear (priv->html_view);
198
199        toc_page_start (view, page_title, page_title);
200
201        sections = priv->important_sections;
202       
203#if 0
204        while (sections != NULL) {
205                important_section = sections->data;
206
207                seriesids = important_section->seriesids;
208
209                /* Check if any of the important documents are installed  *
210                 * before trying to write the section topic               */
211
212                for (seriesids = important_section->seriesids;
213                     seriesids;
214                     seriesids = seriesids->next) {
215                        seriesid = seriesids->data;
216
217                        if (yelp_scrollkeeper_lookup_seriesid (seriesid)){
218                                important_doc_installed = TRUE;
219                        }
220                }
221               
222                if (important_doc_installed) {
223                        if (!left_column_started) {
224                                yelp_html_printf (priv->html_view,
225                                                  COLUMN_LEFT_START);
226                                left_column_started = TRUE;
227                        }
228                       
229                        yelp_html_printf (priv->html_view,
230                                          TOC_BLOCK_SEPARATOR
231                                          TOC_BLOCK_START
232                                          "<h2>%s</h2>",
233                                          important_section->title);
234                }
235               
236                seriesids = important_section->seriesids;
237               
238                while (seriesids != NULL) {
239                        seriesid = seriesids->data;
240
241                        node = yelp_scrollkeeper_lookup_seriesid (seriesid);
242
243                        if (node) {
244                                gchar *str_uri;
245                               
246                                section = node->data;
247
248                                str_uri = yelp_uri_to_string (section->uri);
249                             
250                                yelp_html_printf (priv->html_view,
251                                                  "<a href=\"%s\">%s</a>\n",
252                                                  str_uri,
253                                                  section->name);
254                                g_free (str_uri);
255                        }
256
257                        seriesids = seriesids->next;
258                }
259
260                if (important_doc_installed) {
261                        yelp_html_printf (priv->html_view,
262                                          TOC_BLOCK_END);
263                        if (sections->next) {
264                                yelp_html_printf (priv->html_view,
265                                                  TOC_BLOCK_SEPARATOR);
266                        }
267                }
268               
269                sections = sections->next;
270                important_doc_installed = FALSE;
271        }
272
273        if (left_column_started) {
274                yelp_html_printf (priv->html_view, COLUMN_END);
275        }
276
277       
278        yelp_html_printf (priv->html_view,
279                          COLUMN_RIGHT_START);
280#endif
281
282        root = yelp_util_find_toplevel (priv->doc_tree, "scrollkeeper");
283        node = g_node_first_child (root);
284
285        yelp_html_printf (priv->html_view,
286                          "<td colspan=\"2\"><h2>%s</h2><ul>",
287                          section_gnome);
288                             
289        root = yelp_util_find_node_from_name (priv->doc_tree, "GNOME");
290        node = g_node_first_child (root);
291
292        while (node) {
293                section = YELP_SECTION (node->data);
294                path = yelp_util_node_to_string_path (node);
295                yelp_html_printf (priv->html_view,
296                                  "<li><a href=\"toc:scrollkeeper/%s\">%s</a><br>\n",
297                                  path, section->name);
298                g_free (path);
299               
300                node = g_node_next_sibling (node);
301        }
302
303        yelp_html_printf (priv->html_view,"</ul>");
304
305        yelp_html_printf (priv->html_view,
306                          "<br><h2>%s</h2><ul>",
307                          section_additional);
308
309        root = yelp_util_find_toplevel (priv->doc_tree, "scrollkeeper");
310        node = g_node_first_child (root);
311
312        while (node) {
313                section = YELP_SECTION (node->data);
314                if (strcmp (section->name, "GNOME")) {
315                        path = yelp_util_node_to_string_path (node);
316                        yelp_html_printf (priv->html_view,
317                                          "<li><a href=\"toc:scrollkeeper/%s\">%s</a><br>\n",
318                                          path, section->name);
319                        g_free (path);
320                       
321                }
322                node = g_node_next_sibling (node);
323        }
324
325        if (yelp_util_find_toplevel (priv->doc_tree, "man")) {
326                yelp_html_printf (priv->html_view,
327                                  "<li><a href=\"toc:man\">%s</a><br>\n",
328                                  man_string);
329        }
330               
331        if (yelp_util_find_toplevel (priv->doc_tree, "info")) {
332                yelp_html_printf (priv->html_view,
333                                  "<li><a href=\"toc:info\">%s</a><br>\n",
334                                  info_string);
335        }
336
337        yelp_html_printf (priv->html_view,
338                          "</ul></td><td bgcolor=\"#3b3b4f\" width=\"10%%\">&nbsp;</td></tr>");
339       
340        toc_page_end (view);
341
342        yelp_html_close (priv->html_view);
343}
344
345static char *
346toc_full_path_name (YelpViewTOC *view, GNode *node)
347{
348        char *str, *t;         
349        YelpSection *section;
350
351        section = node->data;
352
353        str = g_strdup (section->name);
354
355        while (node->parent) {
356                node = node->parent;
357               
358                if (node->parent == NULL ||
359                    node->parent->data == NULL) {
360                        /* Skip top node */
361                        break;
362                }
363               
364                section = node->data;
365               
366                t = g_strconcat (section->name, "/", str, NULL);
367                g_free (str);
368                str = t;
369        }
370        return str;
371}
372
373static void
374toc_man_emit (YelpViewTOC *view, GNode *first)
375{
376        YelpViewTOCPriv *priv;
377        GNode           *node, *child;
378        YelpSection     *section;
379        gboolean         got_a_leaf;
380        char            *path, *url;
381        char            *tmp;
382        int              i;
383        gboolean         sub_started = FALSE;
384        gchar           *str_docs = _("Documents");
385        gchar           *str_subcats = _("Categories");
386
387        priv = view->priv;
388
389        got_a_leaf = FALSE;
390        node = first;
391        do {
392                if (node->children != NULL) {
393                        if (!sub_started) {
394                                yelp_html_printf (priv->html_view, "<h3>%s</h3>",
395                                                  str_subcats);
396                               
397                                sub_started = TRUE;
398                        }
399                       
400                        child = node->children;
401                       
402                        section = node->data;
403
404                        path = yelp_util_node_to_string_path (node);
405                        yelp_html_printf (priv->html_view, "<a href=\"toc:man/%s\">%s</a><br>\n", path, section->name);
406                        g_free (path);
407                } else {
408                        got_a_leaf = TRUE;
409                }
410        } while ((node = node->next) != NULL);
411
412        if (sub_started) {
413                yelp_html_printf (priv->html_view,
414                                  "<img alt=\"\" src=\"file:" IMAGEDIR "/empty.png\" height=\"10\">\n");
415        }
416
417        if (got_a_leaf) {
418                yelp_html_printf (priv->html_view, "<h3>%s</h3>", str_docs);
419
420                yelp_html_write (priv->html_view,
421                                 "<table cellpadding=\"2\" cellspacing=\"2\" border=\"0\" width=\"100%%\">\n",
422                                 -1);
423
424                i = 0;
425                node = first;
426                do {
427                        if (node->children == NULL) {
428                                YelpSection *section;
429                               
430                                if (i % 3 == 0) {
431                                        if (i == 0) {
432                                                yelp_html_write (priv->html_view,
433                                                                 "<tr>\n",
434                                                                 -1);
435                                        } else {
436                                                yelp_html_write (priv->html_view,
437                                                                 "</tr>\n<tr>\n",
438                                                                 -1);
439                                        }
440                                }
441                       
442                                section = node->data;
443                                url = yelp_util_compose_path_url (node->parent, yelp_uri_get_path (section->uri));
444                                tmp = yelp_uri_to_string (section->uri);
445                                yelp_html_printf (priv->html_view, "<td valign=\"Top\"><a href=\"%s\">%s</a></td>\n", tmp,
446                                                  section->name);
447                                g_free (url);
448                                g_free (tmp);
449                                i++;
450                        }
451                } while ((node = node->next) != NULL);
452               
453                yelp_html_write (priv->html_view, "</tr>\n", -1);
454                yelp_html_write (priv->html_view, "</table>\n", -1);
455
456        }
457}
458
459static void
460toc_man_2 (YelpViewTOC *view,
461           GNode       *root)
462{
463        YelpViewTOCPriv *priv;
464        GNode           *first;
465        gchar           *name;
466        gchar           *string = _("Manual pages");
467        gchar           *title;
468
469        g_return_if_fail (YELP_IS_VIEW_TOC (view));
470       
471        priv = view->priv;
472
473        if (root->children == NULL) {
474                return;
475        }
476       
477        first = root->children;
478
479        yelp_html_clear (priv->html_view);
480 
481        name = toc_full_path_name (view, root);
482       
483        title = g_strdup_printf ("%s/%s", string, name);
484
485        toc_page_start (view, title, string);
486
487        yelp_html_printf (priv->html_view,
488                          "<td colspan=\"2\"><h2>%s</h2><ul>",
489                          title);
490
491        g_free (title);
492        g_free (name);
493
494        toc_man_emit (view, first);
495
496        yelp_html_printf (priv->html_view,
497                          "</td><td bgcolor=\"#3b3b4f\" width=\"10%%\">&nbsp;</td></tr>\n");
498               
499        toc_page_end (view);
500
501        yelp_html_close (priv->html_view);
502}
503
504static void
505toc_man_1 (YelpViewTOC *view)
506{
507        YelpViewTOCPriv *priv;
508        GNode           *root, *node, *child;
509        YelpSection     *section;
510        char            *path;
511        gchar           *string = _("Manual Pages");
512        gchar           *str_subcats = _("Categories");
513
514        priv = view->priv;
515
516        root = yelp_util_find_toplevel (priv->doc_tree, "man");
517
518        if (!root) {
519                g_warning ("Unable to find man toplevel");
520                return;
521        }
522       
523        node = g_node_first_child (root);
524
525        if (!node) {
526                g_warning ("Unable to find man categories");
527                return;
528        }
529
530        yelp_html_clear (priv->html_view);
531
532        toc_page_start (view, string, string);
533
534        yelp_html_printf (priv->html_view,
535                          "<td colspan=\"2\"><h2>%s</h2><ul>",
536                          str_subcats);
537       
538        do {
539                child = g_node_first_child (node);
540               
541                if (child) {
542                        section = YELP_SECTION (node->data);
543                        path = yelp_util_node_to_string_path (node);
544
545                        yelp_html_printf (priv->html_view,
546                                          "<li><a href=\"toc:man/%s\">%s</a><br>\n",
547                                          path, section->name);
548                       
549                        g_free (path);
550                }
551        } while ((node = g_node_next_sibling (node)));
552
553        yelp_html_printf (priv->html_view,
554                          "</ul></td><td bgcolor=\"#3b3b4f\" width=\"10%%\">&nbsp;</td></tr>");
555
556        toc_page_end (view);
557
558        yelp_html_close (priv->html_view);
559}
560
561static void
562toc_info (YelpViewTOC *view)
563{
564        YelpViewTOCPriv *priv;
565        GNode           *root, *node;
566        YelpSection     *section;
567        gchar           *string = _("Info Pages");
568        gchar           *str_docs = _("Documents");
569
570        priv = view->priv;
571
572        root = yelp_util_find_toplevel (priv->doc_tree, "info");
573
574        if (!root) {
575                g_warning ("Unable to find info toplevel");
576                return;
577        }
578       
579        node = g_node_first_child (root);
580
581        if (!node) {
582                d(g_print ("No first node\n"));
583                return;
584        }
585
586        yelp_html_clear (priv->html_view);
587
588        toc_page_start (view, string, string);
589
590        yelp_html_printf (priv->html_view,
591                          "<td colspan=\"2\"><h2>%s</h2><ul>", str_docs);
592
593        do {
594                gchar *str_uri;
595               
596                section = YELP_SECTION (node->data);
597
598                str_uri = yelp_uri_to_string (section->uri);
599               
600                yelp_html_printf (priv->html_view,
601                                  "<li><a href=\"%s\">%s</a><br>\n",
602                                  str_uri,
603                                  section->name);
604                g_free (str_uri);
605        } while ((node = g_node_next_sibling (node)));
606       
607        yelp_html_printf (priv->html_view,
608                          "</ul></td><td bgcolor=\"#3b3b4f\" width=\"10%%\">&nbsp;</td></tr>");
609
610        toc_page_end (view);
611
612        yelp_html_close (priv->html_view);
613}
614
615static void
616toc_read_important_docs (YelpViewTOC *view)
617{
618        xmlDocPtr   doc;
619        xmlNodePtr  node;
620        xmlNodePtr  child;
621        xmlNodePtr  section;
622        xmlNodePtr  title;
623        xmlChar    *prop;
624        YelpImportantDocsSection *important_section;
625       
626        doc = xmlParseFile (DATADIR "/yelp/important_docs.xml");
627        if (doc == NULL) {
628                return;
629        }
630
631        node = xmlDocGetRootElement (doc);
632        if (node == NULL) {
633                xmlFreeDoc(doc);
634                return;
635        }
636
637        if (strcmp (node->name, "docs") != 0) {
638                xmlFreeDoc(doc);
639                return;
640        }
641
642        section = node->children;
643        while (section) {
644                if (strcmp (section->name, "section") == 0) {
645                        important_section = g_new0 (YelpImportantDocsSection, 1);
646                        child = section->children;
647                        while (child) {
648                                if (strcmp (child->name, "title") == 0) {
649                                        title = child->children;
650                                        if (title && title->type == XML_TEXT_NODE)
651                                                important_section->title = g_strdup (title->content);
652                                } else if (strcmp (child->name, "document") == 0) {
653                                        prop = xmlGetProp (child, "seriesid");
654                                        if (prop) {
655                                                important_section->seriesids =
656                                                        g_list_append (important_section->seriesids, g_strdup (prop));
657                                                xmlFree (prop);
658                                        }
659                                       
660                                }
661                                child = child->next;
662
663                        }
664                        view->priv->important_sections =
665                                g_list_append (view->priv->important_sections,
666                                               important_section);
667                }
668                section = section->next;
669        }
670       
671        xmlFreeDoc(doc);
672}
673
674static void
675toc_uri_selected_cb (YelpHtml    *html,
676                     YelpURI     *uri,
677                     gboolean     handled,
678                     YelpViewTOC *view)
679{
680        g_signal_emit (view, signals[URI_SELECTED], 0, uri, FALSE);
681}
682
683static void
684toc_html_title_changed_cb (YelpHtml    *html,
685                           const gchar *title,
686                           YelpViewTOC *view)
687{
688        g_signal_emit (view, signals[TITLE_CHANGED], 0, title);
689}
690
691static void
692toc_page_start (YelpViewTOC *view, const gchar *title, const gchar *heading)
693{
694        YelpViewTOCPriv *priv;
695       
696        g_return_if_fail (YELP_IS_VIEW_TOC (view));
697        g_return_if_fail (title != NULL);
698        g_return_if_fail (heading != NULL);
699       
700        priv = view->priv;
701       
702        yelp_html_printf (priv->html_view,
703                          "<html>\n"
704                          "<head>\n"
705                          "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n"
706                          "<title>%s</title>\n"
707                          "</head>\n"
708                          "<body marginwidth=\"0\"\n"
709                          "background=\"file:" IMAGEDIR "/bcg.png\" marginheight=\"0\"\n"
710                          "border=\"10\" topmargin=\"0\" leftmargin=\"0\">\n"
711                          "<table width=\"100%%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\">\n"
712                          "<tr valign=\"top\">\n"
713                          "<td width=\"75\">\n"
714                          "<img alt=\"\" src=\"file:" IMAGEDIR "/empty.png\" width=\"75\" height=\"1\">\n"
715                          "</td>\n"
716                          "<td colspan=\"2\"><h1>%s</h1></td>\n"
717                          "<td bgcolor=\"#3b3b4f\" width=\"10%%\">&nbsp;</td>\n"
718                          "</tr>\n"
719                          "<tr valign=\"top\">\n"
720                          "<td width=\"75\">\n"
721                          "<img alt=\"\" src=\"file:" IMAGEDIR "/empty.png\" width=\"75\" height=\"1\">\n"
722                          "</td>\n",
723                          title,
724                          heading);
725}
726
727static void
728toc_page_end (YelpViewTOC *view)
729{
730        YelpViewTOCPriv *priv;
731        gchar           *str_gnome_is  = _("GNOME is");
732        gchar           *str_fs        = _("Free Software");
733        gchar           *str_copyright = _("(C)");
734       
735        g_return_if_fail (YELP_IS_VIEW_TOC (view));
736       
737        priv = view->priv;
738       
739        yelp_html_printf (priv->html_view,
740                          "<tr>\n"
741                          "<td width=\"75\">\n"
742                          "<img alt=\"\" src=\"file:" IMAGEDIR "/empty.png\" width=\"75\" height=\"1\">\n"
743                          "</td>\n"
744                          "<td colspan=\"2\">\n"
745                          "<img src=\"file:" IMAGEDIR "/empty.png\" height=\"200\">\n"
746                          "</td>\n"
747                          "<td bgcolor=\"#3b3b4f\" width=\"10%%\">&nbsp;</td></tr>\n"
748                          "<tr valign=\"top\">\n"
749                          "<td width=\"75\"><img alt=\"\" src=\"file:" IMAGEDIR "/empty.png\" width=\"75\" height=\"1\"></td>\n"
750                          "<td>\n"
751                          "<a href=\"http://www.gnome.org\" target=\"_blank\">"
752                          "<img src=\"file:" IMAGEDIR "/gnome2-button.png\" border=\"0\">\n"
753                          "</a>\n"
754                          "</td>\n"
755                          "<td>\n"
756                          "<font size=\"-1\">%s <a href=\"http://www.gnu.org/philosophy/free-sw.html\">%s</a> | <a href=\"http://www.gnome.org\">http://www.gnome.org</a><br>\n"
757                          "%s 2001-2002 Mikael Hallendal</font>\n"
758                          "</td>\n"
759                          "<td bgcolor=\"#3b3b4f\" width=\"10%%\">&nbsp;</td>\n"
760                          "</tr>\n"
761                          "</table></body></html>\n",
762                          str_gnome_is,
763                          str_fs,
764                          str_copyright);
765}
766
767YelpViewTOC *
768yelp_view_toc_new (GNode *doc_tree)
769{
770        YelpViewTOC     *view;
771        YelpViewTOCPriv *priv;
772
773        view = g_object_new (YELP_TYPE_VIEW_TOC, NULL);
774
775        priv = view->priv;
776
777        priv->doc_tree = doc_tree;
778
779        return view;
780}
781
782static void
783toc_scrollkeeper (YelpViewTOC *view, GNode *root)
784{
785        YelpViewTOCPriv *priv;
786        GNode           *node, *child;
787        YelpSection     *section;
788        gboolean         got_a_leaf;
789        char            *path;
790        gchar           *name;
791        gboolean         sub_started = FALSE;
792        gchar           *str_docs = _("Documents");
793        gchar           *str_subcats = _("Categories");
794               
795        priv = view->priv;
796       
797        if (root->children == NULL) {
798                return;
799        }
800       
801        name = toc_full_path_name (view, root);
802
803        yelp_html_clear (priv->html_view);
804
805        toc_page_start (view, name, name);
806
807        yelp_html_printf (priv->html_view, "<td colspan=\"2\">");
808
809        g_free (name);
810
811        got_a_leaf = FALSE;
812        node = root->children;
813
814        for (node = root->children; node; node = node->next) {
815               
816                if (node->children != NULL) {
817                        if (!sub_started) {
818                                yelp_html_printf (priv->html_view, "<h2>%s</h2><ul>",
819                                                  str_subcats);
820                                                     
821                                sub_started = TRUE;
822                        }
823                       
824                        child = node->children;
825                       
826                        section = node->data;
827
828                        path = yelp_util_node_to_string_path (node);
829
830                        yelp_html_printf (priv->html_view,
831                                          "<li><a href=\"toc:scrollkeeper/%s\">%s</a>\n",
832                                          path, section->name);
833                        g_free (path);
834                } else {
835                        got_a_leaf = TRUE;
836                }
837        }
838
839        if (sub_started) {
840                yelp_html_printf (priv->html_view,
841                                  "</ul><br><img alt=\"\" src=\"file:" IMAGEDIR "/empty.png\" height=\"10\"><br>\n");
842        }
843
844        if (got_a_leaf) {
845                yelp_html_printf (priv->html_view,
846                                  "<h2>%s</h2><ul>",
847                                  str_docs);
848               
849                for (node = root->children; node; node = node->next) {
850                        if (node->children == NULL) {
851                                gchar *str_uri;
852                               
853                                YelpSection *section;
854                       
855                                section = node->data;
856                                str_uri = yelp_uri_to_string (section->uri);
857                               
858                                yelp_html_printf (priv->html_view,
859                                                  "<li><a href=\"%s\">%s</a>\n",
860                                                  str_uri,
861                                                  section->name);
862                                g_free (str_uri);
863                        }
864                }
865        }
866
867        yelp_html_printf (priv->html_view,
868                          "</ul></td><td bgcolor=\"#3b3b4f\" width=\"10%%\">&nbsp;</td></tr>");
869       
870        toc_page_end (view);
871
872        yelp_html_close (priv->html_view);
873}
874
875void
876yelp_view_toc_open_uri (YelpViewTOC *view, YelpURI *uri)
877{
878        YelpViewTOCPriv *priv;
879        GNode           *node;
880        const gchar     *path;
881       
882        g_assert (yelp_uri_get_type (uri) == YELP_URI_TYPE_TOC);
883
884        priv = view->priv;
885
886        yelp_html_set_base_uri (priv->html_view, uri);
887
888        path = yelp_uri_get_path (uri);
889
890        d(g_print ("PATH:[%s]\n", path));
891       
892        if (!strcmp (path, "")) {
893                toc_start (view);
894        }
895        else if (strncmp (path, "man", 3) == 0) {
896                path += 3;
897                if (path[0] == 0) {
898                        toc_man_1 (view);
899                } else if (path[0] == '/') {
900                        /* Calculate where it should go */
901                        path++;
902
903                        node = yelp_util_string_path_to_node  (path,
904                                                               view->priv->doc_tree);
905                        if (node) {
906                                toc_man_2 (view, node);
907                        } else {
908                                g_warning ("Bad path in toc url %s\n",
909                                           yelp_uri_to_string (uri));
910                        }
911                }
912        } else if (strcmp (path, "info") == 0) {
913                toc_info (view);
914        } else if (strncmp (path, "scrollkeeper", strlen ("scrollkeeper")) == 0) {
915                path = path + strlen ("scrollkeeper");
916                if (path[0] == '/') {
917                        /* Calculate where it should go */
918                        path++;
919                       
920                        node = yelp_util_string_path_to_node  (path,
921                                                               view->priv->doc_tree);
922                        if (node) {
923                                toc_scrollkeeper (view, node);
924                        } else {
925                                g_warning ("Bad path in toc url %s\n",
926                                           yelp_uri_to_string (uri));
927                        }
928                }
929        } else {
930                g_warning ("Unknown toc type %s\n",
931                           yelp_uri_to_string (uri));
932        }
933}
934
935GtkWidget *
936yelp_view_toc_get_widget (YelpViewTOC  *view)
937{
938        g_return_val_if_fail (YELP_IS_VIEW_TOC (view), NULL);
939       
940        return view->priv->html_widget;
941}
Note: See TracBrowser for help on using the repository browser.