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_finalize(GObject*
object);
26 static void ih_set_property(GObject*
object, guint prop_id,
27 const GValue* value, GParamSpec* pspec);
28 static void ih_get_property(GObject*
object, guint prop_id, GValue* value,
30 static void ih_append(GiraraInputHistory* history,
const char* input);
31 static girara_list_t* ih_list(GiraraInputHistory* history);
32 static const char* ih_next(GiraraInputHistory* history,
33 const char* current_input);
34 static const char* ih_previous(GiraraInputHistory* history,
35 const char* current_input);
36 static void ih_reset(GiraraInputHistory* history);
46 girara_input_history_class_init(GiraraInputHistoryClass*
class)
52 GObjectClass* object_class = G_OBJECT_CLASS(
class);
53 object_class->finalize = ih_finalize;
54 object_class->set_property = ih_set_property;
55 object_class->get_property = ih_get_property;
57 class->append = ih_append;
58 class->list = ih_list;
59 class->next = ih_next;
60 class->previous = ih_previous;
61 class->reset = ih_reset;
64 g_object_class_install_property(object_class,
PROP_IO,
65 g_param_spec_object(
"io",
"history reader/writer",
66 "GiraraInputHistoryIO object used to read and write history",
68 G_PARAM_WRITABLE | G_PARAM_READABLE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));
73 girara_input_history_init(GiraraInputHistory* history)
83 ih_finalize(GObject*
object)
89 if (priv->
io != NULL) {
90 g_object_unref(priv->
io);
93 G_OBJECT_CLASS(girara_input_history_parent_class)->finalize(
object);
98 ih_set_property(GObject*
object, guint prop_id,
const GValue* value,
105 if (priv->
io != NULL) {
106 g_object_unref(priv->
io);
109 gpointer* tmp = g_value_dup_object(value);
119 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
125 ih_get_property(GObject*
object, guint prop_id, GValue* value,
132 g_value_set_object(value, priv->
io);
135 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
150 ih_append(GiraraInputHistory* history,
const char* input)
169 if (priv->
io != NULL) {
177 static girara_list_t*
178 ih_list(GiraraInputHistory* history)
185 find_next(GiraraInputHistory* history,
const char* current_input,
bool next)
199 if (priv->
reset ==
true) {
211 const char* command = NULL;
213 if (priv->
reset ==
true || next ==
false) {
221 }
else if (next ==
true) {
222 if (priv->
current + 1 >= length) {
235 if (command == NULL) {
257 ih_next(GiraraInputHistory* history,
const char* current_input)
259 return find_next(history, current_input,
true);
263 ih_previous(GiraraInputHistory* history,
const char* current_input)
265 return find_next(history, current_input,
false);
269 ih_reset(GiraraInputHistory* history)
274 if (priv->
io != NULL) {
282 if (newlist != NULL) {