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

Revision 18397, 5.1 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#include <config.h>
24
25#include <bonobo/bonobo-main.h>
26
27#include <string.h>
28
29#include "yelp-cache.h"
30#include "yelp-window.h"
31#include "yelp-section.h"
32#include "yelp-scrollkeeper.h"
33#include "yelp-man.h"
34#include "yelp-info.h"
35#include "yelp-base.h"
36
37typedef struct {
38        YelpBase    *base;
39        GtkTreeIter *parent;
40} ForeachData;
41
42struct _YelpBasePriv {
43        GNode  *toc_tree;
44
45        GList  *index;
46        GSList *windows;
47};
48
49
50static void           yelp_base_init                (YelpBase       *base);
51static void           yelp_base_class_init          (YelpBaseClass  *klass);
52static void           yelp_base_new_window_cb       (YelpWindow     *window,
53                                                     YelpBase       *base);
54static void           yelp_base_window_finalized_cb (YelpBase       *base,
55                                                     YelpWindow     *window);
56
57
58#define PARENT_TYPE BONOBO_OBJECT_TYPE
59static BonoboObjectClass *parent_class;
60
61static void
62impl_Yelp_newWindow (PortableServer_Servant  servant,
63                     const CORBA_char       *url,
64                     CORBA_Environment      *ev)
65{
66        YelpBase  *yelp_base;
67       
68        yelp_base = YELP_BASE (bonobo_object (servant));
69
70        yelp_base_new_window (yelp_base, url);
71}
72
73static GNOME_Yelp_WindowList *
74impl_Yelp_getWindows (PortableServer_Servant  servant,
75                      CORBA_Environment      *ev)
76{
77        YelpBase              *base;
78        YelpBasePriv          *priv;
79        GNOME_Yelp_WindowList *list;
80        gint                   len, i;
81        GSList                *node;
82        YelpURI               *uri;
83       
84        base = YELP_BASE (bonobo_object (servant));
85        priv = base->priv;
86
87        len  = g_slist_length (priv->windows);
88       
89        list = GNOME_Yelp_WindowList__alloc ();
90        list->_buffer = CORBA_sequence_CORBA_string_allocbuf (len);
91        list->_length = len;
92        list->_maximum = len;
93        CORBA_sequence_set_release (list, CORBA_TRUE);
94       
95        for (node = priv->windows, i = 0; node; node = node->next, i++) {
96                gchar *str_uri;
97
98                uri = yelp_window_get_current_uri (YELP_WINDOW (node->data));
99                str_uri = yelp_uri_to_string (uri);
100                list->_buffer[i] = CORBA_string_dup (str_uri);
101                g_free (str_uri);
102        }
103       
104        return list;
105}
106
107static void
108yelp_base_init (YelpBase *base)
109{
110        YelpBasePriv *priv;
111
112        priv = g_new0 (YelpBasePriv, 1);
113       
114        priv->toc_tree = g_node_new (NULL);
115        priv->index    = NULL;
116        priv->windows  = NULL;
117        base->priv     = priv;
118
119        yelp_cache_init ();
120}
121
122static void
123yelp_base_class_init (YelpBaseClass *klass)
124{
125        POA_GNOME_Yelp__epv *epv = &klass->epv;
126       
127        parent_class = gtk_type_class (PARENT_TYPE);
128
129        epv->newWindow  = impl_Yelp_newWindow;
130        epv->getWindows = impl_Yelp_getWindows;
131}
132
133static void
134yelp_base_new_window_cb (YelpWindow *window, YelpBase *base)
135{
136        GtkWidget *new_window;
137       
138        g_return_if_fail (YELP_IS_WINDOW (window));
139        g_return_if_fail (YELP_IS_BASE (base));
140       
141        new_window = yelp_base_new_window (base, NULL);
142       
143        gtk_widget_show_all (new_window);
144}
145
146static void
147yelp_base_window_finalized_cb (YelpBase *base, YelpWindow *window)
148{
149        YelpBasePriv *priv;
150       
151        g_return_if_fail (YELP_IS_BASE (base));
152       
153        priv = base->priv;
154       
155        priv->windows = g_slist_remove (priv->windows, window);
156
157        if (g_slist_length (priv->windows) == 0) {
158                bonobo_main_quit ();
159        }
160}
161
162YelpBase *
163yelp_base_new (void)
164{
165        YelpBase     *base;
166        YelpBasePriv *priv;
167       
168        base = g_object_new (YELP_TYPE_BASE, NULL);
169        priv = base->priv;
170       
171        yelp_scrollkeeper_init (priv->toc_tree, &priv->index);
172        yelp_man_init (base->priv->toc_tree, &priv->index);
173        yelp_info_init (base->priv->toc_tree, &priv->index);
174       
175        priv->index = g_list_sort (priv->index, yelp_section_compare);
176
177        return base;
178}
179
180GtkWidget *
181yelp_base_new_window (YelpBase *base, const gchar *str_uri)
182{
183        YelpBasePriv *priv;
184        GtkWidget    *window;
185       
186        g_return_val_if_fail (YELP_IS_BASE (base), NULL);
187
188        priv = base->priv;
189       
190        window = yelp_window_new (priv->toc_tree, priv->index);
191       
192        priv->windows = g_slist_prepend (priv->windows, window);
193
194        g_object_weak_ref (G_OBJECT (window),
195                           (GWeakNotify) yelp_base_window_finalized_cb,
196                           base);
197       
198        g_signal_connect (window, "new_window_requested",
199                          G_CALLBACK (yelp_base_new_window_cb),
200                          base);
201
202
203        gtk_widget_show_all (window);
204
205        if (str_uri && strcmp (str_uri, "")) {
206                yelp_window_open_uri (YELP_WINDOW (window), str_uri);
207        } else {
208                yelp_window_open_uri (YELP_WINDOW (window), "toc:");
209        }
210
211        return window;
212}
213
214BONOBO_TYPE_FUNC_FULL (YelpBase, GNOME_Yelp, PARENT_TYPE, yelp_base);
Note: See TracBrowser for help on using the repository browser.