From c0ec389b597b5132e7db26eca3fff41fd87c0f7e Mon Sep 17 00:00:00 2001 From: Přemysl Janouch Date: Sat, 25 Sep 2010 16:14:09 +0200 Subject: Renamed LdSymbolLibrary to LdLibrary. --- src/ld-document.h | 2 +- src/ld-library.c | 199 +++++++++++++++++++++++++++++++++++++++++++++++ src/ld-library.h | 70 +++++++++++++++++ src/ld-lua.c | 2 +- src/ld-symbol-category.c | 6 +- src/ld-symbol-category.h | 4 +- src/ld-symbol-library.c | 199 ----------------------------------------------- src/ld-symbol-library.h | 70 ----------------- src/ld-symbol.c | 8 +- src/ld-symbol.h | 2 +- src/ld-window-main.c | 8 +- 11 files changed, 285 insertions(+), 285 deletions(-) create mode 100644 src/ld-library.c create mode 100644 src/ld-library.h delete mode 100644 src/ld-symbol-library.c delete mode 100644 src/ld-symbol-library.h (limited to 'src') diff --git a/src/ld-document.h b/src/ld-document.h index cc7266b..471b3ce 100644 --- a/src/ld-document.h +++ b/src/ld-document.h @@ -14,7 +14,7 @@ G_BEGIN_DECLS -#define LD_TYPE_DOCUMENT (ld_symbol_library_get_type ()) +#define LD_TYPE_DOCUMENT (ld_library_get_type ()) #define LD_DOCUMENT(obj) (G_TYPE_CHECK_INSTANCE_CAST \ ((obj), LD_TYPE_DOCUMENT, LdDocument)) #define LD_DOCUMENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \ diff --git a/src/ld-library.c b/src/ld-library.c new file mode 100644 index 0000000..d035644 --- /dev/null +++ b/src/ld-library.c @@ -0,0 +1,199 @@ +/* + * ld-library.c + * + * This file is a part of logdiag. + * Copyright Přemysl Janouch 2010. All rights reserved. + * + * See the file LICENSE for licensing information. + * + */ + +#include + +#include "config.h" + +#include "ld-library.h" +#include "ld-symbol-category.h" +#include "ld-symbol.h" + + +/** + * SECTION:ld-library + * @short_description: A symbol library. + * @see_also: #LdSymbol, #LdSymbolCategory + * + * #LdLibrary is used for loading symbols from their files. + */ + +/* + * LdLibraryPrivate: + * @script_state: State of the scripting language. + */ +struct _LdLibraryPrivate +{ + gpointer script_state; +}; + +G_DEFINE_TYPE (LdLibrary, ld_library, G_TYPE_OBJECT); + +static void +ld_library_finalize (GObject *gobject); + + +static void +ld_library_class_init (LdLibraryClass *klass) +{ + GObjectClass *object_class; + + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = ld_library_finalize; + +/** + * LdLibrary::changed: + * @library: The library object. + * + * Contents of the library have changed. + */ + klass->changed_signal = g_signal_new + ("changed", G_TYPE_FROM_CLASS (object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, + 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + + g_type_class_add_private (klass, sizeof (LdLibraryPrivate)); +} + +static void +ld_library_init (LdLibrary *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE + (self, LD_TYPE_LIBRARY, LdLibraryPrivate); + + /* TODO */ + self->priv->script_state = NULL; + + self->categories = g_hash_table_new_full (g_str_hash, g_str_equal, + (GDestroyNotify) g_free, (GDestroyNotify) g_object_unref); +} + +static void +ld_library_finalize (GObject *gobject) +{ + LdLibrary *self; + + self = LD_LIBRARY (gobject); + + g_hash_table_destroy (self->categories); + + /* Chain up to the parent class. */ + G_OBJECT_CLASS (ld_library_parent_class)->finalize (gobject); +} + +/** + * ld_library_new: + * + * Create an instance. + */ +LdLibrary * +ld_library_new (void) +{ + return g_object_new (LD_TYPE_LIBRARY, NULL); +} + +/* + * load_category: + * @self: A symbol library object. + * @path: The path to the category. + * @name: The default name of the category. + * + * Loads a category into the library. + */ +static LdSymbolCategory * +load_category (LdLibrary *self, const char *path, const char *name) +{ + LdSymbolCategory *cat; + gchar *icon_file; + + g_return_val_if_fail (LD_IS_LIBRARY (self), NULL); + 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)) + { + g_warning ("The category in %s has no icon.", path); + g_free (icon_file); + return NULL; + } + + /* 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; + return cat; +} + +/** + * ld_library_load: + * @self: A symbol library object. + * @directory: A directory to be loaded. + * + * Load the contents of a directory into the library. + */ +gboolean +ld_library_load (LdLibrary *self, const char *path) +{ + GDir *dir; + const gchar *item; + gboolean changed = FALSE; + + g_return_val_if_fail (LD_IS_LIBRARY (self), FALSE); + g_return_val_if_fail (path != NULL, FALSE); + + dir = g_dir_open (path, 0, NULL); + if (!dir) + return FALSE; + + while ((item = g_dir_read_name (dir))) + { + LdSymbolCategory *cat; + gchar *categ_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_free (categ_path); + + changed = TRUE; + } + g_dir_close (dir); + + if (changed) + g_signal_emit (self, + LD_LIBRARY_GET_CLASS (self)->changed_signal, 0); + + return TRUE; +} + +/** + * ld_library_clear: + * @self: A symbol library object. + * + * Clears all the contents. + */ +void +ld_library_clear (LdLibrary *self) +{ + g_return_if_fail (LD_IS_LIBRARY (self)); + + g_hash_table_remove_all (self->categories); + + g_signal_emit (self, + LD_LIBRARY_GET_CLASS (self)->changed_signal, 0); +} + diff --git a/src/ld-library.h b/src/ld-library.h new file mode 100644 index 0000000..3dd052f --- /dev/null +++ b/src/ld-library.h @@ -0,0 +1,70 @@ +/* + * ld-library.h + * + * This file is a part of logdiag. + * Copyright Přemysl Janouch 2010. All rights reserved. + * + * See the file LICENSE for licensing information. + * + */ + +#ifndef __LD_LIBRARY_H__ +#define __LD_LIBRARY_H__ + +G_BEGIN_DECLS + + +#define LD_TYPE_LIBRARY (ld_library_get_type ()) +#define LD_LIBRARY(obj) (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), LD_TYPE_LIBRARY, LdLibrary)) +#define LD_LIBRARY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \ + ((klass), LD_TYPE_LIBRARY, LdLibraryClass)) +#define LD_IS_LIBRARY(obj) (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), LD_TYPE_LIBRARY)) +#define LD_IS_LIBRARY_CLASS(klass) (G_TYPE_CHECK_INSTANCE_TYPE \ + ((klass), LD_TYPE_LIBRARY)) +#define LD_LIBRARY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), LD_LIBRARY, LdLibraryClass)) + +typedef struct _LdLibrary LdLibrary; +typedef struct _LdLibraryPrivate LdLibraryPrivate; +typedef struct _LdLibraryClass LdLibraryClass; + + +/** + * LdLibrary: + * @categories: Lists all the categories (#LdSymbolCategory). + * + * Object structure. + */ +struct _LdLibrary +{ +/*< private >*/ + GObject parent_instance; + LdLibraryPrivate *priv; + +/*< public >*/ + GHashTable *categories; +}; + +struct _LdLibraryClass +{ +/*< private >*/ + GObjectClass parent_class; + + guint changed_signal; +}; + + +GType ld_library_get_type (void) G_GNUC_CONST; + +LdLibrary *ld_library_new (void); +gboolean ld_library_load (LdLibrary *self, + const gchar *directory); +void ld_library_clear (LdLibrary *self); + + +G_END_DECLS + +#endif /* ! __LD_LIBRARY_H__ */ + diff --git a/src/ld-lua.c b/src/ld-lua.c index 02ff7ac..9bf0e76 100644 --- a/src/ld-lua.c +++ b/src/ld-lua.c @@ -15,7 +15,7 @@ #include "config.h" -#include "ld-symbol-library.h" +#include "ld-library.h" #include "ld-lua.h" diff --git a/src/ld-symbol-category.c b/src/ld-symbol-category.c index 8bfe419..96e6bd1 100644 --- a/src/ld-symbol-category.c +++ b/src/ld-symbol-category.c @@ -12,7 +12,7 @@ #include "config.h" -#include "ld-symbol-library.h" +#include "ld-library.h" #include "ld-symbol-category.h" #include "ld-symbol.h" @@ -20,7 +20,7 @@ /** * SECTION:ld-symbol-category * @short_description: A category of symbols. - * @see_also: #LdSymbol, #LdSymbolLibrary + * @see_also: #LdSymbol, #LdLibrary * * #LdSymbolCategory represents a category of #LdSymbol objects. */ @@ -76,7 +76,7 @@ ld_symbol_category_finalize (GObject *gobject) * Create an instance. */ LdSymbolCategory * -ld_symbol_category_new (LdSymbolLibrary *parent) +ld_symbol_category_new (LdLibrary *parent) { LdSymbolCategory *cat; diff --git a/src/ld-symbol-category.h b/src/ld-symbol-category.h index c06f46a..6f48606 100644 --- a/src/ld-symbol-category.h +++ b/src/ld-symbol-category.h @@ -32,7 +32,7 @@ typedef struct _LdSymbolCategoryClass LdSymbolCategoryClass; /** * LdSymbolCategory: - * @parent: The parent object, may be #LdSymbolLibrary + * @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. @@ -63,7 +63,7 @@ struct _LdSymbolCategoryClass GType ld_symbol_category_get_type (void) G_GNUC_CONST; LdSymbolCategory * -ld_symbol_category_new (LdSymbolLibrary *parent); +ld_symbol_category_new (LdLibrary *parent); G_END_DECLS diff --git a/src/ld-symbol-library.c b/src/ld-symbol-library.c deleted file mode 100644 index 2f5f9d3..0000000 --- a/src/ld-symbol-library.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * ld-symbol-library.c - * - * This file is a part of logdiag. - * Copyright Přemysl Janouch 2010. All rights reserved. - * - * See the file LICENSE for licensing information. - * - */ - -#include - -#include "config.h" - -#include "ld-symbol-library.h" -#include "ld-symbol-category.h" -#include "ld-symbol.h" - - -/** - * SECTION:ld-symbol-library - * @short_description: A symbol library. - * @see_also: #LdSymbol, #LdSymbolCategory - * - * #LdSymbolLibrary is used for loading symbols from their files. - */ - -/* - * LdSymbolLibraryPrivate: - * @script_state: State of the scripting language. - */ -struct _LdSymbolLibraryPrivate -{ - gpointer script_state; -}; - -G_DEFINE_TYPE (LdSymbolLibrary, ld_symbol_library, G_TYPE_OBJECT); - -static void -ld_symbol_library_finalize (GObject *gobject); - - -static void -ld_symbol_library_class_init (LdSymbolLibraryClass *klass) -{ - GObjectClass *object_class; - - object_class = G_OBJECT_CLASS (klass); - object_class->finalize = ld_symbol_library_finalize; - -/** - * LdSymbolLibrary::changed: - * @library: The library object. - * - * Contents of the library have changed. - */ - klass->changed_signal = g_signal_new - ("changed", G_TYPE_FROM_CLASS (object_class), - G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS, - 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); - - g_type_class_add_private (klass, sizeof (LdSymbolLibraryPrivate)); -} - -static void -ld_symbol_library_init (LdSymbolLibrary *self) -{ - self->priv = G_TYPE_INSTANCE_GET_PRIVATE - (self, LD_TYPE_SYMBOL_LIBRARY, LdSymbolLibraryPrivate); - - /* TODO */ - self->priv->script_state = NULL; - - self->categories = g_hash_table_new_full (g_str_hash, g_str_equal, - (GDestroyNotify) g_free, (GDestroyNotify) g_object_unref); -} - -static void -ld_symbol_library_finalize (GObject *gobject) -{ - LdSymbolLibrary *self; - - self = LD_SYMBOL_LIBRARY (gobject); - - g_hash_table_destroy (self->categories); - - /* Chain up to the parent class. */ - G_OBJECT_CLASS (ld_symbol_library_parent_class)->finalize (gobject); -} - -/** - * ld_symbol_library_new: - * - * Create an instance. - */ -LdSymbolLibrary * -ld_symbol_library_new (void) -{ - return g_object_new (LD_TYPE_SYMBOL_LIBRARY, NULL); -} - -/* - * load_category: - * @self: A symbol library object. - * @path: The path to the category. - * @name: The default name of the category. - * - * Loads a category into the library. - */ -static LdSymbolCategory * -load_category (LdSymbolLibrary *self, const char *path, const char *name) -{ - LdSymbolCategory *cat; - gchar *icon_file; - - g_return_val_if_fail (LD_IS_SYMBOL_LIBRARY (self), NULL); - 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)) - { - g_warning ("The category in %s has no icon.", path); - g_free (icon_file); - return NULL; - } - - /* 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; - return cat; -} - -/** - * ld_symbol_library_load: - * @self: A symbol library object. - * @directory: A directory to be loaded. - * - * Load the contents of a directory into the library. - */ -gboolean -ld_symbol_library_load (LdSymbolLibrary *self, const char *path) -{ - GDir *dir; - const gchar *item; - gboolean changed = FALSE; - - g_return_val_if_fail (LD_IS_SYMBOL_LIBRARY (self), FALSE); - g_return_val_if_fail (path != NULL, FALSE); - - dir = g_dir_open (path, 0, NULL); - if (!dir) - return FALSE; - - while ((item = g_dir_read_name (dir))) - { - LdSymbolCategory *cat; - gchar *categ_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_free (categ_path); - - changed = TRUE; - } - g_dir_close (dir); - - if (changed) - g_signal_emit (self, - LD_SYMBOL_LIBRARY_GET_CLASS (self)->changed_signal, 0); - - return TRUE; -} - -/** - * ld_symbol_library_clear: - * @self: A symbol library object. - * - * Clears all the contents. - */ -void -ld_symbol_library_clear (LdSymbolLibrary *self) -{ - g_return_if_fail (LD_IS_SYMBOL_LIBRARY (self)); - - g_hash_table_remove_all (self->categories); - - g_signal_emit (self, - LD_SYMBOL_LIBRARY_GET_CLASS (self)->changed_signal, 0); -} - diff --git a/src/ld-symbol-library.h b/src/ld-symbol-library.h deleted file mode 100644 index 8678201..0000000 --- a/src/ld-symbol-library.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * ld-symbol-library.h - * - * This file is a part of logdiag. - * Copyright Přemysl Janouch 2010. All rights reserved. - * - * See the file LICENSE for licensing information. - * - */ - -#ifndef __LD_SYMBOL_LIBRARY_H__ -#define __LD_SYMBOL_LIBRARY_H__ - -G_BEGIN_DECLS - - -#define LD_TYPE_SYMBOL_LIBRARY (ld_symbol_library_get_type ()) -#define LD_SYMBOL_LIBRARY(obj) (G_TYPE_CHECK_INSTANCE_CAST \ - ((obj), LD_TYPE_SYMBOL_LIBRARY, LdSymbolLibrary)) -#define LD_SYMBOL_LIBRARY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \ - ((klass), LD_TYPE_SYMBOL_LIBRARY, LdSymbolLibraryClass)) -#define LD_IS_SYMBOL_LIBRARY(obj) (G_TYPE_CHECK_INSTANCE_TYPE \ - ((obj), LD_TYPE_SYMBOL_LIBRARY)) -#define LD_IS_SYMBOL_LIBRARY_CLASS(klass) (G_TYPE_CHECK_INSTANCE_TYPE \ - ((klass), LD_TYPE_SYMBOL_LIBRARY)) -#define LD_SYMBOL_LIBRARY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \ - ((obj), LD_SYMBOL_LIBRARY, LdSymbolLibraryClass)) - -typedef struct _LdSymbolLibrary LdSymbolLibrary; -typedef struct _LdSymbolLibraryPrivate LdSymbolLibraryPrivate; -typedef struct _LdSymbolLibraryClass LdSymbolLibraryClass; - - -/** - * LdSymbolLibrary: - * @categories: Lists all the categories (#LdSymbolCategory). - * - * Object structure. - */ -struct _LdSymbolLibrary -{ -/*< private >*/ - GObject parent_instance; - LdSymbolLibraryPrivate *priv; - -/*< public >*/ - GHashTable *categories; -}; - -struct _LdSymbolLibraryClass -{ -/*< private >*/ - GObjectClass parent_class; - - guint changed_signal; -}; - - -GType ld_symbol_library_get_type (void) G_GNUC_CONST; - -LdSymbolLibrary *ld_symbol_library_new (void); -gboolean ld_symbol_library_load (LdSymbolLibrary *self, - const gchar *directory); -void ld_symbol_library_clear (LdSymbolLibrary *self); - - -G_END_DECLS - -#endif /* ! __LD_SYMBOL_LIBRARY_H__ */ - diff --git a/src/ld-symbol.c b/src/ld-symbol.c index deab3f5..4bfe6a2 100644 --- a/src/ld-symbol.c +++ b/src/ld-symbol.c @@ -12,7 +12,7 @@ #include "config.h" -#include "ld-symbol-library.h" +#include "ld-library.h" #include "ld-symbol-category.h" #include "ld-symbol.h" @@ -28,12 +28,12 @@ /* * LdSymbolPrivate: - * @library: The parent LdSymbolLibrary. + * @library: The parent LdLibrary. * The library contains the real function for rendering. */ struct _LdSymbolPrivate { - LdSymbolLibrary *library; + LdLibrary *library; }; G_DEFINE_TYPE (LdSymbol, ld_symbol, G_TYPE_OBJECT); @@ -79,7 +79,7 @@ ld_symbol_finalize (GObject *gobject) * * Load a symbol from a file into the library. */ -LdSymbol *ld_symbol_new (LdSymbolLibrary *library) +LdSymbol *ld_symbol_new (LdLibrary *library) { LdSymbol *symbol; diff --git a/src/ld-symbol.h b/src/ld-symbol.h index 882bde7..f3a2d35 100644 --- a/src/ld-symbol.h +++ b/src/ld-symbol.h @@ -53,7 +53,7 @@ struct _LdSymbolClass GType ld_symbol_get_type (void) G_GNUC_CONST; -LdSymbol *ld_symbol_new (LdSymbolLibrary *library); +LdSymbol *ld_symbol_new (LdLibrary *library); gchar *ld_symbol_build_identifier (LdSymbol *self); void ld_symbol_draw (LdSymbol *self, cairo_t *cr, GHashTable *param); diff --git a/src/ld-window-main.c b/src/ld-window-main.c index 3713cc9..d37488f 100644 --- a/src/ld-window-main.c +++ b/src/ld-window-main.c @@ -15,7 +15,7 @@ #include "ld-window-main.h" #include "ld-document.h" #include "ld-canvas.h" -#include "ld-symbol-library.h" +#include "ld-library.h" #include "ld-symbol-category.h" #include "ld-symbol.h" @@ -41,7 +41,7 @@ struct _LdWindowMainPrivate GtkWidget *menu; GtkWidget *toolbar; - LdSymbolLibrary *library; + LdLibrary *library; LdCanvas *canvas; GtkWidget *statusbar; @@ -215,8 +215,8 @@ ld_window_main_init (LdWindowMain *self) gtk_box_pack_start (GTK_BOX (priv->hbox), priv->toolbar, FALSE, FALSE, 0); /* Symbol library. */ - priv->library = ld_symbol_library_new (); - ld_symbol_library_load (priv->library, PROJECT_SHARE_DIR "library"); + priv->library = ld_library_new (); + ld_library_load (priv->library, PROJECT_SHARE_DIR "library"); load_toolbar (self); -- cgit v1.2.3-70-g09d2