diff --git a/src/.#eom.h b/src/.#eom.h new file mode 120000 index 0000000..0b869d0 --- /dev/null +++ b/src/.#eom.h @@ -0,0 +1 @@ +tom@tom-laptop.14670:1287677918 \ No newline at end of file diff --git a/src/Makefile b/src/Makefile index fdd6c2d..8b0c154 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,15 +1,15 @@ CFLAGS=`pkg-config hildon-1 sqlite3 --cflags --libs` all: - $(CC) -Wall -Wextra -pedantic \ - collections.c \ + $(CC) -Wall -pedantic \ + eom.c \ interface.c \ - c-main-window.c \ - c-edit-window.c \ - c-new-item-dialog.c \ + eom-main-window.c \ + eom-edit-window.c \ + eom-new-item-dialog.c \ data.c \ $(CFLAGS) \ - -o collections + -o eye-on-manga .PHONY: check-syntax check-syntax: diff --git a/src/c-edit-window.h b/src/c-edit-window.h deleted file mode 100644 index e63d30e..0000000 --- a/src/c-edit-window.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef __C_EDIT_WINDOW_H__ -#define __C_EDIT_WINDOW_H__ - -#include - -G_BEGIN_DECLS - -#define C_TYPE_EDIT_WINDOW \ - (c_edit_window_get_type()) - -#define C_EDIT_WINDOW(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - C_TYPE_EDIT_WINDOW, \ - CEditWindow)) - -#define C_EDIT_WINDOW_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - C_TYPE_EDIT_WINDOW, \ - CEditWindowClass)) - -#define C_IS_EDIT_WINDOW(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - C_TYPE_EDIT_WINDOW)) - -#define C_IS_EDIT_WINDOW_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - C_TYPE_EDIT_WINDOW)) - -#define C_EDIT_WINDOW_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - C_TYPE_EDIT_WINDOW, \ - CEditWindowClass)) - -typedef struct _CEditWindow CEditWindow; -typedef struct _CEditWindowClass CEditWindowClass; - -struct _CEditWindowClass -{ - HildonStackableWindowClass parent_class; -}; - -struct _CEditWindow -{ - HildonStackableWindow parent; - - GtkWidget *name_label; - GtkWidget *have_label; - GtkWidget *total_label; - - gint collection_id; -}; - -GType c_edit_window_get_type(void); - -GtkWidget *c_edit_window_new(gint collection_id); - -G_END_DECLS - -#endif /* __C_EDIT_WINDOW_H__ */ diff --git a/src/c-main-window.h b/src/c-main-window.h deleted file mode 100644 index 2b9ea1c..0000000 --- a/src/c-main-window.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef __C_MAIN_WINDOW_H__ -#define __C_MAIN_WINDOW_H__ - -#include - -G_BEGIN_DECLS - -#define C_TYPE_MAIN_WINDOW \ - (c_main_window_get_type()) - -#define C_MAIN_WINDOW(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - C_TYPE_MAIN_WINDOW, \ - CMainWindow)) - -#define C_MAIN_WINDOW_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - C_TYPE_MAIN_WINDOW, \ - CMainWindowClass)) - -#define C_IS_MAIN_WINDOW(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - C_TYPE_MAIN_WINDOW)) - -#define C_IS_MAIN_WINDOW_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - C_TYPE_MAIN_WINDOW)) - -#define C_MAIN_WINDOW_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - C_TYPE_MAIN_WINDOW, \ - CMainWindowClass)) - -typedef struct _CMainWindow CMainWindow; -typedef struct _CMainWindowClass CMainWindowClass; - -struct _CMainWindowClass -{ - HildonStackableWindowClass parent_class; -}; - -struct _CMainWindow -{ - HildonStackableWindow parent; - - GtkTreeIter iter; - GtkListStore *store; - GtkTreeSelection *selection; - - GtkWidget *add_button; - GtkWidget *remove_button; - GtkWidget *edit_button; -}; - -GType c_main_window_get_type(void); - -GtkWidget *c_main_window_new(void); - -void c_main_window_load(CMainWindow *self); -void c_main_window_add_line(CMainWindow *window, - gint id, - const gchar *name, - gint current_qty, - gint total_qty); -void c_main_window_set_no_select(CMainWindow *self); -void c_main_window_set_has_select(CMainWindow *self); - -G_END_DECLS - -#endif /* __C_MAIN_WINDOW_H__ */ diff --git a/src/c-new-item-dialog.h b/src/c-new-item-dialog.h deleted file mode 100644 index 2d83f71..0000000 --- a/src/c-new-item-dialog.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef __C_NEW_ITEM_DIALOG_H__ -#define __C_NEW_ITEM_DIALOG_H__ - -#include - -G_BEGIN_DECLS - -#define C_TYPE_NEW_ITEM_DIALOG \ - (c_new_item_dialog_get_type()) - -#define C_NEW_ITEM_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ - C_TYPE_NEW_ITEM_DIALOG, \ - CNewItemDialog)) - -#define C_NEW_ITEM_DIALOG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST ((klass), \ - C_TYPE_NEW_ITEM_DIALOG, \ - CNewItemDialogClass)) - -#define C_IS_NEW_ITEM_DIALOG(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ - C_TYPE_NEW_ITEM_DIALOG)) - -#define C_IS_NEW_ITEM_DIALOG_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_TYPE ((klass), \ - C_TYPE_NEW_ITEM_DIALOG)) - -#define C_NEW_ITEM_DIALOG_GET_CLASS(obj) \ - (G_TYPE_INSTANCE_GET_CLASS ((obj), \ - C_TYPE_NEW_ITEM_DIALOG, \ - CNewItemDialogClass)) - -typedef struct _CNewItemDialog CNewItemDialog; -typedef struct _CNewItemDialogClass CNewItemDialogClass; - -struct _CNewItemDialogClass -{ - GtkDialogClass parent_class; -}; - -struct _CNewItemDialog -{ - GtkDialog parent; - - GtkWidget *name_entry; - GtkWidget *qty_entry; -}; - -GType c_new_item_dialog_get_type(void); - -GtkWidget *c_new_item_dialog_new(void); - -const gchar *c_new_item_dialog_get_name(CNewItemDialog *dialog); - -gint c_new_item_dialog_get_total_qty(CNewItemDialog *dialog); - -G_END_DECLS - -#endif /* __C_NEW_ITEM_DIALOG_H__ */ diff --git a/src/collections.h b/src/collections.h deleted file mode 100644 index b3f9240..0000000 --- a/src/collections.h +++ /dev/null @@ -1,2 +0,0 @@ -gchar *collections_get_data_file(void); -gchar *collections_get_config_dir(void); diff --git a/src/data.c b/src/data.c index e3c0703..55fea88 100644 --- a/src/data.c +++ b/src/data.c @@ -6,41 +6,41 @@ #include #include #include -#include "collections.h" +#include "eom.h" -static gboolean data_check_and_create_database(gchar *data_file); -static gint data_create_new_database(const gchar *filename); -static struct collection *data_get_collection_from_stmt(sqlite3_stmt *stmt); +static gboolean data_check_and_create_database(gchar *data_file); +static gint data_create_new_database(const gchar *filename); +static Manga *data_get_manga_from_statement(sqlite3_stmt *stmt); -GList *data_get_series(void) +GList *data_get_manga(void) { - sqlite3 *database; + sqlite3 *database; sqlite3_stmt *statement; - gchar *data_file; - GList *list = NULL; + gchar *data_file; + GList *list = NULL; - data_file = collections_get_data_file(); + 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 *sqlStatement = - " SELECT id, " - " name, " + int res; + const char *sql = + " SELECT id, " + " name, " " current_qty, " - " total_qty " - " FROM collection " - " ORDER BY name " - " COLLATE NOCASE "; + " total_qty " + " FROM manga " + " ORDER BY name " + " COLLATE NOCASE "; res = sqlite3_prepare_v2(database, - sqlStatement, - strlen(sqlStatement), + sql, + strlen(sql), &statement, NULL); if (res == SQLITE_OK) { while (sqlite3_step(statement) == SQLITE_ROW) { - struct collection *col = data_get_collection_from_stmt(statement); - list = g_list_append(list, (gpointer)col); + Manga *manga = data_get_manga_from_statement(statement); + list = g_list_append(list, (gpointer)manga); } } else @@ -54,30 +54,30 @@ GList *data_get_series(void) return list; } -struct collection *data_get_series_by_id(gint collection_id) +Manga *data_get_manga_by_id(gint manga_id) { - sqlite3 *database; - sqlite3_stmt *statement; - gchar *data_file; - struct collection *col = NULL; + sqlite3 *database; + sqlite3_stmt *statement; + gchar *data_file; + Manga *manga = NULL; - data_file = collections_get_data_file(); + data_file = eom_get_data_file(); if (data_check_and_create_database(data_file)) { if (sqlite3_open(data_file, &database) == SQLITE_OK) { - int res; + int res; const char *sql = g_strdup_printf( - " SELECT id, " - " name, " + " SELECT id, " + " name, " " current_qty, " - " total_qty " - " FROM collection " - " WHERE id = %d ", collection_id); + " total_qty " + " FROM manga " + " WHERE id = %d ", manga_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); + manga = data_get_manga_from_statement(statement); } } sqlite3_finalize(statement); @@ -85,27 +85,27 @@ struct collection *data_get_series_by_id(gint collection_id) sqlite3_close(database); } - return col; + return manga; } -gint *data_get_items_by_collection_id(gint collection_id) +gint *data_get_volumes_by_manga_id(gint manga_id) { - gint count; - gint *volumes; - sqlite3 *database; + gint count; + gint *volumes; + sqlite3 *database; sqlite3_stmt *statement; - gchar *data_file; + gchar *data_file; - data_file = collections_get_data_file(); + data_file = eom_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); + " SELECT COUNT(number) " + " FROM volume " + " WHERE collection_id = %d ", manga_id); res = sqlite3_prepare_v2(database, sql, strlen(sql), &statement, NULL); if (res == SQLITE_OK) { @@ -117,9 +117,9 @@ gint *data_get_items_by_collection_id(gint collection_id) if (count > 0) { sql = g_strdup_printf( - " SELECT id " - " FROM items " - " WHERE collection_id = %d ", collection_id); + " SELECT number " + " FROM volume " + " WHERE collection_id = %d ", manga_id); res = sqlite3_prepare_v2(database, sql, strlen(sql), &statement, NULL); if (res == SQLITE_OK) { @@ -136,26 +136,26 @@ gint *data_get_items_by_collection_id(gint collection_id) return volumes; } -gboolean data_add_series(gchar *name, gint total_qty) +gboolean data_add_manga(gchar *name, gint total_qty) { - sqlite3 *database; + sqlite3 *database; sqlite3_stmt *statement; - gchar *data_file; - gboolean result; + gchar *data_file; + gboolean result; result = FALSE; - data_file = collections_get_data_file(); + 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 *sqlStatement = - g_strdup_printf("INSERT INTO collection (name, current_qty, total_qty) " - " VALUES ('%s', 0, %d)", name, total_qty); + 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, - sqlStatement, - strlen(sqlStatement), + sql, + strlen(sql), &statement, NULL); if (res == SQLITE_OK) { if (sqlite3_step(statement) == SQLITE_DONE) @@ -169,27 +169,27 @@ gboolean data_add_series(gchar *name, gint total_qty) return result; } -gboolean data_add_to_series(gint collection_id, gint count) +gboolean data_add_to_manga(gint manga_id, gint count) { - sqlite3 *database; + sqlite3 *database; sqlite3_stmt *statement; - gchar *data_file; - gboolean result; + gchar *data_file; + gboolean result; - data_file = collections_get_data_file(); + 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 *sqlStatement = - g_strdup_printf("UPDATE collection " - " SET current_qty = current_qty + %d " - " WHERE id = %d", count, collection_id); + 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, - sqlStatement, - strlen(sqlStatement), + sql, + strlen(sql), &statement, NULL); if (res == SQLITE_OK) { if (sqlite3_step(statement) == SQLITE_DONE) @@ -220,8 +220,8 @@ static gint data_create_new_database(const gchar *filename) char *zErrMsg = 0; int rc; - if (access(collections_get_config_dir(), R_OK) == -1) { - if (mkdir(collections_get_config_dir(), S_IRWXU) == -1) + if (access(eom_get_config_dir(), R_OK) == -1) { + if (mkdir(eom_get_config_dir(), S_IRWXU) == -1) g_printerr("Can't create directory: %s\n", strerror(errno)); } @@ -235,30 +235,30 @@ static gint data_create_new_database(const gchar *filename) } /* Create collections table */ - rc = sqlite3_exec(db, "CREATE TABLE collection(" + rc = sqlite3_exec(db, "CREATE TABLE manga(" "id INTEGER PRIMARY KEY," "name VARCHAR(100)," "current_qty INTEGER," "total_qty INTEGER" ")", NULL, NULL, &zErrMsg); if (rc != SQLITE_OK) { - g_printerr("Can't create collection table: %s\n", zErrMsg); + g_printerr("Can't create manga table: %s\n", zErrMsg); sqlite3_free(zErrMsg); sqlite3_close(db); return -1; } /* Create items table */ - rc = sqlite3_exec(db, "CREATE TABLE item(" - "collection_id INTEGER," - "id INTEGER," - "title VARCHAR(100)," - "PRIMARY KEY(collection_id, id)," - "FOREIGN KEY(collection_id)" - " REFERENCES collection(id)" - ")", NULL, NULL, &zErrMsg); + rc = sqlite3_exec(db, + " CREATE TABLE volume( " + " collection_id INTEGER, " + " id INTEGER, " + " PRIMARY KEY(collection_id, id), " + " FOREIGN KEY(collection_id) " + " REFERENCES collection(id)) ", + NULL, NULL, &zErrMsg); if (rc != SQLITE_OK) { - g_printerr("Can't create item table: %s\n", zErrMsg); + g_printerr("Can't create volume table: %s\n", zErrMsg); sqlite3_free(zErrMsg); sqlite3_close(db); return -1; @@ -268,15 +268,15 @@ static gint data_create_new_database(const gchar *filename) return 0; } -static struct collection *data_get_collection_from_stmt(sqlite3_stmt *stmt) +static Manga *data_get_manga_from_statement(sqlite3_stmt *stmt) { - struct collection *collection = - (struct collection *)malloc(sizeof(struct collection)); + Manga *manga = + (Manga *)malloc(sizeof(Manga)); - 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); + manga->id = sqlite3_column_int(stmt, 0); + manga->name = g_strdup(sqlite3_column_text(stmt, 1)); + manga->current_qty = sqlite3_column_int(stmt, 2); + manga->total_qty = sqlite3_column_int(stmt, 3); - return collection; + return manga; } diff --git a/src/data.h b/src/data.h index c97e228..2152da0 100644 --- a/src/data.h +++ b/src/data.h @@ -1,6 +1,8 @@ #include -struct collection +typedef struct _manga Manga; + +struct _manga { int id; int current_qty; @@ -8,8 +10,8 @@ struct collection char *name; }; -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_to_series(gint id, gint count); +GList *data_get_manga(void); +Manga *data_get_manga_by_id(gint manga_id); +gint *data_get_volumes_by_manga_id(gint manga_id); +gboolean data_add_manga(gchar *name, gint total_qty); +gboolean data_add_to_manga(gint id, gint count); diff --git a/src/c-edit-window.c b/src/eom-edit-window.c similarity index 59% rename from src/c-edit-window.c rename to src/eom-edit-window.c index 999daf7..6776569 100644 --- a/src/c-edit-window.c +++ b/src/eom-edit-window.c @@ -1,35 +1,35 @@ -#include "c-edit-window.h" +#include "eom-edit-window.h" #include #include #include "data.h" enum { - C_EDIT_PROP_0, - C_EDIT_PROP_CID + EOM_EDIT_PROP_0, + EOM_EDIT_PROP_CID }; -static void c_edit_window_set_collection_id(CEditWindow *self, - gint collection_id); +static void eom_edit_window_set_manga_id(EomEditWindow *self, + gint manga_id); -G_DEFINE_TYPE(CEditWindow, c_edit_window, HILDON_TYPE_STACKABLE_WINDOW) +G_DEFINE_TYPE(EomEditWindow, eom_edit_window, HILDON_TYPE_STACKABLE_WINDOW) -GtkWidget *c_edit_window_new(gint collection_id) +GtkWidget *eom_edit_window_new(gint manga_id) { - g_print("1: %d\n", collection_id); - return g_object_new(C_TYPE_EDIT_WINDOW, "collection-id", collection_id, NULL); + g_print("1: %d\n", manga_id); + return g_object_new(EOM_TYPE_EDIT_WINDOW, "manga-id", manga_id, NULL); } -static void c_edit_window_set_property(GObject *object, - guint property_id, - const GValue *value, - GParamSpec *pspec) +static void eom_edit_window_set_property(GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) { - CEditWindow *self = C_EDIT_WINDOW(object); + EomEditWindow *self = EOM_EDIT_WINDOW(object); switch (property_id) { - case C_EDIT_PROP_CID: + case EOM_EDIT_PROP_CID: g_print("2: %d\n", g_value_get_int(value)); - self->collection_id = g_value_get_int(value); + self->manga_id = g_value_get_int(value); break; default: /* We don't have any other properties */ @@ -38,16 +38,16 @@ static void c_edit_window_set_property(GObject *object, } } -static void c_edit_window_get_property(GObject *object, - guint property_id, - GValue *value, - GParamSpec *pspec) +static void eom_edit_window_get_property(GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) { - CEditWindow *self = C_EDIT_WINDOW(object); + EomEditWindow *self = EOM_EDIT_WINDOW(object); switch (property_id) { - case C_EDIT_PROP_CID: - g_value_set_int(value, self->collection_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); @@ -55,27 +55,27 @@ static void c_edit_window_get_property(GObject *object, } } -static void c_edit_window_class_init(CEditWindowClass *klass) +static void eom_edit_window_class_init(EomEditWindowClass *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; + gobject_class->set_property = eom_edit_window_set_property; + gobject_class->get_property = eom_edit_window_get_property; - pspec = g_param_spec_int("collection-id", - "ID for the collection", - "Set the collection-id", + pspec = g_param_spec_int("manga-id", + "ID of the manga", + "Set the manga-id", 0, INT_MAX, 0, G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE); g_object_class_install_property(gobject_class, - C_EDIT_PROP_CID, + EOM_EDIT_PROP_CID, pspec); } -static void c_edit_window_init(CEditWindow *self) +static void eom_edit_window_init(EomEditWindow *self) { GtkWidget *pannablearea; GtkWidget *table; @@ -84,7 +84,7 @@ static void c_edit_window_init(CEditWindow *self) GtkWidget *totalclabel; GtkWidget *vbox; - g_print("3: %d\n", self->collection_id); + g_print("3: %d\n", self->manga_id); pannablearea = hildon_pannable_area_new(); g_object_set(G_OBJECT(pannablearea), @@ -131,20 +131,20 @@ static void c_edit_window_init(CEditWindow *self) GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0); } -static void c_edit_window_set_collection_id(CEditWindow *self, - gint collection_id) +static void eom_edit_window_set_manga_id(EomEditWindow *self, + gint manga_id) { - struct collection *col; - gint *items; + Manga *manga; + gint *volumes; - col = data_get_series_by_id(collection_id); - items = data_get_items_by_collection_id(collection_id); + manga = data_get_manga_by_id(manga_id); + volumes = data_get_volumes_by_manga_id(manga_id); - gtk_label_set_text(GTK_LABEL(self->name_label), col->name); + gtk_label_set_text(GTK_LABEL(self->name_label), manga->name); gtk_label_set_text(GTK_LABEL(self->have_label), - g_strdup_printf("%d", col->current_qty)); + g_strdup_printf("%d", manga->current_qty)); gtk_label_set_text(GTK_LABEL(self->total_label), - g_strdup_printf("%d", col->total_qty)); + g_strdup_printf("%d", manga->total_qty)); - g_free(col); + g_free(manga); } diff --git a/src/eom-edit-window.h b/src/eom-edit-window.h new file mode 100644 index 0000000..cecc7fb --- /dev/null +++ b/src/eom-edit-window.h @@ -0,0 +1,59 @@ +#ifndef __EOM_EDIT_WINDOW_H__ +#define __EOM_EDIT_WINDOW_H__ + +#include + +G_BEGIN_DECLS + +#define EOM_TYPE_EDIT_WINDOW \ + (eom_edit_window_get_type()) + +#define EOM_EDIT_WINDOW(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + EOM_TYPE_EDIT_WINDOW, \ + EomEditWindow)) + +#define EOM_EDIT_WINDOW_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + EOM_TYPE_EDIT_WINDOW, \ + EomEditWindowClass)) + +#define EOM_IS_EDIT_WINDOW(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + EOM_TYPE_EDIT_WINDOW)) + +#define EOM_IS_EDIT_WINDOW_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), \ + EOM_TYPE_EDIT_WINDOW)) + +#define EOM_EDIT_WINDOW_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + EOM_TYPE_EDIT_WINDOW, \ + EomEditWindowClass)) + +typedef struct _EomEditWindow EomEditWindow; +typedef struct _EomEditWindowClass EomEditWindowClass; + +struct _EomEditWindowClass +{ + HildonStackableWindowClass parent_class; +}; + +struct _EomEditWindow +{ + HildonStackableWindow parent; + + GtkWidget *name_label; + GtkWidget *have_label; + GtkWidget *total_label; + + gint manga_id; +}; + +GType eom_edit_window_get_type(void); + +GtkWidget *eom_edit_window_new(gint manga_id); + +G_END_DECLS + +#endif /* __EOM_EDIT_WINDOW_H__ */ diff --git a/src/c-main-window.c b/src/eom-main-window.c similarity index 72% rename from src/c-main-window.c rename to src/eom-main-window.c index e1487dc..8bd96e4 100644 --- a/src/c-main-window.c +++ b/src/eom-main-window.c @@ -1,13 +1,13 @@ -#include "c-main-window.h" +#include "eom-main-window.h" #include #include #include #include -#include "c-new-item-dialog.h" +#include "eom-new-item-dialog.h" #include "data.h" #include "interface.h" -G_DEFINE_TYPE(CMainWindow, c_main_window, HILDON_TYPE_STACKABLE_WINDOW) +G_DEFINE_TYPE(EomMainWindow, eom_main_window, HILDON_TYPE_STACKABLE_WINDOW) enum { COL_ID = 0, @@ -17,44 +17,45 @@ enum { NUM_COLS }; -static void c_main_window_add_menu(CMainWindow *window); -static void c_main_window_on_new(GtkWidget *widget, GtkWindow *window); -static void c_main_window_on_selection_changed(GtkTreeSelection *selection, - gpointer user_data); -static void c_main_window_on_add_clicked(GtkWidget *widget, gpointer user_data); -static void c_main_window_on_remove_clicked(GtkWidget *widget, +static void eom_main_window_add_menu(EomMainWindow *window); +static void eom_main_window_on_new(GtkWidget *widget, GtkWindow *window); +static void eom_main_window_on_selection_changed(GtkTreeSelection *selection, + gpointer user_data); +static void eom_main_window_on_add_clicked(GtkWidget *widget, + gpointer user_data); +static void eom_main_window_on_remove_clicked(GtkWidget *widget, + gpointer user_data); +static void eom_main_window_on_edit_clicked(GtkWidget *widget, gpointer user_data); -static void c_main_window_on_edit_clicked(GtkWidget *widget, - gpointer user_data); -GtkWidget *c_main_window_new(void) +GtkWidget *eom_main_window_new(void) { - return g_object_new(C_TYPE_MAIN_WINDOW, NULL); + return g_object_new(EOM_TYPE_MAIN_WINDOW, NULL); } -void c_main_window_load(CMainWindow *self) +void eom_main_window_load(EomMainWindow *self) { GList *list; gtk_list_store_clear(self->store); - list = data_get_series(); + list = data_get_manga(); while (list) { - struct collection *col = list->data; - c_main_window_add_line(self, col->id, col->name, - col->current_qty, col->total_qty); + Manga *manga = list->data; + eom_main_window_add_line(self, manga->id, manga->name, + manga->current_qty, manga->total_qty); list = g_list_next(list); } g_list_free_1(list); } -void c_main_window_add_line(CMainWindow *window, - gint id, - const gchar *name, - gint current_qty, - gint total_qty) +void eom_main_window_add_line(EomMainWindow *window, + gint id, + const gchar *name, + gint current_qty, + gint total_qty) { gtk_list_store_append(window->store, &window->iter); gtk_list_store_set(window ->store, &window->iter, @@ -65,7 +66,7 @@ void c_main_window_add_line(CMainWindow *window, -1); } -void c_main_window_set_no_select(CMainWindow *self) +void eom_main_window_set_no_select(EomMainWindow *self) { if (GTK_IS_WIDGET(self->add_button)) gtk_widget_set_sensitive(GTK_WIDGET(self->add_button), FALSE); @@ -73,7 +74,7 @@ void c_main_window_set_no_select(CMainWindow *self) gtk_widget_set_sensitive(GTK_WIDGET(self->remove_button), FALSE); } -void c_main_window_set_has_select(CMainWindow *self) +void eom_main_window_set_has_select(EomMainWindow *self) { if (GTK_IS_WIDGET(self->add_button)) gtk_widget_set_sensitive(GTK_WIDGET(self->add_button), TRUE); @@ -81,10 +82,10 @@ void c_main_window_set_has_select(CMainWindow *self) gtk_widget_set_sensitive(GTK_WIDGET(self->remove_button), TRUE); } -static void c_main_window_class_init(CMainWindowClass *class) +static void eom_main_window_class_init(EomMainWindowClass *class) {} -static void c_main_window_init(CMainWindow *window) +static void eom_main_window_init(EomMainWindow *window) { GtkCellRenderer *renderer; GtkWidget *view; @@ -96,7 +97,7 @@ static void c_main_window_init(CMainWindow *window) index = -1; - c_main_window_add_menu(window); + eom_main_window_add_menu(window); g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL); g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL); @@ -121,7 +122,7 @@ static void c_main_window_init(CMainWindow *window) window->selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view)); g_signal_connect(window->selection, "changed", - G_CALLBACK(c_main_window_on_selection_changed), + G_CALLBACK(eom_main_window_on_selection_changed), (gpointer)window); renderer = gtk_cell_renderer_text_new(); @@ -173,7 +174,7 @@ static void c_main_window_init(CMainWindow *window) "Add", NULL); g_signal_connect(window->add_button, "clicked", - G_CALLBACK(c_main_window_on_add_clicked), + G_CALLBACK(eom_main_window_on_add_clicked), (gpointer)window); gtk_box_pack_start(GTK_BOX(hbuttonbox), window->add_button, FALSE, FALSE, 0); @@ -184,7 +185,7 @@ static void c_main_window_init(CMainWindow *window) "Edit", NULL); g_signal_connect(window->edit_button, "clicked", - G_CALLBACK(c_main_window_on_edit_clicked), + G_CALLBACK(eom_main_window_on_edit_clicked), (gpointer)window); gtk_box_pack_start(GTK_BOX(hbuttonbox), window->edit_button, FALSE, FALSE, 0); @@ -195,17 +196,17 @@ static void c_main_window_init(CMainWindow *window) "Remove", NULL); g_signal_connect(window->remove_button, "clicked", - G_CALLBACK(c_main_window_on_remove_clicked), + G_CALLBACK(eom_main_window_on_remove_clicked), (gpointer)window); gtk_box_pack_start(GTK_BOX(hbuttonbox), window->remove_button, FALSE, FALSE, 0); gtk_container_add(GTK_CONTAINER(window), vbox); - c_main_window_set_no_select(window); + eom_main_window_set_no_select(window); } -static void c_main_window_add_menu(CMainWindow *window) +static void eom_main_window_add_menu(EomMainWindow *window) { GtkWidget *appmenu; GtkWidget *new_button; @@ -213,10 +214,10 @@ static void c_main_window_add_menu(CMainWindow *window) appmenu = hildon_app_menu_new(); new_button = hildon_gtk_button_new(HILDON_SIZE_AUTO); - gtk_button_set_label(GTK_BUTTON(new_button), "New Item"); + gtk_button_set_label(GTK_BUTTON(new_button), "New Manga"); g_signal_connect_after(new_button, "clicked", - G_CALLBACK(c_main_window_on_new), + G_CALLBACK(eom_main_window_on_new), GTK_WINDOW(window)); hildon_app_menu_append(HILDON_APP_MENU(appmenu), GTK_BUTTON(new_button)); @@ -226,7 +227,7 @@ static void c_main_window_add_menu(CMainWindow *window) HILDON_APP_MENU(appmenu)); } -static void c_main_window_on_new(GtkWidget *widget, GtkWindow *window) +static void eom_main_window_on_new(GtkWidget *widget, GtkWindow *window) { GtkWidget *dialog; gint result; @@ -239,42 +240,42 @@ static void c_main_window_on_new(GtkWidget *widget, GtkWindow *window) if (result == GTK_RESPONSE_OK) { const gchar *tmp; - tmp = c_new_item_dialog_get_name(C_NEW_ITEM_DIALOG(dialog)); + tmp = eom_new_item_dialog_get_name(EOM_NEW_ITEM_DIALOG(dialog)); name = (gchar *)malloc(strlen(tmp) + 1); strcpy(name, tmp); strcat(name, "\0"); - total_qty = c_new_item_dialog_get_total_qty(C_NEW_ITEM_DIALOG(dialog)); + total_qty = eom_new_item_dialog_get_total_qty(EOM_NEW_ITEM_DIALOG(dialog)); gtk_widget_destroy(dialog); } if (name != NULL) { - if (data_add_series(name, total_qty)) - c_main_window_load(C_MAIN_WINDOW(window)); + if (data_add_manga(name, total_qty)) + eom_main_window_load(EOM_MAIN_WINDOW(window)); } } -static void c_main_window_on_selection_changed(GtkTreeSelection *selection, +static void eom_main_window_on_selection_changed(GtkTreeSelection *selection, gpointer user_data) { gint count; - CMainWindow *self = (CMainWindow *)user_data; + EomMainWindow *self = (EomMainWindow *)user_data; count = gtk_tree_selection_count_selected_rows(selection); if (count == 0) - c_main_window_set_no_select(self); + eom_main_window_set_no_select(self); else - c_main_window_set_has_select(self); + eom_main_window_set_has_select(self); } -static void c_main_window_on_add_clicked(GtkWidget *widget, gpointer user_data) +static void eom_main_window_on_add_clicked(GtkWidget *widget, gpointer user_data) { - CMainWindow *self; + EomMainWindow *self; gint count; - self = (CMainWindow *)user_data; + self = (EomMainWindow *)user_data; count = gtk_tree_selection_count_selected_rows(self->selection); if (count > 0) { @@ -286,7 +287,7 @@ static void c_main_window_on_add_clicked(GtkWidget *widget, gpointer user_data) gtk_tree_model_get(model, &self->iter, COL_ID, &id, -1); gtk_tree_model_get(model, &self->iter, COL_CURRENT, ¤t_count, -1); - if (data_add_to_series(id, 1)) + if (data_add_to_manga(id, 1)) gtk_list_store_set(GTK_LIST_STORE(self->store), &self->iter, COL_CURRENT, current_count + 1, -1); @@ -294,13 +295,13 @@ static void c_main_window_on_add_clicked(GtkWidget *widget, gpointer user_data) } } -static void c_main_window_on_remove_clicked(GtkWidget *widget, +static void eom_main_window_on_remove_clicked(GtkWidget *widget, gpointer user_data) { - CMainWindow *self; + EomMainWindow *self; gint count; - self = (CMainWindow *)user_data; + self = (EomMainWindow *)user_data; count = gtk_tree_selection_count_selected_rows(self->selection); if (count > 0) { @@ -313,19 +314,19 @@ static void c_main_window_on_remove_clicked(GtkWidget *widget, gtk_tree_model_get(model, &self->iter, COL_ID, &id, -1); gtk_tree_model_get(model, &self->iter, COL_CURRENT, ¤t_count, -1); - if (current_count > 0 && data_add_to_series(id, -1)) + if (current_count > 0 && data_add_to_manga(id, -1)) gtk_list_store_set(GTK_LIST_STORE(self->store), &self->iter, COL_CURRENT, current_count - 1, -1); } } } -static void c_main_window_on_edit_clicked(GtkWidget *widget, +static void eom_main_window_on_edit_clicked(GtkWidget *widget, gpointer user_data) { - CMainWindow *self; + EomMainWindow *self; - self = (CMainWindow *)user_data; + self = (EomMainWindow *)user_data; /* TODO: Place more code here */ interface_show_edit_window(); diff --git a/src/eom-main-window.h b/src/eom-main-window.h new file mode 100644 index 0000000..fe82c70 --- /dev/null +++ b/src/eom-main-window.h @@ -0,0 +1,70 @@ +#ifndef __EOM_MAIN_WINDOW_H__ +#define __EOM_MAIN_WINDOW_H__ + +#include + +G_BEGIN_DECLS + +#define EOM_TYPE_MAIN_WINDOW \ + (eom_main_window_get_type()) + +#define EOM_MAIN_WINDOW(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + EOM_TYPE_MAIN_WINDOW, \ + EomMainWindow)) + +#define EOM_MAIN_WINDOW_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + EOM_TYPE_MAIN_WINDOW, \ + EomMainWindowClass)) + +#define EOM_IS_MAIN_WINDOW(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + EOM_TYPE_MAIN_WINDOW)) + +#define EOM_IS_MAIN_WINDOW_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), \ + EOM_TYPE_MAIN_WINDOW)) + +#define EOM_MAIN_WINDOW_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + EOM_TYPE_MAIN_WINDOW, \ + EomMainWindowClass)) + +typedef struct _EomMainWindow EomMainWindow; +typedef struct _EomMainWindowClass EomMainWindowClass; + +struct _EomMainWindowClass +{ + HildonStackableWindowClass parent_class; +}; + +struct _EomMainWindow +{ + HildonStackableWindow parent; + + GtkTreeIter iter; + GtkListStore *store; + GtkTreeSelection *selection; + + GtkWidget *add_button; + GtkWidget *remove_button; + GtkWidget *edit_button; +}; + +GType eom_main_window_get_type(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); +void eom_main_window_set_no_select(EomMainWindow *self); +void eom_main_window_set_has_select(EomMainWindow *self); + +G_END_DECLS + +#endif /* __EOM_MAIN_WINDOW_H__ */ diff --git a/src/c-new-item-dialog.c b/src/eom-new-item-dialog.c similarity index 70% rename from src/c-new-item-dialog.c rename to src/eom-new-item-dialog.c index 76b0686..aa8c169 100644 --- a/src/c-new-item-dialog.c +++ b/src/eom-new-item-dialog.c @@ -1,29 +1,29 @@ -#include "c-new-item-dialog.h" +#include "eom-new-item-dialog.h" #include #include #include -G_DEFINE_TYPE(CNewItemDialog, c_new_item_dialog, GTK_TYPE_DIALOG) +G_DEFINE_TYPE(EomNewItemDialog, eom_new_item_dialog, GTK_TYPE_DIALOG) -GtkWidget *c_new_item_dialog_new(void) +GtkWidget *eom_new_item_dialog_new(void) { - return g_object_new(C_TYPE_NEW_ITEM_DIALOG, NULL); + return g_object_new(EOM_TYPE_NEW_ITEM_DIALOG, NULL); } -const gchar *c_new_item_dialog_get_name(CNewItemDialog *dialog) +const gchar *eom_new_item_dialog_get_name(EomNewItemDialog *dialog) { return hildon_entry_get_text(HILDON_ENTRY(dialog->name_entry)); } -gint c_new_item_dialog_get_total_qty(CNewItemDialog *dialog) +gint eom_new_item_dialog_get_total_qty(EomNewItemDialog *dialog) { return atoi(hildon_entry_get_text(HILDON_ENTRY(dialog->qty_entry))); } -static void c_new_item_dialog_class_init(CNewItemDialogClass *class) +static void eom_new_item_dialog_class_init(EomNewItemDialogClass *class) {} -static void c_new_item_dialog_init(CNewItemDialog *dialog) +static void eom_new_item_dialog_init(EomNewItemDialog *dialog) { GtkWidget *content_area; GtkWidget *hbox; diff --git a/src/eom-new-item-dialog.h b/src/eom-new-item-dialog.h new file mode 100644 index 0000000..b77a93f --- /dev/null +++ b/src/eom-new-item-dialog.h @@ -0,0 +1,60 @@ +#ifndef __EOM_NEW_ITEM_DIALOG_H__ +#define __EOM_NEW_ITEM_DIALOG_H__ + +#include + +G_BEGIN_DECLS + +#define EOM_TYPE_NEW_ITEM_DIALOG \ + (eom_new_item_dialog_get_type()) + +#define EOM_NEW_ITEM_DIALOG(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST ((obj), \ + EOM_TYPE_NEW_ITEM_DIALOG, \ + EomNewItemDialog)) + +#define EOM_NEW_ITEM_DIALOG_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_CAST ((klass), \ + EOM_TYPE_NEW_ITEM_DIALOG, \ + EomNewItemDialogClass)) + +#define EOM_IS_NEW_ITEM_DIALOG(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE ((obj), \ + EOM_TYPE_NEW_ITEM_DIALOG)) + +#define EOM_IS_NEW_ITEM_DIALOG_CLASS(klass) \ + (G_TYPE_CHECK_CLASS_TYPE ((klass), \ + EOM_TYPE_NEW_ITEM_DIALOG)) + +#define EOM_NEW_ITEM_DIALOG_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS ((obj), \ + EOM_TYPE_NEW_ITEM_DIALOG, \ + EomNewItemDialogClass)) + +typedef struct _EomNewItemDialog EomNewItemDialog; +typedef struct _EomNewItemDialogClass EomNewItemDialogClass; + +struct _EomNewItemDialogClass +{ + GtkDialogClass parent_class; +}; + +struct _EomNewItemDialog +{ + GtkDialog parent; + + GtkWidget *name_entry; + GtkWidget *qty_entry; +}; + +GType eom_new_item_dialog_get_type(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 + +#endif /* __EOM_NEW_ITEM_DIALOG_H__ */ diff --git a/src/collections.c b/src/eom.c similarity index 53% rename from src/collections.c rename to src/eom.c index 56c75b7..1b4a12e 100644 --- a/src/collections.c +++ b/src/eom.c @@ -1,26 +1,26 @@ #include #include #include "interface.h" -#include "collections.h" +#include "eom.h" -gchar *collections_get_data_file(void) +gchar *eom_get_data_file(void) { static gchar *filedir = NULL; if (filedir == NULL) { - filedir = g_strdup_printf("%s/collections.db", - collections_get_config_dir()); + filedir = g_strdup_printf("%s/eye-on-manga.db", + eom_get_config_dir()); } return filedir; } -gchar *collections_get_config_dir(void) +gchar *eom_get_config_dir(void) { static gchar *filedir = NULL; if (filedir == NULL) { - filedir = g_strdup_printf("%s/.collections", getenv("HOME")); + filedir = g_strdup_printf("%s/.eom", getenv("HOME")); } return filedir; @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) { hildon_gtk_init(&argc, &argv); - g_set_application_name("Collections"); + g_set_application_name("Eye on Manga"); interface_show_main_window(); diff --git a/src/eom.h b/src/eom.h new file mode 100644 index 0000000..155cd60 --- /dev/null +++ b/src/eom.h @@ -0,0 +1,2 @@ +gchar *eom_get_data_file(void); +gchar *eom_get_config_dir(void); diff --git a/src/eye-on-manga b/src/eye-on-manga new file mode 100755 index 0000000..a5c5b9a Binary files /dev/null and b/src/eye-on-manga differ diff --git a/src/interface.c b/src/interface.c index 9d1b0f1..af07d7a 100644 --- a/src/interface.c +++ b/src/interface.c @@ -1,18 +1,18 @@ #include #include "interface.h" -#include "c-main-window.h" -#include "c-edit-window.h" -#include "c-new-item-dialog.h" +#include "eom-main-window.h" +#include "eom-edit-window.h" +#include "eom-new-item-dialog.h" #include "data.h" void interface_show_main_window(void) { GtkWidget *window; - window = c_main_window_new(); + window = eom_main_window_new(); gtk_widget_show_all(window); - c_main_window_load(C_MAIN_WINDOW(window)); + eom_main_window_load(EOM_MAIN_WINDOW(window)); } void interface_show_edit_window(void) @@ -22,7 +22,7 @@ void interface_show_edit_window(void) stack = hildon_window_stack_get_default(); - window = c_edit_window_new(1); + window = eom_edit_window_new(1); hildon_window_stack_push(stack, HILDON_STACKABLE_WINDOW(window), NULL); gtk_widget_show_all(window); } @@ -31,7 +31,7 @@ GtkWidget *interface_show_new_item_dialog(GtkWindow *window) { GtkWidget *dialog; - dialog = c_new_item_dialog_new(); + dialog = eom_new_item_dialog_new(); gtk_widget_show_all(dialog); gtk_window_set_transient_for(GTK_WINDOW(dialog), window); diff --git a/src/interface.h b/src/interface.h index 0bd37ad..1832b05 100644 --- a/src/interface.h +++ b/src/interface.h @@ -1,4 +1,5 @@ #include void interface_show_main_window(void); +void interface_show_edit_window(void); GtkWidget *interface_show_new_item_dialog(GtkWindow *window);