33 #include "qofundo-p.h" 46 struct QofUndoEntity_t
57 struct QofUndoOperation_t
75 void (*string_setter) (
QofEntity *, gchar *);
80 void (*boolean_setter) (
QofEntity *, gboolean);
83 if (0 ==
safe_strcmp (param->param_type, QOF_TYPE_STRING))
86 (void (*)(
QofEntity *, gchar *)) param->param_setfcn;
89 param->param_setfcn (ent, value);
92 if (0 ==
safe_strcmp (param->param_type, QOF_TYPE_GUID))
94 cm_guid = g_new (
GUID, 1);
99 if (guid_setter != NULL)
101 guid_setter (ent, cm_guid);
105 if ((0 ==
safe_strcmp (param->param_type, QOF_TYPE_NUMERIC)) ||
106 (
safe_strcmp (param->param_type, QOF_TYPE_DEBCRED) == 0))
111 if (numeric_setter != NULL)
113 numeric_setter (ent, cli_numeric);
116 if (0 ==
safe_strcmp (param->param_type, QOF_TYPE_BOOLEAN))
124 (void (*)(
QofEntity *, gboolean)) param->param_setfcn;
125 if (boolean_setter != NULL)
127 boolean_setter (ent, cli_bool);
130 if (0 ==
safe_strcmp (param->param_type, QOF_TYPE_INT32))
133 cli_i32 = (gint32) strtol (value, &tail, 0);
137 (void (*)(
QofEntity *, gint32)) param->param_setfcn;
138 if (i32_setter != NULL)
140 i32_setter (ent, cli_i32);
145 PERR (
" Cannot convert %s into a number: " 146 "an overflow has been detected.", value);
149 if (0 ==
safe_strcmp (param->param_type, QOF_TYPE_INT64))
152 cli_i64 = (gint64) strtol (value, &tail, 0);
156 (void (*)(
QofEntity *, gint64)) param->param_setfcn;
157 if (i64_setter != NULL)
159 i64_setter (ent, cli_i64);
164 PERR (
" Cannot convert %s into a number: " 165 "an overflow has been detected.", value);
168 if (0 ==
safe_strcmp (param->param_type, QOF_TYPE_TIME))
176 if ((time_setter != NULL) && qof_time_is_valid (cli_time))
178 time_setter (ent, cli_time);
181 if (0 ==
safe_strcmp (param->param_type, QOF_TYPE_CHAR))
183 param->param_setfcn (ent, value);
192 set_param (ent, param, value);
197 undo_from_kvp_helper (
const gchar * path,
KvpValue * content,
200 QofUndoEntity *undo_entity;
202 undo_entity = (QofUndoEntity *) data;
203 undo_entity->path = g_strdup (path);
210 QofUndoEntity *undo_entity;
214 undo_entity = g_new0 (QofUndoEntity, 1);
216 undo_entity->param = param;
217 undo_entity->how = UNDO_MODIFY;
218 undo_entity->type = ent->e_type;
220 if (0 == (
safe_strcmp (param->param_type, QOF_TYPE_KVP)))
231 qof_reinstate_entity (QofUndoEntity * undo_entity,
QofBook * book)
237 undo_param = undo_entity->param;
240 PINFO (
" reinstate:%s", undo_entity->type);
247 PINFO (
" undoing %s %s", undo_param->param_name, undo_entity->value);
248 set_param (ent, undo_param, undo_entity->value);
252 qof_recreate_entity (QofUndoEntity * undo_entity,
QofBook * book)
259 guid = undo_entity->guid;
260 type = undo_entity->type;
261 g_return_if_fail (guid || type);
268 qof_dump_entity (QofUndoEntity * undo_entity,
QofBook * book)
275 type = undo_entity->type;
276 guid = undo_entity->guid;
277 g_return_if_fail (type || book);
286 QofUndoOperation *undo_operation;
287 QofUndoEntity *undo_entity;
292 if (book_undo->index_position > 1)
293 book_undo->index_position--;
295 book_undo->index_position = 0;
298 *) (g_list_nth (book_undo->undo_list,
299 book_undo->index_position))->data;
300 g_return_if_fail (undo_operation);
301 ent_list = undo_operation->entity_list;
302 while (ent_list != NULL)
304 undo_entity = (QofUndoEntity *) ent_list->data;
307 switch (undo_entity->how)
311 qof_reinstate_entity (undo_entity, book);
316 qof_recreate_entity (undo_entity, book);
321 qof_dump_entity (undo_entity, book);
329 ent_list = g_list_next (ent_list);
336 QofUndoOperation *undo_operation;
337 QofUndoEntity *undo_entity;
345 *) (g_list_nth (book_undo->undo_list,
346 book_undo->index_position))->data;
349 ent_list = undo_operation->entity_list;
350 while (ent_list != NULL)
352 undo_entity = (QofUndoEntity *) ent_list->data;
355 switch (undo_entity->how)
359 qof_reinstate_entity (undo_entity, book);
364 qof_dump_entity (undo_entity, book);
369 qof_recreate_entity (undo_entity, book);
377 ent_list = g_list_next (ent_list);
379 length = g_list_length (book_undo->undo_list);
380 if (book_undo->index_position < length)
381 book_undo->index_position++;
383 book_undo->index_position = length;
389 QofUndoOperation *operation;
395 while (book_undo != NULL)
397 operation = (QofUndoOperation *) book_undo->undo_list->data;
398 if(operation->entity_list)
399 g_list_free (operation->entity_list);
400 book_undo->undo_list = g_list_next (book_undo->undo_list);
402 book_undo->index_position = 0;
403 g_free (book_undo->undo_label);
413 length = g_list_length (book_undo->undo_list);
414 if ((book_undo->index_position == 0) || (length == 0))
426 length = g_list_length (book_undo->undo_list);
427 if ((book_undo->index_position == length) || (length == 0))
433 qof_undo_new_operation (
QofBook * book, gchar * label)
435 QofUndoOperation *undo_operation;
438 undo_operation = NULL;
440 undo_operation = g_new0 (QofUndoOperation, 1);
441 undo_operation->label = label;
443 undo_operation->entity_list = NULL;
444 g_list_foreach (book_undo->undo_cache,
445 qof_undo_new_entry, undo_operation);
446 return undo_operation;
450 qof_undo_new_entry (gpointer cache, gpointer operation)
452 QofUndoOperation *undo_operation;
453 QofUndoEntity *undo_entity;
455 g_return_if_fail (operation || cache);
456 undo_operation = (QofUndoOperation *) operation;
457 undo_entity = (QofUndoEntity *) cache;
458 g_return_if_fail (undo_operation || undo_entity);
459 undo_operation->entity_list =
460 g_list_prepend (undo_operation->entity_list, undo_entity);
466 QofUndoEntity *undo_entity;
472 book = instance->
book;
474 undo_entity = g_new0 (QofUndoEntity, 1);
476 undo_entity->how = UNDO_DELETE;
478 undo_entity->type = instance->
entity.e_type;
479 book_undo->undo_cache =
480 g_list_prepend (book_undo->undo_cache, undo_entity);
484 undo_get_entity (
QofParam * param, gpointer data)
489 QofUndoEntity *undo_entity;
492 book = instance->
book;
494 g_return_if_fail (instance || param);
495 undo_entity = qof_prepare_undo (&instance->
entity, param);
496 book_undo->undo_cache =
497 g_list_prepend (book_undo->undo_cache, undo_entity);
503 QofUndoEntity *undo_entity;
510 book = instance->
book;
513 type = instance->
entity.e_type;
515 undo_entity = g_new0 (QofUndoEntity, 1);
517 undo_entity->how = UNDO_CREATE;
519 undo_entity->type = type;
520 book_undo->undo_cache =
521 g_list_prepend (book_undo->undo_cache, undo_entity);
529 QofUndoEntity *undo_entity;
531 if (!instance || !param)
533 book = instance->
book;
536 undo_entity = qof_prepare_undo (&instance->
entity, param);
537 book_undo->undo_cache =
538 g_list_prepend (book_undo->undo_cache, undo_entity);
540 if (book_undo->index_position == 0)
542 book_undo->undo_list = g_list_prepend (book_undo->undo_list,
543 qof_undo_new_operation (book,
"initial"));
544 book_undo->index_position++;
551 QofUndoEntity *undo_entity;
555 if (!instance || !param)
557 book = instance->
book;
559 undo_entity = qof_prepare_undo (&instance->
entity, param);
560 book_undo->undo_cache =
561 g_list_prepend (book_undo->undo_cache, undo_entity);
570 if (book_undo->undo_operation_open && book_undo->undo_cache)
572 g_list_free (book_undo->undo_cache);
573 book_undo->undo_operation_open = FALSE;
574 if (book_undo->undo_label)
575 g_free (book_undo->undo_label);
577 book_undo->undo_label = g_strdup (label);
578 book_undo->undo_operation_open = TRUE;
587 book_undo->undo_list = g_list_prepend (book_undo->undo_list,
588 qof_undo_new_operation (book, book_undo->undo_label));
589 book_undo->index_position++;
590 g_list_free (book_undo->undo_cache);
591 book_undo->undo_operation_open = FALSE;
597 QofUndoOperation *undo_operation;
602 (QofUndoOperation *) g_list_last (book_undo->undo_list);
603 return undo_operation->qt;
612 return g_list_length (book_undo->undo_list);
#define QOF_DATE_FORMAT_UTC
QOF UTC format, xsd:date compatible. QOF_UTC_DATE_FORMAT "%Y-%m-%dT%H:%M:%SZ".
#define PERR(format, args...)
gpointer qof_object_new_instance(QofIdTypeConst type_name, QofBook *book)
void qof_undo_delete(QofInstance *instance)
#define PINFO(format, args...)
QofCollection * qof_book_get_collection(QofBook *book, QofIdType entity_type)
struct _QofNumeric QofNumeric
A rational-number type.
gboolean qof_book_can_redo(QofBook *book)
event handler for redo widget
void qof_class_param_foreach(QofIdTypeConst obj_name, QofParamForeachCB cb, gpointer user_data)
void qof_book_start_operation(QofBook *book, gchar *label)
Start recording operation.
gboolean qof_book_can_undo(QofBook *book)
event handler for undo widget
gboolean string_to_guid(const gchar *string, GUID *guid)
void qof_book_end_operation(QofBook *book)
End recording the current operation.
KvpFrame * kvp_frame_copy(const KvpFrame *frame)
struct _KvpFrame KvpFrame
gint qof_util_bool_to_int(const gchar *val)
Private QofBook interface.
QofTime * qof_date_to_qtime(const QofDate *qd)
Full range replacement for struct tm.
QofTime * qof_time_get_current(void)
Get the current QofTime.
struct QofCollection_s QofCollection
const GUID * qof_instance_get_guid(QofInstance *inst)
QofDate * qof_date_parse(const gchar *str, QofDateFormat df)
Convert a timestamp to a QofTime.
struct _KvpValue KvpValue
gboolean qof_numeric_from_string(const gchar *str, QofNumeric *n)
QofEntity * qof_collection_lookup_entity(QofCollection *col, const GUID *guid)
gchar * qof_util_param_to_string(QofEntity *ent, const QofParam *param)
Converts a parameter to a string for storage or display.
void qof_entity_release(QofEntity *ent)
gchar * kvp_value_to_bare_string(const KvpValue *val)
General purpose function to convert any KvpValue to a string.
void qof_book_clear_undo(QofBook *book)
Free the entire undo list for this book.
QofTime * qof_book_undo_first_modified(QofBook *book)
HIG compliance aid to report time of first change.
void kvp_frame_for_each_slot(KvpFrame *f, KvpValueForeachCB proc, gpointer data)
void qof_book_undo(QofBook *book)
Set parameter values from before the previous event.
struct QofTime64 QofTime
Use a 64-bit signed int QofTime.
gint qof_book_undo_count(QofBook *book)
Number of undo operations available.
const GUID * qof_entity_get_guid(QofEntity *ent)
void qof_undo_create(QofInstance *instance)
void qof_entity_set_guid(QofEntity *ent, const GUID *guid)
gint safe_strcmp(const gchar *da, const gchar *db)
void qof_undo_commit(QofInstance *instance, const QofParam *param)
void qof_book_redo(QofBook *book)
Set parameter values from after the previous event.
void qof_undo_modify(QofInstance *instance, const QofParam *param)
const gchar * QofLogModule
void qof_undo_set_param(QofEntity *ent, const QofParam *param, gchar *value)
Set a value in this parameter of the entity.