Restyle, reindent, refactor (a little)
This commit is contained in:
parent
8e49f0c56e
commit
aa77d2a2f5
10 changed files with 894 additions and 983 deletions
471
src/data.c
471
src/data.c
|
@ -1,32 +1,64 @@
|
|||
#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 <gtk/gtk.h>
|
||||
#include <sqlite3.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "eom.h"
|
||||
|
||||
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);
|
||||
static GList *data_get_manga_for_query(const gchar *query);
|
||||
static gboolean check_and_create_database(gchar*);
|
||||
static gint create_new_database(const gchar*);
|
||||
static gboolean execute_non_query(const char *sql);
|
||||
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 =
|
||||
" SELECT id, "
|
||||
" name, "
|
||||
" current_qty, "
|
||||
" total_qty "
|
||||
" FROM manga "
|
||||
" ORDER BY name "
|
||||
" COLLATE NOCASE ";
|
||||
return data_get_manga_for_query(sql);
|
||||
gchar *sql =
|
||||
g_strdup_printf(" INSERT INTO manga (name, current_qty, "
|
||||
"total_qty) VALUES ('%s', 0, %d)",
|
||||
name, total_qty);
|
||||
gboolean ret = execute_non_query(sql);
|
||||
|
||||
g_free(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 =
|
||||
" SELECT id, "
|
||||
|
@ -37,348 +69,169 @@ GList *data_get_incomplete_manga(void)
|
|||
" WHERE current_qty != total_qty "
|
||||
" ORDER BY name "
|
||||
" 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;
|
||||
sqlite3_stmt *statement;
|
||||
gchar *data_file;
|
||||
GList *list = NULL;
|
||||
const char *sql =
|
||||
" SELECT id, "
|
||||
" name, "
|
||||
" current_qty, "
|
||||
" total_qty "
|
||||
" FROM manga "
|
||||
" ORDER BY name "
|
||||
" COLLATE NOCASE ";
|
||||
|
||||
data_file = eom_get_data_file();
|
||||
|
||||
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 get_manga_for_query(sql);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
Manga *data_get_manga_by_id(gint manga_id)
|
||||
Manga *
|
||||
data_get_manga_by_id(gint manga_id)
|
||||
{
|
||||
sqlite3 *database;
|
||||
sqlite3_stmt *statement;
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *stmt;
|
||||
gchar *data_file;
|
||||
Manga *manga = NULL;
|
||||
|
||||
data_file = eom_get_data_file();
|
||||
|
||||
if (data_check_and_create_database(data_file)) {
|
||||
if (sqlite3_open(data_file, &database) == SQLITE_OK) {
|
||||
if (check_and_create_database(data_file)) {
|
||||
if (sqlite3_open(data_file, &db) == SQLITE_OK) {
|
||||
int res;
|
||||
const char *sql = g_strdup_printf(
|
||||
" SELECT id, "
|
||||
char *sql =
|
||||
g_strdup_printf(" SELECT id, "
|
||||
" name, "
|
||||
" current_qty, "
|
||||
" total_qty "
|
||||
" FROM manga "
|
||||
" 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 (sqlite3_step(statement) == SQLITE_ROW) {
|
||||
manga = data_get_manga_from_statement(statement);
|
||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
manga = get_manga_from_statement(stmt);
|
||||
}
|
||||
}
|
||||
|
||||
sqlite3_finalize(statement);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
sqlite3_close(database);
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
return manga;
|
||||
}
|
||||
|
||||
void data_get_volumes_for_manga(Manga *manga)
|
||||
void
|
||||
data_get_volumes_for_manga(Manga *manga)
|
||||
{
|
||||
gint count;
|
||||
Volume *volumes;
|
||||
sqlite3 *database;
|
||||
sqlite3_stmt *statement;
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *stmt;
|
||||
gchar *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) {
|
||||
if (check_and_create_database(data_file)) {
|
||||
if (sqlite3_open(data_file, &db) == SQLITE_OK) {
|
||||
int res;
|
||||
const char *sql = g_strdup_printf(
|
||||
" SELECT COUNT(id) "
|
||||
char *sql = g_strdup_printf(" SELECT COUNT(id) "
|
||||
" 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 (sqlite3_step(statement) == SQLITE_ROW) {
|
||||
count = sqlite3_column_int(statement, 0);
|
||||
if (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
count = sqlite3_column_int(stmt, 0);
|
||||
}
|
||||
}
|
||||
|
||||
sqlite3_finalize(statement);
|
||||
sqlite3_finalize(stmt);
|
||||
volumes = calloc(sizeof(Volume), count);
|
||||
|
||||
if (count > 0) {
|
||||
sql = g_strdup_printf(
|
||||
" SELECT id, "
|
||||
sql = g_strdup_printf(" SELECT id, "
|
||||
" read "
|
||||
" 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) {
|
||||
gint i = 0;
|
||||
while (sqlite3_step(statement) == SQLITE_ROW) {
|
||||
volumes[i].number = sqlite3_column_int(statement, 0);
|
||||
volumes[i].read = sqlite3_column_int(statement, 1);
|
||||
while (sqlite3_step(stmt) == SQLITE_ROW) {
|
||||
volumes[i].number = sqlite3_column_int(stmt, 0);
|
||||
volumes[i].read = sqlite3_column_int(stmt, 1);
|
||||
|
||||
i++;
|
||||
};
|
||||
}
|
||||
|
||||
sqlite3_finalize(statement);
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
}
|
||||
sqlite3_close(database);
|
||||
sqlite3_close(db);
|
||||
}
|
||||
|
||||
manga->vol_count = count;
|
||||
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;
|
||||
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 "
|
||||
gchar *sql = g_strdup_printf(" UPDATE volume "
|
||||
" SET read = %d "
|
||||
" WHERE manga_id = %d "
|
||||
" AND id = %d ",
|
||||
read, manga_id, volume);
|
||||
gboolean ret = execute_non_query(sql);
|
||||
|
||||
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");
|
||||
g_free(sql);
|
||||
|
||||
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;
|
||||
return ret;
|
||||
}
|
||||
|
||||
gboolean data_remove_volume_from_manga(gint manga_id, gint volume)
|
||||
gboolean
|
||||
data_remove_volume_from_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(
|
||||
" DELETE FROM volume "
|
||||
char *sql = g_strdup_printf(" DELETE FROM volume "
|
||||
" WHERE manga_id = %d "
|
||||
" AND id = %d ", manga_id, volume);
|
||||
gboolean ret = execute_non_query(sql);
|
||||
|
||||
res = sqlite3_prepare_v2(database,
|
||||
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");
|
||||
g_free(sql);
|
||||
|
||||
sqlite3_finalize(statement);
|
||||
}
|
||||
else
|
||||
g_print("couldn't open database\n");
|
||||
sqlite3_close(database);
|
||||
}
|
||||
else
|
||||
g_print("couldn't check or create database\n");
|
||||
|
||||
return result;
|
||||
return ret;
|
||||
}
|
||||
|
||||
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 (data_create_new_database(data_file)) {
|
||||
if (create_new_database(data_file)) {
|
||||
g_printerr("Couldn't create a new database\n");
|
||||
|
||||
return FALSE; /* Couldn't create database, can't continue */
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gint data_create_new_database(const gchar *filename)
|
||||
static gint
|
||||
create_new_database(const gchar *filename)
|
||||
{
|
||||
sqlite3 *db;
|
||||
char *zErrMsg = 0;
|
||||
|
@ -391,6 +244,7 @@ static gint data_create_new_database(const gchar *filename)
|
|||
|
||||
/* Open database connection, create file */
|
||||
rc = sqlite3_open(filename, &db);
|
||||
|
||||
if (rc) {
|
||||
g_printerr("Can't open database: %s\n", sqlite3_errmsg(db));
|
||||
if (db)
|
||||
|
@ -399,7 +253,8 @@ static gint data_create_new_database(const gchar *filename)
|
|||
}
|
||||
|
||||
/* Create collections table */
|
||||
rc = sqlite3_exec(db, "CREATE TABLE manga("
|
||||
rc = sqlite3_exec(db,
|
||||
"CREATE TABLE manga("
|
||||
"id INTEGER PRIMARY KEY,"
|
||||
"name VARCHAR(100),"
|
||||
"current_qty INTEGER,"
|
||||
|
@ -433,10 +288,72 @@ static gint data_create_new_database(const gchar *filename)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static Manga *data_get_manga_from_statement(sqlite3_stmt *stmt)
|
||||
static gboolean
|
||||
execute_non_query(const gchar *sql)
|
||||
{
|
||||
Manga *manga =
|
||||
(Manga *)malloc(sizeof(Manga));
|
||||
sqlite3 *db;
|
||||
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->name = g_strdup(sqlite3_column_text(stmt, 1));
|
||||
|
|
28
src/data.h
28
src/data.h
|
@ -3,17 +3,13 @@
|
|||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
typedef struct _volume Volume;
|
||||
|
||||
struct _volume
|
||||
typedef struct
|
||||
{
|
||||
int number;
|
||||
int read;
|
||||
};
|
||||
} Volume;
|
||||
|
||||
typedef struct _manga Manga;
|
||||
|
||||
struct _manga
|
||||
typedef struct
|
||||
{
|
||||
int id;
|
||||
int current_qty;
|
||||
|
@ -21,16 +17,16 @@ struct _manga
|
|||
char *name;
|
||||
int vol_count;
|
||||
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);
|
||||
Manga *data_get_manga_by_id(gint manga_id);
|
||||
void data_get_volumes_for_manga(Manga *manga);
|
||||
gboolean data_add_manga(gchar *name, gint total_qty);
|
||||
gboolean data_add_to_manga(gint id, gint count);
|
||||
gboolean data_add_volume_to_manga(gint manga_id, gint volume);
|
||||
gboolean data_mark_volume_read(gint read, gint manga_id, gint volume);
|
||||
gboolean data_remove_volume_from_manga(gint manga_id, gint volume);
|
||||
GList *data_get_manga(void);
|
||||
Manga *data_get_manga_by_id(gint);
|
||||
void data_get_volumes_for_manga(Manga*);
|
||||
gboolean data_mark_volume_read(gint, gint, gint);
|
||||
gboolean data_remove_volume_from_manga(gint, gint);
|
||||
|
||||
#endif /* __DATA_H__ */
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include "eom-edit-window.h"
|
||||
|
||||
#include <hildon/hildon.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "data.h"
|
||||
#include "eom-main-window.h"
|
||||
|
||||
|
@ -10,103 +12,59 @@ enum {
|
|||
EOM_EDIT_PROP_CID
|
||||
};
|
||||
|
||||
static void eom_edit_window_set_manga_id(EomEditWindow *self,
|
||||
gint manga_id);
|
||||
static void eom_edit_window_on_volume_toggled(GtkToggleButton *togglebutton,
|
||||
gpointer user_data);
|
||||
static void
|
||||
eom_edit_window_on_volume_read_toggled(GtkToggleButton *togglebutton,
|
||||
gpointer user_data);
|
||||
static void eom_edit_window_class_init(EomEditWindowClass*);
|
||||
static void eom_edit_window_init(EomEditWindow *self);
|
||||
static void finalize(GObject*);
|
||||
static void get_property(GObject*, guint, GValue*, GParamSpec*);
|
||||
static void on_volume_read_toggled(GtkToggleButton*, gpointer);
|
||||
static void on_volume_toggled(GtkToggleButton*, gpointer);
|
||||
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)
|
||||
|
||||
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,
|
||||
guint property_id,
|
||||
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)
|
||||
static void
|
||||
eom_edit_window_class_init(EomEditWindowClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
||||
GParamSpec *pspec;
|
||||
|
||||
gobject_class->set_property = eom_edit_window_set_property;
|
||||
gobject_class->get_property = eom_edit_window_get_property;
|
||||
gobject_class->finalize = eom_edit_window_finalize;
|
||||
|
||||
pspec = g_param_spec_int("manga-id",
|
||||
"ID of the manga",
|
||||
"Set the manga-id",
|
||||
0,
|
||||
INT_MAX,
|
||||
0,
|
||||
gobject_class->set_property = set_property;
|
||||
gobject_class->get_property = get_property;
|
||||
gobject_class->finalize = finalize;
|
||||
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,
|
||||
EOM_EDIT_PROP_CID,
|
||||
|
||||
g_object_class_install_property(gobject_class, EOM_EDIT_PROP_CID,
|
||||
pspec);
|
||||
}
|
||||
|
||||
static void eom_edit_window_init(EomEditWindow *self)
|
||||
static void
|
||||
eom_edit_window_init(EomEditWindow *self)
|
||||
{
|
||||
GtkWidget *pannablearea;
|
||||
GtkWidget *panarea;
|
||||
GtkWidget *table;
|
||||
GtkWidget *nameclabel;
|
||||
GtkWidget *haveclabel;
|
||||
GtkWidget *totalclabel;
|
||||
|
||||
pannablearea = hildon_pannable_area_new();
|
||||
g_object_set(G_OBJECT(pannablearea),
|
||||
panarea = hildon_pannable_area_new();
|
||||
g_object_set(G_OBJECT(panarea),
|
||||
"mov-mode", HILDON_MOVEMENT_MODE_VERT,
|
||||
NULL);
|
||||
gtk_container_add(GTK_CONTAINER(self), pannablearea);
|
||||
gtk_container_add(GTK_CONTAINER(self), panarea);
|
||||
|
||||
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);
|
||||
|
||||
/* 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_EXPAND | GTK_FILL, GTK_SHRINK | GTK_FILL, 0, 0);
|
||||
|
||||
self->volumes_box = gtk_vbox_new(TRUE, 0);
|
||||
gtk_table_attach(GTK_TABLE(table), self->volumes_box, 0, 2, 3, 4,
|
||||
self->volsbox = gtk_vbox_new(TRUE, 0);
|
||||
gtk_table_attach(GTK_TABLE(table), self->volsbox, 0, 2, 3, 4,
|
||||
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;
|
||||
gint i;
|
||||
gint j = 0;
|
||||
EomEditWindow *self = EOM_EDIT_WINDOW(object);
|
||||
|
||||
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 *tlabel;
|
||||
GtkWidget *buttonbox;
|
||||
Manga *manga;
|
||||
gchar *txt;
|
||||
gint i;
|
||||
gint j = 0;
|
||||
|
||||
manga = data_get_manga_by_id(manga_id);
|
||||
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_label_set_text(GTK_LABEL(self->have_label),
|
||||
g_strdup_printf("%d", manga->current_qty));
|
||||
gtk_entry_set_text(GTK_ENTRY(self->total_entry),
|
||||
g_strdup_printf("%d", manga->total_qty));
|
||||
|
||||
txt = g_strdup_printf("%d", manga->current_qty);
|
||||
gtk_label_set_text(GTK_LABEL(self->have_label), txt);
|
||||
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 */
|
||||
|
||||
for (i = 0; i < manga->total_qty; i++) {
|
||||
GtkWidget *button;
|
||||
GtkWidget *read_button;
|
||||
GtkWidget *btn;
|
||||
GtkWidget *rbtn;
|
||||
|
||||
buttonbox = gtk_hbox_new(TRUE, 2);
|
||||
gtk_box_pack_start(GTK_BOX(self->volumes_box), buttonbox, TRUE, TRUE, 0);
|
||||
bbox = gtk_hbox_new(TRUE, 2);
|
||||
gtk_box_pack_start(GTK_BOX(self->volsbox), bbox, TRUE, TRUE, 0);
|
||||
|
||||
/* Button indicating collected state */
|
||||
button = gtk_toggle_button_new_with_label(g_strdup_printf("%d", i + 1));
|
||||
gtk_box_pack_start(GTK_BOX(buttonbox), button, TRUE, TRUE, 0);
|
||||
txt = g_strdup_printf("%d", i + 1);
|
||||
btn = gtk_toggle_button_new_with_label(txt);
|
||||
gtk_box_pack_start(GTK_BOX(bbox), btn, TRUE, TRUE, 0);
|
||||
|
||||
/* Button indicating read state */
|
||||
read_button =
|
||||
gtk_toggle_button_new_with_label(g_strdup_printf("%d", i + 1));
|
||||
gtk_box_pack_start(GTK_BOX(buttonbox), read_button, TRUE, TRUE, 0);
|
||||
rbtn = gtk_toggle_button_new_with_label(txt);
|
||||
gtk_box_pack_start(GTK_BOX(bbox), rbtn, TRUE, TRUE, 0);
|
||||
g_free(txt);
|
||||
|
||||
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)
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(read_button), TRUE);
|
||||
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(rbtn),
|
||||
TRUE);
|
||||
|
||||
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);
|
||||
g_signal_connect(read_button, "toggled",
|
||||
G_CALLBACK(eom_edit_window_on_volume_read_toggled),
|
||||
g_signal_connect(rbtn, "toggled",
|
||||
G_CALLBACK(on_volume_read_toggled),
|
||||
(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
|
||||
eom_edit_window_on_volume_read_toggled(GtkToggleButton *togglebutton,
|
||||
gpointer user_data)
|
||||
set_property(GObject *object, guint property_id, const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
EomEditWindow *self;
|
||||
gboolean active;
|
||||
gint volume;
|
||||
EomEditWindow *self = EOM_EDIT_WINDOW(object);
|
||||
gint manga_id = g_value_get_int(value);
|
||||
|
||||
self = (EomEditWindow *)user_data;
|
||||
active = gtk_toggle_button_get_active(togglebutton);
|
||||
volume = atoi(gtk_button_get_label(GTK_BUTTON(togglebutton)));
|
||||
|
||||
if (!data_mark_volume_read(active, self->current_manga->id, volume))
|
||||
g_print("coulnd't mark volume as read\n");
|
||||
switch (property_id) {
|
||||
case EOM_EDIT_PROP_CID:
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define __EOM_EDIT_WINDOW_H__
|
||||
|
||||
#include <hildon/hildon-stackable-window.h>
|
||||
|
||||
#include "data.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
@ -32,29 +33,25 @@ G_BEGIN_DECLS
|
|||
EOM_TYPE_EDIT_WINDOW, \
|
||||
EomEditWindowClass))
|
||||
|
||||
typedef struct _EomEditWindow EomEditWindow;
|
||||
typedef struct _EomEditWindowClass EomEditWindowClass;
|
||||
|
||||
struct _EomEditWindowClass
|
||||
typedef struct
|
||||
{
|
||||
HildonStackableWindowClass parent_class;
|
||||
};
|
||||
} EomEditWindowClass;
|
||||
|
||||
struct _EomEditWindow
|
||||
typedef struct
|
||||
{
|
||||
HildonStackableWindow parent;
|
||||
|
||||
GtkWidget *name_entry;
|
||||
GtkWidget *have_label;
|
||||
GtkWidget *total_entry;
|
||||
GtkWidget *volumes_box;
|
||||
GtkWidget *volsbox;
|
||||
|
||||
Manga *current_manga;
|
||||
};
|
||||
Manga *manga;
|
||||
} EomEditWindow;
|
||||
|
||||
GType eom_edit_window_get_type(void);
|
||||
|
||||
GtkWidget *eom_edit_window_new(gint manga_id);
|
||||
GtkWidget *eom_edit_window_new(gint);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
#include "data.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 {
|
||||
COL_ID = 0,
|
||||
|
@ -25,29 +26,30 @@ struct filter_args {
|
|||
gint state;
|
||||
};
|
||||
|
||||
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_filter(GtkWidget *widget, struct filter_args *arg);
|
||||
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 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);
|
||||
static void add_menu(EomMainWindow*);
|
||||
static void eom_main_window_class_init(EomMainWindowClass*);
|
||||
static void eom_main_window_init(EomMainWindow*);
|
||||
static gboolean on_edit_closed(GtkWidget*, GdkEvent*, gpointer);
|
||||
static void on_filter(GtkWidget*, struct filter_args*);
|
||||
static void on_new(GtkWidget*, GtkWindow*);
|
||||
static void on_row_activated(GtkWidget*, GtkTreePath*, GtkTreeViewColumn*, gpointer);
|
||||
|
||||
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,
|
||||
"state", 0,
|
||||
NULL);
|
||||
gtk_list_store_append(window->store, &window->iter);
|
||||
gtk_list_store_set(window ->store, &window->iter,
|
||||
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;
|
||||
int i;
|
||||
|
@ -61,14 +63,16 @@ void eom_main_window_load(EomMainWindow *self)
|
|||
|
||||
while (list) {
|
||||
Manga *manga = list->data;
|
||||
|
||||
eom_main_window_add_line(self, manga->id, manga->name,
|
||||
manga->current_qty, manga->total_qty);
|
||||
|
||||
free(manga->name);
|
||||
|
||||
if (manga->volumes != NULL) {
|
||||
for (i = 0; i < manga->vol_count; i++)
|
||||
free(manga->volumes + i);
|
||||
}
|
||||
|
||||
free(manga);
|
||||
list = g_list_next(list);
|
||||
}
|
||||
|
@ -76,25 +80,61 @@ void eom_main_window_load(EomMainWindow *self)
|
|||
g_list_free_1(list);
|
||||
}
|
||||
|
||||
void eom_main_window_add_line(EomMainWindow *window,
|
||||
gint id,
|
||||
const gchar *name,
|
||||
gint current_qty,
|
||||
gint total_qty)
|
||||
GtkWidget *
|
||||
eom_main_window_new(void)
|
||||
{
|
||||
gtk_list_store_append(window->store, &window->iter);
|
||||
gtk_list_store_set(window ->store, &window->iter,
|
||||
COL_ID, id,
|
||||
COL_NAME, name,
|
||||
COL_CURRENT, current_qty,
|
||||
COL_TOTAL, total_qty,
|
||||
-1);
|
||||
return g_object_new(EOM_TYPE_MAIN_WINDOW, NULL);
|
||||
}
|
||||
|
||||
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;
|
||||
GtkWidget *view;
|
||||
|
@ -105,10 +145,11 @@ static void eom_main_window_init(EomMainWindow *window)
|
|||
|
||||
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, "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,
|
||||
G_TYPE_INT,
|
||||
|
@ -123,8 +164,8 @@ static void eom_main_window_init(EomMainWindow *window)
|
|||
gtk_container_add(GTK_CONTAINER(window), pannablearea);
|
||||
|
||||
view = hildon_gtk_tree_view_new(HILDON_UI_MODE_NORMAL);
|
||||
g_signal_connect(view, "row-activated",
|
||||
G_CALLBACK(eom_main_window_on_row_activated), window);
|
||||
g_signal_connect(view, "row-activated", G_CALLBACK(on_row_activated),
|
||||
window);
|
||||
gtk_container_add(GTK_CONTAINER(pannablearea), view);
|
||||
|
||||
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
|
||||
|
@ -137,7 +178,8 @@ static void eom_main_window_init(EomMainWindow *window)
|
|||
renderer,
|
||||
"text", COL_NAME,
|
||||
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);
|
||||
|
||||
renderer = gtk_cell_renderer_text_new();
|
||||
|
@ -169,60 +211,25 @@ static void eom_main_window_init(EomMainWindow *window)
|
|||
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;
|
||||
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));
|
||||
EomMainWindow *self = user_data;
|
||||
|
||||
args0->window = window;
|
||||
args0->state = 0;
|
||||
args1->window = window;
|
||||
args1->state = 1;
|
||||
appmenu = HILDON_APP_MENU(hildon_app_menu_new());
|
||||
eom_main_window_load(self);
|
||||
|
||||
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(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));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
gint result;
|
||||
|
@ -230,7 +237,6 @@ static void eom_main_window_on_new(GtkWidget *widget, GtkWindow *window)
|
|||
gint total_qty;
|
||||
|
||||
dialog = interface_show_new_item_dialog(window);
|
||||
|
||||
result = gtk_dialog_run(GTK_DIALOG(dialog));
|
||||
|
||||
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,
|
||||
GdkEvent *event,
|
||||
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)
|
||||
static void
|
||||
on_row_activated(GtkWidget *treeview, GtkTreePath *path,
|
||||
GtkTreeViewColumn *column, gpointer user_data)
|
||||
{
|
||||
EomMainWindow *self = user_data;
|
||||
GtkTreeIter iter;
|
||||
|
@ -275,11 +269,12 @@ static void eom_main_window_on_row_activated(GtkWidget *treeview,
|
|||
GtkWidget *window;
|
||||
|
||||
model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
|
||||
|
||||
if (!gtk_tree_model_get_iter(model, &iter, path))
|
||||
return;
|
||||
|
||||
gtk_tree_model_get(model, &iter, COL_ID, &id, -1);
|
||||
window = interface_show_edit_window(id);
|
||||
g_signal_connect(window, "delete-event",
|
||||
G_CALLBACK(eom_main_window_on_edit_closed), self);
|
||||
g_signal_connect(window, "delete-event", G_CALLBACK(on_edit_closed),
|
||||
self);
|
||||
}
|
||||
|
|
|
@ -31,15 +31,12 @@ G_BEGIN_DECLS
|
|||
EOM_TYPE_MAIN_WINDOW, \
|
||||
EomMainWindowClass))
|
||||
|
||||
typedef struct _EomMainWindow EomMainWindow;
|
||||
typedef struct _EomMainWindowClass EomMainWindowClass;
|
||||
|
||||
struct _EomMainWindowClass
|
||||
typedef struct
|
||||
{
|
||||
HildonStackableWindowClass parent_class;
|
||||
};
|
||||
} EomMainWindowClass;
|
||||
|
||||
struct _EomMainWindow
|
||||
typedef struct
|
||||
{
|
||||
HildonStackableWindow parent;
|
||||
|
||||
|
@ -47,19 +44,14 @@ struct _EomMainWindow
|
|||
GtkListStore *store;
|
||||
|
||||
int state;
|
||||
};
|
||||
} EomMainWindow;
|
||||
|
||||
void eom_main_window_add_line(EomMainWindow*, gint, const gchar*, gint,
|
||||
gint);
|
||||
GType eom_main_window_get_type(void);
|
||||
|
||||
void eom_main_window_load(EomMainWindow*);
|
||||
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
|
||||
|
||||
#endif /* __EOM_MAIN_WINDOW_H__ */
|
||||
|
|
|
@ -1,29 +1,38 @@
|
|||
#include "eom-new-item-dialog.h"
|
||||
#include <hildon/hildon-entry.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <hildon/hildon-entry.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)
|
||||
|
||||
GtkWidget *eom_new_item_dialog_new(void)
|
||||
{
|
||||
return g_object_new(EOM_TYPE_NEW_ITEM_DIALOG, NULL);
|
||||
}
|
||||
|
||||
const gchar *eom_new_item_dialog_get_name(EomNewItemDialog *dialog)
|
||||
const gchar *
|
||||
eom_new_item_dialog_get_name(EomNewItemDialog *dialog)
|
||||
{
|
||||
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)));
|
||||
}
|
||||
|
||||
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 *hbox;
|
||||
|
@ -34,7 +43,8 @@ static void eom_new_item_dialog_init(EomNewItemDialog *dialog)
|
|||
gtk_container_add(GTK_CONTAINER(content_area), hbox);
|
||||
|
||||
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);
|
||||
|
||||
dialog->qty_entry = hildon_entry_new(HILDON_SIZE_AUTO);
|
||||
|
|
|
@ -31,30 +31,24 @@ G_BEGIN_DECLS
|
|||
EOM_TYPE_NEW_ITEM_DIALOG, \
|
||||
EomNewItemDialogClass))
|
||||
|
||||
typedef struct _EomNewItemDialog EomNewItemDialog;
|
||||
typedef struct _EomNewItemDialogClass EomNewItemDialogClass;
|
||||
|
||||
struct _EomNewItemDialogClass
|
||||
typedef struct
|
||||
{
|
||||
GtkDialogClass parent_class;
|
||||
};
|
||||
} EomNewItemDialogClass;
|
||||
|
||||
struct _EomNewItemDialog
|
||||
typedef struct
|
||||
{
|
||||
GtkDialog parent;
|
||||
|
||||
GtkWidget *name_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);
|
||||
|
||||
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__ */
|
||||
|
|
14
src/eom.c
14
src/eom.c
|
@ -1,9 +1,11 @@
|
|||
#include <hildon/hildon.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;
|
||||
|
||||
|
@ -15,7 +17,8 @@ gchar *eom_get_data_file(void)
|
|||
return filedir;
|
||||
}
|
||||
|
||||
gchar *eom_get_config_dir(void)
|
||||
gchar *
|
||||
eom_get_config_dir(void)
|
||||
{
|
||||
static gchar *filedir = NULL;
|
||||
|
||||
|
@ -29,11 +32,8 @@ gchar *eom_get_config_dir(void)
|
|||
int main(int argc, char *argv[])
|
||||
{
|
||||
hildon_gtk_init(&argc, &argv);
|
||||
|
||||
g_set_application_name("Eye on Manga");
|
||||
|
||||
interface_show_main_window();
|
||||
|
||||
gtk_main();
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -1,2 +1,7 @@
|
|||
#ifndef __EOM_H__
|
||||
#define __EOM_H__
|
||||
|
||||
gchar *eom_get_data_file(void);
|
||||
gchar *eom_get_config_dir(void);
|
||||
|
||||
#endif /* __EOM_H__ */
|
||||
|
|
Loading…
Reference in a new issue