File: nemo-menu.c

package info (click to toggle)
nemo 6.4.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,088 kB
  • sloc: ansic: 127,474; xml: 1,555; python: 1,434; sh: 57; makefile: 20
file content (134 lines) | stat: -rw-r--r-- 3,194 bytes parent folder | download | duplicates (3)
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
/*
 *  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>

typedef struct {
	GList *item_list;
} NemoMenuPrivate;

struct _NemoMenu
{
    GObject parent_class;

    NemoMenuPrivate *priv;
};

G_DEFINE_TYPE_WITH_PRIVATE (NemoMenu, nemo_menu, G_TYPE_OBJECT)

/**
 * SECTION:nemo-menu
 * @Title: NemoMenu
 * @Short_description: A menu added to Nemo's context menus by an extension
 *
 * Menu items and submenus can be added to Nemo's selected item and background
 * context menus by a #NemoMenuProvider.  Separators and embedded widgets are also
 * possible (see #NemoSimpleButton.)
 **/

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) {
        nemo_menu_item_list_free (menu->priv->item_list);
	}

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

static void
nemo_menu_init (NemoMenu *menu)
{
	menu->priv = G_TYPE_INSTANCE_GET_PRIVATE (menu, NEMO_TYPE_MENU, NemoMenuPrivate);

    menu->priv->item_list = NULL;
}

static void
nemo_menu_class_init (NemoMenuClass *klass)
{
    GObjectClass *object_class = G_OBJECT_CLASS (klass);
    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;
}