Lines Matching defs:toc
1 /* $XConsortium: toc.c,v 2.59 95/01/09 16:52:53 swick Exp $
2 * $XFree86: xc/programs/xmh/toc.c,v 3.4 2001/10/28 03:34:39 tsi Exp $
28 /* toc.c -- handle things in the toc widget. */
32 #include "toc.h"
107 int TocFolderExists(Toc toc)
110 if (! toc->path) {
111 XtAsprintf(&toc->path, "%s/%s",
112 app_resources.mail_path, toc->foldername);
114 return ((stat(toc->path, &buf) == 0) &&
158 Toc toc;
183 toc = folderList[i] = TUMalloc();
184 toc->foldername = XtNewString(namelist[i]);
198 /* Create a toc and add a folder to the folderList. */
202 Toc toc = TUMalloc();
204 toc->foldername = XtNewString(foldername);
206 folderList[numFolders - 1] = toc;
207 return toc;
215 Toc toc;
221 toc = TocCreate(foldername);
222 return toc;
225 int TocHasMail(Toc toc)
227 return toc->mailpending;
230 static int CheckForNewMail(Toc toc)
232 if (toc->incfile)
233 return (GetFileLength(toc->incfile) > 0);
234 else if (toc == InitialFolder) {
257 Toc toc;
264 toc = folderList[i];
265 if (TocCanIncorporate(toc)) {
266 toc->mailpending = hasmail = CheckForNewMail(toc);
272 BBoxMailFlag(scrn->folderbuttons, TocName(toc),
279 toc = folderList[i];
280 if (toc->mailpending) {
319 Boolean TocTestAndSetDeletePending(Toc toc)
323 flag = toc->delete_pending;
324 toc->delete_pending = True;
328 void TocClearDeletePending(Toc toc)
330 toc->delete_pending = False;
364 void TocDeleteFolder(Toc toc)
368 if (toc == NULL) return;
369 TUGetFullFolderInfo(toc);
374 if (toc2 == toc)
378 if (toc2->msgs[j]->desttoc == toc)
382 NukeDirectory(toc->path);
383 if (toc->validity == valid) {
384 for (i=0 ; i<toc->nummsgs ; i++) {
385 MsgSetScrnForce(toc->msgs[i], (Scrn) NULL);
386 MsgFree(toc->msgs[i]);
388 XtFree((char *) toc->msgs);
390 XtFree((char *)toc);
397 * Display the given toc in the given scrn. If scrn is NULL, then remove the
398 * toc from all scrns displaying it.
401 void TocSetScrn(Toc toc, Scrn scrn)
405 if (toc == NULL && scrn == NULL) return;
407 for (i=0 ; i<toc->num_scrns ; i++)
408 TocSetScrn((Toc) NULL, toc->scrn[i]);
411 if (scrn->toc == toc) return;
412 if (scrn->toc != NULL) {
413 for (i=0 ; i<scrn->toc->num_scrns ; i++)
414 if (scrn->toc->scrn[i] == scrn) break;
415 if (i >= scrn->toc->num_scrns)
417 scrn->toc->scrn[i] = scrn->toc->scrn[--scrn->toc->num_scrns];
419 scrn->toc = toc;
420 if (toc == NULL) {
425 toc->num_scrns++;
426 toc->scrn = XtReallocArray(toc->scrn, toc->num_scrns, sizeof(Scrn));
427 toc->scrn[toc->num_scrns - 1] = scrn;
428 TUEnsureScanIsValidAndOpen(toc, True);
433 progName, toc->foldername);
437 StoreWindowName(scrn, toc->foldername);
439 SetCurrentFolderName(scrn, toc->foldername);
446 /* Remove the given message from the toc. Doesn't actually touch the file.
449 void TocRemoveMsg(Toc toc, Msg msg)
454 if (toc->validity == unknown)
455 TUGetFullFolderInfo(toc);
456 if (toc->validity != valid)
458 newcurmsg = TocMsgAfter(toc, msg);
460 newcurmsg = toc->curmsg;
461 if (msg == toc->curmsg) {
462 newcurmsg = TocMsgAfter(toc, msg);
463 if (newcurmsg == NULL) newcurmsg = TocMsgBefore(toc, msg);
464 toc->curmsg = NULL;
466 toc->length -= msg->length;
467 if (msg->visible) toc->lastPos -= msg->length;
468 for(i = TUGetMsgPosition(toc, msg), toc->nummsgs--; i<toc->nummsgs ; i++) {
469 toc->msgs[i] = toc->msgs[i+1];
470 if (msg->visible) toc->msgs[i]->position -= msg->length;
472 for (i=0 ; i<toc->numsequences ; i++) {
473 mlist = toc->seqlist[i]->mlist;
477 if (msg->visible && toc->num_scrns > 0 && !toc->needsrepaint)
478 TSourceInvalid(toc, msg->position, -msg->length);
479 TocSetCurMsg(toc, newcurmsg);
480 TUSaveTocFile(toc);
485 void TocRecheckValidity(Toc toc)
489 if (toc && toc->validity == valid && TUScanFileOutOfDate(toc)) {
492 TUScanFileForToc(toc);
493 if (toc->source)
494 TULoadTocFile(toc);
495 for (i=0 ; i<toc->num_scrns ; i++)
496 TURedisplayToc(toc->scrn[i]);
505 void TocSetCurMsg(Toc toc, Msg msg)
510 if (toc->validity != valid) return;
511 if (msg != toc->curmsg) {
512 msg2 = toc->curmsg;
513 toc->curmsg = msg;
519 if (toc->num_scrns) {
520 if (toc->stopupdate)
521 toc->needsrepaint = TRUE;
523 for (i=0 ; i<toc->num_scrns ; i++)
524 XawTextSetInsertionPoint(toc->scrn[i]->tocwidget,
534 Msg TocGetCurMsg(Toc toc)
536 return toc->curmsg;
544 Msg TocMsgAfter(Toc toc, Msg msg)
547 i = TUGetMsgPosition(toc, msg);
550 if (i >= toc->nummsgs)
552 } while (!(toc->msgs[i]->visible));
553 return toc->msgs[i];
560 Msg TocMsgBefore(Toc toc, Msg msg)
563 i = TUGetMsgPosition(toc, msg);
568 } while (!(toc->msgs[i]->visible));
569 return toc->msgs[i];
574 /* The caller KNOWS the toc's information is out of date; rescan it. */
576 void TocForceRescan(Toc toc)
580 if (toc->num_scrns) {
581 toc->viewedseq = toc->seqlist[0];
582 for (i=0 ; i<toc->num_scrns ; i++)
583 TUResetTocLabel(toc->scrn[i]);
584 TUScanFileForToc(toc);
585 TULoadTocFile(toc);
586 for (i=0 ; i<toc->num_scrns ; i++)
587 TURedisplayToc(toc->scrn[i]);
589 TUGetFullFolderInfo(toc);
590 (void) unlink(toc->scanfile);
591 toc->validity = invalid;
599 void TocReloadSeqLists(Toc toc)
603 TocSetCacheValid(toc);
604 TULoadSeqLists(toc);
605 TURefigureWhatsVisible(toc);
606 for (i=0 ; i<toc->num_scrns ; i++) {
607 TUResetTocLabel(toc->scrn[i]);
608 EnableProperButtons(toc->scrn[i]);
621 TocReloadSeqLists(scrn->toc);
622 TUCheckSequenceMenu(scrn->toc);
627 /* Return TRUE if the toc has an interesting sequence. */
629 int TocHasSequences(Toc toc)
631 return toc && toc->numsequences > 1;
637 void TocChangeViewedSeq(Toc toc, Sequence seq)
639 if (seq == NULL) seq = toc->viewedseq;
640 toc->viewedseq = seq;
641 toc->force_reset = True; /* %%% force Text source to be reset */
642 TURefigureWhatsVisible(toc);
646 /* Return the sequence with the given name in the given toc. */
648 Sequence TocGetSeqNamed(Toc toc, const char *name)
654 for (i=0 ; i<toc->numsequences ; i++)
655 if (strcmp(toc->seqlist[i]->name, name) == 0)
656 return toc->seqlist[i];
661 /* Return the sequence currently being viewed in the toc. */
663 Sequence TocViewedSequence(Toc toc)
665 return toc->viewedseq;
669 /* Set the selected sequence in the toc */
672 Toc toc,
675 if (toc)
676 toc->selectseq = sequence;
682 Sequence TocSelectedSequence(Toc toc)
684 if (toc) return (toc->selectseq);
693 MsgList TocCurMsgList(Toc toc)
698 if (toc->num_scrns == 0) return NULL;
700 XawTextGetSelectionPos( toc->scrn[0]->tocwidget, &pos1, &pos2); /* %%% */
702 pos1 = SrcScan(toc->source, pos1, XawstEOL, XawsdLeft, 1, FALSE);
703 pos2 = SrcScan(toc->source, pos2, XawstPositions, XawsdLeft, 1, TRUE);
704 pos2 = SrcScan(toc->source, pos2, XawstEOL, XawsdRight, 1, FALSE);
706 AppendMsgList(result, MsgFromPosition(toc, pos1, XawsdRight));
707 pos1 = SrcScan(toc->source, pos1, XawstEOL, XawsdRight, 1, TRUE);
717 void TocUnsetSelection(Toc toc)
719 if (toc->source)
720 XawTextUnsetSelection(toc->scrn[0]->tocwidget);
727 Msg TocMakeNewMsg(Toc toc)
731 TUEnsureScanIsValidAndOpen(toc, False);
732 msg = TUAppendToc(toc, "#### empty\n");
736 toc->foldername, msg->msgid);
737 TocForceRescan(toc);
738 return TocMakeNewMsg(toc); /* Try again. Using recursion here is ugly,
749 void TocStopUpdate(Toc toc)
753 for (i=0 ; i<toc->num_scrns ; i++)
754 XawTextDisableRedisplay(toc->scrn[i]->tocwidget);
755 toc->stopupdate++;
761 void TocStartUpdate(Toc toc)
765 if (toc->stopupdate && --(toc->stopupdate) == 0) {
766 for (i=0 ; i<toc->num_scrns ; i++) {
767 if (toc->needsrepaint)
768 TURedisplayToc(toc->scrn[i]);
769 if (toc->needslabelupdate)
770 TUResetTocLabel(toc->scrn[i]);
772 if (toc->needscachesave)
773 TUSaveTocFile(toc);
775 for (i=0 ; i<toc->num_scrns ; i++)
776 XawTextEnableRedisplay(toc->scrn[i]->tocwidget);
784 void TocSetCacheValid(Toc toc)
786 TUSaveTocFile(toc);
790 /* Return the full folder pathname of the given toc, prefixed w/'+' */
792 char *TocMakeFolderName(Toc toc)
795 XtAsprintf(&name, "+%s", toc->path);
799 char *TocName(Toc toc)
801 return toc->foldername;
806 /* Given a foldername, return the corresponding toc. */
817 Boolean TocHasChanges(Toc toc)
820 for (i=0 ; i<toc->nummsgs ; i++)
821 if (toc->msgs[i]->fate != Fignore) return True;
828 /* Throw out all changes to this toc, and close all views of msgs in it.
837 Toc toc = (Toc) client_data;
840 for (i=0; i < toc->nummsgs; i++)
841 MsgSetFate(toc->msgs[i], Fignore, (Toc)NULL);
844 for (i=0; i < toc->nummsgs; i++)
845 MsgSetScrn(toc->msgs[i], (Scrn) NULL, (XtCallbackList) NULL,
850 Toc toc,
862 if (! toc)
865 if (TocHasChanges(toc)) {
871 toc->foldername);
872 yes_callbacks[0].closure = (XtPointer) toc;
877 for (i=0; i < toc->num_scrns; i++)
878 if (toc->scrn[i]->mapped) {
879 tocwidget = toc->scrn[i]->tocwidget;
888 for (i=0 ; i<toc->nummsgs ; i++)
889 MsgSetFate(toc->msgs[i], Fignore, (Toc)NULL);
891 for (i=0 ; i<toc->nummsgs ; i++)
892 if (MsgSetScrn(toc->msgs[i], (Scrn) NULL, confirms, cancels))
899 /* Commit all the changes in this toc; all messages will meet their 'fate'. */
907 Toc toc = (Toc) client_data;
917 confirms[0].closure = (XtPointer) toc;
921 if (toc == NULL) return;
922 for (i=0 ; i<toc->nummsgs ; i++) {
923 msg = toc->msgs[i];
930 XFlush(XtDisplay(toc->scrn[0]->parent));
933 toc->haschanged = TRUE;
939 while (i < toc->nummsgs) {
940 msg = toc->msgs[i];
948 argv[1] = TocMakeFolderName(toc);
973 TocRemoveMsg(toc, msg);
990 argv[cur++] = TocMakeFolderName(toc);
1021 /* Return whether the given toc can incorporate mail. */
1023 int TocCanIncorporate(Toc toc)
1025 return (toc && (toc == InitialFolder || toc->incfile));
1029 /* Incorporate new messages into the given toc. */
1031 int TocIncorporate(Toc toc)
1038 argv = MakeArgv(toc->incfile ? 7 : 4);
1040 argv[1] = TocMakeFolderName(toc);
1044 if (toc->incfile) {
1046 argv[5] = toc->incfile;
1054 TUGetFullFolderInfo(toc);
1055 if (toc->validity == valid) {
1057 TocStopUpdate(toc);
1060 msg = TUAppendToc(toc, ptr);
1065 TocSetCurMsg(toc, firstmessage);
1067 TocStartUpdate(toc);
1074 toc->mailpending = False;
1081 void TocMsgChanged(Toc toc, Msg msg)
1089 if (toc->validity != valid) return;
1094 argv[1] = TocMakeFolderName(toc);
1110 toc->length += delta;
1113 for (i=TUGetMsgPosition(toc, msg)+1; i<toc->nummsgs ; i++)
1114 toc->msgs[i]->position += delta;
1115 toc->lastPos += delta;
1117 for (i=0 ; i<toc->num_scrns ; i++)
1118 TURedisplayToc(toc->scrn[i]);
1121 TUSaveTocFile(toc);
1127 Msg TocMsgFromId(Toc toc, int msgid)
1131 h = toc->nummsgs - 1;
1133 DEBUG1("Toc is empty! folder=%s\n", toc->foldername)
1138 if (toc->msgs[m]->msgid > msgid)
1143 if (toc->msgs[l]->msgid == msgid) return toc->msgs[l];
1144 if (toc->msgs[h]->msgid == msgid) return toc->msgs[h];
1167 Toc toc;
1170 if (! (toc = scrn->toc)) return;
1173 if (toc->selectseq)
1174 Push(&toc->sequence_stack, XtNewString(toc->selectseq->name));
1178 Push(&toc->sequence_stack, XtNewString(params[i]));
1195 if ((seqname = Pop(&scrn->toc->sequence_stack)) != NULL) {
1206 sequence = TocGetSeqNamed(scrn->toc, seqname);
1207 TocSetSelectedSequence(scrn->toc, sequence);