Add plugin path, separate search plugins
authorChip Black <bytex64@bytex64.net>
Mon, 15 Jun 2009 03:24:13 +0000 (22:24 -0500)
committerChip Black <bytex64@bytex64.net>
Mon, 15 Jun 2009 03:24:13 +0000 (22:24 -0500)
Added plugin path to Config, used to search for plugins. Moved search
plugins into their own directory, with a slightly different makefile.
Modified PluginManager to search for assemblies on the search path.

Search plugins have been modified to do proper url escaping (which,
incidentally, makes them even simpler).

Config.cs
Makefile
PluginManager.cs
plugins/Makefile
searchplugins/GoogleSearch.cs [moved from plugins/GoogleSearch.cs with 57% similarity]
searchplugins/Makefile [new file with mode: 0644]
searchplugins/WikipediaSearch.cs [moved from plugins/WikipediaSearch.cs with 67% similarity]

index 7bf9753..b8f04cd 100644 (file)
--- a/Config.cs
+++ b/Config.cs
@@ -18,6 +18,7 @@ namespace bytex64.WebThing {
     public class Config {
         public static List<string> ConfigPath;
         public static string ConfigPathOut = null;
+        public static List<string> PluginPath;
 
         public static Dictionary<string,string> Options;
         public static Dictionary<string,Dictionary<string,string>> PluginOptions;
@@ -55,6 +56,11 @@ namespace bytex64.WebThing {
                 if (Directory.Exists(homepath))
                     ConfigPathOut = homepath;
             }
+
+            // Set up PluginPath
+            PluginPath = new List<string>();
+            PluginPath.Add(Environment.GetEnvironmentVariable("WEBTHING_HOME") + "/plugins");
+            PluginPath.Add(Environment.GetEnvironmentVariable("WEBTHING_HOME") + "/searchplugins");
         }
 
         private static void ParseOption(string key, string val) {
index d28b428..7d1fe86 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ LDFLAGS = `pkg-config glib-2.0 libsoup-2.4 webkit-1.0 --libs`
 CSFLAGS = -debug
 references = -r:webkit-sharp.dll -pkg:gtk-sharp-2.0
 
-all: WebThingMain.exe plugins
+all: WebThingMain.exe plugins searchplugins
 
 .PHONY: tags
 tags:
@@ -22,3 +22,7 @@ SoupSettings.so: SoupSettings.c
 plugins:
        make -C plugins
 .PHONY: plugins
+
+searchplugins:
+       make -C searchplugins
+.PHONY: searchplugins
index 56bfe55..7ef976c 100644 (file)
@@ -23,8 +23,10 @@ namespace bytex64.WebThing {
         }
 
         public void LoadPlugin(string assemblyname) {
-            Assembly a = Assembly.LoadFile(Environment.GetEnvironmentVariable("WEBTHING_HOME") + "/plugins/" + assemblyname + ".dll");
+            Assembly a = FindAssembly(assemblyname);
+            if (a == null) return;
             Type[] types = a.GetTypes();
+
             foreach (Type t in types) {
                 if (t.IsSubclassOf(typeof(WebThingPlugin))) {
                     if (Plugins.ContainsKey(t.FullName))
@@ -38,6 +40,17 @@ namespace bytex64.WebThing {
             }
         }
 
+        private Assembly FindAssembly(string assemblyname) {
+            foreach (string path in Config.PluginPath) {
+                try {
+                    return Assembly.LoadFile(path + "/" + assemblyname + ".dll");
+                } catch {
+                }
+            }
+            Console.WriteLine("Could not find {0}", assemblyname);
+            return null;
+        }
+
         public void WebViewSetup(WebView view) {
             foreach (string key in PluginOrder) {
                 Plugins[key].InitWebView(view);
index d09a8c4..77b79a2 100644 (file)
@@ -1,15 +1,10 @@
 CSFLAGS = -debug
 references = -r:../webkit-sharp.dll -pkg:gtk-sharp-2.0
 
-all: Vimish.dll FFNav.dll DefaultPage.dll LoadProgress.dll MiddleClickOpen.dll QuickSearch.dll Session.dll Fullscreen.dll GoogleSearch.dll WikipediaSearch.dll
+all: Vimish.dll FFNav.dll DefaultPage.dll LoadProgress.dll MiddleClickOpen.dll QuickSearch.dll Session.dll Fullscreen.dll
 
 clean:
        rm -f *.dll *.mdb *.so
-       make -C SoupSettings clean
-
-.PHONY: SoupSettings.dll
-SoupSettings.dll: 
-       make -C SoupSettings
 
 %.dll: %.cs ../WebThing.dll
        gmcs $(CSFLAGS) $(references) -r:../WebThing.dll -target:library -out:$@ $<
similarity index 57%
rename from plugins/GoogleSearch.cs
rename to searchplugins/GoogleSearch.cs
index 7b1b542..1d345cb 100644 (file)
@@ -1,10 +1,10 @@
 using System;
-using bytex64.WebThing;
+using System.Web;
 using System.Text.RegularExpressions;
+using bytex64.WebThing;
 
 public class GoogleSearch : WebThingPlugin, ISearchPlugin {
     public string SearchTransform(string search) {
-        string[] words = Regex.Split(search, @"\s+");
-        return String.Format("http://google.com/search?q={0}", String.Join("%20", words));
+        return String.Format("http://google.com/search?q={0}", HttpUtility.UrlEncode(search));
     }
 }
diff --git a/searchplugins/Makefile b/searchplugins/Makefile
new file mode 100644 (file)
index 0000000..41b3880
--- /dev/null
@@ -0,0 +1,10 @@
+CSFLAGS = -debug
+references = -r:../WebThing.dll -r:System.Web
+
+all: GoogleSearch.dll WikipediaSearch.dll
+
+clean:
+       rm -f *.dll *.mdb *.so
+
+%.dll: %.cs ../WebThing.dll
+       gmcs $(CSFLAGS) $(references) -target:library -out:$@ $<
similarity index 67%
rename from plugins/WikipediaSearch.cs
rename to searchplugins/WikipediaSearch.cs
index 7224396..85adae4 100644 (file)
@@ -1,10 +1,10 @@
 using System;
-using bytex64.WebThing;
+using System.Web;
 using System.Text.RegularExpressions;
+using bytex64.WebThing;
 
 public class WikipediaSearch : WebThingPlugin, ISearchPlugin {
     public string SearchTransform(string search) {
-        string[] words = Regex.Split(search, @"\s+");
-        return String.Format("http://www.wikipedia.org/search-redirect.php?search={0}&language=en&go=Go", String.Join("%20", words));
+        return String.Format("http://www.wikipedia.org/search-redirect.php?search={0}&language=en&go=Go", HttpUtility.UrlEncode(search));
     }
 }