]> git.street.me.uk Git - andy/viking.git/blob - src/vikexttools.c
[QA] Shift Gtk dependent utility functions into separate file.
[andy/viking.git] / src / vikexttools.c
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   if ( IS_VIK_EXT_TOOL( tool ) )
39     ext_tools_list = g_list_append ( ext_tools_list, g_object_ref ( tool ) );
40 }
41
42 void vik_ext_tools_unregister_all ()
43 {
44   g_list_foreach ( ext_tools_list, (GFunc) g_object_unref, NULL );
45 }
46
47 static void ext_tools_open_cb ( GtkWidget *widget, VikWindow *vwindow )
48 {
49   gpointer ptr = g_object_get_data ( G_OBJECT(widget), VIK_TOOL_DATA_KEY );
50   VikExtTool *ext_tool = VIK_EXT_TOOL ( ptr );
51   vik_ext_tool_open ( ext_tool, vwindow );
52 }
53
54 void vik_ext_tools_add_action_items ( VikWindow *vwindow, GtkUIManager *uim, GtkActionGroup *action_group, guint mid )
55 {
56   GList *iter;
57   for (iter = ext_tools_list; iter; iter = iter->next)
58   {
59     VikExtTool *ext_tool = NULL;
60     gchar *label = NULL;
61     ext_tool = VIK_EXT_TOOL ( iter->data );
62     label = vik_ext_tool_get_label ( ext_tool );
63     if ( label )
64     {
65       gtk_ui_manager_add_ui ( uim, mid, "/ui/MainMenu/Tools/Exttools",
66                               _(label),
67                               label,
68                               GTK_UI_MANAGER_MENUITEM, FALSE );
69
70       GtkAction *action = gtk_action_new ( label, label, NULL, NULL );
71       g_object_set_data ( G_OBJECT(action), VIK_TOOL_DATA_KEY, ext_tool );
72       g_signal_connect ( G_OBJECT(action), "activate", G_CALLBACK(ext_tools_open_cb), vwindow );
73
74       gtk_action_group_add_action ( action_group, action );
75
76       g_object_unref ( action );
77
78       g_free ( label ); label = NULL;
79     }
80   }
81 }