libvideosite: move definition of remote_api and add default reset function
[videosite.git] / videosite-irssi.pl
index 3d72728..3db9af1 100644 (file)
@@ -26,6 +26,14 @@ my %foreground_colors = (
 );
 
 #
+# This is a canary value used in the config system as the default
+# value. As irssi does not have a way to test if a setting exists
+# this is used instead. A config value is never expected to be set
+# to this value and be valid.
+#
+my $config_canary = "\1";
+
+#
 # Initialize the config subsystem. Called by the core.
 #
 # Due to historic reasons this has to deal with a number of possible config sources:
@@ -50,6 +58,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);
@@ -57,7 +66,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;
     }
 
     #
@@ -94,7 +107,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
@@ -121,7 +134,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');
 }
@@ -135,10 +148,10 @@ sub config_get {
     my $val;
 
 
-    Irssi::settings_add_str('videosite', $item, "\0");
+    Irssi::settings_add_str('videosite', $item, $config_canary);
     $val = Irssi::settings_get_str($item);
 
-    return ($val ne "\0")?$val:undef;
+    return ($val ne $config_canary)?$val:undef;
 }
 
 #
@@ -148,8 +161,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, $config_canary);
+    return Irssi::settings_get_str($item) ne $config_canary;
 }
 
 #
@@ -160,18 +173,21 @@ sub config_set {
     my $value = shift;
     my $item = join('.', 'videosite', @{$path});
 
-    Irssi::settings_add_str('videosite', $item, "\0");
+    Irssi::settings_add_str('videosite', $item, $config_canary);
     Irssi::settings_set_str($item, $value);
 }
 
 #
 # Delete a configuration value. Called by the core.
 #
+# Now, according to the configuration Irssi::settings_remove() removes a
+# config settings. This does not work in any irssi version available to me.
+# So just set the key to the canary value.
+#
 sub config_del {
     my $path = shift;
-    my $item = join('.', 'videosite', @{$path});
 
-    Irssi::settings_remove($item);
+    config_set($path, $config_canary);
 }
 
 #
@@ -252,7 +268,7 @@ sub videosite_init {
     if (videosite_reset()) {
         signal_add_last("message public", sub { message_hook(@_) });
         signal_add_last("message own_public", sub { message_hook($_[0], $_[1], undef, undef, $_[2]) });
-        signal_add_last("message private", sub { message_hooK($_[0], $_[1], $_[2], $_[3], $_[2]) });
+        signal_add_last("message private", sub { message_hook($_[0], $_[1], $_[2], $_[3], $_[2]) });
         signal_add_last("message own_private", sub { message_hook($_[0], $_[1], undef, undef, $_[2]) });
         signal_add_last("message irc action", sub { message_hook(@_) });
         signal_add_last("message irc own_action", sub { message_hook($_[0], $_[1], undef, undef, $_[2]) });