Restyle, reindent, refactor (a little)

This commit is contained in:
Tom Willemsen 2012-10-21 16:24:45 +02:00
parent 8e49f0c56e
commit aa77d2a2f5
10 changed files with 894 additions and 983 deletions

View file

@ -1,32 +1,64 @@
#include "data.h" #include "data.h"
#include <sqlite3.h>
#include <gtk/gtk.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <errno.h> #include <errno.h>
#include <gtk/gtk.h>
#include <sqlite3.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "eom.h" #include "eom.h"
static gboolean data_check_and_create_database(gchar *data_file); static gboolean check_and_create_database(gchar*);
static gint data_create_new_database(const gchar *filename); static gint create_new_database(const gchar*);
static Manga *data_get_manga_from_statement(sqlite3_stmt *stmt); static gboolean execute_non_query(const char *sql);
static GList *data_get_manga_for_query(const gchar *query); static GList *get_manga_for_query(const gchar*);
static Manga *get_manga_from_statement(sqlite3_stmt*);
GList *data_get_manga(void) gboolean
data_add_manga(gchar *name, gint total_qty)
{ {
const char *sql = gchar *sql =
" SELECT id, " g_strdup_printf(" INSERT INTO manga (name, current_qty, "
" name, " "total_qty) VALUES ('%s', 0, %d)",
" current_qty, " name, total_qty);
" total_qty " gboolean ret = execute_non_query(sql);
" FROM manga "
" ORDER BY name " g_free(sql);
" COLLATE NOCASE ";
return data_get_manga_for_query(sql); return ret;
} }
GList *data_get_incomplete_manga(void) gboolean
data_add_to_manga(gint manga_id, gint count)
{
gchar *sql =
g_strdup_printf(" UPDATE manga "
" SET current_qty = current_qty + %d "
" WHERE id = %d", count, manga_id);
gboolean ret = execute_non_query(sql);
g_free(sql);
return ret;
}
gboolean
data_add_volume_to_manga(gint manga_id, gint volume)
{
char *sql = g_strdup_printf(" INSERT INTO volume "
" VALUES (%d, %d, 0) ",
manga_id, volume);
gboolean ret = execute_non_query(sql);
g_free(sql);
return ret;
}
GList *
data_get_incomplete_manga(void)
{ {
const char *sql = const char *sql =
" SELECT id, " " SELECT id, "
@ -37,348 +69,169 @@ GList *data_get_incomplete_manga(void)
" WHERE current_qty != total_qty " " WHERE current_qty != total_qty "
" ORDER BY name " " ORDER BY name "
" COLLATE NOCASE "; " COLLATE NOCASE ";
return data_get_manga_for_query(sql);
return get_manga_for_query(sql);
} }
GList *data_get_manga_for_query(const gchar *query) GList *
data_get_manga(void)
{ {
sqlite3 *database; const char *sql =
sqlite3_stmt *statement; " SELECT id, "
gchar *data_file; " name, "
GList *list = NULL; " current_qty, "
" total_qty "
" FROM manga "
" ORDER BY name "
" COLLATE NOCASE ";
data_file = eom_get_data_file(); return get_manga_for_query(sql);
if (data_check_and_create_database(data_file)) {
if (sqlite3_open(data_file, &database) == SQLITE_OK) {
int res = sqlite3_prepare_v2(database,
query,
strlen(query),
&statement, NULL);
if (res == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
Manga *manga = data_get_manga_from_statement(statement);
list = g_list_append(list, (gpointer)manga);
}
}
else
g_print("error %d: %s\n", res, sqlite3_errmsg(database));
/* Release the compiled statement from memory */
sqlite3_finalize(statement);
}
sqlite3_close(database);
} }
return list; Manga *
} data_get_manga_by_id(gint manga_id)
Manga *data_get_manga_by_id(gint manga_id)
{ {
sqlite3 *database; sqlite3 *db;
sqlite3_stmt *statement; sqlite3_stmt *stmt;
gchar *data_file; gchar *data_file;
Manga *manga = NULL; Manga *manga = NULL;
data_file = eom_get_data_file(); data_file = eom_get_data_file();
if (data_check_and_create_database(data_file)) { if (check_and_create_database(data_file)) {
if (sqlite3_open(data_file, &database) == SQLITE_OK) { if (sqlite3_open(data_file, &db) == SQLITE_OK) {
int res; int res;
const char *sql = g_strdup_printf( char *sql =
" SELECT id, " g_strdup_printf(" SELECT id, "
" name, " " name, "
" current_qty, " " current_qty, "
" total_qty " " total_qty "
" FROM manga " " FROM manga "
" WHERE id = %d ", manga_id); " WHERE id = %d ", manga_id);
res = sqlite3_prepare_v2(database, sql, strlen(sql), &statement, NULL); res = sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL);
g_free(sql);
if (res == SQLITE_OK) { if (res == SQLITE_OK) {
if (sqlite3_step(statement) == SQLITE_ROW) { if (sqlite3_step(stmt) == SQLITE_ROW) {
manga = data_get_manga_from_statement(statement); manga = get_manga_from_statement(stmt);
} }
} }
sqlite3_finalize(statement); sqlite3_finalize(stmt);
} }
sqlite3_close(database); sqlite3_close(db);
} }
return manga; return manga;
} }
void data_get_volumes_for_manga(Manga *manga) void
data_get_volumes_for_manga(Manga *manga)
{ {
gint count; gint count;
Volume *volumes; Volume *volumes;
sqlite3 *database; sqlite3 *db;
sqlite3_stmt *statement; sqlite3_stmt *stmt;
gchar *data_file; gchar *data_file;
data_file = eom_get_data_file(); data_file = eom_get_data_file();
count = 0; count = 0;
if (data_check_and_create_database(data_file)) { if (check_and_create_database(data_file)) {
if (sqlite3_open(data_file, &database) == SQLITE_OK) { if (sqlite3_open(data_file, &db) == SQLITE_OK) {
int res; int res;
const char *sql = g_strdup_printf( char *sql = g_strdup_printf(" SELECT COUNT(id) "
" SELECT COUNT(id) "
" FROM volume " " FROM volume "
" WHERE manga_id = %d ", manga->id); " WHERE manga_id = %d ",
manga->id);
res = sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL);
g_free(sql);
res = sqlite3_prepare_v2(database, sql, strlen(sql), &statement, NULL);
if (res == SQLITE_OK) { if (res == SQLITE_OK) {
if (sqlite3_step(statement) == SQLITE_ROW) { if (sqlite3_step(stmt) == SQLITE_ROW) {
count = sqlite3_column_int(statement, 0); count = sqlite3_column_int(stmt, 0);
} }
} }
sqlite3_finalize(statement); sqlite3_finalize(stmt);
volumes = calloc(sizeof(Volume), count); volumes = calloc(sizeof(Volume), count);
if (count > 0) { if (count > 0) {
sql = g_strdup_printf( sql = g_strdup_printf(" SELECT id, "
" SELECT id, "
" read " " read "
" FROM volume " " FROM volume "
" WHERE manga_id = %d ", manga->id); " WHERE manga_id = %d ",
manga->id);
res = sqlite3_prepare_v2(db, sql, strlen(sql), &stmt,
NULL);
g_free(sql);
res = sqlite3_prepare_v2(database, sql, strlen(sql), &statement, NULL);
if (res == SQLITE_OK) { if (res == SQLITE_OK) {
gint i = 0; gint i = 0;
while (sqlite3_step(statement) == SQLITE_ROW) { while (sqlite3_step(stmt) == SQLITE_ROW) {
volumes[i].number = sqlite3_column_int(statement, 0); volumes[i].number = sqlite3_column_int(stmt, 0);
volumes[i].read = sqlite3_column_int(statement, 1); volumes[i].read = sqlite3_column_int(stmt, 1);
i++; i++;
}; };
} }
sqlite3_finalize(statement); sqlite3_finalize(stmt);
} }
} }
sqlite3_close(database); sqlite3_close(db);
} }
manga->vol_count = count; manga->vol_count = count;
manga->volumes = volumes; manga->volumes = volumes;
} }
gboolean data_add_manga(gchar *name, gint total_qty) gboolean
data_mark_volume_read(int read, gint manga_id, gint volume)
{ {
sqlite3 *database; gchar *sql = g_strdup_printf(" UPDATE volume "
sqlite3_stmt *statement;
gchar *data_file;
gboolean result;
result = FALSE;
data_file = eom_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(
" INSERT INTO manga (name, current_qty, total_qty) "
" VALUES ('%s', 0, %d)", name, total_qty);
res = sqlite3_prepare_v2(database,
sql,
strlen(sql),
&statement, NULL);
if (res == SQLITE_OK) {
if (sqlite3_step(statement) == SQLITE_DONE)
result = TRUE;
}
sqlite3_finalize(statement);
}
sqlite3_close(database);
}
return result;
}
gboolean data_add_to_manga(gint manga_id, gint count)
{
sqlite3 *database;
sqlite3_stmt *statement;
gchar *data_file;
gboolean result;
data_file = eom_get_data_file();
result = FALSE;
if (data_check_and_create_database(data_file)) {
if (sqlite3_open(data_file, &database) == SQLITE_OK) {
int res;
const char *sql = g_strdup_printf(
" UPDATE manga "
" SET current_qty = current_qty + %d "
" WHERE id = %d", count, manga_id);
res = sqlite3_prepare_v2(database,
sql,
strlen(sql),
&statement, NULL);
if (res == SQLITE_OK) {
if (sqlite3_step(statement) == SQLITE_DONE)
result = TRUE;
}
sqlite3_finalize(statement);
}
sqlite3_close(database);
}
return result;
}
gboolean data_add_volume_to_manga(gint manga_id, gint volume)
{
sqlite3 *database;
sqlite3_stmt *statement;
gchar *data_file;
gboolean result;
data_file = eom_get_data_file();
result = FALSE;
if (data_check_and_create_database(data_file)) {
if (sqlite3_open(data_file, &database) == SQLITE_OK) {
int res;
const char *sql = g_strdup_printf(
" INSERT INTO volume "
" VALUES (%d, %d, 0) ",
manga_id, volume);
res = sqlite3_prepare_v2(database,
sql,
strlen(sql),
&statement, NULL);
if (res == SQLITE_OK) {
res = sqlite3_step(statement);
if (res == SQLITE_DONE)
result = TRUE;
else
g_print("step did not return DONE, it DID return %d\n", res);
}
else
g_print("res was not OK\n");
sqlite3_finalize(statement);
}
else
g_print("database wasn't opened\n");
sqlite3_close(database);
}
else
g_print("couldn't check or create database\n");
return result;
}
gboolean data_mark_volume_read(int read, gint manga_id, gint volume)
{
sqlite3 *database;
sqlite3_stmt *statement;
gchar *data_file;
gboolean result;
data_file = eom_get_data_file();
result = FALSE;
if (data_check_and_create_database(data_file)) {
if (sqlite3_open(data_file, &database) == SQLITE_OK) {
int res;
const char *sql = g_strdup_printf(
" UPDATE volume "
" SET read = %d " " SET read = %d "
" WHERE manga_id = %d " " WHERE manga_id = %d "
" AND id = %d ", " AND id = %d ",
read, manga_id, volume); read, manga_id, volume);
gboolean ret = execute_non_query(sql);
res = sqlite3_prepare_v2(database, g_free(sql);
sql,
strlen(sql),
&statement, NULL);
if (res == SQLITE_OK) {
res = sqlite3_step(statement);
if (res == SQLITE_DONE)
result = TRUE;
else
g_print("step did not return DONE, it DID return %d\n", res);
}
else
g_print("res was not OK\n");
sqlite3_finalize(statement); return ret;
}
else
g_print("database wasn't opened\n");
sqlite3_close(database);
}
else
g_print("couldn't check or create database\n");
return result;
} }
gboolean data_remove_volume_from_manga(gint manga_id, gint volume) gboolean
data_remove_volume_from_manga(gint manga_id, gint volume)
{ {
sqlite3 *database; char *sql = g_strdup_printf(" DELETE FROM volume "
sqlite3_stmt *statement;
gchar *data_file;
gboolean result;
data_file = eom_get_data_file();
result = FALSE;
if (data_check_and_create_database(data_file)) {
if (sqlite3_open(data_file, &database) == SQLITE_OK) {
int res;
const char *sql = g_strdup_printf(
" DELETE FROM volume "
" WHERE manga_id = %d " " WHERE manga_id = %d "
" AND id = %d ", manga_id, volume); " AND id = %d ", manga_id, volume);
gboolean ret = execute_non_query(sql);
res = sqlite3_prepare_v2(database, g_free(sql);
sql,
strlen(sql),
&statement, NULL);
if (res == SQLITE_OK)
if (sqlite3_step(statement) == SQLITE_DONE)
result = TRUE;
else
g_print("step did not return DONE\n");
else
g_print("result did not return OK\n");
sqlite3_finalize(statement); return ret;
}
else
g_print("couldn't open database\n");
sqlite3_close(database);
}
else
g_print("couldn't check or create database\n");
return result;
} }
static gboolean data_check_and_create_database(gchar *data_file) static gboolean
check_and_create_database(gchar *data_file)
{ {
if (!access(data_file, R_OK) == 0) if (!access(data_file, R_OK) == 0)
if (data_create_new_database(data_file)) { if (create_new_database(data_file)) {
g_printerr("Couldn't create a new database\n"); g_printerr("Couldn't create a new database\n");
return FALSE; /* Couldn't create database, can't continue */ return FALSE; /* Couldn't create database, can't continue */
} }
return TRUE; return TRUE;
} }
static gint data_create_new_database(const gchar *filename) static gint
create_new_database(const gchar *filename)
{ {
sqlite3 *db; sqlite3 *db;
char *zErrMsg = 0; char *zErrMsg = 0;
@ -391,6 +244,7 @@ static gint data_create_new_database(const gchar *filename)
/* Open database connection, create file */ /* Open database connection, create file */
rc = sqlite3_open(filename, &db); rc = sqlite3_open(filename, &db);
if (rc) { if (rc) {
g_printerr("Can't open database: %s\n", sqlite3_errmsg(db)); g_printerr("Can't open database: %s\n", sqlite3_errmsg(db));
if (db) if (db)
@ -399,7 +253,8 @@ static gint data_create_new_database(const gchar *filename)
} }
/* Create collections table */ /* Create collections table */
rc = sqlite3_exec(db, "CREATE TABLE manga(" rc = sqlite3_exec(db,
"CREATE TABLE manga("
"id INTEGER PRIMARY KEY," "id INTEGER PRIMARY KEY,"
"name VARCHAR(100)," "name VARCHAR(100),"
"current_qty INTEGER," "current_qty INTEGER,"
@ -433,10 +288,72 @@ static gint data_create_new_database(const gchar *filename)
return 0; return 0;
} }
static Manga *data_get_manga_from_statement(sqlite3_stmt *stmt) static gboolean
execute_non_query(const gchar *sql)
{ {
Manga *manga = sqlite3 *db;
(Manga *)malloc(sizeof(Manga)); sqlite3_stmt *stmt;
gchar *data_file;
gboolean result;
result = FALSE;
data_file = eom_get_data_file();
if (check_and_create_database(data_file)) {
if (sqlite3_open(data_file, &db) == SQLITE_OK) {
int res =
sqlite3_prepare_v2(db, sql, strlen(sql), &stmt, NULL);
if (res == SQLITE_OK) {
if (sqlite3_step(stmt) == SQLITE_DONE)
result = TRUE;
}
sqlite3_finalize(stmt);
}
sqlite3_close(db);
}
return result;
}
static GList *
get_manga_for_query(const gchar *query)
{
sqlite3 *database;
sqlite3_stmt *statement;
gchar *data_file;
GList *list = NULL;
data_file = eom_get_data_file();
if (check_and_create_database(data_file)) {
if (sqlite3_open(data_file, &database) == SQLITE_OK) {
int res = sqlite3_prepare_v2(database, query, strlen(query),
&statement, NULL);
if (res == SQLITE_OK) {
while (sqlite3_step(statement) == SQLITE_ROW) {
Manga *manga = get_manga_from_statement(statement);
list = g_list_append(list, (gpointer)manga);
}
}
else
g_print("error %d: %s\n", res, sqlite3_errmsg(database));
/* Release the compiled statement from memory */
sqlite3_finalize(statement);
}
sqlite3_close(database);
}
return list;
}
static Manga *
get_manga_from_statement(sqlite3_stmt *stmt)
{
Manga *manga = (Manga *)malloc(sizeof(Manga));
manga->id = sqlite3_column_int(stmt, 0); manga->id = sqlite3_column_int(stmt, 0);
manga->name = g_strdup(sqlite3_column_text(stmt, 1)); manga->name = g_strdup(sqlite3_column_text(stmt, 1));

View file

@ -3,17 +3,13 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
typedef struct _volume Volume; typedef struct
struct _volume
{ {
int number; int number;
int read; int read;
}; } Volume;
typedef struct _manga Manga; typedef struct
struct _manga
{ {
int id; int id;
int current_qty; int current_qty;
@ -21,16 +17,16 @@ struct _manga
char *name; char *name;
int vol_count; int vol_count;
Volume *volumes; Volume *volumes;
}; } Manga;
GList *data_get_manga(void); gboolean data_add_manga(gchar*, gint);
gboolean data_add_to_manga(gint, gint);
gboolean data_add_volume_to_manga(gint, gint);
GList *data_get_incomplete_manga(void); GList *data_get_incomplete_manga(void);
Manga *data_get_manga_by_id(gint manga_id); GList *data_get_manga(void);
void data_get_volumes_for_manga(Manga *manga); Manga *data_get_manga_by_id(gint);
gboolean data_add_manga(gchar *name, gint total_qty); void data_get_volumes_for_manga(Manga*);
gboolean data_add_to_manga(gint id, gint count); gboolean data_mark_volume_read(gint, gint, gint);
gboolean data_add_volume_to_manga(gint manga_id, gint volume); gboolean data_remove_volume_from_manga(gint, gint);
gboolean data_mark_volume_read(gint read, gint manga_id, gint volume);
gboolean data_remove_volume_from_manga(gint manga_id, gint volume);
#endif /* __DATA_H__ */ #endif /* __DATA_H__ */

View file

@ -1,7 +1,9 @@
#include "eom-edit-window.h" #include "eom-edit-window.h"
#include <hildon/hildon.h> #include <hildon/hildon.h>
#include <limits.h> #include <limits.h>
#include <stdlib.h> #include <stdlib.h>
#include "data.h" #include "data.h"
#include "eom-main-window.h" #include "eom-main-window.h"
@ -10,103 +12,59 @@ enum {
EOM_EDIT_PROP_CID EOM_EDIT_PROP_CID
}; };
static void eom_edit_window_set_manga_id(EomEditWindow *self, static void eom_edit_window_class_init(EomEditWindowClass*);
gint manga_id); static void eom_edit_window_init(EomEditWindow *self);
static void eom_edit_window_on_volume_toggled(GtkToggleButton *togglebutton, static void finalize(GObject*);
gpointer user_data); static void get_property(GObject*, guint, GValue*, GParamSpec*);
static void static void on_volume_read_toggled(GtkToggleButton*, gpointer);
eom_edit_window_on_volume_read_toggled(GtkToggleButton *togglebutton, static void on_volume_toggled(GtkToggleButton*, gpointer);
gpointer user_data); static void set_manga_id(EomEditWindow*, gint);
static void set_property(GObject*, guint, const GValue*, GParamSpec*);
G_DEFINE_TYPE(EomEditWindow, eom_edit_window, HILDON_TYPE_STACKABLE_WINDOW) G_DEFINE_TYPE(EomEditWindow, eom_edit_window, HILDON_TYPE_STACKABLE_WINDOW)
GtkWidget *eom_edit_window_new(gint manga_id) GtkWidget *
eom_edit_window_new(gint manga_id)
{ {
return g_object_new(EOM_TYPE_EDIT_WINDOW, "manga-id", manga_id, NULL); return g_object_new(EOM_TYPE_EDIT_WINDOW,
"manga-id", manga_id,
NULL);
} }
static void eom_edit_window_set_property(GObject *object, static void
guint property_id, eom_edit_window_class_init(EomEditWindowClass *klass)
const GValue *value,
GParamSpec *pspec)
{
EomEditWindow *self = EOM_EDIT_WINDOW(object);
gint manga_id = g_value_get_int(value);
switch (property_id) {
case EOM_EDIT_PROP_CID:
eom_edit_window_set_manga_id(self, manga_id);
break;
default:
/* We don't have any other properties */
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
}
}
static void eom_edit_window_get_property(GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
EomEditWindow *self = EOM_EDIT_WINDOW(object);
switch (property_id) {
case EOM_EDIT_PROP_CID:
g_value_set_int(value, self->current_manga->id);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
}
}
static void eom_edit_window_finalize(GObject *object)
{
EomEditWindow *self = EOM_EDIT_WINDOW(object);
g_free(self->current_manga);
G_OBJECT_CLASS(eom_edit_window_parent_class)->finalize(object);
}
static void eom_edit_window_class_init(EomEditWindowClass *klass)
{ {
GObjectClass *gobject_class = G_OBJECT_CLASS(klass); GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
GParamSpec *pspec; GParamSpec *pspec;
gobject_class->set_property = eom_edit_window_set_property; gobject_class->set_property = set_property;
gobject_class->get_property = eom_edit_window_get_property; gobject_class->get_property = get_property;
gobject_class->finalize = eom_edit_window_finalize; gobject_class->finalize = finalize;
pspec = g_param_spec_int("manga-id", "ID of the manga",
pspec = g_param_spec_int("manga-id", "Set the manga-id", 0, INT_MAX, 0,
"ID of the manga",
"Set the manga-id",
0,
INT_MAX,
0,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE); G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE);
g_object_class_install_property(gobject_class,
EOM_EDIT_PROP_CID, g_object_class_install_property(gobject_class, EOM_EDIT_PROP_CID,
pspec); pspec);
} }
static void eom_edit_window_init(EomEditWindow *self) static void
eom_edit_window_init(EomEditWindow *self)
{ {
GtkWidget *pannablearea; GtkWidget *panarea;
GtkWidget *table; GtkWidget *table;
GtkWidget *nameclabel; GtkWidget *nameclabel;
GtkWidget *haveclabel; GtkWidget *haveclabel;
GtkWidget *totalclabel; GtkWidget *totalclabel;
pannablearea = hildon_pannable_area_new(); panarea = hildon_pannable_area_new();
g_object_set(G_OBJECT(pannablearea), g_object_set(G_OBJECT(panarea),
"mov-mode", HILDON_MOVEMENT_MODE_VERT, "mov-mode", HILDON_MOVEMENT_MODE_VERT,
NULL); NULL);
gtk_container_add(GTK_CONTAINER(self), pannablearea); gtk_container_add(GTK_CONTAINER(self), panarea);
table = gtk_table_new(4, 2, FALSE); table = gtk_table_new(4, 2, FALSE);
hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(pannablearea), hildon_pannable_area_add_with_viewport(HILDON_PANNABLE_AREA(panarea),
table); table);
/* Label for the name field */ /* Label for the name field */
@ -145,115 +103,162 @@ static void eom_edit_window_init(EomEditWindow *self)
gtk_table_attach(GTK_TABLE(table), self->total_entry, 1, 2, 2, 3, gtk_table_attach(GTK_TABLE(table), self->total_entry, 1, 2, 2, 3,
GTK_EXPAND | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0); GTK_EXPAND | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
self->volumes_box = gtk_vbox_new(TRUE, 0); self->volsbox = gtk_vbox_new(TRUE, 0);
gtk_table_attach(GTK_TABLE(table), self->volumes_box, 0, 2, 3, 4, gtk_table_attach(GTK_TABLE(table), self->volsbox, 0, 2, 3, 4,
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
} }
static void eom_edit_window_set_manga_id(EomEditWindow *self, gint manga_id) static void
finalize(GObject *object)
{ {
Manga *manga; EomEditWindow *self = EOM_EDIT_WINDOW(object);
gint i;
gint j = 0; g_free(self->manga);
G_OBJECT_CLASS(eom_edit_window_parent_class)->finalize(object);
}
static void
get_property(GObject *object, guint property_id, GValue *value,
GParamSpec *pspec)
{
EomEditWindow *self = EOM_EDIT_WINDOW(object);
switch (property_id) {
case EOM_EDIT_PROP_CID:
g_value_set_int(value, self->manga->id);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
}
}
static void
on_volume_read_toggled(GtkToggleButton *togglebutton, gpointer user_data)
{
EomEditWindow *self = (EomEditWindow *)user_data;
gboolean active = gtk_toggle_button_get_active(togglebutton);
gint volume = atoi(gtk_button_get_label(GTK_BUTTON(togglebutton)));
if (!data_mark_volume_read(active, self->manga->id, volume))
g_print("coulnd't mark volume as read\n");
}
static void
on_volume_toggled(GtkToggleButton *togglebutton, gpointer user_data)
{
EomEditWindow *self = (EomEditWindow *)user_data;
gboolean active = gtk_toggle_button_get_active(togglebutton);
gint volume = atoi(gtk_button_get_label(GTK_BUTTON(togglebutton)));
gchar *txt;
if (active) {
/* Add 1 to mangas collected */
if (!data_add_to_manga(self->manga->id, 1)) {
return;
}
if (!data_add_volume_to_manga(self->manga->id, volume)) {
data_add_to_manga(self->manga->id, 1);
return;
}
self->manga->current_qty++;
}
else {
/* Remove 1 from mangas collected */
if (!data_add_to_manga(self->manga->id, -1)) {
return;
}
if (!data_remove_volume_from_manga(self->manga->id,
volume)) {
data_add_to_manga(self->manga->id, 1); /* Undo */
return;
}
self->manga->current_qty--;
}
txt = g_strdup_printf("%d", self->manga->current_qty);
gtk_label_set_text(GTK_LABEL(self->have_label), txt);
g_free(txt);
}
static void
set_manga_id(EomEditWindow *self, gint manga_id)
{
GtkWidget *bbox;
GtkWidget *clabel; GtkWidget *clabel;
GtkWidget *tlabel; GtkWidget *tlabel;
GtkWidget *buttonbox; Manga *manga;
gchar *txt;
gint i;
gint j = 0;
manga = data_get_manga_by_id(manga_id); manga = data_get_manga_by_id(manga_id);
data_get_volumes_for_manga(manga); data_get_volumes_for_manga(manga);
self->current_manga = manga; self->manga = manga;
gtk_entry_set_text(GTK_ENTRY(self->name_entry), manga->name); gtk_entry_set_text(GTK_ENTRY(self->name_entry), manga->name);
gtk_label_set_text(GTK_LABEL(self->have_label),
g_strdup_printf("%d", manga->current_qty)); txt = g_strdup_printf("%d", manga->current_qty);
gtk_entry_set_text(GTK_ENTRY(self->total_entry), gtk_label_set_text(GTK_LABEL(self->have_label), txt);
g_strdup_printf("%d", manga->total_qty)); g_free(txt);
txt = g_strdup_printf("%d", manga->total_qty);
gtk_entry_set_text(GTK_ENTRY(self->total_entry), txt);
g_free(txt);
/* TODO: Create labels for collected and read lists */ /* TODO: Create labels for collected and read lists */
for (i = 0; i < manga->total_qty; i++) { for (i = 0; i < manga->total_qty; i++) {
GtkWidget *button; GtkWidget *btn;
GtkWidget *read_button; GtkWidget *rbtn;
buttonbox = gtk_hbox_new(TRUE, 2); bbox = gtk_hbox_new(TRUE, 2);
gtk_box_pack_start(GTK_BOX(self->volumes_box), buttonbox, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(self->volsbox), bbox, TRUE, TRUE, 0);
/* Button indicating collected state */ /* Button indicating collected state */
button = gtk_toggle_button_new_with_label(g_strdup_printf("%d", i + 1)); txt = g_strdup_printf("%d", i + 1);
gtk_box_pack_start(GTK_BOX(buttonbox), button, TRUE, TRUE, 0); btn = gtk_toggle_button_new_with_label(txt);
gtk_box_pack_start(GTK_BOX(bbox), btn, TRUE, TRUE, 0);
/* Button indicating read state */ /* Button indicating read state */
read_button = rbtn = gtk_toggle_button_new_with_label(txt);
gtk_toggle_button_new_with_label(g_strdup_printf("%d", i + 1)); gtk_box_pack_start(GTK_BOX(bbox), rbtn, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(buttonbox), read_button, TRUE, TRUE, 0); g_free(txt);
if (j < manga->vol_count && manga->volumes[j].number == i + 1) { if (j < manga->vol_count && manga->volumes[j].number == i + 1) {
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(btn), TRUE);
if (manga->volumes[j].read) if (manga->volumes[j].read)
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(read_button), TRUE); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rbtn),
TRUE);
j++; j++;
} }
g_signal_connect(button, "toggled",
G_CALLBACK(eom_edit_window_on_volume_toggled), g_signal_connect(btn, "toggled", G_CALLBACK(on_volume_toggled),
(gpointer)self); (gpointer)self);
g_signal_connect(read_button, "toggled", g_signal_connect(rbtn, "toggled",
G_CALLBACK(eom_edit_window_on_volume_read_toggled), G_CALLBACK(on_volume_read_toggled),
(gpointer)self); (gpointer)self);
} }
} }
static void eom_edit_window_on_volume_toggled(GtkToggleButton *togglebutton,
gpointer user_data)
{
EomEditWindow *self;
gboolean active;
gint volume;
self = (EomEditWindow *)user_data;
active = gtk_toggle_button_get_active(togglebutton);
volume = atoi(gtk_button_get_label(GTK_BUTTON(togglebutton)));
if (active) {
/* Add 1 to mangas collected */
if (!data_add_to_manga(self->current_manga->id, 1)) {
return;
}
if (!data_add_volume_to_manga(self->current_manga->id, volume)) {
data_add_to_manga(self->current_manga->id, 1);
return;
}
self->current_manga->current_qty++;
}
else {
/* Remove 1 from mangas collected */
if (!data_add_to_manga(self->current_manga->id, -1)) {
return;
}
if (!data_remove_volume_from_manga(self->current_manga->id, volume)) {
data_add_to_manga(self->current_manga->id, 1); /* Undo */
return;
}
self->current_manga->current_qty--;
}
gtk_label_set_text(GTK_LABEL(self->have_label),
g_strdup_printf("%d", self->current_manga->current_qty));
}
static void static void
eom_edit_window_on_volume_read_toggled(GtkToggleButton *togglebutton, set_property(GObject *object, guint property_id, const GValue *value,
gpointer user_data) GParamSpec *pspec)
{ {
EomEditWindow *self; EomEditWindow *self = EOM_EDIT_WINDOW(object);
gboolean active; gint manga_id = g_value_get_int(value);
gint volume;
self = (EomEditWindow *)user_data; switch (property_id) {
active = gtk_toggle_button_get_active(togglebutton); case EOM_EDIT_PROP_CID:
volume = atoi(gtk_button_get_label(GTK_BUTTON(togglebutton))); set_manga_id(self, manga_id);
break;
if (!data_mark_volume_read(active, self->current_manga->id, volume)) default:
g_print("coulnd't mark volume as read\n"); /* We don't have any other properties */
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
break;
}
} }

View file

@ -2,6 +2,7 @@
#define __EOM_EDIT_WINDOW_H__ #define __EOM_EDIT_WINDOW_H__
#include <hildon/hildon-stackable-window.h> #include <hildon/hildon-stackable-window.h>
#include "data.h" #include "data.h"
G_BEGIN_DECLS G_BEGIN_DECLS
@ -32,29 +33,25 @@ G_BEGIN_DECLS
EOM_TYPE_EDIT_WINDOW, \ EOM_TYPE_EDIT_WINDOW, \
EomEditWindowClass)) EomEditWindowClass))
typedef struct _EomEditWindow EomEditWindow; typedef struct
typedef struct _EomEditWindowClass EomEditWindowClass;
struct _EomEditWindowClass
{ {
HildonStackableWindowClass parent_class; HildonStackableWindowClass parent_class;
}; } EomEditWindowClass;
struct _EomEditWindow typedef struct
{ {
HildonStackableWindow parent; HildonStackableWindow parent;
GtkWidget *name_entry; GtkWidget *name_entry;
GtkWidget *have_label; GtkWidget *have_label;
GtkWidget *total_entry; GtkWidget *total_entry;
GtkWidget *volumes_box; GtkWidget *volsbox;
Manga *current_manga; Manga *manga;
}; } EomEditWindow;
GType eom_edit_window_get_type(void); GType eom_edit_window_get_type(void);
GtkWidget *eom_edit_window_new(gint);
GtkWidget *eom_edit_window_new(gint manga_id);
G_END_DECLS G_END_DECLS

View file

@ -10,7 +10,8 @@
#include "data.h" #include "data.h"
#include "interface.h" #include "interface.h"
G_DEFINE_TYPE(EomMainWindow, eom_main_window, HILDON_TYPE_STACKABLE_WINDOW) G_DEFINE_TYPE(EomMainWindow, eom_main_window,
HILDON_TYPE_STACKABLE_WINDOW)
enum { enum {
COL_ID = 0, COL_ID = 0,
@ -25,29 +26,30 @@ struct filter_args {
gint state; gint state;
}; };
static void eom_main_window_add_menu(EomMainWindow *window); static void add_menu(EomMainWindow*);
static void eom_main_window_on_new(GtkWidget *widget, GtkWindow *window); static void eom_main_window_class_init(EomMainWindowClass*);
static void eom_main_window_on_filter(GtkWidget *widget, struct filter_args *arg); static void eom_main_window_init(EomMainWindow*);
static void eom_main_window_on_add_clicked(GtkWidget *widget, static gboolean on_edit_closed(GtkWidget*, GdkEvent*, gpointer);
gpointer user_data); static void on_filter(GtkWidget*, struct filter_args*);
static void eom_main_window_on_remove_clicked(GtkWidget *widget, static void on_new(GtkWidget*, GtkWindow*);
gpointer user_data); static void on_row_activated(GtkWidget*, GtkTreePath*, GtkTreeViewColumn*, gpointer);
static gboolean eom_main_window_on_edit_closed(GtkWidget *widget,
GdkEvent *event,
gpointer user_data);
static void eom_main_window_on_row_activated(GtkWidget *treeview,
GtkTreePath *path,
GtkTreeViewColumn *column,
gpointer user_data);
GtkWidget *eom_main_window_new(void) void
eom_main_window_add_line(EomMainWindow *window, gint id,
const gchar *name, gint current_qty,
gint total_qty)
{ {
return g_object_new(EOM_TYPE_MAIN_WINDOW, gtk_list_store_append(window->store, &window->iter);
"state", 0, gtk_list_store_set(window ->store, &window->iter,
NULL); COL_ID, id,
COL_NAME, name,
COL_CURRENT, current_qty,
COL_TOTAL, total_qty,
-1);
} }
void eom_main_window_load(EomMainWindow *self) void
eom_main_window_load(EomMainWindow *self)
{ {
GList *list; GList *list;
int i; int i;
@ -61,14 +63,16 @@ void eom_main_window_load(EomMainWindow *self)
while (list) { while (list) {
Manga *manga = list->data; Manga *manga = list->data;
eom_main_window_add_line(self, manga->id, manga->name, eom_main_window_add_line(self, manga->id, manga->name,
manga->current_qty, manga->total_qty); manga->current_qty, manga->total_qty);
free(manga->name); free(manga->name);
if (manga->volumes != NULL) { if (manga->volumes != NULL) {
for (i = 0; i < manga->vol_count; i++) for (i = 0; i < manga->vol_count; i++)
free(manga->volumes + i); free(manga->volumes + i);
} }
free(manga); free(manga);
list = g_list_next(list); list = g_list_next(list);
} }
@ -76,25 +80,61 @@ void eom_main_window_load(EomMainWindow *self)
g_list_free_1(list); g_list_free_1(list);
} }
void eom_main_window_add_line(EomMainWindow *window, GtkWidget *
gint id, eom_main_window_new(void)
const gchar *name,
gint current_qty,
gint total_qty)
{ {
gtk_list_store_append(window->store, &window->iter); return g_object_new(EOM_TYPE_MAIN_WINDOW, NULL);
gtk_list_store_set(window ->store, &window->iter,
COL_ID, id,
COL_NAME, name,
COL_CURRENT, current_qty,
COL_TOTAL, total_qty,
-1);
} }
static void eom_main_window_class_init(EomMainWindowClass *class) static void
add_menu(EomMainWindow *window)
{
HildonAppMenu *appmenu;
GtkWidget *new_button;
GtkWidget *all_filter, *collect_filter;
struct filter_args *args0 = malloc(sizeof(struct filter_args));
struct filter_args *args1 = malloc(sizeof(struct filter_args));
args0->window = window;
args0->state = 0;
args1->window = window;
args1->state = 1;
appmenu = HILDON_APP_MENU(hildon_app_menu_new());
new_button = hildon_gtk_button_new(HILDON_SIZE_AUTO);
gtk_button_set_label(GTK_BUTTON(new_button), "New Manga");
g_signal_connect_after(new_button, "clicked", G_CALLBACK(on_new),
GTK_WINDOW(window));
hildon_app_menu_append(appmenu, GTK_BUTTON(new_button));
all_filter = hildon_gtk_radio_button_new(HILDON_SIZE_AUTO, NULL);
gtk_button_set_label(GTK_BUTTON(all_filter), "All");
g_signal_connect_after(all_filter, "clicked", G_CALLBACK(on_filter),
args0);
hildon_app_menu_add_filter(appmenu, GTK_BUTTON(all_filter));
gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(all_filter), FALSE);
collect_filter =
hildon_gtk_radio_button_new_from_widget(HILDON_SIZE_AUTO,
GTK_RADIO_BUTTON(all_filter));
gtk_button_set_label(GTK_BUTTON(collect_filter), "Collect");
g_signal_connect_after(collect_filter, "clicked",
G_CALLBACK(on_filter), args1);
hildon_app_menu_add_filter(appmenu, GTK_BUTTON(collect_filter));
gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(collect_filter), FALSE);
gtk_widget_show_all(GTK_WIDGET(appmenu));
hildon_stackable_window_set_main_menu(HILDON_STACKABLE_WINDOW(window),
HILDON_APP_MENU(appmenu));
}
static void
eom_main_window_class_init(EomMainWindowClass *class)
{} {}
static void eom_main_window_init(EomMainWindow *window) static void
eom_main_window_init(EomMainWindow *window)
{ {
GtkCellRenderer *renderer; GtkCellRenderer *renderer;
GtkWidget *view; GtkWidget *view;
@ -105,10 +145,11 @@ static void eom_main_window_init(EomMainWindow *window)
index = -1; index = -1;
eom_main_window_add_menu(window); add_menu(window);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL); g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL); g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit),
NULL);
window->store = gtk_list_store_new(NUM_COLS, window->store = gtk_list_store_new(NUM_COLS,
G_TYPE_INT, G_TYPE_INT,
@ -123,8 +164,8 @@ static void eom_main_window_init(EomMainWindow *window)
gtk_container_add(GTK_CONTAINER(window), pannablearea); gtk_container_add(GTK_CONTAINER(window), pannablearea);
view = hildon_gtk_tree_view_new(HILDON_UI_MODE_NORMAL); view = hildon_gtk_tree_view_new(HILDON_UI_MODE_NORMAL);
g_signal_connect(view, "row-activated", g_signal_connect(view, "row-activated", G_CALLBACK(on_row_activated),
G_CALLBACK(eom_main_window_on_row_activated), window); window);
gtk_container_add(GTK_CONTAINER(pannablearea), view); gtk_container_add(GTK_CONTAINER(pannablearea), view);
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
@ -137,7 +178,8 @@ static void eom_main_window_init(EomMainWindow *window)
renderer, renderer,
"text", COL_NAME, "text", COL_NAME,
NULL); NULL);
current_column = gtk_tree_view_get_column(GTK_TREE_VIEW(view), index); current_column =
gtk_tree_view_get_column(GTK_TREE_VIEW(view), index);
gtk_tree_view_column_set_expand(current_column, TRUE); gtk_tree_view_column_set_expand(current_column, TRUE);
renderer = gtk_cell_renderer_text_new(); renderer = gtk_cell_renderer_text_new();
@ -169,60 +211,25 @@ static void eom_main_window_init(EomMainWindow *window)
g_object_unref(window->store); g_object_unref(window->store);
} }
static void eom_main_window_add_menu(EomMainWindow *window) static gboolean
on_edit_closed(GtkWidget *widget, GdkEvent *event, gpointer user_data)
{ {
HildonAppMenu *appmenu; EomMainWindow *self = user_data;
GtkWidget *new_button;
GtkWidget *all_filter, *collect_filter;
struct filter_args *args0 = malloc(sizeof(struct filter_args));
struct filter_args *args1 = malloc(sizeof(struct filter_args));
args0->window = window; eom_main_window_load(self);
args0->state = 0;
args1->window = window;
args1->state = 1;
appmenu = HILDON_APP_MENU(hildon_app_menu_new());
new_button = hildon_gtk_button_new(HILDON_SIZE_AUTO); return FALSE;
gtk_button_set_label(GTK_BUTTON(new_button), "New Manga");
g_signal_connect_after(new_button,
"clicked",
G_CALLBACK(eom_main_window_on_new),
GTK_WINDOW(window));
hildon_app_menu_append(appmenu, GTK_BUTTON(new_button));
all_filter = hildon_gtk_radio_button_new(HILDON_SIZE_AUTO, NULL);
gtk_button_set_label(GTK_BUTTON(all_filter), "All");
g_signal_connect_after(all_filter, "clicked",
G_CALLBACK(eom_main_window_on_filter),
args0);
hildon_app_menu_add_filter(appmenu, GTK_BUTTON(all_filter));
gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(all_filter), FALSE);
collect_filter =
hildon_gtk_radio_button_new_from_widget(HILDON_SIZE_AUTO,
GTK_RADIO_BUTTON(all_filter));
gtk_button_set_label(GTK_BUTTON(collect_filter), "Collect");
g_signal_connect_after(collect_filter, "clicked",
G_CALLBACK(eom_main_window_on_filter),
args1);
hildon_app_menu_add_filter(appmenu, GTK_BUTTON(collect_filter));
gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(collect_filter), FALSE);
gtk_widget_show_all(GTK_WIDGET(appmenu));
hildon_stackable_window_set_main_menu(HILDON_STACKABLE_WINDOW(window),
HILDON_APP_MENU(appmenu));
} }
static void eom_main_window_on_filter(GtkWidget *widget, struct filter_args *arg) static void
on_filter(GtkWidget *widget, struct filter_args *arg)
{ {
arg->window->state = arg->state; arg->window->state = arg->state;
eom_main_window_load(arg->window); eom_main_window_load(arg->window);
} }
static void eom_main_window_on_new(GtkWidget *widget, GtkWindow *window) static void
on_new(GtkWidget *widget, GtkWindow *window)
{ {
GtkWidget *dialog; GtkWidget *dialog;
gint result; gint result;
@ -230,7 +237,6 @@ static void eom_main_window_on_new(GtkWidget *widget, GtkWindow *window)
gint total_qty; gint total_qty;
dialog = interface_show_new_item_dialog(window); dialog = interface_show_new_item_dialog(window);
result = gtk_dialog_run(GTK_DIALOG(dialog)); result = gtk_dialog_run(GTK_DIALOG(dialog));
if (result == GTK_RESPONSE_OK) { if (result == GTK_RESPONSE_OK) {
@ -252,21 +258,9 @@ static void eom_main_window_on_new(GtkWidget *widget, GtkWindow *window)
} }
} }
static gboolean eom_main_window_on_edit_closed(GtkWidget *widget, static void
GdkEvent *event, on_row_activated(GtkWidget *treeview, GtkTreePath *path,
gpointer user_data) GtkTreeViewColumn *column, gpointer user_data)
{
EomMainWindow *self = user_data;
eom_main_window_load(self);
return FALSE;
}
static void eom_main_window_on_row_activated(GtkWidget *treeview,
GtkTreePath *path,
GtkTreeViewColumn *column,
gpointer user_data)
{ {
EomMainWindow *self = user_data; EomMainWindow *self = user_data;
GtkTreeIter iter; GtkTreeIter iter;
@ -275,11 +269,12 @@ static void eom_main_window_on_row_activated(GtkWidget *treeview,
GtkWidget *window; GtkWidget *window;
model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview)); model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
if (!gtk_tree_model_get_iter(model, &iter, path)) if (!gtk_tree_model_get_iter(model, &iter, path))
return; return;
gtk_tree_model_get(model, &iter, COL_ID, &id, -1); gtk_tree_model_get(model, &iter, COL_ID, &id, -1);
window = interface_show_edit_window(id); window = interface_show_edit_window(id);
g_signal_connect(window, "delete-event", g_signal_connect(window, "delete-event", G_CALLBACK(on_edit_closed),
G_CALLBACK(eom_main_window_on_edit_closed), self); self);
} }

View file

@ -31,15 +31,12 @@ G_BEGIN_DECLS
EOM_TYPE_MAIN_WINDOW, \ EOM_TYPE_MAIN_WINDOW, \
EomMainWindowClass)) EomMainWindowClass))
typedef struct _EomMainWindow EomMainWindow; typedef struct
typedef struct _EomMainWindowClass EomMainWindowClass;
struct _EomMainWindowClass
{ {
HildonStackableWindowClass parent_class; HildonStackableWindowClass parent_class;
}; } EomMainWindowClass;
struct _EomMainWindow typedef struct
{ {
HildonStackableWindow parent; HildonStackableWindow parent;
@ -47,19 +44,14 @@ struct _EomMainWindow
GtkListStore *store; GtkListStore *store;
int state; int state;
}; } EomMainWindow;
void eom_main_window_add_line(EomMainWindow*, gint, const gchar*, gint,
gint);
GType eom_main_window_get_type(void); GType eom_main_window_get_type(void);
void eom_main_window_load(EomMainWindow*);
GtkWidget *eom_main_window_new(void); GtkWidget *eom_main_window_new(void);
void eom_main_window_load(EomMainWindow *self);
void eom_main_window_add_line(EomMainWindow *window,
gint id,
const gchar *name,
gint current_qty,
gint total_qty);
G_END_DECLS G_END_DECLS
#endif /* __EOM_MAIN_WINDOW_H__ */ #endif /* __EOM_MAIN_WINDOW_H__ */

View file

@ -1,29 +1,38 @@
#include "eom-new-item-dialog.h" #include "eom-new-item-dialog.h"
#include <hildon/hildon-entry.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <hildon/hildon-entry.h>
#include <stdlib.h> #include <stdlib.h>
static void eom_new_item_dialog_class_init(EomNewItemDialogClass*);
static void eom_new_item_dialog_init(EomNewItemDialog*);
G_DEFINE_TYPE(EomNewItemDialog, eom_new_item_dialog, GTK_TYPE_DIALOG) G_DEFINE_TYPE(EomNewItemDialog, eom_new_item_dialog, GTK_TYPE_DIALOG)
GtkWidget *eom_new_item_dialog_new(void) const gchar *
{ eom_new_item_dialog_get_name(EomNewItemDialog *dialog)
return g_object_new(EOM_TYPE_NEW_ITEM_DIALOG, NULL);
}
const gchar *eom_new_item_dialog_get_name(EomNewItemDialog *dialog)
{ {
return hildon_entry_get_text(HILDON_ENTRY(dialog->name_entry)); return hildon_entry_get_text(HILDON_ENTRY(dialog->name_entry));
} }
gint eom_new_item_dialog_get_total_qty(EomNewItemDialog *dialog) gint
eom_new_item_dialog_get_total_qty(EomNewItemDialog *dialog)
{ {
return atoi(hildon_entry_get_text(HILDON_ENTRY(dialog->qty_entry))); return atoi(hildon_entry_get_text(HILDON_ENTRY(dialog->qty_entry)));
} }
static void eom_new_item_dialog_class_init(EomNewItemDialogClass *class) GtkWidget *
eom_new_item_dialog_new(void)
{
return g_object_new(EOM_TYPE_NEW_ITEM_DIALOG, NULL);
}
static void
eom_new_item_dialog_class_init(EomNewItemDialogClass *class)
{} {}
static void eom_new_item_dialog_init(EomNewItemDialog *dialog) static void
eom_new_item_dialog_init(EomNewItemDialog *dialog)
{ {
GtkWidget *content_area; GtkWidget *content_area;
GtkWidget *hbox; GtkWidget *hbox;
@ -34,7 +43,8 @@ static void eom_new_item_dialog_init(EomNewItemDialog *dialog)
gtk_container_add(GTK_CONTAINER(content_area), hbox); gtk_container_add(GTK_CONTAINER(content_area), hbox);
dialog->name_entry = hildon_entry_new(HILDON_SIZE_AUTO); dialog->name_entry = hildon_entry_new(HILDON_SIZE_AUTO);
hildon_entry_set_placeholder(HILDON_ENTRY(dialog->name_entry), "Name..."); hildon_entry_set_placeholder(HILDON_ENTRY(dialog->name_entry),
"Name...");
gtk_box_pack_start(GTK_BOX(hbox), dialog->name_entry, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox), dialog->name_entry, TRUE, TRUE, 0);
dialog->qty_entry = hildon_entry_new(HILDON_SIZE_AUTO); dialog->qty_entry = hildon_entry_new(HILDON_SIZE_AUTO);

View file

@ -31,30 +31,24 @@ G_BEGIN_DECLS
EOM_TYPE_NEW_ITEM_DIALOG, \ EOM_TYPE_NEW_ITEM_DIALOG, \
EomNewItemDialogClass)) EomNewItemDialogClass))
typedef struct _EomNewItemDialog EomNewItemDialog; typedef struct
typedef struct _EomNewItemDialogClass EomNewItemDialogClass;
struct _EomNewItemDialogClass
{ {
GtkDialogClass parent_class; GtkDialogClass parent_class;
}; } EomNewItemDialogClass;
struct _EomNewItemDialog typedef struct
{ {
GtkDialog parent; GtkDialog parent;
GtkWidget *name_entry; GtkWidget *name_entry;
GtkWidget *qty_entry; GtkWidget *qty_entry;
}; } EomNewItemDialog;
const gchar *eom_new_item_dialog_get_name(EomNewItemDialog*);
gint eom_new_item_dialog_get_total_qty(EomNewItemDialog*);
GType eom_new_item_dialog_get_type(void); GType eom_new_item_dialog_get_type(void);
GtkWidget *eom_new_item_dialog_new(void); GtkWidget *eom_new_item_dialog_new(void);
const gchar *eom_new_item_dialog_get_name(EomNewItemDialog *dialog);
gint eom_new_item_dialog_get_total_qty(EomNewItemDialog *dialog);
G_END_DECLS G_END_DECLS
#endif /* __EOM_NEW_ITEM_DIALOG_H__ */ #endif /* __EOM_NEW_ITEM_DIALOG_H__ */

View file

@ -1,9 +1,11 @@
#include <hildon/hildon.h> #include <hildon/hildon.h>
#include <stdlib.h> #include <stdlib.h>
#include "interface.h"
#include "eom.h"
gchar *eom_get_data_file(void) #include "eom.h"
#include "interface.h"
gchar *
eom_get_data_file(void)
{ {
static gchar *filedir = NULL; static gchar *filedir = NULL;
@ -15,7 +17,8 @@ gchar *eom_get_data_file(void)
return filedir; return filedir;
} }
gchar *eom_get_config_dir(void) gchar *
eom_get_config_dir(void)
{ {
static gchar *filedir = NULL; static gchar *filedir = NULL;
@ -29,11 +32,8 @@ gchar *eom_get_config_dir(void)
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
hildon_gtk_init(&argc, &argv); hildon_gtk_init(&argc, &argv);
g_set_application_name("Eye on Manga"); g_set_application_name("Eye on Manga");
interface_show_main_window(); interface_show_main_window();
gtk_main(); gtk_main();
return 0; return 0;

View file

@ -1,2 +1,7 @@
#ifndef __EOM_H__
#define __EOM_H__
gchar *eom_get_data_file(void); gchar *eom_get_data_file(void);
gchar *eom_get_config_dir(void); gchar *eom_get_config_dir(void);
#endif /* __EOM_H__ */