How to Create a Remote Paging Listview Using GWT-Ext

24Jul08

Creating a remote paging listview isn’t particularly difficult but getting to the point of knowing how all the pieces fit together can be tricky first time round. This post describes how I created a very simple remote paging listview that retrieves each page of data from an Oracle database table. As well as describing the listview I’ve also included the code for the server side that actually fetches and returns each page of data to the client.

Deploying GWT-Ext
If you’ve not used GWT-Ext before then here’s how to include it in your GWT application. First you’ll need to download GWT-Ext itself. At the time of writing 2.0.4 is the latest release, you can get it here. The real workhorse behind GWT-Ext is the Javascript library ExtJS. GWT-Ext 2.0.4 requires ExtJS 2.0.2 which you can download from here.

If you don’t already have a GWT application then GWT’s The Basics guide is a good place to start.

With your application up and running here are the steps required to deploy GWT-Ext within it.

1. Create the directory js/ext under your application’s public folder and copy the following files and directories from ExtJS into it,

 /adapter
 /resources
 ext-all.js
 ext-all-debug.js
 ext-core.js
 ext-core-debug.js

2. Edit your module file and add these lines to it,

  <inherits name='com.gwtext.GwtExt'/>
  <stylesheet src="js/ext/resources/css/ext-all.css"/>
  <script src="js/ext/adapter/ext/ext-base.js" />
  <script src="js/ext/ext-all.js" />

3. The final step it to add the GWT-Ext jar, gwtext.jar, to your application’s classpath.

The Client Side Code
GWT-Ext refers to a listview as a Grid so to avoid confusion I’ll use that term throughout the rest of this post. I used the term listview up to this point because it’s probably a more generally accepted description.

Before going into the code it’s worth spending a little time understanding the various objects that are needed to support the Grid object. The first thing worth pointing out is that GWT-Ext doesn’t use standard GWT Remote Procedure Calls to fetch the data needed in the Grid. What you do instead is provide it with a HTTP URL from which to retrieve the data. To do this you use a DataProxy object. There are three types of DataProxy, the HttpProxy, the MemoryProxy and the ScriptTagProxy. The MemoryProxy is just a static in memory data source and the ScriptTagProxy is the same as HttpProxy except that it retrieves data from a site other than the one where your Grid is hosted. So what format should the data coming back from this URL be in? Two formats are supported, JSON and XML. In order to understand the structure of this JSON or XML we need to use a RecordDef. This object contains FieldDef objects each of which describe a particular field in the data feed. Once you’ve described you data structure using a RecordDef you create either a JsonReader or an XmlReader and give it a reference to your RecordDef. Finally, to tie all these objects together you create a Store. The Store is the object you present to the Grid. It uses the DataProxy to retrieve the data and and the Reader to parse it.

With the Store defined we can turn our attention to the Grid. To define what columns the Grid should have and where the data for each column should come from we use a ColumnModel object. This object contains a number of ColumnConfig objects, one for each column. A ColumnConfig contains the column title, the name of the record in the RecordDef to populate the column with, it’s width, weather it’s sortable and how the data should be rendered. To create the Grid itself we use the GridPanel object. You can link it to the Store and ColumnModel using either the constructor or the setter methods.

The final point to note is that you’ll need to add an onRender event handler to the Grid so that the first page of data is loaded when the Grid is displayed.

Bringing all that together here’s the class I ended up with,


package com._17od.gwtexamples.client;

import java.util.Date;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.RootPanel;
import com.gwtext.client.core.SortDir;
import com.gwtext.client.data.DateFieldDef;
import com.gwtext.client.data.FieldDef;
import com.gwtext.client.data.HttpProxy;
import com.gwtext.client.data.IntegerFieldDef;
import com.gwtext.client.data.JsonReader;
import com.gwtext.client.data.Record;
import com.gwtext.client.data.RecordDef;
import com.gwtext.client.data.Store;
import com.gwtext.client.data.StringFieldDef;
import com.gwtext.client.util.DateUtil;
import com.gwtext.client.widgets.Component;
import com.gwtext.client.widgets.PagingToolbar;
import com.gwtext.client.widgets.Panel;
import com.gwtext.client.widgets.event.PanelListenerAdapter;
import com.gwtext.client.widgets.grid.CellMetadata;
import com.gwtext.client.widgets.grid.ColumnConfig;
import com.gwtext.client.widgets.grid.ColumnModel;
import com.gwtext.client.widgets.grid.GridPanel;
import com.gwtext.client.widgets.grid.GridView;
import com.gwtext.client.widgets.grid.Renderer;
import com.gwtext.client.widgets.grid.RowSelectionModel;

public class PersonGrid implements EntryPoint {

	public void onModuleLoad() {

		Panel panel = new Panel();
		panel.setBorder(false);
		panel.setPaddings(15);

		HttpProxy dataProxy = new HttpProxy("http://localhost:8888/persons");

        final RecordDef recordDef = new RecordDef(new FieldDef[]{
                new StringFieldDef("class"),
                new DateFieldDef("dateOfBirth", "Y-m-d"),
                new StringFieldDef("firstname"),
                new IntegerFieldDef("id"),
                new StringFieldDef("lastname"),
        });

        JsonReader reader = new JsonReader(recordDef);
        reader.setRoot("persons");
        reader.setTotalProperty("totalPerons");
        reader.setId("id");

        final Store store = new Store(dataProxy, reader, true);
        store.setDefaultSort("id", SortDir.ASC);

        ColumnConfig firstNameColumn = new ColumnConfig("First Name", "firstname", 45, true);
        ColumnConfig lastNameColumn = new ColumnConfig("Last Name", "lastname", 45, true);
        ColumnConfig dateOfBirthColumn = new ColumnConfig("Date of Birth", "dateOfBirth", 45, true, dateRender);

        ColumnModel columnModel = new ColumnModel(new ColumnConfig[] {
        		firstNameColumn,
        		lastNameColumn,
        		dateOfBirthColumn});
        columnModel.setDefaultSortable(true);

        GridPanel grid = new GridPanel();
        grid.setWidth(700);
        grid.setHeight(300);
        grid.setTitle("People");
        grid.setStore(store);
        grid.setColumnModel(columnModel);
        grid.setTrackMouseOver(true);
        grid.setLoadMask(true);
        grid.setSelectionModel(new RowSelectionModel());
        grid.setStripeRows(true);
        grid.setIconCls("grid-icon");
        grid.setEnableColumnResize(true);

        GridView view = new GridView();
        view.setForceFit(true);
        grid.setView(view);

        PagingToolbar pagingToolbar = new PagingToolbar(store);
        pagingToolbar.setPageSize(15);
        pagingToolbar.setDisplayInfo(true);

        grid.setBottomToolbar(pagingToolbar);

        grid.addListener(new PanelListenerAdapter() {
            public void onRender(Component component) {
                store.load(0, 15);
            }
        });
        panel.add(grid);

        RootPanel.get().add(panel);

  	}

    private Renderer dateRender = new Renderer() {
        public String render(Object value, CellMetadata cellMetadata, Record record, int rowIndex, int colNum, Store store) {
            return DateUtil.format((Date) value, "d-m-Y");
        }
    };

}

Where Does the Data Come From?
The code below is the servlet I developed to return each page of data to the Grid. It retrieves the data from an Oracle database table called “person”. It’s not particularly complicated but it does demonstrate some challenges that are worth pointing out.


package com._17od.gwtexamples.servlets;

import java.io.IOException;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Enumeration;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import oracle.jdbc.pool.OracleDataSource;

import org.json.JSONArray;
import org.json.JSONObject;

public class GetPersonsServlet extends HttpServlet {

	private Connection connection;

	public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
		doPost(req, res);
	}

	public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException {

		// Display the parameters we're passed in for debugging purposes
		printParameters(req);

		// Get the limit and sort parameters off the request
		int start = req.getParameter("start") == null ? 1 : Integer.parseInt(req.getParameter("start"));
		int numberToReturn = req.getParameter("limit") == null ? 10 : Integer.parseInt(req.getParameter("limit"));
		String sortBy = req.getParameter("sort") == null ? "id" : req.getParameter("sort");
		String sortOrder = req.getParameter("dir") == null ? "asc" : req.getParameter("dir");

		// Create the SQL query used to retrieve the persons
		String sql = createMainSQLQuery(sortBy, sortOrder);

		ArrayList persons = null;
		try {

			// Get a connection to the Oracle database and put it on the object so that it's easily accessible
			connection = getConnection();

			// Execute the query to return the exact records requested
			persons = queryForPersonsUsingLimits(sql, start, numberToReturn);

			// Convert the list of persons into a JSON string
			JSONObject jsonDataToReturn = new JSONObject();
			JSONArray jsonPersons = new JSONArray(persons, true);
			jsonDataToReturn.put("totalPerons", getTotalNumberOfPersons(sql));
			jsonDataToReturn.put("persons", jsonPersons);

			// Write everything back to the requestor
			res.getWriter().print(jsonDataToReturn.toString(1));

		} catch (Exception e) {
			e.printStackTrace();
			throw new IOException(e);
		} finally {
			if (connection != null) {
				try {
					connection.close();
				} catch (SQLException e) {
					e.printStackTrace();
					throw new IOException(e);
				}
			}
		}

	}

	/**
	 * Create the query used to retrieve the persons from the database.
	 * @param sortBy
	 * @param sortOrder
	 * @return
	 */
	private String createMainSQLQuery(String sortBy, String sortOrder) {

		StringBuffer sql = new StringBuffer("SELECT id, firstname, lastname, dateofbirth FROM person");
		sql.append(" ORDER BY ");
		sql.append(sortBy);
		sql.append(" ");
		sql.append(sortOrder);

		return sql.toString();

	}

	/**
	 * Wrap the query passed in with some extra SQL that pulls out the exact
	 * page of persons requested, i.e. starting at record number 10 return 20
	 * records.
	 * It's vital that the query given in 'sql' has an 'order by' clause.
	 * If it didn't then the persons could be returned in a random order
	 * making it impossible to order them into pages.
	 * @param sql
	 * @param start
	 * @param numberToReturn
	 * @return
	 * @throws SQLException
	 */
	private ArrayList queryForPersonsUsingLimits(String sql, int start, int numberToReturn) throws SQLException {

		StringBuffer sqlBuffer = new StringBuffer("SELECT * FROM (SELECT a.*, ROWNUM rnum from (");
		sqlBuffer.append(sql);
		sqlBuffer.append(") a WHERE ROWNUM <= ");
		sqlBuffer.append(start + numberToReturn);
		sqlBuffer.append(") WHERE rnum > ");
		sqlBuffer.append(start);

		Statement statement = null;
		ResultSet rs = null;

		ArrayList persons = new ArrayList();

		try {

			statement = connection.createStatement();
			rs = statement.executeQuery(sqlBuffer.toString());

			while (rs.next()) {
				Person person = new Person();
				person.setId(rs.getInt("id"));
				person.setFirstname(rs.getString("firstname"));
				person.setLastname(rs.getString("lastname"));
				person.setDateOfBirth(rs.getDate("dateofbirth"));
				persons.add(person);
			}

		} finally {
			if (rs != null) {
				rs.close();
			}
			if (statement != null) {
				statement.close();
			}
		}

		return persons;

	}

	/**
	 * Return the total numbner of records that the given query will return.
	 * @param sql
	 * @return
	 * @throws SQLException
	 */
	private int getTotalNumberOfPersons(String sql) throws SQLException {

		int count = 0;

		StringBuffer sqlBuffer = new StringBuffer("SELECT COUNT(*) count FROM (");
		sqlBuffer.append(sql);
		sqlBuffer.append(")");

		Statement statement = null;
		ResultSet rs = null;

		try {

			statement = connection.createStatement();
			rs = statement.executeQuery(sqlBuffer.toString());

			while (rs.next()) {
				count = rs.getInt("count");
			}

		} finally {
			if (rs != null) {
				rs.close();
			}
			if (statement != null) {
				statement.close();
			}
		}

		return count;

	}

	/**
	 * Return a database connection from the connection poll that's stored on the servlet/application context
	 * @return
	 * @throws SQLException
	 */
	private Connection getConnection() throws SQLException {
		OracleDataSource ods = (OracleDataSource) getServletContext().getAttribute("CONNECTION_POOL");
		if (ods == null) {
			ods = createConnectionPool();
			getServletContext().setAttribute("CONNECTION_POOL", ods);
		}
		return ods.getConnection();
	}

	/**
	 * Create a database connection pool
	 * @return
	 * @throws SQLException
	 */
	private OracleDataSource createConnectionPool() throws SQLException {
        String username = "replace with db username";
        String password = "replace with db password";
        String url = "jdbc:oracle:thin:@localhost:1521:XE";

        OracleDataSource ods = new OracleDataSource();
        ods.setURL(url);
        ods.setUser(username);
        ods.setPassword(password);
        ods.setConnectionCachingEnabled(true);

        return ods;
	}

	private void printParameters(HttpServletRequest req) {
		Enumeration parameterNames = req.getParameterNames();
		System.out.println("\nRequest Parameters:");
		while (parameterNames.hasMoreElements()) {
			String parameterName = (String) parameterNames.nextElement();
			System.out.println(" " + parameterName + "=" + req.getParameter(parameterName));
		}
	}

}

The first point of interest in doPost() is the code that takes the ordering and limit parameters off the request. This servlet is requested when the grid is first drawn or when the user clicks on the “Next Page” or “Previous Page” buttons. For the paging to work the data needs to be ordered. The sort parameter indicates what column to sort the data by. It uses the name you give the column in the RecordDef when creating the Grid. The dir parameter says what direction the ordering should be in, ascending or descending. The start parameter is the number of the first record to return and limit is the number of records to return.

Now that we know what the user is asking for it’s time to build the SQL query that will fetch that data. The method createMainSQLQuery() creates a query string to select the required columns and order the ResultSet.

In the next section we call getConnection(). This method (and createConnectionPool()) demonstrate how to create an Oracle connection pool using OracleDataSource and it’s method setConnectionCachingEnabled().

The method queryForPersonsUsingLimits() is where we actually execute the query. In the first section the query is wrapped in some SQL that fetches only the rows we want starting at row start and returning only numberToReturn records. I picked this up from this Ask Tom article. It’s well worth a read if you’re interested in how the ROWNUM pseudocolumn works.

The next section takes the query ResultSet, creates a Person object for each row and puts each on an ArrayList.

Back in doPost() the ArrayList of Persons is serialized to JSON text using the JSON classes freely availabe here. The method getTotalNumberOfPersons() is called to retrieve the total number of rows the query would return if we weren’t limiting the results. The reason we need this is because the Grid will have a message at the bottom saying like “Displaying 1 to 20 of 100”. The getTotalNumberOfPersons() method reuses the SQL we created earlier and simply wraps it in a SELECT COUNT(*).

Finally we write the JSON text to the output stream which is sent back to the browser.

Deploying the servlet into a web application is simply a matter of adding servlet and servlet-mapping entries to the application’s web.xml. For testing purposed I chose to use the web application created by GWT. By default this application is located in the <project dir>\tomcat\webapps\ROOT. Here are the entries I added…


	
		GetPersonsServlet
		com._17od.GetPersonsServlet
	

	
		GetPersonsServlet
		/persons
	

Here’s a sample of the JSON returned from the URL http://localhost:8888/persons?start=2&limit=3.

{
 "persons": [
  {
   "class": "class com._17od.servlets.Person",
   "dateOfBirth": "1901-01-17",
   "firstname": "Laurel",
   "id": 3,
   "lastname": "Davis"
  },
  {
   "class": "class com._17od.servlets.Person",
   "dateOfBirth": "1892-05-16",
   "firstname": "Ted",
   "id": 4,
   "lastname": "Schoenberger"
  },
  {
   "class": "class com._17od.servlets.Person",
   "dateOfBirth": "2001-05-19",
   "firstname": "Rebecca",
   "id": 5,
   "lastname": "Taylor"
  }
 ],
 "totalPerons": 20
}

The JSON implementation I’m using includes the name of the class being serialized, hence the class attribute.

Since I’ve included all the other code here’s the Person class,


package com._17od.gwtexamples.servlets;

import java.util.Date;

public class Person {

	private int id;
	private String firstname;
	private String lastname;
	private Date dateOfBirth;

	public Date getDateOfBirth() {
		return dateOfBirth;
	}

	public void setDateOfBirth(Date dateOfBirth) {
		this.dateOfBirth = dateOfBirth;
	}

	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public int getId() {
		return id;
	}

	public void setId(int personId) {
		this.id = personId;
	}

	public String getLastname() {
		return lastname;
	}

	public void setLastname(String lastname) {
		this.lastname = lastname;

	}

}

To finish off here’s a screenshot of the Grid,
Grid Screenshot

UPC DVR Review

25May08

After getting myself a new flat screen TV recently I decided to splash out get UPC’s DVR. I’ve had a MythTV setup in the past so I was keen to get back the features I got use to (pause live TV, easy to setup recordings, recording library, etc). Before I critize the DVR too much I should start by saying that it is a good product. It does what it says on the box and for the price (€5 per month) it’s well worth it.

With the niceties out of the was I’ll start off with my biggest complaint, UPC’s inability to deliver when they say they will. I’ve been itching to get their DVR for a while but I’ve been let down badly in the past. No doubt several readers will have had the experience of waiting in for a full day for the engineers to arrive. It’s extremely frustrating and after the the last episode I had with them I went so far as so cancel my broadband and move to a different provider. I had hoped that was a once off but my experience with them this time around was no different. I was told it would be delivered between 9am and 1pm on a Thursday. After about 10 calls they finally arrived at 6pm on Friday. Luckily my wife’s at home these days so she could stay in. I don’t know how anyone who has to wait home from work would cope. Needless to say my wife wasn’t very happy and after speaking to a supervisor she managed to convince them to credit our account with €160. I haven’t received our next bill yet to confirm weather we actually got it or not.

Anyway that’s enough complaining, on to the box itself.

The first thing I noticed was that the menu system is a bit slow. It takes a good two or three seconds from when you press the menu button until it actually appears. That mightn’t seem like much but when you’re watching a program and you just want to flick into the full EPG quickly it’s a little bit annoying (note, you can easily and quickly see what’s on now and next for every channel by hitting the OK and bringing up the mini-guide).

One of the main advantages of having a DVR is that you can fast-forward through the ads. This box does have fast-forward (and rewind obviously) but it’s very restrictive. MythTV has a really useful feature where you can key in the number of minutes you want to forward and then hit the fast-forward button. This means that when you get to an ad break you could just hit 4 and then ff and you’d be right up to the next part of your program. With this DVR you’ve only got five speeds of forward and rewind and the fastest is still very slow. It’s not too bad for ad breaks I suppose but if you’re watching a movie and you want to skip the first hour even the fastest fast forward speed will take about 5 minutes to get there.

The final criticism I’ll make is around recurring/repeat recordings. Setting one up is relatively easy, the only minor problem being that you have to know the channel number you want to set the recording up on, e.g. 101 for RTE1. The problems really start after you’ve setup the repeat recording. In the Digital Video Recorder menu there are two sub-menus, one called “My Recordings” where you can see everything you’ve recorded and one called “My Planner” where you can see what’s scheduled to be recorded. For standard recordings you see the program name, channel, date and time. For repeat recordings the channel name is given for the program name as well as the channel name. What that means is that when you look in your Planner or Recordings you can’t tell what the program is unless you know from the time or you start playing it.

Another two problems with repeat recordings is that you can’t edit one after you’ve created it and you can’t tell the difference between a repeat recording and a once off recording in the Planner. Not big problems but they do take away from the experience.

Aside from the negatives I do like this DVR. Given the choice I’d still prefer MythTV but the hassle of setting it up and keeping it up to date is just more time that I’m prepared to invest. UPC’s DVR does what it says on the box and it is relatively cheap. If you’re prepared to go through the hassle of getting it installed I would definately recommend it.

For a more indepth review have a look at this blog entry from Adam Maguire.

Installing Mercurial with Apache

02Apr08

If you’ve been following one of these guides explaining how to configure Mercurial with Apache you may have encountered the following error…
TypeError: 'hgwebdir' object is not callable
There may be a number of scenarios under which this error can happen but in my case it was because I was using an incompatible version hgwebdir.cgi. After installing Mercurial 0.9.4 I downloaded hgwebdir.cgi from here (which at the time of writing was for Mercurial 1.0). To fix the problem I had to use the version of hgwebdir.cgi that came with the Mercurial 0.9.4 install. On Ubuntu you’ll find it here /usr/share/doc/mercurial/examples/hgwebdir.cgi.

Accessing the NIB & ROS Websites Using Linux

04Nov07

Flexible and all as the Linux operating system is there are a few drawbacks that make the experience less than perfect. One of the main reasons I didn’t go Linux 100% of the time was that there was always one or two applications that I couldn’t live without that only ran on Windows. The main one was Internet Explorer, or more specifically a few websites that I use that were designed to only work with Internet Explorer. The websites in question are my bank’s, NIB and the Irish revenue website ROS. In fairness to NIB they do offer a workaround but it involves using an a calculator like device to generate a unique token each time you logon to their website.

As it happens, getting Internet Explorer to work in Linux is relatively straightforward. The tricky bit it pulling the various pieces of the puzzle together.

Install Wine and Internet Explorer
Because the problem of not having access to IE within Linux is such a common problem, some nice people have put together an install process that installs both Wine and IE with minimal fuss. It’s called IEs4Linux. To make the process as painless as possible there’s a step by step guide available here. The most important thing to remember is to carry out the install as a normal user, i.e. NOT the root user.

If you’re running Ubuntu Gutsy then for step 2 add the following lines to /etc/apt/sources.list
deb http://de.archive.ubuntu.com/ubuntu gutsy universe deb http://wine.budgetdedicated.com/apt gutsy main

When asked if I wanted to install IE5.5 or IE5.0 I said no. That meant that only IE 6 was installed. Installing all three isn’t a problem but I had no need for 5.0 and 5.5.

Once the process has finished you should have an Internet Explorer icon on your desktop.

Installing the Java Runtime Environment Plug-in for IE
This was the part that I was a little unsure about. I thought getting IE to run was an achievement but I never thought the IE JRE plug-in would work. As luck would have it I came across this post by Ranjit Mathew that was exactly what I needed.

Following Ranjit’s post here are the steps I carried out…

i) Go to the Sun website and download the latest version of the Windows 1.5 JRE. The reason for using 1.5 and not the latest 1.6 is that the ROS website states that they only support Sun 1.5 on IE6. The 1.6 version may work but I didn’t want to tempt faith.

ii) Open a command prompt and execute the following lines,
export WINEPREFIX=$HOME/.ies4linux/ie6 wine jre-1_5_0_13-windows-i586-p.exe

iii) I was having some problems with the entire screen blacking out when I’d visit a page with a Java applet on it. If you have the same problem open a command prompt and execute these commands…
export WINEPREFIX=$HOME/.ies4linux/ie6 regedit
Go to the key HKEY_CURRENT_USER\Software\JavaSoft\Java2D\1.5.0_13 and set the property “DXAcceleration” to 0.

Installing The ROS Software
When you visit the ROS website for the first time you’ll have to install the KCrypto software. KCrypto is the Java code that handles the secure transfer of data between your browser and the NIB servers. The first time I tried to install it it failed. The second time it worked fine.

Installing your ROS Certificates
Your ROS security certificates are held in the folder C:\ROS on your Windows machine. Copy this entire folder from your Windows machine into the folder $HOME/.ies4linux/ie6/drive_c. When you restart your IE browser you should see your user id appear on the ROS logon page.

Installing you NIB UserID File
i) Logon to your NIB account on your Windows machine
ii) Click on “Settings” at the top of the page and then “Security” in the left hand menu
iii) Select the function “Back up user ID” and click OK
iv) On the next screen click OK. Take the file that’s downloaded and go back to your Linux machine
v) Start up IE and go to the logon page
vi) Select “Search for user id” just under the userid and password fields. Browse to where you have the file downloaded in step iv, select the second radio button (i.e. copy to a local location) and click OK

That’s it. One step closer to going Linux full time.

Installing Mythbuntu 7.10

26Oct07

Mythbuntu is “an Ubuntu derivative focused upon setting up a standalone MythTV system similar to Knoppmyth or Mythdora”. The last time I installed MythTV I did it on a standard Ubuntu desktop installation. The problem with this is that as well as ending up with a load of software you don’t really need you have to go through the pain of installing and configuring your TV card, graphics card, remote control and so on. Mythbuntu on the other hand takes care of absolutely everything. I won’t go into the details of the installation (because it’s pretty much next, next, next…) but suffice to say, Mythbuntu makes the whole process extremely simple. There were just two areas I had problems with, configuring XMLTV and configuring my wireless card.

The last time I installed MythTV I had the same problem with XMLTV. I don’t know if it’s something that I keep missing but after the installation mythfilldatabase never seems to works properly. The problem is that the XMLTV file containing the list of channels to fetch program information for never gets created. Luckily it’s easy enough to fix. What you do is take the name of the Video Source you setup in the MythTV Backend Setup program (in my case NTL) and then create a file in the directory $HOME/.mythtv called &lt;video source name&gt;.xmltv (e.g. NTL.xmltv in my case). When I refer to $HOME here I’m referring to the home directory of the user that you’re asked to create during the Mythbuntu installation. Within that file you list the XMLTV channel ids you want to retrieve program information for. Here’s what I have…

channel northern-ireland.bbc1.bbc.co.uk
channel northern-ireland.bbc2.bbc.co.uk
channel channel4.com
channel discoveryeurope.com
channel e4.channel4.com
channel livingtv.co.uk
channel mtv.co.uk
channel paramountcomedy.com
channel rte-1.rte.ie
channel rte2.rte.ie
channel 1.setanta.com
channel sky-news.sky.com
channel sky-one.sky.com
channel tg4.ie
channel tv3.ie
channel utvlive.com
channel nickelodeon.co.uk

This is the program listing for NTL’s analogue network in Dublin. Unfortunately (I suppose) Channel 6 isn’t available from the Radio Times XMLTV feed.

The second problem I had was configuring my wireless network card. The card I have is a Linksys WMP54G (version 4, PCI id 1814:0201). What I did was follow the instructions on this page https://help.ubuntu.com/community/WifiDocs/Driver/Ndiswrapper. When it comes to installing the windows drivers I used the files from the directory /Drivers/WMP54Gv4/2KXP on the installation CD that I got with the card. At the end of the process the card still wasn’t working. The problem was that a kernel module shipped with Ubuntu, namely rt2500pci, was getting loaded before (and hence interfering with) the module I wanted to load, i.e. ndiswrapper. To fix the problem I blacklisted rt2500pci and rebooted. The line I added to /etc/modprobe.d/blacklist was blacklist rt2500pci.

That’s it, a relatively easy install and nowhere near as timeconsuming or complicated as perfoming a MythTV installation from scratch.

P.S. another useful resource if you’re stuck is https://help.ubuntu.com/community/WifiDocs/WirelessTroubleShootingGuide.