Edit screen
This commit is contained in:
parent
10901f7dcb
commit
dcf562d835
5 changed files with 226 additions and 56 deletions
|
@ -1,30 +1,90 @@
|
||||||
#include "c-edit-window.h"
|
#include "c-edit-window.h"
|
||||||
#include <hildon/hildon.h>
|
#include <hildon/hildon.h>
|
||||||
|
#include <limits.h>
|
||||||
#include "data.h"
|
#include "data.h"
|
||||||
|
|
||||||
|
enum {
|
||||||
|
C_EDIT_PROP_0,
|
||||||
|
C_EDIT_PROP_CID
|
||||||
|
};
|
||||||
|
|
||||||
|
static void c_edit_window_set_collection_id(CEditWindow *self,
|
||||||
|
gint collection_id);
|
||||||
|
|
||||||
G_DEFINE_TYPE(CEditWindow, c_edit_window, HILDON_TYPE_STACKABLE_WINDOW)
|
G_DEFINE_TYPE(CEditWindow, c_edit_window, HILDON_TYPE_STACKABLE_WINDOW)
|
||||||
|
|
||||||
GtkWidget *c_edit_window_new(void)
|
GtkWidget *c_edit_window_new(gint collection_id)
|
||||||
{
|
{
|
||||||
return g_object_new(C_TYPE_EDIT_WINDOW, NULL);
|
g_print("1: %d\n", collection_id);
|
||||||
|
return g_object_new(C_TYPE_EDIT_WINDOW, "collection-id", collection_id, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void c_edit_window_class_init(CEditWindowClass *class)
|
static void c_edit_window_set_property(GObject *object,
|
||||||
{}
|
guint property_id,
|
||||||
|
const GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
CEditWindow *self = C_EDIT_WINDOW(object);
|
||||||
|
|
||||||
|
switch (property_id) {
|
||||||
|
case C_EDIT_PROP_CID:
|
||||||
|
g_print("2: %d\n", g_value_get_int(value));
|
||||||
|
self->collection_id = g_value_get_int(value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
/* We don't have any other properties */
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void c_edit_window_get_property(GObject *object,
|
||||||
|
guint property_id,
|
||||||
|
GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
CEditWindow *self = C_EDIT_WINDOW(object);
|
||||||
|
|
||||||
|
switch (property_id) {
|
||||||
|
case C_EDIT_PROP_CID:
|
||||||
|
g_value_set_int(value, self->collection_id);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void c_edit_window_class_init(CEditWindowClass *klass)
|
||||||
|
{
|
||||||
|
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
||||||
|
GParamSpec *pspec;
|
||||||
|
|
||||||
|
gobject_class->set_property = c_edit_window_set_property;
|
||||||
|
gobject_class->get_property = c_edit_window_get_property;
|
||||||
|
|
||||||
|
pspec = g_param_spec_int("collection-id",
|
||||||
|
"ID for the collection",
|
||||||
|
"Set the collection-id",
|
||||||
|
0,
|
||||||
|
INT_MAX,
|
||||||
|
0,
|
||||||
|
G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE);
|
||||||
|
g_object_class_install_property(gobject_class,
|
||||||
|
C_EDIT_PROP_CID,
|
||||||
|
pspec);
|
||||||
|
}
|
||||||
|
|
||||||
static void c_edit_window_init(CEditWindow *self)
|
static void c_edit_window_init(CEditWindow *self)
|
||||||
{
|
{
|
||||||
GtkWidget *pannablearea;
|
GtkWidget *pannablearea;
|
||||||
GtkWidget *table;
|
GtkWidget *table;
|
||||||
GtkWidget *nameclabel;
|
GtkWidget *nameclabel;
|
||||||
GtkWidget *namelabel;
|
|
||||||
GtkWidget *haveclabel;
|
GtkWidget *haveclabel;
|
||||||
GtkWidget *havelabel;
|
|
||||||
GtkWidget *totalclabel;
|
GtkWidget *totalclabel;
|
||||||
GtkWidget *totallabel;
|
GtkWidget *vbox;
|
||||||
GtkWidget *layout;
|
|
||||||
int i;
|
g_print("3: %d\n", self->collection_id);
|
||||||
struct collection test = { 0, 3, 10, "Biomega" };
|
|
||||||
|
|
||||||
pannablearea = hildon_pannable_area_new();
|
pannablearea = hildon_pannable_area_new();
|
||||||
g_object_set(G_OBJECT(pannablearea),
|
g_object_set(G_OBJECT(pannablearea),
|
||||||
|
@ -41,9 +101,9 @@ static void c_edit_window_init(CEditWindow *self)
|
||||||
gtk_table_attach(GTK_TABLE(table), nameclabel, 0, 1, 0, 1,
|
gtk_table_attach(GTK_TABLE(table), nameclabel, 0, 1, 0, 1,
|
||||||
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
|
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
|
||||||
|
|
||||||
namelabel = gtk_label_new(test.name);
|
self->name_label = gtk_label_new("");
|
||||||
gtk_misc_set_alignment(GTK_MISC(namelabel), 1.0, 0.5);
|
gtk_misc_set_alignment(GTK_MISC(self->name_label), 1.0, 0.5);
|
||||||
gtk_table_attach(GTK_TABLE(table), namelabel, 1, 2, 0, 1,
|
gtk_table_attach(GTK_TABLE(table), self->name_label, 1, 2, 0, 1,
|
||||||
GTK_EXPAND | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
|
GTK_EXPAND | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
|
||||||
|
|
||||||
haveclabel = gtk_label_new("You have:");
|
haveclabel = gtk_label_new("You have:");
|
||||||
|
@ -51,9 +111,9 @@ static void c_edit_window_init(CEditWindow *self)
|
||||||
gtk_table_attach(GTK_TABLE(table), haveclabel, 0, 1, 1, 2,
|
gtk_table_attach(GTK_TABLE(table), haveclabel, 0, 1, 1, 2,
|
||||||
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
|
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
|
||||||
|
|
||||||
havelabel = gtk_label_new(g_strdup_printf("%d", test.current_qty));
|
self->have_label = gtk_label_new("");
|
||||||
gtk_misc_set_alignment(GTK_MISC(havelabel), 1.0, 0.5);
|
gtk_misc_set_alignment(GTK_MISC(self->have_label), 1.0, 0.5);
|
||||||
gtk_table_attach(GTK_TABLE(table), havelabel, 1, 2, 1, 2,
|
gtk_table_attach(GTK_TABLE(table), self->have_label, 1, 2, 1, 2,
|
||||||
GTK_EXPAND | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
|
GTK_EXPAND | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
|
||||||
|
|
||||||
totalclabel = gtk_label_new("There are:");
|
totalclabel = gtk_label_new("There are:");
|
||||||
|
@ -61,23 +121,30 @@ static void c_edit_window_init(CEditWindow *self)
|
||||||
gtk_table_attach(GTK_TABLE(table), totalclabel, 0, 1, 2, 3,
|
gtk_table_attach(GTK_TABLE(table), totalclabel, 0, 1, 2, 3,
|
||||||
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
|
GTK_SHRINK | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
|
||||||
|
|
||||||
totallabel = gtk_label_new((test.total_qty == 0)
|
self->total_label = gtk_label_new("");
|
||||||
? "?"
|
gtk_misc_set_alignment(GTK_MISC(self->total_label), 1.0, 0.5);
|
||||||
: g_strdup_printf("%d", test.total_qty));
|
gtk_table_attach(GTK_TABLE(table), self->total_label, 1, 2, 2, 3,
|
||||||
gtk_misc_set_alignment(GTK_MISC(totallabel), 1.0, 0.5);
|
|
||||||
gtk_table_attach(GTK_TABLE(table), totallabel, 1, 2, 2, 3,
|
|
||||||
GTK_EXPAND | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
|
GTK_EXPAND | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
|
||||||
|
|
||||||
/*layout = gtk_layout_new(NULL, NULL);
|
vbox = gtk_vbox_new(TRUE, 0);
|
||||||
gtk_table_attach(GTK_TABLE(table), layout, 0, 2, 3, 4,
|
gtk_table_attach(GTK_TABLE(table), vbox, 0, 2, 3, 4,
|
||||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||||
|
}
|
||||||
for (i = 0; i < test.total_qty; i++) {
|
|
||||||
GtkWidget *button;
|
static void c_edit_window_set_collection_id(CEditWindow *self,
|
||||||
|
gint collection_id)
|
||||||
button = hildon_check_button_new(HILDON_SIZE_FINGER_HEIGHT |
|
{
|
||||||
HILDON_SIZE_AUTO_WIDTH);
|
struct collection *col;
|
||||||
gtk_button_set_label(GTK_BUTTON(button), g_strdup_printf("%d", i));
|
gint *items;
|
||||||
|
|
||||||
}*/
|
col = data_get_collection_by_id(collection_id);
|
||||||
|
items = data_get_items_by_collection_id(collection_id);
|
||||||
|
|
||||||
|
gtk_label_set_text(GTK_LABEL(self->name_label), col->name);
|
||||||
|
gtk_label_set_text(GTK_LABEL(self->have_label),
|
||||||
|
g_strdup_printf("%d", col->current_qty));
|
||||||
|
gtk_label_set_text(GTK_LABEL(self->total_label),
|
||||||
|
g_strdup_printf("%d", col->total_qty));
|
||||||
|
|
||||||
|
g_free(col);
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,11 +42,17 @@ struct _CEditWindowClass
|
||||||
struct _CEditWindow
|
struct _CEditWindow
|
||||||
{
|
{
|
||||||
HildonStackableWindow parent;
|
HildonStackableWindow parent;
|
||||||
|
|
||||||
|
GtkWidget *name_label;
|
||||||
|
GtkWidget *have_label;
|
||||||
|
GtkWidget *total_label;
|
||||||
|
|
||||||
|
gint collection_id;
|
||||||
};
|
};
|
||||||
|
|
||||||
GType c_edit_window_get_type(void);
|
GType c_edit_window_get_type(void);
|
||||||
|
|
||||||
GtkWidget *c_edit_window_new(void);
|
GtkWidget *c_edit_window_new(gint collection_id);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
123
src/data.c
123
src/data.c
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
static gboolean data_check_and_create_database(gchar *data_file);
|
static gboolean data_check_and_create_database(gchar *data_file);
|
||||||
static gint data_create_new_database(const gchar *filename);
|
static gint data_create_new_database(const gchar *filename);
|
||||||
|
static struct collection *data_get_collection_from_stmt(sqlite3_stmt *stmt);
|
||||||
|
|
||||||
GList *data_get_series(void)
|
GList *data_get_series(void)
|
||||||
{
|
{
|
||||||
|
@ -38,14 +39,7 @@ GList *data_get_series(void)
|
||||||
&statement, NULL);
|
&statement, NULL);
|
||||||
if (res == SQLITE_OK) {
|
if (res == SQLITE_OK) {
|
||||||
while (sqlite3_step(statement) == SQLITE_ROW) {
|
while (sqlite3_step(statement) == SQLITE_ROW) {
|
||||||
struct collection *col =
|
struct collection *col = data_get_collection_from_stmt(statement);
|
||||||
(struct collection *)malloc(sizeof(struct collection));
|
|
||||||
|
|
||||||
col->id = sqlite3_column_int(statement, 0);
|
|
||||||
col->name = g_strdup(sqlite3_column_text(statement, 1));
|
|
||||||
col->current_qty = sqlite3_column_int(statement, 2);
|
|
||||||
col->total_qty = sqlite3_column_int(statement, 3);
|
|
||||||
|
|
||||||
list = g_list_append(list, (gpointer)col);
|
list = g_list_append(list, (gpointer)col);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,12 +54,96 @@ GList *data_get_series(void)
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct collection *data_get_series_by_id(gint collection_id)
|
||||||
|
{
|
||||||
|
sqlite3 *database;
|
||||||
|
sqlite3_stmt *statement;
|
||||||
|
gchar *data_file;
|
||||||
|
struct collection *col = NULL;
|
||||||
|
|
||||||
|
data_file = collections_get_data_file();
|
||||||
|
|
||||||
|
if (data_check_and_create_database(data_file)) {
|
||||||
|
if (sqlite3_open(data_file, &database) == SQLITE_OK) {
|
||||||
|
int res;
|
||||||
|
const char *sql = g_strdup_printf(
|
||||||
|
" SELECT id, "
|
||||||
|
" name, "
|
||||||
|
" current_qty, "
|
||||||
|
" total_qty "
|
||||||
|
" FROM collection "
|
||||||
|
" WHERE id = %d ", collection_id);
|
||||||
|
|
||||||
|
res = sqlite3_prepare_v2(database, sql, strlen(sql), &statement, NULL);
|
||||||
|
if (res == SQLITE_OK) {
|
||||||
|
if (sqlite3_step(statement) == SQLITE_ROW) {
|
||||||
|
col = data_get_collection_from_stmt(statement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sqlite3_finalize(statement);
|
||||||
|
}
|
||||||
|
sqlite3_close(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
return col;
|
||||||
|
}
|
||||||
|
|
||||||
|
gint *data_get_items_by_collection_id(gint collection_id)
|
||||||
|
{
|
||||||
|
gint count;
|
||||||
|
gint *volumes;
|
||||||
|
sqlite3 *database;
|
||||||
|
sqlite3_stmt *statement;
|
||||||
|
gchar *data_file;
|
||||||
|
|
||||||
|
data_file = collections_get_data_file();
|
||||||
|
count = 0;
|
||||||
|
|
||||||
|
if (data_check_and_create_database(data_file)) {
|
||||||
|
if (sqlite3_open(data_file, &database) == SQLITE_OK) {
|
||||||
|
int res;
|
||||||
|
const char *sql = g_strdup_printf(
|
||||||
|
" SELECT COUNT(id) "
|
||||||
|
" FROM items "
|
||||||
|
" WHERE collection_id = %d ", collection_id);
|
||||||
|
|
||||||
|
res = sqlite3_prepare_v2(database, sql, strlen(sql), &statement, NULL);
|
||||||
|
if (res == SQLITE_OK) {
|
||||||
|
if (sqlite3_step(statement) == SQLITE_ROW) {
|
||||||
|
count = sqlite3_column_int(statement, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sqlite3_finalize(statement);
|
||||||
|
|
||||||
|
if (count > 0) {
|
||||||
|
sql = g_strdup_printf(
|
||||||
|
" SELECT id "
|
||||||
|
" FROM items "
|
||||||
|
" WHERE collection_id = %d ", collection_id);
|
||||||
|
|
||||||
|
res = sqlite3_prepare_v2(database, sql, strlen(sql), &statement, NULL);
|
||||||
|
if (res == SQLITE_OK) {
|
||||||
|
gint i = 0;
|
||||||
|
while (sqlite3_step(statement) == SQLITE_ROW) {
|
||||||
|
volumes[i++] = sqlite3_column_int(statement, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sqlite3_close(database);
|
||||||
|
}
|
||||||
|
|
||||||
|
return volumes;
|
||||||
|
}
|
||||||
|
|
||||||
gboolean data_add_series(gchar *name, gint total_qty)
|
gboolean data_add_series(gchar *name, gint total_qty)
|
||||||
{
|
{
|
||||||
sqlite3 *database;
|
sqlite3 *database;
|
||||||
sqlite3_stmt *statement;
|
sqlite3_stmt *statement;
|
||||||
gchar *data_file;
|
gchar *data_file;
|
||||||
|
gboolean result;
|
||||||
|
|
||||||
|
result = FALSE;
|
||||||
data_file = collections_get_data_file();
|
data_file = collections_get_data_file();
|
||||||
|
|
||||||
if (data_check_and_create_database(data_file)) {
|
if (data_check_and_create_database(data_file)) {
|
||||||
|
@ -81,12 +159,14 @@ gboolean data_add_series(gchar *name, gint total_qty)
|
||||||
&statement, NULL);
|
&statement, NULL);
|
||||||
if (res == SQLITE_OK) {
|
if (res == SQLITE_OK) {
|
||||||
if (sqlite3_step(statement) == SQLITE_DONE)
|
if (sqlite3_step(statement) == SQLITE_DONE)
|
||||||
return TRUE;
|
result = TRUE;
|
||||||
}
|
}
|
||||||
|
sqlite3_finalize(statement);
|
||||||
}
|
}
|
||||||
|
sqlite3_close(database);
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean data_add_to_series(gint collection_id, gint count)
|
gboolean data_add_to_series(gint collection_id, gint count)
|
||||||
|
@ -94,10 +174,10 @@ gboolean data_add_to_series(gint collection_id, gint count)
|
||||||
sqlite3 *database;
|
sqlite3 *database;
|
||||||
sqlite3_stmt *statement;
|
sqlite3_stmt *statement;
|
||||||
gchar *data_file;
|
gchar *data_file;
|
||||||
|
gboolean result;
|
||||||
g_print("collection_id: %d, count: %d\n", collection_id, count);
|
|
||||||
|
|
||||||
data_file = collections_get_data_file();
|
data_file = collections_get_data_file();
|
||||||
|
result = FALSE;
|
||||||
|
|
||||||
if (data_check_and_create_database(data_file)) {
|
if (data_check_and_create_database(data_file)) {
|
||||||
if (sqlite3_open(data_file, &database) == SQLITE_OK) {
|
if (sqlite3_open(data_file, &database) == SQLITE_OK) {
|
||||||
|
@ -113,12 +193,14 @@ gboolean data_add_to_series(gint collection_id, gint count)
|
||||||
&statement, NULL);
|
&statement, NULL);
|
||||||
if (res == SQLITE_OK) {
|
if (res == SQLITE_OK) {
|
||||||
if (sqlite3_step(statement) == SQLITE_DONE)
|
if (sqlite3_step(statement) == SQLITE_DONE)
|
||||||
return TRUE;
|
result = TRUE;
|
||||||
}
|
}
|
||||||
|
sqlite3_finalize(statement);
|
||||||
}
|
}
|
||||||
|
sqlite3_close(database);
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean data_check_and_create_database(gchar *data_file)
|
static gboolean data_check_and_create_database(gchar *data_file)
|
||||||
|
@ -185,3 +267,16 @@ static gint data_create_new_database(const gchar *filename)
|
||||||
sqlite3_close(db);
|
sqlite3_close(db);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct collection *data_get_collection_from_stmt(sqlite3_stmt *stmt)
|
||||||
|
{
|
||||||
|
struct collection *collection =
|
||||||
|
(struct collection *)malloc(sizeof(struct collection));
|
||||||
|
|
||||||
|
collection->id = sqlite3_column_int(stmt, 0);
|
||||||
|
collection->name = g_strdup(sqlite3_column_text(stmt, 1));
|
||||||
|
collection->current_qty = sqlite3_column_int(stmt, 2);
|
||||||
|
collection->total_qty = sqlite3_column_int(stmt, 3);
|
||||||
|
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
|
|
@ -9,5 +9,7 @@ struct collection
|
||||||
};
|
};
|
||||||
|
|
||||||
GList *data_get_series(void);
|
GList *data_get_series(void);
|
||||||
|
struct collection *data_get_series_by_id(gint collection_id);
|
||||||
|
gint *data_get_items_by_collection_id(gint collection_id);
|
||||||
gboolean data_add_series(gchar *name, gint total_qty);
|
gboolean data_add_series(gchar *name, gint total_qty);
|
||||||
gboolean data_add_to_series(gint id, gint count);
|
gboolean data_add_to_series(gint id, gint count);
|
||||||
|
|
|
@ -22,7 +22,7 @@ void interface_show_edit_window(void)
|
||||||
|
|
||||||
stack = hildon_window_stack_get_default();
|
stack = hildon_window_stack_get_default();
|
||||||
|
|
||||||
window = c_edit_window_new();
|
window = c_edit_window_new(1);
|
||||||
hildon_window_stack_push(stack, HILDON_STACKABLE_WINDOW(window), NULL);
|
hildon_window_stack_push(stack, HILDON_STACKABLE_WINDOW(window), NULL);
|
||||||
gtk_widget_show_all(window);
|
gtk_widget_show_all(window);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue