source: trunk/third/gnome-vfs/libgnomevfs/gnome-vfs-context.c @ 15497

Revision 15497, 3.5 KB checked in by ghudson, 24 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r15496, 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/* gnome-vfs-context.c - context VFS modules can use to communicate with gnome-vfs proper
3
4   Copyright (C) 1999 Free Software Foundation
5
6   The Gnome Library is free software; you can redistribute it and/or
7   modify it under the terms of the GNU Library 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   The Gnome Library 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   Library General Public License for more details.
15
16   You should have received a copy of the GNU Library General Public
17   License along with the Gnome Library; see the file COPYING.LIB.  If not,
18   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19   Boston, MA 02111-1307, USA.
20
21   Author: Havoc Pennington <hp@redhat.com> */
22
23#include "gnome-vfs-context.h"
24#include "gnome-vfs-cancellation.h"
25#include "gnome-vfs-messages.h"
26
27#include <stdio.h>
28
29struct GnomeVFSContext {
30        GnomeVFSCancellation *cancellation;
31        GnomeVFSMessageCallbacks *callbacks;
32        gchar* redirect_uri;
33        guint refcount;
34};
35
36GnomeVFSContext*
37gnome_vfs_context_new (void)
38{
39        GnomeVFSContext *ctx;
40
41        ctx = g_new0(GnomeVFSContext, 1);
42
43        ctx->cancellation = gnome_vfs_cancellation_new();
44        ctx->callbacks = gnome_vfs_message_callbacks_new();
45        ctx->redirect_uri = NULL;
46        ctx->refcount = 1;
47 
48        return ctx;
49}
50
51void
52gnome_vfs_context_ref (GnomeVFSContext *ctx)
53{
54        g_return_if_fail(ctx != NULL);
55 
56        ctx->refcount += 1;
57}
58
59void
60gnome_vfs_context_unref (GnomeVFSContext *ctx)
61{
62        g_return_if_fail(ctx != NULL);
63        g_return_if_fail(ctx->refcount > 0);
64 
65        if (ctx->refcount == 1) {
66                gnome_vfs_cancellation_destroy(ctx->cancellation);
67                gnome_vfs_message_callbacks_destroy(ctx->callbacks);
68                if (ctx->redirect_uri)
69                        g_free(ctx->redirect_uri);
70         
71                g_free(ctx);
72        } else {
73                ctx->refcount -= 1;
74        }
75}
76
77
78GnomeVFSMessageCallbacks*
79gnome_vfs_context_get_message_callbacks (GnomeVFSContext *ctx)
80{
81        g_return_val_if_fail(ctx != NULL, NULL);
82        return ctx->callbacks;
83}
84
85GnomeVFSCancellation*
86gnome_vfs_context_get_cancellation (GnomeVFSContext *ctx)
87{
88        g_return_val_if_fail(ctx != NULL, NULL);
89        return ctx->cancellation;
90}
91
92
93const gchar*
94gnome_vfs_context_get_redirect_uri      (GnomeVFSContext *ctx)
95{
96        g_return_val_if_fail(ctx != NULL, NULL);
97        return ctx->redirect_uri;
98}
99
100void
101gnome_vfs_context_set_redirect_uri      (GnomeVFSContext *ctx,
102                                         const gchar     *uri)
103{
104        g_return_if_fail(ctx != NULL);
105       
106        if (ctx->redirect_uri)
107                g_free(ctx->redirect_uri);
108       
109        ctx->redirect_uri = uri ? g_strdup(uri) : NULL;
110}
111
112void
113gnome_vfs_context_emit_message           (GnomeVFSContext *ctx,
114                                          const gchar* message)
115{
116        GnomeVFSMessageCallbacks *callbacks;
117       
118        if (ctx == NULL) {
119                fprintf(stderr, "Debug: NULL context so not reporting status: %s\n", message);
120                return;
121        }
122       
123        callbacks = ctx->callbacks;
124       
125        if (callbacks)
126                gnome_vfs_message_callbacks_emit (callbacks, message);
127}
Note: See TracBrowser for help on using the repository browser.