1 /* GIMP - The GNU Image Manipulation Program
2 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3 *
4 * gimppluginmanager-menu-branch.c
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #include "config.h"
21
22 #include <gio/gio.h>
23
24 #include "plug-in-types.h"
25
26 #include "gimppluginmanager.h"
27 #include "gimppluginmanager-menu-branch.h"
28 #include "plug-in-menu-path.h"
29
30
31 /* public functions */
32
33 void
gimp_plug_in_manager_menu_branch_exit(GimpPlugInManager * manager)34 gimp_plug_in_manager_menu_branch_exit (GimpPlugInManager *manager)
35 {
36 GSList *list;
37
38 g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
39
40 for (list = manager->menu_branches; list; list = list->next)
41 {
42 GimpPlugInMenuBranch *branch = list->data;
43
44 g_object_unref (branch->file);
45 g_free (branch->menu_path);
46 g_free (branch->menu_label);
47 g_slice_free (GimpPlugInMenuBranch, branch);
48 }
49
50 g_slist_free (manager->menu_branches);
51 manager->menu_branches = NULL;
52 }
53
54 void
gimp_plug_in_manager_add_menu_branch(GimpPlugInManager * manager,GFile * file,const gchar * menu_path,const gchar * menu_label)55 gimp_plug_in_manager_add_menu_branch (GimpPlugInManager *manager,
56 GFile *file,
57 const gchar *menu_path,
58 const gchar *menu_label)
59 {
60 GimpPlugInMenuBranch *branch;
61
62 g_return_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager));
63 g_return_if_fail (G_IS_FILE (file));
64 g_return_if_fail (menu_path != NULL);
65 g_return_if_fail (menu_label != NULL);
66
67 branch = g_slice_new (GimpPlugInMenuBranch);
68
69 branch->file = g_object_ref (file);
70 branch->menu_path = plug_in_menu_path_map (menu_path, menu_label);
71 branch->menu_label = g_strdup (menu_label);
72
73 manager->menu_branches = g_slist_append (manager->menu_branches, branch);
74
75 g_signal_emit_by_name (manager, "menu-branch-added",
76 branch->file,
77 branch->menu_path,
78 branch->menu_label);
79
80 #ifdef VERBOSE
81 g_print ("added menu branch \"%s\" at path \"%s\"\n",
82 branch->menu_label, branch->menu_path);
83 #endif
84 }
85
86 GSList *
gimp_plug_in_manager_get_menu_branches(GimpPlugInManager * manager)87 gimp_plug_in_manager_get_menu_branches (GimpPlugInManager *manager)
88 {
89 g_return_val_if_fail (GIMP_IS_PLUG_IN_MANAGER (manager), NULL);
90
91 return manager->menu_branches;
92 }
93