source: trunk/third/nautilus/components/adapter/nautilus-adapter-stream-load-strategy.c @ 18383

Revision 18383, 6.2 KB checked in by ghudson, 22 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r18382, which included commits to RCS files with non-trunk default branches.
Line 
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2
3/*
4 * Nautilus
5 *
6 * Copyright (C) 2000 Eazel, Inc.
7 *
8 * Nautilus is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
12 *
13 * Nautilus is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public
19 * License along with this program; see the file COPYING.  If not,
20 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 *
23 * Author: Maciej Stachowiak <mjs@eazel.com>
24 */
25
26
27/* nautilus-adapter-stream-load-strategy.c -
28 */
29
30
31#include <config.h>
32
33#include <string.h>
34#include "nautilus-adapter-stream-load-strategy.h"
35
36#include <bonobo/bonobo-stream.h>
37#include <bonobo/bonobo-moniker-util.h>
38#include <bonobo/bonobo-exception.h>
39#include <gtk/gtkobject.h>
40#include <eel/eel-gtk-macros.h>
41#include <libnautilus/nautilus-view.h>
42#include <libgnomevfs/gnome-vfs-utils.h>
43
44struct NautilusAdapterStreamLoadStrategyDetails {
45        Bonobo_PersistStream  persist_stream;
46};
47
48
49static void nautilus_adapter_stream_load_strategy_class_init (NautilusAdapterStreamLoadStrategyClass *klass);
50static void nautilus_adapter_stream_load_strategy_init       (NautilusAdapterStreamLoadStrategy      *strategy);
51static void nautilus_adapter_stream_load_strategy_destroy          (GtkObject                              *object);
52
53static void nautilus_adapter_stream_load_strategy_load_location (NautilusAdapterLoadStrategy *strategy,
54                                                                 const char                  *uri);
55
56static void nautilus_adapter_stream_load_strategy_stop_loading  (NautilusAdapterLoadStrategy *strategy);
57
58
59EEL_CLASS_BOILERPLATE (NautilusAdapterStreamLoadStrategy, nautilus_adapter_stream_load_strategy, NAUTILUS_TYPE_ADAPTER_LOAD_STRATEGY)
60
61
62static void
63nautilus_adapter_stream_load_strategy_class_init (NautilusAdapterStreamLoadStrategyClass *klass)
64{
65        GtkObjectClass                   *object_class;
66        NautilusAdapterLoadStrategyClass *adapter_load_strategy_class;
67
68        object_class = GTK_OBJECT_CLASS (klass);
69
70        object_class->destroy = nautilus_adapter_stream_load_strategy_destroy;
71
72        adapter_load_strategy_class = NAUTILUS_ADAPTER_LOAD_STRATEGY_CLASS (klass);
73
74        adapter_load_strategy_class->load_location = nautilus_adapter_stream_load_strategy_load_location;
75        adapter_load_strategy_class->stop_loading = nautilus_adapter_stream_load_strategy_stop_loading;
76}
77
78static void
79nautilus_adapter_stream_load_strategy_init (NautilusAdapterStreamLoadStrategy *strategy)
80{
81        strategy->details = g_new0 (NautilusAdapterStreamLoadStrategyDetails, 1);
82}
83
84static void
85nautilus_adapter_stream_load_strategy_destroy (GtkObject *object)
86{
87        NautilusAdapterStreamLoadStrategy *strategy;
88        CORBA_Environment ev;
89
90        strategy = NAUTILUS_ADAPTER_STREAM_LOAD_STRATEGY (object);
91
92        if (strategy->details->persist_stream != CORBA_OBJECT_NIL) {
93                CORBA_exception_init (&ev);
94                bonobo_object_release_unref (strategy->details->persist_stream, &ev);
95                CORBA_exception_free (&ev);
96        }
97
98        g_free (strategy->details);
99
100        EEL_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
101}
102
103
104NautilusAdapterLoadStrategy *
105nautilus_adapter_stream_load_strategy_new (Bonobo_PersistStream  persist_stream)
106{
107        NautilusAdapterStreamLoadStrategy *strategy;
108
109        strategy = NAUTILUS_ADAPTER_STREAM_LOAD_STRATEGY (g_object_new (NAUTILUS_TYPE_ADAPTER_STREAM_LOAD_STRATEGY, NULL));
110        g_object_ref (strategy);
111        gtk_object_sink (GTK_OBJECT (strategy));
112
113        strategy->details->persist_stream = persist_stream;
114
115        return NAUTILUS_ADAPTER_LOAD_STRATEGY (strategy);
116}
117
118static ORBit_IMethod *
119get_stream_load_method (void)
120{
121        guint i;
122        ORBit_IInterface *iface;
123        static ORBit_IMethod *method = NULL;
124       
125        iface = &Bonobo_PersistStream__iinterface;
126        if (!method) {
127                for (i = 0; i < iface->methods._length; i++) {
128                        if (!strcmp ("load", iface->methods._buffer [i].name)) {
129                                method = &iface->methods._buffer [i];
130                        }
131                }
132        }
133        g_assert (method);
134
135        return method;
136}
137
138static void
139unref_stream_cb (gpointer user_data)
140{
141        bonobo_object_release_unref (user_data, NULL);
142}
143
144static void
145nautilus_adapter_stream_load_strategy_load_location (NautilusAdapterLoadStrategy *abstract_strategy,
146                                                     const char                  *uri)
147{
148        NautilusAdapterStreamLoadStrategy *strategy;
149        Bonobo_Stream stream;
150        CORBA_Environment ev;
151        char *moniker_str;
152        char *escaped_uri;
153        char *mime_type;
154        gpointer args[2];
155
156        strategy = NAUTILUS_ADAPTER_STREAM_LOAD_STRATEGY (abstract_strategy);
157        g_object_ref (strategy);
158
159        CORBA_exception_init (&ev);
160
161        nautilus_adapter_load_strategy_report_load_underway (abstract_strategy);
162
163        /* We must escape the '!' in the URI here, because it is
164         * used as argument delimiter within monikers.
165         */
166        escaped_uri = gnome_vfs_escape_set (uri, "!");
167        moniker_str = g_strconcat ("vfs:", escaped_uri, NULL);
168        stream = bonobo_get_object (moniker_str, "IDL:Bonobo/Stream:1.0", &ev);
169        g_free (moniker_str);
170        g_free (escaped_uri);
171
172        if (BONOBO_EX (&ev) || CORBA_Object_is_nil (stream, &ev)) {
173                nautilus_adapter_load_strategy_report_load_failed (abstract_strategy);
174        } else {
175                /* FIXME bugzilla.gnome.org 41248:
176                 * Dan Winship points out that we should pass the
177                 * MIME type here to work with new implementers of
178                 * PersistStream that pay attention to the MIME type. It
179                 * doesn't matter right now, but we should fix it
180                 * eventually. Currently, we don't store the MIME type, but
181                 * it should be easy to keep it around and pass it in here.
182                 */
183
184                mime_type = "";
185                args [0] = &stream;
186                args [1] = &mime_type;
187
188                nautilus_adapter_load_strategy_load_async (
189                        abstract_strategy,
190                        strategy->details->persist_stream,
191                        get_stream_load_method (),
192                        args,
193                        unref_stream_cb,
194                        stream);
195        }
196
197        g_object_unref (strategy);
198
199        CORBA_exception_free (&ev);
200}
201
202static void
203nautilus_adapter_stream_load_strategy_stop_loading  (NautilusAdapterLoadStrategy *strategy)
204{
205        g_return_if_fail (NAUTILUS_IS_ADAPTER_STREAM_LOAD_STRATEGY (strategy));
206
207        /* FIXME bugzilla.gnome.org 43456: is there anything we can do? */
208}
Note: See TracBrowser for help on using the repository browser.