Commit 169d66c0 authored by Sebastian Ramacher's avatar Sebastian Ramacher

Use G_ADD_PRIVATE

Fix deprecation warnings with glib 2.58.
parent b8416ea9
......@@ -3,10 +3,8 @@
#include "input-history.h"
#include "datastructures.h"
G_DEFINE_TYPE(GiraraInputHistory, girara_input_history, G_TYPE_OBJECT)
/**
* Private data of the settings manager
* Private data of the input history
*/
typedef struct ih_private_s {
girara_list_t* history; /**< List of stored inputs */
......@@ -15,11 +13,9 @@ typedef struct ih_private_s {
size_t current_match;
GiraraInputHistoryIO* io;
char* command_line;
} ih_private_t;
} GiraraInputHistoryPrivate;
#define GIRARA_INPUT_HISTORY_GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIRARA_TYPE_INPUT_HISTORY, \
ih_private_t))
G_DEFINE_TYPE_WITH_CODE(GiraraInputHistory, girara_input_history, G_TYPE_OBJECT, G_ADD_PRIVATE(GiraraInputHistory))
/* Methods */
static void ih_dispose(GObject* object);
......@@ -46,9 +42,6 @@ enum {
static void
girara_input_history_class_init(GiraraInputHistoryClass* class)
{
/* add private members */
g_type_class_add_private(class, sizeof(ih_private_t));
/* overwrite methods */
GObjectClass* object_class = G_OBJECT_CLASS(class);
object_class->dispose = ih_dispose;
......@@ -74,7 +67,7 @@ girara_input_history_class_init(GiraraInputHistoryClass* class)
static void
girara_input_history_init(GiraraInputHistory* history)
{
ih_private_t* priv = GIRARA_INPUT_HISTORY_GET_PRIVATE(history);
GiraraInputHistoryPrivate* priv = girara_input_history_get_instance_private(history);
priv->history = girara_list_new2((girara_free_function_t) g_free);
priv->reset = true;
priv->io = NULL;
......@@ -84,7 +77,8 @@ girara_input_history_init(GiraraInputHistory* history)
static void
ih_dispose(GObject* object)
{
ih_private_t* priv = GIRARA_INPUT_HISTORY_GET_PRIVATE(object);
GiraraInputHistory* ih = GIRARA_INPUT_HISTORY(object);
GiraraInputHistoryPrivate* priv = girara_input_history_get_instance_private(ih);
g_clear_object(&priv->io);
......@@ -95,7 +89,8 @@ ih_dispose(GObject* object)
static void
ih_finalize(GObject* object)
{
ih_private_t* priv = GIRARA_INPUT_HISTORY_GET_PRIVATE(object);
GiraraInputHistory* ih = GIRARA_INPUT_HISTORY(object);
GiraraInputHistoryPrivate* priv = girara_input_history_get_instance_private(ih);
girara_list_free(priv->history);
g_free(priv->command_line);
......@@ -107,7 +102,8 @@ static void
ih_set_property(GObject* object, guint prop_id, const GValue* value,
GParamSpec* pspec)
{
ih_private_t* priv = GIRARA_INPUT_HISTORY_GET_PRIVATE(object);
GiraraInputHistory* ih = GIRARA_INPUT_HISTORY(object);
GiraraInputHistoryPrivate* priv = girara_input_history_get_instance_private(ih);
switch (prop_id) {
case PROP_IO: {
......@@ -130,7 +126,8 @@ static void
ih_get_property(GObject* object, guint prop_id, GValue* value,
GParamSpec* pspec)
{
ih_private_t* priv = GIRARA_INPUT_HISTORY_GET_PRIVATE(object);
GiraraInputHistory* ih = GIRARA_INPUT_HISTORY(object);
GiraraInputHistoryPrivate* priv = girara_input_history_get_instance_private(ih);
switch (prop_id) {
case PROP_IO:
......@@ -170,7 +167,7 @@ ih_append(GiraraInputHistory* history, const char* input)
girara_list_append(list, g_strdup(input));
ih_private_t* priv = GIRARA_INPUT_HISTORY_GET_PRIVATE(history);
GiraraInputHistoryPrivate* priv = girara_input_history_get_instance_private(history);
if (priv->io != NULL) {
girara_input_history_io_append(priv->io, input);
}
......@@ -182,14 +179,14 @@ ih_append(GiraraInputHistory* history, const char* input)
static girara_list_t*
ih_list(GiraraInputHistory* history)
{
ih_private_t* priv = GIRARA_INPUT_HISTORY_GET_PRIVATE(history);
GiraraInputHistoryPrivate* priv = girara_input_history_get_instance_private(history);
return priv->history;
}
static const char*
find_next(GiraraInputHistory* history, const char* current_input, bool next)
{
ih_private_t* priv = GIRARA_INPUT_HISTORY_GET_PRIVATE(history);
GiraraInputHistoryPrivate* priv = girara_input_history_get_instance_private(history);
girara_list_t* list = girara_input_history_list(history);
if (list == NULL) {
......@@ -269,7 +266,7 @@ ih_previous(GiraraInputHistory* history, const char* current_input)
static void
ih_reset(GiraraInputHistory* history)
{
ih_private_t* priv = GIRARA_INPUT_HISTORY_GET_PRIVATE(history);
GiraraInputHistoryPrivate* priv = girara_input_history_get_instance_private(history);
priv->reset = true;
if (priv->io != NULL) {
......
......@@ -6,8 +6,6 @@
#include <glib.h>
G_DEFINE_TYPE(GiraraTemplate, girara_template, G_TYPE_OBJECT)
/**
* Private data of the template
*/
......@@ -18,12 +16,9 @@ typedef struct private_s {
girara_list_t* variables_in_base;
girara_list_t* variables;
bool valid;
} private_t;
typedef struct private_s GiraraTemplatePrivate;
} GiraraTemplatePrivate;
#define GET_PRIVATE(obj) \
(G_TYPE_INSTANCE_GET_PRIVATE((obj), GIRARA_TYPE_TEMPLATE, private_t))
G_DEFINE_TYPE_WITH_CODE(GiraraTemplate, girara_template, G_TYPE_OBJECT, G_ADD_PRIVATE(GiraraTemplate))
/**
* Internal variables
......@@ -109,9 +104,6 @@ static guint signals[LAST_SIGNAL] = { 0 };
static void
girara_template_class_init(GiraraTemplateClass* class)
{
/* add private members */
g_type_class_add_private(class, sizeof(private_t));
/* overwrite methods */
GObjectClass* object_class = G_OBJECT_CLASS(class);
object_class->dispose = dispose;
......@@ -184,7 +176,7 @@ girara_template_init(GiraraTemplate* history)
g_error_free(error);
}
private_t* priv = GET_PRIVATE(history);
GiraraTemplatePrivate* priv = girara_template_get_instance_private(history);
priv->base = g_strdup("");
priv->variable_regex = regex;
priv->variable_check_regex = check_regex;
......@@ -197,7 +189,8 @@ girara_template_init(GiraraTemplate* history)
static void
dispose(GObject* object)
{
private_t* priv = GET_PRIVATE(object);
GiraraTemplate* obj = GIRARA_TEMPLATE(object);
GiraraTemplatePrivate* priv = girara_template_get_instance_private(obj);
g_regex_unref(priv->variable_regex);
g_regex_unref(priv->variable_check_regex);
......@@ -212,7 +205,8 @@ dispose(GObject* object)
static void
finalize(GObject* object)
{
private_t* priv = GET_PRIVATE(object);
GiraraTemplate* obj = GIRARA_TEMPLATE(object);
GiraraTemplatePrivate* priv = girara_template_get_instance_private(obj);
g_free(priv->base);
girara_list_free(priv->variables_in_base);
......@@ -277,7 +271,7 @@ girara_template_set_base(GiraraTemplate* object, const char* base)
{
g_return_if_fail(GIRARA_IS_TEMPLATE(object));
private_t* priv = GET_PRIVATE(object);
GiraraTemplatePrivate* priv = girara_template_get_instance_private(object);
if (g_strcmp0(base, priv->base) != 0) {
g_free(priv->base);
priv->base = g_strdup(base != NULL ? base : "");
......@@ -292,14 +286,14 @@ girara_template_get_base(GiraraTemplate* object)
{
g_return_val_if_fail(GIRARA_IS_TEMPLATE(object), NULL);
private_t* priv = GET_PRIVATE(object);
GiraraTemplatePrivate* priv = girara_template_get_instance_private(object);
return priv->base;
}
static void
base_changed(GiraraTemplate* object)
{
private_t* priv = GET_PRIVATE(object);
GiraraTemplatePrivate* priv = girara_template_get_instance_private(object);
girara_list_clear(priv->variables_in_base);
priv->valid = true;
......@@ -333,7 +327,7 @@ base_changed(GiraraTemplate* object)
static void
variable_changed(GiraraTemplate* object, const char* GIRARA_UNUSED(name))
{
private_t* priv = GET_PRIVATE(object);
GiraraTemplatePrivate* priv = girara_template_get_instance_private(object);
priv->valid = true;
GIRARA_LIST_FOREACH_BODY(priv->variables_in_base, char*, variable,
......@@ -355,7 +349,7 @@ girara_template_referenced_variables(GiraraTemplate* object)
{
g_return_val_if_fail(GIRARA_IS_TEMPLATE(object), NULL);
private_t* priv = GET_PRIVATE(object);
GiraraTemplatePrivate* priv = girara_template_get_instance_private(object);
return priv->variables_in_base;
}
......@@ -365,7 +359,7 @@ girara_template_add_variable(GiraraTemplate* object, const char* name)
g_return_val_if_fail(GIRARA_IS_TEMPLATE(object), false);
g_return_val_if_fail(name != NULL, false);
private_t* priv = GET_PRIVATE(object);
GiraraTemplatePrivate* priv = girara_template_get_instance_private(object);
if (g_regex_match(priv->variable_check_regex, name, 0, NULL) == FALSE) {
girara_debug("'%s' is not a valid variable name.", name);
......@@ -400,7 +394,7 @@ girara_template_set_variable_value(GiraraTemplate* object, const char* name,
g_return_if_fail(name != NULL);
g_return_if_fail(value != NULL);
private_t* priv = GET_PRIVATE(object);
GiraraTemplatePrivate* priv = girara_template_get_instance_private(object);
variable_t* variable = girara_list_find(priv->variables, compare_variable_name,
name);
......@@ -439,7 +433,7 @@ girara_template_evaluate(GiraraTemplate* object)
{
g_return_val_if_fail(GIRARA_IS_TEMPLATE(object), NULL);
private_t* priv = GET_PRIVATE(object);
GiraraTemplatePrivate* priv = girara_template_get_instance_private(object);
if (priv->valid == false) {
girara_error("Base contains variables that do not have a value assigned.");
return NULL;
......
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