]> git.street.me.uk Git - andy/viking.git/blame - src/vikexttools.c
Add option to auto connect to GPSD rather than having to manually control
[andy/viking.git] / src / vikexttools.c
CommitLineData
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"
027ff770 33#define VIK_TOOL_WIN_KEY "vik-tool-win"
92806042
GB
34
35static GList *ext_tools_list = NULL;
36
37void vik_ext_tools_register ( VikExtTool *tool )
38{
619a68f3
RN
39 if ( IS_VIK_EXT_TOOL( tool ) )
40 ext_tools_list = g_list_append ( ext_tools_list, g_object_ref ( tool ) );
92806042
GB
41}
42
43void vik_ext_tools_unregister_all ()
44{
45 g_list_foreach ( ext_tools_list, (GFunc) g_object_unref, NULL );
46}
47
48static 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
a147baa7 55void vik_ext_tools_add_action_items ( VikWindow *vwindow, GtkUIManager *uim, GtkActionGroup *action_group, guint mid )
92806042
GB
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 {
a147baa7
RN
66 gtk_ui_manager_add_ui ( uim, mid, "/ui/MainMenu/Tools/Exttools",
67 _(label),
68 label,
69 GTK_UI_MANAGER_MENUITEM, FALSE );
70
71 GtkAction *action = gtk_action_new ( label, label, NULL, NULL );
72 g_object_set_data ( G_OBJECT(action), VIK_TOOL_DATA_KEY, ext_tool );
73 g_signal_connect ( G_OBJECT(action), "activate", G_CALLBACK(ext_tools_open_cb), vwindow );
74
75 gtk_action_group_add_action ( action_group, action );
76
644eea0e
RN
77 g_object_unref ( action );
78
92806042 79 g_free ( label ); label = NULL;
92806042
GB
80 }
81 }
82}
027ff770
RN
83
84static void ext_tool_open_at_position_cb ( GtkWidget *widget, VikCoord *vc )
85{
86 gpointer ptr = g_object_get_data ( G_OBJECT(widget), VIK_TOOL_DATA_KEY );
87 VikExtTool *ext_tool = VIK_EXT_TOOL ( ptr );
88 gpointer wptr = g_object_get_data ( G_OBJECT(widget), VIK_TOOL_WIN_KEY );
89 VikWindow *vw = VIK_WINDOW ( wptr );
90 vik_ext_tool_open_at_position ( ext_tool, vw, vc );
91}
92
93/**
94 * Add to any menu
95 * mostly for allowing to assign for TrackWaypoint layer menus
96 */
97void vik_ext_tools_add_menu_items_to_menu ( VikWindow *vw, GtkMenu *menu, VikCoord *vc )
98{
99 for (GList *iter = ext_tools_list; iter; iter = iter->next) {
100 VikExtTool *ext_tool = NULL;
101 gchar *label = NULL;
102 ext_tool = VIK_EXT_TOOL ( iter->data );
103 label = vik_ext_tool_get_label ( ext_tool );
104 if ( label ) {
105 GtkWidget *item = NULL;
106 item = gtk_menu_item_new_with_label ( _(label) );
107 g_free ( label ); label = NULL;
108 // Store some data into the menu entry
109 g_object_set_data ( G_OBJECT(item), VIK_TOOL_DATA_KEY, ext_tool );
110 g_object_set_data ( G_OBJECT(item), VIK_TOOL_WIN_KEY, vw );
111 if ( vc )
112 g_signal_connect ( G_OBJECT(item), "activate", G_CALLBACK(ext_tool_open_at_position_cb), vc );
113 else
114 g_signal_connect ( G_OBJECT(item), "activate", G_CALLBACK(ext_tools_open_cb), vw );
115 gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
116 gtk_widget_show ( item );
117 }
118 }
119}