Version: 15.1 (using KDE KDE 3.3.2) Installed from: FreeBSD Ports It would be nice to be able to quickly search Google from the input box, by entering something like: /g searchword Probably this can be implemented as a simple script. Care should be taken that a search on 'K&R syntax' really searches on K&R syntax: correct treatment of the ampersand and spaces in the search term might need some attention. This is how I implemented it in the C++ code; a script would be nicer. QString url = "http://www.google.com"; // If a parameter is specified, append it to Google's URL as a searchword if (parameter!="") { QString cooked(parameter); cooked.replace(QRegExp("&"),"%26"); // In case someone searches for K&R ;-) url+="/search?q="+cooked; }
CVS commit by cartman: A google script. Launches konqueror with google search url.Try /google kde BUG:99354 FEATURE: A google 1.1 M +1 -1 Makefile.am 1.17 --- kdeextragear-2/konversation/scripts/Makefile.am #1.16:1.17 @@ -1,4 +1,4 @@ scriptsdir=$(kde_datadir)/konversation/scripts -scripts_SCRIPTS=bug fortune gauge uptime kdeversion cmd sayclip weather colorizer sysinfo media mail +scripts_SCRIPTS=bug fortune gauge uptime kdeversion cmd sayclip weather colorizer sysinfo media mail google scripts_DATA=fortunes.dat
CVS commit by cartman: A better google script using Google SOAP api. You need to get a license key from http://api.google.com/createkey and put it in ~/.googlekey .Here is the sample usage: /google (-s) foo # Searches for foo and displays top 10 results /google -s|--spell foo # Spellcheck foo using Google /google -b|--browser foo # Launch konqueror and show google search page for foo TODO: Handle errors: Soap exceptions,Non-existent license,no results etc Queries containing & doesn't seem to work CCBUG:99354 FEATURE: M +49 -12 google 1.2 --- kdeextragear-2/konversation/scripts/google #1.1:1.2 @@ -1,22 +1,59 @@ #!/usr/bin/env perl -# -# Copyright (C) 2004 by İsmail Dönmez -# Licensed under GPL v2 or later at your option use warnings; -use strict; +use SOAP::Lite; +use Getopt::Long; + +my $PORT=shift; +my $SERVER=shift; +my $TARGET=shift; +my $key=`cat ~/.googlekey`; +my $googleSearch; +my $result; +my $print; +my $spell; -my $PORT= shift; -shift; -shift; -my $url="http://www.google.com/search?q="; +GetOptions('search=s' => \$search, + 'spell=s' => \$spellcheck, + 'browser' => \$browser); -if(!@ARGV) +if(!$browser && !$search && !$spellcheck && !@ARGV) { - exec 'dcop', $PORT, 'Konversation', 'error', 'Please provide a query, e.g /google linux'; + $info = "/google (-s) <keyword> : Search for keyword at Google, /google -s|--spell <word> : Spellcheck word using Google, /google -b <keyword> : Show results in konqueror"; + exec 'dcop', $PORT, 'Konversation', 'info', $info; } -else +elsif($browser) { - $url="$url@ARGV"; + $query = join(" ",@ARGV); + $query =~ s/\&/\%26/g; + $url="http://www.google.com/search?q=$query"; exec 'kfmclient','openURL',$url; } +elsif($search || !$spellcheck) +{ + $search = join(" ",$search,@ARGV); + + system 'dcop', $PORT, 'Konversation', 'say', $SERVER, $TARGET, "Searching Google for %B$search%B ..."; + + $googleSearch = SOAP::Lite->service("http://api.google.com/GoogleSearch.wsdl"); + $result = $googleSearch->doGoogleSearch($key, $search, 0, 10, "false", "", "false", "", "UTF-8", "UTF-8"); + + system 'dcop', $PORT, 'Konversation', 'say', $SERVER, $TARGET, "Results %B1-10%B of about %B$result->{estimatedTotalResultsCount}%B for %B$search%B (%B$result->{searchTime}%B seconds)"; + + foreach $result (@{$result->{resultElements}}) + { + $print = $result->{URL}." (".$result->{title}.")"; + $print =~ s/\<b\>/\%B/g; + $print =~ s/\<\/b\>/\%B/g; + system 'dcop', $PORT, 'Konversation', 'say', $SERVER, $TARGET, $print; + } +} +elsif($spellcheck) +{ + $spellcheck = join(" ",$spellcheck,@ARGV); + system 'dcop', $PORT, 'Konversation', 'say', $SERVER, $TARGET,"Spellchecking %B$spellcheck%B ..."; + $googleSearch = SOAP::Lite->service("http://api.google.com/GoogleSearch.wsdl"); + $spell = $googleSearch->doSpellingSuggestion($key, $spellcheck); + $spell = "Spelling suggestion: ".$spell; + system 'dcop', $PORT, 'Konversation', 'say', $SERVER, $TARGET,$spell; +}
cartman can you use CGI::escape or something at least not less bug-free instead of that ugly $query =~ s/\&/\%26/g ?
On Sunday 20 February 2005 01:13, Stanislav Karchebny wrote: > ------- You are receiving this mail because: ------- > You are the assignee for the bug, or are watching the assignee. > > http://bugs.kde.org/show_bug.cgi?id=99354 > > > > > ------- Additional Comments From berk inbox ru 2005-02-20 00:13 ------- > cartman can you use CGI::escape or something at least not less bug-free > instead of that ugly $query =~ s/\&/\%26/g ? Ok, will check that.
CVS commit by cartman: Use CGI::escape CCBUG:99354 M +4 -3 google 1.8 --- kdeextragear-2/konversation/scripts/google #1.7:1.8 @@ -5,4 +5,5 @@ use warnings; use Getopt::Long; +use CGI qw(:standard); my $PORT=shift; @@ -51,5 +52,5 @@ { $query = join(" ",@ARGV); - $query =~ s/\&/\%26/g; + $query = CGI::escape($query); $url="http://www.google.com/search?q=$query"; exec 'kfmclient','openURL',$url; @@ -58,7 +59,6 @@ { $search = join(" ",$search,@ARGV); - system 'dcop', $PORT, 'Konversation', 'info', "Searching Google for \x02$search\x02 ..."; - + $googleSearch = SOAP::Lite->service("http://api.google.com/GoogleSearch.wsdl"); $result = $googleSearch->doGoogleSearch($key, $search, 0, 10, "false", "", "false", "", "UTF-8", "UTF-8"); @@ -84,4 +84,5 @@ { $spellcheck = join(" ",$spellcheck,@ARGV); + system 'dcop', $PORT, 'Konversation', 'info', "Spellchecking \x02$spellcheck\x02 ..."; $googleSearch = SOAP::Lite->service("http://api.google.com/GoogleSearch.wsdl");
A scripts/google [License: Trivialfile.] commit 551c7d287bd905882c9310c4fdc00c9a67ed992d Author: İsmail Dönmez <ismail@kde.org> Date: Sat Feb 19 09:38:55 2005 +0000 A google script. Launches konqueror with google search url.Try /google kde BUG:99354 FEATURE: svn path=/trunk/kdeextragear-2/konversation/; revision=390828 diff --git a/scripts/Makefile.am b/scripts/Makefile.am index dc15c2c..af63141 100644 --- a/scripts/Makefile.am +++ b/scripts/Makefile.am @@ -1,4 +1,4 @@ scriptsdir=$(kde_datadir)/konversation/scripts -scripts_SCRIPTS=bug fortune gauge uptime kdeversion cmd sayclip weather colorizer sysinfo media mail +scripts_SCRIPTS=bug fortune gauge uptime kdeversion cmd sayclip weather colorizer sysinfo media mail google scripts_DATA=fortunes.dat diff --git a/scripts/google b/scripts/google new file mode 100755 index 0000000..af902ee --- /dev/null +++ b/scripts/google @@ -0,0 +1,22 @@ +#!/usr/bin/env perl +# +# Copyright (C) 2004 by İsmail Dönmez +# Licensed under GPL v2 or later at your option + +use warnings; +use strict; + +my $PORT= shift; +shift; +shift; +my $url="http://www.google.com/search?q="; + +if(!@ARGV) +{ + exec 'dcop', $PORT, 'Konversation', 'error', 'Please provide a query, e.g /google linux'; +} +else +{ + $url="$url@ARGV"; + exec 'kfmclient','openURL',$url; +}
commit 018ed4cbc8abb07e2a010db297515c8cc3ccac16 Author: İsmail Dönmez <ismail@kde.org> Date: Sat Feb 19 14:05:04 2005 +0000 A better google script using Google SOAP api. You need to get a license key from http://api.google.com/createkey and put it in ~/.googlekey .Here is the sample usage: /google (-s) foo # Searches for foo and displays top 10 results /google -s|--spell foo # Spellcheck foo using Google /google -b|--browser foo # Launch konqueror and show google search page for foo TODO: Handle errors: Soap exceptions,Non-existent license,no results etc Queries containing & doesn't seem to work CCBUG:99354 FEATURE: svn path=/trunk/kdeextragear-2/konversation/; revision=390904 diff --git a/scripts/google b/scripts/google index af902ee..2107bdb 100755 --- a/scripts/google +++ b/scripts/google @@ -1,22 +1,59 @@ #!/usr/bin/env perl -# -# Copyright (C) 2004 by İsmail Dönmez -# Licensed under GPL v2 or later at your option use warnings; -use strict; +use SOAP::Lite; +use Getopt::Long; + +my $PORT=shift; +my $SERVER=shift; +my $TARGET=shift; +my $key=`cat ~/.googlekey`; +my $googleSearch; +my $result; +my $print; +my $spell; -my $PORT= shift; -shift; -shift; -my $url="http://www.google.com/search?q="; +GetOptions('search=s' => \$search, + 'spell=s' => \$spellcheck, + 'browser' => \$browser); -if(!@ARGV) +if(!$browser && !$search && !$spellcheck && !@ARGV) { - exec 'dcop', $PORT, 'Konversation', 'error', 'Please provide a query, e.g /google linux'; + $info = "/google (-s) <keyword> : Search for keyword at Google, /google -s|--spell <word> : Spellcheck word using Google, /google -b <keyword> : Show results in konqueror"; + exec 'dcop', $PORT, 'Konversation', 'info', $info; } -else +elsif($browser) { - $url="$url@ARGV"; + $query = join(" ",@ARGV); + $query =~ s/\&/\%26/g; + $url="http://www.google.com/search?q=$query"; exec 'kfmclient','openURL',$url; } +elsif($search || !$spellcheck) +{ + $search = join(" ",$search,@ARGV); + + system 'dcop', $PORT, 'Konversation', 'say', $SERVER, $TARGET, "Searching Google for %B$search%B ..."; + + $googleSearch = SOAP::Lite->service("http://api.google.com/GoogleSearch.wsdl"); + $result = $googleSearch->doGoogleSearch($key, $search, 0, 10, "false", "", "false", "", "UTF-8", "UTF-8"); + + system 'dcop', $PORT, 'Konversation', 'say', $SERVER, $TARGET, "Results %B1-10%B of about %B$result->{estimatedTotalResultsCount}%B for %B$search%B (%B$result->{searchTime}%B seconds)"; + + foreach $result (@{$result->{resultElements}}) + { + $print = $result->{URL}." (".$result->{title}.")"; + $print =~ s/\<b\>/\%B/g; + $print =~ s/\<\/b\>/\%B/g; + system 'dcop', $PORT, 'Konversation', 'say', $SERVER, $TARGET, $print; + } +} +elsif($spellcheck) +{ + $spellcheck = join(" ",$spellcheck,@ARGV); + system 'dcop', $PORT, 'Konversation', 'say', $SERVER, $TARGET,"Spellchecking %B$spellcheck%B ..."; + $googleSearch = SOAP::Lite->service("http://api.google.com/GoogleSearch.wsdl"); + $spell = $googleSearch->doSpellingSuggestion($key, $spellcheck); + $spell = "Spelling suggestion: ".$spell; + system 'dcop', $PORT, 'Konversation', 'say', $SERVER, $TARGET,$spell; +}
commit e4d9fec745a67c67bf38fa0f195f85a62fa5b7f0 Author: İsmail Dönmez <ismail@kde.org> Date: Sun Feb 20 07:37:27 2005 +0000 Use CGI::escape CCBUG:99354 svn path=/trunk/kdeextragear-2/konversation/; revision=391162 diff --git a/scripts/google b/scripts/google index 83a9837..9450259 100755 --- a/scripts/google +++ b/scripts/google @@ -4,6 +4,7 @@ use warnings; use Getopt::Long; +use CGI qw(:standard); my $PORT=shift; my $SERVER=shift; @@ -50,16 +51,15 @@ else elsif($browser) { $query = join(" ",@ARGV); - $query =~ s/\&/\%26/g; + $query = CGI::escape($query); $url="http://www.google.com/search?q=$query"; exec 'kfmclient','openURL',$url; } elsif($search || !$spellcheck) { $search = join(" ",$search,@ARGV); - system 'dcop', $PORT, 'Konversation', 'info', "Searching Google for \x02$search\x02 ..."; - + $googleSearch = SOAP::Lite->service("http://api.google.com/GoogleSearch.wsdl"); $result = $googleSearch->doGoogleSearch($key, $search, 0, 10, "false", "", "false", "", "UTF-8", "UTF-8"); @@ -83,6 +83,7 @@ else elsif($spellcheck) { $spellcheck = join(" ",$spellcheck,@ARGV); + system 'dcop', $PORT, 'Konversation', 'info', "Spellchecking \x02$spellcheck\x02 ..."; $googleSearch = SOAP::Lite->service("http://api.google.com/GoogleSearch.wsdl"); $spell = $googleSearch->doSpellingSuggestion($key, $spellcheck);