File: nemo-menu.c

package info (click to toggle)
nemo 3.2.2-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 8,028 kB
  • ctags: 11,121
  • sloc: ansic: 117,739; makefile: 953; xml: 562; python: 149; sh: 66
file content (121 lines) | stat: -rw-r--r-- 2,869 bytes parent folder | download | duplicates (4)
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
/*
 *  nemo-menu.h - Menus exported by NemoMenuProvider objects.
 *
 *  Copyright (C) 2005 Raffaele Sandrini
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License as published by the Free Software Foundation; either
 *  version 2 of the License, or (at your option) any later version.
 *
 *  This library 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
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public
 *  License along with this library; if not, write to the Free
 *  Software Foundation, Inc., 51 Franklin Street, Suite 500, MA 02110-1335, USA.
 * 
 *  Author:  Raffaele Sandrini <rasa@gmx.ch>
 *
 */

#include <config.h>
#include "nemo-menu.h"
#include "nemo-extension-i18n.h"

#include <glib.h>

#define NEMO_MENU_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NEMO_TYPE_MENU, NemoMenuPrivate))
G_DEFINE_TYPE (NemoMenu, nemo_menu, G_TYPE_OBJECT);

struct _NemoMenuPrivate {
	GList *item_list;
};

void
nemo_menu_append_item (NemoMenu *menu, NemoMenuItem *item)
{
	g_return_if_fail (menu != NULL);
	g_return_if_fail (item != NULL);
	
	menu->priv->item_list = g_list_append (menu->priv->item_list, g_object_ref (item));
}

/**
 * nemo_menu_get_items:
 * @menu: a #NemoMenu
 *
 * Returns: (element-type NemoMenuItem) (transfer full): the provided #NemoMenuItem list
 */
GList *
nemo_menu_get_items (NemoMenu *menu)
{
	GList *item_list;

	g_return_val_if_fail (menu != NULL, NULL);
	
	item_list = g_list_copy (menu->priv->item_list);
	g_list_foreach (item_list, (GFunc)g_object_ref, NULL);
	
	return item_list;
}

/**
 * nemo_menu_item_list_free:
 * @item_list: (element-type NemoMenuItem): a list of #NemoMenuItem
 *
 */
void
nemo_menu_item_list_free (GList *item_list)
{
	g_return_if_fail (item_list != NULL);
	
	g_list_foreach (item_list, (GFunc)g_object_unref, NULL);
	g_list_free (item_list);
}

/* Type initialization */

static void
nemo_menu_finalize (GObject *object)
{
	NemoMenu *menu = NEMO_MENU (object);

	if (menu->priv->item_list) {
		g_list_free (menu->priv->item_list);
	}

	G_OBJECT_CLASS (nemo_menu_parent_class)->finalize (object);
}

static void
nemo_menu_init (NemoMenu *menu)
{
	menu->priv = NEMO_MENU_GET_PRIVATE (menu);

	menu->priv->item_list = NULL;
}

static void
nemo_menu_class_init (NemoMenuClass *klass)
{
	GObjectClass *object_class = G_OBJECT_CLASS (klass);
	
	g_type_class_add_private (klass, sizeof (NemoMenuPrivate));
	
	object_class->finalize = nemo_menu_finalize;
}

/* public constructors */

NemoMenu *
nemo_menu_new (void)
{
	NemoMenu *obj;
	
	obj = NEMO_MENU (g_object_new (NEMO_TYPE_MENU, NULL));
	
	return obj;
}