static void destroy_employee_on_book_close(QofInstance *ent, gpointer data) { GncEmployee* e = GNC_EMPLOYEE(ent); gncEmployeeBeginEdit(e); gncEmployeeDestroy(e); }
/* ================================================================= */ static gboolean save_employee (GncSqlBackend* be, QofInstance* inst) { GncEmployee* emp; const GncGUID* guid; E_DB_OPERATION op; gboolean is_infant; gboolean is_ok = TRUE; g_return_val_if_fail (inst != NULL, FALSE); g_return_val_if_fail (GNC_IS_EMPLOYEE (inst), FALSE); g_return_val_if_fail (be != NULL, FALSE); emp = GNC_EMPLOYEE (inst); is_infant = qof_instance_get_infant (inst); if (qof_instance_get_destroying (inst)) { op = OP_DB_DELETE; } else if (be->is_pristine_db || is_infant) { op = OP_DB_INSERT; } else { op = OP_DB_UPDATE; } if (op != OP_DB_DELETE) { // Ensure the commodity is in the db is_ok = gnc_sql_save_commodity (be, gncEmployeeGetCurrency (emp)); } if (is_ok) { is_ok = gnc_sql_do_db_operation (be, op, TABLE_NAME, GNC_ID_EMPLOYEE, emp, col_table); } if (is_ok) { // Now, commit or delete any slots guid = qof_instance_get_guid (inst); if (!qof_instance_get_destroying (inst)) { is_ok = gnc_sql_slots_save (be, guid, is_infant, inst); } else { is_ok = gnc_sql_slots_delete (be, guid); } } return is_ok; }
/** Get displayable name */ static gchar* impl_get_display_name(const QofInstance* inst) { GncEmployee* emp; g_return_val_if_fail(inst != NULL, FALSE); g_return_val_if_fail(GNC_IS_EMPLOYEE(inst), FALSE); emp = GNC_EMPLOYEE(inst); return g_strdup_printf("Employee %s", emp->username); }
static void compare_single_employee( QofInstance* inst, gpointer user_data ) { CompareInfoStruct* info = (CompareInfoStruct*)user_data; GncEmployee* emp_1 = GNC_EMPLOYEE(inst); GncEmployee* emp_2 = gncEmployeeLookup( info->book_2, qof_instance_get_guid(inst) ); if (!gncEmployeeEqual( emp_1, emp_2 )) { info->result = FALSE; } }
static void write_single_employee (QofInstance* term_p, gpointer data_p) { write_objects_t* s = (write_objects_t*)data_p; g_return_if_fail (term_p != NULL); g_return_if_fail (GNC_IS_EMPLOYEE (term_p)); g_return_if_fail (data_p != NULL); if (s->is_ok && employee_should_be_saved (GNC_EMPLOYEE (term_p))) { s->is_ok = save_employee (s->be, term_p); } }
/** Does this object refer to a specific object */ static gboolean impl_refers_to_object(const QofInstance* inst, const QofInstance* ref) { GncEmployee* emp; g_return_val_if_fail(inst != NULL, FALSE); g_return_val_if_fail(GNC_IS_EMPLOYEE(inst), FALSE); emp = GNC_EMPLOYEE(inst); if (GNC_IS_COMMODITY(ref)) { return (emp->currency == GNC_COMMODITY(ref)); } else if (GNC_IS_ACCOUNT(ref)) { return (emp->ccard_acc == GNC_ACCOUNT(ref)); } return FALSE; }
static void gnc_employee_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec) { GncEmployee *emp; g_return_if_fail(GNC_IS_EMPLOYEE(object)); emp = GNC_EMPLOYEE(object); switch (prop_id) { case PROP_USERNAME: gncEmployeeSetUsername(emp, g_value_get_string(value)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; } }
/** * Listens for MODIFY events from addresses. If the address belongs to an employee, * mark the employee as dirty. * * @param entity Entity for the event * @param event_type Event type * @param user_data User data registered with the handler * @param event_data Event data passed with the event. */ static void listen_for_address_events(QofInstance *entity, QofEventId event_type, gpointer user_data, gpointer event_data) { GncEmployee* empl; if ((event_type & QOF_EVENT_MODIFY) == 0) { return; } if (!GNC_IS_ADDRESS(entity)) { return; } if (!GNC_IS_EMPLOYEE(event_data)) { return; } empl = GNC_EMPLOYEE(event_data); gncEmployeeBeginEdit(empl); mark_employee(empl); gncEmployeeCommitEdit(empl); }