Changeset a38becd


Ignore:
Timestamp:
Aug 8, 2013, 2:38:50 PM (4 years ago)
Author:
Edward Z. Yang <ezyang@mit.edu>
Branches:
master
Children:
120dac7
Parents:
4f7b1f4
git-author:
Jason Gross <jgross@mit.edu> (05/27/11 17:39:59)
git-committer:
Edward Z. Yang <ezyang@mit.edu> (08/08/13 14:38:50)
Message:
Added a perl hook for :away

Note: The sepbar no longer distinguishes between AWAY, A-AWAY, and
Z-AWAY.
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    r3b9ca71 ra38becd  
    479479
    480480  OWLCMD_ARGS("away", owl_command_away, OWL_CTX_INTERACTIVE,
    481               "Set, enable or disable both AIM and zephyr away messages",
     481              "Set, enable or disable all away messages",
    482482              "away [ on | off | toggle ]\n"
    483483              "away <message>",
    484               "Turn on or off the AIM and zephyr away message.  If\n"
     484              "Turn on or off all away messages.  If\n"
    485485              "'message' is specified turn them on with that message,\n"
    486486              "otherwise use the default.\n"
    487               "\n"
    488               "This command really just runs the 'aaway' and 'zaway'\n"
    489               "commands together\n"
    490487              "\n"
    491488              "SEE ALSO: aaway, zaway"),
     
    15311528char *owl_command_away(int argc, const char *const *argv, const char *buff)
    15321529{
    1533   if ((argc==1) ||
    1534       ((argc==2) && !strcmp(argv[1], "on"))) {
     1530  bool away_off;
     1531  const char *message = NULL;
     1532
     1533  if (argc == 1 ||
     1534      (argc == 2 && !strcmp(argv[1], "on"))) {
     1535    away_off = false;
    15351536    owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g));
    15361537    owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
     1538  } else if (argc == 2 && !strcmp(argv[1], "off")) {
     1539    away_off = true;
     1540  } else if (argc == 2 && !strcmp(argv[1], "toggle")) {
     1541    away_off = owl_function_is_away();
     1542  } else {
     1543    away_off = false;
     1544    message = skiptokens(buff, 1);
     1545  }
     1546
     1547  if (away_off) {
     1548    owl_function_aaway_off();
     1549    owl_function_zaway_off();
     1550    owl_perlconfig_perl_call_norv("BarnOwl::Hooks::_away_off", 0, NULL);
     1551    owl_function_makemsg("Away messages off.");
     1552  } else if (message != NULL) {
     1553    owl_global_set_aaway_msg(&g, message);
     1554    owl_global_set_zaway_msg(&g, message);
    15371555    owl_function_aaway_on();
    15381556    owl_function_zaway_on();
     1557    owl_perlconfig_perl_call_norv("BarnOwl::Hooks::_away_on", 1, &message);
     1558    owl_function_makemsg("Away messages set (%s).", message);
     1559  } else {
     1560    owl_function_aaway_on();
     1561    owl_function_zaway_on();
     1562    owl_perlconfig_perl_call_norv("BarnOwl::Hooks::_away_on", 0, NULL);
    15391563    owl_function_makemsg("Away messages set.");
    1540     return NULL;
    1541   }
    1542 
    1543   if (argc==2 && !strcmp(argv[1], "off")) {
    1544     owl_function_aaway_off();
    1545     owl_function_zaway_off();
    1546     return NULL;
    1547   }
    1548 
    1549   if (argc==2 && !strcmp(argv[1], "toggle")) {
    1550     /* if either one is on, turn it off, otherwise toggle both (turn
    1551      *  them both on)
    1552      */
    1553     if (!owl_global_is_zaway(&g) && !owl_global_is_aaway(&g)) {
    1554       owl_function_aaway_toggle();
    1555       owl_function_zaway_toggle();
    1556       owl_function_makemsg("Away messages set.");
    1557     } else {
    1558       if (owl_global_is_zaway(&g)) owl_function_zaway_toggle();
    1559       if (owl_global_is_aaway(&g)) owl_function_aaway_toggle();
    1560       owl_function_makemsg("Away messages off.");
    1561     }
    1562     return NULL;
    1563   }
    1564 
    1565   buff = skiptokens(buff, 1);
    1566   owl_global_set_aaway_msg(&g, buff);
    1567   owl_global_set_zaway_msg(&g, buff);
    1568   owl_function_aaway_on();
    1569   owl_function_zaway_on();
    1570   owl_function_makemsg("Away messages set.");
     1564  }
     1565
    15711566  return NULL;
    15721567}
  • functions.c

    r60e8617 ra38becd  
    993993}
    994994
     995bool owl_function_is_away(void)
     996{
     997  return owl_global_is_zaway(&g) ||
     998         owl_global_is_aaway(&g) ||
     999         owl_perlconfig_perl_call_bool("BarnOwl::Hooks::_get_is_away", 0, NULL);
     1000}
     1001
    9951002void owl_function_quit(void)
    9961003{
  • perl/lib/BarnOwl/Hooks.pm

    rb8a3e00 ra38becd  
    5757from every function registered with this hook will be appended and
    5858displayed in a popup window, with zephyr formatting parsed.
     59
     60=item $awayOn
     61
     62Called, for all protocol handlers, to go away, with the away message,
     63if any.
     64
     65=item $awayOff
     66
     67Called, for all protocol handlers, to come back from away.
     68
     69=item $getIsAway
     70
     71Called to check away status for all protocol handlers.  Protocol
     72handlers should return a true value if any account of the user is away
     73for the given protocol, and a false value otherwise.
    5974
    6075=item $getQuickstart
     
    7590                    $receiveMessage $newMessage
    7691                    $mainLoop $getBuddyList
     92                    $awayOn $awayOff $getIsAway
    7793                    $getQuickstart);
    7894
     
    88104our $getBuddyList = BarnOwl::Hook->new;
    89105our $getQuickstart = BarnOwl::Hook->new;
     106our $awayOn = BarnOwl::Hook->new;
     107our $awayOff = BarnOwl::Hook->new;
     108our $getIsAway = BarnOwl::Hook->new;
    90109
    91110# Internal startup/shutdown routines called by the C code
     
    201220}
    202221
     222sub _away_on {
     223    $awayOn->run(@_);
     224}
     225
     226sub _away_off {
     227    $awayOff->run();
     228}
     229
     230sub _get_is_away {
     231    my @is_away = grep { $_ } $getIsAway->run();
     232    return scalar @is_away;
     233}
     234
    203235sub _new_command {
    204236    my $command = shift;
  • sepbar.c

    r6eb3ed9 ra38becd  
    6767  }
    6868
    69   if (owl_global_is_zaway(&g) || owl_global_is_aaway(&g)) {
     69  if (owl_function_is_away()) {
    7070    getyx(sepwin, y, x);
    7171    wmove(sepwin, y, x+2);
    7272    wattron(sepwin, A_BOLD);
    7373    wattroff(sepwin, A_REVERSE);
    74     if (owl_global_is_zaway(&g) && owl_global_is_aaway(&g)) {
    75       waddstr(sepwin, " AWAY ");
    76     } else if (owl_global_is_zaway(&g)) {
    77       waddstr(sepwin, " Z-AWAY ");
    78     } else if (owl_global_is_aaway(&g)) {
    79       waddstr(sepwin, " A-AWAY ");
    80     }
     74    waddstr(sepwin, " AWAY ");
    8175    wattron(sepwin, A_REVERSE);
    8276    wattroff(sepwin, A_BOLD);
Note: See TracChangeset for help on using the changeset viewer.