ui: glade - added initial glade support - needs support files.
[nova.git] / src / main.c
blob402384e8cf45d1fe98f7dd9902fed3a854473afe
1 /*
2 * Copyright (C) 2008 Liam Girdwood
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330,
17 * Boston, MA 02111-1307, USA.
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
24 #include <gtk/gtk.h>
26 #include "db/db.h"
27 #include "sky/sky.h"
28 #include "sky/legend.h"
29 #include "ui/glade.h"
31 static gboolean menu_help_clicked_event(GtkWidget *widget,
32 gpointer user_data)
34 printf("about\n");
35 return TRUE;
38 static GtkItemFactoryEntry menu_items[] = {
39 { "/_File", NULL, NULL, 0, "<Branch>" },
40 { "/File/_New", "<control>N", NULL, 0, "<StockItem>", GTK_STOCK_NEW },
41 { "/File/_Open", "<control>O", NULL, 0, "<StockItem>", GTK_STOCK_OPEN },
42 { "/File/_Save", "<control>S", NULL, 0, "<StockItem>", GTK_STOCK_SAVE },
43 { "/File/Save _As", NULL, NULL, 0, "<Item>" },
44 { "/File/sep1", NULL, NULL, 0, "<Separator>" },
45 { "/File/_Quit", "<CTRL>Q", gtk_main_quit, 0, "<StockItem>", GTK_STOCK_QUIT },
46 { "/_Help", NULL, NULL, 0, "<LastBranch>" },
47 { "/_Help/About", NULL, G_CALLBACK(menu_help_clicked_event), 0, "<Item>" },
50 static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
52 static GtkWidget *get_menubar_menu(GtkWidget *window)
54 GtkItemFactory *item_factory;
55 GtkAccelGroup *accel_group;
57 accel_group = gtk_accel_group_new();
58 item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>",
59 accel_group);
61 gtk_item_factory_create_items(item_factory, nmenu_items, menu_items, NULL);
62 gtk_window_add_accel_group(GTK_WINDOW (window), accel_group);
64 return gtk_item_factory_get_widget(item_factory, "<main>");
67 static gboolean tool_button_clicked_event(GtkWidget *widget,
68 gpointer user_data)
70 printf("convert\n");
71 return TRUE;
74 static GtkWidget *create_toolbar(void)
76 GtkWidget *toolbar;
77 GtkToolItem *item;
79 toolbar = gtk_toolbar_new();
80 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS);
82 item = gtk_toggle_tool_button_new_from_stock(GTK_STOCK_CONVERT);
83 gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, 0);
84 g_signal_connect(item, "clicked",
85 G_CALLBACK(tool_button_clicked_event), NULL);
87 return toolbar;
90 int main (int argc, char **argv)
92 GtkWidget *window;
93 GtkWidget *gtk_sky;
94 GtkWidget *gtk_legend;
95 GtkWidget *vbox;
96 GtkWidget *menubar;
97 GtkWidget *toolbar;
98 int err;
100 #ifdef ENABLE_NLS
101 bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
102 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
103 textdomain (GETTEXT_PACKAGE);
104 #endif
106 gtk_init (&argc, &argv);
108 err = db_init();
109 if (err < 0)
110 g_critical("db_init: failed %d\n", err);
112 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
113 gtk_window_set_title(GTK_WINDOW(window), "Nova");
114 g_signal_connect (window, "destroy",
115 G_CALLBACK (gtk_main_quit), NULL);
117 gtk_sky = virtual_sky_new();
118 gtk_widget_set_usize(gtk_sky, 800, 600);
120 gtk_legend = legend_new();
121 gtk_widget_set_usize(gtk_legend, -1, 20);
123 menubar = get_menubar_menu (window);
124 toolbar = create_toolbar();
126 vbox = gtk_vbox_new(FALSE, 0);
127 gtk_container_add(GTK_CONTAINER(window), vbox);
128 gtk_box_pack_start (GTK_BOX (vbox), menubar, FALSE, TRUE, 0);
129 gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, TRUE, 0);
130 gtk_box_pack_start(GTK_BOX(vbox),
131 gtk_sky,
132 TRUE, TRUE, 0);
133 gtk_box_pack_start(GTK_BOX(vbox),
134 gtk_legend,
135 FALSE, FALSE, 0);
137 load_glade();
139 gtk_widget_show_all(window);
140 sky_connect_signals(gtk_sky);
141 sky_set_legend(gtk_sky, gtk_legend);
143 gtk_main ();
145 db_release();
146 return 0;