Bug 99354 - Googling from the input box
Summary: Googling from the input box
Status: RESOLVED FIXED
Alias: None
Product: konversation
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: FreeBSD Ports Linux
: NOR wishlist
Target Milestone: ---
Assignee: Konversation Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-02-14 14:42 UTC by Michiel Overtoom
Modified: 2010-07-01 15:59 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michiel Overtoom 2005-02-14 14:42:10 UTC
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;
  }
Comment 1 Ismail Donmez 2005-02-19 10:38:59 UTC
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
 


Comment 2 Ismail Donmez 2005-02-19 15:05:14 UTC
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;
+}


Comment 3 Stanislav Karchebny 2005-02-20 00:13:53 UTC
cartman can you use CGI::escape or something at least not less bug-free instead of that ugly $query =~ s/\&/\%26/g ?
Comment 4 Ismail Donmez 2005-02-20 08:18:55 UTC
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.

Comment 5 Ismail Donmez 2005-02-20 08:37:33 UTC
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"); 


Comment 6 Ismail Donmez 2010-07-01 15:59:22 UTC
	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;
+}
Comment 7 Ismail Donmez 2010-07-01 15:59:23 UTC
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;
+}
Comment 8 Ismail Donmez 2010-07-01 15:59:34 UTC
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);