[3328] in BarnOwl Developers

home help back first fref pref prev next nref lref last post

[PATCH 3/5] Added a perl hook for :away

daemon@ATHENA.MIT.EDU (Jason Gross)
Sun Jan 13 14:08:43 2013

From: Jason Gross <jgross@MIT.EDU>
To: barnowl-dev@mit.edu
Cc: Jason Gross <jgross@mit.edu>
Date: Sun, 13 Jan 2013 14:07:52 -0500
In-Reply-To: <1358104074-23031-1-git-send-email-jgross@mit.edu>

Note: The sepbar no longer distinguishes between AWAY, A-AWAY, and
Z-AWAY.
---
 commands.c                |   65 ++++++++++++++++++++------------------------
 functions.c               |    7 +++++
 perl/lib/BarnOwl/Hooks.pm |   32 ++++++++++++++++++++++
 sepbar.c                  |   10 +-----
 4 files changed, 71 insertions(+), 43 deletions(-)

diff --git a/commands.c b/commands.c
index 03e8fe6..1eb7258 100644
--- a/commands.c
+++ b/commands.c
@@ -478,16 +478,13 @@ void owl_cmd_add_defaults(owl_cmddict *cd)
 	      "use the default.\n"),
 
   OWLCMD_ARGS("away", owl_command_away, OWL_CTX_INTERACTIVE,
-	      "Set, enable or disable both AIM and zephyr away messages",
+	      "Set, enable or disable all away messages",
 	      "away [ on | off | toggle ]\n"
 	      "away <message>",
-	      "Turn on or off the AIM and zephyr away message.  If\n"
+	      "Turn on or off all away messages.  If\n"
 	      "'message' is specified turn them on with that message,\n"
 	      "otherwise use the default.\n"
 	      "\n"
-	      "This command really just runs the 'aaway' and 'zaway'\n"
-	      "commands together\n"
-	      "\n"
 	      "SEE ALSO: aaway, zaway"),
 
   OWLCMD_ARGS("load-subs", owl_command_loadsubs, OWL_CTX_ANY,
@@ -1530,44 +1527,42 @@ char *owl_command_aaway(int argc, const char *const *argv, const char *buff)
 
 char *owl_command_away(int argc, const char *const *argv, const char *buff)
 {
-  if ((argc==1) ||
-      ((argc==2) && !strcmp(argv[1], "on"))) {
+  bool away_off;
+  const char *message = NULL;
+
+  if (argc == 1 ||
+      (argc == 2 && !strcmp(argv[1], "on"))) {
+    away_off = false;
     owl_global_set_aaway_msg(&g, owl_global_get_aaway_msg_default(&g));
     owl_global_set_zaway_msg(&g, owl_global_get_zaway_msg_default(&g));
-    owl_function_aaway_on();
-    owl_function_zaway_on();
-    owl_function_makemsg("Away messages set.");
-    return NULL;
+  } else if (argc == 2 && !strcmp(argv[1], "off")) {
+    away_off = true;
+  } else if (argc == 2 && !strcmp(argv[1], "toggle")) {
+    away_off = owl_function_is_away();
+  } else {
+    away_off = false;
+    message = skiptokens(buff, 1);
   }
 
-  if (argc==2 && !strcmp(argv[1], "off")) {
+  if (away_off) {
     owl_function_aaway_off();
     owl_function_zaway_off();
-    return NULL;
-  }
-
-  if (argc==2 && !strcmp(argv[1], "toggle")) {
-    /* if either one is on, turn it off, otherwise toggle both (turn
-     *  them both on)
-     */
-    if (!owl_global_is_zaway(&g) && !owl_global_is_aaway(&g)) {
-      owl_function_aaway_toggle();
-      owl_function_zaway_toggle();
-      owl_function_makemsg("Away messages set.");
-    } else {
-      if (owl_global_is_zaway(&g)) owl_function_zaway_toggle();
-      if (owl_global_is_aaway(&g)) owl_function_aaway_toggle();
-      owl_function_makemsg("Away messages off.");
-    }
-    return NULL;
+    owl_perlconfig_perl_call_norv("BarnOwl::Hooks::_away_off", 0, NULL);
+    owl_function_makemsg("Away messages off.");
+  } else if (message != NULL) {
+    owl_global_set_aaway_msg(&g, message);
+    owl_global_set_zaway_msg(&g, message);
+    owl_function_aaway_on();
+    owl_function_zaway_on();
+    owl_perlconfig_perl_call_norv("BarnOwl::Hooks::_away_on", 1, &message);
+    owl_function_makemsg("Away messages set (%s).", message);
+  } else {
+    owl_function_aaway_on();
+    owl_function_zaway_on();
+    owl_perlconfig_perl_call_norv("BarnOwl::Hooks::_away_on", 0, NULL);
+    owl_function_makemsg("Away messages set.");
   }
 
-  buff = skiptokens(buff, 1);
-  owl_global_set_aaway_msg(&g, buff);
-  owl_global_set_zaway_msg(&g, buff);
-  owl_function_aaway_on();
-  owl_function_zaway_on();
-  owl_function_makemsg("Away messages set.");
   return NULL;
 }
 
diff --git a/functions.c b/functions.c
index e7d2fef..563899d 100644
--- a/functions.c
+++ b/functions.c
@@ -991,6 +991,13 @@ void owl_function_aaway_off(void)
   owl_function_makemsg("AIM away off");
 }
 
+bool owl_function_is_away(void)
+{
+  return owl_global_is_zaway(&g) ||
+         owl_global_is_aaway(&g) ||
+         owl_perlconfig_perl_call_bool("BarnOwl::Hooks::_get_is_away", 0, NULL);
+}
+
 void owl_function_quit(void)
 {
   char *ret;
diff --git a/perl/lib/BarnOwl/Hooks.pm b/perl/lib/BarnOwl/Hooks.pm
index 74e01d2..28c29ce 100644
--- a/perl/lib/BarnOwl/Hooks.pm
+++ b/perl/lib/BarnOwl/Hooks.pm
@@ -57,6 +57,21 @@ Called to display buddy lists for all protocol handlers. The result
 from every function registered with this hook will be appended and
 displayed in a popup window, with zephyr formatting parsed.
 
+=item $awayOn
+
+Called, for all protocol handlers, to go away, with the away message,
+if any.
+
+=item $awayOff
+
+Called, for all protocol handlers, to come back from away.
+
+=item $getIsAway
+
+Called to check away status for all protocol handlers.  Protocol
+handlers should return a true value if any account of the user is away
+for the given protocol, and a false value otherwise.
+
 =item $getQuickstart
 
 Called by :show quickstart to display 2-5 lines of help on how to
@@ -74,6 +89,7 @@ use Exporter;
 our @EXPORT_OK = qw($startup $shutdown
                     $receiveMessage $newMessage
                     $mainLoop $getBuddyList
+                    $awayOn $awayOff $getIsAway
                     $getQuickstart);
 
 our %EXPORT_TAGS = (all => [@EXPORT_OK]);
@@ -87,6 +103,9 @@ our $newMessage = BarnOwl::Hook->new;
 our $mainLoop = BarnOwl::MainLoopCompatHook->new;
 our $getBuddyList = BarnOwl::Hook->new;
 our $getQuickstart = BarnOwl::Hook->new;
+our $awayOn = BarnOwl::Hook->new;
+our $awayOff = BarnOwl::Hook->new;
+our $getIsAway = BarnOwl::Hook->new;
 
 # Internal startup/shutdown routines called by the C code
 
@@ -200,6 +219,19 @@ sub _get_quickstart {
     return join("\n", $getQuickstart->run);
 }
 
+sub _away_on {
+    $awayOn->run(@_);
+}
+
+sub _away_off {
+    $awayOff->run();
+}
+
+sub _get_is_away {
+    my @is_away = grep { $_ } $getIsAway->run();
+    return scalar @is_away;
+}
+
 sub _new_command {
     my $command = shift;
     (my $symbol = $command) =~ s/-/_/g;
diff --git a/sepbar.c b/sepbar.c
index 3da4aa2..cafaf79 100644
--- a/sepbar.c
+++ b/sepbar.c
@@ -66,18 +66,12 @@ static void sepbar_redraw(owl_window *w, WINDOW *sepwin, void *user_data)
     wprintw(sepwin, " right: %i ", owl_global_get_rightshift(&g));
   }
 
-  if (owl_global_is_zaway(&g) || owl_global_is_aaway(&g)) {
+  if (owl_function_is_away()) {
     getyx(sepwin, y, x);
     wmove(sepwin, y, x+2);
     wattron(sepwin, A_BOLD);
     wattroff(sepwin, A_REVERSE);
-    if (owl_global_is_zaway(&g) && owl_global_is_aaway(&g)) {
-      waddstr(sepwin, " AWAY ");
-    } else if (owl_global_is_zaway(&g)) {
-      waddstr(sepwin, " Z-AWAY ");
-    } else if (owl_global_is_aaway(&g)) {
-      waddstr(sepwin, " A-AWAY ");
-    }
+    waddstr(sepwin, " AWAY ");
     wattron(sepwin, A_REVERSE);
     wattroff(sepwin, A_BOLD);
   }
-- 
1.7.2.5


home help back first fref pref prev next nref lref last post