aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/symbol-category.h5
-rw-r--r--src/symbol-library.c9
-rw-r--r--src/window-main.c74
3 files changed, 72 insertions, 16 deletions
diff --git a/src/symbol-category.h b/src/symbol-category.h
index bb0a6de..e6b1b75 100644
--- a/src/symbol-category.h
+++ b/src/symbol-category.h
@@ -27,7 +27,6 @@ G_BEGIN_DECLS
((obj), LOGDIAG_SYMBOL_CATEGORY, LogdiagSymbolCategoryClass))
typedef struct _LogdiagSymbolCategory LogdiagSymbolCategory;
-/*typedef struct _LogdiagSymbolCategoryPrivate LogdiagSymbolCategoryPrivate;*/
typedef struct _LogdiagSymbolCategoryClass LogdiagSymbolCategoryClass;
@@ -46,8 +45,8 @@ struct _LogdiagSymbolCategory
/*< public >*/
gpointer parent;
- char *name;
- char *image_path;
+ gchar *name;
+ gchar *image_path;
GHashTable *children;
};
diff --git a/src/symbol-library.c b/src/symbol-library.c
index 743aa39..869e3f2 100644
--- a/src/symbol-library.c
+++ b/src/symbol-library.c
@@ -74,8 +74,8 @@ logdiag_symbol_library_init (LogdiagSymbolLibrary *self)
/* TODO: lua */
self->priv->lua_state = NULL;
- /* TODO: use _new_full and specify destroy functions. */
- self->categories = g_hash_table_new (g_str_hash, g_str_equal);
+ self->categories = g_hash_table_new_full (g_str_hash, g_str_equal,
+ (GDestroyNotify) g_free, (GDestroyNotify) g_object_unref);
}
static void
@@ -110,7 +110,7 @@ logdiag_symbol_library_new (void)
*
* Loads a category into the library.
*/
-LogdiagSymbolCategory *
+static LogdiagSymbolCategory *
load_category (LogdiagSymbolLibrary *self, const char *path, const char *name)
{
LogdiagSymbolCategory *cat;
@@ -120,6 +120,9 @@ load_category (LogdiagSymbolLibrary *self, const char *path, const char *name)
g_return_val_if_fail (path != NULL, NULL);
g_return_val_if_fail (name != NULL, NULL);
+ if (!g_file_test (path, G_FILE_TEST_IS_DIR))
+ return NULL;
+
icon_file = g_build_filename (path, "icon.svg", NULL);
if (!g_file_test (icon_file, G_FILE_TEST_IS_REGULAR))
{
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)
{