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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
* Copyright (C) 2000 Eazel, Inc
*
* This program 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.
*
* This program 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: Maciej Stachowiak
*/
/* nautilus-sample-content-view.c - sample content view
component. This component displays a simple label of the URI
and demonstrates merging menu items & toolbar buttons.
It should be a good basis for writing out-of-proc content views.
*/
#include <config.h>
#include "nautilus-sample-content-view.h"
#include <bonobo/bonobo-control.h>
#include <gtk/gtksignal.h>
#include <libgnome/gnome-i18n.h>
#include <libgnomeui/gnome-stock.h>
#include <libnautilus/nautilus-gtk-macros.h>
/* A NautilusContentViewFrame's private information. */
struct _NautilusSampleContentViewDetails {
gchar *uri;
NautilusContentViewFrame *view_frame;
};
static void nautilus_sample_content_view_initialize_class (NautilusSampleContentViewClass *klass);
static void nautilus_sample_content_view_initialize (NautilusSampleContentView *view);
static void nautilus_sample_content_view_destroy (GtkObject *object);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusSampleContentView, nautilus_sample_content_view, GTK_TYPE_LABEL)
static void sample_notify_location_change_callback (NautilusContentViewFrame *view_frame,
Nautilus_NavigationInfo *navinfo,
const char *initial_title,
NautilusSampleContentView *view);
static void sample_merge_bonobo_items_callback (BonoboObject *control,
gboolean state,
gpointer user_data);
static void
nautilus_sample_content_view_initialize_class (NautilusSampleContentViewClass *klass)
{
GtkObjectClass *object_class;
object_class = GTK_OBJECT_CLASS (klass);
object_class->destroy = nautilus_sample_content_view_destroy;
}
static void
nautilus_sample_content_view_initialize (NautilusSampleContentView *view)
{
view->details = g_new0 (NautilusSampleContentViewDetails, 1);
gtk_label_set_text (GTK_LABEL (view), g_strdup ("(none)"));
view->details->view_frame = nautilus_content_view_frame_new (GTK_WIDGET (view));
gtk_signal_connect (GTK_OBJECT (view->details->view_frame),
"notify_location_change",
GTK_SIGNAL_FUNC (sample_notify_location_change_callback),
view);
/*
* Get notified when our bonobo control is activated so we
* can merge menu & toolbar items into Nautilus's UI.
*/
gtk_signal_connect (GTK_OBJECT (nautilus_view_frame_get_bonobo_control (
NAUTILUS_VIEW_FRAME (view->details->view_frame))),
"activate",
sample_merge_bonobo_items_callback,
view);
gtk_widget_show (GTK_WIDGET (view));
}
static void
nautilus_sample_content_view_destroy (GtkObject *object)
{
NautilusSampleContentView *view;
view = NAUTILUS_SAMPLE_CONTENT_VIEW (object);
g_free (view->details->uri);
g_free (view->details);
NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
}
/**
* nautilus_sample_content_view_get_view_frame:
*
* Return the NautilusViewFrame object associated with this view; this
* is needed to export the view via CORBA/Bonobo.
* @view: NautilusSampleContentView to get the view_frame from..
*
**/
NautilusContentViewFrame *
nautilus_sample_content_view_get_view_frame (NautilusSampleContentView *view)
{
return view->details->view_frame;
}
/**
* nautilus_sample_content_view_load_uri:
*
* Load the resource pointed to by the specified URI.
* @view: NautilusSampleContentView to get the view_frame from.
*
**/
void
nautilus_sample_content_view_load_uri (NautilusSampleContentView *view,
const gchar *uri)
{
gchar *label_text;
g_free (view->details->uri);
view->details->uri = g_strdup (uri);
label_text = g_strdup_printf ("%s\n\nThis is a sample Nautilus content view component.", uri);
gtk_label_set_text (GTK_LABEL (view), label_text);
g_free (label_text);
}
static void
sample_notify_location_change_callback (NautilusContentViewFrame *view_frame,
Nautilus_NavigationInfo *navinfo,
const char *initial_title,
NautilusSampleContentView *view)
{
Nautilus_ProgressRequestInfo pri;
g_assert (view_frame == view->details->view_frame);
memset(&pri, 0, sizeof(pri));
/*
* It's mandatory to send a PROGRESS_UNDERWAY message once the
* component starts loading, otherwise nautilus will assume it
* failed. In a real component, this will probably happen in
* some sort of callback from whatever loading mechanism it is
* using to load the data; this component loads no data, so it
* gives the progrss update here.
*/
pri.type = Nautilus_PROGRESS_UNDERWAY;
pri.amount = 0.0;
nautilus_view_frame_request_progress_change (NAUTILUS_VIEW_FRAME (view_frame), &pri);
/* Do the actual load. */
nautilus_sample_content_view_load_uri (view, navinfo->actual_uri);
/*
* It's mandatory to send a PROGRESS_DONE_OK message once the
* component is done loading successfully, or
* PROGRESS_DONE_ERROR if it completes unsuccessfully. In a
* real component, this will probably happen in some sort of
* callback from whatever loading mechanism it is using to
* load the data; this component loads no data, so it gives
* the progrss upodate here.
*/
pri.type = Nautilus_PROGRESS_DONE_OK;
pri.amount = 100.0;
nautilus_view_frame_request_progress_change (NAUTILUS_VIEW_FRAME (view_frame), &pri);
}
static void
bonobo_sample_callback (BonoboUIHandler *ui_handler, gpointer user_data, const char *path)
{
NautilusSampleContentView *view;
BonoboUIHandler *local_ui_handler;
char *label_text;
g_assert (NAUTILUS_IS_SAMPLE_CONTENT_VIEW (user_data));
view = NAUTILUS_SAMPLE_CONTENT_VIEW (user_data);
if (strcmp (path, "/File/Sample") == 0) {
label_text = g_strdup_printf ("%s\n\nYou selected the Sample menu item.", view->details->uri);
} else {
g_assert (strcmp (path, "/Main/Sample") == 0);
label_text = g_strdup_printf ("%s\n\nYou clicked the Sample toolbar button.", view->details->uri);
}
gtk_label_set_text (GTK_LABEL (view), label_text);
g_free (label_text);
}
static void
sample_merge_bonobo_items_callback (BonoboObject *control, gboolean state, gpointer user_data)
{
NautilusSampleContentView *view;
BonoboUIHandler *local_ui_handler;
g_assert (NAUTILUS_IS_SAMPLE_CONTENT_VIEW (user_data));
view = NAUTILUS_SAMPLE_CONTENT_VIEW (user_data);
local_ui_handler = bonobo_control_get_ui_handler (BONOBO_CONTROL (control));
if (state) {
/* Tell the Nautilus window to merge our bonobo_ui_handler items with its ones */
bonobo_ui_handler_set_container (local_ui_handler,
bonobo_control_get_remote_ui_handler (BONOBO_CONTROL (control)));
/*
* Create our sample menu item.
*
* Note that it's sorta bogus that we know Nautilus has a menu whose
* path is "/File", and also that we know a sensible position to use within
* that menu. Nautilus should publish this information somehow.
*/
bonobo_ui_handler_menu_new_item (local_ui_handler, /* BonoboUIHandler */
"/File/Sample", /* menu item path, must start with /some-existing-menu-path and be otherwise unique */
_("_Sample"), /* menu item user-displayed label */
_("This is a sample merged menu item"), /* hint that appears in status bar */
1, /* position within menu; -1 means last */
BONOBO_UI_HANDLER_PIXMAP_NONE, /* pixmap type */
NULL, /* pixmap data */
'M', /* accelerator key, couldn't bear the thought of using Control-S for anything except Save */
GDK_CONTROL_MASK, /* accelerator key modifiers */
bonobo_sample_callback, /* callback function */
view); /* callback function data */
/*
* Create our sample toolbar button.
*
* Note that it's sorta bogus that we know Nautilus has a toolbar whose
* path is "/Main". Nautilus should publish this information somehow.
*/
bonobo_ui_handler_toolbar_new_item (local_ui_handler, /* BonoboUIHandler */
"/Main/Sample", /* button path, must start with /Main/ and be otherwise unique */
_("Sample"), /* button user-displayed label */
_("This is a sample merged toolbar button"),/* hint that appears in status bar */
-1, /* position, -1 means last */
BONOBO_UI_HANDLER_PIXMAP_STOCK, /* pixmap type */
GNOME_STOCK_PIXMAP_BOOK_BLUE, /* pixmap data */
0, /* accelerator key */
0, /* accelerator key modifiers */
bonobo_sample_callback, /* callback function */
view); /* callback function's data */
}
/*
* Note that we do nothing if state is FALSE. Nautilus content views are activated
* when installed, but never explicitly deactivated. When the view changes to another,
* the content view object is destroyed, which ends up calling bonobo_ui_handler_unset_container,
* which removes its merged menu & toolbar items.
*/
}
|