From 49874593371a30a89e2e88f43d3e249a70a07516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 22 May 2018 12:59:28 +0200 Subject: [PATCH] restructured code --- layer-widget/layer-element.c | 2 +- layer-widget/layer-element.h | 18 ++++---- main.c | 77 ++++--------------------------- tree-renderer/lib-cell-renderer.h | 14 ++---- tree-renderer/tree-store.c | 56 ++++++++++++++++++++++ tree-renderer/tree-store.h | 16 +++++++ 6 files changed, 93 insertions(+), 90 deletions(-) create mode 100644 tree-renderer/tree-store.c create mode 100644 tree-renderer/tree-store.h diff --git a/layer-widget/layer-element.c b/layer-widget/layer-element.c index a6ecf69..d6aa310 100644 --- a/layer-widget/layer-element.c +++ b/layer-widget/layer-element.c @@ -62,7 +62,7 @@ static void layer_element_init(LayerElement *self) GtkWidget *layer_element_new(void) { - return GTK_WIDGET(g_object_new(layer_element_get_type(), NULL)); + return GTK_WIDGET(g_object_new(TYPE_LAYER_ELEMENT, NULL)); } const char *layer_element_get_name(LayerElement *elem) diff --git a/layer-widget/layer-element.h b/layer-widget/layer-element.h index 7ab5ca9..de5a37c 100644 --- a/layer-widget/layer-element.h +++ b/layer-widget/layer-element.h @@ -21,11 +21,13 @@ #define __LAYER_ELEMENT_H__ #include -// #include -#define LAYER_ELEMENT(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, layer_element_get_type(), LayerElement) -#define LAYER_ELEMENT_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, layer_element_get_type(), LayerElementClass) -#define IS_LAYER_ELEMENT(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, layer_element_get_type()) +G_BEGIN_DECLS + +/* Creates Class structure etc */ +G_DECLARE_FINAL_TYPE(LayerElement, layer_element, LAYER, ELEMENT, GtkBox) + +#define TYPE_LAYER_ELEMENT (layer_element_get_type()) typedef struct _LayerElementPriv { GtkEntry *name; @@ -42,12 +44,6 @@ typedef struct _LayerElement { LayerElementPriv priv; } LayerElement; -typedef struct _LayerElementClass { - GtkBoxClass parent_class; -} LayerElementClass; - - -GType layer_element_get_type(void); GtkWidget *layer_element_new(void); const char *layer_element_get_name(LayerElement *elem); @@ -59,4 +55,6 @@ gboolean layer_element_get_export(LayerElement *elem); void layer_element_get_color(LayerElement *elem, GdkRGBA *rgba); void layer_element_set_color(LayerElement *elem, GdkRGBA *rgba); +G_END_DECLS + #endif /* __LAYER_ELEMENT_H__ */ diff --git a/main.c b/main.c index 75f6c26..e78e20b 100644 --- a/main.c +++ b/main.c @@ -23,16 +23,7 @@ #include #include "layer-selector.h" #include "tree-renderer/lib-cell-renderer.h" - - -enum cell_store_columns { - LIBRARY, - CELL, - MODDATE, - ACCESSDATE, - STORE_COLUMN_COUNT -}; - +#include "tree-renderer/tree-store.h" struct open_button_data { GtkWindow *main_window; @@ -123,9 +114,9 @@ void on_load_gds(gpointer button, gpointer user) acc_date = generate_string_from_date(&gds_lib->access_time); gtk_tree_store_set (store, &libiter, - LIBRARY, gds_lib, - MODDATE, mod_date->str, - ACCESSDATE, acc_date->str, + CELL_SEL_LIBRARY, gds_lib, + CELL_SEL_MODDATE, mod_date->str, + CELL_SEL_ACCESSDATE, acc_date->str, -1); /* Delete GStrings including string data. */ @@ -142,9 +133,9 @@ void on_load_gds(gpointer button, gpointer user) acc_date = generate_string_from_date(&gds_c->access_time); gtk_tree_store_set (store, &celliter, - CELL, gds_c, - MODDATE, mod_date->str, - ACCESSDATE, acc_date->str, + CELL_SEL_CELL, gds_c, + CELL_SEL_MODDATE, mod_date->str, + CELL_SEL_ACCESSDATE, acc_date->str, -1); /* Delete GStrings including string data. */ @@ -163,63 +154,11 @@ end_destroy: gtk_widget_destroy(open_dialog); } -void on_convert_clicked(gpointer button, gpointer user) +static void on_convert_clicked(gpointer button, gpointer user) { printf("convert\n"); } -static GtkTreeStore * setup_cell_selector(GtkTreeView* view) -{ - GtkTreeStore *cell_store; - - GtkCellRenderer *render_dates; - GtkCellRenderer *render_cell; - GtkCellRenderer *render_lib; - GtkTreeViewColumn *column; - GdkRGBA cell_text_color; - GValue val = G_VALUE_INIT; - - cell_store = gtk_tree_store_new(STORE_COLUMN_COUNT, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING); - gtk_tree_view_set_model(view, GTK_TREE_MODEL(cell_store)); - - render_dates = gtk_cell_renderer_text_new(); - render_cell = lib_cell_renderer_new(); - render_lib = lib_cell_renderer_new(); - - /* Set foreground color for cell column */ - cell_text_color.alpha = 1; - cell_text_color.red = (double)61.0/(double)255.0; - cell_text_color.green = (double)152.0/(double)255.0; - cell_text_color.blue = 0.0; - - g_value_init(&val, G_TYPE_BOOLEAN); - g_value_set_boolean(&val, TRUE); - g_object_set_property(G_OBJECT(render_cell), "foreground-set", &val); - g_value_unset(&val); - - g_value_init(&val, GDK_TYPE_RGBA); - g_value_set_boxed(&val, &cell_text_color); - g_object_set_property(G_OBJECT(render_cell), "foreground-rgba", &val); - g_value_unset(&val); - - - - - column = gtk_tree_view_column_new_with_attributes("Library", render_lib, "gds-lib", LIBRARY, NULL); - gtk_tree_view_append_column(view, column); - - /* Cell color: #3D9801 */ - column = gtk_tree_view_column_new_with_attributes("Cell", render_cell, "gds-cell", CELL, NULL); - gtk_tree_view_append_column(view, column); - - column = gtk_tree_view_column_new_with_attributes("Mod. Date", render_dates, "text", MODDATE, NULL); - gtk_tree_view_append_column(view, column); - - column = gtk_tree_view_column_new_with_attributes("Acc. Date", render_dates, "text", ACCESSDATE, NULL); - gtk_tree_view_append_column(view, column); - - return cell_store; -} int main(int argc, char **argv) { diff --git a/tree-renderer/lib-cell-renderer.h b/tree-renderer/lib-cell-renderer.h index eea28ab..4e0949f 100644 --- a/tree-renderer/lib-cell-renderer.h +++ b/tree-renderer/lib-cell-renderer.h @@ -20,12 +20,11 @@ #ifndef __LIB_CELL_RENDERER_H__ #define __LIB_CELL_RENDERER_H__ - #include -#define LIB_CELL_RENDERER(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, lib_cell_renderer_get_type(), LibCellRenderer) -#define LIB_CELL_RENDERER_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, lib_cell_renderer_get_type(), LibCellRendererClass) -#define IS_LIB_CELL_RENDERER(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, layer_element_get_type()) +G_BEGIN_DECLS + +G_DECLARE_FINAL_TYPE(LibCellRenderer, lib_cell_renderer, LIB_CELL, RENDERER, GtkCellRendererText) #define TYPE_LIB_CELL_RENDERER (lib_cell_renderer_get_type()) typedef struct _LibCellRenderer { @@ -34,14 +33,9 @@ typedef struct _LibCellRenderer { /* Custom Elements */ } LibCellRenderer; -typedef struct _LibCellRendererClass { - GtkCellRendererTextClass parent; -} LibCellRendererClass; - - GType lib_cell_renderer_get_type(void); GtkCellRenderer *lib_cell_renderer_new(void); - +G_END_DECLS #endif /* __LIB_CELL_RENDERER_H__ */ diff --git a/tree-renderer/tree-store.c b/tree-renderer/tree-store.c new file mode 100644 index 0000000..40eeb67 --- /dev/null +++ b/tree-renderer/tree-store.c @@ -0,0 +1,56 @@ +#include "tree-store.h" +#include "lib-cell-renderer.h" +#include "../gds-types.h" + +GtkTreeStore *setup_cell_selector(GtkTreeView* view) +{ + GtkTreeStore *cell_store; + + GtkCellRenderer *render_dates; + GtkCellRenderer *render_cell; + GtkCellRenderer *render_lib; + GtkTreeViewColumn *column; + GdkRGBA cell_text_color; + GValue val = G_VALUE_INIT; + + cell_store = gtk_tree_store_new(CELL_SEL_COLUMN_COUNT, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING); + gtk_tree_view_set_model(view, GTK_TREE_MODEL(cell_store)); + + render_dates = gtk_cell_renderer_text_new(); + render_cell = lib_cell_renderer_new(); + render_lib = lib_cell_renderer_new(); + + /* Set foreground color for cell column */ + cell_text_color.alpha = 1; + cell_text_color.red = (double)61.0/(double)255.0; + cell_text_color.green = (double)152.0/(double)255.0; + cell_text_color.blue = 0.0; + + g_value_init(&val, G_TYPE_BOOLEAN); + g_value_set_boolean(&val, TRUE); + g_object_set_property(G_OBJECT(render_cell), "foreground-set", &val); + g_value_unset(&val); + + g_value_init(&val, GDK_TYPE_RGBA); + g_value_set_boxed(&val, &cell_text_color); + g_object_set_property(G_OBJECT(render_cell), "foreground-rgba", &val); + g_value_unset(&val); + + + + + column = gtk_tree_view_column_new_with_attributes("Library", render_lib, "gds-lib", CELL_SEL_LIBRARY, NULL); + gtk_tree_view_append_column(view, column); + + /* Cell color: #3D9801 */ + column = gtk_tree_view_column_new_with_attributes("Cell", render_cell, "gds-cell", CELL_SEL_CELL, NULL); + gtk_tree_view_append_column(view, column); + + column = gtk_tree_view_column_new_with_attributes("Mod. Date", render_dates, "text", CELL_SEL_MODDATE, NULL); + gtk_tree_view_append_column(view, column); + + column = gtk_tree_view_column_new_with_attributes("Acc. Date", render_dates, "text", CELL_SEL_ACCESSDATE, NULL); + gtk_tree_view_append_column(view, column); + + return cell_store; +} diff --git a/tree-renderer/tree-store.h b/tree-renderer/tree-store.h new file mode 100644 index 0000000..af16a76 --- /dev/null +++ b/tree-renderer/tree-store.h @@ -0,0 +1,16 @@ +#ifndef __TREE_STORE_H__ +#define __TREE_STORE_H__ + +#include + +enum cell_store_columns { + CELL_SEL_LIBRARY = 0, + CELL_SEL_CELL, + CELL_SEL_MODDATE, + CELL_SEL_ACCESSDATE, + CELL_SEL_COLUMN_COUNT +}; + +GtkTreeStore *setup_cell_selector(GtkTreeView* view); + +#endif /* __TREE_STORE_H__ */