Jan 3, 2009

Kubuntu 8.10: First impressions

My laptop has been "upgraded" since Feisty, I think. Feisty Beta actually. It's gone from Feisty -> Gutsy -> Hardy. And while it's sweet that one can upgrade the operating system without having to reinstall everything, cruft has built up. Suspend quit working after the Gutsy -> Hardy upgrade. The way stuff like X works has completely changed: my old /etc/X11/xorg.conf was full of options I'd discovered by trial and error in order to get KDE4's desktop effects to work. There were lines that I'd carefully commented out in a failed attempt to keep X from spewing errors about imaginary Wacom tablets. Imagine my surprise when I learned that nowadays, xorg.conf is practically blank - all the monitors, input devices, etc. are hotplugged. English translation: All that confusing stuff I had to do to get stuff working in the past? That's done by magic now. I don't need that stuff. (And more than likely, keeping those config files makes things worse, because those options might override the ones chosen by the magic.)

At some point I might have to learn where the new magical X settings come from, if for some reason the magical settings it chooses don't suit me. But frankly, I have less patience for that stuff than I used to. I just want it to work by default.

But the point is: "upgrading" wasn't giving me all the benefits of a fresh new install. So for Intrepid, I said screw this, I'm reinstalling. I want a brand new, out-of-the-box system. Luckily, I had been clever enough in the past to put my /home directory on a separate partition, so it wasn't a big issue. I just made a full backup, and then reinstalled over the partition that had root. I actually went through and hand picked what config files in my home dir to keep, and which to toss out in favor of whatever new default config files are provided nowadays. I kept .mozilla and .opera, so I wouldn't lose my bookmarks and history. I kept .mozilla-thunderbird so I'd keep my email settings. I merged my old .bash_rc with the new .bash_rc, and so on. Finally, I deleted the home dir in the root partition, added a line to the new /etc/fstab to mount my home partition in /home, rebooted, and lived happily ever after.

Haha, yeah right like anything computer-related is "happily ever after". But it was pretty close. Here are some of my comments and feedback on Kubuntu Intrepid.

Sound works out-of-the-box. Yeah! However, I had to change the Master Channel in KMix from PCM to Front. On PCM, the multimedia buttons brought up the on-screen volume display, but didn't actually change the volume.

I went to change the wallpaper - only one wallpaper is installed by default? Come on. That's just lame. And then to confuse things worse, there are TWO packages of wallpapers: kdewallpapers and kdebase-workspace-wallpapers. The ones in kdewallpapers were aweful (Repeating tile patterns? That's so Windows 95.) so I just kept kdebase-workspace-wallpapers. Next time, install that package by default please!

I like that I can just install kubuntu-restriced-extras and get .mp3 playback and friends. Kubuntu might have even prompted that when I tried to play an .mp3 the first time, I forget. Still have to add medibuntu for some stuff, but that's really easy.

But no, I have a list of quibbles and complaints. Some are due to specific KDE4->KDE3 functionality losses, some are stupid defaults, but most are just because of laziness or lack of time on the developers' part probably. Here we go:
  • The installer. When I hit "Forward", the focus isn't set to the first text box on that page - I must move the mouse and select the first text box myself. An anoyance that got in the way of my type-type-tab-type-type hit "Forward" type-type-tab-type-type mentality. Seriously, it's probably just one line of code to set the focus; I expected more from the Kubuntu devs who put so much emphasis on usability.
  • When I created a Google Talk account in Kopete, it set the default server to gmail.com. I was baffeled as to why it didn't work until I went to the Google Talk page and saw it says clearly to use the server talk.google.com. Also, "Use SSL" was unchecked by default when for Google Talk it should be checked by default. Seriously, if they're going to add a separate item for Google Talk instead of including it as a Jabber account, put in the right defaults for goodness sake!
  • The knetworkmanager UI has regressed. I use to love clicking the knetworkmanager icon, seeing the available wireless networks and their signal strength in the dropdown, and clicking one to switch to that network immediately. I now have to click multiple times to even see what wireless networks are available! That's worse than in XP. I know Celeste did a usability report on it, so maybe the "good" knetworkmanager was a version modified specifically for Kubuntu and now Kubuntu 8.10 has the vanilla KDE version. I must say, I hope the vanilla KDE knetworkmanager people accept Celeste's advice and implement the usability changes.
  • Searching in krunner. No offense, I LOVE THE NEW KRUNNER! I use it all the time. But seriously, some keywords need to be added to apps or smarter indexing used. Typing the word "Internet" returns no hits. Searching for "printer" brings up the HPLIP Toolbox but not system-config-printer-kde. On a general note, how are users going to know to hit F2? Should that be mentioned in the K-menu perhaps?
  • The clock was in 24hr mode be default, and no menu option for the clock widget takes you to the time/date settings. Don't be a lazy developer; add a link to the date and time settings from all clock widgets. It's little things like that that need polishing. Maybe that's fixed in 4.2 already, I guess I'll find out later this month.
  • There's no printer settings in System Settings. This is a KDE4->KDE3 regression, so I'll give Kubuntu some slack. There is a printer setup utility K-menu > Applications > System, so it's not a total loss. It's not as nice as the old utility, but hopefully that'll be worked out soon. However, I wonder how hard it would have been to put a link in System Settings to the printer utility, or re-use the KDE3 printer module in System Settings. Same applies to the User Manager - it's in the K-menu but not in System Settings which makes it harder to find.
  • I have a sneaking suspicion that parts of Special Window Settings may not work. Rules for Keep Above and Show on All Desktops seems to work, but I'm having trouble getting geometry rules to be applied to FF windows based on the window title. Might just be me though... and I hadn't tried that in KDE3 before so I have nothing to compare it with.
  • Another Kwin questions: Why is "Desktop navigation wraps around" under Focus, and "Active Desktop Borders" under "Advanced"? They seem tightly related to me. Well, all the Kwin settings need to be organized and explained a little better - I submitted the idea of being able to move your mouse across virtual desktops as a KDE4 feature request, only to later learn it's been in KDE3 for ages, if I had only guessed that's what Active Desktop Borders meant.
  • The MythTV frontend package tried to call kdesu to add the user to the mythtv group, but Kubuntu apparently now uses kdesudo. That needs to be fixed. Hm, I may actually file a bug report for that one. (Aw, it's already been fixed.) You really got to be on top of things to file a virgin bug report for KDE these days. I made that mistake just the other day.
  • I haven't figured out how to take advantage of strigi. In my old install, I could type "strigi:/" in the addressbar of Konqueror, but that protocol appears to be unsupported now. I installed strigi-client, but in addition to being terribly slow, it has only served to inform me that Strigi has indexed 0 files, despite being enabled in System Settings. Hmph.
  • Dolphin is mysteriously slow. Like... I don't know it behaves like it's running on Windows sometimes. Three second delays between when I right click and a menu pops up, that sort of thing. Konqueror seems fine. I'm throwing the Dolphin devs the benefit of the doubt here guessing the speed thing is due to something beyond their control, or that they have implemented large speed improvements in time for KDE 4.2.
Overall, I'm fairly happy with Kubuntu 8.10. It's no panacea, but compared to 2 years ago, it's amazing progress, particularly given the switch to KDE 4. Almost all my complaints at this point are polish - things that could be fixed with one or two - ok maybe 5 or 6 - lines of code here and there. It still kicks ass compared to Windows. Although on a personal note, I'm starting to tire of tech - I think I may need to get outside and start canoeing and camping again.

Dec 22, 2008

Compiling Qt apps in Windows with MinGW

I love Qt. I haven't actually used it much, as I haven't written many programs, but I've seen enough stuff written about it in developer blogs to have a fanboyish appreciation for the cross-platform toolkit. But aside from installing KDE for Windows back in it's beta days, I hadn't had the opportunity to use the "cross platform" bit until yesterday. I needed to compile screenie for a Windows environment. I knew what I was getting into, having compiled C and C# programs in the past. (I'm a big fan of interpreted languages; compiling always seems to waste hours of development time and involve enormously frustrating obscure compiler and linker errors.) But I loved learning about the process, and particularly discovering that I was capable of overcoming all my compiler errors with my current knowledge and Google. I got to understand Qt (and Windows executables, for that matter) on a more intimate level, solidify in my mind what .dll's are, and what dynamic and static linking are. After multiple attempts, I ended up with a standalone executable that ran perfectly on XP and Vista. It's an amazing feeling, knowing you started with hundreds, maybe thousands of text files - barely contained chaos! - and ended with a single file - pure simplicity. Plus, I may be the first person to compile screenie for Win32, making my work useful to others. Hopefully the author will make it available on screenie's website.

And now for the boring stuff if you're reading this for the human interest aspect; or the interesting part if you're reading this for the "How To" aspect. After reading several articles about cross-compiling Qt, I decided not to attempt that, and just did the whole process in Windows XP.

How to compile a C++ Qt4 application for Windows
Obviously, these directions are specific to compiling screenie. If you're using this as a guide for compiling something else, use your imagination as needed to adjust the steps.
Where applicable, I specify the generic download page for each application, as well as the specific binary version I used.
1. Download and install Qt4 with MinGW
(http://trolltech.com/downloads/opensource/appdev/windows-cpp)
I used version: ftp://ftp.trolltech.com/qt/source/qt-win-opensource-4.4.3-mingw.exe
Since the source for screenie is a Git repository, I figured we need git. Update 2008-12-26: There is a Download button on the screenie Github page to download the source as a zip file. Extract it to C:\screenie and jump to step 5.
2. Download and install msysgit
(http://code.google.com/p/msysgit/downloads/list)
I used version: http://msysgit.googlecode.com/files/Git-1.6.0.2-preview20080923.exe
3. Run Git Bash and execute git clone git://github.com/ariya/screenie.git
4. Copy the downloaded source directory to c:\screenie
5. Open the Qt 4.4.3 Command Prompt from the start menu.
It's like a normal command prompt, except with some environment variables and bash scripts set. (For instance, it appears to alias make to mingw32-make, which saves typing.) It is assumed you are using the Qt Command Prompt for all the steps below involving a prompt.

By default Qt installs itself for compiling with dynamically linked libraries. This means you have to copy the compiled executable, as well as a bunch of .dll's to each computer you install it on. It's not really a problem: just put them all in a zip file, unzip it on the Desktop, and it runs nicely. But if you're like me, and want a single executable with no dependencies, scroll down to the statically linked bit.

Dynamically linked (.dll dependencies, distribute as .zip file)
6. cd C:\screenie
7. Issue qmake -spec "C:\Qt\4.4.3\mkspecs\win32-g++"
For some reason, qmake seemed confused out-of-the-box, and I had to fix several things in the makefile. I used the Find and Replace feature in Crimson Editor (my favorite Windows text editor.)
8. In Makefile.Release replace:
"iwmake\build_mingw_opensource" with "Qt\4.4.3"
(There were 8 instances)
"QtGui" with "QtGui4"
"QtCore" with "QtCore4"
(Both in the LIBS line)
The same substitutions would be needed to fix Makefile.Debug, except instead of QtGui4 and QtCore4 it's the debug versions QtGui4d and QtCore4d. But you don't need to build the debug version anyway.
9. Issue make.
The compiled executable appears in C:\screenie\release. Test the program and see if it works. For me, Screenie worked on Windows! Yea!

Following the advice on the Trolltech website, I used Dependency Walker to find what .dll's the executable requires. I copied those .dll's to the release directory. In screenie's case, Dependency Walker listed QtCore4.dll, QtGui4.dll, msvcrt.dll, and kernel.dll. Kernel.dll is already installed on every windows system so no need to distribute it. Msvcrt.dll is the Microsoft C Runtime Library - probably installed on people's computers, but I included a copy anyway, along with QtCore4.dll and QtGui4.dll. I had to include one more .dll that Dependency Walker did not find, a copy of c:\MinGW\mingwm10.dll. (See note in static compiling.) Also, any plugins used need to be copied to the release folder. In this case, screenie needs the image plugins to read JPEG or GIF files, so copy the contents of c:\Qt\4.4.3\plugins\imageformats to c:\screenie\release\imageformats. You can delete the .dll's whose names end in the letter "d"; they are debug versions and take up a lot of space, and are not used if you compile for release. Copy the release folder to the Desktop, give it a better name (like "screenie"), zip it, and voila! Copy it to another computer and hopefully it will run.

Statically linked (no dependencies, single file to distribute)

To my dismay, compiling statically was not simple. To begin, we must recompile Qt itself.
6. Using the Qt 4.4.3 Command Prompt from the start menu...
cd C:\Qt\4.4.3
configure -static
This takes a long time. I read later to do a distclean before rebuilding... but I didn't and it built OK. However, I wonder if this is why later qmake decided to link to the old .dll's ending in 4.
7. make sub-src
This takes a really long time. (By this point it was past 3:00 am, so I left it running while I slept.)

When Qt is statically linked, it cannot dynamically load plugins. (Turns out it's an artificial restriction that's easily overwritten.) But we want those image plugins statically compiled into our final executable. To make that happen you have to do the following voodoo. Luckily it's straight from the Trolltech documentation.
8. Add Q_IMPORT_PLUGIN() statements for each plugin to the c++ code.
I added the lines:
Q_IMPORT_PLUGIN(qjpeg)
Q_IMPORT_PLUGIN(qgif)
to screenie.cpp

(There are plugins for some other image formats, like .tiff and .ico but I didn't think most people would need more than .jpeg, .png, and .gif. PNG support is built into Qt so it doesn't have a plugin.) These lines of code are necessary to compile it statically, but I don't know yet if those lines cause trouble if you try to compile the code dynamically.
9. Add a QTPLUGIN line to the .pro file
I added the lines
QTPLUGIN += qjpeg qgif
CONFIG += static
to screenie.pro
(The CONFIG one is a guess... I actually got it from a page on compiling custom plugins, but figured we want all things static, so why not throw it in? Not gonna make them less static.) Voodoo done.
10. cd C:\screenie
make clean
qmake -config release
This time, it seems to not have the iwmake\build_mingw_opensource problem, but it does need for the 4 from the library names to be deleted. When compiling statically, the library names used do not have the 4 in them. I'd love to know why Trolltech thought that was necessary. (Funny how the 4's weren't there when I needed them, and now are there when I don't want them!)
11. In Makefile.Release, in the LIBS line, replace -lqjpeg4 and -lqgif4 with -lqjpeg and -lqgif.
Delete mthreads because it's an unneeded dependency on mingw10.dll which isn't compiled statically. Apparently Qt doesn't use it, so I don't know why qmake adds it by default. If you don't delete -mthreads, you get an error saying mingw10.dll can't be found when you run it on other computers.
12. Delete all instances of -mthreads in Makefile.Release
13. Now back in C:\screenie issue make
cd release
You should now have a statically compiled executable c:\screenie\release\screenie.exe. See if it works! If everything went according to plan, you can run that file on any Windows XP / Vista computer and use Ariya Hidayat's awesome screenie!

But no! You're a perfectionist. You want more. The screenie.exe file is about 10 MB. Let's see if we can shrink that! I got these tips from http://www.qtforum.org/post/85635/static-compiling.html#post85635
14. From the release folder, issue strip screenie.exe
This is a command from Qt that removes unnecessary parts of Qt from statically compiled files. Sadly, this didn't reduce the file size much, if any. (Perhaps Qt does that behavior by default now.) But there's another thing you can do to reduce file size.
15. Download and install the Ultimate Packer for eXecutables (http://upx.sourceforge.net/)
I used version: http://upx.sourceforge.net/download/upx303w.zip
I had to manually unzip it to C:\Program Files and add it's directory to Window's Path environment variable.
16. Open cmd and cd to c:\screenie\release
Issue upx screenie.exe
Now it is only 3.58 MB. Sweet!

Sep 11, 2008

How to build a MythTV for under $300

If you search for a media center PC online or in a store, they tend to be quite expensive, often in excess of a thousand dollars. But you don't need that much money to get a working media center that lets you pause live TV, record shows, rip DVDs onto the hard drive, and more. I did it for under $300, and with a little bargain hunting, you can too!

Here's what I have and how much I paid (rounded to the dollar):
$39 - ECS 761GX-M754 motherboard (eBay)
$10 - AMD64 3000+ CPU on sale at Fry's because the 754 socket is being discontinued. Great time to buy one!*
$33 - 1GB Corsair RAM (Fry's)
$25 - PowerSpec TX366 mATX Case (Microcenter)
$25 - XION 450W power supply (Microcenter)
$33 - Hauppauge PVR-150 NTSC TV tuner (eBay)
$38 - ATI X700 (eBay)
$21 - 50' CAT5 cable (Home Depot)
$20 - 1 year subscription to Schedules Direct (needed if you want to get channel schedules in North America)
$27 - Windows MCE remote (eBay)
Some additional parts that I already owned:
$0 - Two 80GB Western Digital IDE hard drives
$0 - DVD reader
---------------
= $271

* I actually got several since they were such a steal... if you wanna buy one, leave a comment!

Now, you're probably thinking, "Hey, that's not fair - you didn't include the price of the hard drives or the DVD reader!" Frankly, if you're not the kind of person who has a some spare computer parts lying around your house, you should probably quit reading now, because despite many advances in usability, MythTV is still quite a challenge to install and configure. However, for the sake of thoroughness: you can get a 160GB SATA drive for $50 and a DVD-ROM reader from $20 at Microcenter. Plus, in hindsight, I believe a 300W power supply would suffice, so instead of paying $50 for the case and power supply, Microcenter sells the case with a 300W power supply for $34. And on Craigslist, which I discovered late in the process of buying things, people are selling old desktops for as low as $50, which is as much as I paid for the case and power supply alone, but would potentially get you RAM, hard drives, an extra keyboard, maybe even the DVD drive if you're lucky. I got a 20" CRT monitor for $15 on Craigslist, so I'm sure that if you live near a big city you could get a better deal on a bare bones PC than I did building from scratch.

Be warned, installing MythTV is not for the faint of heart. It took the better part of two weeks to get it configured the way I like it, and I am already pretty well versed in Linux and Ubuntu. Most of the first week was spent trying to make the ATI tuner card, the ATI remote, and a cheap Trendnet TEW-424UB USB wireless dongle work with Linux. (The USB wireless adapter worked fine with ndiswrapper on my laptop, but refused to connect on my desktop.) After a week I gave up, and researched the best, most highly recommended hardware for MythTV and got a Hauppauge card, a Windows MCE remote, and traded wireless for a CAT5 cable, which all work great. I had to mess around with the LIRC config files until I got all the buttons on my remote programmed the way I like, but that really wasn't too hard once I figured out how. Also, MythTV's internal player had extremely poor DVD playback on my setup, so I had to configure MythTV to use Xine instead (the MythTV wiki explains how to do that very clearly).

All of the parts I used are a few years old - you don't need "modern" hardware to run MythTV. The AMD64 3000+ was released in 2003 according to Wikipedia. The 80GB hard drives are both from an old computer that got replaced years ago. Using the Hauppauge card with its hardware MPEG-2 encoder, standard definition analog TV takes up 2.2GB per hour; one drive is formatted with XFS and has 75GB of free space, the other is ext3 and has nearly 70GB free. That's over 65 hours of TV! (Mythbuntu itself appears to only take about 2GB. The formatted capacity of ext3 is less than XFS apparently.) As for the other hardware, I don't necessarily recommend the power supply I got - I find the fan rather loud and annoying. And I'm not sure where I stand on ATI vs Nvidia when it comes to Linux. But I definitely recommend the Hauppauge if you're recording analog. You might want a PVR-500, which has two tuners in it, if you want to be able to watch live TV while recording another show, or record two show at once. I figure the chances of two good shows being on at the same time, with no reruns that could be recorded later, are so slim all I need is one for now. Since I'm stuck with college cable, I doubt I'll get any digital or HDTV for a while, so I stuck with an analog tuner.

So if you've got a lot of free time and $300, go ahead - build yourself a MythTV! Record shows and skip through the commercials! Never worry about when your favorite show is on; MythTV can find and records your show on any channel at any time. Try programming a VCR to do that! MythTV also remembers which episodes it's previously recorded so it doesn't fill up your hard drive with reruns you've already seen. You can rip your DVDs to the hard drives. You can have multiple frontends, connected to a single MythTV backend by ethernet. The MythWeb plugin even lets you stream your recordings over the Internet so you can watch them on any computer. And all sorts of cool things. Useful resources definitely are the MythTV wiki, the Mythbuntu forums, the MythTV wiki, and did I mention the MythTV wiki? Really, the MythTV wiki is the most useful thing I encountered. FYI, I tried MythDora and KnoppMyth - MythDora seemed really nice - but stuck with Mythbuntu simply because I'm use to Debian/Ubuntu systems.

Here's some more pictures. I printed the MythTV sticker in the above picture by using the unused portion of inkjet DVD label paper.

The MythTV home screen with the "neon-wide" theme.

The MythTV program guide.

For fun, I re-branded the Windows Media Center Remote.
(You can guess what logo was there originally.)
So that's it.