basic lttvwindow works
[lttv.git] / ltt / branches / poly / lttv / modules / gui / lttvwindow / lttvwindow / init_module.c
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
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
30 #include <lttv/lttv.h>
31 #include <lttv/attribute.h>
32 #include <lttv/hook.h>
33 #include <lttv/option.h>
34 #include <lttv/module.h>
35 #include <lttv/tracecontext.h>
36 #include <lttv/state.h>
37 #include <lttv/stats.h>
38 #include <lttvwindow/menu.h>
39 #include <lttvwindow/toolbar.h>
40
41 #include "interface.h"
42 #include "support.h"
43 #include <lttvwindow/mainwindow.h>
44 #include <lttvwindow/mainwindow-private.h>
45 #include "callbacks.h"
46 #include <ltt/trace.h>
47
48
49 /** Array containing instanced objects. */
50 GSList * g_main_window_list = NULL ;
51
52 LttvHooks
53 *main_hooks;
54
55 /* Initial trace from command line */
56 LttvTrace *g_init_trace = NULL;
57
58 static char *a_trace;
59
60 void lttv_trace_option(void *hook_data)
61 {
62 LttTrace *trace;
63
64 trace = ltt_trace_open(a_trace);
65 if(trace == NULL) g_critical("cannot open trace %s", a_trace);
66 g_init_trace = lttv_trace_new(trace);
67 }
68
69 /*****************************************************************************
70 * Functions for module loading/unloading *
71 *****************************************************************************/
72 /**
73 * plugin's init function
74 *
75 * This function initializes the GUI.
76 */
77
78 static gboolean window_creation_hook(void *hook_data, void *call_data)
79 {
80 g_debug("GUI window_creation_hook()");
81 #ifdef ENABLE_NLS
82 bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
83 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
84 textdomain (GETTEXT_PACKAGE);
85 #endif
86
87 gtk_set_locale ();
88 gtk_init (&lttv_argc, &lttv_argv);
89
90 add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");
91 add_pixmap_directory ("pixmaps");
92 add_pixmap_directory ("../modules/gui/main/pixmaps");
93
94 construct_main_window(NULL);
95
96 gtk_main ();
97
98 return FALSE;
99 }
100
101 static void init() {
102
103 LttvAttributeValue value;
104
105 // Global attributes only used for interaction with main() here.
106 LttvIAttribute *attributes = LTTV_IATTRIBUTE(lttv_global_attributes());
107
108 g_debug("GUI init()");
109
110 lttv_option_add("trace", 't',
111 "add a trace to the trace set to analyse",
112 "pathname of the directory containing the trace",
113 LTTV_OPT_STRING, &a_trace, lttv_trace_option, NULL);
114
115 g_assert(lttv_iattribute_find_by_path(attributes, "hooks/main/before",
116 LTTV_POINTER, &value));
117 g_assert((main_hooks = *(value.v_pointer)) != NULL);
118
119 lttv_hooks_add(main_hooks, window_creation_hook, NULL, LTTV_PRIO_DEFAULT);
120
121 }
122
123 void
124 main_window_destructor(MainWindow * mw)
125 {
126 g_assert(GTK_IS_WIDGET(mw->mwindow));
127 gtk_widget_destroy(mw->mwindow);
128 }
129
130
131 /**
132 * plugin's destroy function
133 *
134 * This function releases the memory reserved by the module and unregisters
135 * everything that has been registered in the gtkTraceSet API.
136 */
137 static void destroy() {
138
139 LttvAttributeValue value;
140 LttvTrace *trace;
141 GSList *iter = NULL;
142
143 lttv_option_remove("trace");
144
145 lttv_hooks_remove_data(main_hooks, window_creation_hook, NULL);
146
147 g_debug("GUI destroy()");
148
149 if(g_main_window_list){
150 for(iter=g_main_window_list;iter!=NULL;iter=g_slist_next(iter)) {
151 main_window_destructor((MainWindow*)iter->data);
152 }
153 g_slist_free(g_main_window_list);
154 }
155
156 }
157
158
159 LTTV_MODULE("lttvwindow", "Viewer main window", \
160 "Viewer with multiple windows, tabs and panes for graphical modules", \
161 init, destroy, "stats", "option")
This page took 0.032868 seconds and 4 git commands to generate.