Changeset 4211f50b for functions.c


Ignore:
Timestamp:
Oct 24, 2006, 11:45:16 AM (14 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
216c734
Parents:
908e388
Message:
Refactoring the editwin code to use an explicit callback.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    r1aa2b1a r4211f50b  
    320320
    321321  owl_global_set_buffercommand(&g, line);
     322  owl_global_set_buffercallback(&g, &owl_function_zwrite);
    322323}
    323324
     
    350351
    351352  owl_global_set_buffercommand(&g, line);
     353  owl_global_set_buffercallback(&g, &owl_function_aimwrite);
    352354}
    353355
     
    374376
    375377  owl_global_set_buffercommand(&g, "loopwrite");
     378  owl_global_set_buffercallback(&g, &owl_function_loopwrite);
    376379}
    377380
     
    483486}
    484487
    485 void owl_function_aimwrite(char *to)
     488void owl_function_aimwrite(char *line, char *msg)
    486489{
    487490  int ret;
    488   char *msg, *format_msg;
     491  char *to, *format_msg;
    489492  owl_message *m;
    490493
     494  to = line + 9;
     495
    491496  /* make a formatted copy of the message */
    492   msg=owl_editwin_get_text(owl_global_get_typwin(&g));
    493497  format_msg=owl_strdup(msg);
    494498  owl_text_wordunwrap(format_msg);
     
    558562}
    559563
    560 void owl_function_loopwrite()
     564void owl_function_loopwrite(char *line, char *msg)
    561565{
    562566  owl_message *min, *mout;
     
    565569   * an incoming message */
    566570  min=owl_malloc(sizeof(owl_message));
    567   owl_message_create_loopback(min, owl_editwin_get_text(owl_global_get_typwin(&g)));
     571  owl_message_create_loopback(min, msg);
    568572  owl_message_set_direction_in(min);
    569573  owl_global_messagequeue_addmsg(&g, min);
    570574
    571   mout=owl_function_make_outgoing_loopback(owl_editwin_get_text(owl_global_get_typwin(&g)));
     575  mout=owl_function_make_outgoing_loopback(msg);
    572576  owl_log_message(mout);
    573577  if (owl_global_is_displayoutgoing(&g)) {
     
    928932    owl_function_error("Error subscribing to login messages from file.");
    929933  }
     934}
     935
     936void owl_function_aimlogin(char *user, char *passwd) {
     937  int ret;
     938
     939  /* clear the buddylist */
     940  owl_buddylist_clear(owl_global_get_buddylist(&g));
     941
     942  /* try to login */
     943  ret=owl_aim_login(user, passwd);
     944  if (ret) owl_function_makemsg("Warning: login for %s failed.\n", user);
    930945}
    931946
     
    13091324void owl_function_run_buffercommand()
    13101325{
    1311   char *buff, *ptr;
     1326  char *buff;
     1327  void (*cb)(char*, char*);
    13121328
    13131329  buff=owl_global_get_buffercommand(&g);
    1314   if (!strncmp(buff, "zwrite ", 7)) {
    1315     owl_function_zwrite(buff, owl_editwin_get_text(owl_global_get_typwin(&g)));
    1316   } else if (!strncmp(buff, "zcrypt ", 7)) {
    1317     owl_function_zcrypt(buff, owl_editwin_get_text(owl_global_get_typwin(&g)));
    1318   } else if (!strncmp(buff, "aimwrite ", 9)) {
    1319     owl_function_aimwrite(buff+9);
    1320   } else if (!strncmp(buff, "loopwrite", 9) || !strncmp(buff, "loopwrite ", 10)) {
    1321     owl_function_loopwrite();
    1322   } else if (!strncmp(buff, "aimlogin ", 9)) {
    1323     ptr=owl_sprintf("%s %s", buff, owl_global_get_response(&g));
    1324     owl_function_command(ptr);
    1325     owl_free(ptr);
    1326   } else {
    1327     owl_function_error("Internal error: invalid buffercommand %s", buff);
     1330  cb=owl_global_get_buffercallback(&g);
     1331  if(!cb) {
     1332    owl_function_error("Internal error: No callback for buffercommand %s", buff);
     1333  } else {
     1334    cb(buff, owl_editwin_get_text(owl_global_get_typwin(&g)));
    13281335  }
    13291336}
Note: See TracChangeset for help on using the changeset viewer.