Back to index

webcit  8.12-dfsg
tasks.c
Go to the documentation of this file.
00001 #include "webcit.h"
00002 #include "calendar.h"
00003 #include "webserver.h"
00004 
00005 /*
00006  * qsort filter to move completed tasks to bottom of task list
00007  */
00008 int task_completed_cmp(const void *vtask1, const void *vtask2) {
00009        disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
00010 /*     disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2); */
00011 
00012        icalproperty_status t1 = icalcomponent_get_status((Task1)->cal);
00013        /* icalproperty_status t2 = icalcomponent_get_status(((struct disp_cal *)task2)->cal); */
00014        
00015        if (t1 == ICAL_STATUS_COMPLETED) 
00016               return 1;
00017        return 0;
00018 }
00019 
00020 
00021 /*
00022  * Helper function for do_tasks_view().  Returns the due date/time of a vtodo.
00023  */
00024 time_t get_task_due_date(icalcomponent *vtodo, int *is_date) {
00025        icalproperty *p;
00026 
00027        if (vtodo == NULL) {
00028               return(0L);
00029        }
00030 
00031        /*
00032         * If we're looking at a fully encapsulated VCALENDAR
00033         * rather than a VTODO component, recurse into the data
00034         * structure until we get a VTODO.
00035         */
00036        if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
00037               return get_task_due_date(
00038                      icalcomponent_get_first_component(
00039                             vtodo, ICAL_VTODO_COMPONENT
00040                             ), is_date
00041                      );
00042        }
00043 
00044        p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
00045        if (p != NULL) {
00046               struct icaltimetype t = icalproperty_get_due(p);
00047 
00048               if (is_date)
00049                      *is_date = t.is_date;
00050               return(icaltime_as_timet(t));
00051        }
00052        else {
00053               return(0L);
00054        }
00055 }
00056 
00057 /*
00058  * Compare the due dates of two tasks (this is for sorting)
00059  */
00060 int task_due_cmp(const void *vtask1, const void *vtask2) {
00061        disp_cal * Task1 = (disp_cal *)GetSearchPayload(vtask1);
00062        disp_cal * Task2 = (disp_cal *)GetSearchPayload(vtask2);
00063 
00064        time_t t1;
00065        time_t t2;
00066 
00067        t1 =  get_task_due_date(Task1->cal, NULL);
00068        t2 =  get_task_due_date(Task2->cal, NULL);
00069        if (t1 < t2) return(-1);
00070        if (t1 > t2) return(1);
00071        return(0);
00072 }
00073 
00074 /*
00075  * do the whole task view stuff
00076  */
00077 int tasks_RenderView_or_Tail(SharedMessageStatus *Stat, 
00078                            void **ViewSpecific, 
00079                            long oper)
00080 {
00081        long hklen;
00082        const char *HashKey;
00083        void *vCal;
00084        disp_cal *Cal;
00085        HashPos *Pos;
00086        int nItems;
00087        time_t due;
00088        char buf[SIZ];
00089        icalproperty *p;
00090        wcsession *WCC = WC;
00091 
00092        wc_printf("<table class=\"calendar_view_background\"><tbody id=\"taskview\">\n<tr>\n<th>");
00093        wc_printf(_("Completed?"));
00094        wc_printf("</th><th>");
00095        wc_printf(_("Name of task"));
00096        wc_printf("</th><th>");
00097        wc_printf(_("Date due"));
00098        wc_printf("</th><th>");
00099        wc_printf(_("Category"));
00100        wc_printf(" (<select id=\"selectcategory\"><option value=\"showall\">%s</option></select>)</th></tr>\n",
00101               _("Show All"));
00102 
00103        nItems = GetCount(WC->disp_cal_items);
00104 
00105        /* Sort them if necessary
00106        if (nItems > 1) {
00107               SortByPayload(WC->disp_cal_items, task_due_cmp);
00108        }
00109        * this shouldn't be neccessary, since we sort by the start time.
00110        */
00111 
00112        /* And then again, by completed */
00113        if (nItems > 1) {
00114               SortByPayload(WC->disp_cal_items, 
00115                            task_completed_cmp);
00116        }
00117 
00118        Pos = GetNewHashPos(WCC->disp_cal_items, 0);
00119        while (GetNextHashPos(WCC->disp_cal_items, Pos, &hklen, &HashKey, &vCal)) {
00120               icalproperty_status todoStatus;
00121               int is_date;
00122 
00123               Cal = (disp_cal*)vCal;
00124               wc_printf("<tr><td>");
00125               todoStatus = icalcomponent_get_status(Cal->cal);
00126               wc_printf("<input type=\"checkbox\" name=\"completed\" value=\"completed\" ");
00127               if (todoStatus == ICAL_STATUS_COMPLETED) {
00128                      wc_printf("checked=\"checked\" ");
00129               }
00130               wc_printf("disabled=\"disabled\">\n</td><td>");
00131               p = icalcomponent_get_first_property(Cal->cal,
00132                      ICAL_SUMMARY_PROPERTY);
00133               wc_printf("<a href=\"display_edit_task?msgnum=%ld?taskrm=", Cal->cal_msgnum);
00134               urlescputs(ChrPtr(WC->CurRoom.name));
00135               wc_printf("\">");
00136               /* wc_printf("<img align=middle "
00137               "src=\"static/taskmanag_16x.gif\" border=0>&nbsp;"); */
00138               if (p != NULL) {
00139                      escputs((char *)icalproperty_get_comment(p));
00140               }
00141               wc_printf("</a>\n");
00142               wc_printf("</td>\n");
00143 
00144               due = get_task_due_date(Cal->cal, &is_date);
00145               wc_printf("<td><span");
00146               if (due > 0) {
00147                      webcit_fmt_date(buf, SIZ, due, is_date ? DATEFMT_RAWDATE : DATEFMT_FULL);
00148                      wc_printf(">%s",buf);
00149               }
00150               else {
00151                      wc_printf(">");
00152               }
00153               wc_printf("</span></td>");
00154               wc_printf("<td>");
00155               p = icalcomponent_get_first_property(Cal->cal,
00156                      ICAL_CATEGORIES_PROPERTY);
00157               if (p != NULL) {
00158                      escputs((char *)icalproperty_get_categories(p));
00159               }
00160               wc_printf("</td>");
00161               wc_printf("</tr>");
00162        }
00163 
00164        wc_printf("</tbody></table>\n");
00165 
00166        /* Free the list */
00167        DeleteHash(&WC->disp_cal_items);
00168        DeleteHashPos(&Pos);
00169        return 0;
00170 }
00171 
00172 
00173 /*
00174  * Display a task by itself (for editing)
00175  */
00176 void display_edit_individual_task(icalcomponent *supplied_vtodo, long msgnum, char *from,
00177                      int unread, calview *calv)
00178 {
00179        icalcomponent *vtodo;
00180        icalproperty *p;
00181        struct icaltimetype IcalTime;
00182        int created_new_vtodo = 0;
00183        icalproperty_status todoStatus;
00184 
00185        if (supplied_vtodo != NULL) {
00186               vtodo = supplied_vtodo;
00187 
00188               /*
00189                * It's safe to convert to UTC here because there are no recurrences to worry about.
00190                */
00191               ical_dezonify(vtodo);
00192 
00193               /*
00194                * If we're looking at a fully encapsulated VCALENDAR
00195                * rather than a VTODO component, attempt to use the first
00196                * relevant VTODO subcomponent.  If there is none, the
00197                * NULL returned by icalcomponent_get_first_component() will
00198                * tell the next iteration of this function to create a
00199                * new one.
00200                */
00201               if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
00202                      display_edit_individual_task(
00203                             icalcomponent_get_first_component(
00204                                    vtodo, ICAL_VTODO_COMPONENT
00205                                    ), 
00206                             msgnum, from, unread, calv
00207                             );
00208                      return;
00209               }
00210        }
00211        else {
00212               vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
00213               created_new_vtodo = 1;
00214        }
00215        
00216        /* TODO: Can we take all this and move it into a template?      */
00217        output_headers(1, 1, 1, 0, 0, 0);
00218        wc_printf("<!-- start task edit form -->");
00219        p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
00220        /* Get summary early for title */
00221        wc_printf("<div class=\"box\">\n");
00222        wc_printf("<div class=\"boxlabel\">");
00223        wc_printf(_("Edit task"));
00224        wc_printf("- ");
00225        if (p != NULL) {
00226               escputs((char *)icalproperty_get_comment(p));
00227        }
00228        wc_printf("</div>");
00229        
00230        wc_printf("<div class=\"boxcontent\">\n");
00231        wc_printf("<FORM METHOD=\"POST\" action=\"save_task\">\n");
00232        wc_printf("<div style=\"display: none;\">\n      ");
00233        wc_printf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
00234        wc_printf("<INPUT TYPE=\"hidden\" NAME=\"msgnum\" VALUE=\"%ld\">\n", msgnum);
00235        wc_printf("<INPUT TYPE=\"hidden\" NAME=\"return_to_summary\" VALUE=\"%d\">\n",
00236               ibstr("return_to_summary"));
00237        wc_printf("</div>");
00238        wc_printf("<table class=\"calendar_background\"><tr><td>");
00239        wc_printf("<TABLE STYLE=\"border: none;\">\n");
00240 
00241        wc_printf("<TR><TD>");
00242        wc_printf(_("Summary:"));
00243        wc_printf("</TD><TD>"
00244               "<INPUT TYPE=\"text\" NAME=\"summary\" "
00245               "MAXLENGTH=\"64\" SIZE=\"64\" VALUE=\"");
00246        p = icalcomponent_get_first_property(vtodo, ICAL_SUMMARY_PROPERTY);
00247        if (p != NULL) {
00248               escputs((char *)icalproperty_get_comment(p));
00249        }
00250        wc_printf("\"></TD></TR>\n");
00251 
00252        wc_printf("<TR><TD>");
00253        wc_printf(_("Start date:"));
00254        wc_printf("</TD><TD>");
00255        p = icalcomponent_get_first_property(vtodo, ICAL_DTSTART_PROPERTY);
00256        wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"nodtstart\" ID=\"nodtstart\" VALUE=\"NODTSTART\" ");
00257        if (p == NULL) {
00258               wc_printf("CHECKED=\"CHECKED\"");
00259        }
00260        wc_printf(">");
00261        wc_printf(_("No date"));
00262        
00263        wc_printf(" ");
00264        wc_printf("<span ID=\"dtstart_date\">");
00265        wc_printf(_("or"));
00266        wc_printf(" ");
00267        if (p != NULL) {
00268               IcalTime = icalproperty_get_dtstart(p);
00269        }
00270        else
00271               IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone());
00272        display_icaltimetype_as_webform(&IcalTime, "dtstart", 0);
00273 
00274        wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"dtstart_time_assoc\" ID=\"dtstart_time_assoc\" VALUE=\"yes\"");
00275        if (!IcalTime.is_date) {
00276               wc_printf("CHECKED=\"CHECKED\"");
00277        }
00278        wc_printf(">");
00279        wc_printf(_("Time associated"));
00280        wc_printf("</span></TD></TR>\n");
00281 
00282        wc_printf("<TR><TD>");
00283        wc_printf(_("Due date:"));
00284        wc_printf("</TD><TD>");
00285        p = icalcomponent_get_first_property(vtodo, ICAL_DUE_PROPERTY);
00286        wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"nodue\" ID=\"nodue\" VALUE=\"NODUE\"");
00287        if (p == NULL) {
00288               wc_printf("CHECKED=\"CHECKED\"");
00289        }
00290        wc_printf(">");
00291        wc_printf(_("No date"));
00292        wc_printf(" ");
00293        wc_printf("<span ID=\"due_date\">\n");
00294        wc_printf(_("or"));
00295        wc_printf(" ");
00296        if (p != NULL) {
00297               IcalTime = icalproperty_get_due(p);
00298        }
00299        else
00300               IcalTime = icaltime_current_time_with_zone(get_default_icaltimezone());
00301        display_icaltimetype_as_webform(&IcalTime, "due", 0);
00302 
00303        wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"due_time_assoc\" ID=\"due_time_assoc\" VALUE=\"yes\"");
00304        if (!IcalTime.is_date) {
00305               wc_printf("CHECKED=\"CHECKED\"");
00306        }
00307        wc_printf(">");
00308        wc_printf(_("Time associated"));
00309        wc_printf("</span></TD></TR>\n");
00310        todoStatus = icalcomponent_get_status(vtodo);
00311        wc_printf("<TR><TD>\n");
00312        wc_printf(_("Completed:"));
00313        wc_printf("</TD><TD>");
00314        wc_printf("<INPUT TYPE=\"CHECKBOX\" NAME=\"status\" VALUE=\"COMPLETED\"");
00315        if (todoStatus == ICAL_STATUS_COMPLETED) {
00316               wc_printf(" CHECKED=\"CHECKED\"");
00317        } 
00318        wc_printf(" >");
00319        wc_printf("</TD></TR>");
00320        /* start category field */
00321        p = icalcomponent_get_first_property(vtodo, ICAL_CATEGORIES_PROPERTY);
00322        wc_printf("<TR><TD>");
00323        wc_printf(_("Category:"));
00324        wc_printf("</TD><TD>");
00325        wc_printf("<INPUT TYPE=\"text\" NAME=\"category\" MAXLENGTH=\"32\" SIZE=\"32\" VALUE=\"");
00326        if (p != NULL) {
00327               escputs((char *)icalproperty_get_categories(p));
00328        }
00329        wc_printf("\">");
00330        wc_printf("</TD></TR>\n     ");
00331        /* end category field */
00332        wc_printf("<TR><TD>");
00333        wc_printf(_("Description:"));
00334        wc_printf("</TD><TD>");
00335        wc_printf("<TEXTAREA NAME=\"description\" "
00336               "ROWS=\"10\" COLS=\"80\">\n"
00337               );
00338        p = icalcomponent_get_first_property(vtodo, ICAL_DESCRIPTION_PROPERTY);
00339        if (p != NULL) {
00340               escputs((char *)icalproperty_get_comment(p));
00341        }
00342        wc_printf("</TEXTAREA></TD></TR></TABLE>\n");
00343 
00344        wc_printf("<SPAN STYLE=\"text-align: center;\">"
00345               "<INPUT TYPE=\"submit\" NAME=\"save_button\" VALUE=\"%s\">"
00346               "&nbsp;&nbsp;"
00347               "<INPUT TYPE=\"submit\" NAME=\"delete_button\" VALUE=\"%s\">\n"
00348               "&nbsp;&nbsp;"
00349               "<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">\n"
00350               "</SPAN>\n",
00351               _("Save"),
00352               _("Delete"),
00353               _("Cancel")
00354               );
00355        wc_printf("</td></tr></table>");
00356        wc_printf("</FORM>\n");
00357        wc_printf("</div></div></div>\n");
00358        wc_printf("<!-- end task edit form -->");
00359        wDumpContent(1);
00360 
00361        if (created_new_vtodo) {
00362               icalcomponent_free(vtodo);
00363        }
00364 }
00365 
00366 /*
00367  * Save an edited task
00368  *
00369  * supplied_vtodo    the task to save
00370  * msgnum            number of the mesage in our db
00371  */
00372 void save_individual_task(icalcomponent *supplied_vtodo, long msgnum, char* from, int unread,
00373                        calview *calv)
00374 {
00375        char buf[SIZ];
00376        int delete_existing = 0;
00377        icalproperty *prop;
00378        icalcomponent *vtodo, *encaps;
00379        int created_new_vtodo = 0;
00380        int i;
00381        int sequence = 0;
00382        struct icaltimetype t;
00383 
00384        if (supplied_vtodo != NULL) {
00385               vtodo = supplied_vtodo;
00394               if (icalcomponent_isa(vtodo) == ICAL_VCALENDAR_COMPONENT) {
00395                      save_individual_task(
00396                             icalcomponent_get_first_component(
00397                                    vtodo, ICAL_VTODO_COMPONENT), 
00398                             msgnum, from, unread, calv
00399                             );
00400                      return;
00401               }
00402        }
00403        else {
00404               vtodo = icalcomponent_new(ICAL_VTODO_COMPONENT);
00405               created_new_vtodo = 1;
00406        }
00407 
00408        if (havebstr("save_button")) {
00409 
00412               while (prop = icalcomponent_get_first_property(vtodo,
00413                                                         ICAL_SUMMARY_PROPERTY), prop != NULL) {
00414                      icalcomponent_remove_property(vtodo, prop);
00415                      icalproperty_free(prop);
00416               }
00417               if (havebstr("summary")) {
00418 
00419                      icalcomponent_add_property(vtodo,
00420                                              icalproperty_new_summary(bstr("summary")));
00421               } else {
00422                      icalcomponent_add_property(vtodo,
00423                                              icalproperty_new_summary(_("Untitled Task")));
00424               }
00425        
00426               while (prop = icalcomponent_get_first_property(vtodo,
00427                                                         ICAL_DESCRIPTION_PROPERTY), prop != NULL) {
00428                      icalcomponent_remove_property(vtodo, prop);
00429                      icalproperty_free(prop);
00430               }
00431               if (havebstr("description")) {
00432                      icalcomponent_add_property(vtodo,
00433                                              icalproperty_new_description(bstr("description")));
00434               }
00435        
00436               while (prop = icalcomponent_get_first_property(vtodo,
00437                                                         ICAL_DTSTART_PROPERTY), prop != NULL) {
00438                      icalcomponent_remove_property(vtodo, prop);
00439                      icalproperty_free(prop);
00440               }
00441               if (IsEmptyStr(bstr("nodtstart"))) {
00442                      if (yesbstr("dtstart_time")) {
00443                             icaltime_from_webform(&t, "dtstart");
00444                      }
00445                      else {
00446                             icaltime_from_webform_dateonly(&t, "dtstart");
00447                      }
00448                      icalcomponent_add_property(vtodo,
00449                                              icalproperty_new_dtstart(t)
00450                             );
00451               }
00452               while(prop = icalcomponent_get_first_property(vtodo,
00453                                                        ICAL_STATUS_PROPERTY), prop != NULL) {
00454                      icalcomponent_remove_property(vtodo,prop);
00455                      icalproperty_free(prop);
00456               }
00457               while(prop = icalcomponent_get_first_property(vtodo,
00458                                                        ICAL_PERCENTCOMPLETE_PROPERTY), prop != NULL) {
00459                      icalcomponent_remove_property(vtodo,prop);
00460                      icalproperty_free(prop);
00461               }
00462 
00463               if (havebstr("status")) {
00464                      icalproperty_status taskStatus = icalproperty_string_to_status(bstr("status"));
00465                      icalcomponent_set_status(vtodo, taskStatus);
00466                      icalcomponent_add_property(vtodo,
00467                             icalproperty_new_percentcomplete(
00468                                    (strcasecmp(bstr("status"), "completed") ? 0 : 100)
00469                             )
00470                      );
00471               }
00472               else {
00473                      icalcomponent_add_property(vtodo, icalproperty_new_percentcomplete(0));
00474               }
00475               while (prop = icalcomponent_get_first_property(vtodo,
00476                                                         ICAL_CATEGORIES_PROPERTY), prop != NULL) {
00477                      icalcomponent_remove_property(vtodo,prop);
00478                      icalproperty_free(prop);
00479               }
00480               if (!IsEmptyStr(bstr("category"))) {
00481                      prop = icalproperty_new_categories(bstr("category"));
00482                      icalcomponent_add_property(vtodo,prop);
00483               }
00484               while (prop = icalcomponent_get_first_property(vtodo,
00485                                                         ICAL_DUE_PROPERTY), prop != NULL) {
00486                      icalcomponent_remove_property(vtodo, prop);
00487                      icalproperty_free(prop);
00488               }
00489               if (IsEmptyStr(bstr("nodue"))) {
00490                      if (yesbstr("due_time")) {
00491                             icaltime_from_webform(&t, "due");
00492                      }
00493                      else {
00494                             icaltime_from_webform_dateonly(&t, "due");
00495                      }
00496                      icalcomponent_add_property(vtodo,
00497                                              icalproperty_new_due(t)
00498                             );
00499               }
00501               syslog(9, "Give this task a UID if it doesn't have one.\n");
00502               if (icalcomponent_get_first_property(vtodo,
00503                                                ICAL_UID_PROPERTY) == NULL) {
00504                      generate_uuid(buf);
00505                      icalcomponent_add_property(vtodo,
00506                                              icalproperty_new_uid(buf)
00507                             );
00508               }
00509 
00510               /* Increment the sequence ID */
00511               syslog(9, "Increment the sequence ID\n");
00512               while (prop = icalcomponent_get_first_property(vtodo,
00513                                                         ICAL_SEQUENCE_PROPERTY), (prop != NULL) ) {
00514                      i = icalproperty_get_sequence(prop);
00515                      syslog(9, "Sequence was %d\n", i);
00516                      if (i > sequence) sequence = i;
00517                      icalcomponent_remove_property(vtodo, prop);
00518                      icalproperty_free(prop);
00519               }
00520               ++sequence;
00521               syslog(9, "New sequence is %d.  Adding...\n", sequence);
00522               icalcomponent_add_property(vtodo,
00523                                       icalproperty_new_sequence(sequence)
00524                      );
00525 
00526               /*
00527                * Encapsulate event into full VCALENDAR component.  Clone it first,
00528                * for two reasons: one, it's easier to just free the whole thing
00529                * when we're done instead of unbundling, but more importantly, we
00530                * can't encapsulate something that may already be encapsulated
00531                * somewhere else.
00532                */
00533               syslog(9, "Encapsulating into a full VCALENDAR component\n");
00534               encaps = ical_encapsulate_subcomponent(icalcomponent_new_clone(vtodo));
00535 
00536               /* Serialize it and save it to the message base */
00537               serv_puts("ENT0 1|||4");
00538               serv_getln(buf, sizeof buf);
00539               if (buf[0] == '4') {
00540                      serv_puts("Content-type: text/calendar");
00541                      serv_puts("");
00542                      serv_puts(icalcomponent_as_ical_string(encaps));
00543                      serv_puts("000");
00544 
00545                      /*
00546                       * Probably not necessary; the server will see the UID
00547                       * of the object and delete the old one anyway, but
00548                       * just in case...
00549                       */
00550                      delete_existing = 1;
00551               }
00552               icalcomponent_free(encaps);
00553        }
00554 
00558        if (havebstr("delete_button")) {
00559               delete_existing = 1;
00560        }
00561 
00562        if ( (delete_existing) && (msgnum > 0L) ) {
00563               serv_printf("DELE %ld", lbstr("msgnum"));
00564               serv_getln(buf, sizeof buf);
00565        }
00566 
00567        if (created_new_vtodo) {
00568               icalcomponent_free(vtodo);
00569        }
00570 
00571        /* Go back to wherever we came from */
00572        if (ibstr("return_to_summary") == 1) {
00573               display_summary_page();
00574        }
00575        else {
00576               readloop(readfwd, eUseDefault);
00577        }
00578 }
00579 
00580 
00581 /*
00582  * free memory allocated using libical
00583  */
00584 void delete_task(void *vCal)
00585 {
00586         disp_cal *Cal = (disp_cal*) vCal;
00587         icalcomponent_free(Cal->cal);
00588         free(Cal->from);
00589         free(Cal);
00590 }
00591 
00592 
00593 /*
00594  * Load a Task into a hash table for later display.
00595  */
00596 void load_task(icalcomponent *event, long msgnum, char *from, int unread, calview *calv)
00597 {
00598        icalproperty *ps = NULL;
00599        struct icaltimetype dtstart, dtend;
00600        wcsession *WCC = WC;
00601        disp_cal *Cal;
00602        size_t len;
00603        icalcomponent *cptr = NULL;
00604 
00605        dtstart = icaltime_null_time();
00606        dtend = icaltime_null_time();
00607        
00608        if (WCC->disp_cal_items == NULL) {
00609               WCC->disp_cal_items = NewHash(0, Flathash);
00610        }
00611 
00612        Cal = (disp_cal*) malloc(sizeof(disp_cal));
00613        memset(Cal, 0, sizeof(disp_cal));
00614        Cal->cal = icalcomponent_new_clone(event);
00615 
00616        /* Dezonify and decapsulate at the very last moment */
00617        ical_dezonify(Cal->cal);
00618        if (icalcomponent_isa(Cal->cal) != ICAL_VTODO_COMPONENT) {
00619               cptr = icalcomponent_get_first_component(Cal->cal, ICAL_VTODO_COMPONENT);
00620               if (cptr) {
00621                      cptr = icalcomponent_new_clone(cptr);
00622                      icalcomponent_free(Cal->cal);
00623                      Cal->cal = cptr;
00624               }
00625        }
00626 
00627        Cal->unread = unread;
00628        len = strlen(from);
00629        Cal->from = (char*)malloc(len+ 1);
00630        memcpy(Cal->from, from, len + 1);
00631        Cal->cal_msgnum = msgnum;
00632 
00633        /* Precalculate the starting date and time of this event, and store it in our top-level
00634         * structure.  Later, when we are rendering the calendar, we can just peek at these values
00635         * without having to break apart every calendar item.
00636         */
00637        ps = icalcomponent_get_first_property(Cal->cal, ICAL_DTSTART_PROPERTY);
00638        if (ps != NULL) {
00639               dtstart = icalproperty_get_dtstart(ps);
00640               Cal->event_start = icaltime_as_timet(dtstart);
00641        }
00642 
00643        /* Do the same for the ending date and time.  It makes the day view much easier to render. */
00644        ps = icalcomponent_get_first_property(Cal->cal, ICAL_DTEND_PROPERTY);
00645        if (ps != NULL) {
00646               dtend = icalproperty_get_dtend(ps);
00647               Cal->event_end = icaltime_as_timet(dtend);
00648        }
00649 
00650        /* Store it in the hash list. */
00651        /* syslog(LOG_DEBUG, "INITIAL: %s", ctime(&Cal->event_start)); */
00652        Put(WCC->disp_cal_items, 
00653            (char*) &Cal->event_start,
00654            sizeof(Cal->event_start), 
00655            Cal, 
00656            delete_task
00657        );
00658 }
00659 
00660 
00661 
00662 /*
00663  * Display task view
00664  */
00665 int tasks_LoadMsgFromServer(SharedMessageStatus *Stat, 
00666                          void **ViewSpecific, 
00667                          message_summary* Msg, 
00668                          int is_new, 
00669                          int i)
00670 {
00671        /* Not (yet?) needed here? calview *c = (calview *) *ViewSpecific; */
00672 
00673        load_ical_object(Msg->msgnum, is_new, ICAL_VTODO_COMPONENT, load_task, NULL, 0);
00674        return 0;
00675 }
00676 
00677 /*
00678  * Display the editor component for a task
00679  */
00680 void display_edit_task(void) {
00681        long msgnum = 0L;
00682                      
00683        /* Force change the room if we have to */
00684        if (havebstr("taskrm")) {
00685               gotoroom(sbstr("taskrm"));
00686        }
00687 
00688        msgnum = lbstr("msgnum");
00689        if (msgnum > 0L) {
00690               /* existing task */
00691               load_ical_object(msgnum, 0,
00692                              ICAL_VTODO_COMPONENT,
00693                              display_edit_individual_task,
00694                              NULL, 0
00695               );
00696        }
00697        else {
00698               /* new task */
00699               display_edit_individual_task(NULL, 0L, "", 0, NULL);
00700        }
00701 }
00702 
00703 /*
00704  * save an edited task
00705  */
00706 void save_task(void) {
00707        long msgnum = 0L;
00708        msgnum = lbstr("msgnum");
00709        if (msgnum > 0L) {
00710               load_ical_object(msgnum, 0, ICAL_VTODO_COMPONENT, save_individual_task, NULL, 0);
00711        }
00712        else {
00713               save_individual_task(NULL, 0L, "", 0, NULL);
00714        }
00715 }
00716 
00717 
00718 
00719 int tasks_GetParamsGetServerCall(SharedMessageStatus *Stat, 
00720                              void **ViewSpecific, 
00721                              long oper, 
00722                              char *cmd, 
00723                              long len,
00724                              char *filter,
00725                              long flen)
00726 {
00727        strcpy(cmd, "MSGS ALL");
00728        Stat->maxmsgs = 32767;
00729        return 200;
00730 }
00731 
00732 
00733 int tasks_Cleanup(void **ViewSpecific)
00734 {
00735        wDumpContent(1);
00736 /* Tasks doesn't need the calview struct... 
00737        free (*ViewSpecific);
00738        *ViewSpecific = NULL;
00739        */
00740        return 0;
00741 }
00742 
00743 void 
00744 InitModule_TASKS
00745 (void)
00746 {
00747        RegisterReadLoopHandlerset(
00748               VIEW_TASKS,
00749               tasks_GetParamsGetServerCall,
00750               NULL,
00751               NULL,
00752               NULL,
00753               tasks_LoadMsgFromServer,
00754               tasks_RenderView_or_Tail,
00755               tasks_Cleanup);
00756        WebcitAddUrlHandler(HKEY("save_task"), "", 0, save_task, 0);
00757 }