It compiles and runs after the cleanups
[lttv.git] / ltt / branches / poly / lttv / modules / gui / lttvwindow / src / init_module.c
CommitLineData
e076699e 1/* This file is part of the Linux Trace Toolkit viewer
2 * Copyright (C) 2003-2004 Mathieu Desnoyers and XangXiu Yang
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License Version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
16 * MA 02111-1307, USA.
17 */
18
fb87279e 19/*
20 * Initial main.c file generated by Glade. Edit as required.
21 * Glade will not overwrite this file.
22 */
23
24#ifdef HAVE_CONFIG_H
25# include <config.h>
26#endif
27
28#include <gtk/gtk.h>
29
fb87279e 30#include <lttv/lttv.h>
0a6808c0 31#include <lttv/attribute.h>
32#include <lttv/hook.h>
33#include <lttv/option.h>
34#include <lttv/module.h>
d8f124de 35#include <lttv/tracecontext.h>
ec25ff5e 36#include <lttv/state.h>
6b1d3120 37#include <lttv/stats.h>
0c56e138 38#include <lttvgui/menu.h>
39#include <lttvgui/toolbar.h>
fb87279e 40
41#include "interface.h"
42#include "support.h"
0c56e138 43#include <lttvgui/mainwindow.h>
fb87279e 44#include "callbacks.h"
a5dcde2f 45#include <ltt/trace.h>
46
fb87279e 47
ec25ff5e 48/** Array containing instanced objects. */
68b48a45 49GSList * g_main_window_list = NULL ;
ec25ff5e 50
f7afe191 51LttvHooks
ec25ff5e 52 *main_hooks;
53
f7afe191 54/* Initial trace from command line */
68b48a45 55LttvTrace *g_init_trace = NULL;
f7afe191 56
ec25ff5e 57static char *a_trace;
58
59void lttv_trace_option(void *hook_data)
60{
308711e5 61 LttTrace *trace;
62
63 trace = ltt_trace_open(a_trace);
64 if(trace == NULL) g_critical("cannot open trace %s", a_trace);
68b48a45 65 g_init_trace = lttv_trace_new(trace);
ec25ff5e 66}
fb87279e 67
68/*****************************************************************************
69 * Functions for module loading/unloading *
70 *****************************************************************************/
71/**
72 * plugin's init function
73 *
74 * This function initializes the GUI.
75 */
76
68b48a45 77static gboolean window_creation_hook(void *hook_data, void *call_data)
fb87279e 78{
2a2fa4f0 79 g_debug("GUI window_creation_hook()");
fb87279e 80#ifdef ENABLE_NLS
81 bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
82 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
83 textdomain (GETTEXT_PACKAGE);
84#endif
85
86 gtk_set_locale ();
08b1c66e 87 gtk_init (&lttv_argc, &lttv_argv);
fb87279e 88
89 add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");
90 add_pixmap_directory ("pixmaps");
077ba5c0 91 add_pixmap_directory ("../modules/gui/main/pixmaps");
fb87279e 92
08b1c66e 93 construct_main_window(NULL);
fb87279e 94
95 gtk_main ();
0a6808c0 96
ec25ff5e 97 return FALSE;
0a6808c0 98}
99
08b1c66e 100static void init() {
0a6808c0 101
ec25ff5e 102 LttvAttributeValue value;
f7afe191 103
104 // Global attributes only used for interaction with main() here.
ec25ff5e 105 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
106
2a2fa4f0 107 g_debug("GUI init()");
558aa013 108
ec25ff5e 109 lttv_option_add("trace", 't',
110 "add a trace to the trace set to analyse",
111 "pathname of the directory containing the trace",
112 LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
113
ec25ff5e 114 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
115 LTTV_POINTER, &value));
116 g_assert((main_hooks = *(value.v_pointer)) != NULL);
117
08b1c66e 118 lttv_hooks_add(main_hooks, window_creation_hook, NULL);
0a6808c0 119
fb87279e 120}
121
7a859036 122void
bca3b81f 123main_window_free(MainWindow * mw)
7a859036 124{
125 if(mw){
540edb40 126 while(mw->tab){
127 lttv_state_remove_event_hooks(
128 (LttvTracesetState*)mw->tab->traceset_info->traceset_context);
129 mw->tab = mw->tab->next;
130 }
bca3b81f 131 g_object_unref(mw->attributes);
68b48a45 132 g_main_window_list = g_slist_remove(g_main_window_list, mw);
2061e03d 133
134 g_hash_table_destroy(mw->hash_menu_item);
135 g_hash_table_destroy(mw->hash_toolbar_item);
f7afe191 136
137 g_free(mw);
138 mw = NULL;
7a859036 139 }
140}
141
142void
bca3b81f 143main_window_destructor(MainWindow * mw)
7a859036 144{
bca3b81f 145 if(GTK_IS_WIDGET(mw->mwindow)){
146 gtk_widget_destroy(mw->mwindow);
7a859036 147 // gtk_widget_destroy(mw->HelpContents);
148 // gtk_widget_destroy(mw->AboutBox);
149 mw = NULL;
150 }
68b48a45 151 //main_window_free called when the object mw in the widget is unref.
152 //main_window_free(mw);
7a859036 153}
154
155
2176f952 156void main_window_destroy_walk(gpointer data, gpointer user_data)
fb87279e 157{
bca3b81f 158 main_window_destructor((MainWindow*)data);
fb87279e 159}
160
161
162
163/**
164 * plugin's destroy function
165 *
166 * This function releases the memory reserved by the module and unregisters
167 * everything that has been registered in the gtkTraceSet API.
168 */
08b1c66e 169static void destroy() {
fb87279e 170
7a859036 171 LttvAttributeValue value;
308711e5 172 LttvTrace *trace;
ec25ff5e 173
ec25ff5e 174 lttv_option_remove("trace");
175
08b1c66e 176 lttv_hooks_remove_data(main_hooks, window_creation_hook, NULL);
ec25ff5e 177
2a2fa4f0 178 g_debug("GUI destroy()");
fb87279e 179
68b48a45 180 if(g_main_window_list){
181 g_slist_foreach(g_main_window_list, main_window_destroy_walk, NULL );
182 g_slist_free(g_main_window_list);
2176f952 183 }
ec25ff5e 184
fb87279e 185}
186
187
db2c9c14 188LTTV_MODULE("lttvwindow", "Viewer main window", \
08b1c66e 189 "Viewer with multiple windows, tabs and panes for graphical modules", \
190 init, destroy, "stats")
This page took 0.035898 seconds and 4 git commands to generate.