Update style

This commit is contained in:
Moritz Lipp 2012-03-09 08:04:54 +01:00
parent b244e016d0
commit 7271166b20
4 changed files with 62 additions and 43 deletions

View file

@ -35,15 +35,16 @@ G_DEFINE_TYPE_WITH_CODE(ZathuraPlainDatabase, zathura_plaindatabase, G_TYPE_OBJE
static void plain_finalize(GObject* object); static void plain_finalize(GObject* object);
static bool plain_add_bookmark(zathura_database_t* db, const char* file, static bool plain_add_bookmark(zathura_database_t* db, const char* file,
zathura_bookmark_t* bookmark); zathura_bookmark_t* bookmark);
static bool plain_remove_bookmark(zathura_database_t* db, const char* file, const static bool plain_remove_bookmark(zathura_database_t* db, const char* file,
char* id); const char* id);
static girara_list_t* plain_load_bookmarks(zathura_database_t* db, const char* static girara_list_t* plain_load_bookmarks(zathura_database_t* db,
file); const char* file);
static bool plain_set_fileinfo(zathura_database_t* db, const char* file, unsigned static bool plain_set_fileinfo(zathura_database_t* db, const char* file,
int page, int offset, double scale, int rotation); unsigned int page, int offset, double scale, int rotation);
static bool plain_get_fileinfo(zathura_database_t* db, const char* file, unsigned static bool plain_get_fileinfo(zathura_database_t* db, const char* file,
int* page, int* offset, double* scale, int* rotation); unsigned int* page, int* offset, double* scale, int* rotation);
static void plain_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec); static void plain_set_property(GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec);
/* forward declaration */ /* forward declaration */
static bool zathura_db_check_file(const char* path); static bool zathura_db_check_file(const char* path);
@ -75,11 +76,11 @@ static void
zathura_database_interface_init(ZathuraDatabaseInterface* iface) zathura_database_interface_init(ZathuraDatabaseInterface* iface)
{ {
/* initialize interface */ /* initialize interface */
iface->add_bookmark = plain_add_bookmark; iface->add_bookmark = plain_add_bookmark;
iface->remove_bookmark = plain_remove_bookmark; iface->remove_bookmark = plain_remove_bookmark;
iface->load_bookmarks = plain_load_bookmarks; iface->load_bookmarks = plain_load_bookmarks;
iface->set_fileinfo = plain_set_fileinfo; iface->set_fileinfo = plain_set_fileinfo;
iface->get_fileinfo = plain_get_fileinfo; iface->get_fileinfo = plain_get_fileinfo;
} }
static void static void
@ -90,7 +91,7 @@ zathura_plaindatabase_class_init(ZathuraPlainDatabaseClass* class)
/* override methods */ /* override methods */
GObjectClass* object_class = G_OBJECT_CLASS(class); GObjectClass* object_class = G_OBJECT_CLASS(class);
object_class->finalize = plain_finalize; object_class->finalize = plain_finalize;
object_class->set_property = plain_set_property; object_class->set_property = plain_set_property;
g_object_class_install_property(object_class, PROP_PATH, g_object_class_install_property(object_class, PROP_PATH,
@ -102,12 +103,13 @@ static void
zathura_plaindatabase_init(ZathuraPlainDatabase* db) zathura_plaindatabase_init(ZathuraPlainDatabase* db)
{ {
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db); zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
priv->bookmark_path = NULL;
priv->bookmark_path = NULL;
priv->bookmark_monitor = NULL; priv->bookmark_monitor = NULL;
priv->bookmarks = NULL; priv->bookmarks = NULL;
priv->history_path = NULL; priv->history_path = NULL;
priv->history_monitor = NULL; priv->history_monitor = NULL;
priv->history = NULL; priv->history = NULL;
} }
zathura_database_t* zathura_database_t*
@ -121,6 +123,7 @@ zathura_plaindatabase_new(const char* path)
g_object_unref(db); g_object_unref(db);
return NULL; return NULL;
} }
return db; return db;
} }
@ -141,6 +144,7 @@ plain_db_init(ZathuraPlainDatabase* db, const char* dir)
} else { } else {
goto error_free; goto error_free;
} }
g_object_unref(bookmark_file); g_object_unref(bookmark_file);
g_signal_connect( g_signal_connect(
@ -167,6 +171,7 @@ plain_db_init(ZathuraPlainDatabase* db, const char* dir)
} else { } else {
goto error_free; goto error_free;
} }
g_object_unref(history_file); g_object_unref(history_file);
g_signal_connect( g_signal_connect(
@ -180,6 +185,7 @@ plain_db_init(ZathuraPlainDatabase* db, const char* dir)
if (priv->history == NULL) { if (priv->history == NULL) {
goto error_free; goto error_free;
} }
return; return;
error_free: error_free:
@ -232,6 +238,7 @@ plain_finalize(GObject* object)
{ {
ZathuraPlainDatabase* db = ZATHURA_PLAINDATABASE(object); ZathuraPlainDatabase* db = ZATHURA_PLAINDATABASE(object);
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db); zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
/* bookmarks */ /* bookmarks */
g_free(priv->bookmark_path); g_free(priv->bookmark_path);
@ -306,8 +313,9 @@ plain_load_bookmarks(zathura_database_t* db, const char* file)
return NULL; return NULL;
} }
girara_list_t* result = girara_sorted_list_new2((girara_compare_function_t) zathura_bookmarks_compare, girara_list_t* result = girara_sorted_list_new2((girara_compare_function_t)
(girara_free_function_t) zathura_bookmark_free); zathura_bookmarks_compare, (girara_free_function_t)
zathura_bookmark_free);
gsize length; gsize length;
char** keys = g_key_file_get_keys(priv->bookmarks, file, &length, NULL); char** keys = g_key_file_get_keys(priv->bookmarks, file, &length, NULL);
@ -506,11 +514,13 @@ cb_zathura_db_watch_file(GFileMonitor* UNUSED(monitor), GFile* file, GFile* UNUS
if (priv->bookmarks != NULL) { if (priv->bookmarks != NULL) {
g_key_file_free(priv->bookmarks); g_key_file_free(priv->bookmarks);
} }
priv->bookmarks = zathura_db_read_key_file_from_file(priv->bookmark_path); priv->bookmarks = zathura_db_read_key_file_from_file(priv->bookmark_path);
} else if (priv->history_path && strcmp(priv->history_path, path) == 0) { } else if (priv->history_path && strcmp(priv->history_path, path) == 0) {
if (priv->history != NULL) { if (priv->history != NULL) {
g_key_file_free(priv->history); g_key_file_free(priv->history);
} }
priv->history = zathura_db_read_key_file_from_file(priv->history_path); priv->history = zathura_db_read_key_file_from_file(priv->history_path);
} }
} }

View file

@ -15,15 +15,16 @@ G_DEFINE_TYPE_WITH_CODE(ZathuraSQLDatabase, zathura_sqldatabase, G_TYPE_OBJECT,
static void sqlite_finalize(GObject* object); static void sqlite_finalize(GObject* object);
static bool sqlite_add_bookmark(zathura_database_t* db, const char* file, static bool sqlite_add_bookmark(zathura_database_t* db, const char* file,
zathura_bookmark_t* bookmark); zathura_bookmark_t* bookmark);
static bool sqlite_remove_bookmark(zathura_database_t* db, const char* file, const static bool sqlite_remove_bookmark(zathura_database_t* db, const char* file,
char* id); const char* id);
static girara_list_t* sqlite_load_bookmarks(zathura_database_t* db, const char* static girara_list_t* sqlite_load_bookmarks(zathura_database_t* db,
file); const char* file);
static bool sqlite_set_fileinfo(zathura_database_t* db, const char* file, unsigned static bool sqlite_set_fileinfo(zathura_database_t* db, const char* file,
int page, int offset, double scale, int rotation); unsigned int page, int offset, double scale, int rotation);
static bool sqlite_get_fileinfo(zathura_database_t* db, const char* file, unsigned static bool sqlite_get_fileinfo(zathura_database_t* db, const char* file,
int* page, int* offset, double* scale, int* rotation); unsigned int* page, int* offset, double* scale, int* rotation);
static void sqlite_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec); static void sqlite_set_property(GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec);
typedef struct zathura_sqldatabase_private_s { typedef struct zathura_sqldatabase_private_s {
sqlite3* session; sqlite3* session;
@ -42,11 +43,11 @@ static void
zathura_database_interface_init(ZathuraDatabaseInterface* iface) zathura_database_interface_init(ZathuraDatabaseInterface* iface)
{ {
/* initialize interface */ /* initialize interface */
iface->add_bookmark = sqlite_add_bookmark; iface->add_bookmark = sqlite_add_bookmark;
iface->remove_bookmark = sqlite_remove_bookmark; iface->remove_bookmark = sqlite_remove_bookmark;
iface->load_bookmarks = sqlite_load_bookmarks; iface->load_bookmarks = sqlite_load_bookmarks;
iface->set_fileinfo = sqlite_set_fileinfo; iface->set_fileinfo = sqlite_set_fileinfo;
iface->get_fileinfo = sqlite_get_fileinfo; iface->get_fileinfo = sqlite_get_fileinfo;
} }
static void static void
@ -57,7 +58,7 @@ zathura_sqldatabase_class_init(ZathuraSQLDatabaseClass* class)
/* override methods */ /* override methods */
GObjectClass* object_class = G_OBJECT_CLASS(class); GObjectClass* object_class = G_OBJECT_CLASS(class);
object_class->finalize = sqlite_finalize; object_class->finalize = sqlite_finalize;
object_class->set_property = sqlite_set_property; object_class->set_property = sqlite_set_property;
g_object_class_install_property(object_class, PROP_PATH, g_object_class_install_property(object_class, PROP_PATH,
@ -82,6 +83,7 @@ zathura_sqldatabase_new(const char* path)
g_object_unref(db); g_object_unref(db);
return NULL; return NULL;
} }
return db; return db;
} }
@ -202,7 +204,8 @@ sqlite_add_bookmark(zathura_database_t* db, const char* file,
int res = sqlite3_step(stmt); int res = sqlite3_step(stmt);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return res == SQLITE_DONE;
return (res == SQLITE_DONE) ? true : false;
} }
static bool static bool
@ -228,7 +231,8 @@ sqlite_remove_bookmark(zathura_database_t* db, const char* file, const char*
int res = sqlite3_step(stmt); int res = sqlite3_step(stmt);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return res == SQLITE_DONE;
return (res == SQLITE_DONE) ? true : false;
} }
static girara_list_t* static girara_list_t*
@ -252,6 +256,7 @@ sqlite_load_bookmarks(zathura_database_t* db, const char* file)
girara_list_t* result = girara_sorted_list_new2((girara_compare_function_t) zathura_bookmarks_compare, girara_list_t* result = girara_sorted_list_new2((girara_compare_function_t) zathura_bookmarks_compare,
(girara_free_function_t) zathura_bookmark_free); (girara_free_function_t) zathura_bookmark_free);
while (sqlite3_step(stmt) == SQLITE_ROW) { while (sqlite3_step(stmt) == SQLITE_ROW) {
zathura_bookmark_t* bookmark = g_malloc0(sizeof(zathura_bookmark_t)); zathura_bookmark_t* bookmark = g_malloc0(sizeof(zathura_bookmark_t));
@ -260,7 +265,9 @@ sqlite_load_bookmarks(zathura_database_t* db, const char* file)
girara_list_append(result, bookmark); girara_list_append(result, bookmark);
} }
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return result; return result;
} }
@ -290,7 +297,8 @@ sqlite_set_fileinfo(zathura_database_t* db, const char* file, unsigned int
int res = sqlite3_step(stmt); int res = sqlite3_step(stmt);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return res == SQLITE_DONE;
return (res == SQLITE_DONE) ? true : false;
} }
static bool static bool
@ -324,5 +332,6 @@ sqlite_get_fileinfo(zathura_database_t* db, const char* file, unsigned int*
*scale = sqlite3_column_double(stmt, 2); *scale = sqlite3_column_double(stmt, 2);
*rotation = sqlite3_column_int(stmt, 3); *rotation = sqlite3_column_int(stmt, 3);
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return true; return true;
} }

View file

@ -425,7 +425,7 @@ sc_scroll(girara_session_t* session, girara_argument_t* argument,
GtkAdjustment* adjustment = NULL; GtkAdjustment* adjustment = NULL;
if ( (argument->n == LEFT) || (argument->n == FULL_LEFT) || (argument->n == HALF_LEFT) || if ( (argument->n == LEFT) || (argument->n == FULL_LEFT) || (argument->n == HALF_LEFT) ||
(argument->n == RIGHT) || (argument->n == FULL_RIGHT) || (argument->n == HALF_RIGHT)) { (argument->n == RIGHT) || (argument->n == FULL_RIGHT) || (argument->n == HALF_RIGHT)) {
adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view)); adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
} else { } else {
adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(session->gtk.view)); adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));