Commit a4d1df87 authored by Sebastian Ramacher's avatar Sebastian Ramacher

Use G_ADD_PRIVATE

Fix deprecation warnings with glib 2.58.
parent 04c37544
......@@ -48,6 +48,18 @@ file_lock_set(int fd, short cmd)
static void zathura_database_interface_init(ZathuraDatabaseInterface* iface);
static void io_interface_init(GiraraInputHistoryIOInterface* iface);
typedef struct zathura_plaindatabase_private_s {
char* bookmark_path;
GKeyFile* bookmarks;
GFileMonitor* bookmark_monitor;
char* history_path;
GKeyFile* history;
GFileMonitor* history_monitor;
char* input_history_path;
} ZathuraPlainDatabasePrivate;
G_DEFINE_TYPE_WITH_CODE(ZathuraPlainDatabase, zathura_plaindatabase, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE(ZATHURA_TYPE_DATABASE, zathura_database_interface_init)
G_IMPLEMENT_INTERFACE(GIRARA_TYPE_INPUT_HISTORY_IO, io_interface_init))
......@@ -72,21 +84,6 @@ static GKeyFile* zathura_db_read_key_file_from_file(const char* path);
static void zathura_db_write_key_file_to_file(const char* file, GKeyFile* key_file);
static void cb_zathura_db_watch_file(GFileMonitor* monitor, GFile* file, GFile* other_file, GFileMonitorEvent event, zathura_database_t* database);
typedef struct zathura_plaindatabase_private_s {
char* bookmark_path;
GKeyFile* bookmarks;
GFileMonitor* bookmark_monitor;
char* history_path;
GKeyFile* history;
GFileMonitor* history_monitor;
char* input_history_path;
} zathura_plaindatabase_private_t;
#define ZATHURA_PLAINDATABASE_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZATHURA_TYPE_PLAINDATABASE, zathura_plaindatabase_private_t))
enum {
PROP_0,
PROP_PATH
......@@ -131,9 +128,6 @@ io_interface_init(GiraraInputHistoryIOInterface* iface)
static void
zathura_plaindatabase_class_init(ZathuraPlainDatabaseClass* class)
{
/* add private members */
g_type_class_add_private(class, sizeof(zathura_plaindatabase_private_t));
/* override methods */
GObjectClass* object_class = G_OBJECT_CLASS(class);
object_class->dispose = plain_dispose;
......@@ -148,7 +142,7 @@ zathura_plaindatabase_class_init(ZathuraPlainDatabaseClass* class)
static void
zathura_plaindatabase_init(ZathuraPlainDatabase* db)
{
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
ZathuraPlainDatabasePrivate* priv = zathura_plaindatabase_get_instance_private(db);
priv->bookmark_path = NULL;
priv->bookmark_monitor = NULL;
......@@ -165,7 +159,7 @@ zathura_plaindatabase_new(const char* path)
g_return_val_if_fail(path != NULL && strlen(path) != 0, NULL);
zathura_database_t* db = g_object_new(ZATHURA_TYPE_PLAINDATABASE, "path", path, NULL);
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
ZathuraPlainDatabasePrivate* priv = zathura_plaindatabase_get_instance_private(ZATHURA_PLAINDATABASE(db));
if (priv->bookmark_path == NULL) {
g_object_unref(db);
return NULL;
......@@ -177,7 +171,7 @@ zathura_plaindatabase_new(const char* path)
static void
plain_db_init(ZathuraPlainDatabase* db, const char* dir)
{
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
ZathuraPlainDatabasePrivate* priv = zathura_plaindatabase_get_instance_private(db);
/* bookmarks */
priv->bookmark_path = g_build_filename(dir, BOOKMARKS, NULL);
......@@ -288,7 +282,7 @@ static void
plain_dispose(GObject* object)
{
ZathuraPlainDatabase* db = ZATHURA_PLAINDATABASE(object);
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
ZathuraPlainDatabasePrivate* priv = zathura_plaindatabase_get_instance_private(db);
g_clear_object(&priv->bookmark_monitor);
g_clear_object(&priv->history_monitor);
......@@ -300,7 +294,7 @@ static void
plain_finalize(GObject* object)
{
ZathuraPlainDatabase* db = ZATHURA_PLAINDATABASE(object);
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
ZathuraPlainDatabasePrivate* priv = zathura_plaindatabase_get_instance_private(db);
/* bookmarks */
g_free(priv->bookmark_path);
......@@ -326,7 +320,8 @@ static bool
plain_add_bookmark(zathura_database_t* db, const char* file,
zathura_bookmark_t* bookmark)
{
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
ZathuraPlainDatabase* plaindb = ZATHURA_PLAINDATABASE(db);
ZathuraPlainDatabasePrivate* priv = zathura_plaindatabase_get_instance_private(plaindb);
if (priv->bookmarks == NULL || priv->bookmark_path == NULL ||
bookmark->id == NULL) {
return false;
......@@ -364,7 +359,8 @@ plain_add_bookmark(zathura_database_t* db, const char* file,
static bool
plain_remove_bookmark(zathura_database_t* db, const char* file, const char* id)
{
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
ZathuraPlainDatabase* plaindb = ZATHURA_PLAINDATABASE(db);
ZathuraPlainDatabasePrivate* priv = zathura_plaindatabase_get_instance_private(plaindb);
if (priv->bookmarks == NULL || priv->bookmark_path == NULL) {
return false;
}
......@@ -387,7 +383,8 @@ plain_remove_bookmark(zathura_database_t* db, const char* file, const char* id)
static girara_list_t*
plain_load_bookmarks(zathura_database_t* db, const char* file)
{
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
ZathuraPlainDatabase* plaindb = ZATHURA_PLAINDATABASE(db);
ZathuraPlainDatabasePrivate* priv = zathura_plaindatabase_get_instance_private(plaindb);
if (priv->bookmarks == NULL) {
return NULL;
}
......@@ -498,9 +495,10 @@ plain_load_jumplist(zathura_database_t* db, const char* file)
{
g_return_val_if_fail(db != NULL && file != NULL, NULL);
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
char* str_value = g_key_file_get_string(priv->history, file, KEY_JUMPLIST, NULL);
ZathuraPlainDatabase* plaindb = ZATHURA_PLAINDATABASE(db);
ZathuraPlainDatabasePrivate* priv = zathura_plaindatabase_get_instance_private(plaindb);
char* str_value = g_key_file_get_string(priv->history, file, KEY_JUMPLIST, NULL);
if (str_value == NULL) {
return girara_list_new2(g_free);
}
......@@ -533,7 +531,8 @@ plain_save_jumplist(zathura_database_t* db, const char* file, girara_list_t* jum
GString* str_val = g_string_new(NULL);
girara_list_foreach(jumplist, jump_to_str, str_val);
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
ZathuraPlainDatabase* plaindb = ZATHURA_PLAINDATABASE(db);
ZathuraPlainDatabasePrivate* priv = zathura_plaindatabase_get_instance_private(plaindb);
g_key_file_set_string(priv->history, file, KEY_JUMPLIST, str_val->str);
zathura_db_write_key_file_to_file(priv->history_path, priv->history);
......@@ -546,7 +545,8 @@ static bool
plain_set_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t*
file_info)
{
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
ZathuraPlainDatabase* plaindb = ZATHURA_PLAINDATABASE(db);
ZathuraPlainDatabasePrivate* priv = zathura_plaindatabase_get_instance_private(plaindb);
if (priv->history == NULL || file_info == NULL || file == NULL) {
return false;
}
......@@ -578,7 +578,8 @@ plain_get_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t*
return false;
}
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
ZathuraPlainDatabase* plaindb = ZATHURA_PLAINDATABASE(db);
ZathuraPlainDatabasePrivate* priv = zathura_plaindatabase_get_instance_private(plaindb);
if (priv->history == NULL) {
return false;
}
......@@ -742,7 +743,8 @@ cb_zathura_db_watch_file(GFileMonitor* UNUSED(monitor), GFile* file, GFile* UNUS
return;
}
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(database);
ZathuraPlainDatabase* plaindb = ZATHURA_PLAINDATABASE(database);
ZathuraPlainDatabasePrivate* priv = zathura_plaindatabase_get_instance_private(plaindb);
if (priv->bookmark_path && strcmp(priv->bookmark_path, path) == 0) {
if (priv->bookmarks != NULL) {
g_key_file_free(priv->bookmarks);
......@@ -763,7 +765,8 @@ cb_zathura_db_watch_file(GFileMonitor* UNUSED(monitor), GFile* file, GFile* UNUS
static girara_list_t*
plain_io_read(GiraraInputHistoryIO* db)
{
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
ZathuraPlainDatabase* plaindb = ZATHURA_PLAINDATABASE(db);
ZathuraPlainDatabasePrivate* priv = zathura_plaindatabase_get_instance_private(plaindb);
/* open file */
FILE* file = fopen(priv->input_history_path, "r");
......@@ -794,7 +797,8 @@ plain_io_read(GiraraInputHistoryIO* db)
static void
plain_io_append(GiraraInputHistoryIO* db, const char* input)
{
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
ZathuraPlainDatabase* plaindb = ZATHURA_PLAINDATABASE(db);
ZathuraPlainDatabasePrivate* priv = zathura_plaindatabase_get_instance_private(plaindb);
/* open file */
FILE* file = fopen(priv->input_history_path, "r+");
......@@ -859,7 +863,8 @@ compare_time(const void* l, const void* r, void* data)
static girara_list_t*
plain_get_recent_files(zathura_database_t* db, int max, const char* basepath)
{
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
ZathuraPlainDatabase* plaindb = ZATHURA_PLAINDATABASE(db);
ZathuraPlainDatabasePrivate* priv = zathura_plaindatabase_get_instance_private(plaindb);
girara_list_t* result = girara_list_new2(g_free);
if (result == NULL) {
......
......@@ -19,9 +19,14 @@ sqlite3_column_text_dup(sqlite3_stmt* stmt, int col)
static void zathura_database_interface_init(ZathuraDatabaseInterface* iface);
static void io_interface_init(GiraraInputHistoryIOInterface* iface);
typedef struct zathura_sqldatabase_private_s {
sqlite3* session;
} ZathuraSQLDatabasePrivate;
G_DEFINE_TYPE_WITH_CODE(ZathuraSQLDatabase, zathura_sqldatabase, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE(ZATHURA_TYPE_DATABASE, zathura_database_interface_init)
G_IMPLEMENT_INTERFACE(GIRARA_TYPE_INPUT_HISTORY_IO, io_interface_init))
G_IMPLEMENT_INTERFACE(GIRARA_TYPE_INPUT_HISTORY_IO, io_interface_init)
G_ADD_PRIVATE(ZathuraSQLDatabase))
static bool check_column(sqlite3* session, const char* table, const char* col, bool* result);
static bool check_column_type(sqlite3* session, const char* table, const char* col, const char* type, bool* result);
......@@ -38,13 +43,6 @@ static void sqlite_io_append(GiraraInputHistoryIO* db, const char*);
static girara_list_t* sqlite_io_read(GiraraInputHistoryIO* db);
static girara_list_t* sqlite_get_recent_files(zathura_database_t* db, int max, const char* basepath);
typedef struct zathura_sqldatabase_private_s {
sqlite3* session;
} zathura_sqldatabase_private_t;
#define ZATHURA_SQLDATABASE_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), ZATHURA_TYPE_SQLDATABASE, zathura_sqldatabase_private_t))
enum {
PROP_0,
PROP_PATH
......@@ -75,9 +73,6 @@ io_interface_init(GiraraInputHistoryIOInterface* iface)
static void
zathura_sqldatabase_class_init(ZathuraSQLDatabaseClass* class)
{
/* add private members */
g_type_class_add_private(class, sizeof(zathura_sqldatabase_private_t));
/* override methods */
GObjectClass* object_class = G_OBJECT_CLASS(class);
object_class->finalize = sqlite_finalize;
......@@ -91,7 +86,7 @@ zathura_sqldatabase_class_init(ZathuraSQLDatabaseClass* class)
static void
zathura_sqldatabase_init(ZathuraSQLDatabase* db)
{
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
ZathuraSQLDatabasePrivate* priv = zathura_sqldatabase_get_instance_private(db);
priv->session = NULL;
}
......@@ -101,7 +96,7 @@ zathura_sqldatabase_new(const char* path)
g_return_val_if_fail(path != NULL && strlen(path) != 0, NULL);
zathura_database_t* db = g_object_new(ZATHURA_TYPE_SQLDATABASE, "path", path, NULL);
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
ZathuraSQLDatabasePrivate* priv = zathura_sqldatabase_get_instance_private(ZATHURA_SQLDATABASE(db));
if (priv->session == NULL) {
g_object_unref(G_OBJECT(db));
return NULL;
......@@ -114,7 +109,7 @@ static void
sqlite_finalize(GObject* object)
{
ZathuraSQLDatabase* db = ZATHURA_SQLDATABASE(object);
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
ZathuraSQLDatabasePrivate* priv = zathura_sqldatabase_get_instance_private(db);
if (priv->session) {
sqlite3_exec(priv->session, "VACUUM;", NULL, 0, NULL);
sqlite3_close(priv->session);
......@@ -126,7 +121,7 @@ sqlite_finalize(GObject* object)
static void
sqlite_db_init(ZathuraSQLDatabase* db, const char* path)
{
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
ZathuraSQLDatabasePrivate* priv = zathura_sqldatabase_get_instance_private(db);
/* create bookmarks table */
static const char SQL_BOOKMARK_INIT[] =
......@@ -296,8 +291,8 @@ sqlite_db_init(ZathuraSQLDatabase* db, const char* path)
static void
sqlite_set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec)
{
ZathuraSQLDatabase* db = ZATHURA_SQLDATABASE(object);
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
ZathuraSQLDatabase* db = ZATHURA_SQLDATABASE(object);
ZathuraSQLDatabasePrivate* priv = zathura_sqldatabase_get_instance_private(db);
switch (prop_id) {
case PROP_PATH:
......@@ -406,7 +401,8 @@ static bool
sqlite_add_bookmark(zathura_database_t* db, const char* file,
zathura_bookmark_t* bookmark)
{
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
ZathuraSQLDatabase* sqldb = ZATHURA_SQLDATABASE(db);
ZathuraSQLDatabasePrivate* priv = zathura_sqldatabase_get_instance_private(sqldb);
static const char SQL_BOOKMARK_ADD[] =
"REPLACE INTO bookmarks (file, id, page, hadj_ratio, vadj_ratio) VALUES (?, ?, ?, ?, ?);";
......@@ -436,7 +432,8 @@ static bool
sqlite_remove_bookmark(zathura_database_t* db, const char* file, const char*
id)
{
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
ZathuraSQLDatabase* sqldb = ZATHURA_SQLDATABASE(db);
ZathuraSQLDatabasePrivate* priv = zathura_sqldatabase_get_instance_private(sqldb);
static const char SQL_BOOKMARK_ADD[] =
"DELETE FROM bookmarks WHERE file = ? AND id = ?;";
......@@ -462,7 +459,8 @@ sqlite_remove_bookmark(zathura_database_t* db, const char* file, const char*
static girara_list_t*
sqlite_load_bookmarks(zathura_database_t* db, const char* file)
{
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
ZathuraSQLDatabase* sqldb = ZATHURA_SQLDATABASE(db);
ZathuraSQLDatabasePrivate* priv = zathura_sqldatabase_get_instance_private(sqldb);
static const char SQL_BOOKMARK_SELECT[] =
"SELECT id, page, hadj_ratio, vadj_ratio FROM bookmarks WHERE file = ?;";
......@@ -513,9 +511,11 @@ sqlite_save_jumplist(zathura_database_t* db, const char* file, girara_list_t* ju
static const char SQL_INSERT_JUMP[] = "INSERT INTO jumplist (file, page, hadj_ratio, vadj_ratio) VALUES (?, ?, ?, ?);";
static const char SQL_REMOVE_JUMPLIST[] = "DELETE FROM jumplist WHERE file = ?;";
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
sqlite3_stmt* stmt = NULL;
int res = 0;
ZathuraSQLDatabase* sqldb = ZATHURA_SQLDATABASE(db);
ZathuraSQLDatabasePrivate* priv = zathura_sqldatabase_get_instance_private(sqldb);
sqlite3_stmt* stmt = NULL;
int res = 0;
if (sqlite3_exec(priv->session, "BEGIN;", NULL, 0, NULL) != SQLITE_OK) {
return false;
......@@ -591,9 +591,10 @@ sqlite_load_jumplist(zathura_database_t* db, const char* file)
static const char SQL_GET_JUMPLIST[] = "SELECT page, hadj_ratio, vadj_ratio FROM jumplist WHERE file = ? ORDER BY id ASC;";
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
sqlite3_stmt* stmt = prepare_statement(priv->session, SQL_GET_JUMPLIST);
ZathuraSQLDatabase* sqldb = ZATHURA_SQLDATABASE(db);
ZathuraSQLDatabasePrivate* priv = zathura_sqldatabase_get_instance_private(sqldb);
sqlite3_stmt* stmt = prepare_statement(priv->session, SQL_GET_JUMPLIST);
if (stmt == NULL) {
return NULL;
}
......@@ -643,7 +644,8 @@ sqlite_set_fileinfo(zathura_database_t* db, const char* file,
return false;
}
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
ZathuraSQLDatabase* sqldb = ZATHURA_SQLDATABASE(db);
ZathuraSQLDatabasePrivate* priv = zathura_sqldatabase_get_instance_private(sqldb);
static const char SQL_FILEINFO_SET[] =
"REPLACE INTO fileinfo (file, page, offset, zoom, rotation, pages_per_row, first_page_column, position_x, position_y, time) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, DATETIME('now'));";
......@@ -682,7 +684,8 @@ sqlite_get_fileinfo(zathura_database_t* db, const char* file,
return false;
}
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
ZathuraSQLDatabase* sqldb = ZATHURA_SQLDATABASE(db);
ZathuraSQLDatabasePrivate* priv = zathura_sqldatabase_get_instance_private(sqldb);
static const char SQL_FILEINFO_GET[] =
"SELECT page, offset, zoom, rotation, pages_per_row, first_page_column, position_x, position_y FROM fileinfo WHERE file = ?;";
......@@ -724,7 +727,9 @@ sqlite_io_append(GiraraInputHistoryIO* db, const char* input)
static const char SQL_HISTORY_SET[] =
"REPLACE INTO history (line, time) VALUES (?, DATETIME('now'));";
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
ZathuraSQLDatabase* sqldb = ZATHURA_SQLDATABASE(db);
ZathuraSQLDatabasePrivate* priv = zathura_sqldatabase_get_instance_private(sqldb);
sqlite3_stmt* stmt = prepare_statement(priv->session, SQL_HISTORY_SET);
if (stmt == NULL) {
return;
......@@ -746,7 +751,9 @@ sqlite_io_read(GiraraInputHistoryIO* db)
static const char SQL_HISTORY_GET[] =
"SELECT line FROM history ORDER BY time";
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
ZathuraSQLDatabase* sqldb = ZATHURA_SQLDATABASE(db);
ZathuraSQLDatabasePrivate* priv = zathura_sqldatabase_get_instance_private(sqldb);
sqlite3_stmt* stmt = prepare_statement(priv->session, SQL_HISTORY_GET);
if (stmt == NULL) {
return NULL;
......@@ -774,7 +781,9 @@ sqlite_get_recent_files(zathura_database_t* db, int max, const char* basepath)
static const char SQL_HISTORY_GET_WITH_BASEPATH[] =
"SELECT file FROM fileinfo WHERE file LIKE ? || '%' ORDER BY time DESC LIMIT ?";
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
ZathuraSQLDatabase* sqldb = ZATHURA_SQLDATABASE(db);
ZathuraSQLDatabasePrivate* priv = zathura_sqldatabase_get_instance_private(sqldb);
sqlite3_stmt* stmt = prepare_statement(priv->session, basepath == NULL ? SQL_HISTORY_GET : SQL_HISTORY_GET_WITH_BASEPATH);
if (stmt == NULL) {
return NULL;
......
......@@ -30,33 +30,30 @@ static GBytes* load_xml_data(void)
return NULL;
}
G_DEFINE_TYPE(ZathuraDbus, zathura_dbus, G_TYPE_OBJECT)
/* template for bus name */
static const char DBUS_NAME_TEMPLATE[] = "org.pwmt.zathura.PID-%d";
/* object path */
static const char DBUS_OBJPATH[] = "/org/pwmt/zathura";
/* interface name */
static const char DBUS_INTERFACE[] = "org.pwmt.zathura";
typedef struct private_s {
zathura_t* zathura;
GDBusNodeInfo* introspection_data;
GDBusConnection* connection;
guint owner_id;
guint registration_id;
} private_t;
} ZathuraDbusPrivate;
G_DEFINE_TYPE_WITH_CODE(ZathuraDbus, zathura_dbus, G_TYPE_OBJECT, G_ADD_PRIVATE(ZathuraDbus))
#define GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), ZATHURA_TYPE_DBUS, private_t))
/* template for bus name */
static const char DBUS_NAME_TEMPLATE[] = "org.pwmt.zathura.PID-%d";
/* object path */
static const char DBUS_OBJPATH[] = "/org/pwmt/zathura";
/* interface name */
static const char DBUS_INTERFACE[] = "org.pwmt.zathura";
static const GDBusInterfaceVTable interface_vtable;
static void
finalize(GObject* object)
{
ZathuraDbus* dbus = ZATHURA_DBUS(object);
private_t* priv = GET_PRIVATE(dbus);
ZathuraDbus* dbus = ZATHURA_DBUS(object);
ZathuraDbusPrivate* priv = zathura_dbus_get_instance_private(dbus);
if (priv->connection != NULL && priv->registration_id > 0) {
g_dbus_connection_unregister_object(priv->connection, priv->registration_id);
......@@ -76,9 +73,6 @@ finalize(GObject* object)
static void
zathura_dbus_class_init(ZathuraDbusClass* class)
{
/* add private members */
g_type_class_add_private(class, sizeof(private_t));
/* overwrite methods */
GObjectClass* object_class = G_OBJECT_CLASS(class);
object_class->finalize = finalize;
......@@ -87,7 +81,7 @@ zathura_dbus_class_init(ZathuraDbusClass* class)
static void
zathura_dbus_init(ZathuraDbus* dbus)
{
private_t* priv = GET_PRIVATE(dbus);
ZathuraDbusPrivate* priv = zathura_dbus_get_instance_private(dbus);
priv->zathura = NULL;
priv->introspection_data = NULL;
priv->connection = NULL;
......@@ -113,8 +107,8 @@ bus_acquired(GDBusConnection* connection, const gchar* name, void* data)
g_signal_connect(G_OBJECT(connection), "closed",
G_CALLBACK(gdbus_connection_closed), NULL);
ZathuraDbus* dbus = data;
private_t* priv = GET_PRIVATE(dbus);
ZathuraDbus* dbus = data;
ZathuraDbusPrivate* priv = zathura_dbus_get_instance_private(dbus);
GError* error = NULL;
priv->registration_id = g_dbus_connection_register_object(
......@@ -154,7 +148,7 @@ zathura_dbus_new(zathura_t* zathura)
}
ZathuraDbus* dbus = ZATHURA_DBUS(obj);
private_t* priv = GET_PRIVATE(dbus);
ZathuraDbusPrivate* priv = zathura_dbus_get_instance_private(dbus);
priv->zathura = zathura;
GBytes* xml_data = load_xml_data();
......@@ -187,7 +181,7 @@ zathura_dbus_new(zathura_t* zathura)
void
zathura_dbus_edit(ZathuraDbus* edit, unsigned int page, unsigned int x, unsigned int y) {
private_t* priv = GET_PRIVATE(edit);
ZathuraDbusPrivate* priv = zathura_dbus_get_instance_private(edit);
const char* filename = zathura_document_get_path(priv->zathura->document);
......@@ -393,7 +387,7 @@ handle_method_call(GDBusConnection* UNUSED(connection),
void* data)
{
ZathuraDbus* dbus = data;
private_t* priv = GET_PRIVATE(dbus);
ZathuraDbusPrivate* priv = zathura_dbus_get_instance_private(dbus);
girara_debug("Handling call '%s.%s' on '%s'.", interface_name, method_name,
object_path);
......@@ -434,8 +428,8 @@ handle_get_property(GDBusConnection* UNUSED(connection),
const gchar* UNUSED(interface_name),
const gchar* property_name, GError** error, void* data)
{
ZathuraDbus* dbus = data;
private_t* priv = GET_PRIVATE(dbus);
ZathuraDbus* dbus = data;
ZathuraDbusPrivate* priv = zathura_dbus_get_instance_private(dbus);
if (priv->zathura->document == NULL) {
g_set_error(error, G_IO_ERROR, G_IO_ERROR_FAILED, "No document open.");
......
......@@ -9,14 +9,11 @@
#include <girara/utils.h>
G_DEFINE_TYPE(ZathuraFileMonitor, zathura_filemonitor, G_TYPE_OBJECT)
typedef struct private_s {
char* file_path;
} private_t;
} ZathuraFileMonitorPrivate;
#define GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), ZATHURA_TYPE_FILEMONITOR, private_t))
G_DEFINE_TYPE_WITH_CODE(ZathuraFileMonitor, zathura_filemonitor, G_TYPE_OBJECT, G_ADD_PRIVATE(ZathuraFileMonitor))
enum {
PROP_0,
......@@ -34,7 +31,7 @@ static void
finalize(GObject* object)
{
ZathuraFileMonitor* file_monitor = ZATHURA_FILEMONITOR(object);
private_t* private = GET_PRIVATE(file_monitor);
ZathuraFileMonitorPrivate* private = zathura_filemonitor_get_instance_private(file_monitor);
if (private->file_path != NULL) {
g_free(private->file_path);
......@@ -47,7 +44,7 @@ static void
set_property(GObject* object, guint prop_id, const GValue* value, GParamSpec* pspec)
{
ZathuraFileMonitor* file_monitor = ZATHURA_FILEMONITOR(object);
private_t* private = GET_PRIVATE(file_monitor);
ZathuraFileMonitorPrivate* private = zathura_filemonitor_get_instance_private(file_monitor);
switch (prop_id) {
case PROP_FILE_PATH:
......@@ -65,7 +62,7 @@ static void
get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec)
{
ZathuraFileMonitor* file_monitor = ZATHURA_FILEMONITOR(object);
private_t* private = GET_PRIVATE(file_monitor);
ZathuraFileMonitorPrivate* private = zathura_filemonitor_get_instance_private(file_monitor);
switch (prop_id) {
case PROP_FILE_PATH:
......@@ -79,9 +76,6 @@ get_property(GObject* object, guint prop_id, GValue* value, GParamSpec* pspec)
static void
zathura_filemonitor_class_init(ZathuraFileMonitorClass* class)
{
/* add private members */
g_type_class_add_private(class, sizeof(private_t));
/* set up methods */
class->start = NULL;
class->stop = NULL;
......@@ -107,14 +101,13 @@ zathura_filemonitor_class_init(ZathuraFileMonitorClass* class)
static void
zathura_filemonitor_init(ZathuraFileMonitor* file_monitor)
{
private_t* private = GET_PRIVATE(file_monitor);
private->file_path = NULL;
ZathuraFileMonitorPrivate* private = zathura_filemonitor_get_instance_private(file_monitor);
private->file_path = NULL;
}
const char* zathura_filemonitor_get_filepath(ZathuraFileMonitor* file_monitor)
{
private_t* private = GET_PRIVATE(file_monitor);
ZathuraFileMonitorPrivate* private = zathura_filemonitor_get_instance_private(file_monitor);
return private->file_path;
}
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment