home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1999 November / PCOnline_11_1999.iso / filesbbs / OS2 / MMSRC029.ZIP / mmail-0.29 / interfac / arealist.cc < prev    next >
C/C++ Source or Header  |  1999-08-23  |  8KB  |  369 lines

  1. /*
  2.  * MultiMail offline mail reader
  3.  * area list
  4.  
  5.  Copyright (c) 1996 Kolossvary Tamas <thomas@vma.bme.hu>
  6.  Copyright (c) 1999 William McBrine <wmcbrine@clark.net>
  7.  
  8.  Distributed under the GNU General Public License.
  9.  For details, see the file COPYING in the parent directory. */
  10.  
  11. #include "interfac.h"
  12.  
  13. //**************        LittleAreaListWindow    *****************
  14.  
  15. void LittleAreaListWindow::MakeActive()
  16. {
  17.     position = active = 0;
  18.     areanum = -1;
  19.  
  20.     disp = 0;
  21.     do
  22.         mm.areaList->gotoActive(disp++);
  23.     while (mm.areaList->isCollection());
  24.     disp--;
  25.  
  26.     list_max_y = (NumOfItems() < LINES - 10) ? NumOfItems() : LINES - 10;
  27.     list_max_x = 52;
  28.     top_offset = 3;
  29.  
  30.     borderCol = C_LALBTEXT;
  31.  
  32.     list = new InfoWin(list_max_y + 4, 54, 3, borderCol, 0, 0, 4,
  33.         top_offset);
  34.  
  35.     mm.areaList->gotoArea(mm.letterList->getAreaID());
  36.     active = mm.areaList->getActive() - disp;
  37.  
  38.     list->put(1, 2, "Reply goes to area:");
  39.  
  40.     DrawAll();
  41.  
  42.     Select();
  43. }
  44.  
  45. void LittleAreaListWindow::Select()
  46. {
  47.     mm.areaList->gotoActive(active + disp);
  48. }
  49.  
  50. void LittleAreaListWindow::Delete()
  51. {
  52.     delete list;
  53. }
  54.  
  55. int LittleAreaListWindow::getArea()
  56. {
  57.     return areanum;
  58. }
  59.  
  60. int LittleAreaListWindow::NumOfItems()
  61. {
  62.     return mm.areaList->noOfActive() - disp;
  63. }
  64.  
  65. void LittleAreaListWindow::oneLine(int i)
  66. {
  67.     mm.areaList->gotoActive(position + i + disp);
  68.     sprintf(list->lineBuf, "%c%-50.50s ", (!mm.areaList->isShortlist()
  69.         && (mm.areaList->getType() & ACTIVE)) ? '*' : ' ',
  70.         mm.areaList->getDescription());
  71.     areaconv_in(list->lineBuf);
  72.     DrawOne(i, C_LALLINES);
  73. }
  74.  
  75. searchret LittleAreaListWindow::oneSearch(int x, const char *item,
  76.     int ignore)
  77. {
  78.     ignore = ignore;
  79.     mm.areaList->gotoActive(x + disp);
  80.     return searchstr(mm.areaList->getDescription(), item) ? True : False;
  81. }
  82.  
  83. bool LittleAreaListWindow::extrakeys(int key)
  84. {
  85.     switch (key) {
  86.     case MM_ENTER:
  87.         Select();
  88.         areanum = mm.areaList->getAreaNo();
  89.         break;
  90.     case 'L':
  91.         interface->areas.Select();
  92.         interface->areas.KeyHandle('L');
  93.     }
  94.     return false;
  95. }
  96.  
  97. //*************         AreaListWindow          ******************
  98.  
  99. void AreaListWindow::FirstUnread()
  100. {
  101.     int i;
  102.  
  103.     position = active = 0;
  104.     for (i = 0; i < NumOfItems(); i++) {
  105.         mm.areaList->gotoActive(i);
  106.         if (!mm.areaList->getNoOfUnread())
  107.             Move(DOWN);
  108.         else
  109.             break;
  110.     }
  111.     if (i == NumOfItems()) {
  112.         position = active = 0;
  113.         for (i = 0; i < NumOfItems(); i++) {
  114.             mm.areaList->gotoActive(i);
  115.             if (!mm.areaList->getNoOfLetters())
  116.                 Move(DOWN);
  117.             else
  118.                 break;
  119.         }
  120.     }
  121. }
  122.  
  123. int AreaListWindow::NumOfItems()
  124. {
  125.     return mm.areaList->noOfActive();
  126. }
  127.  
  128. void AreaListWindow::oneLine(int i)
  129. {
  130.     char *p = list->lineBuf;
  131.  
  132.     mm.areaList->gotoActive(position + i);
  133.  
  134.     int attrib = mm.areaList->getType();
  135.  
  136.     if (position + i == active) {
  137.         p += sprintf(p, "%.20s", mm.areaList->getAreaType());
  138.  
  139.         if (mm.areaList->isNetmail())
  140.             p += sprintf(p, ", Netmail");
  141.         else
  142.             if (mm.areaList->isInternet())
  143.                 p += sprintf(p, ", Email");
  144.             else
  145.                 if (mm.areaList->isUsenet())
  146.                     p += sprintf(p, ", Usenet");
  147.                 else
  148.                     if (attrib & ECHO)
  149.                         p += sprintf(p, ", Echo");
  150.  
  151.         if (attrib & PERSONLY)
  152.             p += sprintf(p, ", Pers");
  153.         else
  154.             if (attrib & PERSALL)
  155.                 p += sprintf(p, ", Pers+All");
  156.  
  157.         int q = 27 - (p - list->lineBuf);
  158.         while (--q > 0)
  159.             sprintf(p++, " ");
  160.         p = list->lineBuf;
  161.  
  162.         list->attrib(C_ALINFOTEXT2);
  163.         list->put(list_max_y + 4, 8, p);
  164.  
  165.         sprintf(p, format2, mm.areaList->getDescription());
  166.         areaconv_in(p);
  167.         list->put(list_max_y + 5, 20, p);
  168.  
  169.         list->delay_update();
  170.     }
  171.     p += sprintf(p, format, ((attrib & ADDED) ? '+' :
  172.         ((attrib & DROPPED) ? '-' : ((attrib & ACTIVE) &&
  173.         !mm.areaList->isShortlist()) ? '*' : ' ')),
  174.         mm.areaList->getShortName(), mm.areaList->getDescription());
  175.  
  176.     if (mm.areaList->getNoOfLetters())
  177.         p += sprintf(p, "  %5d  ", mm.areaList->getNoOfLetters());
  178.     else
  179.         p += sprintf(p, "      .  ");
  180.  
  181.     if (mm.areaList->getNoOfUnread())
  182.         p += sprintf(p, "  %5d   ", mm.areaList->getNoOfUnread());
  183.     else
  184.         p += sprintf(p, "      .   ");
  185.  
  186.     if (mode)
  187.         if (mm.areaList->getNoOfPersonal())
  188.             sprintf(p, "   %5d   ",
  189.                 mm.areaList->getNoOfPersonal());
  190.         else
  191.             sprintf(p, "       .   ");
  192.  
  193.     chtype ch = (attrib & (REPLYAREA | ADDED | DROPPED)) ?
  194.         C_ALREPLINE : C_ALPACKETLINE;
  195.  
  196.     areaconv_in(list->lineBuf);
  197.     DrawOne(i, mm.areaList->getNoOfUnread() ? emph(ch) : noemph(ch));
  198. }
  199.  
  200. searchret AreaListWindow::oneSearch(int x, const char *item, int mode)
  201. {
  202.     const char *s;
  203.     searchret retval;
  204.  
  205.     mm.areaList->gotoActive(x);
  206.  
  207.     s = searchstr(mm.areaList->getShortName(), item);
  208.     if (!s)
  209.         s = searchstr(mm.areaList->getDescription(), item);
  210.  
  211.     retval = s ? True : False;
  212.     if (!s && (mode < s_arealist) && mm.areaList->getNoOfLetters()) {
  213.         int oldactive = active;
  214.         ResetActive();
  215.         mm.areaList->getLetterList();
  216.         mm.letterList->relist();
  217.         interface->changestate(letterlist);
  218.         interface->letters.setActive(-1);
  219.         retval = interface->letters.search(item, mode);
  220.         if (retval != True) {
  221.             active = oldactive;
  222.             interface->changestate(arealist);
  223.             delete mm.letterList;
  224.         }
  225.     }
  226.  
  227.     return retval;
  228. }
  229.  
  230. void AreaListWindow::Select()
  231. {
  232.     mm.areaList->gotoActive(active);
  233. }
  234.  
  235. void AreaListWindow::ResetActive()
  236. {
  237.     active = mm.areaList->getActive();
  238. }
  239.  
  240. void AreaListWindow::MakeActive()
  241. {
  242.     int padding, middle;
  243.     char tmp[80], tpad[7];
  244.  
  245.     mode = mm.driverList->hasPersonal();
  246.  
  247.     sprintf(tmp, "Message Areas (%d)", NumOfItems());
  248.  
  249.     list_max_y = LINES - 15;
  250.     list_max_x = COLS - 6;
  251.     top_offset = 2;
  252.  
  253.     borderCol = C_ALBORDER;
  254.  
  255.     list = new InfoWin(list_max_y + 7, list_max_x + 2, 2, borderCol,
  256.         tmp, C_ALBTEXT, 7);
  257.  
  258.     list->attrib(C_ALHEADTEXT);
  259.     list->put(1, 3, "Area#  Description");
  260.     int newloc = list_max_x - 15;
  261.     if (mode)
  262.         newloc -= 11;
  263.     list->put(1, newloc, "Total   Unread");
  264.     if (mode)
  265.         list->put(1, list_max_x - 9, "Personal");
  266.  
  267.     list->horizline(list_max_y + 2, list_max_x);
  268.  
  269.     padding = list_max_x - 28;
  270.     if (mode)
  271.         padding -= 11;
  272.     sprintf(format, "%%c%%6s  %%-%d.%ds", padding, padding);
  273.  
  274.     middle = (list_max_x - 2) >> 1;
  275.  
  276.     list->attrib(C_ALINFOTEXT);
  277.     list->put(list_max_y + 3, 3, "BBS:");
  278.     list->put(list_max_y + 3, middle, " Sysop:");
  279.     list->put(list_max_y + 4, 2, "Type:");
  280.     list->put(list_max_y + 4, middle, "Packet:");
  281.     list->put(list_max_y + 5, 2, "Area description:");
  282.  
  283.     sprintf(tpad, "%%.%ds", (middle < 87) ? middle - 8 : 79);
  284.     middle += 8;
  285.  
  286.     list->attrib(C_ALINFOTEXT2);
  287.     sprintf(tmp, tpad, mm.resourceObject->get(BBSName));
  288.     charconv_in(tmp);
  289.     list->put(list_max_y + 3, 8, tmp);
  290.  
  291.     sprintf(tmp, tpad, mm.resourceObject->get(SysOpName));
  292.     charconv_in(tmp);
  293.     list->put(list_max_y + 3, middle, tmp);
  294.  
  295.     list->put(list_max_y + 4, middle, mm.resourceObject->get(PacketName));
  296.  
  297.     padding = list_max_x - 20;
  298.     sprintf(format2, "%%-%d.%ds", padding, padding);
  299.  
  300.     DrawAll();
  301.     Select();
  302. }
  303.  
  304. void AreaListWindow::Delete()
  305. {
  306.     delete list;
  307. }
  308.  
  309. void AreaListWindow::Prev()
  310. {
  311.     do {
  312.         Move(UP);
  313.         Select();
  314.     } while (!mm.areaList->getNoOfLetters() &&
  315.          (mm.areaList->getActive() > 0));
  316. }
  317.  
  318. void AreaListWindow::Next()
  319. {
  320.     do {
  321.         Move(DOWN);
  322.         Select();
  323.     } while (!mm.areaList->getNoOfLetters() &&
  324.          (mm.areaList->getActive() <
  325.           mm.areaList->noOfActive() - 1));
  326. }
  327.  
  328. bool AreaListWindow::extrakeys(int key)
  329. {
  330.     bool end = false;
  331.  
  332.     Select();
  333.     switch (key) {
  334.     case 'E':
  335.         if (!mm.areaList->isCollection()) {
  336.             if (mm.areaList->isEmail()) {
  337.                 interface->addressbook();
  338.                 Select();
  339.             }
  340.             interface->letterwindow.set_Letter_Params(
  341.                 mm.areaList->getAreaNo(), 'E');
  342.             interface->letterwindow.EnterLetter();
  343.             interface->redraw();
  344.         }
  345.         break;
  346.     case 'L':
  347.         mm.areaList->relist();
  348.         ResetActive();
  349.         interface->redraw();
  350.         break;
  351.     case 'S':
  352.     case KEY_IC:
  353.     case 'U':
  354.     case KEY_DC:
  355.         if (mm.areaList->hasOffConfig()) {
  356.             if ((key == 'S') || (key == KEY_IC))
  357.                 mm.areaList->Add();
  358.             else
  359.                 mm.areaList->Drop();
  360.             interface->setUnsavedNoAuto();
  361.             Move(DOWN);
  362.             Draw();
  363.         } else
  364.             interface->nonFatalError(
  365.                 "Offline config is unavailable");
  366.     }
  367.     return end;
  368. }
  369.