Google Talk Status Countdown

A few days ago I was counting down to a presentation in my faculty. As I was setting counters all over my world (Side Bar Gadget, To Do List) I thought of a way to change my Google Talk status to a counter also.
Since I know that Google Talk uses XMPP protocol, and since my friends and I implemented XMPP last year in our faculty I tried to make a program to set my status to a counter; and here is the result:
XMPP Status Changer

The basic idea behind status changing

Since Google Talk uses XMPP then if you can connect using an XMPP client to your Google account you can use the client instead of Google talk. But indeed that’s not what we want here, we want to use Google Talk while changing the status automatically.
I searched to see if there were an API to communicate with Google Talk from any other program but I had no luck.
So the solution was to use XMPP’s Presence Priority attribute.
In XMPP, a user can connect from multiple clients with the same ID, each client will have a unique resource so messages sent from one client get their replies to the same client. But what about status? XMPP has an attribute sent with each status (Status is called Presence in XMPP) which is Priority, this attribute describes the priority of this resource presence. In Google Talk the highest priority is 24. So if you can change the priority of the automatic presence to 24 it will be considered high priority and its status will appear instead of the old one.

Programming it

I used Java for developing the program. There is no direct reason for using Java but that’s what I used :)
To be able to use XMPP I used the Smack XMPP Library because it is simple and serves me well.
The whole mechanism is too simple:

  1. Login.
  2. Calculate difference between now and the targeted date.
  3. Send the presence.

Using Smack makes the whole process so easy.

Login

Calculate difference between now and the targeted date

This process is done using Java Calendar and Date objects:

This code calculates the difference between the two dates in days, hours and minutes.

Send the presence

After calculating the difference all we have to do is to send the presence:

After this point people will see your new status instead of the one in Google Talk. (Notice that you won’t be able to see the change inside Google Talk but rest assured it is changed ;)).

Testing

XMPP Status Changer Test

Last note

The GUI is self explanatory, just make sure you enter a big value for “Update Interval” because when you’re talking to others and your status changes they’ll have a red line with the new status in the conversation window and certainly you don’t want them to be distracted by the counter from the real conversation.

And BTW, you can use this program with any XMPP account, not just Google Talk. And it’s cross platform 😉

Download

Google Talk Status Countdown on GitHub
Smack library is attached to the files already, no need to download it separately.

Hope you use it :)

19 thoughts on “Google Talk Status Countdown

  1. PBUY friend,

    There is no need to talk about wonderfulness because it already seems clearly.

    Hope you get in future the better and better and then better 😛 and finally better than what’s supposed to.
    it’s so nice project.

    regards
    -Eyad


  2. marc:

    i still cant understand what does this do? does it auto change ur status based on a schedule?

    It changes your status periodically to reflect a counter to a given event, see the testing image for an example.

  3. HI,

    GTalk Client desktop and GTalk Android Client, both set the priority to 24. Do you think that it is possible to set the priority for the Android GTalk to be always inferior to the GTalk desktop app, in a way similar to what you have done??

    Regrds,
    Andre


  4. André:

    HI,

    GTalk Client desktop and GTalk Android Client, both set the priority to 24. Do you think that it is possible to set the priority for the Android GTalk to be always inferior to the GTalk desktop app, in a way similar to what you have done??

    Regrds,
    Andre

    Hmmm, using my way you can override the presence message by sending another one with the same priority, but I don’t think that using the same method above you can lower the presence priority of another client.
    To do so you should listen to the port that the client is using to connect to the server and change the presence priority when you recognize it. Not as easy as the method above but can work certainly.

    :)

  5. Hi,

    I tried to set the message using this utility but nothing happens on clicking ‘Set Values & Start’ button.

    I logged in successfully and it shows the status as connected on login button click.
    Can anybody please help and provide the inputs…??

    Thanks
    Shalabh Dixit


  6. Shalabh Dixit:

    Hi,

    I tried to set the message using this utility but nothing happens on clicking ‘Set Values & Start’ button.

    I logged in successfully and it shows the status as connected on login button click.
    Can anybody please help and provide the inputs…??

    Thanks
    Shalabh Dixit

    Sorry for the late response but I was on a vacation;
    If the program didn’t show an error message then it is working, and I mentioned before that you can’t see if it is really working unless you check it from another account :)

  7. I have a proxy set in google talk, have you considered improving this to allow a proxy to be used?

    I would like to use this to set my status message while I am in the office. So I don’t need an update interval, I would just like to set it to clear my at office message at say 17.30.

  8. Aslam o Alaykum Diab!

    Well as you mentioned in the post, I tried this code. But it’s not updating GTalk status nor it giving any exception. Run perfect.

    XMPPConnection connection = new XMPPConnection("gmail.com"); //Server is gmail.com for Google Talk.        connection.connect();        connection.login("mygmailid@gmail.com", "mypassword"); //Username and password.                    Presence p = new Presence(Presence.Type.available);        p.setStatus("MY STATUS");        p.setPriority(24); //Highest priority in Google Talk        p.setMode(Presence.Mode.available); //This is one of XMPP modes (Available, Chat, DND, Away, XA).        connection.sendPacket(p);

    Please help what should I do to just programmaticaly update GTalk status.

    Thanks in advance.

    1. Wa Alaikom Al Salam,
      This code works, and it does changes the GTalk status, but as I said in the post, you won’t notice the change from the GTalk interface, if you wanna make sure it is changed ask one of your friends to tell you your status, you can ask me if you want an image to prevent spam 😉

  9. Hi- I can’t log in..am i doing something wrong? I downloaded and extracted the 2 files….and opened the interface and tried to log in..but it just keeps saying Not Connected

    1. Are you sure it doesn’t even become “Connecting …”? If it encounters an error while connecting it displays a message with the error, and that’s while saying “Connecting …”.

    1. After I read your code and done some tests I decided not to include your method in my solution, not that your method is wrong or something, but I don’t want to change the shared status, since it’d be changing periodically. And by changing the shared status any services connected to the status will get notified (e.g. Google Buzz) and it’d be annoying to have a notification every time the status changes.

      Thanks for your code, it helped me do another thing not related to this post 😉

  10. hi- I am using your code and it’s working fine but when i closed the app the status message set to previous one, how can we set status message permanently like gtalk sets. please give me some inputs that how to set status message permanently.

    1. My code is not designed to save the status, since the status will be changing frequently, if you want to set a static status message you can set it using Google Talk, or if you want to set it in code you can check Gaby’s reply here which contains such code.

Leave a Reply