static xmlNodePtr job_dom_tree_create (GncJob *job) { xmlNodePtr ret; ret = xmlNewNode(NULL, BAD_CAST gnc_job_string); xmlSetProp(ret, BAD_CAST "version", BAD_CAST job_version_string); xmlAddChild(ret, guid_to_dom_tree(job_guid_string, qof_instance_get_guid (QOF_INSTANCE (job)))); xmlAddChild(ret, text_to_dom_tree(job_id_string, gncJobGetID (job))); xmlAddChild(ret, text_to_dom_tree(job_name_string, gncJobGetName (job))); maybe_add_string (ret, job_reference_string, gncJobGetReference (job)); xmlAddChild(ret, gnc_owner_to_dom_tree (job_owner_string, gncJobGetOwner (job))); xmlAddChild(ret, int_to_dom_tree(job_active_string, gncJobGetActive (job))); return ret; }
static gboolean job_should_be_saved (GncJob *job) { const char *id; /* make sure this is a valid job before we save it -- should have an ID */ id = gncJobGetID (job); if (id == NULL || *id == '\0') return FALSE; return TRUE; }
const char * gncOwnerGetID (const GncOwner *owner) { if (!owner) return NULL; switch (owner->type) { case GNC_OWNER_NONE: case GNC_OWNER_UNDEFINED: default: return NULL; case GNC_OWNER_CUSTOMER: return gncCustomerGetID (owner->owner.customer); case GNC_OWNER_JOB: return gncJobGetID (owner->owner.job); case GNC_OWNER_VENDOR: return gncVendorGetID (owner->owner.vendor); case GNC_OWNER_EMPLOYEE: return gncEmployeeGetID (owner->owner.employee); } }
static JobWindow * gnc_job_new_window (QofBook *bookp, GncOwner *owner, GncJob *job) { JobWindow *jw; GtkBuilder *builder; GtkWidget *owner_box, *owner_label; /* * Find an existing window for this job. If found, bring it to * the front. */ if (job) { GncGUID job_guid; job_guid = *gncJobGetGUID (job); jw = gnc_find_first_gui_component (DIALOG_EDIT_JOB_CM_CLASS, find_handler, &job_guid); if (jw) { gtk_window_present (GTK_WINDOW(jw->dialog)); return(jw); } } /* * No existing job window found. Build a new one. */ jw = g_new0 (JobWindow, 1); jw->book = bookp; gncOwnerCopy (owner, &(jw->owner)); /* save it off now, we know it's valid */ /* Load the Glade File */ builder = gtk_builder_new(); gnc_builder_add_from_file (builder, "dialog-job.glade", "Job Dialog"); /* Find the dialog */ jw->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "Job Dialog")); /* Get entry points */ jw->id_entry = GTK_WIDGET(gtk_builder_get_object (builder, "id_entry")); jw->name_entry = GTK_WIDGET(gtk_builder_get_object (builder, "name_entry")); jw->desc_entry = GTK_WIDGET(gtk_builder_get_object (builder, "desc_entry")); jw->active_check = GTK_WIDGET(gtk_builder_get_object (builder, "active_check")); owner_box = GTK_WIDGET(gtk_builder_get_object (builder, "customer_hbox")); owner_label = GTK_WIDGET(gtk_builder_get_object (builder, "owner_label")); /* Setup signals */ gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, jw); /* Set initial entries */ if (job != NULL) { jw->job_guid = *gncJobGetGUID (job); jw->dialog_type = EDIT_JOB; jw->cust_edit = gnc_owner_edit_create (owner_label, owner_box, bookp, owner); gtk_entry_set_text (GTK_ENTRY (jw->id_entry), gncJobGetID (job)); gtk_entry_set_text (GTK_ENTRY (jw->name_entry), gncJobGetName (job)); gtk_entry_set_text (GTK_ENTRY (jw->desc_entry), gncJobGetReference (job)); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (jw->active_check), gncJobGetActive (job)); jw->component_id = gnc_register_gui_component (DIALOG_EDIT_JOB_CM_CLASS, gnc_job_window_refresh_handler, gnc_job_window_close_handler, jw); } else { job = gncJobCreate (bookp); gncJobSetOwner (job, owner); jw->job_guid = *gncJobGetGUID (job); jw->dialog_type = NEW_JOB; /* If we are passed a real owner, don't allow the user to change it */ if (owner->owner.undefined) { jw->cust_edit = gnc_owner_edit_create (owner_label, owner_box, bookp, owner); } else { jw->cust_edit = gnc_owner_select_create (owner_label, owner_box, bookp, owner); } jw->component_id = gnc_register_gui_component (DIALOG_NEW_JOB_CM_CLASS, gnc_job_window_refresh_handler, gnc_job_window_close_handler, jw); } gnc_job_name_changed_cb (NULL, jw); gnc_gui_component_watch_entity_type (jw->component_id, GNC_JOB_MODULE_NAME, QOF_EVENT_MODIFY | QOF_EVENT_DESTROY); gtk_widget_show_all (jw->dialog); // The job name should have keyboard focus gtk_widget_grab_focus(jw->name_entry); // Or should the owner field have focus? // if (GNC_IS_GENERAL_SEARCH(jw->cust_edit)) // { // gnc_general_search_grab_focus(GNC_GENERAL_SEARCH(jw->cust_edit)); // } g_object_unref(G_OBJECT(builder)); return jw; }