summaryrefslogtreecommitdiff
path: root/src/nautilus-throbber.c
blob: f8db07d103c000a4bf4a71119ad8da5f02fca487 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/* 
 * Nautilus
 *
 * Copyright (C) 2000 Eazel, Inc.
 * Copyright (C) 2006 Christian Persch
 *
 * Nautilus is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Nautilus is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Author: Andy Hertzfeld <andy@eazel.com>
 *
 * This is the throbber (for busy feedback) for the location bar
 *
 */

#include <config.h>

#include "nautilus-throbber.h"

#include <eel/eel-debug.h>
#include <eel/eel-glib-extensions.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-accessibility.h>
#include <glib/gi18n.h>

static AtkObject *nautilus_throbber_get_accessible   (GtkWidget *widget);

G_DEFINE_TYPE (NautilusThrobber, nautilus_throbber, EPHY_TYPE_SPINNER)

static void
nautilus_throbber_init (NautilusThrobber *throbber)
{
}	

void
nautilus_throbber_start (NautilusThrobber *throbber)
{
	ephy_spinner_start (EPHY_SPINNER (throbber));
}

void
nautilus_throbber_stop (NautilusThrobber *throbber)
{
	ephy_spinner_stop (EPHY_SPINNER (throbber));
}

void
nautilus_throbber_set_size (NautilusThrobber *throbber, GtkIconSize size)
{
	ephy_spinner_set_size (EPHY_SPINNER (throbber), size);
}

static void
nautilus_throbber_class_init (NautilusThrobberClass *class)
{
	GtkWidgetClass *widget_class;

	widget_class = GTK_WIDGET_CLASS (class);

	widget_class->get_accessible = nautilus_throbber_get_accessible;
}

static AtkObjectClass *a11y_parent_class = NULL;

static void
nautilus_throbber_accessible_initialize (AtkObject *accessible,
					 gpointer   widget)
{
	atk_object_set_name (accessible, _("throbber"));
	atk_object_set_description (accessible, _("provides visual status"));

	a11y_parent_class->initialize (accessible, widget);
}

static void
nautilus_throbber_accessible_class_init (AtkObjectClass *klass)
{
	a11y_parent_class = g_type_class_peek_parent (klass);

	klass->initialize = nautilus_throbber_accessible_initialize;
}

static void
nautilus_throbber_accessible_image_get_size (AtkImage *image,
					     gint     *width,
					     gint     *height)
{
	GtkWidget *widget;

	widget = GTK_ACCESSIBLE (image)->widget;
	if (!widget) {
		*width = *height = 0;
	} else {
		*width = widget->allocation.width;
		*height = widget->allocation.height;
	}
}

static void
nautilus_throbber_accessible_image_interface_init (AtkImageIface *iface)
{
	iface->get_image_size = nautilus_throbber_accessible_image_get_size;
}

static GType
nautilus_throbber_accessible_get_type (void)
{
        static GType type = 0;

	/* Action interface
	   Name etc. ... */
	if (G_UNLIKELY (type == 0)) {
		const GInterfaceInfo atk_image_info = {
			(GInterfaceInitFunc) nautilus_throbber_accessible_image_interface_init,
			(GInterfaceFinalizeFunc) NULL,
			NULL
		};

		type = eel_accessibility_create_derived_type 
			("NautilusThrobberAccessible",
			 GTK_TYPE_IMAGE,
			 nautilus_throbber_accessible_class_init);
		
                g_type_add_interface_static (type, ATK_TYPE_IMAGE,
                                             &atk_image_info);
        }

        return type;
}

static AtkObject *
nautilus_throbber_get_accessible (GtkWidget *widget)
{
	AtkObject *accessible;
	
	if ((accessible = eel_accessibility_get_atk_object (widget))) {
		return accessible;
	}
	
	accessible = g_object_new 
		(nautilus_throbber_accessible_get_type (), NULL);
	
	return eel_accessibility_set_atk_object_return (widget, accessible);
}

GtkWidget    *
nautilus_throbber_new (void)
{
	return g_object_new (NAUTILUS_TYPE_THROBBER, NULL);
}