summaryrefslogtreecommitdiffstats
path: root/khelpcenter/searchhandlers/khc_beagle_search.pl
diff options
context:
space:
mode:
authortpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-09-03 09:14:57 +0000
committertpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2010-09-03 09:14:57 +0000
commit27856879bf962f178d88e79144e37a47e731b122 (patch)
treea3bd3f489b755cd2941e7c53b90d12d6bfd4fbe3 /khelpcenter/searchhandlers/khc_beagle_search.pl
parentc5228d52f504d6d2c0fefdd625ec08ebb8e91f85 (diff)
downloadtdebase-27856879bf962f178d88e79144e37a47e731b122.tar.gz
tdebase-27856879bf962f178d88e79144e37a47e731b122.zip
* Massive import of OpenSUSE patches, primarily for bugfixes
* Added some infrastructure created by OpenSUSE to allow for future addition of the Kickoff menu as an option * Minor Slackware compilation fixes git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebase@1171255 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'khelpcenter/searchhandlers/khc_beagle_search.pl')
-rw-r--r--khelpcenter/searchhandlers/khc_beagle_search.pl88
1 files changed, 88 insertions, 0 deletions
diff --git a/khelpcenter/searchhandlers/khc_beagle_search.pl b/khelpcenter/searchhandlers/khc_beagle_search.pl
new file mode 100644
index 000000000..d7a1f44b8
--- /dev/null
+++ b/khelpcenter/searchhandlers/khc_beagle_search.pl
@@ -0,0 +1,88 @@
+#!/usr/bin/perl -w
+# vim:sw=4:et
+
+use warnings;
+use strict;
+use Getopt::Long;
+
+sub isBeagleRunning()
+{
+ open(IN, "-|") || exec "beagle-ping";
+ while(<IN>) {
+ if (/^Daemon version:/) {
+ close(IN);
+ return 1;
+ }
+ }
+ close(IN);
+ return 0;
+}
+
+sub formatHTML($$)
+{
+ my ($query, $hits) = @_;
+
+ print "<html>\n<body\n<ul>\n";
+
+ foreach my $hit(@$hits) {
+ print "<li>$hit</li>\n";
+ }
+ print "</ul>\n</body>\n</html>\n";
+}
+
+sub beagleQuery($$$)
+{
+ my ($words, $method, $maxnum) = @_;
+
+ my @hits = ();
+
+ open(IN, "-|") || exec "beagle-query", "--type", "DocbookEntry", "--type", "File", "--max-hits", $maxnum, @$words, "ext:docbook";
+ while(<IN>) {
+ chop;
+ next if (/^Debug:/);
+
+ my $uri = $_;
+ $uri = $1 if ($uri =~ /^file:\/\/(.*)$/);
+
+ print "uri: $uri\n";
+ my $helpLink = &makeHelpLink($uri);
+
+ push(@hits, $helpLink) if (!grep { /^$helpLink$/ } @hits);
+ }
+ close(IN);
+ return @hits;
+}
+
+sub makeHelpLink($)
+{
+ # Try to figure out the name of the application from the path to its index.docbook file
+
+ my ($path) = @_;
+ my @pathcomponents = split '/', $path;
+
+ my $appName = $pathcomponents[-2];
+ my $appName2 = $pathcomponents[-3];
+
+ if ($appName eq $appName2 or $appName2 eq "doc"
+ or (-d "/usr/share/locale/$appName2")) {
+ return "<a href=\"help:/$appName\">$appName</a>";
+ }
+ return "<a href=\"help:/$appName2/$appName\">$appName ($appName2)</a>";
+}
+
+my $method = "and";
+my $maxnum = 100;
+
+GetOptions("method=s", \$method, "maxnum=i", \$maxnum);
+
+my @hits = ("The Beagle daemon is not running, search is not available");
+
+my @words = @ARGV;
+
+if (isBeagleRunning()) {
+ @hits = beagleQuery(\@words, $method, $maxnum);
+}
+
+@hits = ("There are no search results") if ($#hits < 0);
+
+formatHTML(\@words, \@hits);