]> git.street.me.uk Git - andy/viking.git/blob - src/vikexttool_datasources.c
Merge commit 'ToolbarConfig'
[andy/viking.git] / src / vikexttool_datasources.c
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3  * viking -- GPS Data and Topo Analyzer, Explorer, and Manager
4  *
5  * Copyright (C) 2013, Rob Norris <rw_norris@hotmail.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program 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
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include "vikexttools.h"
28
29 #include <string.h>
30
31 #include <glib/gi18n.h>
32
33 #define VIK_TOOL_DATASOURCE_KEY "vik-datasource-tool"
34
35 static GList *ext_tool_datasources_list = NULL;
36
37 void vik_ext_tool_datasources_register ( VikExtTool *tool )
38 {
39         if ( IS_VIK_EXT_TOOL( tool ) )
40                 ext_tool_datasources_list = g_list_append ( ext_tool_datasources_list, g_object_ref ( tool ) );
41 }
42
43 void vik_ext_tool_datasources_unregister_all ()
44 {
45         g_list_foreach ( ext_tool_datasources_list, (GFunc) g_object_unref, NULL );
46 }
47
48 static void ext_tool_datasources_open_cb ( GtkWidget *widget, VikWindow *vw )
49 {
50         gpointer ptr = g_object_get_data ( G_OBJECT(widget), VIK_TOOL_DATASOURCE_KEY );
51         VikExtTool *ext_tool = VIK_EXT_TOOL ( ptr );
52         vik_ext_tool_open ( ext_tool, vw );
53 }
54
55 /**
56  * Add to any menu
57  *  mostly for allowing to assign for TrackWaypoint layer menus
58  */
59 void vik_ext_tool_datasources_add_menu_items_to_menu ( VikWindow *vw, GtkMenu *menu )
60 {
61         GList *iter;
62         for (iter = ext_tool_datasources_list; iter; iter = iter->next) {
63                 VikExtTool *ext_tool = NULL;
64                 gchar *label = NULL;
65                 ext_tool = VIK_EXT_TOOL ( iter->data );
66                 label = vik_ext_tool_get_label ( ext_tool );
67                 if ( label ) {
68                         GtkWidget *item = NULL;
69                         item = gtk_menu_item_new_with_label ( _(label) );
70                         g_free ( label ); label = NULL;
71                         // Store tool's ref into the menu entry
72                         g_object_set_data ( G_OBJECT(item), VIK_TOOL_DATASOURCE_KEY, ext_tool );
73                         g_signal_connect ( G_OBJECT(item), "activate", G_CALLBACK(ext_tool_datasources_open_cb), vw );
74                         gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
75                         gtk_widget_show ( item );
76                 }
77         }
78 }
79
80 /**
81  * Adds to the File->Acquire menu only
82  */
83 void vik_ext_tool_datasources_add_menu_items ( VikWindow *vw, GtkUIManager *uim )
84 {
85         GtkWidget *widget = gtk_ui_manager_get_widget ( uim, "/MainMenu/File/Acquire/" );
86         GtkMenu *menu = GTK_MENU ( gtk_menu_item_get_submenu ( GTK_MENU_ITEM(widget) ) );
87         vik_ext_tool_datasources_add_menu_items_to_menu ( vw, menu );
88         gtk_widget_show ( widget );
89 }