[413] in BarnOwl Developers

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

[D-O-H] r545 - trunk/conf.asedeno/owl/modules

daemon@ATHENA.MIT.EDU (asedeno@MIT.EDU)
Thu Oct 29 18:05:52 2009

Resent-From: nelhage@mit.edu
Resent-To: barnowl-dev-mtg@charon.mit.edu
To: dirty-owl-hackers@mit.edu
From: asedeno@MIT.EDU
Reply-to: dirty-owl-hackers@MIT.EDU
Date: Mon, 22 Jan 2007 18:56:52 -0500 (EST)

Author: asedeno
Date: 2007-01-22 18:56:52 -0500 (Mon, 22 Jan 2007)
New Revision: 545

Added:
   trunk/conf.asedeno/owl/modules/ColorUtilsBG.pl
Modified:
   trunk/conf.asedeno/owl/modules/ColorUtils.pl
Log:
New copy of ColorUtils for background colors.
Updates to ColorUtils to DTRT for GroupChat.



Modified: trunk/conf.asedeno/owl/modules/ColorUtils.pl
===================================================================
--- trunk/conf.asedeno/owl/modules/ColorUtils.pl	2007-01-22 19:11:51 UTC (rev 544)
+++ trunk/conf.asedeno/owl/modules/ColorUtils.pl	2007-01-22 23:56:52 UTC (rev 545)
@@ -43,8 +43,8 @@
     M-C-d (0-9)   These keybindings work like their counterparts above, but
     M-C-d b        for instances of a class. Class+Instance settings override
     M-C-d u        specific class settings.
-    M-C-d d       
-    
+    M-C-d d
+
     C-d l         (Re)Load color information from ~/.owl/colormap
     C-d s         Save color information to ~/.owl/colormap
 
@@ -69,6 +69,7 @@
 our %mode2Protocol = ('zephyr' => 'zephyr',
 		      'zephyr-personal' => 'zephyr',
 		      'aim' => 'aim',
+		      'jabber' => 'jabber',
 		      'loopback' => 'loopback');
 
 ################################################################################
@@ -95,7 +96,7 @@
 		{
 		    $strClass .= ' ( class ^'.$c.'(.d)*$ ';
 		    my $strInst = '';
-		    
+
 		    foreach my $i (sort keys %{ $currentColorMap{$mode}{$c} })
 		    {
 			next if (($i eq '*') || ($currentColorMap{$mode}{$c}{$i} eq $color));
@@ -103,7 +104,7 @@
 			$strInst .= ' and ' if ($strInst ne "");
 			$strInst .= ' ( not instance ^'.$i.'(.d)*$ ) ';
 		    }
-		    
+
 		    $strClass .= ' and ( '.$strInst.' ) ' if ($strInst ne "");
 		    $strClass .= ' ) ';
 		}
@@ -154,6 +155,21 @@
 	    $str .= $aimStr if ($count);
 	}
 	#######################################################################
+	$mode = 'jabber';
+	{
+	    my $jabberStr .= ' ( type ^'.$mode2Protocol{$mode}.'$ and ( ';
+	    my $count = 0;
+	    foreach my $sender (sort keys %{ $currentColorMap{$mode} })
+	    {
+		next if ($currentColorMap{$mode}{$sender} ne $color);
+		$sender =~ s/([+*])/\\\1/g;
+		$count++;
+		$jabberStr .= ' sender ^'.$sender.'$ or recipient ^'.$sender.'$ or ';
+	    }
+	    $jabberStr .= ' false ) ) or ';
+	    $str .= $jabberStr if ($count);
+	}
+	#######################################################################
 	$mode = 'loopback';
 	{
 	    $str .= ' ( type ^'.$mode2Protocol{$mode}.'$ ) or ' if ($currentColorMap{$mode} eq $color);
@@ -230,7 +246,7 @@
 sub setMagenta {setColor('magenta',shift)}
 sub setCyan {setColor('cyan',shift)}
 sub setWhite {setColor('white',shift)}
-sub setUndef 
+sub setUndef
 {
     my $bInst = shift;
     my $m = owl::getcurmsg();
@@ -247,7 +263,7 @@
 	{
 	    my $class = lc($m->class);
 	    my $instance = ($bInst || ($class eq 'message')) ? lc($m->instance) : '*';
-	    
+
 	    if ($instance eq '*')
 	    {
 		$currentColorMap{$type}{$class}{$instance} = default;
@@ -259,9 +275,11 @@
 	    delete $currentBoldMap{$type}{$class}{$instance};
 	}
     }
-    elsif ($type eq 'aim')
+    elsif ($type eq 'aim' || $type eq 'jabber')
     {
 	my $sender = (lc($m->direction) eq 'in') ? $m->sender : $m->recipient;
+	$sender = $m->recipient if ($type eq 'jabber' && lc($m->jtype) eq 'groupchat');
+
 	delete $currentColorMap{$type}{$sender};
 	delete $currentBoldMap{$type}{$sender};
     }
@@ -295,9 +313,10 @@
 	    $currentColorMap{$type}{$class}{$instance} = $color;
 	}
     }
-    elsif ($type eq 'aim')
+    elsif ($type eq 'aim' || $type eq 'jabber')
     {
 	my $sender = lc((lc($m->direction) eq 'in') ? $m->sender : $m->recipient);
+	$sender = $m->recipient if ($type eq 'jabber' && lc($m->jtype) eq 'groupchat');
 	$currentColorMap{$type}{$sender} = $color;
     }
     elsif ($type eq 'loopback')
@@ -332,8 +351,8 @@
 	{
 	    my $class = lc($m->class);
 	    $instance = lc($m->instance);
-	    $instance = 
-		($bInst 
+	    $instance =
+		($bInst
 		 || ($class eq 'message')
 		 || (($savedColorMap{$type}{$class}{'*'} eq $currentColorMap{$type}{$class}{'*'})
 		     && ($savedBoldMap{$type}{$class}{'*'} eq $currentBoldMap{$type}{$class}{'*'})
@@ -354,9 +373,10 @@
 	    $currentBoldMap{$type}{$class}{$instance} = $savedBoldMap{$type}{$class}{$instance};
 	}
     }
-    elsif ($type eq 'aim')
+    elsif ($type eq 'aim' || $type eq 'jabber')
     {
 	my $sender = lc((lc($m->direction) eq 'in') ? $m->sender : $m->recipient);
+	$sender = $m->recipient if ($type eq 'jabber' && lc($m->jtype) eq 'groupchat');
 	if (my $oldColor = $savedColorMap{$type}{$sender})
 	{
 	    $currentColorMap{$type}{$sender} = $oldColor;
@@ -372,11 +392,11 @@
 
 	if (my $oldColor = $savedColorMap{$type})
 	{
-	    $savedColorMap{$type} = $oldColor; 
+	    $currentColorMap{$type} = $oldColor;
 	}
 	else
 	{
-	    delete $savedColorMap{$type} 
+	    delete $currentColorMap{$type};
 	}
 	$currentBoldMap{$type} = $savedBoldMap{$type};
     }
@@ -401,13 +421,14 @@
 	{
 	    my $class = lc($m->class);
 	    my $instance = ($bInst || ($class eq 'message')) ? lc($m->instance) : '*';
-	    
+
 	    $currentBoldMap{$type}{$class}{$instance} = (($currentBoldMap{$type}{$class}{$instance}) ? 0 : 1);
 	}
     }
-    elsif ($type eq 'aim')
+    elsif ($type eq 'aim' || $type eq 'jabber')
     {
 	my $sender = (lc($m->direction) eq 'in') ? $m->sender : $m->recipient;
+	$sender = $m->recipient if ($type eq 'jabber' && lc($m->jtype) eq 'groupchat');
 	$currentBoldMap{$type}{$sender} = $currentBoldMap{$type}{$sender} ? 0 : 1;
     }
     elsif ($type eq 'loopback')
@@ -435,7 +456,6 @@
 sub isBold($)
 {
     my $m = shift;
-    
     my $type = lc($m->type);
 
     if ($type eq 'zephyr')
@@ -449,7 +469,7 @@
 	{
 	    my $c = undef;
 	    my $class = lc($m->class);
-	    
+
 	    do
 	    {
 		my $instance = lc($m->instance);
@@ -458,28 +478,26 @@
 		    $c = $currentBoldMap{$type}{$class}{$instance};
 		    $instance =~ s/(.*)\.d$/$1/ei;
 		} while (($c eq undef) && $instance =~ /\.d$/i);
-		
+
 		if ($c eq undef)
 		{
 		    $c = $currentBoldMap{$type}{$class}{$instance} || $currentBoldMap{$type}{$class}{'*'};
 		}
 		$class =~ s/(.*)\.d$/$1/ei;
-		
 	    } while (($c eq undef) && $class =~ /\.d$/i);
-	    
+
 	    if ($c eq undef)
 	    {
 		$c = $currentBoldMap{$type}{$class}{$instance} || $currentBoldMap{$type}{$class}{'*'};
 	    }
-	    
 	    return $c ? 1 : 0;
 	}
     }
-    elsif ($type eq 'aim')
+    elsif ($type eq 'aim' || $type eq 'jabber')
     {
 	my $sender = (lc($m->direction) eq 'in') ? $m->sender : $m->recipient;
+	$sender = $m->recipient if ($type eq 'jabber' && lc($m->jtype) eq 'groupchat');
 	return $currentBoldMap{$type}{$sender};
-	
     }
     elsif ($type eq 'loopback')
     {
@@ -508,7 +526,7 @@
 		print COLORS "$c,$i,".($currentBoldMap{$type}{$c}{$i}?'b':'').($currentColorMap{$type}{$c}{$i} ? $currentColorMap{$type}{$c}{$i} : 'default')."\n";
 	    }
         }
-    } 
+    }
 
     $type = 'zephyr-personal';
     print COLORS "MODE: $type\n";
@@ -524,6 +542,13 @@
 	print COLORS "$s,".($currentBoldMap{$type}{$s}?'b':'').($currentColorMap{$type}{$s} ? $currentColorMap{$type}{$s} : 'default')."\n";
     }
 
+    $type = 'jabber';
+    print COLORS "MODE: $type\n";
+    foreach my $s (sort keys %{ $currentColorMap{$type} })
+    {
+	print COLORS "$s,".($currentBoldMap{$type}{$s}?'b':'').($currentColorMap{$type}{$s} ? $currentColorMap{$type}{$s} : 'default')."\n";
+    }
+
     $type = 'loopback';
     print COLORS "MODE: $type\n";
     print COLORS ($currentBoldMap{$type}{$s}?'b':'').($currentColorMap{$type}{$s} ? $currentColorMap{$type}{$s} : 'default')."\n";
@@ -548,7 +573,7 @@
     {
 	if ($line =~ /^MODE: (.*)$/)
 	{
-	    if (lc($1) eq "zephyr") 
+	    if (lc($1) eq "zephyr")
 	    { 
 		$mode = 'zephyr';
 	    }
@@ -556,12 +581,16 @@
 	    {
 		$mode = 'zephyr-personal';
 	    }
-	    elsif (lc($1) eq "aim") 
+	    elsif (lc($1) eq "aim")
 	    {
 		$mode = 'aim';
 	    }
-	    elsif (lc($1) eq "loopback") 
+	    elsif (lc($1) eq "jabber")
 	    {
+		$mode = 'jabber';
+	    }
+	    elsif (lc($1) eq "loopback")
+	    {
 		$mode = 'loopback';
 	    }
 	    else 
@@ -583,7 +612,7 @@
 	    $currentBoldMap{$mode}{lc($1)}  = $2 ? 1 : 0;
 	    $savedBoldMap{$mode}{lc($1)}    = $2 ? 1 : 0;
 	}
-	elsif ($mode eq 'aim' && $line =~ /^(.+),(b?)(black|red|green|yellow|blue|magenta|cyan|white|default)$/i)
+	elsif (($mode eq 'aim' || $mode eq 'jabber') && $line =~ /^(.+),(b?)(black|red|green|yellow|blue|magenta|cyan|white|default)$/i)
 	{
 	    $currentColorMap{$mode}{lc($1)} = lc($3);
 	    $savedColorMap{$mode}{lc($1)}   = lc($3);

Added: trunk/conf.asedeno/owl/modules/ColorUtilsBG.pl
===================================================================
--- trunk/conf.asedeno/owl/modules/ColorUtilsBG.pl	                        (rev 0)
+++ trunk/conf.asedeno/owl/modules/ColorUtilsBG.pl	2007-01-22 23:56:52 UTC (rev 545)
@@ -0,0 +1,501 @@
+# Colors module.
+package ARS_ColorBG;
+
+################################################################################
+#Run this on start and reload. Adds styles, sets style to start.
+################################################################################
+sub onStart
+{
+    bindings_Color();
+    load();
+}
+
+push @::onStartSubs, \&onStart;
+
+
+################################################################################
+# Help information
+################################################################################
+sub moduleHelp()
+{
+    my @helpmsgArray = <<END_OF_HELP ;
+Module: ColorUtilsBG (package: ARS_ColorBG)
+
+  Module keys:
+    C-b (0-9)     Change the color for this sender or class (or instance if 
+		   -c message) to
+                  0 - Black              1 - Red
+                  2 - Green              3 - Yellow
+                  4 - Blue               5 - Magenta
+                  6 - Cyan               7 - White
+		  8 - (reset)            9 - (reset)
+
+    C-b u         Unset the color for this sender or class (or instance if
+		   -c message).
+    C-b d         Reset color for this sender or class to the color specified
+                   when colors were last loaded. This will reset the instance
+		   color instead if -c message, or if reseting the class color
+		   would be a no-op.
+
+    M-C-b (0-9)   These keybindings work like their counterparts above, but
+    M-C-b u        for instances of a class. Class+Instance settings override
+    M-C-b d        specific class settings.
+
+    C-b l         (Re)Load color information from ~/.owl/colormap
+    C-b s         Save color information to ~/.owl/colormap
+
+END_OF_HELP
+
+    return @helpmsgArray;
+}
+push @::onModuleHelp, \&moduleHelp;
+
+################################################################################
+## Color state.
+################################################################################
+our %currentColorMap = ();
+our %savedColorMap = ();
+our %mode2Protocol = ('zephyr' => 'zephyr',
+		      'zephyr-personal' => 'zephyr',
+		      'aim' => 'aim',
+		      'jabber' => 'jabber',
+		      'loopback' => 'loopback');
+
+################################################################################
+## Loading function
+################################################################################
+sub createFilters
+{
+    # Prepare the color filters.
+    my @colorList = ('black','red','green','yellow',
+		     'blue','magenta','cyan','white');
+    foreach my $color (@colorList)
+    {
+	my $str = "filter ".$color."-bg -b $color ( ";
+
+	#######################################################################
+	my $mode = 'zephyr';
+	{
+	    $str .= ' ( type ^'.$mode2Protocol{$mode}.'$ and ( ';
+	    foreach my $c (sort keys %{ $currentColorMap{$mode} })
+	    {
+		$c =~ s/([+*])/\\\1/g;
+		my $strClass = '';
+		if ($currentColorMap{$mode}{$c}{'*'} eq $color)
+		{
+		    $strClass .= ' ( class ^'.$c.'(.d)*$ ';
+		    my $strInst = '';
+
+		    foreach my $i (sort keys %{ $currentColorMap{$mode}{$c} })
+		    {
+			next if (($i eq '*') || ($currentColorMap{$mode}{$c}{$i} eq $color));
+			$i =~ s/([+*])/\\\1/g;
+			$strInst .= ' and ' if ($strInst ne "");
+			$strInst .= ' ( not instance ^'.$i.'(.d)*$ ) ';
+		    }
+
+		    $strClass .= ' and ( '.$strInst.' ) ' if ($strInst ne "");
+		    $strClass .= ' ) ';
+		}
+		else
+		{
+		    my $strInst = '';
+		    foreach my $i (sort keys %{ $currentColorMap{$mode}{$c} })
+		    {
+			next if (($i eq '*') || ($currentColorMap{$mode}{$c}{$i} ne $color));
+			$i =~ s/([+*])/\\\1/g;
+			$strInst .= ' or ' if ($strInst ne "");
+			$strInst .= ' ( instance ^'.$i.'(.d)*$ ) ';
+		    }
+		    $strClass = '( class ^'.$c.'(.d)*$ and ( '.$strInst.' ) ) '  if ($strInst ne "");
+		}
+		$str .= ' '.$strClass.' or ' if ($strClass ne "");
+	    }
+	    $str .= ' false ) ) or ';
+	}
+	#######################################################################
+	$mode = 'zephyr-personal';
+	{
+	    my $zpStr .= ' ( type ^'.$mode2Protocol{$mode}.'$ and ( ( class ^message$ and instance ^personal$ ) or class ^login$ ) and ( ';
+	    my $count = 0;
+	    foreach my $sender (sort keys %{ $currentColorMap{$mode} })
+	    {
+		next if ($currentColorMap{$mode}{$sender} ne $color);
+		$sender =~ s/([+*])/\\\1/g;
+		$count++;
+		$zpStr .= ' sender ^'.$sender.'$ or recipient ^'.$sender.'$ or ';
+	    }
+	    $zpStr .= ' false ) ) or ';
+	    $str .= $zpStr if ($count);
+	}
+	#######################################################################
+	$mode = 'aim';
+	{
+	    my $aimStr .= ' ( type ^'.$mode2Protocol{$mode}.'$ and ( ';
+	    my $count = 0;
+	    foreach my $sender (sort keys %{ $currentColorMap{$mode} })
+	    {
+		next if ($currentColorMap{$mode}{$sender} ne $color);
+		$sender =~ s/([+*])/\\\1/g;
+		$count++;
+		$aimStr .= ' sender ^'.$sender.'$ or recipient ^'.$sender.'$ or ';
+	    }
+	    $aimStr .= ' false ) ) or ';
+	    $str .= $aimStr if ($count);
+	}
+	#######################################################################
+	$mode = 'jabber';
+	{
+	    my $jabberStr .= ' ( type ^'.$mode2Protocol{$mode}.'$ and ( ';
+	    my $count = 0;
+	    foreach my $sender (sort keys %{ $currentColorMap{$mode} })
+	    {
+		next if ($currentColorMap{$mode}{$sender} ne $color);
+		$sender =~ s/([+*])/\\\1/g;
+		$count++;
+		$jabberStr .= ' sender ^'.$sender.'$ or recipient ^'.$sender.'$ or ';
+	    }
+	    $jabberStr .= ' false ) ) or ';
+	    $str .= $jabberStr if ($count);
+	}
+	#######################################################################
+	$mode = 'loopback';
+	{
+	    $str .= ' ( type ^'.$mode2Protocol{$mode}.'$ ) or ' if ($currentColorMap{$mode} eq $color);
+	}
+	#######################################################################
+	$str .= " false ) ";
+	$str =~ s/or\s+false//g;
+	owl::command($str);
+    }
+}
+
+sub bindings_Color
+{
+    # sender/class coloring (also works on -c message)
+    owl::command('bindkey recv "C-b 0" command perl ARS_ColorBG::setBlack(0)');
+    owl::command('bindkey recv "C-b 1" command perl ARS_ColorBG::setRed(0)');
+    owl::command('bindkey recv "C-b 2" command perl ARS_ColorBG::setGreen(0)');
+    owl::command('bindkey recv "C-b 3" command perl ARS_ColorBG::setYellow(0)');
+    owl::command('bindkey recv "C-b 4" command perl ARS_ColorBG::setBlue(0)');
+    owl::command('bindkey recv "C-b 5" command perl ARS_ColorBG::setMagenta(0)');
+    owl::command('bindkey recv "C-b 6" command perl ARS_ColorBG::setCyan(0)');
+    owl::command('bindkey recv "C-b 7" command perl ARS_ColorBG::setWhite(0)');
+    owl::command('bindkey recv "C-b 8" command perl ARS_ColorBG::reset(0)');
+    owl::command('bindkey recv "C-b 9" command perl ARS_ColorBG::reset(0)');
+    owl::command('bindkey recv "C-b d" command perl ARS_ColorBG::reset(0)');
+    owl::command('bindkey recv "C-b u" command perl ARS_ColorBG::setUndef(0)');
+    owl::command('bindkey recv "C-b C-b" command perl ARS_ColorBG::reset(0)');
+
+    # instance coloring
+    owl::command('bindkey recv "M-C-b 0" command perl ARS_ColorBG::setBlack(1)');
+    owl::command('bindkey recv "M-C-b 1" command perl ARS_ColorBG::setRed(1)');
+    owl::command('bindkey recv "M-C-b 2" command perl ARS_ColorBG::setGreen(1)');
+    owl::command('bindkey recv "M-C-b 3" command perl ARS_ColorBG::setYellow(1)');
+    owl::command('bindkey recv "M-C-b 4" command perl ARS_ColorBG::setBlue(1)');
+    owl::command('bindkey recv "M-C-b 5" command perl ARS_ColorBG::setMagenta(1)');
+    owl::command('bindkey recv "M-C-b 6" command perl ARS_ColorBG::setCyan(1)');
+    owl::command('bindkey recv "M-C-b 7" command perl ARS_ColorBG::setWhite(1)');
+    owl::command('bindkey recv "M-C-b 8" command perl ARS_ColorBG::reset(1)');
+    owl::command('bindkey recv "M-C-b 9" command perl ARS_ColorBG::reset(1)');
+    owl::command('bindkey recv "M-C-b d" command perl ARS_ColorBG::reset(1)');
+    owl::command('bindkey recv "M-C-b u" command perl ARS_ColorBG::setUndef(1)');
+    owl::command('bindkey recv "M-C-b d" command perl ARS_ColorBG::reset(1)');
+    owl::command('bindkey recv "M-C-b M-C-u" command perl ARS_ColorBG::setUndef(1)');
+    owl::command('bindkey recv "M-C-b M-C-b" command perl ARS_ColorBG::reset(1)');
+
+    # save/load
+    owl::command('bindkey recv "C-b s" command perl ARS_ColorBG::save()');
+    owl::command('bindkey recv "C-b l" command perl ARS_ColorBG::load()');
+}
+
+################################################################################
+## Color toggling functions
+################################################################################
+sub isZPersonal
+{
+    # Return 1 for things that would qualify a zephyr as personal.
+    $m = shift;
+    return 1 if ($m->recipient ne "" and $m->recipient !~ /^@/);
+    return 1 if lc($m->class) eq "login";
+    return 0;
+}
+
+sub setBlack {setColor('black',shift)}
+sub setRed {setColor('red',shift)}
+sub setGreen {setColor('green',shift)}
+sub setYellow {setColor('yellow',shift)}
+sub setBlue {setColor('blue',shift)}
+sub setMagenta {setColor('magenta',shift)}
+sub setCyan {setColor('cyan',shift)}
+sub setWhite {setColor('white',shift)}
+sub setUndef
+{
+    my $bInst = shift;
+    my $m = owl::getcurmsg();
+    my $type = lc($m->type);
+    if ($type eq 'zephyr')
+    {
+	if (isZPersonal($m))
+	{
+	    my $sender = lc((lc($m->direction) eq 'in') ? $m->sender : $m->recipient);
+	    delete $currentColorMap{'zephyr-personal'}{$sender};
+	}
+	else
+	{
+	    my $class = lc($m->class);
+	    my $instance = ($bInst || ($class eq 'message')) ? lc($m->instance) : '*';
+
+	    if ($instance eq '*')
+	    {
+		$currentColorMap{$type}{$class}{$instance} = default;
+	    }
+	    else
+	    {
+		delete $currentColorMap{$type}{$class}{$instance};
+	    }
+	}
+    }
+    elsif ($type eq 'aim' || $type eq 'jabber')
+    {
+	my $sender = (lc($m->direction) eq 'in') ? $m->sender : $m->recipient;
+	$sender = $m->recipient if ($type eq 'jabber' && lc($m->jtype) eq 'groupchat');
+	delete $currentColorMap{$type}{$sender};
+    }
+    elsif ($type eq 'loopback')
+    {
+	delete $currentColorMap{$type};
+    }
+
+    refreshView();
+}
+
+sub setColor
+{
+    my $color = shift;
+    my $bInst = shift;
+    my $m = owl::getcurmsg();
+
+    my $type = lc($m->type);
+    if ($type eq 'zephyr')
+    {
+	if (isZPersonal($m))
+	{
+	    my $sender = lc((lc($m->direction) eq 'in') ? $m->sender : $m->recipient);
+	    $currentColorMap{'zephyr-personal'}{$sender} = $color;
+	}
+	else
+	{
+	    my $class = lc($m->class);
+	    my $instance = ($bInst || ($class eq 'message')) ? lc($m->instance) : '*';
+	    $currentColorMap{$type}{$class}{$instance} = $color;
+	}
+    }
+    elsif ($type eq 'aim' || $type eq 'jabber')
+    {
+	my $sender = lc((lc($m->direction) eq 'in') ? $m->sender : $m->recipient);
+	$sender = $m->recipient if ($type eq 'jabber' && lc($m->jtype) eq 'groupchat');
+	$currentColorMap{$type}{$sender} = $color;
+    }
+    elsif ($type eq 'loopback')
+    {
+	$currentColorMap{$type} = $color;
+    }
+
+    refreshView();
+}
+
+sub reset
+{
+    my $bInst = shift;
+    my $m = owl::getcurmsg();
+    my $type = lc($m->type);
+    if ($type eq 'zephyr')
+    {
+	if (isZPersonal($m))
+	{
+	    my $sender = lc((lc($m->direction) eq 'in') ? $m->sender : $m->recipient);
+	    if (my $oldColor = $savedColorMap{'zephyr-personal'}{$sender})
+	    {
+		$currentColorMap{'zephyr-personal'}{$sender} = $oldColor;
+	    }
+	    else
+	    {
+		delete $currentColorMap{'zephyr-personal'}{$sender};
+	    }
+	}
+	else
+	{
+	    my $class = lc($m->class);
+	    $instance = lc($m->instance);
+	    $instance =
+		($bInst
+		 || ($class eq 'message')
+		 || (($savedColorMap{$type}{$class}{'*'} eq $currentColorMap{$type}{$class}{'*'})
+		     && ($savedColorMap{$type}{$class}{$instance} ne $currentColorMap{$type}{$class}{$instance})))
+		? $instance
+		: '*';
+
+	    if(my $oldColor = $savedColorMap{$type}{$class}{$instance})
+	    {
+		$currentColorMap{$type}{$class}{$instance} = $oldColor;
+	    }
+	    else
+	    {
+		delete $currentColorMap{$type}{$class}{$instance};
+	    }
+	}
+    }
+    elsif ($type eq 'aim' || $type eq 'jabber')
+    {
+	my $sender = lc((lc($m->direction) eq 'in') ? $m->sender : $m->recipient);
+	$sender = $m->recipient if ($type eq 'jabber' && lc($m->jtype) eq 'groupchat');
+	if (my $oldColor = $savedColorMap{$type}{$sender})
+	{
+	    $currentColorMap{$type}{$sender} = $oldColor;
+	}
+	else
+	{
+	    delete $currentColorMap{$type}{$sender};
+	}
+    }
+    elsif ($type eq 'loopback')
+    {
+
+	if (my $oldColor = $savedColorMap{$type})
+	{
+	    $currentColorMap{$type} = $oldColor;
+	}
+	else
+	{
+	    delete $currentColorMap{$type};
+	}
+    }
+
+    refreshView();
+}
+
+sub refreshView()
+{
+    createFilters();
+    my $filter = owl::command("getview");
+    my $style = owl::command("getstyle");
+
+    owl::command("view -f $filter ".($style?"-s $style":""));
+}
+
+################################################################################
+## Saving/Loading functions
+################################################################################
+sub save
+{
+    open(COLORS, ">$ENV{HOME}/.owl/colormap_bg");
+
+    my $type = 'zephyr';
+    print COLORS "MODE: $type\n";
+    foreach my $c (sort keys %{ $currentColorMap{$type} })
+    {
+
+	foreach my $i (sort keys %{ $currentColorMap{$type}{$c} })
+	{
+	    if ($i eq '*'
+		|| !($currentColorMap{$type}{$c}{$i} eq $currentColorMap{$type}{$c}{'*'} || !$currentColorMap{$type}{$c}{$i}))
+	    {
+		print COLORS "$c,$i,".($currentColorMap{$type}{$c}{$i} ? $currentColorMap{$type}{$c}{$i} : 'default')."\n";
+	    }
+        }
+    }
+
+    $type = 'zephyr-personal';
+    print COLORS "MODE: $type\n";
+    foreach my $s (sort keys %{ $currentColorMap{$type} })
+    {
+	print COLORS "$s,".($currentColorMap{$type}{$s} ? $currentColorMap{$type}{$s} : 'default')."\n";
+    }
+
+    $type = 'aim';
+    print COLORS "MODE: $type\n";
+    foreach my $s (sort keys %{ $currentColorMap{$type} })
+    {
+	print COLORS "$s,".($currentColorMap{$type}{$s} ? $currentColorMap{$type}{$s} : 'default')."\n";
+    }
+
+    $type = 'jabber';
+    print COLORS "MODE: $type\n";
+    foreach my $s (sort keys %{ $currentColorMap{$type} })
+    {
+	print COLORS "$s,".($currentColorMap{$type}{$s} ? $currentColorMap{$type}{$s} : 'default')."\n";
+    }
+
+    $type = 'loopback';
+    print COLORS "MODE: $type\n";
+    print COLORS ($currentColorMap{$type}{$s} ? $currentColorMap{$type}{$s} : 'default')."\n";
+
+    close(COLORS);
+    load();
+}
+
+sub load
+{
+    %currentColorMap = ();
+    %savedColorMap = ();
+
+    # Parse the color file.
+    open(COLORS, "<$ENV{HOME}/.owl/colormap_bg");
+
+    my $mode = "zephyr";
+
+    while (chomp(my $line = <COLORS>))
+    {
+	if ($line =~ /^MODE: (.*)$/)
+	{
+	    if (lc($1) eq "zephyr")
+	    { 
+		$mode = 'zephyr';
+	    }
+	    elsif (lc($1) eq "zephyr-personal")
+	    {
+		$mode = 'zephyr-personal';
+	    }
+	    elsif (lc($1) eq "aim")
+	    {
+		$mode = 'aim';
+	    }
+	    elsif (lc($1) eq "jabber")
+	    {
+		$mode = 'jabber';
+	    }
+	    elsif (lc($1) eq "loopback")
+	    {
+		$mode = 'loopback';
+	    }
+	    else 
+	    {
+		$mode = 'zephyr';
+	    }
+	}
+	elsif ($mode eq 'zephyr' && $line =~ /^(.+),(.+),(b?)(black|red|green|yellow|blue|magenta|cyan|white|default)$/i)
+	{
+	    $currentColorMap{$mode}{lc($1)}{lc($2)} = lc($4);
+	    $savedColorMap{$mode}{lc($1)}{lc($2)}   = lc($4);
+	}
+	elsif ($mode eq 'zephyr-personal' && $line =~ /^(.+),(b?)(black|red|green|yellow|blue|magenta|cyan|white|default)$/i)
+	{
+	    $currentColorMap{$mode}{lc($1)} = lc($3);
+	    $savedColorMap{$mode}{lc($1)}   = lc($3);
+	}
+	elsif (($mode eq 'aim' || $mode eq 'jabber') && $line =~ /^(.+),(b?)(black|red|green|yellow|blue|magenta|cyan|white|default)$/i)
+	{
+	    $currentColorMap{$mode}{lc($1)} = lc($3);
+	    $savedColorMap{$mode}{lc($1)}   = lc($3);
+	}
+	elsif ($mode eq 'loopback' && $line =~ /^(b?)(black|red|green|yellow|blue|magenta|cyan|white|default)$/i)
+	{
+	    $currentColorMap{$mode} = lc($2);
+	    $savedColorMap{$mode}   = lc($2);
+	}
+
+    }
+    close(COLORS);
+    refreshView();
+}


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