diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2010-09-30 05:19:31 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2010-10-26 13:58:33 +0200 |
commit | e0e63649dc830cd63ae4e7a958e224ef3b2a1375 (patch) | |
tree | bfd6ebef764e0e439b2207d1f9d9ddb09985a0bd /src | |
parent | 0c9b297e50ffaf9a34f50a99f7bc4e02ea295d1d (diff) | |
download | logdiag-e0e63649dc830cd63ae4e7a958e224ef3b2a1375.tar.gz logdiag-e0e63649dc830cd63ae4e7a958e224ef3b2a1375.tar.xz logdiag-e0e63649dc830cd63ae4e7a958e224ef3b2a1375.zip |
Redesign the library and related components.
This step is needed, since the current design is quite chaotic
and it would not be possible to finish the application.
There's still a lot to be done.
After this step, it's time to implement the rest of LdLua.
Diffstat (limited to 'src')
-rw-r--r-- | src/ld-library.c | 15 | ||||
-rw-r--r-- | src/ld-library.h | 3 | ||||
-rw-r--r-- | src/ld-lua-symbol.c | 12 | ||||
-rw-r--r-- | src/ld-lua-symbol.h | 2 | ||||
-rw-r--r-- | src/ld-lua.c | 5 | ||||
-rw-r--r-- | src/ld-symbol-category.c | 101 | ||||
-rw-r--r-- | src/ld-symbol-category.h | 42 | ||||
-rw-r--r-- | src/ld-symbol.c | 24 | ||||
-rw-r--r-- | src/ld-symbol.h | 10 | ||||
-rw-r--r-- | src/ld-window-main.c | 10 |
10 files changed, 139 insertions, 85 deletions
diff --git a/src/ld-library.c b/src/ld-library.c index ba12d5d..d4eec09 100644 --- a/src/ld-library.c +++ b/src/ld-library.c @@ -12,9 +12,10 @@ #include "config.h" -#include "ld-library.h" -#include "ld-symbol-category.h" #include "ld-symbol.h" +#include "ld-symbol-category.h" +#include "ld-library.h" + #include "ld-lua.h" @@ -132,9 +133,10 @@ load_category (LdLibrary *self, const char *path, const char *name) /* TODO: Search for category.json and read the category name from it. */ /* TODO: Search for xyz.lua and load the objects into the category. */ - cat = ld_symbol_category_new (self); - cat->name = g_strdup (name); - cat->image_path = icon_file; + cat = ld_symbol_category_new (name); + ld_symbol_category_set_image_path (cat, icon_file); + + g_free (icon_file); return cat; } @@ -167,7 +169,8 @@ ld_library_load (LdLibrary *self, const char *path) categ_path = g_build_filename (path, item, NULL); cat = load_category (self, categ_path, item); if (cat) - g_hash_table_insert (self->categories, cat->name, cat); + g_hash_table_insert (self->categories, + g_strdup (ld_symbol_category_get_name (cat)), cat); g_free (categ_path); changed = TRUE; diff --git a/src/ld-library.h b/src/ld-library.h index 3dd052f..76a76a5 100644 --- a/src/ld-library.h +++ b/src/ld-library.h @@ -59,8 +59,7 @@ struct _LdLibraryClass GType ld_library_get_type (void) G_GNUC_CONST; LdLibrary *ld_library_new (void); -gboolean ld_library_load (LdLibrary *self, - const gchar *directory); +gboolean ld_library_load (LdLibrary *self, const gchar *directory); void ld_library_clear (LdLibrary *self); diff --git a/src/ld-lua-symbol.c b/src/ld-lua-symbol.c index b3e13af..63a1665 100644 --- a/src/ld-lua-symbol.c +++ b/src/ld-lua-symbol.c @@ -12,9 +12,10 @@ #include "config.h" -#include "ld-library.h" #include "ld-symbol.h" #include "ld-symbol-category.h" +#include "ld-library.h" + #include "ld-lua.h" #include "ld-lua-symbol.h" @@ -35,6 +36,10 @@ struct _LdLuaSymbolPrivate { LdLua *lua; + /* XXX: Note that this identifier != symbol name, + * since there can be more symbols with the same name, + * only in different categories. + */ gchar *ident; }; @@ -88,15 +93,18 @@ ld_lua_symbol_finalize (GObject *gobject) * Load a symbol from a file into the library. */ LdSymbol * -ld_lua_symbol_new (LdLua *lua, const gchar *ident) +ld_lua_symbol_new (const gchar *name, LdLua *lua, const gchar *ident) { LdLuaSymbol *self; + g_return_val_if_fail (name != NULL, NULL); g_return_val_if_fail (LD_IS_LUA (lua), NULL); g_return_val_if_fail (ident != NULL, NULL); self = g_object_new (LD_TYPE_LUA_SYMBOL, NULL); + /* TODO: Set the symbol name. */ + self->priv->lua = lua; g_object_ref (lua); diff --git a/src/ld-lua-symbol.h b/src/ld-lua-symbol.h index 9e5af9b..c8b6f35 100644 --- a/src/ld-lua-symbol.h +++ b/src/ld-lua-symbol.h @@ -53,7 +53,7 @@ struct _LdLuaSymbolClass GType ld_lua_symbol_get_type (void) G_GNUC_CONST; -LdSymbol *ld_lua_symbol_new (LdLua *lua, const gchar *ident); +LdSymbol *ld_lua_symbol_new (const gchar *name, LdLua *lua, const gchar *ident); G_END_DECLS diff --git a/src/ld-lua.c b/src/ld-lua.c index 5e4da89..c95a46e 100644 --- a/src/ld-lua.c +++ b/src/ld-lua.c @@ -15,9 +15,10 @@ #include "config.h" -#include "ld-library.h" -#include "ld-symbol-category.h" #include "ld-symbol.h" +#include "ld-symbol-category.h" +#include "ld-library.h" + #include "ld-lua.h" diff --git a/src/ld-symbol-category.c b/src/ld-symbol-category.c index 96e6bd1..15c1351 100644 --- a/src/ld-symbol-category.c +++ b/src/ld-symbol-category.c @@ -12,9 +12,9 @@ #include "config.h" -#include "ld-library.h" -#include "ld-symbol-category.h" #include "ld-symbol.h" +#include "ld-symbol-category.h" +#include "ld-library.h" /** @@ -25,6 +25,19 @@ * #LdSymbolCategory represents a category of #LdSymbol objects. */ +/* + * LdSymbolCategoryPrivate: + * @name: The name of this category. + * @image_path: Path to the image for this category. + * @children: Children of this category. + */ +struct _LdSymbolCategoryPrivate +{ + gchar *name; + gchar *image_path; + GSList *children; +}; + G_DEFINE_TYPE (LdSymbolCategory, ld_symbol_category, G_TYPE_OBJECT); static void @@ -38,16 +51,15 @@ ld_symbol_category_class_init (LdSymbolCategoryClass *klass) object_class = G_OBJECT_CLASS (klass); object_class->finalize = ld_symbol_category_finalize; + + g_type_class_add_private (klass, sizeof (LdSymbolCategoryPrivate)); } static void ld_symbol_category_init (LdSymbolCategory *self) { - /* TODO: use _new_full, correct equal and specify destroy functions. */ - /* XXX: How's the situation with subcategory names and symbol names - * within the same hashtable? - */ - self->children = g_hash_table_new (g_str_hash, g_str_equal); + self->priv = G_TYPE_INSTANCE_GET_PRIVATE + (self, LD_TYPE_SYMBOL_CATEGORY, LdSymbolCategoryPrivate); } static void @@ -57,13 +69,10 @@ ld_symbol_category_finalize (GObject *gobject) self = LD_SYMBOL_CATEGORY (gobject); - if (self->name) - g_free (self->name); - if (self->image_path) - g_free (self->image_path); - - g_object_unref (self->parent); - g_hash_table_destroy (self->children); + if (self->priv->name) + g_free (self->priv->name); + if (self->priv->image_path) + g_free (self->priv->image_path); /* Chain up to the parent class. */ G_OBJECT_CLASS (ld_symbol_category_parent_class)->finalize (gobject); @@ -76,15 +85,71 @@ ld_symbol_category_finalize (GObject *gobject) * Create an instance. */ LdSymbolCategory * -ld_symbol_category_new (LdLibrary *parent) +ld_symbol_category_new (const gchar *name) { LdSymbolCategory *cat; cat = g_object_new (LD_TYPE_SYMBOL_CATEGORY, NULL); - - cat->parent = parent; - g_object_ref (parent); + cat->priv->name = g_strdup (name); return cat; } +/** + * ld_symbol_category_set_name: + * @self: An #LdSymbolCategory object. + * @name: The new name for this category. + */ +void +ld_symbol_category_set_name (LdSymbolCategory *self, const gchar *name) +{ + g_return_if_fail (LD_IS_SYMBOL_CATEGORY (self)); + g_return_if_fail (name != NULL); + + if (self->priv->name) + g_free (self->priv->name); + self->priv->name = g_strdup (name); +} + +/** + * ld_symbol_category_get_name: + * @self: An #LdSymbolCategory object. + * + * Return the name of this category. + */ +const gchar * +ld_symbol_category_get_name (LdSymbolCategory *self) +{ + g_return_val_if_fail (LD_IS_SYMBOL_CATEGORY (self), NULL); + return self->priv->name; +} + +/** + * ld_symbol_category_set_image_path: + * @self: An #LdSymbolCategory object. + * @image_path: The new path to the image for this category. May be NULL. + */ +void +ld_symbol_category_set_image_path (LdSymbolCategory *self, + const gchar *image_path) +{ + g_return_if_fail (LD_IS_SYMBOL_CATEGORY (self)); + + if (self->priv->image_path) + g_free (self->priv->image_path); + self->priv->image_path = g_strdup (image_path); +} + +/** + * ld_symbol_category_get_image_path: + * @self: An #LdSymbolCategory object. + * + * Return the filesystem path to the image for this category. May be NULL. + */ +const gchar * +ld_symbol_category_get_image_path (LdSymbolCategory *self) +{ + g_return_val_if_fail (LD_IS_SYMBOL_CATEGORY (self), NULL); + return self->priv->image_path; +} + diff --git a/src/ld-symbol-category.h b/src/ld-symbol-category.h index 42ad8ac..21286c9 100644 --- a/src/ld-symbol-category.h +++ b/src/ld-symbol-category.h @@ -27,33 +27,24 @@ G_BEGIN_DECLS ((obj), LD_SYMBOL_CATEGORY, LdSymbolCategoryClass)) typedef struct _LdSymbolCategory LdSymbolCategory; +typedef struct _LdSymbolCategoryPrivate LdSymbolCategoryPrivate; typedef struct _LdSymbolCategoryClass LdSymbolCategoryClass; /** * LdSymbolCategory: - * @parent: The parent object, may be #LdLibrary - * or another #LdSymbolCategory. - * @name: The name of the category. - * @image_path: Path to the image for this category. - * @children: Children of this category. - */ -/* TODO: Make the public fields private and set them as properties - * + implement setters and getters. On change the category - * shall emit a "changed" signal in the Library. */ struct _LdSymbolCategory { /*< private >*/ GObject parent_instance; - -/*< public >*/ - gpointer parent; - gchar *name; - gchar *image_path; - GHashTable *children; + LdSymbolCategoryPrivate *priv; }; +/* TODO: If required sometime, categories (and maybe symbols) should implement + * a "changed" signal. This can be somewhat tricky. The library might be + * a good candidate for what they call a proxy. See GtkUIManager. + */ struct _LdSymbolCategoryClass { GObjectClass parent_class; @@ -62,13 +53,20 @@ struct _LdSymbolCategoryClass GType ld_symbol_category_get_type (void) G_GNUC_CONST; -LdSymbolCategory * -ld_symbol_category_new (LdLibrary *parent); - -/* TODO: Methods for inserting and removing children. */ -/* TODO: Create a separate ld-symbol-private.h, include it in this ld-s-c.c - * and then assign and ref the parent category here. - */ +LdSymbolCategory *ld_symbol_category_new (const gchar *name); + +/* TODO: Create properties for "name" and "image_path". */ +void ld_symbol_category_set_name (LdSymbolCategory *self, const gchar *name); +const gchar *ld_symbol_category_get_name (LdSymbolCategory *self); +void ld_symbol_category_set_image_path (LdSymbolCategory *self, + const gchar *image_path); +const gchar *ld_symbol_category_get_image_path (LdSymbolCategory *self); +/* TODO: Implement. */ +void ld_symbol_category_insert_child (LdSymbolCategory *self, + GObject *child, gint pos); +void ld_symbol_category_remove_child (LdSymbolCategory *self, + GObject *child); +GSList *ld_symbol_category_get_children (LdSymbolCategory *self); G_END_DECLS diff --git a/src/ld-symbol.c b/src/ld-symbol.c index 9dc4394..0c79d23 100644 --- a/src/ld-symbol.c +++ b/src/ld-symbol.c @@ -12,9 +12,9 @@ #include "config.h" -#include "ld-library.h" -#include "ld-symbol-category.h" #include "ld-symbol.h" +#include "ld-symbol-category.h" +#include "ld-library.h" /** @@ -28,12 +28,11 @@ /* * LdSymbolPrivate: - * @parent: The parent LdSymbolCategory. It is used to identify - * the object within it's library. + * @name: The name of this symbol. */ struct _LdSymbolPrivate { - LdSymbolCategory *parent; + gchar *name; }; G_DEFINE_ABSTRACT_TYPE (LdSymbol, ld_symbol, G_TYPE_OBJECT); @@ -65,27 +64,12 @@ ld_symbol_finalize (GObject *gobject) LdSymbol *self; self = LD_SYMBOL (gobject); - g_object_unref (self->priv->parent); /* Chain up to the parent class. */ G_OBJECT_CLASS (ld_symbol_parent_class)->finalize (gobject); } /** - * ld_symbol_build_identifier: - * @self: A symbol object. - * - * Build an identifier for the symbol. - * The identifier is in the format "Category/Category/Symbol". - */ -gchar * -ld_symbol_build_identifier (LdSymbol *self) -{ - /* TODO: Implement. */ - return NULL; -} - -/** * ld_symbol_draw: * @self: A symbol object. * @cr: A cairo surface to be drawn on. diff --git a/src/ld-symbol.h b/src/ld-symbol.h index 8ead147..7e8a00e 100644 --- a/src/ld-symbol.h +++ b/src/ld-symbol.h @@ -40,9 +40,6 @@ struct _LdSymbol /*< private >*/ GObject parent_instance; LdSymbolPrivate *priv; - -/*< public >*/ - gchar *name; }; /** @@ -60,13 +57,10 @@ struct _LdSymbolClass GType ld_symbol_get_type (void) G_GNUC_CONST; -gchar *ld_symbol_build_identifier (LdSymbol *self); - void ld_symbol_draw (LdSymbol *self, cairo_t *cr); -/* TODO: An interface for symbol terminals etc. */ -/* TODO: Store a pointer to the parent, probably as a property, - * using g_object_add_weak_pointer/remove_weak_pointer. +/* TODO: Interface for symbol terminals + * Interface + property for symbol name (will be used by _new) */ diff --git a/src/ld-window-main.c b/src/ld-window-main.c index d37488f..236e118 100644 --- a/src/ld-window-main.c +++ b/src/ld-window-main.c @@ -13,11 +13,13 @@ #include "config.h" #include "ld-window-main.h" + +#include "ld-symbol.h" +#include "ld-symbol-category.h" +#include "ld-library.h" + #include "ld-document.h" #include "ld-canvas.h" -#include "ld-library.h" -#include "ld-symbol-category.h" -#include "ld-symbol.h" /** @@ -286,7 +288,7 @@ cb_load_category (gpointer key, gpointer value, gpointer user_data) g_return_if_fail (LD_IS_SYMBOL_CATEGORY (cat)); pbuf = gdk_pixbuf_new_from_file_at_size - (cat->image_path, TOOLBAR_ICON_WIDTH, -1, NULL); + (ld_symbol_category_get_image_path (cat), TOOLBAR_ICON_WIDTH, -1, NULL); g_return_if_fail (pbuf != NULL); img = gtk_image_new_from_pixbuf (pbuf); |