Wednesday, June 24, 2009

Google Picasa Photos Sample

Now it's time for Google Picasa. You may be wondering why in the hell am I working on Data API's. Well my idea is to integrate these modules with my Clutter Application launcher. First thing I have to do is to get these module to work in Linux using mono and then comup with an IPC to share info between Mono App and Clutter Application Launcher so that I can display info fetched from Google Servers. This is going to take some time. I will post a video here once I am done with it. For now have fun with the code snippet below.





using System;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;

using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.Photos;
using Google.GData.Extensions.Location;
using System.IO;

namespace GooglePicasaPhotos
{
class Program
{
static void Main(string[] args)
{
GetPicasaPhotos();
}

static void GetPicasaPhotos()
{
PicasaService Service = new PicasaService("GooglePicasaPhotos");
Service.setUserCredentials("mail-id@gmail.com", "password");

AlbumQuery Query = new AlbumQuery(PicasaQuery.CreatePicasaUri("mail-id@gmail.com"));
PicasaFeed Feed = Service.Query(Query);

foreach (PicasaEntry Entry in Feed.Entries)
{
AlbumAccessor AA = new AlbumAccessor(Entry);
Console.WriteLine("Album Title : " + AA.AlbumTitle);
Console.WriteLine("No of Photos : " + AA.NumPhotos.ToString());

Stream stream = Service.Query(new Uri(Entry.Media.Thumbnails[0].Url.ToString()));
Bitmap bitmap = new Bitmap(stream);
System.IO.Directory.CreateDirectory(AA.AlbumTitle);
bitmap.Save(AA.AlbumTitle + "\\" + "Album Thumbnail.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);

PhotoQuery PhotoQuery = new PhotoQuery(Entry.FeedUri.ToString());
PicasaFeed PhotoFeed = Service.Query(PhotoQuery);

foreach (PicasaEntry PhotoEntry in PhotoFeed.Entries)
{
PhotoAccessor PAA = new PhotoAccessor(PhotoEntry);
Console.WriteLine("Photo Title : " + PAA.PhotoTitle);

for (int i = 0; i < PhotoEntry.Media.Thumbnails.Count; i++)
{
Console.WriteLine("Width = " + PhotoEntry.Media.Thumbnails[i].Width + " Height = " + PhotoEntry.Media.Thumbnails[i].Height);
}
Stream pstream = Service.Query(new Uri(PhotoEntry.Media.Thumbnails[0].Url.ToString()));
Bitmap pbitmap = new Bitmap(pstream);
pbitmap.Save(AA.AlbumTitle + "\\" + PAA.PhotoTitle, System.Drawing.Imaging.ImageFormat.Jpeg);

}
}

Console.WriteLine("\n\n");
}
}
}



Google Calender Events Sample

Google Contacts was my first experiment with Google Data API. So I thought why not try out Google Calender Events. I started working on my app to fetch Calender Events from Google Servers and finally got it to work after spending lot of time experimenting wih the code. Next is Google Picasa Photos. I will post the code snippet in my next post.





using System;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;

using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.Calendar;

namespace GoogleCalenderEvents
{
class Program
{
static void Main(string[] args)
{
GetCalenderEvents();
}

static void GetCalenderEvents()
{
// Create a CalenderService and authenticate
CalendarService myService = new CalendarService("GoogleCalenderEventsCom-GoogleCalenderEventsApp-1");
myService.setUserCredentials("email-id", "password");

// Create the query object:
EventQuery eventquery = new EventQuery();
eventquery.Uri = new Uri("http://www.google.com/calendar/feeds/mail-id@gmail.com/private/full");

// Tell the service to query:
EventFeed calFeed = myService.Query(eventquery);

foreach (EventEntry entry in calFeed.Entries)
{
Console.WriteLine("Title : " + entry.Title.Text);
Console.WriteLine("Locations : " + entry.Locations[0].ValueString);
Console.WriteLine("Start Date: " + entry.Times[0].StartTime.ToShortDateString());
Console.WriteLine("Start Time: " + entry.Times[0].StartTime.ToShortTimeString());
Console.WriteLine("End Date: " + entry.Times[0].EndTime.ToShortDateString());
Console.WriteLine("End Time: " + entry.Times[0].EndTime.ToShortTimeString());

for (int i = 0; i < entry.Participants.Count; i++)
{
Console.WriteLine("Participant : " + i + " : " + entry.Participants[i].ValueString);
}

Console.WriteLine("\n\n");
}
}
}
}



Google Contacts Sample

From past few days I have been experimenting with Google Data API's to come up with modules to fetch Contacts from Google Servers. After spending couple of hours reading documents from Google, I finaly figured out how to get the module working. So to make things easier for people looking for some sample I am Posting my code here. So kickstart you work with the snippet below.





using System;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;

using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.Contacts;
using Google.Contacts;

namespace GoogleContacts
{
class Program
{
static void Main(string[] args)
{
GetContacts();
}

static void GetContacts()
{
ContactsService CntService = new ContactsService("GoogleContactsCom-GoogleContactsApp-1");
CntService.setUserCredentials("mail-id@gmail.com", "password");

ContactsQuery CntQuery = new ContactsQuery();
CntQuery.Uri = new Uri("http://www.google.com/m8/feeds/contacts/mail-id@gmail.com/full");

ContactsFeed CntFeed = CntService.Query(CntQuery);

foreach (ContactEntry CE in CntFeed.Entries)
{
Console.WriteLine("Name : " + CE.Title.Text);

for (int i = 0; i < CE.IMs.Count; i++)
{
Console.WriteLine("IMs : " + i + " : " + CE.IMs[i].Value);
}

for (int i = 0; i < CE.Organizations.Count; i++)
{
Console.WriteLine("Orgs : " + i + " : " + CE.Organizations[i].Title.ToString());
}

for (int i = 0; i < CE.Phonenumbers.Count; i++)
{
Console.WriteLine("Ph No : " + i + " : " + CE.Phonenumbers[i].Value);
}

for (int i = 0; i < CE.PostalAddresses.Count; i++)
{
Console.WriteLine("Addr : " + i + " : " + CE.PostalAddresses[i].Value);
}

if (CE.PrimaryEmail != null)
Console.WriteLine("Primary EMail : " + CE.PrimaryEmail.Address);

if (CE.PrimaryIMAddress != null)
Console.WriteLine("Primary IM : " + CE.PrimaryIMAddress.Value);

if (CE.PrimaryPhonenumber != null)
Console.WriteLine("Primary Ph No : " + CE.PrimaryPhonenumber.Value);

if (CE.PrimaryPostalAddress != null)
Console.WriteLine("Primary Postal Addr : " + CE.PrimaryPostalAddress.Value);

Console.WriteLine("\n\n");
}
}
}


}

Wednesday, June 17, 2009

Clutter Muti-Tab Web Browser

This is fully functional web browser developed uing clutter and webkit. Supports multiple tabs. supports basic features like Home, Back, Forward, Create New Tab, Close Selected Tab and Find. Find automatically seaches for the text match in forward direction.

Wednesday, June 10, 2009

Clutter Surface Implementation - Part 1

This is one part of the surface implementation developed using clutter toolkit.

Clutter Cover Flow Demo

This is a cover flow implementation developed using clutter toolkit.

Wednesday, May 6, 2009

Clutter Box2D OpenGL Physics Demo

This is a Demo application written using Clutter and Box2D.


Take a look at the logic used to develope this program:

1) Create a default Stage
2) Set the Stage size to desired resolution
4) Now create a Physics container and add it to the Stage
3) Create Two Clutter Texture Actors and add them to the Physics container
4) Now create four Clutter Rectangles
5) These four rectangles will be places on four corners of the Physics container
6) For rectangle placed left and right side of the Physics container, set the width to 5 pixels and height to Y Resolution
7) For rectangle placed at Top and Bottom of the Physics container, set the width to X Resolution and height to 5 pixels
8) Now using the Clutter Box2D api set the four rectangles property as Static bodies
9) Set the two Clutter Texture Actor's property as Dynamic body
10) Now Start the Physics Simulation using the Clutter Box2D api

This completes the logic for the above program. You can extend this simple logic to create fancy application with physics making them look more realistic.

Source code for the application demonstarted in the video above is given below. You can use this application source code for any purpose whatsoever.



//gcc -Wall -g Phy.c -o Phy `pkg-config clutter-0.8 clutter-box2d-0.8 --cflags -libs`

#include "clutter.h"
#include "clutter-box2d.h"

#define XRESOLUTION 640
#define YRESOLUTION 480

gint main(gint argc, gchar **argv)
{
ClutterActor *Stage;
ClutterActor *PhyStage;
ClutterActor *StaticActor;
ClutterActor *DynamicActor;
ClutterActor *Top;
ClutterActor *Bottom;
ClutterActor *Left;
ClutterActor *Right;
ClutterColor black = {0x33, 0x33, 0x33, 0xff};
ClutterVertex Gravity = {0.0,0.0};
GError *Error;

clutter_init(&argc,&argv);

Stage = clutter_stage_get_default();
clutter_actor_set_size(Stage,XRESOLUTION,YRESOLUTION);
clutter_actor_show(Stage);

PhyStage = clutter_box2d_new();

Error = NULL;
StaticActor = clutter_texture_new_from_file("Ball1.png",&Error);
if(StaticActor == NULL)
{
g_print("%s : %d\n",__FUNCTION__,__LINE__);
exit(0);
}

clutter_actor_set_position(StaticActor,10,10);

Error = NULL;
DynamicActor = clutter_texture_new_from_file("Ball2.png",&Error);
if(DynamicActor == NULL)
{
g_print("%s : %d\n",__FUNCTION__,__LINE__);
exit(0);
}

clutter_actor_set_position(DynamicActor,10,100);

clutter_container_add_actor (CLUTTER_CONTAINER (Stage), PhyStage);
//g_object_set (PhyStage, "gravity", &Gravity, NULL);


Top = clutter_rectangle_new_with_color (&black);
clutter_actor_set_size(Top,XRESOLUTION,5);
clutter_actor_set_position(Top,0,5);

Bottom = clutter_rectangle_new_with_color (&black);
clutter_actor_set_size(Bottom,XRESOLUTION,5);
clutter_actor_set_position(Bottom,0,YRESOLUTION-10);

Left = clutter_rectangle_new_with_color (&black);
clutter_actor_set_size(Left,5,YRESOLUTION);
clutter_actor_set_position(Left,5,0);

Right = clutter_rectangle_new_with_color (&black);
clutter_actor_set_size(Right,5,YRESOLUTION);
clutter_actor_set_position(Right,XRESOLUTION-10,0);

clutter_group_add_many(CLUTTER_GROUP(PhyStage),Bottom,Right,Top,Left,NULL);
clutter_group_add_many(CLUTTER_GROUP(PhyStage),StaticActor,DynamicActor,NULL);

clutter_container_child_set(CLUTTER_CONTAINER(PhyStage),Right,"mode",CLUTTER_BOX2D_STATIC,NULL);
clutter_container_child_set(CLUTTER_CONTAINER(PhyStage),Bottom,"mode",CLUTTER_BOX2D_STATIC,NULL);
clutter_container_child_set(CLUTTER_CONTAINER(PhyStage),Top,"mode",CLUTTER_BOX2D_STATIC,NULL);
clutter_container_child_set(CLUTTER_CONTAINER(PhyStage),Left,"mode",CLUTTER_BOX2D_STATIC,NULL);

clutter_container_child_set(CLUTTER_CONTAINER(PhyStage),StaticActor,"manipulatable",TRUE,"mode",CLUTTER_BOX2D_DYNAMIC,NULL);
clutter_container_child_set(CLUTTER_CONTAINER(PhyStage),DynamicActor,"manipulatable",TRUE,"mode",CLUTTER_BOX2D_DYNAMIC,NULL);

clutter_box2d_set_simulating(CLUTTER_BOX2D(PhyStage),TRUE);

clutter_main();

return 0;

}