00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00030 #include <glib.h>
00031 #include <glib/gprintf.h>
00032 #include <qof.h>
00033 #include "pilot-todo.h"
00034 #include "qof-main.h"
00035 #include "pilot-qof.h"
00036 #include "pi-todo.h"
00037
00038 #ifdef COMPATIBILITY_MODE
00039 typedef enum
00040 {
00041 todo_v1,
00042 } todoType;
00043 #endif
00044
00045 #define TODO_VERSION todo_v1
00046 #define QOF_TODO_DESC "Pilot-Link QOF ToDo"
00047
00048 static QofLogModule log_module = PQ_MOD_PILOT;
00049
00050 typedef struct
00051 {
00052 QofInstance inst;
00053 gchar *category;
00054 ToDo_t wrap;
00055 } QofTodo;
00056
00057 static QofTodo *
00058 todo_create (QofBook * book)
00059 {
00060 ToDo_t *qt;
00061 QofTodo *obj;
00062 QofCollection *coll;
00063 GList *all;
00064
00065 obj = g_new0 (QofTodo, 1);
00066 qof_instance_init (&obj->inst, PILOT_LINK_QOF_TODO, book);
00067 coll = qof_book_get_collection (book, PILOT_LINK_QOF_TODO);
00068 all = qof_collection_get_data (coll);
00069 all = g_list_prepend (all, obj);
00070 qof_collection_set_data (coll, all);
00071 qt = &obj->wrap;
00072 return obj;
00073 }
00074
00075 static gint
00076 todo_getLength (QofTodo * t)
00077 {
00078 ToDo_t *qt;
00079
00080 g_return_val_if_fail (t != NULL, 0);
00081 qt = &t->wrap;
00082 return qt->indefinite;
00083 }
00084
00085 static QofTime*
00086 todo_getTimeDue (QofTodo * t)
00087 {
00088 ToDo_t *qtd;
00089 QofTime *qt;
00090
00091 g_return_val_if_fail (t != NULL, NULL);
00092 qtd = &t->wrap;
00093 qt = qof_time_from_tm (&qtd->due, 0);
00094 return qt;
00095 }
00096
00097 static gint
00098 todo_getPriority (QofTodo * t)
00099 {
00100 ToDo_t *qt;
00101
00102 g_return_val_if_fail (t != NULL, 0);
00103 qt = &t->wrap;
00104 return qt->priority;
00105 }
00106
00107 static gint
00108 todo_getComplete (QofTodo * t)
00109 {
00110 ToDo_t *qt;
00111
00112 g_return_val_if_fail (t != NULL, 0);
00113 qt = &t->wrap;
00114 return qt->complete;
00115 }
00116
00117 static gchar *
00118 todo_getDescription (QofTodo * t)
00119 {
00120 ToDo_t *qt;
00121
00122 g_return_val_if_fail (t != NULL, NULL);
00123 qt = &t->wrap;
00124 return qt->description;
00125 }
00126
00127 static gchar *
00128 todo_getNote (QofTodo * t)
00129 {
00130 ToDo_t *qt;
00131
00132 g_return_val_if_fail (t != NULL, NULL);
00133 qt = &t->wrap;
00134 return qt->note;
00135 }
00136
00137 static gchar *
00138 todo_getCategory (QofTodo * t)
00139 {
00140 g_return_val_if_fail (t != NULL, NULL);
00141 return t->category;
00142 }
00143
00144 static void
00145 todo_setLength (QofTodo * t, gint l)
00146 {
00147 ToDo_t *qt;
00148
00149 g_return_if_fail (t != NULL);
00150 qt = &t->wrap;
00151 qt->indefinite = l;
00152 }
00153
00154 static void
00155 todo_setTimeDue (QofTodo * t, QofTime *qt)
00156 {
00157 ToDo_t *qtd;
00158 gboolean result;
00159 QofDate *qdate;
00160
00161 g_return_if_fail (t != NULL);
00162 qtd = &t->wrap;
00163 qdate = qof_date_from_qtime (qt);
00164 result = qof_date_to_struct_tm (qdate, &qtd->due, 0);
00165 if(!result)
00166 PERR (" Date too large for due.");
00167 qof_date_free (qdate);
00168 }
00169
00170 static void
00171 todo_setPriority (QofTodo * t, gint p)
00172 {
00173 ToDo_t *qt;
00174
00175 g_return_if_fail (t != NULL);
00176 if ((p < 1) || (p > 5))
00177 p = 1;
00178 qt = &t->wrap;
00179 qt->priority = p;
00180 }
00181
00182 static void
00183 todo_setComplete (QofTodo * t, gint c)
00184 {
00185 ToDo_t *qt;
00186
00187 g_return_if_fail (t != NULL);
00188 qt = &t->wrap;
00189 qt->complete = c;
00190 }
00191
00192 static void
00193 todo_setDescription (QofTodo * t, gchar * d)
00194 {
00195 ToDo_t *qt;
00196
00197 g_return_if_fail (t != NULL);
00198 qt = &t->wrap;
00199 qt->description = g_strdup (qof_main_make_utf8 (d));
00200 }
00201
00202 static void
00203 todo_setNote (QofTodo * t, gchar * n)
00204 {
00205 ToDo_t *qt;
00206
00207 g_return_if_fail (t != NULL);
00208 qt = &t->wrap;
00209 qt->note = g_strdup (qof_main_make_utf8 (n));
00210 }
00211
00212 static void
00213 todo_setCategory (QofTodo * t, gchar * n)
00214 {
00215 g_return_if_fail (t != NULL);
00216 t->category = g_strdup (qof_main_make_utf8 (n));
00217 }
00218
00219 static gint
00220 todo_unpack (QofEntity * ent, gpointer user_data)
00221 {
00222 pi_buffer_t *pi_buf;
00223 ToDo_t *qt;
00224 QofTodo *obj;
00225 PQContext *context;
00226 gint size;
00227
00228 context = (PQContext *) user_data;
00229 g_return_val_if_fail (context != NULL, -1);
00230 g_return_val_if_fail (ent != NULL, -1);
00231 ENTER (" ");
00232 obj = (QofTodo *) ent;
00233 qt = &obj->wrap;
00234 pi_buf = (pi_buffer_t *) context->pi_buf;
00235 size = 0;
00236 size = unpack_ToDo (qt, pi_buf, TODO_VERSION);
00237 todo_setCategory (obj, context->names[context->ent_category]);
00238 LEAVE (" ");
00239 return size;
00240 }
00241
00242 static gint
00243 todo_pack (QofEntity * ent, gpointer user_data)
00244 {
00245 ToDo_t *qt;
00246 QofTodo *obj;
00247 PQContext *context;
00248 gint size;
00249
00250 size = 0;
00251 context = (PQContext *) user_data;
00252 g_return_val_if_fail ((context || ent), -1);
00253 ENTER (" ");
00254 obj = (QofTodo *) ent;
00255 qt = &obj->wrap;
00256 size = pack_ToDo (qt, context->pi_buf, TODO_VERSION);
00257 LEAVE (" ");
00258 return size;
00259 }
00260
00261 static gint
00262 qof_todo_free (QofEntity * ent, gpointer user_data)
00263 {
00264 ToDo_t *qt;
00265 QofTodo *obj;
00266
00267 g_return_val_if_fail (ent != NULL, -1);
00268 ENTER (" ");
00269 obj = (QofTodo *) ent;
00270 qt = &obj->wrap;
00271 free_ToDo (qt);
00272 LEAVE (" ");
00273 return 0;
00274 }
00275
00276 static gint
00277 todo_appinfo_unpack (QofEntity * ent, gpointer user_data)
00278 {
00279 ToDoAppInfo_t app_t;
00280 PQContext *context;
00281 gint name_count;
00282
00283 context = (PQContext *) user_data;
00284 g_return_val_if_fail (context != NULL, -1);
00285 ENTER (" ");
00286 unpack_ToDoAppInfo (&app_t, context->app_buf->data, PQ_DEF_BUFSZ);
00287 for (name_count = 0; name_count < 16; name_count++)
00288 g_sprintf (context->names[name_count], "%s",
00289 app_t.category.name[name_count]);
00290 context->pi_cat = &app_t.category;
00291 LEAVE (" ");
00292 return 0;
00293 }
00294
00295 static const gchar *
00296 todoPrintable (gpointer instance)
00297 {
00298 return todo_getDescription ((QofTodo *) instance);
00299 }
00300
00301 static QofObject todo_object_def = {
00302 interface_version:QOF_OBJECT_VERSION,
00303 e_type:PILOT_LINK_QOF_TODO,
00304 type_label:QOF_TODO_DESC,
00305 create:(gpointer) todo_create,
00306 book_begin:NULL,
00307 book_end:NULL,
00308 is_dirty:qof_collection_is_dirty,
00309 mark_clean:qof_collection_mark_clean,
00310 foreach:qof_collection_foreach,
00311 printable:todoPrintable,
00312 version_cmp:(gint (*)(gpointer, gpointer)) qof_instance_version_cmp,
00313 };
00314
00315 static PQPack todo_pack_def = {
00316 e_type:PILOT_LINK_QOF_TODO,
00317 pack_func:todo_pack,
00318 unpack_func:todo_unpack,
00319 free_pack_func:qof_todo_free,
00320 palm_db_name:"ToDoDB",
00321 app_info_unpack:todo_appinfo_unpack,
00322 };
00323
00324 gboolean
00325 ToDoRegister (void)
00326 {
00327 static QofParam params[] = {
00328 {TODO_LENGTH, QOF_TYPE_INT32, (QofAccessFunc) todo_getLength,
00329 (QofSetterFunc) todo_setLength},
00330 {TODO_DATE, QOF_TYPE_TIME, (QofAccessFunc) todo_getTimeDue,
00331 (QofSetterFunc) todo_setTimeDue},
00332 {TODO_PRIORITY, QOF_TYPE_INT32, (QofAccessFunc) todo_getPriority,
00333 (QofSetterFunc) todo_setPriority},
00334 {TODO_COMPLETE, QOF_TYPE_INT32, (QofAccessFunc) todo_getComplete,
00335 (QofSetterFunc) todo_setComplete},
00336 {TODO_DESCRIPTION, QOF_TYPE_STRING,
00337 (QofAccessFunc) todo_getDescription,
00338 (QofSetterFunc) todo_setDescription},
00339 {TODO_CATEGORY, QOF_TYPE_STRING, (QofAccessFunc) todo_getCategory,
00340 (QofSetterFunc) todo_setCategory},
00341 {TODO_NOTE, QOF_TYPE_STRING, (QofAccessFunc) todo_getNote,
00342 (QofSetterFunc) todo_setNote},
00343 {QOF_PARAM_BOOK, QOF_ID_BOOK,
00344 (QofAccessFunc) qof_instance_get_book, NULL},
00345 {QOF_PARAM_GUID, QOF_TYPE_GUID,
00346 (QofAccessFunc) qof_instance_get_guid, NULL},
00347 {NULL},
00348 };
00349 qof_class_register (PILOT_LINK_QOF_TODO, NULL, params);
00350
00351 pilot_qof_pack_register (&todo_pack_def);
00352
00353 return qof_object_register (&todo_object_def);
00354 }
00355