Click here to Skip to main content
15,884,177 members
Articles / Programming Languages / C#

A google search application using Gtk#

Rate me:
Please Sign up or sign in to vote.
4.49/5 (17 votes)
14 Jan 20058 min read 174.9K   1.1K   46  
An application (based on Gtk#) which uses the google web service to search the internet.
  • googlesearch_demo.zip
    • googleSearch
      • bin
        • Debug
          • googleSearch.exe
          • googleSearch.pdb
        • Release
          • googleSearch.exe
      • googleSearch.csproj
      • googleSearch.csproj.user
      • googlesearch.glade
      • googlesearch.glade.bak
      • googlesearch.gladep
      • googlesearch.gladep.bak
      • googleSearch.sln
      • googleSearch.suo
      • GtkApp.cs
      • obj
        • Debug
          • googleSearch.exe
          • googleSearch.pdb
          • googleSearch.projdata
          • googleSearch.projdata1
          • temp
          • TempPE
            • Web References.com.google.api.Reference.cs.dll
        • Release
          • googleSearch.exe
          • googleSearch.projdata
          • temp
          • TempPE
            • Web References.com.google.api.Reference.cs.dll
      • Web References
using System;
using Gtk;
using Glade;
using googleSearch.com.google.api;

namespace googleSearch
{
	/// <summary>
	/// Summary description for GtkApp.
	/// </summary>
	public class GtkApp
	{
		
		[Widget]Window mainWindow;
		[Widget]Button btnSearch;
		[Widget]Button btnClear;
		[Widget]Entry entry1;
		[Widget]TextView textview1;

		/* Main Function */
		public static void Main (string[] args)
		{
			new GtkApp (args);
		}


		public GtkApp(string []args)
		{
			Application.Init();

			Glade.XML gxml = new Glade.XML (null, "googleSearch.googlesearch.glade", "mainWindow", null);
			gxml.Autoconnect (this);
			mainWindow.DeleteEvent+=new DeleteEventHandler(mainWindow_DeleteEvent);
			btnSearch.Clicked+=new EventHandler(btnSearch_Clicked);
			btnClear.Clicked+=new EventHandler(btnClear_Clicked);
			Application.Run();
		}

		private void mainWindow_DeleteEvent(object o, DeleteEventArgs args)
		{
			Application.Quit ();
			args.RetVal = true;
		}

		private void btnSearch_Clicked(object sender, EventArgs e)
		{
			try
			{
				textview1.Buffer.Text="";

				//do search
				GoogleSearchService svc=new GoogleSearchService();
				GoogleSearchResult result=svc.doGoogleSearch("FEkTsl8kwgQtrQIeGHJDSELrTtjNcp1eC",entry1.Text,0,10,true,"",true,"","","");
			
				foreach(ResultElement re in result.resultElements)
				{
					textview1.Buffer.Text+="Title: "+re.title+"\r\n";
					textview1.Buffer.Text+="Summary: "+re.summary+"\r\n";
					textview1.Buffer.Text+="URL: "+re.URL+"\r\n";
					textview1.Buffer.Text+="==========================\r\n\r\n";
				}

			}
			catch(Exception ex)
			{
				Gtk.MessageDialog md=new MessageDialog(mainWindow,Gtk.DialogFlags.Modal,Gtk.MessageType.Error,Gtk.ButtonsType.Ok,ex.Message);
				md.Show();
			}
		}

		private void btnClear_Clicked(object sender, EventArgs e)
		{
			textview1.Buffer.Text="";
			entry1.Text="";
		}

		
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Singapore Singapore
Samir Kuthiala founded a Singapore based technology firm Innove Technologies Pte Ltd in 2002. Innove Technologies specialises in providing enterprise level .NET solutions to their clients.

Comments and Discussions