The birth of an idea due to the prospect of a mundane task

So a few days ago, my mom told me that I had to index the contents of all our data CDs and DVDs, this was not the first time, and like all other times it was a really shoulder-sagging moment. The steps of the boring job was, insert each CD/DVD, read the folder names in the root of the media and write them down, which frankly is one of the dullest and most monotonous jobs I can think of(frankly I would rather watch a hard-core financial documentary for 6 hours), so with the fear of the mundane task ahead of me, I tried to think of a solution to the conundrum.

The solution was to write a program that would do all that(and perhaps more) for me all in the time of a few seconds rather than that of a few 10 minutes along with the absence of the headache and fury if was I doing it manually. I did not bother with writing a script because frankly I don’t know enough bash to save my life and since I already had a fairly good idea of how to do it with DeviceKit-Disks(now UDisks) and GLib along with a few other choice libraries.

So I started writing the program, but immediately I had a problem, even though I was informed by UDisks that there was a media change, I somehow could not obtain the mount point of it, which is highly essential since you need to open that path as a directory. So after a few hours of looking everywhere and trying different things, I discovered the problem which was one of the smallest, yet most mind boggling issues ever, I was using an audio CD to test it instead of a data CD, the reason being that GVFS mounted special media at a gvfs mount(USER_HOME/.gvfs/….) instead of a normal unix mount(/media/…), which meant that UDisks did not have a clue about the mount path(I think that was a bad idea on the part of the GNOME devs personally).

But after that big problem, things got a lot easier and I finished the basics of the program. Mind you, this post is about three days after I finished the program, the reasons being that my mom forgot about the task(like all the previous times), so now all that effort was a bit of a waste(not a total waste because it gave me something to do and it improved my knowledge on a few areas of the GNOME desktop), and because I thought I would post the program in case it may benefit someone directly or in an obscure fashion after making it a bit more “mainstream friendly” and adding a few nice touches.

The features of this small program(I dubbed it “cd-root-dir-reader” which is a stupid name :P):

1) Automatically eject the media after it has been finished(option “-e” if you want it).

2) Read the media recursively once(option “-r” if you want it), or not at all(not sophisticated, but I couldn’t think of a plausible way of doing this without resorting to nesting code on and on until infinity).

3) Output the contents of the media at a file in USER_HOME/Media-reader.

Code is here if anyone wants it(Sorry for the ubuntu pastebin link, I don’t really own a server and I could see no other way of providing the source). Compile with:

gcc name-of-input-file -o output-file -Wall `pkg-config –libs –cflags gtk+-2.0 dbus-glib-1 gthread-2.0 gio-2.0 polkit-agent-1`

Note: The media to be read should be inserted after the program has been started.

Since I have nothing much to do these days, feature requests and anything else would be accepted. šŸ™‚


7 Responses to “The birth of an idea due to the prospect of a mundane task”

  1. sEbastian Says:

    why not use something like a CD/DVD database. Have a look at GTKatalog

    • pmdematagoda Says:

      Well, firstly, what was needed was to just list all the directories(in the root) in the CDs and DVDs and print them out, which gtkatalog does not seem to do. And secondly, it would seem that the project is not being maintained now, with the last release in the link posted being in 1999, there seems to be a new maintainer with the website provided, but it seems to be down at the moment.

      Perhaps I should take a look at it sometime soon, see if it’s something I can do, thanks for the suggestion anyway. šŸ™‚

      • sEbastian Says:

        Well, there are other ready build applications to do the same thing. Catalogue discs and provide a search GUI.

        Just search for disk catalogue or something similar

      • pmdematagoda Says:

        I don’t think that would really be necessary now that I’ve written the application that does what I need(apart from full recursion which I am interested in implementing anyway). But if I face another problem like before and it’s something I can’t write a program for, then I will google for it. šŸ™‚

  2. Kirk Says:

    Great app idea! New to building GTK apps – what dependencies (Ubuntu flavour if possible) are needed (package-wise). I’m getting compile errors:

    disk-catalogue.c:29:27: error: polkit/polkit.h: No such file or directory
    disk-catalogue.c:31:27: error: glib-2.0/glib.h: No such file or directory
    disk-catalogue.c:32:25: error: glib/gstdio.h: No such file or directory
    disk-catalogue.c:33:28: error: dbus/dbus-glib.h: No such file or directory
    disk-catalogue.c:34:21: error: gio/gio.h: No such file or directory

    Here’s the serach results for polkit
    libpolkit-agent-1-0 – PolicyKit Authentication Agent API
    libpolkit-agent-1-dev – PolicyKit Authentication Agent API – development files
    libpolkit-backend-1-0 – PolicyKit backend API
    libpolkit-backend-1-dev – PolicyKit backend API – development files
    libpolkit-dbus-dev – library for accessing PolicyKit via D-Bus – development files
    libpolkit-dbus2 – library for accessing PolicyKit via D-Bus
    libpolkit-dev – library for accessing PolicyKit – development files
    libpolkit-gobject-1-0 – PolicyKit Authorization API
    libpolkit-gobject-1-dev – PolicyKit Authorization API – development files
    libpolkit-grant-dev – library for obtaining privileges via PolicyKit – development files
    libpolkit-grant2 – library for obtaining privileges via PolicyKit
    libpolkit-gtk-1-0 – PolicyKit GTK+ API
    libpolkit-gtk-1-dev – PolicyKit GTK+ API – development files
    libpolkit-qt-dev – PolicyKit-qt development files
    libpolkit-qt0 – PolicyKit-qt library
    libpolkit2 – library for accessing PolicyKit
    gksu-polkit – command line utility to run programs as root
    libgksu-polkit-dev – simple gobject-based API to run programs as root (development files)
    libgksu-polkit0 – simple gobject-based API to run programs as root
    libpolkit-gnome-dev – PolicyKit-gnome development files
    libpolkit-gnome0 – PolicyKit-gnome library

    • pmdematagoda Says:

      Those errors are due to the absence of the required headers, I believe that you should install libpolkit-dev, libdbus-glib-1-dev and libglib2.0-dev. After installing them see if you can compile the source properly.

  3. Jason Allen Says:

    I would like to be able to purchase a $20 USB barcode scanner, plug it into my PC/Notebook/Netbook and then scan the barcodes on my books, cd’s, and dvd’s. A gnome linux (Ubuntu!) application will read/accept the scanned barcodes, lookup an internet database for all the relevant contents/information related to that title, and store it into my local application/database. It should do it in real-time, or in-bulk later once I’ve finished reading/scanning all my collection(s).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: