summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2010-09-15 19:31:57 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2010-09-15 19:31:57 +0200
commit55c25ae1bd95b9956952a4fe0c9699bb62251079 (patch)
tree7cb58ce6d0d791baeac2583589beff9f2cb39750
parent82cfa129209fbc76cd8fdac992703f66ccccfc7a (diff)
downloadlogdiag-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.
-rw-r--r--share/library/Logical/icon.svg125
-rw-r--r--share/library/Passive/icon.svg94
-rw-r--r--src/symbol-category.h5
-rw-r--r--src/symbol-library.c9
-rw-r--r--src/window-main.c74
5 files changed, 291 insertions, 16 deletions
diff --git a/share/library/Logical/icon.svg b/share/library/Logical/icon.svg
new file mode 100644
index 0000000..fdd6425
--- /dev/null
+++ b/share/library/Logical/icon.svg
@@ -0,0 +1,125 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="128"
+ height="128"
+ id="svg2"
+ version="1.1"
+ inkscape:version="0.48.0 r9654"
+ sodipodi:docname="icon.svg">
+ <defs
+ id="defs4" />
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="1"
+ inkscape:cx="56.201683"
+ inkscape:cy="68.554775"
+ inkscape:document-units="px"
+ inkscape:current-layer="g3016-8"
+ showgrid="true"
+ inkscape:window-width="1280"
+ inkscape:window-height="748"
+ inkscape:window-x="0"
+ inkscape:window-y="0"
+ inkscape:window-maximized="1">
+ <inkscape:grid
+ type="xygrid"
+ id="grid3780"
+ empspacing="5"
+ visible="true"
+ enabled="true"
+ snapvisiblegridlinesonly="true" />
+ </sodipodi:namedview>
+ <metadata
+ id="metadata7">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1"
+ transform="translate(0,-924.36218)">
+ <g
+ id="g3016"
+ transform="translate(-10,-60)">
+ <path
+ transform="translate(0,924.36218)"
+ inkscape:connector-curvature="0"
+ id="path3008"
+ d="m 25,108 20,0"
+ style="fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ transform="translate(0,924.36218)"
+ inkscape:connector-curvature="0"
+ id="path3010"
+ d="m 25,88 20,0"
+ style="fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ sodipodi:nodetypes="cccscc"
+ transform="translate(0,924.36218)"
+ inkscape:connector-curvature="0"
+ id="path3012"
+ d="m 45,118 0,-40 25,0 c 0,0 20,0 20,20 0,20 -20,20 -20,20 z"
+ style="fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ inkscape:connector-curvature="0"
+ id="path3014"
+ d="m 90,98 20,0"
+ style="fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
+ transform="translate(0,924.36218)" />
+ </g>
+ <g
+ id="g3016-8"
+ transform="translate(5,-5)">
+ <path
+ inkscape:connector-curvature="0"
+ id="path3010-0"
+ d="m 25,1022.3622 20,0"
+ style="fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ sodipodi:nodetypes="cccc"
+ transform="translate(0,924.36218)"
+ inkscape:connector-curvature="0"
+ id="path3012-9"
+ d="M 45,118 45,78 75,98 z"
+ style="fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ inkscape:connector-curvature="0"
+ id="path3014-6"
+ d="m 87.5,1022.3622 17.5,0"
+ style="fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
+ sodipodi:nodetypes="cc" />
+ <path
+ sodipodi:type="arc"
+ style="fill:none;stroke:#000000;stroke-width:6;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
+ id="path3820"
+ sodipodi:cx="90"
+ sodipodi:cy="93"
+ sodipodi:rx="10"
+ sodipodi:ry="10"
+ d="m 100,93 a 10,10 0 1 1 -20,0 10,10 0 1 1 20,0 z"
+ transform="matrix(0.5,0,0,0.5,37,975.86218)" />
+ </g>
+ </g>
+</svg>
diff --git a/share/library/Passive/icon.svg b/share/library/Passive/icon.svg
new file mode 100644
index 0000000..ac62a26
--- /dev/null
+++ b/share/library/Passive/icon.svg
@@ -0,0 +1,94 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+ xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+ width="128"
+ height="128"
+ id="svg2"
+ version="1.1"
+ inkscape:version="0.48.0 r9654"
+ sodipodi:docname="New document 1">
+ <defs
+ id="defs4" />
+ <sodipodi:namedview
+ id="base"
+ pagecolor="#ffffff"
+ bordercolor="#666666"
+ borderopacity="1.0"
+ inkscape:pageopacity="0.0"
+ inkscape:pageshadow="2"
+ inkscape:zoom="1"
+ inkscape:cx="65.613954"
+ inkscape:cy="65.153369"
+ inkscape:document-units="px"
+ inkscape:current-layer="g3784"
+ showgrid="true"
+ inkscape:window-width="1280"
+ inkscape:window-height="748"
+ inkscape:window-x="0"
+ inkscape:window-y="0"
+ inkscape:window-maximized="1">
+ <inkscape:grid
+ type="xygrid"
+ id="grid3780"
+ empspacing="5"
+ visible="true"
+ enabled="true"
+ snapvisiblegridlinesonly="true" />
+ </sodipodi:namedview>
+ <metadata
+ id="metadata7">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <g
+ inkscape:label="Layer 1"
+ inkscape:groupmode="layer"
+ id="layer1"
+ transform="translate(0,-924.36218)">
+ <g
+ id="g3784"
+ transform="translate(0,10)">
+ <path
+ inkscape:connector-curvature="0"
+ id="path2985"
+ d="m 15,962.36218 25,0 0,0"
+ style="fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ inkscape:connector-curvature="0"
+ id="path2987"
+ d="m 40,937.36218 0,50"
+ style="fill:none;stroke:#000000;stroke-width:5;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ inkscape:connector-curvature="0"
+ id="path2985-2"
+ d="m 85,962.36218 -25,0 0,0"
+ style="fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ <path
+ inkscape:connector-curvature="0"
+ id="path2987-7"
+ d="m 60,937.36216 0,50.00002"
+ style="fill:none;stroke:#000000;stroke-width:5;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
+ </g>
+ <path
+ style="fill:none;stroke:#000000;stroke-width:3;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none"
+ d="m 29,1033.3622 15,0 c 0,0 0,-15 10,-15 10,0 10,15 10,15 0,0 0,-15 10,-15 10,0 10,15 10,15 0,0 0,-15 10,-15 10,0 10,15 10,15 l 15,0"
+ id="path3782"
+ inkscape:connector-curvature="0"
+ sodipodi:nodetypes="ccscscscc" />
+ </g>
+</svg>
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)
{