6 G_DEFINE_TYPE(GiraraInputHistory, girara_input_history, G_TYPE_OBJECT)
11 typedef struct ih_private_s {
20 #define GIRARA_INPUT_HISTORY_GET_PRIVATE(obj) \
21 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GIRARA_TYPE_INPUT_HISTORY, \
25 static void ih_dispose(GObject*
object);
26 static void ih_finalize(GObject*
object);
27 static void ih_set_property(GObject*
object, guint prop_id,
28 const GValue* value, GParamSpec* pspec);
29 static void ih_get_property(GObject*
object, guint prop_id, GValue* value,
31 static void ih_append(GiraraInputHistory* history,
const char* input);
32 static girara_list_t* ih_list(GiraraInputHistory* history);
33 static const char* ih_next(GiraraInputHistory* history,
34 const char* current_input);
35 static const char* ih_previous(GiraraInputHistory* history,
36 const char* current_input);
37 static void ih_reset(GiraraInputHistory* history);
47 girara_input_history_class_init(GiraraInputHistoryClass*
class)
53 GObjectClass* object_class = G_OBJECT_CLASS(
class);
54 object_class->dispose = ih_dispose;
55 object_class->finalize = ih_finalize;
56 object_class->set_property = ih_set_property;
57 object_class->get_property = ih_get_property;
59 class->append = ih_append;
60 class->list = ih_list;
61 class->next = ih_next;
62 class->previous = ih_previous;
63 class->reset = ih_reset;
66 g_object_class_install_property(object_class,
PROP_IO,
67 g_param_spec_object(
"io",
"history reader/writer",
68 "GiraraInputHistoryIO object used to read and write history",
70 G_PARAM_WRITABLE | G_PARAM_READABLE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
75 girara_input_history_init(GiraraInputHistory* history)
85 ih_dispose(GObject*
object)
89 g_clear_object(&priv->
io);
91 G_OBJECT_CLASS(girara_input_history_parent_class)->dispose(
object);
96 ih_finalize(GObject*
object)
102 G_OBJECT_CLASS(girara_input_history_parent_class)->finalize(
object);
107 ih_set_property(GObject*
object, guint prop_id,
const GValue* value,
114 if (priv->
io != NULL) {
115 g_object_unref(priv->
io);
118 gpointer* tmp = g_value_dup_object(value);
128 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
134 ih_get_property(GObject*
object, guint prop_id, GValue* value,
141 g_value_set_object(value, priv->
io);
144 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
159 ih_append(GiraraInputHistory* history,
const char* input)
178 if (priv->
io != NULL) {
186 static girara_list_t*
187 ih_list(GiraraInputHistory* history)
194 find_next(GiraraInputHistory* history,
const char* current_input,
bool next)
208 if (priv->
reset ==
true) {
220 const char* command = NULL;
222 if (priv->
reset ==
true || next ==
false) {
230 }
else if (next ==
true) {
231 if (priv->
current + 1 >= length) {
244 if (command == NULL) {
266 ih_next(GiraraInputHistory* history,
const char* current_input)
268 return find_next(history, current_input,
true);
272 ih_previous(GiraraInputHistory* history,
const char* current_input)
274 return find_next(history, current_input,
false);
278 ih_reset(GiraraInputHistory* history)
283 if (priv->
io != NULL) {
291 if (newlist != NULL) {
void girara_list_remove(girara_list_t *list, void *data)
void * girara_list_nth(girara_list_t *list, size_t n)
#define GIRARA_INPUT_HISTORY(obj)
void girara_list_append(girara_list_t *list, void *data)
GType girara_input_history_io_get_type(void)
void(* girara_free_function_t)(void *data)
size_t girara_list_size(girara_list_t *list)
girara_list_t * girara_list_new2(girara_free_function_t gfree)
#define GIRARA_INPUT_HISTORY_IO(obj)
void girara_input_history_io_append(GiraraInputHistoryIO *io, const char *input)
#define GIRARA_INPUT_HISTORY_GET_PRIVATE(obj)
void girara_list_free(girara_list_t *list)
struct girara_input_history_io_s GiraraInputHistoryIO
void * girara_list_find(girara_list_t *list, girara_compare_function_t compare, const void *data)
int(* girara_compare_function_t)(const void *data1, const void *data2)
GiraraInputHistoryIO * io
void girara_input_history_reset(GiraraInputHistory *history)
const char * girara_input_history_previous(GiraraInputHistory *history, const char *current_input)
#define GIRARA_IS_INPUT_HISTORY(obj)
girara_list_t * girara_input_history_list(GiraraInputHistory *history)
const char * girara_input_history_next(GiraraInputHistory *history, const char *current_input)
girara_list_t * girara_input_history_io_read(GiraraInputHistoryIO *io)
#define GIRARA_INPUT_HISTORY_GET_CLASS(obj)
GiraraInputHistory * girara_input_history_new(GiraraInputHistoryIO *io)
void girara_list_clear(girara_list_t *list)
#define GIRARA_TYPE_INPUT_HISTORY
void girara_input_history_append(GiraraInputHistory *history, const char *input)
#define GIRARA_LIST_FOREACH_END(list, type, iter, data)
#define GIRARA_LIST_FOREACH(list, type, iter, data)