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

Revision 18397, 22.6 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 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public
16 * License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
19 *
20 * Author: Mikael Hallendal <micke@codefactory.se>
21 */
22
23#ifdef HAVE_CONFIG_H
24#include <config.h>
25#endif
26
27#include <gdk-pixbuf/gdk-pixbuf.h>
28#include <gtk/gtk.h>
29#include <bonobo/bonobo-main.h>
30#include <gconf/gconf-client.h>
31#include <libgnomevfs/gnome-vfs.h>
32#include <libgnomeui/gnome-about.h>
33#include <libgnomeui/gnome-stock-icons.h>
34#include <libgnome/gnome-i18n.h>
35#include <libgnome/gnome-url.h>
36#include <libgnome/gnome-program.h>
37#include <string.h>
38#include "yelp-error.h"
39#include "yelp-html.h"
40#include "yelp-util.h"
41#include "yelp-section.h"
42#include "yelp-history.h"
43#include "yelp-view-content.h"
44#include "yelp-view-index.h"
45#include "yelp-view-toc.h"
46#include "yelp-window.h"
47
48#define d(x)
49
50typedef enum {
51        YELP_WINDOW_ACTION_BACK = 1,
52        YELP_WINDOW_ACTION_FORWARD
53} YelpHistoryAction;
54
55static GConfEnumStringPair toolbar_styles[] = {
56        { GTK_TOOLBAR_TEXT, "text" },
57        { GTK_TOOLBAR_ICONS, "icons" },
58        { GTK_TOOLBAR_BOTH, "both" },
59        { GTK_TOOLBAR_BOTH_HORIZ, "both_horiz" }
60};
61
62static void        window_init                    (YelpWindow        *window);
63static void        window_class_init              (YelpWindowClass   *klass);
64
65static void        window_populate                (YelpWindow        *window);
66
67static gboolean    window_handle_uri              (YelpWindow        *window,
68                                                   YelpURI           *uri);
69static void        window_uri_selected_cb         (gpointer           view,
70                                                   YelpURI           *uri,
71                                                   gboolean           handled,
72                                                   YelpWindow        *window);
73static void        window_title_changed_cb        (gpointer           view,
74                                                   const gchar       *title,
75                                                   YelpWindow        *window);
76static void        window_toggle_history_back     (YelpHistory       *history,
77                                                   gboolean           sensitive,
78                                                   YelpWindow        *window);
79 
80static void        window_toggle_history_forward  (YelpHistory       *history,
81                                                   gboolean           sensitive,
82                                                   YelpWindow        *window);
83
84static void        window_history_action          (YelpWindow        *window,
85                                                   YelpHistoryAction  action);
86static void        window_back_button_clicked     (GtkWidget         *button,
87                                                   YelpWindow        *window);
88static void        window_forward_button_clicked  (GtkWidget         *button,
89                                                   YelpWindow        *window);
90static void        window_home_button_clicked     (GtkWidget         *button,
91                                                   YelpWindow        *window);
92static void        window_index_button_clicked    (GtkWidget         *button,
93                                                   YelpWindow        *window);
94static void        window_new_window_cb           (gpointer           data,
95                                                   guint              section,
96                                                   GtkWidget         *widget);
97static void        window_close_window_cb         (gpointer           data,
98                                                   guint              section,
99                                                   GtkWidget         *widget);
100static void        window_history_go_cb           (gpointer           data,
101                                                   guint              section,
102                                                   GtkWidget         *widget);
103static void        window_go_home_cb              (gpointer           data,
104                                                   guint              section,
105                                                   GtkWidget         *widget);
106static void        window_go_index_cb             (gpointer           data,
107                                                   guint              section,
108                                                   GtkWidget         *widget);
109static void        window_about_cb                (gpointer           data,
110                                                   guint              section,
111                                                   GtkWidget         *widget);
112static GtkWidget * window_create_toolbar          (YelpWindow        *window);
113
114static GdkPixbuf * window_load_icon               (void);
115
116static void       
117window_toolbar_style_changed_cb                   (GConfClient      *client,
118                                                   guint             cnxn_id,
119                                                   GConfEntry       *entry,
120                                                   gpointer          data);
121
122
123
124
125enum {
126        PAGE_TOC_VIEW,
127        PAGE_CONTENT_VIEW,
128        PAGE_INDEX_VIEW
129};
130
131enum {
132        NEW_WINDOW_REQUESTED,
133        LAST_SIGNAL
134};
135
136static gint signals[LAST_SIGNAL] = { 0 };
137
138struct _YelpWindowPriv {
139        GNode          *doc_tree;
140        GList          *index;
141
142        GtkWidget      *notebook;
143
144        YelpViewTOC    *toc_view;
145        GtkWidget      *content_view;
146        GtkWidget      *index_view;
147       
148        GtkWidget      *view_current;
149
150        YelpHistory    *history;
151
152        GtkItemFactory *item_factory;
153
154        GtkWidget      *forward_button;
155        GtkWidget      *back_button;
156};
157
158static GtkItemFactoryEntry menu_items[] = {
159        {N_("/_File"),              NULL,         0,                  0,                           "<Branch>"},
160        {N_("/File/_New window"),   NULL,         window_new_window_cb,   0,                           "<StockItem>", GTK_STOCK_NEW     },
161        {N_("/File/_Close window"), NULL,         window_close_window_cb, 0,                           "<StockItem>", GTK_STOCK_CLOSE   },
162/*      {N_("/File/_Quit"),         NULL,         window_exit_cb,         0,                           "<StockItem>", GTK_STOCK_QUIT    }, */
163        {N_("/_Go"),                NULL,         0,                  0,                           "<Branch>"},
164        {N_("/Go/_Back"),           NULL,         window_history_go_cb,   YELP_WINDOW_ACTION_BACK,     "<StockItem>", GTK_STOCK_GO_BACK    },
165        {N_("/Go/_Forward"),        NULL,         window_history_go_cb,   YELP_WINDOW_ACTION_FORWARD,  "<StockItem>", GTK_STOCK_GO_FORWARD },
166        {N_("/Go/_Home"),           NULL,         window_go_home_cb,      0,                           "<StockItem>", GTK_STOCK_HOME },
167        {N_("/Go/_Index"),          NULL,         window_go_index_cb,     0,                           "<StockItem>", GTK_STOCK_INDEX },
168        {N_("/_Help"),              NULL,         0,                  0,                           "<Branch>"},
169        {N_("/Help/_About"),        NULL,         window_about_cb,        0,                           "<StockItem>", GNOME_STOCK_ABOUT },
170};
171
172GType
173yelp_window_get_type (void)
174{
175        static GType window_type = 0;
176
177        if (!window_type) {
178                static const GTypeInfo window_info =
179                        {
180                                sizeof (YelpWindowClass),
181                                NULL,
182                                NULL,
183                                (GClassInitFunc) window_class_init,
184                                NULL,
185                                NULL,
186                                sizeof (YelpWindow),
187                                0,
188                                (GInstanceInitFunc) window_init,
189                        };
190               
191                window_type = g_type_register_static (GTK_TYPE_WINDOW,
192                                                      "YelpWindow",
193                                                      &window_info, 0);
194        }
195       
196        return window_type;
197}
198
199static void
200window_init (YelpWindow *window)
201{
202        YelpWindowPriv *priv;
203/*      YelpURI        *uri; */
204       
205        priv = g_new0 (YelpWindowPriv, 1);
206        window->priv = priv;
207       
208        priv->toc_view     = NULL;
209        priv->content_view = NULL;
210        priv->index_view   = NULL;
211        priv->view_current = NULL;
212       
213        priv->history = yelp_history_new ();
214
215        g_signal_connect (priv->history,
216                          "back_exists_changed",
217                          G_CALLBACK (window_toggle_history_back),
218                          window);
219
220        g_signal_connect (priv->history,
221                          "forward_exists_changed",
222                          G_CALLBACK (window_toggle_history_forward),
223                          window);
224
225        gtk_window_set_default_size (GTK_WINDOW (window), 600, 420);
226
227        gtk_window_set_title (GTK_WINDOW (window), _("Help Browser"));
228}
229
230static void
231window_class_init (YelpWindowClass *klass)
232{
233        signals[NEW_WINDOW_REQUESTED] =
234                g_signal_new ("new_window_requested",
235                              G_TYPE_FROM_CLASS (klass),
236                              G_SIGNAL_RUN_LAST,
237                              G_STRUCT_OFFSET (YelpWindowClass,
238                                               new_window_requested),
239                              NULL, NULL,
240                              g_cclosure_marshal_VOID__VOID,
241                              G_TYPE_NONE, 0);
242}
243
244static void
245window_populate (YelpWindow *window)
246{
247        YelpWindowPriv *priv;
248        GtkWidget      *toolbar;
249        GtkWidget      *main_box;
250        GtkWidget      *sw;
251        GtkAccelGroup  *accel_group;
252        GtkWidget      *menu_item;
253       
254        priv = window->priv;
255
256        main_box        = gtk_vbox_new (FALSE, 0);
257       
258        gtk_container_add (GTK_CONTAINER (window), main_box);
259
260        accel_group  = gtk_accel_group_new ();
261        priv->item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR,
262                                                   "<main>", accel_group);
263
264        gtk_item_factory_set_translate_func (priv->item_factory,
265                                             (GtkTranslateFunc) gettext,
266                                             NULL, NULL);
267
268        gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
269
270        gtk_item_factory_create_items (priv->item_factory,
271                                       G_N_ELEMENTS (menu_items),
272                                       menu_items,
273                                       window);
274
275        menu_item = gtk_item_factory_get_item_by_action (priv->item_factory,
276                                                         YELP_WINDOW_ACTION_BACK);
277        gtk_widget_set_sensitive (menu_item, FALSE);
278
279        menu_item = gtk_item_factory_get_item_by_action (priv->item_factory,
280                                                         YELP_WINDOW_ACTION_FORWARD);
281        gtk_widget_set_sensitive (menu_item, FALSE);
282
283        gtk_box_pack_start (GTK_BOX (main_box),
284                            gtk_item_factory_get_widget (priv->item_factory,
285                                                         "<main>"),
286                            FALSE, FALSE, 0);
287
288        toolbar         = window_create_toolbar (window);
289
290        priv->notebook  = gtk_notebook_new ();
291
292        gtk_notebook_set_show_tabs (GTK_NOTEBOOK (priv->notebook), FALSE);
293        gtk_notebook_set_show_border (GTK_NOTEBOOK (priv->notebook), FALSE);
294
295        sw = gtk_scrolled_window_new (NULL, NULL);
296       
297        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
298                                        GTK_POLICY_AUTOMATIC,
299                                        GTK_POLICY_AUTOMATIC);
300
301        gtk_container_add (GTK_CONTAINER (sw),
302                           yelp_view_toc_get_widget (priv->toc_view));
303
304        gtk_notebook_insert_page (GTK_NOTEBOOK (priv->notebook),
305                                  sw, NULL, PAGE_TOC_VIEW);
306       
307        gtk_notebook_insert_page (GTK_NOTEBOOK (priv->notebook),
308                                  priv->content_view,
309                                  NULL, PAGE_CONTENT_VIEW);
310
311        if (priv->index) {
312                gtk_notebook_insert_page (GTK_NOTEBOOK (priv->notebook),
313                                          priv->index_view,
314                                          NULL, PAGE_INDEX_VIEW);
315        }
316       
317        gtk_box_pack_start (GTK_BOX (main_box), toolbar, FALSE, FALSE, 0);
318        gtk_box_pack_end (GTK_BOX (main_box), priv->notebook,
319                          TRUE, TRUE, 0);
320}
321
322static gboolean
323window_handle_uri (YelpWindow *window, YelpURI *uri)
324{
325        YelpWindowPriv *priv;
326        GError         *error = NULL;
327        gboolean        handled = FALSE;
328
329        priv = window->priv;
330
331        d(g_print ("Handling URL: %s\n", yelp_uri_to_string (uri)));
332
333        if (!yelp_uri_exists (uri)) {
334                gchar *str_uri = yelp_uri_to_string (uri);
335               
336                g_set_error (&error,
337                             YELP_ERROR,
338                             YELP_ERROR_URI_NOT_EXIST,
339                             _("The document '%s' does not exist"), str_uri);
340                g_free (str_uri);
341        }
342        else if (yelp_uri_get_type (uri) == YELP_URI_TYPE_TOC) {
343                d(g_print ("[TOC]\n"));
344               
345                yelp_view_toc_open_uri (YELP_VIEW_TOC (priv->toc_view), uri);
346
347                gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
348                                               PAGE_TOC_VIEW);
349                handled = TRUE;
350        }
351        else if (yelp_uri_get_type (uri) == YELP_URI_TYPE_INDEX) {
352                d(g_print ("[INDEX]\n"));
353                gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
354                                               PAGE_INDEX_VIEW);
355                yelp_view_index_show_uri (YELP_VIEW_INDEX (priv->index_view),
356                                          uri,
357                                          &error);
358                handled = TRUE;
359        }
360        else if (yelp_uri_get_type (uri) == YELP_URI_TYPE_MAN ||
361                 yelp_uri_get_type (uri) == YELP_URI_TYPE_INFO ||
362                 yelp_uri_get_type (uri) == YELP_URI_TYPE_DOCBOOK_XML ||
363                 yelp_uri_get_type (uri) == YELP_URI_TYPE_DOCBOOK_SGML ||
364                 yelp_uri_get_type (uri) == YELP_URI_TYPE_HTML ||
365                 yelp_uri_get_type (uri) == YELP_URI_TYPE_PATH) {
366                d(g_print ("[CONTENT]\n"));
367                gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->notebook),
368                                               PAGE_CONTENT_VIEW);
369                yelp_view_content_show_uri (YELP_VIEW_CONTENT (priv->content_view),
370                                            uri,
371                                            &error);
372                handled = TRUE;
373        } else {
374                gnome_url_show (yelp_uri_to_string (uri), &error);
375                handled = FALSE;
376        }
377
378        if (error) {
379                GtkWidget *dialog;
380               
381                dialog = gtk_message_dialog_new (GTK_WINDOW (window),
382                                                 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
383                                                 GTK_MESSAGE_ERROR,
384                                                 GTK_BUTTONS_OK,
385                                                 error->message);
386                gtk_dialog_run (GTK_DIALOG (dialog));
387                gtk_widget_destroy (dialog);
388        }
389
390        return handled;
391}
392
393static void
394window_uri_selected_cb (gpointer    view,
395                        YelpURI    *uri,
396                        gboolean    handled,
397                        YelpWindow *window)
398{
399        YelpWindowPriv *priv;
400
401        g_return_if_fail (YELP_IS_WINDOW (window));
402
403        d(g_print ("uri_selected: %s, handled: %d\n",
404                   yelp_uri_to_string (uri), handled));
405
406        priv = window->priv;
407
408        yelp_uri_ref (uri);
409       
410        if (handled) {
411                yelp_history_goto (priv->history, uri);
412        } else {
413                if (window_handle_uri (window, uri)) {
414                        yelp_history_goto (priv->history, uri);
415                }
416        }
417
418        yelp_uri_unref (uri);
419}
420
421static void
422window_title_changed_cb (gpointer view, const gchar *title, YelpWindow *window)
423{
424        gchar *new_title;
425       
426        g_return_if_fail (title != NULL);
427        g_return_if_fail (YELP_IS_WINDOW (window));
428       
429        new_title = g_strconcat (_("Help Browser"), ":", title, NULL);
430
431        gtk_window_set_title (GTK_WINDOW (window), new_title);
432
433        g_free (new_title);
434}
435
436static void
437window_toggle_history_back (YelpHistory *history,
438                            gboolean     sensitive,
439                            YelpWindow  *window)
440{
441        YelpWindowPriv *priv;
442        GtkWidget      *menu_item;
443
444        g_return_if_fail (YELP_IS_HISTORY (history));
445        g_return_if_fail (YELP_IS_WINDOW (window));
446
447        priv = window->priv;
448
449        gtk_widget_set_sensitive (priv->back_button, sensitive);
450
451        menu_item = gtk_item_factory_get_item_by_action (priv->item_factory,
452                                                         YELP_WINDOW_ACTION_BACK);
453        gtk_widget_set_sensitive (menu_item, sensitive);
454}
455
456static void
457window_toggle_history_forward (YelpHistory *history,
458                               gboolean     sensitive,
459                               YelpWindow  *window)
460{
461        YelpWindowPriv *priv;
462        GtkWidget      *menu_item;
463
464        g_return_if_fail (YELP_IS_HISTORY (history));
465        g_return_if_fail (YELP_IS_WINDOW (window));
466
467        priv = window->priv;
468
469        gtk_widget_set_sensitive (priv->forward_button, sensitive);
470
471        menu_item = gtk_item_factory_get_item_by_action (priv->item_factory,
472                                                         YELP_WINDOW_ACTION_FORWARD);
473        gtk_widget_set_sensitive (menu_item, sensitive);
474}
475
476static void
477window_history_action (YelpWindow *window, YelpHistoryAction action)
478{
479        YelpWindowPriv *priv;
480        YelpURI        *uri;
481       
482        g_return_if_fail (YELP_IS_WINDOW (window));
483
484        priv = window->priv;
485
486        switch (action) {
487        case YELP_WINDOW_ACTION_BACK:
488                uri = yelp_history_go_back (priv->history);
489                break;
490        case YELP_WINDOW_ACTION_FORWARD:
491                uri = yelp_history_go_forward (priv->history);
492                break;
493        default:
494                return;
495        }
496       
497        if (uri) {
498                window_handle_uri (window, uri);
499        }
500}
501
502static void
503window_back_button_clicked (GtkWidget *button, YelpWindow *window)
504{
505        g_return_if_fail (GTK_IS_BUTTON (button));
506        g_return_if_fail (YELP_IS_WINDOW (window));
507
508        window_history_action (window, YELP_WINDOW_ACTION_BACK);
509}
510
511static void
512window_forward_button_clicked (GtkWidget *button, YelpWindow *window)
513{
514        g_return_if_fail (GTK_IS_BUTTON (button));
515        g_return_if_fail (YELP_IS_WINDOW (window));
516
517        window_history_action (window, YELP_WINDOW_ACTION_FORWARD);
518}
519
520static void
521window_home_button_clicked (GtkWidget *button, YelpWindow *window)
522{
523        YelpURI *uri;
524       
525        g_return_if_fail (YELP_IS_WINDOW (window));
526       
527        uri = yelp_uri_new ("toc:");
528
529        yelp_history_goto (window->priv->history, uri);
530        yelp_view_toc_open_uri (window->priv->toc_view, uri);
531
532        yelp_uri_unref (uri);
533
534        gtk_notebook_set_current_page (GTK_NOTEBOOK (window->priv->notebook),
535                                       PAGE_TOC_VIEW);
536}
537
538static void
539window_index_button_clicked (GtkWidget *button, YelpWindow *window)
540{
541        YelpURI *uri;
542       
543        g_return_if_fail (YELP_IS_WINDOW (window));
544
545        uri = yelp_uri_new ("index:");
546        yelp_history_goto (window->priv->history, uri);
547        yelp_uri_unref (uri);
548       
549        gtk_notebook_set_current_page (GTK_NOTEBOOK (window->priv->notebook),
550                                       PAGE_INDEX_VIEW);
551}
552
553static void
554window_new_window_cb (gpointer data, guint section, GtkWidget *widget)
555{
556        g_return_if_fail (YELP_IS_WINDOW (data));
557
558        g_signal_emit (data, signals[NEW_WINDOW_REQUESTED], 0);
559}
560
561static void
562window_close_window_cb (gpointer   data,
563                        guint      section,
564                        GtkWidget *widget)
565{
566        gtk_widget_destroy (GTK_WIDGET (data));
567}
568
569static void
570window_history_go_cb (gpointer data, guint section, GtkWidget *widget)
571{
572        window_history_action (data, section);
573}
574
575static void
576window_go_home_cb (gpointer data, guint section, GtkWidget *widget)
577{
578        window_home_button_clicked (NULL, YELP_WINDOW (data));
579}
580
581static void
582window_go_index_cb (gpointer data, guint section, GtkWidget *widget)
583{
584        window_index_button_clicked (NULL, YELP_WINDOW (data));
585}
586
587static void
588window_about_cb (gpointer data, guint section, GtkWidget *widget)
589{
590        GtkWidget   *about;
591        const gchar *authors[] = {
592                "Mikael Hallendal <micke@codefactory.se>",
593                "Alexander Larsson <alexl@redhat.com>",
594                NULL
595        };
596        /* Note to translators: put here your name (and address) so it
597         * will shop up in the "about" box */
598        gchar       *translator_credits = _("translator_credits");
599       
600        about = gnome_about_new (PACKAGE, VERSION,
601                                 "Copyright 2001-2002 Mikael Hallendal <micke@codefactory.se>",
602                                 _("Help Browser for GNOME 2.0"),
603                                 authors,
604                                 NULL,
605                                 strcmp (translator_credits, "translator_credits") != 0 ? translator_credits : NULL,
606                                 window_load_icon ());
607
608        gtk_window_set_transient_for (GTK_WINDOW (about), GTK_WINDOW (data));
609        gtk_widget_show (about);
610}
611
612static GtkWidget *
613window_create_toolbar (YelpWindow *window)
614{
615        YelpWindowPriv  *priv;
616        GtkWidget       *toolbar;
617        GtkWidget       *button;
618        GtkWidget       *icon;
619        GConfClient     *conf_client;
620        gchar           *str;
621        GtkToolbarStyle  style = GTK_TOOLBAR_BOTH;
622       
623        g_return_val_if_fail (YELP_IS_WINDOW (window), NULL);
624
625        priv = window->priv;
626
627        toolbar = gtk_toolbar_new ();
628
629        conf_client = gconf_client_get_default ();
630       
631        str = gconf_client_get_string (conf_client,
632                                       "/desktop/gnome/interface/toolbar_style",
633                                       NULL);
634
635        if (str) {
636                gconf_string_to_enum (toolbar_styles,
637                                      str,
638                                      (gint*)&style);
639                g_free (str);
640        }
641
642        gconf_client_notify_add (conf_client,
643                                 "/desktop/gnome/interface/toolbar_style",
644                                 window_toolbar_style_changed_cb,
645                                 toolbar, NULL, NULL);
646       
647/*      g_signal_connect(toolbar, "destroy", */
648/*                       G_CALLBACK(window_remove_notify_cb), */
649/*                       GINT_TO_POINTER(notify_id)); */
650
651        gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), style);
652
653        icon = gtk_image_new_from_stock ("gtk-go-back",
654                                         GTK_ICON_SIZE_LARGE_TOOLBAR);
655
656        priv->back_button = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
657                                                     _("Back"),
658                                                     _("Show previous page in history"),
659                                                     NULL, icon,
660                                                     G_CALLBACK (window_back_button_clicked),
661                                                     window);
662       
663        gtk_widget_set_sensitive (priv->back_button, FALSE);
664
665        icon = gtk_image_new_from_stock ("gtk-go-forward",
666                                         GTK_ICON_SIZE_LARGE_TOOLBAR);
667
668        priv->forward_button = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
669                                                        _("Forward"),
670                                                        _("Show next page in history"),
671                                                        NULL, icon,
672                                                        G_CALLBACK (window_forward_button_clicked),
673                                                        window);
674
675        gtk_widget_set_sensitive (priv->forward_button, FALSE);
676
677        gtk_toolbar_append_space (GTK_TOOLBAR (toolbar));
678
679        icon = gtk_image_new_from_stock ("gtk-home",
680                                         GTK_ICON_SIZE_LARGE_TOOLBAR);
681       
682        button = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
683                                          _("Home"),
684                                          _("Go to home view"),
685                                          NULL, icon,
686                                          G_CALLBACK (window_home_button_clicked),
687                                          window);
688
689        if (priv->index) {
690                icon = gtk_image_new_from_stock ("gtk-index",
691                                                 GTK_ICON_SIZE_LARGE_TOOLBAR);
692
693                button = gtk_toolbar_append_item (GTK_TOOLBAR (toolbar),
694                                                  _("Index"),
695                                                  _("Search in the index"),
696                                                  NULL, icon,
697                                                  G_CALLBACK (window_index_button_clicked),
698                                                  window);
699               
700        }
701       
702        return toolbar;
703}
704
705static GdkPixbuf *
706window_load_icon (void)
707{
708        static GdkPixbuf *pixbuf = NULL;
709       
710        if (!pixbuf) {
711                gchar *file;
712               
713                file = gnome_program_locate_file (NULL,
714                                                  GNOME_FILE_DOMAIN_PIXMAP,
715                                                  "gnome-help.png",
716                                                  TRUE,
717                                                  NULL);
718
719                if (file) {
720                        pixbuf = gdk_pixbuf_new_from_file (file,
721                                                           NULL);
722                        g_free (file);
723                }
724        }
725
726        return pixbuf;
727}
728
729static void
730window_toolbar_style_changed_cb (GConfClient *client,
731                                 guint        cnxn_id,
732                                 GConfEntry  *entry,
733                                 gpointer     data)
734{
735        GtkToolbarStyle  style   = GTK_TOOLBAR_BOTH;
736        GtkToolbar      *toolbar = GTK_TOOLBAR(data);
737        GConfValue      *value;
738
739        value = gconf_entry_get_value (entry);
740
741        /* If no per-app setting use this new global setting */
742        if (value &&
743            value->type == GCONF_VALUE_STRING &&
744            gconf_value_get_string (value) != NULL) {
745                gconf_string_to_enum(toolbar_styles,
746                                     gconf_value_get_string(value),
747                                     (gint*)&style);
748        }
749
750        gtk_toolbar_set_style(toolbar, style);
751}
752
753GtkWidget *
754yelp_window_new (GNode *doc_tree, GList *index)
755{
756        YelpWindow     *window;
757        YelpWindowPriv *priv;
758       
759        window = g_object_new (YELP_TYPE_WINDOW, NULL);
760        priv   = window->priv;
761
762        priv->doc_tree = doc_tree;
763        priv->index    = index;
764
765        priv->toc_view     = yelp_view_toc_new (doc_tree);
766        priv->content_view = yelp_view_content_new (doc_tree);
767
768        if (priv->index) {
769                priv->index_view = yelp_view_index_new (index);
770
771                g_signal_connect (priv->index_view, "uri_selected",
772                                  G_CALLBACK (window_uri_selected_cb),
773                                  window);
774        }
775
776        g_signal_connect (priv->toc_view, "uri_selected",
777                          G_CALLBACK (window_uri_selected_cb),
778                          window);
779
780        g_signal_connect (priv->toc_view, "title_changed",
781                          G_CALLBACK (window_title_changed_cb),
782                          window);
783
784        g_signal_connect (priv->content_view, "uri_selected",
785                          G_CALLBACK (window_uri_selected_cb),
786                          window);
787
788        g_signal_connect (priv->content_view, "title_changed",
789                          G_CALLBACK (window_title_changed_cb),
790                          window);
791
792        window_populate (window);
793
794        gtk_window_set_icon (GTK_WINDOW (window), window_load_icon ());
795
796        return GTK_WIDGET (window);
797}
798
799void
800yelp_window_open_uri (YelpWindow  *window,
801                      const gchar *str_uri)
802{
803        YelpWindowPriv *priv;
804        YelpURI        *uri;
805       
806        g_return_if_fail (YELP_IS_WINDOW (window));
807       
808        priv = window->priv;
809
810        uri = yelp_uri_new (str_uri);
811
812        yelp_history_goto (priv->history, uri);
813       
814        window_handle_uri (window, uri);
815       
816        yelp_uri_unref (uri);
817}
818
819YelpURI *
820yelp_window_get_current_uri (YelpWindow *window)
821{
822        g_return_val_if_fail (YELP_IS_WINDOW (window), NULL);
823       
824        return yelp_history_get_current (window->priv->history);
825}
826
Note: See TracBrowser for help on using the repository browser.