home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 10 / AU_CD10.iso / Archived / MP3 / Riscster / riscsrc / c / !Runimage next >
Text File  |  2000-05-24  |  38KB  |  1,451 lines

  1. /*
  2.        _             __
  3.   ____(_)__ _______ / /____ ____
  4.  / __/ (_-</ __(_-</ __/ -_) __/
  5. /_/ /_/___/\__/___/\__/\__/_/   
  6.  
  7. Napster client for RISC OS
  8. Copyright (C) 2000 Robert Dimond
  9.  
  10. Portions are based on gnap by Ryan Dahl.
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program; if not, write to the Free Software
  24. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
  25.  
  26. Bransley Cottage, Cleobury Mortimer, Kidderminster, WORCS. DY14 0BZ
  27. England. robdimond@cwcom.net
  28.  
  29. */
  30.  
  31. #include "runimage.h"
  32.  
  33. int wmversion, finished = FALSE;
  34. wimp_t taskhandle;
  35.  
  36.  
  37.  
  38. connect_level connected=notc;
  39.  
  40. int message_expire=-1;
  41.  
  42. char email[100]="";
  43. char username[100]="", password[100]="";
  44. int connection=0;
  45.  
  46. int listening_port;
  47. int new_user=0;
  48.  
  49. char * motd[100];
  50. int motd_line=0;
  51.  
  52. wimp_w win_connect;
  53. wimp_window * win_connectb;
  54. wimp_w win_info;
  55. wimp_window * win_infob;
  56. wimp_w win_mess;
  57. wimp_window * win_messb;
  58. wimp_w win_motd;
  59. wimp_window * win_motdb;
  60. wimp_w win_search;
  61. wimp_window * win_searchb;
  62. wimp_w win_searchres;
  63. wimp_window * win_searchresb;
  64.  
  65. wimp_window * win_getb[C_DOWNLOADS];
  66.  
  67. osspriteop_area * sarea;
  68.  
  69. wimp_i icon_iconbar;
  70.  
  71. const char title[]="Riscster";
  72.  
  73. char * indirected_sp;
  74. char * nextwd;
  75.  
  76. messagetrans_control_block mess_controlblock;
  77. char * mbuffer;
  78.  
  79. wimp_menu * menu_ibar;
  80. wimp_menu * menu_con;
  81. wimp_menu * menu_com;
  82.  
  83. int menu_com_last;
  84. wimp_w menu_con_last;
  85.  
  86. wimp_menu * menu_open;
  87.  
  88. int search_connection=0;
  89. int search_c_br=0;
  90. int search_c_lt=0;
  91. int search_c_fr=0;
  92. const char search_c[]="?>=<";
  93.  
  94. search_result * search_resblock=NULL;
  95.  
  96. int search_numres=0;
  97. int search_currentres=0;
  98.  
  99. int last_get_update;
  100.  
  101.  
  102. transfer downloads[C_DOWNLOADS];
  103.  
  104. incoming incon[C_INCOMING];
  105.  
  106.  
  107. void strcpy_nl(char * target, char * source);
  108.  
  109.  
  110. wimp_menu_entry * makeentry(char * text, wimp_menu_flags flags,wimp_menu * sub,wimp_icon_flags more);
  111. void standardmen(wimp_menu * menu);
  112. wimp_window * loadwin(char * name);
  113.  
  114.  
  115. int main(void)
  116. {
  117.  int evt;
  118.  
  119.  wimp_block block;
  120.  error(xwimp_initialise(400, title, NULL, &wmversion, &taskhandle));
  121.  motd_init();
  122.  get_init();
  123.  ui_loadmessages();
  124.  ui_loadsprites();
  125.  ui_loadwindows();
  126.  ui_setupmenus();
  127.  ui_iconbaricon();
  128.  napster_init_server();
  129.  while(!finished)
  130.  {
  131.   evt=wimp_poll(0, &block, NULL);
  132.   switch(evt)
  133.   {
  134.    case wimp_NULL_REASON_CODE: mess_nullevent(&block);
  135.    break;
  136.    case wimp_REDRAW_WINDOW_REQUEST: mess_redrawwindow(&block);
  137.    break;
  138.    case wimp_OPEN_WINDOW_REQUEST: mess_openwindow(&block);
  139.    break;
  140.    case wimp_CLOSE_WINDOW_REQUEST: mess_closewindow(&block);
  141.    break;
  142.    case wimp_MOUSE_CLICK: mess_mouseclick(&block);
  143.    break;
  144.    case wimp_KEY_PRESSED: mess_keypressed(&block);
  145.    break;
  146.    case wimp_MENU_SELECTION: mess_menuselect(&block);
  147.    break;
  148.    case wimp_USER_MESSAGE: mess_usermessage(&block);
  149.    break;
  150.   }
  151.  }
  152.  ui_close();
  153.  wimp_close_down(taskhandle);
  154.  return(0);
  155. }
  156.  
  157. void mess_keypressed(wimp_block * block)
  158. {
  159.  error(xwimp_process_key(block->key.c));
  160. }
  161.  
  162. void mess_openwindow(wimp_block * block)
  163. {
  164.  /*wimp_window_info temp;*/
  165.  wimp_open win;
  166.  error(xwimp_open_window(&(block->open)));
  167.  if (block->open.w==win_searchres)
  168.  {
  169.   /*temp.w=win_search;
  170.   error(xwimp_get_window_info(&temp));*/
  171.   win.w=win_search;
  172.   win.visible.x0=block->open.visible.x0;
  173.   win.visible.x1=block->open.visible.x1;
  174.   win.visible.y1=block->open.visible.y1;
  175.   win.visible.y0=block->open.visible.y0;
  176.   win.xscroll=0;
  177.   win.yscroll=0;
  178.   win.next=block->open.next;
  179.   error(xwimp_open_window(&win));
  180.  }
  181.  
  182. }
  183.  
  184. void mess_closewindow(wimp_block * block)
  185. {
  186.  if (block->close.w==win_searchres) error(xwimp_close_window(win_search));
  187.  error(xwimp_close_window(block->close.w));
  188. }
  189.  
  190. void mess_usermessage(wimp_block * block)
  191. {
  192.   switch(block->message.action)
  193.   {
  194.     case 0: finished = TRUE;
  195.     break;
  196.     default:;
  197.     break;
  198.   }
  199. }
  200.  
  201. void mess_nullevent(wimp_block * block)
  202. {
  203.  int i, time=0;
  204.  time=os_read_monotonic_time();
  205.  if (time>=message_expire)
  206.  {
  207.   error(xwimp_close_window(win_mess));
  208.  }
  209.  
  210.   napster_poll();
  211.  
  212.  if (time>(last_get_update+50))
  213.  {
  214.   for (i=0; i<C_DOWNLOADS; i++)
  215.                    if (downloads[i].active==download) search_updatebar(i);
  216.   last_get_update=time;
  217.  }
  218. }
  219.  
  220. void mess_mouseclick(wimp_block * block)
  221. {
  222.  int i;
  223.  if(block->pointer.i==icon_iconbar)
  224.  {
  225.   switch(block->pointer.buttons)
  226.   {
  227.    case wimp_CLICK_MENU:
  228.    error(xwimp_create_menu(menu_ibar,block->pointer.pos.x-64,96+(44*6)));
  229.    menu_open=menu_ibar;
  230.    break;
  231.    case wimp_CLICK_SELECT:
  232.    switch(connected)
  233.    {
  234.     case notc:
  235.     ui_openconnectwin();
  236.     break;
  237.     case loggedin:
  238.     search_openwin();
  239.     break;
  240.     default: break;
  241.    }
  242.    break;
  243.   }
  244.  }
  245.  if(block->pointer.w==win_connect)
  246.  {
  247.   switch(block->pointer.i)
  248.   {
  249.    case CONNECTWIN_OKICON:  ui_connectok(); break;
  250.    case CONNECTWIN_CONB:  ui_openconmenu(); break;
  251.    case CONNECTWIN_NEWUSR: ui_newuserclick(); break;
  252.   }
  253.  }
  254.  else if(block->pointer.w==win_mess)
  255.  {
  256.   if (block->pointer.i==MESSAGEWIN_DISMISS)
  257.   {
  258.    error(xwimp_close_window(win_mess));
  259.   }
  260.  }
  261.  else if(block->pointer.w==win_search)
  262.  {
  263.   switch(block->pointer.i)
  264.   {
  265.    case SEARCHWIN_BRC:
  266.    case SEARCHWIN_LTC:
  267.    case SEARCHWIN_FRC:
  268.    ui_opencommenu(block->pointer.i);
  269.    break;
  270.    case SEARCHWIN_LTM: ui_opencon2menu();
  271.    break;
  272.    case SEARCHWIN_OK: search_ok();
  273.    break;
  274.   }
  275.  }
  276.  else if(block->pointer.w==win_searchres)
  277.  {
  278.   search_click(block);
  279.  }
  280.  for (i=0; i<C_DOWNLOADS; i++)
  281.  {
  282.   if (block->pointer.w==(wimp_w) downloads[i].whandle)
  283.   {
  284.    switch(block->pointer.i)
  285.    {
  286.     case GETWIN_OK: search_getok(i); break;
  287.     case GETWIN_CANCEL: napster_download_end(i); break;
  288.    }
  289.   }
  290.  }
  291. }
  292.  
  293. void mess_menuselect(wimp_block * block)
  294. {
  295.  wimp_pointer pointer;
  296.  error(xwimp_get_pointer_info(&pointer));
  297.  if (menu_open==menu_ibar)
  298.  {
  299.   switch(block->selection.items[0])
  300.   {
  301.    case 1: ui_openconnectwin(); break;
  302.    case 2: napster_close(); break;
  303.    case 3: search_openwin(); break;
  304.    case 4: motd_openwin(); break;
  305.    case 5: finished=TRUE; break;
  306.   }
  307.  } else
  308.  if (menu_open==menu_con)
  309.  {
  310.   if (menu_con_last==win_connect)
  311.   {
  312.    connection=block->selection.items[0];
  313.    ui_updatecond();
  314.   }
  315.   if (menu_con_last==win_search)
  316.   {
  317.    search_connection=block->selection.items[0];
  318.    search_updatecond();
  319.   }
  320.  } else
  321.  if (menu_open==menu_com)
  322.  {
  323.   switch(menu_com_last)
  324.   {
  325.    case SEARCHWIN_BRC: search_c_br=block->selection.items[0]; break;
  326.    case SEARCHWIN_LTC: search_c_lt=block->selection.items[0]; break;
  327.    case SEARCHWIN_FRC: search_c_fr=block->selection.items[0]; break;
  328.   }
  329.   search_updatecond();
  330.  }
  331.  if (pointer.buttons==wimp_CLICK_ADJUST)
  332.  {
  333.   error(xwimp_create_menu(menu_open, 0, 0));
  334.  } else
  335.  if (menu_open==menu_com)
  336.  {
  337.  
  338.  }
  339. }
  340.  
  341. void mess_redrawwindow(wimp_block * block)
  342. {
  343.  if (block->redraw.w==win_motd)
  344.  {
  345.   motd_redrawwin(block);
  346.  } else
  347.  if (block->redraw.w==win_searchres)
  348.  {
  349.   search_redrawwin(block);
  350.  }
  351. }
  352.  
  353. void ui_close(void)
  354. {
  355.  int i;
  356.  napster_close();
  357.  napster_end_server();
  358.  error(xmessagetrans_close_file(&mess_controlblock));
  359.  free(sarea);
  360.  free(win_connectb);
  361.  free(win_infob);
  362.  free(win_messb);
  363.  free(win_motdb);
  364.  free(win_searchb);
  365.  free(win_searchresb);
  366.  free(menu_ibar);
  367.  free(menu_con);
  368.  free(menu_com);
  369.  free(mbuffer);
  370.  search_new();
  371.  for(i=0; i<C_DOWNLOADS; i++)
  372.  {
  373.   napster_download_end(i);
  374.   free(win_getb[i]);
  375.  }
  376.  for(i=0; i<C_INCOMING; i++)
  377.  {
  378.   if(incon[i].active!=0)
  379.   {
  380.    xsocket_close(incon[i].socket);
  381.   }
  382.  }
  383. }
  384.  
  385. void ui_openconnectwin(void)
  386. {
  387.  wimp_open open;
  388.  wimp_pointer pointer;
  389.  wimp_icon_state temp;
  390.  int x, y;
  391.  ui_loaddetails();
  392.  temp.w=win_connect;
  393.  temp.i=CONNECTWIN_USERNM;
  394.  error(xwimp_get_icon_state(&temp));
  395.  strcpy(temp.icon.data.indirected_text.text, username);
  396.  temp.i=CONNECTWIN_PASSWD;
  397.  error(xwimp_get_icon_state(&temp));
  398.  strcpy(temp.icon.data.indirected_text.text, password);
  399.  error(xwimp_get_pointer_info(&pointer));
  400.  x=pointer.pos.x-64;
  401.  y=128;
  402.  open.visible.x0=x;
  403.  open.visible.x1=x+500;
  404.  open.visible.y0=y;
  405.  open.visible.y1=y+600;
  406.  open.w=win_connect;
  407.  open.xscroll=0;
  408.  open.yscroll=0;
  409.  open.next=wimp_TOP;
  410.  error(xwimp_open_window(&open));
  411.  ui_updatecond();
  412. }
  413.  
  414. void ui_iconbaricon(void)
  415. {
  416.  wimp_icon_create ib;
  417.  ib.w=wimp_ICON_BAR_RIGHT;
  418.  ib.icon.extent.x0=0;
  419.  ib.icon.extent.y0=0;
  420.  ib.icon.extent.x1=64;
  421.  ib.icon.extent.y1=64;
  422.  ib.icon.flags=wimp_ICON_SPRITE|wimp_ICON_HCENTRED|wimp_ICON_VCENTRED|
  423.                (wimp_ICON_BUTTON_TYPE*wimp_BUTTON_CLICK);
  424.  strcpy(ib.icon.data.sprite, "!riscster");
  425.  error(xwimp_create_icon(&ib, &icon_iconbar));
  426. }
  427.  
  428. void ui_loadsprites(void)
  429. {
  430.  FILE * file;
  431.  int size=0;
  432.  file = fopen("<Riscster$Dir>.Sprites", "rb");
  433.  while(size++, fgetc(file)!=EOF);
  434.  fclose(file);
  435.  sarea=(osspriteop_area *) malloc(size+16);
  436.  error(xosspriteop_clear_sprites(osspriteop_USER_AREA, sarea));
  437.  error(xosspriteop_load_sprite_file(osspriteop_USER_AREA, sarea,
  438.                                       "<Riscster$Dir>.Sprites"));
  439.  
  440. }
  441.  
  442. void ui_loadwindows(void)
  443. {
  444.  wimp_icon_state temp;
  445.  int i;
  446.  indirected_sp=malloc(ISIZE);
  447.  nextwd=indirected_sp;
  448.  error(xwimp_open_template("<Riscster$Dir>.Templates"));
  449.  win_infob=loadwin("info");
  450.  win_connectb=loadwin("connect");
  451.  win_messb=loadwin("message");
  452.  win_motdb=loadwin("motd");
  453.  win_searchb=loadwin("search");
  454.  win_searchresb=loadwin("searchres");
  455.  for (i=0; i<C_DOWNLOADS; i++)
  456.  {
  457.   win_getb[i]=loadwin("get");
  458.   error(xwimp_create_window(win_getb[i], (wimp_w *) &downloads[i].whandle));
  459.  }
  460.  error(xwimp_close_template());
  461.  win_infob->sprite_area=sarea;
  462.  error(xwimp_create_window(win_infob, &win_info));
  463.  error(xwimp_create_window(win_connectb, &win_connect));
  464.  error(xwimp_create_window(win_messb, &win_mess));
  465.  error(xwimp_create_window(win_motdb, &win_motd));
  466.  error(xwimp_create_window(win_searchb, &win_search));
  467.  error(xwimp_create_window(win_searchresb, &win_searchres));
  468.  temp.w=win_info;
  469.  temp.i=INFOWIN_PURPOSE;
  470.  error(xwimp_get_icon_state(&temp));
  471.  strcpy(temp.icon.data.indirected_text.text, PURPOSE);
  472.  temp.w=win_info;
  473.  temp.i=INFOWIN_AUTHOR;
  474.  error(xwimp_get_icon_state(&temp));
  475.  strcpy(temp.icon.data.indirected_text.text, AUTHOR);
  476.  temp.w=win_info;
  477.  temp.i=INFOWIN_VERSION;
  478.  error(xwimp_get_icon_state(&temp));
  479.  strcpy(temp.icon.data.indirected_text.text, VERSION);
  480. }
  481.  
  482. wimp_window * loadwin(char * name)
  483. {
  484.  wimp_window * win;
  485.  int used, dused;
  486.  error(xwimp_load_template(0, nextwd, indirected_sp+(ISIZE), 0,
  487.                            name, 0, &used, &dused, NULL));
  488.  win = (wimp_window *) malloc(used);
  489.  error(xwimp_load_template(win, nextwd, indirected_sp+(ISIZE), 0,
  490.                            name, 0, NULL, &dused, NULL));
  491.  nextwd=(char *) dused;
  492.  return(win);
  493. }
  494.  
  495. void ui_loadmessages(void)
  496. {
  497.  FILE * file;
  498.  int size=0;
  499.  file = fopen("<Riscster$Dir>.Messages", "rb");
  500.  while(size++, fgetc(file)!=EOF);
  501.  mbuffer = malloc(size+16);
  502.  error(xmessagetrans_open_file(&mess_controlblock, "<Riscster$Dir>.Messages",
  503.                                mbuffer));
  504. }
  505.  
  506. void ui_setupmenus(void)
  507. {
  508.  wimp_menu_entry * ent;
  509.  char buffer[20];
  510.  char str[20];
  511.  char * out;
  512.  size_t size;
  513.  int  i;
  514.  size = sizeof(wimp_menu)+(sizeof(wimp_menu_entry)*7);
  515.  menu_ibar=malloc(size);
  516.  error(xmessagetrans_lookup(&mess_controlblock, "IBMENUT", buffer, 20,
  517.                             NULL, NULL, NULL, NULL, &out, NULL));
  518.  strcpy(menu_ibar->title_data.text, out);
  519.  standardmen(menu_ibar);
  520.  ent=(wimp_menu_entry *) &menu_ibar->entries;
  521.  memcpy(ent++,
  522.         makeentry("IBMENU1",0,(wimp_menu *)win_info,0),
  523.                                            sizeof(wimp_menu_entry));
  524.  memcpy(ent++,
  525.         makeentry("IBMENU2",0,NULL,0), sizeof(wimp_menu_entry));
  526.  memcpy(ent++,
  527.         makeentry("IBMENU3",0,NULL,wimp_ICON_SHADED), sizeof(wimp_menu_entry));
  528.  memcpy(ent++,
  529.         makeentry("IBMENU4",0,NULL,wimp_ICON_SHADED), sizeof(wimp_menu_entry));
  530.  memcpy(ent++,
  531.         makeentry("IBMENU5",0,NULL,0), sizeof(wimp_menu_entry));
  532.  memcpy(ent ++,
  533.         makeentry("IBMENU6",wimp_MENU_LAST, NULL,0), sizeof(wimp_menu_entry));
  534.  
  535.  size = sizeof(wimp_menu)+(sizeof(wimp_menu_entry)*12);
  536.  menu_con=malloc(size);
  537.  error(xmessagetrans_lookup(&mess_controlblock, "CONT", buffer, 20,
  538.                             NULL, NULL, NULL, NULL, &out, NULL));
  539.  strcpy(menu_con->title_data.text, out);
  540.  standardmen(menu_con);
  541.  ent=(wimp_menu_entry *) &menu_con->entries;
  542.  for (i=0; i<10; i++)
  543.  {
  544.   sprintf(str, "CON%d", i);
  545.   memcpy(ent++,
  546.          makeentry(str, 0, NULL, 0), sizeof(wimp_menu_entry));
  547.  
  548.  }
  549.  memcpy(ent++,
  550.          makeentry("CON10", wimp_MENU_LAST, NULL, 0), sizeof(wimp_menu_entry));
  551.  
  552.  size = sizeof(wimp_menu)+(sizeof(wimp_menu_entry)*5);
  553.  menu_com=malloc(size);
  554.  error(xmessagetrans_lookup(&mess_controlblock, "COMT", buffer, 20,
  555.                             NULL, NULL, NULL, NULL, &out, NULL));
  556.  strcpy(menu_com->title_data.text, out);
  557.  standardmen(menu_com);
  558.  ent=(wimp_menu_entry *) &menu_com->entries;
  559.  for (i=0; i<3; i++)
  560.  {
  561.   sprintf(str, "COM%d", i);
  562.   memcpy(ent++,
  563.          makeentry(str, 0, NULL, 0), sizeof(wimp_menu_entry));
  564.  
  565.  }
  566.  memcpy(ent++,
  567.          makeentry("COM3", wimp_MENU_LAST, NULL, 0), sizeof(wimp_menu_entry));
  568. }
  569.  
  570. wimp_menu_entry * makeentry(char * text, wimp_menu_flags flags, wimp_menu * sub, wimp_icon_flags more)
  571. {
  572.  char buffer[20];
  573.  wimp_menu_entry temp;
  574.  char * out;
  575.  error(xmessagetrans_lookup(&mess_controlblock, text, buffer, 20,
  576.                             NULL, NULL, NULL, NULL, &out, NULL));
  577.  temp.menu_flags=flags;
  578.  temp.sub_menu=sub;
  579.  temp.icon_flags=0x7000021|more;
  580.  strcpy(temp.data.text, out);
  581.  return(&temp);
  582. }
  583.  
  584. void ui_connectok(void)
  585. {
  586.  wimp_icon_state temp;
  587.  int err=0;
  588.  temp.w=win_connect;
  589.  temp.i=CONNECTWIN_USERNM;
  590.  error(xwimp_get_icon_state(&temp));
  591.  strcpy_nl(username, temp.icon.data.indirected_text.text);
  592.  temp.i=CONNECTWIN_PASSWD;
  593.  error(xwimp_get_icon_state(&temp));
  594.  strcpy_nl(password, temp.icon.data.indirected_text.text);
  595.  temp.i=CONNECTWIN_EMAIL;
  596.  error(xwimp_get_icon_state(&temp));
  597.  strcpy_nl(email, temp.icon.data.indirected_text.text);
  598.  temp.i=CONNECTWIN_NEWUSR;
  599.  error(xwimp_get_icon_state(&temp));
  600.  if (temp.icon.flags&wimp_ICON_SELECTED) new_user=1;
  601.  if (strlen(username)<1)
  602.  {
  603.   ui_messalert("ERRUSERN");
  604.   err=1;
  605.  }
  606.  if (strlen(password)<1)
  607.  {
  608.   ui_messalert("ERRPASSW");
  609.   err=1;
  610.  }
  611.  if ((strlen(email)<1)&&(new_user==1))
  612.  {
  613.   ui_messalert("ERREMAIL");
  614.   err=1;
  615.  }
  616.  if (err) return;
  617.  temp.i=CONNECTWIN_REMD;
  618.  error(xwimp_get_icon_state(&temp));
  619.  if (temp.icon.flags&wimp_ICON_SELECTED) ui_storedetails();
  620.  napster_connect();
  621.  error(xwimp_close_window(win_connect));
  622. }
  623.  
  624. void ui_newuserclick(void)
  625. {
  626.  wimp_icon_state newusr;
  627.  newusr.w=win_connect;
  628.  newusr.i=CONNECTWIN_NEWUSR;
  629.  error(xwimp_get_icon_state(&newusr));
  630.  if (newusr.icon.flags&wimp_ICON_SELECTED)
  631.  {
  632.   error(xwimp_set_icon_state(win_connect,
  633.                                 CONNECTWIN_EMAIL, 0, wimp_ICON_SHADED));
  634.  }
  635.  else
  636.  {
  637.   error(xwimp_set_icon_state(win_connect,
  638.                  CONNECTWIN_EMAIL, wimp_ICON_SHADED, wimp_ICON_SHADED));
  639.  }
  640. }
  641.  
  642. void ui_messalert(char * token)
  643. {
  644.  char buffer[100];
  645.  char * out;
  646.  error(xmessagetrans_lookup(&mess_controlblock, token, buffer, 100,
  647.                             NULL, NULL, NULL, NULL, &out, NULL));
  648.  ui_alert(out);
  649. }
  650.  
  651. void ui_alert(char * text)
  652. {
  653.  wimp_open open;
  654.  wimp_icon_state temp;
  655.  int sx, sy, xeig, yeig, swidth, sheight, xwa, ywa;
  656.  error(xos_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_XEIG_FACTOR, &xeig,
  657.                                                                         NULL));
  658.  error(xos_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_YEIG_FACTOR, &yeig,
  659.                                                                         NULL));
  660.  error(xos_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_XWIND_LIMIT, &sx,
  661.                                                                         NULL));
  662.  error(xos_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_YWIND_LIMIT, &sy,
  663.                                                                         NULL));
  664.  swidth=sx<<xeig;
  665.  sheight=sy<<yeig;
  666.  xwa=win_messb->extent.x1-win_messb->extent.x0;
  667.  ywa=win_messb->extent.y1-win_messb->extent.y0;
  668.  open.w=win_mess;
  669.  open.visible.x0=(swidth/2)-(xwa/2);
  670.  open.visible.y0=(sheight/2)-(ywa/2);
  671.  open.visible.x1=xwa+open.visible.x0;
  672.  open.visible.y1=ywa+open.visible.y0;
  673.  open.xscroll=0; open.yscroll=0;
  674.  open.next=wimp_TOP;
  675.  temp.w=win_mess;
  676.  temp.i=MESSAGEWIN_MESSAGE;
  677.  error(xwimp_get_icon_state(&temp));
  678.  strcpy(temp.icon.data.indirected_text.text, text);
  679.  error(xwimp_set_icon_state(win_mess, MESSAGEWIN_MESSAGE, 0,0));
  680.  error(xwimp_open_window(&open));
  681.  message_expire=os_read_monotonic_time()+MESSAGE_DELAY;
  682. }
  683.  
  684. void standardmen(wimp_menu * menu)
  685. {
  686.  menu->title_fg=7;
  687.  menu->title_bg=2;
  688.  menu->work_fg=7;
  689.  menu->work_bg=0;
  690.  menu->height=44;
  691.  menu->gap=0;
  692. }
  693.  
  694.  
  695. int error(os_error * err)
  696. {
  697.  if (err!=NULL)
  698.  {
  699.   wimp_report_error(err, wimp_ERROR_BOX_OK_ICON|wimp_ERROR_BOX_CATEGORY_ERROR,
  700.                     title);
  701.   return(1);
  702.  }
  703.  return(0);
  704. }
  705.  
  706. void connectedchange(int new)
  707. {
  708.  wimp_menu_entry * ent;
  709.  connected=(connect_level) new;
  710.  ent = (wimp_menu_entry *) &menu_ibar->entries;
  711.  switch(connected)
  712.  {
  713.   case notc:
  714.   (ent+1)->icon_flags=0x7000021;
  715.   (ent+2)->icon_flags=0x7000021|wimp_ICON_SHADED;
  716.   (ent+3)->icon_flags=0x7000021|wimp_ICON_SHADED;
  717.   (ent+4)->icon_flags=0x7000021;
  718.   break;
  719.   case tc_redir:
  720.   case get_redir:
  721.   case tc_server:
  722.   case try_login:
  723.   (ent+1)->icon_flags=0x7000021|wimp_ICON_SHADED;
  724.   (ent+2)->icon_flags=0x7000021;
  725.   (ent+3)->icon_flags=0x7000021|wimp_ICON_SHADED;
  726.   (ent+4)->icon_flags=0x7000021;
  727.   break;
  728.   case loggedin:
  729.   (ent+1)->icon_flags=0x7000021|wimp_ICON_SHADED;
  730.   (ent+2)->icon_flags=0x7000021;
  731.   (ent+3)->icon_flags=0x7000021;
  732.   (ent+4)->icon_flags=0x7000021;
  733.   break;
  734.  }
  735.  if (connected!=loggedin)
  736.  {
  737.   error(xwimp_close_window(win_searchres));
  738.   error(xwimp_close_window(win_search));
  739.  }
  740. }
  741.  
  742.  
  743. void ui_openconmenu(void)
  744. {
  745.  int x, y;
  746.  wimp_icon_state conicon;
  747.  wimp_window_state wind;
  748.  conicon.w=win_connect;
  749.  conicon.i=CONNECTWIN_CONB;
  750.  error(xwimp_get_icon_state(&conicon));
  751.  wind.w=win_connect;
  752.  error(xwimp_get_window_state(&wind));
  753.  x=wind.visible.x0+conicon.icon.extent.x1;
  754.  y=wind.visible.y1+conicon.icon.extent.y1;
  755.  error(xwimp_create_menu(menu_con, x, y));
  756.  menu_open=menu_con;
  757.  menu_con_last=win_connect;
  758. }
  759.  
  760. void ui_opencon2menu(void)
  761. {
  762.  int x, y;
  763.  wimp_icon_state conicon;
  764.  wimp_window_state wind;
  765.  conicon.w=win_search;
  766.  conicon.i=SEARCHWIN_LTM;
  767.  error(xwimp_get_icon_state(&conicon));
  768.  wind.w=win_search;
  769.  error(xwimp_get_window_state(&wind));
  770.  x=wind.visible.x0+conicon.icon.extent.x1;
  771.  y=wind.visible.y1+conicon.icon.extent.y1;
  772.  error(xwimp_create_menu(menu_con, x, y));
  773.  menu_open=menu_con;
  774.  menu_con_last=win_search;
  775. }
  776.  
  777. void ui_opencommenu(wimp_i icon)
  778. {
  779.  int x, y;
  780.  wimp_icon_state comicon;
  781.  wimp_window_state wind;
  782.  comicon.w=win_search;
  783.  comicon.i=icon;
  784.  error(xwimp_get_icon_state(&comicon));
  785.  wind.w=win_search;
  786.  error(xwimp_get_window_state(&wind));
  787.  x=wind.visible.x0+comicon.icon.extent.x1;
  788.  y=wind.visible.y1+comicon.icon.extent.y1;
  789.  error(xwimp_create_menu(menu_com, x, y));
  790.  menu_open=menu_com;
  791.  menu_com_last=(int) icon;
  792. }
  793.  
  794. void ui_updatecond()
  795. {
  796.  wimp_icon_state temp;
  797.  char buffer[100];
  798.  char * out;
  799.  char token[20];
  800.  sprintf(token, "CON%d", connection);
  801.  error(xmessagetrans_lookup(&mess_controlblock, token, buffer, 100,
  802.                             NULL, NULL, NULL, NULL, &out, NULL));
  803.  temp.w=win_connect;
  804.  temp.i=CONNECTWIN_COND;
  805.  error(xwimp_get_icon_state(&temp));
  806.  strcpy(temp.icon.data.indirected_text.text, out);
  807.  error(xwimp_set_icon_state(win_connect, CONNECTWIN_COND, 0,0));
  808. }
  809.  
  810. void motd_openwin(void)
  811. {
  812.  wimp_open open;
  813.  int sx, sy, xeig, yeig, swidth, sheight, xwa, ywa;
  814.  error(xos_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_XEIG_FACTOR, &xeig,
  815.                                                                         NULL));
  816.  error(xos_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_YEIG_FACTOR, &yeig,
  817.                                                                         NULL));
  818.  error(xos_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_XWIND_LIMIT, &sx,
  819.                                                                         NULL));
  820.  error(xos_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_YWIND_LIMIT, &sy,
  821.                                                                         NULL));
  822.  swidth=sx<<xeig;
  823.  sheight=sy<<yeig;
  824.  xwa=win_motdb->extent.x1-win_motdb->extent.x0;
  825.  ywa=win_motdb->extent.y1-win_motdb->extent.y0;
  826.  open.w=win_motd;
  827.  open.visible.x0=(swidth/2)-(xwa/2);
  828.  open.visible.y0=(sheight/2)-(ywa/2);
  829.  open.visible.x1=xwa+open.visible.x0;
  830.  open.visible.y1=ywa+open.visible.y0;
  831.  open.xscroll=0; open.yscroll=0;
  832.  open.next=wimp_TOP;
  833.  error(xwimp_open_window(&open));
  834. }
  835.  
  836. void motd_redrawwin(wimp_block * block)
  837. {
  838.  wimp_draw area;
  839.  wimp_window_state wind;
  840.  int more=0;
  841.  int xorigin, yorigin;
  842.  wind.w=block->redraw.w;
  843.  error(xwimp_get_window_state(&wind));
  844.  xorigin=wind.visible.x0-wind.xscroll;
  845.  yorigin=wind.visible.y1-wind.yscroll;
  846.  area = block->redraw;
  847.  error(xwimp_redraw_window(&area, &more));
  848.  if (more) motd_drawblock(&area, more, xorigin, yorigin);
  849. }
  850.  
  851. void motd_drawblock(wimp_draw * area, int more, int xorigin, int yorigin)
  852. {
  853.   int startline, endline, line;
  854.   startline=((area->clip.y1-yorigin)/-50);
  855.   endline=((area->clip.y0-yorigin)/-50)+1;
  856.   if (startline>motd_line) startline=motd_line;
  857.   if (startline<0) startline=0;
  858.   if (endline>motd_line) endline=motd_line;
  859.   if (endline<0) endline=0;
  860.   for (line=startline; line<endline; line++)
  861.   {
  862.    if (motd[line]!=NULL)
  863.    {
  864.     error(xwimptextop_set_colour(os_COLOUR_BLACK, os_COLOUR_WHITE));
  865.     error(xwimptextop_paint(wimptextop_GIVEN_BASELINE, motd[line],
  866.                                 xorigin+20, yorigin-((line+1)*50)));
  867.    }
  868.   }
  869.   error(xwimp_get_rectangle(area, &more));
  870.   if (more) motd_drawblock(area, more, xorigin, yorigin);
  871. }
  872.  
  873. void motd_addline(char * text)
  874. {
  875.  int xorigin, yorigin, more;
  876.  os_box box;
  877.  wimp_window_state wind;
  878.  wimp_draw red;
  879.  wind.w=win_motd;
  880.  error(xwimp_get_window_state(&wind));
  881.  xorigin=wind.visible.x0-wind.xscroll;
  882.  yorigin=wind.visible.y1-wind.yscroll;
  883.  if (motd_line>=100) motd_reset();
  884.  motd[motd_line] = malloc((strlen(text)+1)*sizeof(char));
  885.  strcpy(motd[motd_line], text);
  886.  motd_line++;
  887.  if (wind.visible.y1-wind.visible.y0<(motd_line+2)*50)
  888.  {
  889.   box.x0=win_motdb->extent.x0;
  890.   box.x1=win_motdb->extent.x1;
  891.   box.y1=0;
  892.   box.y0=-((motd_line+2)*50);
  893.   error(xwimp_set_extent(win_motd, &box));
  894.  }
  895.  red.w=win_motd;
  896.  red.box.x0=win_motdb->extent.x0;
  897.  red.box.x1=win_motdb->extent.x1;
  898.  red.box.y0=-((motd_line+1)*50);
  899.  red.box.y1=-((motd_line-1)*50);
  900.  error(xwimp_update_window(&red, &more));
  901.  if (more) motd_drawblock(&red, more, xorigin, yorigin);
  902. }
  903.  
  904. void motd_reset(void)
  905. {
  906.  int i;
  907.  motd_line=0;
  908.  for (i=0; i<100; i++)
  909.  {
  910.   if (motd[i]!=NULL) free(motd[i]);
  911.   motd[i]=NULL;
  912.  }
  913. }
  914.  
  915. void motd_init(void)
  916. {
  917.  int i;
  918.  for (i=0; i<100; i++)
  919.  {
  920.   motd[i]=NULL;
  921.  }
  922. }
  923.  
  924. void search_openwin(void)
  925. {
  926.  wimp_open open, open2;
  927.  int sx, sy, xeig, yeig, swidth, sheight, xwa, ywa;
  928.  error(xos_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_XEIG_FACTOR, &xeig,
  929.                                                                         NULL));
  930.  error(xos_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_YEIG_FACTOR, &yeig,
  931.                                                                         NULL));
  932.  error(xos_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_XWIND_LIMIT, &sx,
  933.                                                                         NULL));
  934.  error(xos_read_mode_variable(os_CURRENT_MODE, os_MODEVAR_YWIND_LIMIT, &sy,
  935.                                                                         NULL));
  936.  swidth=sx<<xeig;
  937.  sheight=sy<<yeig;
  938.  xwa=win_searchresb->extent.x1-win_searchresb->extent.x0;
  939.  ywa=win_searchresb->extent.y1-win_searchresb->extent.y0;
  940.  open.w=win_searchres;
  941.  open.visible.x0=(swidth/2)-(xwa/2);
  942.  open.visible.y0=(sheight/2)-(ywa/2);
  943.  open.visible.x1=xwa+open.visible.x0;
  944.  open.visible.y1=ywa+open.visible.y0;
  945.  open.xscroll=0; open.yscroll=0;
  946.  open.next=wimp_TOP;
  947.  error(xwimp_open_window(&open));
  948.  open2.w=win_search;
  949.  open2.visible.x0=open.visible.x0;
  950.  open2.visible.x1=open.visible.x1;
  951.  open2.visible.y0=open.visible.y0;
  952.  open2.visible.y1=open.visible.y1;
  953.  open2.xscroll=0;
  954.  open2.yscroll=0;
  955.  open2.next=open.next;
  956.  error(xwimp_open_window(&open2));
  957.  search_updatecond();
  958.  search_ungrey();
  959. }
  960.  
  961. void search_updatecond()
  962. {
  963.  wimp_icon_state temp;
  964.  char buffer[100];
  965.  char * out;
  966.  char token[20];
  967.  sprintf(token, "CON%d", search_connection);
  968.  error(xmessagetrans_lookup(&mess_controlblock, token, buffer, 100,
  969.                             NULL, NULL, NULL, NULL, &out, NULL));
  970.  temp.w=win_search;
  971.  temp.i=SEARCHWIN_LTI;
  972.  error(xwimp_get_icon_state(&temp));
  973.  strcpy(temp.icon.data.indirected_text.text, out);
  974.  error(xwimp_set_icon_state(win_search, SEARCHWIN_LTI, 0,0));
  975.  
  976.  temp.w=win_search;
  977.  temp.i=SEARCHWIN_BRD;
  978.  error(xwimp_get_icon_state(&temp));
  979.  temp.icon.data.indirected_text.text[0]=search_c[search_c_br];
  980.  temp.icon.data.indirected_text.text[1]='\0';
  981.  error(xwimp_set_icon_state(win_search, SEARCHWIN_BRD, 0,0));
  982.  
  983.  temp.w=win_search;
  984.  temp.i=SEARCHWIN_LTD;
  985.  error(xwimp_get_icon_state(&temp));
  986.  temp.icon.data.indirected_text.text[0]=search_c[search_c_lt];
  987.  temp.icon.data.indirected_text.text[1]='\0';
  988.  error(xwimp_set_icon_state(win_search, SEARCHWIN_LTD, 0,0));
  989.  
  990.  temp.w=win_search;
  991.  temp.i=SEARCHWIN_FRD;
  992.  error(xwimp_get_icon_state(&temp));
  993.  temp.icon.data.indirected_text.text[0]=search_c[search_c_fr];
  994.  temp.icon.data.indirected_text.text[1]='\0';
  995.  error(xwimp_set_icon_state(win_search, SEARCHWIN_FRD, 0,0));
  996.  
  997. }
  998.  
  999. /*void search_ok()
  1000. {
  1001.  char artist[50], title[50], bitrate[5], maxres[5], freq[10];
  1002.  char out[500]; char add[50];
  1003.  search_result * tb;
  1004.  char * comp[4];
  1005.  char atleast[]="AT LEAST";
  1006.  char atbest[]="AT BEST";
  1007.  char equalto[]="EQUAL TO";
  1008.  search_result * item;
  1009.  wimp_icon_state temp;
  1010.  comp[1]=atleast; comp[3]=atbest; comp[2]=equalto;
  1011.  temp.w=win_search;
  1012.  temp.i=SEARCHWIN_ARTIST;
  1013.  error(xwimp_get_icon_state(&temp));
  1014.  strcpy_nl(artist, temp.icon.data.indirected_text.text);
  1015.  temp.i=SEARCHWIN_TRACK;
  1016.  error(xwimp_get_icon_state(&temp));
  1017.  strcpy_nl(title, temp.icon.data.indirected_text.text);
  1018.  temp.i=SEARCHWIN_MAXRES;
  1019.  error(xwimp_get_icon_state(&temp));
  1020.  strcpy_nl(maxres, temp.icon.data.indirected_text.text);
  1021.  temp.i=SEARCHWIN_BRI;
  1022.  error(xwimp_get_icon_state(&temp));
  1023.  strcpy_nl(bitrate, temp.icon.data.indirected_text.text);
  1024.  temp.i=SEARCHWIN_FRI;
  1025.  error(xwimp_get_icon_state(&temp));
  1026.  strcpy_nl(freq, temp.icon.data.indirected_text.text);
  1027.  sprintf(out,
  1028.  "FILENAME CONTAINS \"%s\" MAX_RESULTS %s FILENAME CONTAINS \"%s\" ",
  1029.  artist, maxres, title);
  1030.  if (search_c_br)
  1031.  {
  1032.   sprintf(add, "BITRATE \"%s\" \"%s\" ", comp[search_c_br], bitrate);
  1033.   strcat(out, add);
  1034.  }
  1035.  if (search_c_fr)
  1036.  {
  1037.   sprintf(add, "FREQ \"%s\" \"%s\" ", comp[search_c_fr], freq);
  1038.   strcat(out, add);
  1039.  }
  1040.  if (search_c_lt)
  1041.  {
  1042.   sprintf(add, "LINESPEED \"%s\" %d ", comp[search_c_lt], search_connection);
  1043.   strcat(out, add);
  1044.  }
  1045.  if (!strcmp(maxres, "")) strcpy(maxres, "50");
  1046.  search_new();
  1047.  napster_send(out, 200, strlen(out));
  1048.  error(xwimp_set_icon_state(win_search, SEARCHWIN_OK,
  1049.                    wimp_ICON_SHADED, wimp_ICON_SHADED));
  1050. }*/
  1051.  
  1052. void search_ok()
  1053. {
  1054.  char artist[50], title[50], bitrate[5], maxres[5], freq[10];
  1055.  char out[500]=""; char add[50]="";
  1056.  int mr;
  1057.  search_result * tb;
  1058.  char * comp[4];
  1059.  char atleast[]="AT LEAST";
  1060.  char atbest[]="AT BEST";
  1061.  char equalto[]="EQUAL TO";
  1062.  wimp_icon_state temp;
  1063.  comp[1]=atleast; comp[3]=atbest; comp[2]=equalto;
  1064.  temp.w=win_search;
  1065.  temp.i=SEARCHWIN_ARTIST;
  1066.  error(xwimp_get_icon_state(&temp));
  1067.  strcpy_nl(artist, temp.icon.data.indirected_text.text);
  1068.  temp.i=SEARCHWIN_TRACK;
  1069.  error(xwimp_get_icon_state(&temp));
  1070.  strcpy_nl(title, temp.icon.data.indirected_text.text);
  1071.  temp.i=SEARCHWIN_MAXRES;
  1072.  error(xwimp_get_icon_state(&temp));
  1073.  strcpy_nl(maxres, temp.icon.data.indirected_text.text);
  1074.  temp.i=SEARCHWIN_BRI;
  1075.  error(xwimp_get_icon_state(&temp));
  1076.  strcpy_nl(bitrate, temp.icon.data.indirected_text.text);
  1077.  temp.i=SEARCHWIN_FRI;
  1078.  error(xwimp_get_icon_state(&temp));
  1079.  strcpy_nl(freq, temp.icon.data.indirected_text.text);
  1080.  
  1081.  if((!strlen(artist))&&(!strlen(title)))
  1082.  {
  1083.   ui_messalert("ERRNTNA");
  1084.   return;
  1085.  }
  1086.  if(strlen(artist))
  1087.  {
  1088.   sprintf(add, "FILENAME CONTAINS \"%s\" ", artist);
  1089.   strcat(out, add);
  1090.  }
  1091.  if(strlen(maxres))
  1092.  {
  1093.   sprintf(add, "MAX RESULTS %s ", maxres);
  1094.   strcat(out, add);
  1095.  }
  1096.  if(strlen(title))
  1097.  {
  1098.   sprintf(add, "FILENAME CONTAINS \"%s\" ", title);
  1099.   strcat(out, add);
  1100.  }
  1101.  if (search_c_br)
  1102.  {
  1103.   sprintf(add, "BITRATE \"%s\" \"%s\" ", comp[search_c_br], bitrate);
  1104.   strcat(out, add);
  1105.  }
  1106.  if (search_c_fr)
  1107.  {
  1108.   sprintf(add, "FREQ \"%s\" \"%s\" ", comp[search_c_fr], freq);
  1109.   strcat(out, add);
  1110.  }
  1111.  if (search_c_lt)
  1112.  {
  1113.   sprintf(add, "LINESPEED \"%s\" %d ", comp[search_c_lt], search_connection);
  1114.   strcat(out, add);
  1115.  }
  1116.  search_new();
  1117.  napster_send(out, 200, strlen(out));
  1118.  error(xwimp_set_icon_state(win_search, SEARCHWIN_OK,
  1119.                    wimp_ICON_SHADED, wimp_ICON_SHADED));
  1120. }
  1121.  
  1122. void search_new()
  1123. {
  1124.  search_result * i, * oi;
  1125.  i=search_resblock;
  1126.  while (i!=NULL)
  1127.  {
  1128.   oi=i;
  1129.   i=i->next;
  1130.   free(oi);
  1131.  }
  1132.  search_resblock=NULL;
  1133.  search_numres=0;
  1134. }
  1135.  
  1136. void search_ungrey()
  1137. {
  1138.  error(xwimp_set_icon_state(win_search, SEARCHWIN_OK,
  1139.         0, wimp_ICON_SHADED));
  1140. }
  1141.  
  1142. void search_update(search_result * result)
  1143. {
  1144.  search_result * i;
  1145.  int no=0, xorigin, yorigin;
  1146.  wimp_draw red;
  1147.  wimp_window_state wind;
  1148.  os_box box;
  1149.  int more=0;
  1150.  
  1151.  i=search_resblock;
  1152.  if(i==NULL)
  1153.  {
  1154.   search_resblock=result;
  1155.  }
  1156.  else
  1157.  {
  1158.   while (i->next!=NULL)
  1159.   {
  1160.    i=i->next;
  1161.    no++;
  1162.   }
  1163.   i->next=result;
  1164.  }
  1165.  search_numres++;
  1166.  wind.w=win_searchres;
  1167.  error(xwimp_get_window_state(&wind));
  1168.  xorigin=wind.visible.x0-wind.xscroll;
  1169.  yorigin=wind.visible.y1-wind.yscroll-250;
  1170.  box.y1=win_searchresb->extent.y1;
  1171.  box.x0=win_searchresb->extent.x0;
  1172.  box.x1=win_searchresb->extent.x1;
  1173.  box.y0=-50*(no+1)-250;
  1174.  error(xwimp_set_extent(win_searchres, &box));
  1175.  red.w=win_searchres;
  1176.  red.box.x0=win_searchresb->extent.x0;
  1177.  red.box.x1=win_searchresb->extent.x1;
  1178.  red.box.y0=-50*(no+1)-250;
  1179.  red.box.y1=-50*(no)-250;
  1180.  error(xwimp_update_window(&red, &more));
  1181.  if (more) search_drawblock(&red, more, xorigin, yorigin); 
  1182. }
  1183.  
  1184. void search_finish()
  1185. {
  1186.  search_result * sr, * i;
  1187.  wimp_draw red;
  1188.  wimp_window_state wind;
  1189.  os_box box;
  1190.  int more=0;
  1191.  int xorigin, yorigin;
  1192.  wind.w=win_searchres;
  1193.  error(xwimp_get_window_state(&wind));
  1194.  xorigin=wind.visible.x0-wind.xscroll;
  1195.  yorigin=wind.visible.y1-wind.yscroll-250;
  1196.  
  1197.  /*search_numres=0;
  1198.  i=search_resblock;
  1199.  while (i!=NULL)
  1200.  {
  1201.   i=i->next;
  1202.   search_numres++;
  1203.  }*/
  1204.  
  1205.  box.y1=win_searchresb->extent.y1;
  1206.  box.x0=win_searchresb->extent.x0;
  1207.  box.x1=win_searchresb->extent.x1;
  1208.  box.y0=-50*(search_numres+1)-250;
  1209.  error(xwimp_set_extent(win_searchres, &box));
  1210.  red.w=win_searchres;
  1211.  red.box.x0=win_searchresb->extent.x0;
  1212.  red.box.x1=win_searchresb->extent.x1;
  1213.  red.box.y0=-50*(search_numres+1)-250;
  1214.  red.box.y1=win_searchresb->extent.y1;
  1215.  error(xwimp_update_window(&red, &more));
  1216.  if (more) search_drawblock(&red, more, xorigin, yorigin);
  1217. }
  1218.  
  1219. void search_drawblock(wimp_draw * area, int more, int xorigin, int yorigin)
  1220. {
  1221.  int startline, endline, line;
  1222.  char numconv[10];
  1223.  char * out;
  1224.  char buffer[100], token[6];
  1225.  search_result * sr;
  1226.  startline=((area->clip.y1-yorigin)/-50);
  1227.  endline=((area->clip.y0-yorigin)/-50)+1;
  1228.  if (startline>search_numres) startline=search_numres;
  1229.  if (startline<0) startline=0;
  1230.  if (endline>search_numres) endline=search_numres;
  1231.  if (endline<0) endline=0;
  1232.  error(xwimp_set_colour(wimp_COLOUR_WHITE));
  1233.  error(xos_plot(4, area->clip.x0, area->clip.y0));
  1234.  error(xos_plot(96+5, area->clip.x1, area->clip.y1));
  1235.  line=0;
  1236.  sr=search_resblock;
  1237.  while((line<startline)&&(sr!=NULL))
  1238.  {
  1239.   sr=sr->next;
  1240.   line++;
  1241.  }
  1242.  
  1243.  /*for (line=startline; line<endline; line++)
  1244.  {*/
  1245.  while((line<endline)&&(sr!=NULL))
  1246.  {
  1247.   error(xwimptextop_set_colour(os_COLOUR_BLACK, os_COLOUR_WHITE));
  1248.   error(xwimptextop_paint(wimptextop_GIVEN_BASELINE,
  1249.                                 search_trim(sr->filename, 20),
  1250.                                 xorigin+10, yorigin-((line+1)*50)));
  1251.   error(xwimptextop_paint(wimptextop_GIVEN_BASELINE,
  1252.                                 search_trim(sr->user, 10),
  1253.                                 xorigin+10+324, yorigin-((line+1)*50)));          error(xwimptextop_paint(wimptextop_GIVEN_BASELINE,
  1254.                                 search_trim(sr->filename, 20),
  1255.                                 xorigin+10, yorigin-((line+1)*50)));
  1256.   sprintf(numconv, "%.2fMb\n",(double)sr->size/(1024*1024));
  1257.   error(xwimptextop_paint(wimptextop_GIVEN_BASELINE,
  1258.                                 numconv,
  1259.                                 xorigin+10+324+164, yorigin-((line+1)*50)));
  1260.   sprintf(numconv, "%d\n", sr->bitrate);
  1261.   error(xwimptextop_paint(wimptextop_GIVEN_BASELINE,
  1262.                                 numconv,
  1263.                           xorigin+10+324+164+116, yorigin-((line+1)*50)));
  1264.   sprintf(numconv, "%d\n", sr->frequency);
  1265.   error(xwimptextop_paint(wimptextop_GIVEN_BASELINE,
  1266.                                 numconv,
  1267.                         xorigin+10+324+164+116+120, yorigin-((line+1)*50)));
  1268.   sprintf(token, "CON%d", sr->speed);
  1269.   error(xmessagetrans_lookup(&mess_controlblock, token, buffer, 100,
  1270.                             NULL, NULL, NULL, NULL, &out, NULL));
  1271.   error(xwimptextop_paint(wimptextop_GIVEN_BASELINE,
  1272.                                 out,
  1273.                     xorigin+10+324+164+116+120+116, yorigin-((line+1)*50)));
  1274.   sprintf(numconv, "%d:%.2d", sr->number/60, sr->number%60);
  1275.   error(xwimptextop_paint(wimptextop_GIVEN_BASELINE,
  1276.                                 numconv,
  1277.                  xorigin+10+324+164+116+120+116+156, yorigin-((line+1)*50)));
  1278.  line++;
  1279.  sr=sr->next;
  1280.  }
  1281.  error(xwimp_get_rectangle(area, &more));
  1282.  if (more) search_drawblock(area, more, xorigin, yorigin);
  1283. }
  1284.  
  1285. void search_redrawwin(wimp_block * block)
  1286. {
  1287.  wimp_draw area;
  1288.  wimp_window_state wind;
  1289.  int xorigin, yorigin;
  1290.  int more=0;
  1291.  wind.w=block->redraw.w;
  1292.  error(xwimp_get_window_state(&wind));
  1293.  xorigin=wind.visible.x0-wind.xscroll;
  1294.  yorigin=wind.visible.y1-wind.yscroll-250;
  1295.  area = block->redraw;
  1296.  error(xwimp_redraw_window(&area, &more));
  1297.  if (more) search_drawblock(&area, more, xorigin, yorigin);
  1298. }
  1299.  
  1300. char * search_trim(char * in, int len)
  1301. {
  1302.  if (strlen(in)>len)
  1303.  {
  1304.   return(in+(strlen(in)-len));
  1305.  }
  1306.  return (in);
  1307. }
  1308.  
  1309. void search_click(wimp_block * block)
  1310. {
  1311.  wimp_window_state wind;
  1312.  wimp_open getopen;
  1313.  wimp_icon_state temp;
  1314.  int xorigin, yorigin, resno;
  1315.  int search_no, dl_slot=0;
  1316.  search_result * sr;
  1317.  while((dl_slot<=C_DOWNLOADS)&&(downloads[dl_slot].active!=freesl)) dl_slot++;
  1318.  if (dl_slot>=C_DOWNLOADS)
  1319.  {
  1320.   ui_messalert("ERRMAXD");
  1321.   return;
  1322.  }
  1323.  downloads[dl_slot].size=0;
  1324.  downloads[dl_slot].totalsize=1;
  1325.  search_updatebar(dl_slot);
  1326.  wind.w=win_searchres;
  1327.  error(xwimp_get_window_state(&wind));
  1328.  xorigin=wind.visible.x0-wind.xscroll;
  1329.  yorigin=wind.visible.y1-wind.yscroll-250;
  1330.  search_no=((block->pointer.pos.y-yorigin)/-50);
  1331.  if ((search_no<0)||(search_no>=search_numres)) return;
  1332.  
  1333.  sr=search_resblock;
  1334.  resno=0;
  1335.  while((resno<search_no)&&(sr!=NULL))
  1336.  {
  1337.   sr=sr->next;
  1338.   resno++;
  1339.  }
  1340.  
  1341.  getopen.w=(wimp_w) downloads[dl_slot].whandle;
  1342.  getopen.visible.y1=block->pointer.pos.y+96;
  1343.  getopen.visible.y0=getopen.visible.y1+win_getb[0]->extent.y0;
  1344.  getopen.visible.x0=block->pointer.pos.x;
  1345.  getopen.visible.x1=block->pointer.pos.x+win_getb[0]->extent.x1;
  1346.  getopen.xscroll=0; getopen.yscroll=0;
  1347.  getopen.next=wimp_TOP;
  1348.  error(xwimp_open_window(&getopen));
  1349.  temp.w=(wimp_w) downloads[dl_slot].whandle;
  1350.  temp.i=GETWIN_FILE;
  1351.  error(xwimp_get_icon_state(&temp));
  1352.  strcpy(temp.icon.data.indirected_text.text,
  1353.                     search_trim(sr->filename, 40));
  1354.  error(xwimp_set_icon_state((wimp_w)downloads[dl_slot].whandle,
  1355.                                                          GETWIN_FILE, 0,0));
  1356.  temp.w=(wimp_w) downloads[dl_slot].whandle;
  1357.  temp.i=GETWIN_USER;
  1358.  error(xwimp_get_icon_state(&temp));
  1359.  strcpy(temp.icon.data.indirected_text.text,
  1360.                     search_trim(sr->user, 20));
  1361.  error(xwimp_set_icon_state((wimp_w)downloads[dl_slot].whandle,
  1362.                                                           GETWIN_USER, 0,0));
  1363.  downloads[dl_slot].searchres=sr;
  1364.  strcpy(downloads[dl_slot].filename, sr->filename);
  1365.  strcpy(downloads[dl_slot].user, sr->user);
  1366.  downloads[dl_slot].active=window;
  1367. }
  1368.  
  1369. void search_updatebar(int tno)
  1370. {
  1371.  float percent;
  1372.  char pctxt[6];
  1373.  wimp_icon_state temp;
  1374.  percent=((float)100*(float)
  1375.               ((float)downloads[tno].size/(float)downloads[tno].totalsize));
  1376.  sprintf(pctxt, "%.1f", percent);
  1377.  temp.w=(wimp_w) downloads[tno].whandle;
  1378.  temp.i=GETWIN_PROGN;
  1379.  error(xwimp_get_icon_state(&temp));
  1380.  strcpy(temp.icon.data.indirected_text.text, pctxt);
  1381.  error(xwimp_set_icon_state((wimp_w) downloads[tno].whandle,
  1382.                                                   GETWIN_PROGN, 0,0));
  1383.  temp.i=GETWIN_BAR;
  1384.  error(xwimp_get_icon_state(&temp));
  1385.  error(xwimp_resize_icon((wimp_w) downloads[tno].whandle, GETWIN_BAR,
  1386.        temp.icon.extent.x0, temp.icon.extent.y0,
  1387.        temp.icon.extent.x0+(5*(int)percent), temp.icon.extent.y1));
  1388.  error(xwimp_set_icon_state((wimp_w) downloads[tno].whandle,
  1389.                                                   GETWIN_BAR, 0, 0));
  1390. }
  1391.  
  1392. void search_getok(int tno)
  1393. {
  1394.  if (connected==loggedin)
  1395.  {
  1396.   napster_mo_dlrequest(downloads[tno].searchres);
  1397.  }
  1398.  else
  1399.  {
  1400.   ui_messalert("ERRNPNC");
  1401.  }
  1402. }
  1403.  
  1404. void get_init(void)
  1405. {
  1406.  int i;
  1407.  for (i=0; i<C_DOWNLOADS; i++) downloads[i].active=freesl;
  1408.  for (i=0; i<C_INCOMING; i++) incon[i].active=0;
  1409. }
  1410.  
  1411. void strcpy_nl(char * target, char * source)
  1412. {
  1413.  int pos=0;
  1414.  while(source[pos]!=0x0d)
  1415.  {
  1416.   target[pos]=source[pos];
  1417.   pos++;
  1418.  }
  1419.  target[pos]='\0';
  1420. }
  1421.  
  1422. void get_closewin(int tno)
  1423. {
  1424.  error(xwimp_close_window((wimp_w) downloads[tno].whandle));
  1425. }
  1426.  
  1427. void ui_storedetails(void)
  1428. {
  1429.  FILE * cfile;
  1430.  if(error(xosfile_create_dir("<Choices$Dir>.Riscster",0))) return;
  1431.  cfile=fopen("<Choices$Dir>.Riscster.user", "w");
  1432.  if (cfile==NULL) return;
  1433.  fprintf(cfile, "%s %s %d", username, password, connection);
  1434.  fclose(cfile); 
  1435. }
  1436.  
  1437. void ui_loaddetails(void)
  1438. {
  1439.  FILE * cfile;
  1440.  cfile=fopen("<Choices$Dir>.Riscster.user", "r");
  1441.  if (cfile==NULL) return;
  1442.  fscanf(cfile, "%s %s %d", username, password, &connection);
  1443.  fclose(cfile);
  1444. }
  1445.  
  1446.  
  1447.  
  1448.  
  1449.  
  1450.  
  1451.