]>
Commit | Line | Data |
---|---|---|
92806042 GB |
1 | /* |
2 | * viking -- GPS Data and Topo Analyzer, Explorer, and Manager | |
3 | * | |
4 | * Copyright (C) 2008, Guilhem Bonnefille <guilhem.bonnefille@gmail.com> | |
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 2 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, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 | * | |
20 | */ | |
21 | ||
22 | #ifdef HAVE_CONFIG_H | |
23 | #include "config.h" | |
24 | #endif | |
25 | ||
26 | #include "vikexttools.h" | |
27 | ||
28 | #include <string.h> | |
29 | ||
30 | #include <glib/gi18n.h> | |
31 | ||
32 | #define VIK_TOOL_DATA_KEY "vik-tool-data" | |
33 | ||
34 | static GList *ext_tools_list = NULL; | |
35 | ||
36 | void vik_ext_tools_register ( VikExtTool *tool ) | |
37 | { | |
38 | IS_VIK_EXT_TOOL( tool ); | |
39 | ||
40 | ext_tools_list = g_list_append ( ext_tools_list, g_object_ref ( tool ) ); | |
41 | } | |
42 | ||
43 | void vik_ext_tools_unregister_all () | |
44 | { | |
45 | g_list_foreach ( ext_tools_list, (GFunc) g_object_unref, NULL ); | |
46 | } | |
47 | ||
48 | static void ext_tools_open_cb ( GtkWidget *widget, VikWindow *vwindow ) | |
49 | { | |
50 | gpointer ptr = g_object_get_data ( G_OBJECT(widget), VIK_TOOL_DATA_KEY ); | |
51 | VikExtTool *ext_tool = VIK_EXT_TOOL ( ptr ); | |
52 | vik_ext_tool_open ( ext_tool, vwindow ); | |
53 | } | |
54 | ||
55 | void vik_ext_tools_add_menu_items_to_menu ( VikWindow *vwindow, GtkMenu *menu ) | |
56 | { | |
57 | GList *iter; | |
58 | for (iter = ext_tools_list; iter; iter = iter->next) | |
59 | { | |
60 | VikExtTool *ext_tool = NULL; | |
61 | gchar *label = NULL; | |
62 | ext_tool = VIK_EXT_TOOL ( iter->data ); | |
63 | label = vik_ext_tool_get_label ( ext_tool ); | |
64 | if ( label ) | |
65 | { | |
66 | GtkWidget *item = NULL; | |
67 | item = gtk_menu_item_new_with_label ( _(label) ); | |
68 | g_free ( label ); label = NULL; | |
69 | // Store tool's ref into the menu entry | |
70 | g_object_set_data ( G_OBJECT(item), VIK_TOOL_DATA_KEY, ext_tool ); | |
71 | g_signal_connect ( G_OBJECT(item), "activate", G_CALLBACK(ext_tools_open_cb), vwindow ); | |
72 | gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); | |
73 | gtk_widget_show ( item ); | |
74 | } | |
75 | } | |
76 | } | |
77 | ||
78 | void vik_ext_tools_add_menu_items ( VikWindow *vwindow, GtkUIManager *uim ) | |
79 | { | |
80 | GtkWidget *widget = NULL; | |
81 | GtkMenu *menu = NULL; | |
82 | widget = gtk_ui_manager_get_widget (uim, "/MainMenu/Tools/Exttools"); | |
83 | menu = GTK_MENU ( gtk_menu_item_get_submenu ( GTK_MENU_ITEM ( widget ) ) ); | |
84 | vik_ext_tools_add_menu_items_to_menu ( vwindow, menu ); | |
85 | gtk_widget_show ( widget ); | |
86 | } |