diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2010-09-15 19:31:57 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2010-09-15 19:31:57 +0200 |
commit | 55c25ae1bd95b9956952a4fe0c9699bb62251079 (patch) | |
tree | 7cb58ce6d0d791baeac2583589beff9f2cb39750 /src/window-main.c | |
parent | 82cfa129209fbc76cd8fdac992703f66ccccfc7a (diff) | |
download | logdiag-55c25ae1bd95b9956952a4fe0c9699bb62251079.tar.gz logdiag-55c25ae1bd95b9956952a4fe0c9699bb62251079.tar.xz logdiag-55c25ae1bd95b9956952a4fe0c9699bb62251079.zip |
Added basic loading of categories.
Added two empty sample categories with corresponding icons.
The categories are now being loaded into the toolbar
in the main program window.
Diffstat (limited to 'src/window-main.c')
-rw-r--r-- | src/window-main.c | 74 |
1 files changed, 64 insertions, 10 deletions
diff --git a/src/window-main.c b/src/window-main.c index f5133e5..43ce429 100644 --- a/src/window-main.c +++ b/src/window-main.c @@ -14,6 +14,7 @@ #include "window-main.h" #include "symbol-library.h" +#include "symbol-category.h" /** @@ -45,6 +46,24 @@ struct _LogdiagWindowMainPrivate G_DEFINE_TYPE (LogdiagWindowMain, logdiag_window_main, GTK_TYPE_WINDOW); +/* ===== Local functions =================================================== */ + +/* + * cb_load_category: + * + * A hashtable foreach callback for adding categories into the toolbar. + */ +static void +cb_load_category (gpointer key, gpointer value, gpointer user_data); + +/* + * load_toolbar: + * + * Load symbols from the library into the toolbar. + */ +static void +load_toolbar (LogdiagWindowMain *self); + /* * cb_ui_proxy_connected: * @@ -76,6 +95,8 @@ static void cb_show_about_dialog (GtkAction *action, LogdiagWindowMain *window); +/* ===== Local variables =================================================== */ + /* Actions for menus, toolbars, accelerators. */ static GtkActionEntry mw_actionEntries[] = { @@ -177,10 +198,10 @@ logdiag_window_main_init (LogdiagWindowMain *self) priv->menu = gtk_ui_manager_get_widget (ui_manager, "/MenuBar"); gtk_box_pack_start (GTK_BOX (priv->vbox), priv->menu, FALSE, FALSE, 0); - priv->hbox = gtk_hbox_new(FALSE, 0); gtk_box_pack_start (GTK_BOX (priv->vbox), priv->hbox, TRUE, TRUE, 0); + /* Add the symbol toolbar. */ priv->toolbar = gtk_toolbar_new (); /* NOTE: For GTK 2.16+, s/toolbar/orientable/ */ gtk_toolbar_set_orientation @@ -190,18 +211,13 @@ logdiag_window_main_init (LogdiagWindowMain *self) gtk_toolbar_set_style (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS); + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->toolbar, FALSE, FALSE, 0); + /* Symbol library. */ priv->library = logdiag_symbol_library_new (); - logdiag_symbol_library_load (priv->library, PROJECT_SHARE_DIR "library/"); - - /* TODO: Show contents of the library in the toolbar. */ - GtkToolItem *item; - item = gtk_tool_button_new (/* icon widget */ NULL, _("Blah")); - gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), "network"); - gtk_toolbar_insert (GTK_TOOLBAR (priv->toolbar), item, 0); - /* http://library.gnome.org/devel/gdk-pixbuf/unstable/ */ + logdiag_symbol_library_load (priv->library, PROJECT_SHARE_DIR "library"); - gtk_box_pack_start (GTK_BOX (priv->hbox), priv->toolbar, FALSE, FALSE, 0); + load_toolbar (self); /* TODO: GtkHPaned */ @@ -221,6 +237,44 @@ logdiag_window_main_init (LogdiagWindowMain *self) } static void +cb_load_category (gpointer key, gpointer value, gpointer user_data) +{ + const gchar *name; + LogdiagSymbolCategory *cat; + LogdiagWindowMain *self; + GdkPixbuf *pbuf; + GtkWidget *img; + GtkToolItem *item; + + name = key; + cat = value; + self = user_data; + + g_return_if_fail (key != NULL); + g_return_if_fail (LOGDIAG_IS_SYMBOL_CATEGORY (cat)); + + /* XXX: Hardcoded icon width, unref? */ + pbuf = gdk_pixbuf_new_from_file_at_size (cat->image_path, 32, -1, NULL); + if (!pbuf) + return; + img = gtk_image_new_from_pixbuf (pbuf); + g_object_unref (pbuf); + + item = gtk_tool_button_new (img, name); + gtk_tool_item_set_tooltip_text (item, name); + gtk_toolbar_insert (GTK_TOOLBAR (self->priv->toolbar), item, 0); +} + +static void +load_toolbar (LogdiagWindowMain *self) +{ + /* TODO: Clear the toolbar first, if there was already something in it. */ + + g_hash_table_foreach (self->priv->library->categories, + cb_load_category, self); +} + +static void cb_ui_proxy_connected (GtkUIManager *ui, GtkAction *action, GtkWidget *proxy, LogdiagWindowMain *window) { |