nautilus-3.6.3/libnautilus-extension/nautilus-menu-item.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found nautilus-menu-item.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /*
  2  *  nautilus-menu-item.c - Menu items exported by NautilusMenuProvider
  3  *                         objects.
  4  *
  5  *  Copyright (C) 2003 Novell, Inc.
  6  *
  7  *  This library is free software; you can redistribute it and/or
  8  *  modify it under the terms of the GNU Library General Public
  9  *  License as published by the Free Software Foundation; either
 10  *  version 2 of the License, or (at your option) any later version.
 11  *
 12  *  This library is distributed in the hope that it will be useful,
 13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 15  *  Library General Public License for more details.
 16  *
 17  *  You should have received a copy of the GNU Library General Public
 18  *  License along with this library; if not, write to the Free
 19  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 20  * 
 21  *  Author:  Dave Camp <dave@ximian.com>
 22  *
 23  */
 24 
 25 #include <config.h>
 26 #include "nautilus-menu.h"
 27 #include "nautilus-extension-i18n.h"
 28 
 29 enum {
 30 	ACTIVATE,
 31 	LAST_SIGNAL
 32 };
 33 
 34 enum {
 35 	PROP_0,
 36 	PROP_NAME,
 37 	PROP_LABEL,
 38 	PROP_TIP,
 39 	PROP_ICON,
 40 	PROP_SENSITIVE,
 41 	PROP_PRIORITY,
 42 	PROP_MENU,
 43 	LAST_PROP
 44 };
 45 
 46 struct _NautilusMenuItemDetails {
 47 	char *name;
 48 	char *label;
 49 	char *tip;
 50 	char *icon;
 51 	NautilusMenu *menu;
 52 	gboolean sensitive;
 53 	gboolean priority;
 54 };
 55 
 56 static guint signals[LAST_SIGNAL];
 57 
 58 static GObjectClass *parent_class = NULL;
 59 
 60 /**
 61  * nautilus_menu_item_new:
 62  * @name: the identifier for the menu item
 63  * @label: the user-visible label of the menu item
 64  * @tip: the tooltip of the menu item
 65  * @icon: the name of the icon to display in the menu item
 66  *
 67  * Creates a new menu item that can be added to the toolbar or to a contextual menu.
 68  *
 69  * Returns: a newly create #NautilusMenuItem
 70  */
 71 NautilusMenuItem *
 72 nautilus_menu_item_new (const char *name,
 73 			const char *label,
 74 			const char *tip,
 75 			const char *icon)
 76 {
 77 	NautilusMenuItem *item;
 78 
 79 	g_return_val_if_fail (name != NULL, NULL);
 80 	g_return_val_if_fail (label != NULL, NULL);
 81 	g_return_val_if_fail (tip != NULL, NULL);
 82 
 83 	item = g_object_new (NAUTILUS_TYPE_MENU_ITEM, 
 84 			     "name", name,
 85 			     "label", label,
 86 			     "tip", tip,
 87 			     "icon", icon,
 88 			     NULL);
 89 
 90 	return item;
 91 }
 92 
 93 /**
 94  * nautilus_menu_item_activate:
 95  * @item: pointer to a #NautilusMenuItem
 96  *
 97  * emits the activate signal.
 98  */
 99 void
100 nautilus_menu_item_activate (NautilusMenuItem *item)
101 {
102 	g_signal_emit (item, signals[ACTIVATE], 0);
103 }
104 
105 /**
106  * nautilus_menu_item_set_submenu:
107  * @item: pointer to a #NautilusMenuItem
108  * @menu: pointer to a #NautilusMenu to attach to the button
109  *
110  * Attachs a menu to the given #NautilusMenuItem.
111  */
112 void
113 nautilus_menu_item_set_submenu (NautilusMenuItem *item, NautilusMenu *menu)
114 {
115 	g_object_set (item, "menu", menu, NULL);
116 }
117 
118 static void
119 nautilus_menu_item_get_property (GObject *object,
120 				 guint param_id,
121 				 GValue *value,
122 				 GParamSpec *pspec)
123 {
124 	NautilusMenuItem *item;
125 	
126 	item = NAUTILUS_MENU_ITEM (object);
127 	
128 	switch (param_id) {
129 	case PROP_NAME :
130 		g_value_set_string (value, item->details->name);
131 		break;
132 	case PROP_LABEL :
133 		g_value_set_string (value, item->details->label);
134 		break;
135 	case PROP_TIP :
136 		g_value_set_string (value, item->details->tip);
137 		break;
138 	case PROP_ICON :
139 		g_value_set_string (value, item->details->icon);
140 		break;
141 	case PROP_SENSITIVE :
142 		g_value_set_boolean (value, item->details->sensitive);
143 		break;
144 	case PROP_PRIORITY :
145 		g_value_set_boolean (value, item->details->priority);
146 		break;
147 	case PROP_MENU :
148 		g_value_set_object (value, item->details->menu);
149 		break;
150 	default :
151 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
152 		break;
153 	}
154 }
155 
156 static void
157 nautilus_menu_item_set_property (GObject *object,
158 				 guint param_id,
159 				 const GValue *value,
160 				 GParamSpec *pspec)
161 {
162 	NautilusMenuItem *item;
163 	
164 	item = NAUTILUS_MENU_ITEM (object);
165 
166 	switch (param_id) {
167 	case PROP_NAME :
168 		g_free (item->details->name);
169 		item->details->name = g_strdup (g_value_get_string (value));
170 		g_object_notify (object, "name");
171 		break;
172 	case PROP_LABEL :
173 		g_free (item->details->label);
174 		item->details->label = g_strdup (g_value_get_string (value));
175 		g_object_notify (object, "label");
176 		break;
177 	case PROP_TIP :
178 		g_free (item->details->tip);
179 		item->details->tip = g_strdup (g_value_get_string (value));
180 		g_object_notify (object, "tip");
181 		break;
182 	case PROP_ICON :
183 		g_free (item->details->icon);
184 		item->details->icon = g_strdup (g_value_get_string (value));
185 		g_object_notify (object, "icon");
186 		break;
187 	case PROP_SENSITIVE :
188 		item->details->sensitive = g_value_get_boolean (value);
189 		g_object_notify (object, "sensitive");
190 		break;
191 	case PROP_PRIORITY :
192 		item->details->priority = g_value_get_boolean (value);
193 		g_object_notify (object, "priority");
194 		break;
195 	case PROP_MENU :
196 		if (item->details->menu) {
197 			g_object_unref (item->details->menu);
198 		}
199 		item->details->menu = g_object_ref (g_value_get_object (value));
200 		g_object_notify (object, "menu");
201 		break;
202 	default :
203 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
204 		break;
205 	}
206 }
207 
208 static void
209 nautilus_menu_item_finalize (GObject *object)
210 {
211 	NautilusMenuItem *item;
212 
213 	item = NAUTILUS_MENU_ITEM (object);
214 
215 	g_free (item->details->name);
216 	g_free (item->details->label);
217 	g_free (item->details->tip);
218 	g_free (item->details->icon);
219 	if (item->details->menu) {
220 		g_object_unref (item->details->menu);
221 	}
222 
223 	g_free (item->details);
224 
225 	G_OBJECT_CLASS (parent_class)->finalize (object);
226 }
227 
228 static void
229 nautilus_menu_item_instance_init (NautilusMenuItem *item)
230 {
231 	item->details = g_new0 (NautilusMenuItemDetails, 1);
232 	item->details->sensitive = TRUE;
233 	item->details->menu = NULL;
234 }
235 
236 static void
237 nautilus_menu_item_class_init (NautilusMenuItemClass *class)
238 {
239 	parent_class = g_type_class_peek_parent (class);
240 	
241 	G_OBJECT_CLASS (class)->finalize = nautilus_menu_item_finalize;
242 	G_OBJECT_CLASS (class)->get_property = nautilus_menu_item_get_property;
243 	G_OBJECT_CLASS (class)->set_property = nautilus_menu_item_set_property;
244 
245         signals[ACTIVATE] =
246                 g_signal_new ("activate",
247                               G_TYPE_FROM_CLASS (class),
248                               G_SIGNAL_RUN_LAST,
249                               G_STRUCT_OFFSET (NautilusMenuItemClass, 
250 					       activate),
251                               NULL, NULL,
252                               g_cclosure_marshal_VOID__VOID,
253                               G_TYPE_NONE, 0); 
254 
255 	g_object_class_install_property (G_OBJECT_CLASS (class),
256 					 PROP_NAME,
257 					 g_param_spec_string ("name",
258 							      "Name",
259 							      "Name of the item",
260 							      NULL,
261 							      G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE | G_PARAM_READABLE));
262 	g_object_class_install_property (G_OBJECT_CLASS (class),
263 					 PROP_LABEL,
264 					 g_param_spec_string ("label",
265 							      "Label",
266 							      "Label to display to the user",
267 							      NULL,
268 							      G_PARAM_READWRITE));
269 	g_object_class_install_property (G_OBJECT_CLASS (class),
270 					 PROP_TIP,
271 					 g_param_spec_string ("tip",
272 							      "Tip",
273 							      "Tooltip for the menu item",
274 							      NULL,
275 							      G_PARAM_READWRITE));
276 	g_object_class_install_property (G_OBJECT_CLASS (class),
277 					 PROP_ICON,
278 					 g_param_spec_string ("icon",
279 							      "Icon",
280 							      "Name of the icon to display in the menu item",
281 							      NULL,
282 							      G_PARAM_READWRITE));
283 
284 	g_object_class_install_property (G_OBJECT_CLASS (class),
285 					 PROP_SENSITIVE,
286 					 g_param_spec_boolean ("sensitive",
287 							       "Sensitive",
288 							       "Whether the menu item is sensitive",
289 							       TRUE,
290 							       G_PARAM_READWRITE));
291 	g_object_class_install_property (G_OBJECT_CLASS (class),
292 					 PROP_PRIORITY,
293 					 g_param_spec_boolean ("priority",
294 							       "Priority",
295 							       "Show priority text in toolbars",
296 							       TRUE,
297 							       G_PARAM_READWRITE));
298 	g_object_class_install_property (G_OBJECT_CLASS (class),
299 					 PROP_MENU,
300 					 g_param_spec_object ("menu",
301 							       "Menu",
302 							       "The menu belonging to this item. May be null.",
303 							       NAUTILUS_TYPE_MENU,
304 							       G_PARAM_READWRITE));
305 }
306 
307 GType 
308 nautilus_menu_item_get_type (void)
309 {
310 	static GType type = 0;
311 	
312 	if (!type) {
313 		const GTypeInfo info = {
314 			sizeof (NautilusMenuItemClass),
315 			NULL,
316 			NULL,
317 			(GClassInitFunc)nautilus_menu_item_class_init,
318 			NULL,
319 			NULL,
320 			sizeof (NautilusMenuItem),
321 			0,
322 			(GInstanceInitFunc)nautilus_menu_item_instance_init
323 		};
324 		
325 		type = g_type_register_static 
326 			(G_TYPE_OBJECT, 
327 			 "NautilusMenuItem",
328 			 &info, 0);
329 	}
330 
331 	return type;
332 }