|
GnuCash 2.4.99
|
00001 /* 00002 * gnc-ab-kvp.c -- 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License as 00006 * published by the Free Software Foundation; either version 2 of 00007 * the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, contact: 00016 * 00017 * Free Software Foundation Voice: +1-617-542-5942 00018 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 00019 * Boston, MA 02110-1301, USA gnu@gnu.org 00020 */ 00021 00030 #include "config.h" 00031 #include "gnc-ui-util.h" 00032 00033 #include "gnc-ab-kvp.h" 00034 00035 #define AB_KEY "hbci" 00036 #define AB_ACCOUNT_ID "account-id" 00037 #define AB_ACCOUNT_UID "account-uid" 00038 #define AB_BANK_CODE "bank-code" 00039 #define AB_TRANS_RETRIEVAL "trans-retrieval" 00040 #define AB_TEMPLATES "template-list" 00041 00042 /* This static indicates the debugging module that this .o belongs to. */ 00043 static QofLogModule log_module = G_LOG_DOMAIN; 00044 00045 static kvp_frame *gnc_ab_get_account_kvp(const Account *a, gboolean create); 00046 static kvp_frame *gnc_ab_get_book_kvp(QofBook *b, gboolean create); 00047 00048 G_CONST_RETURN gchar * 00049 gnc_ab_get_account_accountid(const Account *a) 00050 { 00051 kvp_frame *frame = gnc_ab_get_account_kvp(a, FALSE); 00052 kvp_value *value = kvp_frame_get_slot(frame, AB_ACCOUNT_ID); 00053 return kvp_value_get_string(value); 00054 } 00055 00056 void 00057 gnc_ab_set_account_accountid(Account *a, const gchar *id) 00058 { 00059 kvp_frame *frame = gnc_ab_get_account_kvp(a, TRUE); 00060 kvp_value *value = kvp_value_new_string(id); 00061 xaccAccountBeginEdit(a); 00062 kvp_frame_set_slot_nc(frame, AB_ACCOUNT_ID, value); 00063 qof_instance_set_dirty(QOF_INSTANCE (a)); 00064 xaccAccountCommitEdit(a); 00065 } 00066 00067 G_CONST_RETURN gchar * 00068 gnc_ab_get_account_bankcode(const Account *a) 00069 { 00070 kvp_frame *frame = gnc_ab_get_account_kvp(a, FALSE); 00071 kvp_value *value = kvp_frame_get_slot(frame, AB_BANK_CODE); 00072 return kvp_value_get_string(value); 00073 } 00074 00075 void 00076 gnc_ab_set_account_bankcode(Account *a, const gchar *code) 00077 { 00078 kvp_frame *frame = gnc_ab_get_account_kvp(a, TRUE); 00079 kvp_value *value = kvp_value_new_string(code); 00080 xaccAccountBeginEdit(a); 00081 kvp_frame_set_slot_nc(frame, AB_BANK_CODE, value); 00082 qof_instance_set_dirty(QOF_INSTANCE (a)); 00083 xaccAccountCommitEdit(a); 00084 } 00085 00086 guint32 00087 gnc_ab_get_account_uid(const Account *a) 00088 { 00089 kvp_frame *frame = gnc_ab_get_account_kvp(a, FALSE); 00090 kvp_value *value = kvp_frame_get_slot(frame, AB_ACCOUNT_UID); 00091 return (guint32) kvp_value_get_gint64(value); 00092 } 00093 00094 void 00095 gnc_ab_set_account_uid(Account *a, guint32 uid) 00096 { 00097 kvp_frame *frame = gnc_ab_get_account_kvp(a, TRUE); 00098 kvp_value *value = kvp_value_new_gint64(uid); 00099 xaccAccountBeginEdit(a); 00100 kvp_frame_set_slot_nc(frame, AB_ACCOUNT_UID, value); 00101 qof_instance_set_dirty(QOF_INSTANCE (a)); 00102 xaccAccountCommitEdit(a); 00103 } 00104 00105 Timespec 00106 gnc_ab_get_account_trans_retrieval(const Account *a) 00107 { 00108 kvp_frame *frame = gnc_ab_get_account_kvp(a, FALSE); 00109 kvp_value *value = kvp_frame_get_slot(frame, AB_TRANS_RETRIEVAL); 00110 return kvp_value_get_timespec(value); 00111 } 00112 00113 void 00114 gnc_ab_set_account_trans_retrieval(Account *a, Timespec time) 00115 { 00116 kvp_frame *frame = gnc_ab_get_account_kvp(a, TRUE); 00117 kvp_value *value = kvp_value_new_timespec(time); 00118 xaccAccountBeginEdit(a); 00119 kvp_frame_set_slot_nc(frame, AB_TRANS_RETRIEVAL, value); 00120 qof_instance_set_dirty(QOF_INSTANCE (a)); 00121 xaccAccountCommitEdit(a); 00122 } 00123 00124 GList * 00125 gnc_ab_get_book_template_list(QofBook *b) 00126 { 00127 kvp_frame *frame = gnc_ab_get_book_kvp(b, FALSE); 00128 kvp_value *value = kvp_frame_get_slot(frame, AB_TEMPLATES); 00129 return kvp_value_get_glist(value); 00130 } 00131 00132 void 00133 gnc_ab_set_book_template_list(QofBook *b, GList *template_list) 00134 { 00135 kvp_frame *frame = gnc_ab_get_book_kvp(b, TRUE); 00136 kvp_value *value = kvp_value_new_glist_nc(template_list); 00137 kvp_frame_set_slot_nc(frame, AB_TEMPLATES, value); 00138 qof_book_kvp_changed (b); 00139 } 00140 00141 static kvp_frame * 00142 gnc_ab_get_account_kvp(const Account *a, gboolean create) 00143 { 00144 kvp_frame *toplevel = xaccAccountGetSlots(a); 00145 kvp_frame *result = kvp_frame_get_frame(toplevel, AB_KEY); 00146 if (!result && create) 00147 { 00148 result = kvp_frame_new(); 00149 kvp_frame_add_frame_nc(toplevel, AB_KEY, result); 00150 } 00151 return result; 00152 } 00153 00154 static kvp_frame * 00155 gnc_ab_get_book_kvp(QofBook *b, gboolean create) 00156 { 00157 kvp_frame *toplevel = qof_book_get_slots(b); 00158 kvp_frame *result = kvp_frame_get_frame(toplevel, AB_KEY); 00159 if (!result && create) 00160 { 00161 result = kvp_frame_new(); 00162 kvp_frame_add_frame_nc(toplevel, AB_KEY, result); 00163 } 00164 return result; 00165 }
1.7.4