diff options
author | Přemysl Janouch <p.janouch@gmail.com> | 2010-09-13 19:24:53 +0200 |
---|---|---|
committer | Přemysl Janouch <p.janouch@gmail.com> | 2010-09-13 19:24:53 +0200 |
commit | b230b69539c1ec84c425da9808dceb5b13a37bb0 (patch) | |
tree | 11e0eb6338f03246ed7fc38d5dad6ccd649f1686 /src | |
download | logdiag-b230b69539c1ec84c425da9808dceb5b13a37bb0.tar.gz logdiag-b230b69539c1ec84c425da9808dceb5b13a37bb0.tar.xz logdiag-b230b69539c1ec84c425da9808dceb5b13a37bb0.zip |
Initial commit
Diffstat (limited to 'src')
-rw-r--r-- | src/canvas.c | 1 | ||||
-rw-r--r-- | src/canvas.h | 0 | ||||
-rw-r--r-- | src/document.c | 0 | ||||
-rw-r--r-- | src/document.h | 0 | ||||
-rw-r--r-- | src/main.c | 40 | ||||
-rw-r--r-- | src/symbol-category.h | 69 | ||||
-rw-r--r-- | src/symbol-library.c | 307 | ||||
-rw-r--r-- | src/symbol-library.h | 69 | ||||
-rw-r--r-- | src/symbol.h | 69 | ||||
-rw-r--r-- | src/window-main.c | 283 | ||||
-rw-r--r-- | src/window-main.h | 60 |
11 files changed, 898 insertions, 0 deletions
diff --git a/src/canvas.c b/src/canvas.c new file mode 100644 index 0000000..7febdb3 --- /dev/null +++ b/src/canvas.c @@ -0,0 +1 @@ +/* http://www.gnomejournal.org/article/34/writing-a-widget-using-cairo-and-gtk28 */ diff --git a/src/canvas.h b/src/canvas.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/canvas.h diff --git a/src/document.c b/src/document.c new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/document.c diff --git a/src/document.h b/src/document.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/document.h diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..ed0dfb7 --- /dev/null +++ b/src/main.c @@ -0,0 +1,40 @@ +/* + * main.c -- logdiag main source file. + * + * This file is a part of logdiag. + * Copyright Přemysl Janouch 2010. All rights reserved. + * + * See the file LICENSE for licensing information. + * + */ + +#include <gtk/gtk.h> +#include <stdlib.h> + +#include "config.h" + +#include "window-main.h" + + +int main (int argc, char *argv[]) +{ + GtkWidget *wnd; + +#ifdef HAVE_GETTEXT + setlocale (LC_ALL, ""); + + bindtextdomain (GETTEXT_DOMAIN, GETTEXT_DIRNAME); + textdomain (GETTEXT_DOMAIN); +#endif + + /* For custom command line arguments, see: + * http://git.gnome.org/browse/glade3/tree/src/main.c + */ + + gtk_init (&argc, &argv); + wnd = logdiag_window_main_new (); + gtk_main (); + + return 0; +} + diff --git a/src/symbol-category.h b/src/symbol-category.h new file mode 100644 index 0000000..bb0a6de --- /dev/null +++ b/src/symbol-category.h @@ -0,0 +1,69 @@ +/* + * symbol-category.h + * + * This file is a part of logdiag. + * Copyright Přemysl Janouch 2010. All rights reserved. + * + * See the file LICENSE for licensing information. + * + */ + +#ifndef __SYMBOL_CATEGORY_H__ +#define __SYMBOL_CATEGORY_H__ + +G_BEGIN_DECLS + + +#define LOGDIAG_TYPE_SYMBOL_CATEGORY (logdiag_symbol_category_get_type ()) +#define LOGDIAG_SYMBOL_CATEGORY(obj) (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), LOGDIAG_TYPE_SYMBOL_CATEGORY, LogdiagSymbolCategory)) +#define LOGDIAG_SYMBOL_CATEGORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \ + ((klass), LOGDIAG_TYPE_SYMBOL_CATEGORY, LogdiagSymbolCategoryClass)) +#define LOGDIAG_IS_SYMBOL_CATEGORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), LOGDIAG_TYPE_SYMBOL_CATEGORY)) +#define LOGDIAG_IS_SYMBOL_CATEGORY_CLASS(klass) (G_TYPE_CHECK_INSTANCE_TYPE \ + ((klass), LOGDIAG_TYPE_SYMBOL_CATEGORY)) +#define LOGDIAG_SYMBOL_CATEGORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), LOGDIAG_SYMBOL_CATEGORY, LogdiagSymbolCategoryClass)) + +typedef struct _LogdiagSymbolCategory LogdiagSymbolCategory; +/*typedef struct _LogdiagSymbolCategoryPrivate LogdiagSymbolCategoryPrivate;*/ +typedef struct _LogdiagSymbolCategoryClass LogdiagSymbolCategoryClass; + + +/** + * LogdiagSymbolCategory: + * @parent: The parent object, may be LogdiagSymbolLibrary + * or another LogdiagSymbolCategory. + * @name: The name of the category. + * @image_path: Path to the image of the category. + * @children: Children of this category. + */ +struct _LogdiagSymbolCategory +{ +/*< private >*/ + GObject parent_instance; + +/*< public >*/ + gpointer parent; + char *name; + char *image_path; + GHashTable *children; +}; + +struct _LogdiagSymbolCategoryClass +{ + GtkObjectClass parent_class; +}; + + +GType logdiag_symbol_category_get_type (void) G_GNUC_CONST; + +LogdiagSymbolCategory * +logdiag_symbol_category_new (LogdiagSymbolLibrary *parent); + + +G_END_DECLS + +#endif /* ! __SYMBOL_CATEGORY_H__ */ + diff --git a/src/symbol-library.c b/src/symbol-library.c new file mode 100644 index 0000000..3f4e078 --- /dev/null +++ b/src/symbol-library.c @@ -0,0 +1,307 @@ +/* + * 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 <gtk/gtk.h> +#include <lua.h> +/* #include <lauxlib.h> */ +#include <stdlib.h> + +#include "config.h" + +#include "symbol-library.h" +#include "symbol-category.h" +#include "symbol.h" + +/* ===== Symbol library ==================================================== */ + +/** + * SECTION:symbol-library + * @short_description: A symbol library. + * @see_also: #LogdiagSymbol, #LogdiagSymbolCategory + * + * #LogdiagSymbolLibrary is used for loading symbols from their files. + */ + +/* + * LogdiagSymbolLibraryPrivate: + * @lua_state: Lua state. + */ +struct _LogdiagSymbolLibraryPrivate +{ + lua_State *lua_state; +}; + +G_DEFINE_TYPE (LogdiagSymbolLibrary, logdiag_symbol_library, G_TYPE_OBJECT); + +static void +logdiag_symbol_library_finalize (GObject *gobject); + + +static void +logdiag_symbol_library_class_init (LogdiagSymbolLibraryClass *klass) +{ + GObjectClass *object_class; + + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = logdiag_symbol_library_finalize; + +/** + * LogdiagSymbolLibrary::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 (LogdiagSymbolLibraryPrivate)); +} + +static void +logdiag_symbol_library_init (LogdiagSymbolLibrary *self) +{ + self->priv = G_TYPE_INSTANCE_GET_PRIVATE + (self, LOGDIAG_TYPE_SYMBOL_LIBRARY, LogdiagSymbolLibraryPrivate); + + /* 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); +} + +static void +logdiag_symbol_library_finalize (GObject *gobject) +{ + LogdiagSymbolLibrary *self; + + self = LOGDIAG_SYMBOL_LIBRARY (gobject); + + g_hash_table_destroy (self->categories); + + /* Chain up to the parent class. */ + G_OBJECT_CLASS (logdiag_symbol_library_parent_class)->finalize (gobject); +} + +/** + * logdiag_symbol_library_new: + * + * Create an instance. + */ +LogdiagSymbolLibrary * +logdiag_symbol_library_new (void) +{ + return g_object_new (LOGDIAG_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. + */ +LogdiagSymbolCategory * +load_category (LogdiagSymbolLibrary *self, const char *path, const char *name) +{ + LogdiagSymbolCategory *cat; + gchar *icon_file; + + g_return_val_if_fail (LOGDIAG_IS_SYMBOL_LIBRARY (self), NULL); + g_return_val_if_fail (path != NULL, NULL); + g_return_val_if_fail (name != NULL, 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 = logdiag_symbol_category_new (self); + cat->name = g_strdup (name); + cat->image_path = icon_file; + return cat; +} + +/** + * logdiag_symbol_library_load: + * @self: A symbol library object. + * @directory: A directory to be loaded. + * + * Load the contents of a directory into the library. + */ +gboolean +logdiag_symbol_library_load (LogdiagSymbolLibrary *self, const char *path) +{ + GDir *dir; + const gchar *item; + + g_return_val_if_fail (LOGDIAG_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))) + { + LogdiagSymbolCategory *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); + } + g_dir_close (dir); + return TRUE; +} + +/** + * logdiag_symbol_library_clear: + * + * Clears all the contents. + */ +void +logdiag_symbol_library_clear (LogdiagSymbolLibrary *self) +{ + g_return_if_fail (LOGDIAG_IS_SYMBOL_LIBRARY (self)); + + g_hash_table_remove_all (self->categories); + return; +} + + +/* ===== Symbol category =================================================== */ + +/** + * SECTION:symbol-category + * @short_description: A category of symbols. + * @see_also: #LogdiagSymbol, #LogdiagSymbolLibrary + * + * #LogdiagSymbolCategory represents a category of #LogdiagSymbol objects. + */ + +G_DEFINE_TYPE (LogdiagSymbolCategory, logdiag_symbol_category, G_TYPE_OBJECT); + +static void +logdiag_symbol_category_finalize (GObject *gobject); + + +static void +logdiag_symbol_category_class_init (LogdiagSymbolCategoryClass *klass) +{ + GObjectClass *object_class; + + object_class = G_OBJECT_CLASS (klass); + object_class->finalize = logdiag_symbol_category_finalize; +} + +static void +logdiag_symbol_category_init (LogdiagSymbolCategory *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); +} + +static void +logdiag_symbol_category_finalize (GObject *gobject) +{ + LogdiagSymbolCategory *self; + + self = LOGDIAG_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); + + /* Chain up to the parent class. */ + G_OBJECT_CLASS (logdiag_symbol_category_parent_class)->finalize (gobject); +} + +/** + * logdiag_symbol_category_new: + * + * Create an instance. + */ +LogdiagSymbolCategory * +logdiag_symbol_category_new (LogdiagSymbolLibrary *parent) +{ + LogdiagSymbolCategory *cat; + + cat = g_object_new (LOGDIAG_TYPE_SYMBOL_CATEGORY, NULL); + + cat->parent = parent; + g_object_ref (parent); + + return cat; +} + + +/* ===== Symbol ============================================================ */ + +/** + * SECTION:symbol + * @short_description: A symbol. + * @see_also: #LogdiagDocument, #LogdiagCanvas + * + * #LogdiagSymbol represents a symbol in the #LogdiagDocument that is in turn + * drawn onto the #LogdiagCanvas. + */ + +/* + * LogdiagSymbolPrivate: + * @parent_library: The parent LogdiagSymbolLibrary. + * The library contains the real function for rendering. + */ +struct _LogdiagSymbolPrivate +{ + LogdiagSymbolLibrary *parent_library; +}; + +/** + * logdiag_symbol_build_identifier: + * + * Build an identifier for the symbol. + * The identifier is in the format "Category/Category/Symbol". + */ +char * +logdiag_symbol_build_identifier (LogdiagSymbol *self) +{ + return NULL; +} + +/** + * logdiag_symbol_draw: + * + * Draw the symbol onto a Cairo surface. + */ +void +logdiag_symbol_draw (LogdiagSymbol *self, cairo_t *surface, + GHashTable *param, gint x, gint y, gdouble zoom) +{ + return; +} diff --git a/src/symbol-library.h b/src/symbol-library.h new file mode 100644 index 0000000..5091453 --- /dev/null +++ b/src/symbol-library.h @@ -0,0 +1,69 @@ +/* + * 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 __SYMBOL_LIBRARY_H__ +#define __SYMBOL_LIBRARY_H__ + +G_BEGIN_DECLS + + +#define LOGDIAG_TYPE_SYMBOL_LIBRARY (logdiag_symbol_library_get_type ()) +#define LOGDIAG_SYMBOL_LIBRARY(obj) (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), LOGDIAG_TYPE_SYMBOL_LIBRARY, LogdiagSymbolLibrary)) +#define LOGDIAG_SYMBOL_LIBRARY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \ + ((klass), LOGDIAG_TYPE_SYMBOL_LIBRARY, LogdiagSymbolLibraryClass)) +#define LOGDIAG_IS_SYMBOL_LIBRARY(obj) (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), LOGDIAG_TYPE_SYMBOL_LIBRARY)) +#define LOGDIAG_IS_SYMBOL_LIBRARY_CLASS(klass) (G_TYPE_CHECK_INSTANCE_TYPE \ + ((klass), LOGDIAG_TYPE_SYMBOL_LIBRARY)) +#define LOGDIAG_SYMBOL_LIBRARY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), LOGDIAG_SYMBOL_LIBRARY, LogdiagSymbolLibraryClass)) + +typedef struct _LogdiagSymbolLibrary LogdiagSymbolLibrary; +typedef struct _LogdiagSymbolLibraryPrivate LogdiagSymbolLibraryPrivate; +typedef struct _LogdiagSymbolLibraryClass LogdiagSymbolLibraryClass; + + +/** + * LogdiagSymbolLibrary: + * @categories: Lists all the categories (#LogdiagSymbolCategory). + * + * Object structure. + */ +struct _LogdiagSymbolLibrary +{ +/*< private >*/ + GObject parent_instance; + LogdiagSymbolLibraryPrivate *priv; + +/*< public >*/ + GHashTable *categories; +}; + +struct _LogdiagSymbolLibraryClass +{ +/*< private >*/ + GObjectClass parent_class; + guint changed_signal; +}; + + +GType logdiag_symbol_library_get_type (void) G_GNUC_CONST; + +LogdiagSymbolLibrary *logdiag_symbol_library_new (void); +gboolean logdiag_symbol_library_load (LogdiagSymbolLibrary *self, + const char *directory); +void logdiag_symbol_library_clear (LogdiagSymbolLibrary *self); + + +G_END_DECLS + +#endif /* ! __SYMBOL_LIBRARY_H__ */ + diff --git a/src/symbol.h b/src/symbol.h new file mode 100644 index 0000000..c8f851f --- /dev/null +++ b/src/symbol.h @@ -0,0 +1,69 @@ +/* + * symbol.h + * + * This file is a part of logdiag. + * Copyright Přemysl Janouch 2010. All rights reserved. + * + * See the file LICENSE for licensing information. + * + */ + +#ifndef __SYMBOL_H__ +#define __SYMBOL_H__ + +G_BEGIN_DECLS + + +#define LOGDIAG_TYPE_SYMBOL (logdiag_symbol_get_type ()) +#define LOGDIAG_SYMBOL(obj) (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), LOGDIAG_TYPE_SYMBOL, LogdiagSymbol)) +#define LOGDIAG_SYMBOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \ + ((klass), LOGDIAG_TYPE_SYMBOL, LogdiagSymbolClass)) +#define LOGDIAG_IS_SYMBOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), LOGDIAG_TYPE_SYMBOL)) +#define LOGDIAG_IS_SYMBOL_CLASS(klass) (G_TYPE_CHECK_INSTANCE_TYPE \ + ((klass), LOGDIAG_TYPE_SYMBOL)) +#define LOGDIAG_SYMBOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), LOGDIAG_SYMBOL, LogdiagSymbolClass)) + +typedef struct _LogdiagSymbol LogdiagSymbol; +/*typedef struct _LogdiagSymbolPrivate LogdiagSymbolPrivate;*/ +typedef struct _LogdiagSymbolClass LogdiagSymbolClass; + + +/** + * LogdiagSymbol: + * @parent: The parent category. + * @name: The name of this symbol. + */ +struct _LogdiagSymbol +{ +/*< private >*/ + GObject parent_instance; +/* LogdiagSymbolPrivate *priv;*/ + +/*< public >*/ + LogdiagSymbolCategory *parent; + char *name; +}; + +struct _LogdiagSymbolClass +{ + GtkObjectClass parent_class; +}; + + +GType logdiag_symbol_get_type (void) G_GNUC_CONST; + +char *logdiag_symbol_build_identifier (LogdiagSymbol *self); +void logdiag_symbol_draw (LogdiagSymbol *self, cairo_t *surface, + GHashTable *param, gint x, gint y, gdouble zoom); + +/* TODO: Funkce pro získání terminálů. */ + + + +G_END_DECLS + +#endif /* ! __SYMBOL_H__ */ + diff --git a/src/window-main.c b/src/window-main.c new file mode 100644 index 0000000..a34d5ed --- /dev/null +++ b/src/window-main.c @@ -0,0 +1,283 @@ +/* + * window-main.c + * + * This file is a part of logdiag. + * Copyright Přemysl Janouch 2010. All rights reserved. + * + * See the file LICENSE for licensing information. + * + */ + +#include <gtk/gtk.h> +#include <stdlib.h> +#include <string.h> + +#include "config.h" + +#include "window-main.h" +#include "symbol-library.h" + + +/** + * SECTION:window-main + * @short_description: The main application window. + * + * #LogdiagWindowMain is the main window of the application. + */ +/* NOTE: The main window should not maybe be included in either + * the documentation or the static library. + */ + + +/* Private members of the window. */ +struct _LogdiagWindowMainPrivate +{ + GtkWidget *vbox; + GtkWidget *hbox; + GtkWidget *menu; + GtkWidget *toolbar; + + LogdiagSymbolLibrary *library; + + GtkWidget *statusbar; + guint statusbar_menu_context_id; +}; + +/* Define the type. */ +G_DEFINE_TYPE (LogdiagWindowMain, logdiag_window_main, GTK_TYPE_WINDOW); + + +/* + * cb_ui_proxy_connected: + * + * An item was connected to the manager. + */ +static void +cb_ui_proxy_connected (GtkUIManager *ui, GtkAction *action, + GtkWidget *proxy, LogdiagWindowMain *window); + +/* + * cb_ui_proxy_disconnected: + * + * An item was disconnected from the manager. + */ +static void +cb_ui_proxy_disconnected (GtkUIManager *ui, GtkAction *action, + GtkWidget *proxy, LogdiagWindowMain *window); + +/* A menu item was selected. */ +static void +cb_menu_item_selected (GtkWidget *item, LogdiagWindowMain *window); + +/* A menu item was deselected. */ +static void +cb_menu_item_deselected (GtkItem *item, LogdiagWindowMain *window); + +/* Show the about dialog. */ +static void +cb_show_about_dialog (GtkAction *action, LogdiagWindowMain *window); + + +/* Actions for menus, toolbars, accelerators. */ +static GtkActionEntry mw_actionEntries[] = +{ + {"FileMenu", NULL, Q_("_File")}, + {"New", GTK_STOCK_NEW, NULL, NULL, + Q_("Create a new document"), NULL}, + {"Open", GTK_STOCK_OPEN, NULL, NULL, + Q_("Open a document"), NULL}, + {"Save", GTK_STOCK_SAVE, NULL, NULL, + Q_("Save the current document"), NULL}, + {"SaveAs", GTK_STOCK_SAVE_AS, NULL, NULL, + Q_("Save the current document with another name"), NULL}, + {"Export", NULL, Q_("_Export"), NULL, + Q_("Export the document"), NULL}, + {"Quit", GTK_STOCK_QUIT, NULL, NULL, + Q_("Quit the program"), NULL}, + + {"EditMenu", NULL, Q_("_Edit")}, + {"Cut", GTK_STOCK_CUT, NULL, NULL, NULL, NULL}, + {"Copy", GTK_STOCK_COPY, NULL, NULL, NULL, NULL}, + {"Paste", GTK_STOCK_PASTE, NULL, NULL, NULL, NULL}, + {"Delete", GTK_STOCK_DELETE, NULL, NULL, NULL, NULL}, + {"SelectAll", GTK_STOCK_SELECT_ALL, NULL, NULL, NULL, NULL}, + + {"HelpMenu", NULL, Q_("_Help")}, + {"About", GTK_STOCK_ABOUT, NULL, NULL, NULL, + G_CALLBACK(cb_show_about_dialog)} +}; + + + +/** + * logdiag_window_main_new: + * + * Create an instance. + */ +GtkWidget * +logdiag_window_main_new (void) +{ + return g_object_new (LOGDIAG_TYPE_WINDOW_MAIN, NULL); +} + +static void +logdiag_window_main_class_init (LogdiagWindowMainClass *klass) +{ + GObjectClass *object_class; + GtkWidgetClass *widget_class; + + object_class = G_OBJECT_CLASS (klass); + widget_class = GTK_WIDGET_CLASS (klass); + + g_type_class_add_private (klass, sizeof (LogdiagWindowMainPrivate)); +} + +static void +logdiag_window_main_init (LogdiagWindowMain *self) +{ + LogdiagWindowMainPrivate *priv; + GtkActionGroup *action_group; + GtkUIManager *ui_manager; + GError *error; + + self->priv = priv = G_TYPE_INSTANCE_GET_PRIVATE + (self, LOGDIAG_TYPE_WINDOW_MAIN, LogdiagWindowMainPrivate); + + priv->vbox = gtk_vbox_new (FALSE, 0); + gtk_container_add (GTK_CONTAINER (self), priv->vbox); + + + ui_manager = gtk_ui_manager_new (); + + /* TODO: Show tooltips in the statusbar: + * http://git.gnome.org/browse/glade3/tree/src/glade-window.c : 2165 + */ + g_signal_connect (ui_manager, "connect-proxy", + G_CALLBACK (cb_ui_proxy_connected), self); + g_signal_connect (ui_manager, "disconnect-proxy", + G_CALLBACK (cb_ui_proxy_disconnected), self); + + /* Prepare our actions. */ + action_group = gtk_action_group_new ("MainActions"); + gtk_action_group_add_actions (action_group, + mw_actionEntries, G_N_ELEMENTS (mw_actionEntries), self); + gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); + + error = NULL; + gtk_ui_manager_add_ui_from_file + (ui_manager, PROJECT_SHARE_DIR "gui/window-main.ui", &error); + if (error) + { + g_message (_("Building UI failed: %s"), error->message); + g_error_free (error); + } + + /* Load keyboard accelerators into the window. */ + gtk_window_add_accel_group + (GTK_WINDOW (self), gtk_ui_manager_get_accel_group (ui_manager)); + + 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); + + priv->toolbar = gtk_toolbar_new (); + /* NOTE: For GTK 2.16+, s/toolbar/orientable/ */ + gtk_toolbar_set_orientation + (GTK_TOOLBAR (priv->toolbar), GTK_ORIENTATION_VERTICAL); + gtk_toolbar_set_icon_size + (GTK_TOOLBAR (priv->toolbar), GTK_ICON_SIZE_LARGE_TOOLBAR); + gtk_toolbar_set_style + (GTK_TOOLBAR (priv->toolbar), GTK_TOOLBAR_ICONS); + + /* 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/ */ + + gtk_box_pack_start (GTK_BOX (priv->hbox), priv->toolbar, FALSE, FALSE, 0); + + /* TODO: GtkHPaned */ + + priv->statusbar = gtk_statusbar_new (); + priv->statusbar_menu_context_id = gtk_statusbar_get_context_id + (GTK_STATUSBAR (priv->statusbar), "menu"); + gtk_box_pack_end (GTK_BOX (priv->vbox), priv->statusbar, FALSE, FALSE, 0); + + + /* Do this on disposal. */ + /* g_object_unref(ui_manager); */ + + /* Proceed to showing the window. */ + g_signal_connect (self, "destroy", G_CALLBACK (gtk_main_quit), NULL); + gtk_window_set_default_size (GTK_WINDOW (self), 500, 400); + gtk_widget_show_all (GTK_WIDGET (self)); +} + +static void +cb_ui_proxy_connected (GtkUIManager *ui, GtkAction *action, + GtkWidget *proxy, LogdiagWindowMain *window) +{ + if (GTK_IS_MENU_ITEM (proxy)) + { + g_signal_connect (proxy, "select", + G_CALLBACK (cb_menu_item_selected), window); + g_signal_connect (proxy, "deselect", + G_CALLBACK (cb_menu_item_deselected), window); + } +} + +static void +cb_ui_proxy_disconnected (GtkUIManager *ui, GtkAction *action, + GtkWidget *proxy, LogdiagWindowMain *window) +{ + if (GTK_IS_MENU_ITEM (proxy)) + { + g_signal_handlers_disconnect_by_func + (proxy, G_CALLBACK (cb_menu_item_selected), window); + g_signal_handlers_disconnect_by_func + (proxy, G_CALLBACK (cb_menu_item_deselected), window); + } +} + +static void +cb_menu_item_selected (GtkWidget *item, LogdiagWindowMain *window) +{ + GtkAction *action; + gchar *tooltip; + + action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (item)); + g_object_get (G_OBJECT (action), "tooltip", &tooltip, NULL); + + if (tooltip != NULL) + gtk_statusbar_push (GTK_STATUSBAR (window->priv->statusbar), + window->priv->statusbar_menu_context_id, tooltip); + + g_free (tooltip); +} + +static void +cb_menu_item_deselected (GtkItem *item, LogdiagWindowMain *window) +{ + gtk_statusbar_pop (GTK_STATUSBAR (window->priv->statusbar), + window->priv->statusbar_menu_context_id); +} + +static void +cb_show_about_dialog (GtkAction *action, LogdiagWindowMain *window) +{ + gtk_show_about_dialog (GTK_WINDOW (window), + "program-name", PROJECT_NAME, + "version", PROJECT_VERSION, + "copyright", "Copyright Přemysl Janouch 2010", + NULL); +} + diff --git a/src/window-main.h b/src/window-main.h new file mode 100644 index 0000000..28b3024 --- /dev/null +++ b/src/window-main.h @@ -0,0 +1,60 @@ +/* + * window-main.h + * + * This file is a part of logdiag. + * Copyright Přemysl Janouch 2010. All rights reserved. + * + * See the file LICENSE for licensing information. + * + */ + +#ifndef __WINDOW_MAIN_H__ +#define __WINDOW_MAIN_H__ + +G_BEGIN_DECLS + + +#define LOGDIAG_TYPE_WINDOW_MAIN (logdiag_window_main_get_type ()) +#define LOGDIAG_WINDOW_MAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), LOGDIAG_TYPE_WINDOW_MAIN, LogdiagWindowMain)) +#define LOGDIAG_WINDOW_MAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST \ + ((klass), LOGDIAG_TYPE_WINDOW_MAIN, LogdiagWindowMainClass)) +#define LOGDIAG_IS_WINDOW_MAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), LOGDIAG_TYPE_WINDOW_MAIN)) +#define LOGDIAG_IS_WINDOW_MAIN_CLASS(klass) (G_TYPE_CHECK_INSTANCE_TYPE \ + ((klass), LOGDIAG_TYPE_WINDOW_MAIN)) +#define LOGDIAG_WINDOW_MAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), LOGDIAG_WINDOW_MAIN, LogdiagWindowMainClass)) + +typedef struct _LogdiagWindowMain LogdiagWindowMain; +typedef struct _LogdiagWindowMainPrivate LogdiagWindowMainPrivate; +typedef struct _LogdiagWindowMainClass LogdiagWindowMainClass; + + +/** + * LogdiagWindowMain: + * + * Object structure. + */ +struct _LogdiagWindowMain +{ +/*< private >*/ + GtkWindow parent_instance; + LogdiagWindowMainPrivate *priv; +}; + +struct _LogdiagWindowMainClass +{ + GtkWindowClass parent_class; +}; + + +GType logdiag_window_main_get_type (void) G_GNUC_CONST; + +GtkWidget *logdiag_window_main_new (void); + + +G_END_DECLS + +#endif /* ! __WINDOW_MAIN_H__ */ + |