Archive for the ‘code’ Category

Programmatically making an Internet connection in Windows Mobile in C++

Tuesday, April 29th, 2008

Although a lot of people seem to be finding my Twitter widget for Windows Mobile useful, it seems that there are also a few people who noticed that it was hacked together in a few hours overnight!

One of the more noticed issues was the fact that the widget reused the mobile’s existing Internet connection.

It was described in emails such as:

Some times I have to invoke a data session with PIE or another networked app before it will let me send a twit. Anyway to make it start it’s own network session if one doesn’t already exist?

and in tweets such as

ooh i'm liking cetwit. But not you, twittoday

oh and a side note to data apps everywhere: if you want a connection, REQUEST IT YOURSELF. I have better things to do than holding your hand

The issue is that when you use the web services APIs, this is all handled for you. But I rolled my own HTTP POST code using the wininet API. And these low-level calls aren’t so helpful.

It wasn’t a problem for me, because my phone is always connected anyway. But enough people have mentioned it, so I figured it was worth looking into!

If anyone is interested in how you start a connection programmatically in C++, read on.

(more…)

HackDay – writing a Twitter dictionary

Sunday, April 27th, 2008

As I said on Friday, Friday was IBM Hackday 5. I didn’t really explain what HackDay is, but if you’re not familiar with it, Kelly has posted a good description.

I made all my excuses in my last post, so with them out of the way, here is my hack.

The idea is an old one – but I’ll summarise it again here.

The hack was to extend the twitter.com website to provide additional context for people’s tweets.

Every twitter user can maintain their own personal dictionary of terms, that describe their personal significance when they use them in tweets. When one of these terms is used in a tweet, it is highlighted in some way, and if the user hovers their mouse over them, the full description is shown in a pop-up.

For example, my twitter dictionary might include entries like:

  • Grace – my three-year old daughter
  • Faith – my baby girl
  • Hursley – IBM Hursley Park, the site where I work
  • SYA – a youth charity that I started and am now on the board of trustees for

an example - screenshot of my hack in action

The idea isn’t to say what something means (why try and replace people’s ability to use Google?) but to say what it means to the tweeter.

Other uses could include to provide ‘disclosure’. For example, when I see posts by James Governor, I often see a few lines at the end such as:

…IBM is a client. RedMonk runs Google Docs. Google and Salesforce are not clients. We don’t currently use Salesforce apps…

But in the twitter world where thoughts fit into 140 characters, there isn’t the space to include this sort of context with every tweet. So James’ twitter glossary might include entries like:

  • IBM – IBM is a client

(more…)

But, I like transcoding!

Sunday, April 20th, 2008

screenshot - Image Hosted by ImageShack.usMobile transcoding – services which turn a webpage into something better suited for a mobile web browser – is an often contentious topic. It’s a topic which has come up several times recently, and at best people will begrudgingly describe it as a necessary temporary evil.

Don’t get me wrong – it hasn’t been without problems. It has been used in inappropriate ways, and I know web-developers whose sites have been broken by poor (and inflicted!) uses of mobile transcoding.

But as a practical, day-to-day tool – I kinda like it.

I started using Google’s transcoder (GWT) because when you use the mobile version of Google’s RSS reader, any links you click on are transcoded by GWT for you. And I find it very useful.

It creates efficient pages which render well in Pocket Internet Explorer. Plus it stops my phone trying to download some ridiculously large webpages over GPRS (argh… curse web-developers who have 1MB webpages on the front of your sites!).

It also adds a link to any RSS feeds it finds in a page at the top – clicking on which will take you to the feed in Google Reader (my RSS reader of choice at the moment), from where you can subscribe to the feed. (Slightly roundabout, but the only way I know to subscribe to new feeds from Google Reader Mobile).

I like.

But it’s a bit of a faff getting a page transcoded by GWT if you aren’t already given a link to a transcoded page. So (in the tiny window between tonight’s screaming fits… gah – when will the baby start sleeping through the night?!) I added a new tool to my set of Pocket Internet Explorer (PIE) extensions: one that will re-open the current page using Google mobile transcoder.

(more…)

Capturing page loaded events from a Firefox extension

Sunday, April 6th, 2008

One of my hacks at Over The Air was an attempt to sync browser histories between desktop and mobile. A part of this was a Firefox extension which listens for when I go to a new webpage, gets the URL from the Firefox address bar and sends it to a connected mobile.

As my first attempt at a Firefox extension, I was surprised by how easy this was. I’ve made it, so if anyone wants to learn or build on it, downloading the source may be useful. (Remembering it was thrown together in a bit of a hurry!) But I wanted to highlight a couple of quick points.

Firstly – getting started. Owen pointed me at a brilliant Firefox extension wizard. Fill in the simple form – telling it stuff like whether you want to add an options dialog and preferences, or a context menu item, or a toolbar button, and so on. And it generates you a skeleton Firefox extension ready for you to fill in with code. This probably saved me an hour or two of reading about how to create Firefox extensions!

Secondly – capturing new pages. This was done by adding a listener for DOMContentLoaded events:

var appcontent = window.document.getElementById("appcontent");
appcontent.addEventListener("DOMContentLoaded", 
                            myContentLoadedFunction, 
                            false);

And in my content loaded function, I got the URL like this:

var urlbar = document.getElementById('urlbar');

Browser syncing – mobile to desktop

Saturday, April 5th, 2008

Completing the loop for my browser sync hack for Over The Air – this time, syncing back the browser history from your mobile browser when you get back to your desktop computer.

When you connect your mobile to your computer, the URL history of Pocket Internet Explorer is queried and the most recent item is opened on the desktop using your default web browser.

This was a little tricky to implement and needed me to cobble a few bits and pieces together:

  • A C# service running on the desktop that uses RAPIManager to trap and handle device connection events
    On connection, the service uses RAPI to invoke a process on the mobile…
  • The process on the mobile is something that I wrote in C++ to query the PIE cache – using the FindFirstUrlCacheEntry / FindNextUrlCacheEntry API. The URL retrieved is written to a file on the mobile.
  • The C# service on the desktop transfers the file containing the URL from the mobile, and uses Process.Start to launch it in the desktop’s default web browser

It’s a little icky… but it seems to work!

Browser syncing – desktop to mobile

Saturday, April 5th, 2008

Third of the random ideas for Over The Air hacks – a browser sync for Windows Mobile.

The aim was to let you transfer your browser history from desktop to a Windows Mobile PDA, so when you leave your desk, you can pick up where you left off in whatever you were doing online.

I’ve written the hack as a Firefox extension, and it currently has two modes:

  • Always on
    Every web page you view in Firefox gets opened on the mobile browser in the background without you noticing. When you disconnect your mobile from the computer, you not only have the most recent page all ready for you in your mobile browser, but you also have a mirror of the Firefox history – so clicking ‘Back’ on your mobile browser will take you back to the previous page you were viewing with desktop Firefox.
  • Single sync
    Take the current page you are viewing in Firefox, and open it on your mobile browser

The toggle to start/stop the ‘always on’ mode, and the switch to perform a single sync are both provided as toolbar buttons.

Install the Firefox extension here

(more…)

Data Capture widget for Windows Mobile

Friday, April 4th, 2008

Second of the random ideas for Over The Air hacks – a Data Capture widget for Windows Mobile.

Data Capture widget for Windows MobileScribble a note or capture an idea without waiting for a second or two for an app to be launched!

Enter some text in the box, then tap OK. The text will be appended to a file or Note (of your choice – specify the path it should write to in ‘Options’).

If you tap on the icon, the notes app (of your choice – again, specifying the path to it in ‘Options’) will be launched to the page the widget writes to.

Create an “incoming” or “to be sorted” note or page, and add to it throughout the day. When you’re ready, launch the notes app and go through and process what you’ve collected.

Very GTD. 🙂

It’s a lightweight C++ app, reusing a lot of the code from the Twitter client I posted about earlier.

Download a copy here
To specify paths, go to the Options dialog for “bLADE Wiki Today” from the Today screen control panel applet.

Twitter for Windows Mobile

Friday, April 4th, 2008

First of the random ideas for Over The Air hacks – a Twitter client for Windows Mobile.

Twitter client for Windows MobileWhen posting a tweet, the key is speed. I don’t want to wait to launch an app, I don’t want lots of features. I just want something to take my message and post it.

When reading tweets, I don’t mind waiting (e.g. for the list to be gathered).

And on mobile, I don’t really want regular notifications or polling. Following over a hundred people, I’d either hose my phone battery by constantly getting updates, or I’d miss most updates anyway. I just need to be able to see a list of updates when I want.

I went for a Today screen widget for posting, written in C++ to keep it quick and lightweight.
And if you click on the twitter logo, it launches your default browser at the mobile Twitter site http://m.twitter.com/. The best of both worlds 🙂

Download a copy here
To set your username and password, go to the Options dialog for “Twit Today” from the Today screen control panel applet.

(more…)