Changeset 4211f50b


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.
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    rc0a90c2 r4211f50b  
    23672367char *owl_command_aimlogin(int argc, char **argv, char *buff)
    23682368{
    2369   int ret;
    2370  
    23712369  if ((argc<2) || (argc>3)) {
    23722370    owl_function_makemsg("Wrong number of arguments to aimlogin command");
     
    23762374  /* if we get two arguments, ask for the password */
    23772375  if (argc==2) {
    2378     owl_global_set_buffercommand(&g, buff);
     2376    owl_global_set_buffercommand(&g, argv[1]);
     2377    owl_global_set_buffercallback(&g, owl_function_aimlogin);
    23792378    owl_function_start_password("AIM Password: ");
    23802379    return(NULL);
    2381   }
    2382 
    2383   /* clear the buddylist */
    2384   owl_buddylist_clear(owl_global_get_buddylist(&g));
    2385 
    2386   /* try to login */
    2387   ret=owl_aim_login(argv[1], argv[2]);
    2388   if (ret) owl_function_makemsg("Warning: login for %s failed.\n", argv[1]);
     2380  } else {
     2381    owl_function_aimlogin(argv[1], argv[2]);
     2382  }
    23892383
    23902384  /* this is a test */
  • 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}
  • global.c

    r176d3443 r4211f50b  
    250250}
    251251
     252void owl_global_set_buffercallback(owl_global *g, void (*cb)(char*,char*)) {
     253  g->buffercallback = cb;
     254}
     255
     256void (*owl_global_get_buffercallback(owl_global *g))(char*,char*) {
     257  return g->buffercallback;
     258}
     259
    252260/* refresh */
    253261
  • owl.h

    r1152d45 r4211f50b  
    533533  int config_format;
    534534  char *buffercommand;
     535  void (*buffercallback)(char *cmd, char *msg);
    535536  owl_editwin tw;
    536537  owl_viewwin vw;
Note: See TracChangeset for help on using the changeset viewer.