videosite-test: Allow selective tests by using grabber names on the command line
[videosite.git] / videosite-irssi.pl
index 55d7b20..f1c9b1d 100644 (file)
@@ -7,6 +7,23 @@ use Irssi 20020324 qw (command_bind command_runsub signal_add_first signal_add_l
 use vars qw($VERSION %IRSSI);
 use File::Spec;
 use Module::Load;
+use XML::Simple;
+use JSON -support_by_pp;
+
+#
+# List of foreground colors. This list is not complete, it just
+# contains the colors needed by videosite.
+#
+# The % are doubled because these are used in sprintf.
+#
+my %foreground_colors = (
+    'magenta'   => '%%m',
+    '*magenta'  => '%%M',
+    '*yellow'   => '%%Y',
+    '*green'    => '%%G',
+    '*red'      => '%%R',
+    'default'   => '%%n',
+);
 
 #
 # Initialize the config subsystem. Called by the core.
@@ -33,6 +50,7 @@ sub config_init {
 
     # Try to find old config files and load them.
     if (-r $conffile) {
+        Irssi::print("Converting configuration from videosite.json. This will happen only once.");
         eval {
             local $/;
             open(CONF, '<', $conffile);
@@ -40,7 +58,11 @@ sub config_init {
             close(CONF);
         };
     } elsif (-r $xmlconffile) {
+        Irssi::print("Converting configuration from videosite.xml. This will happen only once.");
         $conf = XML::Simple::XMLin($xmlconffile, ForceArray => ['config', 'option', 'connectorlist'], KeepRoot => 1, KeyAttr => {'connector' => '+name', 'config' => 'module', 'option' => 'key'});
+    } else {
+        # No old config files around. Just exit.
+        return;
     }
 
     #
@@ -77,7 +99,7 @@ sub config_init {
 
     # Copy the "basic" settings.
     foreach (qw(getter mode)) {
-        config_set(['getter'], $conf->{videosite}->{$_});
+        config_set([$_], $conf->{videosite}->{$_});
     }
 
     # Copy the per-getter/setter settings
@@ -104,7 +126,7 @@ sub config_init {
             }
         }
     }
-    config_set(['active-connectors'], join(",", @{$conf->{connectorlist}}));
+    config_set(['active-connectors'], join(",", @{$conf->{videosite}->{connectorlist}}));
     config_set(['defined-connectors'], join(",", @connectors));
     config_set(['config-version'], '2');
 }
@@ -118,10 +140,10 @@ sub config_get {
     my $val;
 
 
-    Irssi::settings_add_str('videosite', $item, "\0");
+    Irssi::settings_add_str('videosite', $item, "\1");
     $val = Irssi::settings_get_str($item);
 
-    return ($val ne "\0")?$val:undef;
+    return ($val ne "\1")?$val:undef;
 }
 
 #
@@ -131,8 +153,8 @@ sub config_has {
     my $path = shift;
     my $item = join('.', 'videosite', @{$path});
 
-    Irssi::settings_add_str('videosite', $item, "\0");
-    return Irssi::settings_get_str($item) ne "\0";
+    Irssi::settings_add_str('videosite', $item, "\1");
+    return Irssi::settings_get_str($item) ne "\1";
 }
 
 #
@@ -143,7 +165,7 @@ sub config_set {
     my $value = shift;
     my $item = join('.', 'videosite', @{$path});
 
-    Irssi::settings_add_str('videosite', $item, "\0");
+    Irssi::settings_add_str('videosite', $item, "\1");
     Irssi::settings_set_str($item, $value);
 }
 
@@ -160,12 +182,15 @@ sub config_del {
 #
 # Return a color code. Called by the core
 #
+# Does not handle background colors yet.
+#
 sub colorpair {
     my ($fg, $bg) = @_;
 
-    Irssi::print(sprintf("Asked to convert (%s,%s) into irssi color codes", $fg, $bg));
+    $fg = exists($foreground_colors{$fg})?$foreground_colors{$fg}:'';
+    $bg = '';
 
-    return '';
+    return $fg . $bg;
 }
 
 #