restructured code

This commit is contained in:
Mario Hüttel 2018-05-22 12:59:28 +02:00
parent 1db0ac1d17
commit 4987459337
6 changed files with 93 additions and 90 deletions

View File

@ -62,7 +62,7 @@ static void layer_element_init(LayerElement *self)
GtkWidget *layer_element_new(void) 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) const char *layer_element_get_name(LayerElement *elem)

View File

@ -21,11 +21,13 @@
#define __LAYER_ELEMENT_H__ #define __LAYER_ELEMENT_H__
#include <gtk/gtk.h> #include <gtk/gtk.h>
// #include <gdk/gdk.h>
#define LAYER_ELEMENT(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, layer_element_get_type(), LayerElement) G_BEGIN_DECLS
#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()) /* 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 { typedef struct _LayerElementPriv {
GtkEntry *name; GtkEntry *name;
@ -42,12 +44,6 @@ typedef struct _LayerElement {
LayerElementPriv priv; LayerElementPriv priv;
} LayerElement; } LayerElement;
typedef struct _LayerElementClass {
GtkBoxClass parent_class;
} LayerElementClass;
GType layer_element_get_type(void);
GtkWidget *layer_element_new(void); GtkWidget *layer_element_new(void);
const char *layer_element_get_name(LayerElement *elem); 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_get_color(LayerElement *elem, GdkRGBA *rgba);
void layer_element_set_color(LayerElement *elem, GdkRGBA *rgba); void layer_element_set_color(LayerElement *elem, GdkRGBA *rgba);
G_END_DECLS
#endif /* __LAYER_ELEMENT_H__ */ #endif /* __LAYER_ELEMENT_H__ */

77
main.c
View File

@ -23,16 +23,7 @@
#include <layer-element.h> #include <layer-element.h>
#include "layer-selector.h" #include "layer-selector.h"
#include "tree-renderer/lib-cell-renderer.h" #include "tree-renderer/lib-cell-renderer.h"
#include "tree-renderer/tree-store.h"
enum cell_store_columns {
LIBRARY,
CELL,
MODDATE,
ACCESSDATE,
STORE_COLUMN_COUNT
};
struct open_button_data { struct open_button_data {
GtkWindow *main_window; 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); acc_date = generate_string_from_date(&gds_lib->access_time);
gtk_tree_store_set (store, &libiter, gtk_tree_store_set (store, &libiter,
LIBRARY, gds_lib, CELL_SEL_LIBRARY, gds_lib,
MODDATE, mod_date->str, CELL_SEL_MODDATE, mod_date->str,
ACCESSDATE, acc_date->str, CELL_SEL_ACCESSDATE, acc_date->str,
-1); -1);
/* Delete GStrings including string data. */ /* 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); acc_date = generate_string_from_date(&gds_c->access_time);
gtk_tree_store_set (store, &celliter, gtk_tree_store_set (store, &celliter,
CELL, gds_c, CELL_SEL_CELL, gds_c,
MODDATE, mod_date->str, CELL_SEL_MODDATE, mod_date->str,
ACCESSDATE, acc_date->str, CELL_SEL_ACCESSDATE, acc_date->str,
-1); -1);
/* Delete GStrings including string data. */ /* Delete GStrings including string data. */
@ -163,63 +154,11 @@ end_destroy:
gtk_widget_destroy(open_dialog); 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"); 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) int main(int argc, char **argv)
{ {

View File

@ -20,12 +20,11 @@
#ifndef __LIB_CELL_RENDERER_H__ #ifndef __LIB_CELL_RENDERER_H__
#define __LIB_CELL_RENDERER_H__ #define __LIB_CELL_RENDERER_H__
#include <gtk/gtk.h> #include <gtk/gtk.h>
#define LIB_CELL_RENDERER(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, lib_cell_renderer_get_type(), LibCellRenderer) G_BEGIN_DECLS
#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_DECLARE_FINAL_TYPE(LibCellRenderer, lib_cell_renderer, LIB_CELL, RENDERER, GtkCellRendererText)
#define TYPE_LIB_CELL_RENDERER (lib_cell_renderer_get_type()) #define TYPE_LIB_CELL_RENDERER (lib_cell_renderer_get_type())
typedef struct _LibCellRenderer { typedef struct _LibCellRenderer {
@ -34,14 +33,9 @@ typedef struct _LibCellRenderer {
/* Custom Elements */ /* Custom Elements */
} LibCellRenderer; } LibCellRenderer;
typedef struct _LibCellRendererClass {
GtkCellRendererTextClass parent;
} LibCellRendererClass;
GType lib_cell_renderer_get_type(void); GType lib_cell_renderer_get_type(void);
GtkCellRenderer *lib_cell_renderer_new(void); GtkCellRenderer *lib_cell_renderer_new(void);
G_END_DECLS
#endif /* __LIB_CELL_RENDERER_H__ */ #endif /* __LIB_CELL_RENDERER_H__ */

View File

@ -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;
}

View File

@ -0,0 +1,16 @@
#ifndef __TREE_STORE_H__
#define __TREE_STORE_H__
#include <gtk/gtk.h>
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__ */