Mark Needham

Thoughts on Software Development

Archive for the ‘ipad’ tag

iPad: Getting PragProg books onto the Kindle App

with 5 comments

As I’ve mentioned previously I think the Kindle application on the iPad is the best one for reading books and as a result of that I wanted to be able to read some books which I’d bought from the PragProg store onto it.

The first step is to download the ‘.mobi’ version of the book and use iPhoneExplorer to drag the file into the ‘Kindle/Documents/eBook’ folder on the iPad.

This works fine but if you add more than one book in this way they all have the same cover image when viewed on the iPad which is quite annoying when trying to work out which book is which.

I went on a yak shaving mission to try and figure out how to solve that problem and came across a post by GRiker where he described how to set a custom cover image.

His instructions were as follows:

For example, let’s say you want to sideload WarOfTheWorlds.MOBI with its cover WarOfTheWorlds.JPG into the Kindle for iPad app:

  • Modify WarOfTheWorlds.MOBI (using Mobi2Mobi, for example), adding or modifying the ASIN field (in the EXTH block) with the name of the cover jpg, WarOfTheWorlds.JPG. (Since your sideloaded book didn’t come from Amazon, you don’t need a real ASIN.)
  • Copy the modified WarOfTheWorlds.MOBI to Kindle/Documents/eBooks (using iPhone Explorer)
  • Copy WarOfTheWorlds.JPG to Kindle/Documents/LibraryCovers (using iPhone Explorer)

I first loaded the mobi files into Calibre so that I could get the cover image by doing the following:

  • Click on the icon in the top left hand corner which looks like a book with a + sign on it
  • Add books from a single directory
  • Find the .mobi file you want to import
  • Right click on the book
  • Open containing folder

After I’d done that I needed to install ‘mobi2mobi’ in order to update the ‘ASIN’ number of the book. The Kindle application looks for a file with the same name as the ASIN number in the ‘LibraryCovers’ folder and uses that as the cover image for the book.

There are a crazy number of instructions to follow on the mobileread wiki in order to install this.

I followed these but was getting the following error when I tried to run the command:

Can't locate in @INC (@INC contains: /Users/mneedham/eBooks/tools /Library/Perl/Updates/5.10.0/darwin-thread-multi-2level /Library/Perl/Updates/5.10.0 /System/Library/Perl/5.10.0/darwin-thread-multi-2level /System/Library/Perl/5.10.0 /Library/Perl/5.10.0/darwin-thread-multi-2level /Library/Perl/5.10.0 /Network/Library/Perl/5.10.0/darwin-thread-multi-2level /Network/Library/Perl/5.10.0 /Network/Library/Perl /System/Library/Perl/Extras/5.10.0/darwin-thread-multi-2level /System/Library/Perl/Extras/5.10.0 .) at /Users/mneedham/eBooks/tools/MobiPerl/ line 23.
BEGIN failed--compilation aborted at /Users/mneedham/eBooks/tools/MobiPerl/ line 23.

I came across the following thread where pilotbob described a way to fix this:

I got it working on Snow Leopard. Here is what I did.

1. Install MacPorts… this will make it a whole lot easier.

2. Once you get ports installed use macports to install the gd lib stuff:
sudo port install gd2

This will also install perl 5.8.9… perl 5.10 comes with Snow Leopard. Not sure it any mac stuff requires that… but you can always go back, macports puts stuff in a separate location.

I also installed the following macports:


Then, I use CPAN to install the following… there didn’t seem to be any macports for them:


After that mobi2mobi ran… well it gave me the command line options. I didn’t actually try it. But, it doesn’t seem to run unless all the dependencies are there.

I tried to install all of those dependencies as he suggests although not all of them worked for me.

After I’d done that I went back to the mobileread wiki and re-ran the following commands:

sudo perl -MCPAN -e shell
install Palm::PDB
install XML::Parser::Lite::Tree
install GD
install Image::BMP
install Image::Size
install HTML::TreeBuilder
install Getopt::Mixed
install Date::Parse
install Date::Format

And after all that I was finally able to run ‘mobi2mobi’ to change the ‘ASIN’ of the file which can be done by executing the following command:

mobi2mobi --outfile --exthtype asin --exthdata "mycoverimage.jpg"

To get the Kindle application to pick up the new image I needed to be connected to the internet for some reason but all my books are showing with the correct covers now.

Written by Mark Needham

August 16th, 2010 at 7:18 am

Posted in iPad

Tagged with

iPad: Redrawing the screen

with one comment

As I mentioned in a post I wrote last week I’ve been writing a little iPad application to parse a cctray feed and then display the status of the various builds on the screen.

The way I’ve been doing this is by dynamically adding labels to the view and colouring the background of those labels red or green depending on the build status.


@interface FirstViewController : UIViewController {
	NSMutableArray *dynamicallyAddedFields;


@implementation FirstViewController
- (void)viewDidLoad {
	// parse xml and put projects into 'theDelegate.projects
	NSInteger x = 30;
	NSInteger y = 0;
	NSInteger column1 = true;
	dynamicallyAddedFields = [[NSMutableArray alloc] init];
	for(Project *project in theDelegate.projects) {		
		if(column1) {
			x = 30;
			y = y + 110;
			column1 = false;
		} else {
			x = 290;
			column1 = true;
		UILabel *aLabel	= [self createLabelFrom:project withXCoordinate:x withYCoordinate:y];
		[dynamicallyAddedFields addObject:aLabel];
		[self.view addSubview:aLabel];	
-(UILabel*) createLabelFrom:(Project *)project withXCoordinate:(NSInteger)x withYCoordinate:(NSInteger)y  {
	// code to create a label

The full code is on github and this is what the application looks like when launched in the simulator:


I’m storing each of the labels inside ‘dynamicallyAddedFields’ so that I can easily remove them and then redraw new ones with the new feed url when the user clicks on the ‘Go’ button. I saw a similar idea suggested in an iPhone Dev SDK article.

The ‘Touch Up Inside’ event of the ‘Go’ button is hooked up to the ‘changedFeedUrl’ method inside my view controller as described in Brandon Treb’s blog.

The code to handle the button being pressed is as follows:

- (IBAction) changedFeedUrl:(id) sender {		
	for (id item in dynamicallyAddedFields) {
		[item removeFromSuperview];
	[dynamicallyAddedFields removeAllObjects];	
	// parse xml and put projects into 'theDelegate.projects
	NSInteger x = 30;
	NSInteger y = 0;
	NSInteger column1 = true;
	for(Project *project in theDelegate.projects) {		
		if(column1) {
			x = 30;
			y = y + 110;
			column1 = false;
		} else {
			x = 290;
			column1 = true;
		UILabel *aLabel	= [self createLabelFrom:project withXCoordinate:x withYCoordinate:y];
		[dynamicallyAddedFields addObject:aLabel];
		[self.view addSubview: aLabel];

In order to redraw all the labels I had to first remove them all from their super view (line 3).

We then have the same code as in the ‘loadView’ method – copy and pasted for now – to add the new labels to the screen.

Although this code does what I want it is very hacky so I’d be grateful for any tips on how I can achieve the same thing in a cleaner way.

Written by Mark Needham

August 9th, 2010 at 4:38 am

Posted in iPad

Tagged with

iPad: First thoughts

with 4 comments

I’ve had the iPad for about a month now and since my colleagues Martin Fowler, Neal Ford and Chris Stevenson have already previously written about their experiences with it I thought I’d share the way I’m using it as well.


I follow a lot of people involved in software development on twitter and come across a lot of interesting articles/blogs that people link to or write. A lot of the time I don’t really want to read those posts when I come across them – it would be much better if I could just save them to read later on.

Before I had the iPad the way I did this was just by having loads of tabs open on Chrome which tended to result in my computer grinding to a halt because of the memory being consumed by having all those articles open.

On the iPad I’ve been making use of the Osfoora HD twitter client which is integrated with Instapaper – an application which allows you to save web pages and then read them offline.

I’m online most of the time so I was initially unsure how much value I’d get out of it. I now read almost every technical article I come across via Instapaper.

I’ve been posting to twitter way more because it’s now so easy to post links there which is the main way that I use it.

Reading technical material

Before I bought the iPad I wanted to make sure that I’d be able to read pdfs on it. I have a lot of technical books as pdfs and I’ve wanted to buy a device that would allow me to read those more easily since I don’t like reading pdfs on my laptop unless they’re purely coding books.

Luckily the Good Reader application allows me to do exactly that and the ability to crop the pages to be exactly how you want is fantastic and something that I’d never even thought of until I saw it.

I use Google Reader for my RSS feeds so none of the RSS reader applications really appealed to me until I came across reeder which basically sits on top of Google Reader and downloads all the unread items for offline viewing.

It’s integrated with twitter as well so I can easily post any interesting things that I read.


I’m using the Blog Press application which I’ve found to be better than the Word Press one because it allows me to cut and paste text around the post – I found that I couldn’t do this with the Word Press application.

Ben Parr has a more extensive post on his experiences blogging from the iPad but overall for me it’s still not as good as blogging from Mars Edit on the Mac.

It’s a bit of a hassle copying links into posts because you need to manually write the Html to do so which is pretty painful in itself but also because you have to keep switching to other applications to get the links in the first place.

I have been using BlogPress to quickly copy/paste any interesting quotes from the blogs that I read but more often than not I end up posting it as a draft and then tidying it up with Mars Edit later on.


Watching videos on the iPad is amazing – the picture is obviously much bigger than it would be on an iPhone and it’s much more convenient than it would be on a laptop.

I watch technical videos now and then for which the Air Video application comes in really handy. It can convert any video files you have on your computer to a format that can be watched on the iPad although there are several formats which work without conversion as well.

InfoQ and Skills Matter both frequently post technical presentations and this week NDC 2010 has made a lot of the presentations from that conference available to download.

Written by Mark Needham

June 21st, 2010 at 9:30 pm

Posted in Software Development

Tagged with