• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

pilot-todo.c

Go to the documentation of this file.
00001 /***************************************************************************
00002  *            pilot-todo.c
00003  *
00004  *  Sun Jan 30 16:07:21 2005
00005  *  Copyright  2005-2007  Neil Williams
00006  *  linux@codehelp.co.uk
00007  ****************************************************************************/
00008 /*
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 3 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU General Public License for more details.
00018 
00019     You should have received a copy of the GNU General Public License
00020     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00021  */
00029 #include <glib.h>
00030 #include <glib/gprintf.h>
00031 #include <qof.h>
00032 #include "pilot-todo.h"
00033 #include "qof-main.h"
00034 #include "pilot-qof.h"
00035 #include "pi-todo.h"
00036 
00037 #ifdef COMPATIBILITY_MODE
00038 typedef enum
00039 {
00040     todo_v1,
00041 } todoType;
00042 #endif
00043 
00044 #define QOF_TODO_DESC "Pilot-Link QOF ToDo"
00045 
00046 static QofLogModule log_module = PQ_MOD_PILOT;
00047 
00048 typedef struct
00049 {
00050     QofInstance inst;
00051     gchar *category;
00052     ToDo_t wrap;                // 0.12
00053 } QofTodo;
00054 
00055 static QofTodo *
00056 todo_create (QofBook * book)
00057 {
00058     ToDo_t *qt;
00059     QofTodo *obj;
00060     QofCollection *coll;
00061     GList *all;
00062 
00063     obj = g_new0 (QofTodo, 1);
00064     qof_instance_init (&obj->inst, PILOT_LINK_QOF_TODO, book);
00065     coll = qof_book_get_collection (book, PILOT_LINK_QOF_TODO);
00066     all = qof_collection_get_data (coll);
00067     all = g_list_prepend (all, obj);
00068     qof_collection_set_data (coll, all);
00069     qt = &obj->wrap;
00070     return obj;
00071 }
00072 
00073 ToDo_t * todo_get_pilot (QofInstance * inst)
00074 {
00075     QofTodo * t;
00076 
00077     t = (QofTodo*)inst;
00078     return &t->wrap;
00079 }
00080 
00081 static gint
00082 todo_getLength (QofTodo * t)
00083 {
00084     ToDo_t *qt;
00085 
00086     g_return_val_if_fail (t != NULL, 0);
00087     qt = &t->wrap;
00088     return qt->indefinite;
00089 }
00090 
00091 static QofTime*
00092 todo_getTimeDue (QofTodo * t)
00093 {
00094     ToDo_t *qtd;
00095     QofTime *qt;
00096 
00097     g_return_val_if_fail (t != NULL, NULL);
00098     qtd = &t->wrap;
00099     qt = qof_time_from_tm (&qtd->due, 0);
00100     return qt;
00101 }
00102 
00103 static gint
00104 todo_getPriority (QofTodo * t)
00105 {
00106     ToDo_t *qt;
00107 
00108     g_return_val_if_fail (t != NULL, 0);
00109     qt = &t->wrap;
00110     return qt->priority;
00111 }
00112 
00113 static gint
00114 todo_getComplete (QofTodo * t)
00115 {
00116     ToDo_t *qt;
00117 
00118     g_return_val_if_fail (t != NULL, 0);
00119     qt = &t->wrap;
00120     return qt->complete;
00121 }
00122 
00123 static gchar *
00124 todo_getDescription (QofTodo * t)
00125 {
00126     ToDo_t *qt;
00127 
00128     g_return_val_if_fail (t != NULL, NULL);
00129     qt = &t->wrap;
00130     return qt->description;
00131 }
00132 
00133 static gchar *
00134 todo_getNote (QofTodo * t)
00135 {
00136     ToDo_t *qt;
00137 
00138     g_return_val_if_fail (t != NULL, NULL);
00139     qt = &t->wrap;
00140     return qt->note;
00141 }
00142 
00143 static gchar *
00144 todo_getCategory (QofTodo * t)
00145 {
00146     g_return_val_if_fail (t != NULL, NULL);
00147     return t->category;
00148 }
00149 
00150 static void
00151 todo_setLength (QofTodo * t, gint l)
00152 {
00153     ToDo_t *qt;
00154 
00155     g_return_if_fail (t != NULL);
00156     qt = &t->wrap;
00157     qt->indefinite = l;
00158 }
00159 
00160 static void
00161 todo_setTimeDue (QofTodo * t, QofTime *qt)
00162 {
00163     ToDo_t *qtd;
00164     gboolean result;
00165     QofDate *qdate;
00166 
00167     g_return_if_fail (t != NULL);
00168     qtd = &t->wrap;
00169     qdate = qof_date_from_qtime (qt);
00170     result = qof_date_to_struct_tm (qdate, &qtd->due, 0);
00171     if(!result)
00172         PERR (" Date too large for due.");
00173     qof_date_free (qdate);
00174 }
00175 
00176 static void
00177 todo_setPriority (QofTodo * t, gint p)
00178 {
00179     ToDo_t *qt;
00180 
00181     g_return_if_fail (t != NULL);
00182     if ((p < 1) || (p > 5))
00183         p = 1;
00184     qt = &t->wrap;
00185     qt->priority = p;
00186 }
00187 
00188 static void
00189 todo_setComplete (QofTodo * t, gint c)
00190 {
00191     ToDo_t *qt;
00192 
00193     g_return_if_fail (t != NULL);
00194     qt = &t->wrap;
00195     qt->complete = c;
00196 }
00197 
00198 static void
00199 todo_setDescription (QofTodo * t, gchar * d)
00200 {
00201     ToDo_t *qt;
00202 
00203     g_return_if_fail (t != NULL);
00204     qt = &t->wrap;
00205     qt->description = g_strdup (qof_util_make_utf8 (d));
00206 }
00207 
00208 static void
00209 todo_setNote (QofTodo * t, gchar * n)
00210 {
00211     ToDo_t *qt;
00212 
00213     g_return_if_fail (t != NULL);
00214     qt = &t->wrap;
00215     qt->note = g_strdup (qof_util_make_utf8 (n));
00216 }
00217 
00218 static void
00219 todo_setCategory (QofTodo * t, gchar * n)
00220 {
00221     g_return_if_fail (t != NULL);
00222     t->category = g_strdup (qof_util_make_utf8 (n));
00223 }
00224 
00225 static const gchar *
00226 todoPrintable (gpointer instance)
00227 {
00228     return todo_getDescription ((QofTodo *) instance);
00229 }
00230 
00231 static QofObject todo_object_def = {
00232   interface_version:QOF_OBJECT_VERSION,
00233   e_type:PILOT_LINK_QOF_TODO,
00234   type_label:QOF_TODO_DESC,
00235   create:(gpointer) todo_create,
00236   book_begin:NULL,
00237   book_end:NULL,
00238   is_dirty:qof_collection_is_dirty,
00239   mark_clean:qof_collection_mark_clean,
00240   foreach:qof_collection_foreach,
00241   printable:todoPrintable,
00242   version_cmp:(gint (*)(gpointer, gpointer)) qof_instance_version_cmp,
00243 };
00244 
00245 gboolean
00246 ToDoRegister (void)
00247 {
00248     static QofParam params[] = {
00249         {TODO_LENGTH, QOF_TYPE_INT32, (QofAccessFunc) todo_getLength,
00250                 (QofSetterFunc) todo_setLength},
00251         {TODO_DATE, QOF_TYPE_TIME, (QofAccessFunc) todo_getTimeDue,
00252                 (QofSetterFunc) todo_setTimeDue},
00253         {TODO_PRIORITY, QOF_TYPE_INT32, (QofAccessFunc) todo_getPriority,
00254                 (QofSetterFunc) todo_setPriority},
00255         {TODO_COMPLETE, QOF_TYPE_INT32, (QofAccessFunc) todo_getComplete,
00256                 (QofSetterFunc) todo_setComplete},
00257         {TODO_DESCRIPTION, QOF_TYPE_STRING,
00258                 (QofAccessFunc) todo_getDescription,
00259                 (QofSetterFunc) todo_setDescription},
00260         {TODO_CATEGORY, QOF_TYPE_STRING, (QofAccessFunc) todo_getCategory,
00261                 (QofSetterFunc) todo_setCategory},
00262         {TODO_NOTE, QOF_TYPE_STRING, (QofAccessFunc) todo_getNote,
00263                 (QofSetterFunc) todo_setNote},
00264         {QOF_PARAM_BOOK, QOF_ID_BOOK,
00265                 (QofAccessFunc) qof_instance_get_book, NULL},
00266         {QOF_PARAM_GUID, QOF_TYPE_GUID,
00267                 (QofAccessFunc) qof_instance_get_guid, NULL},
00268         {NULL},
00269     };
00270     qof_class_register (PILOT_LINK_QOF_TODO, NULL, params);
00271 
00272     return qof_object_register (&todo_object_def);
00273 }
00274 

Generated on Wed Jul 28 2010 21:39:21 for pilot-qof by  doxygen 1.7.1