How Transmission Does Cross-Platform

John Gruber went out of his way to mention that Transmission is a cross-platform app which is actually very good on the Mac. In other words, it feels like it was designed for the platform. I was curious about this, so I looked at the source. I found a pleasant surprise.

Transmission
(screenshot from the Transmission site)


Transmission doesn't just give the appearance of being a good Mac app, it actually is. There's real, solid Cocoa goodness here. Based on a quick survey of the project (so don't hold me to the details), it looks like the developers did this by separating the core application logic out into a library called libtransmission, which I assume is shared across the different platforms.

The Mac application project imports libtransmission and uses Objective-C's natural integration with ansi C to layer a Mac UI on top of the core library. The Torrent Objective-C class wraps the low-level C structs, acting as a bridge for the data model.

For example, the -checkForFiles: implementation calls tr_torrentGetFileDL() with the tr_torrent struct as an argument (edited slightly for formatting here):

- (int) checkForFiles: (NSIndexSet *) indexSet
{
    BOOL onState = NO;
    BOOL offState = NO;
    int index;
    for ( index = [indexSet firstIndex];
          index != NSNotFound;
          index = [indexSet indexGreaterThanIndex: index] )
    {
        if (tr_torrentGetFileDL(fHandle, index)
          || ![self canChangeDownloadCheckForFile: index])
            onState = YES;
        else
            offState = YES;
        
        if (onState && offState)
            return NSMixedState;
    }
    return onState ? NSOnState : NSOffState;
}


(I believe I'm allowed to post snippets without inclding the entire copyright, but this chunk of code is essentially under an MIT license. See the project for details.)

As if the concept wasn't enough, even the actual code for Transmission is beautiful. Very well written and easy to understand. It even has a great icon. If you're wondering how to go about writing a cross-platform app that takes advange of all the Mac has to offer, this is a working model of how to do it. All of this in a 2.5MB download.

Also interesting is that the project is covered under two separate open source licenses, thanks to a special exemption.
Design Element
How Transmission Does Cross-Platform
Posted Jan 31, 2008 — 17 comments below




 

ACoolie — Jan 31, 08 5423

I totally agree. I've been following Transmission svn for a while now (and wrote some personal hacks as well), and I really enjoy it. You should also mention how they separated it more than just "core", "osx", and "linux," as the article says. They have a BeOS, CLI, daemon, GTK, and OS X version, all native code.
Oh and you can post snippets of MIT source code.

Kevin Ballard — Jan 31, 08 5424

It's too bad they don't support encryption/proxies (at least one of those, but I don't remember which and I'm not going to bother re-downloading just to find out).

Chris — Jan 31, 08 5425

The real issue for me is no support for https trackers.

Dirk Stoop — Jan 31, 08 5426

Another example of a cross-platform app with a decent Cocoa Mac UI is Miro.

Funny coincidence that both are open source projects. Does anyone know of a closed-source app other than those in the huge suites (Office, Creative Suite) that has a proper Mac UI?

Jeff Greene — Feb 01, 08 5427

Transmission supports encryption and prefers to use it by default. It does not yet support SSL with the announce URL. As for proxies, I'm not quite sure why you would want to use one. If you really want to, I think you can set up SSH tunneling to act as a proxy for BitTorrent.

Transmission is really wonderful lightweight, yet powerful BitTorrent client. It just keeps getting better with each new version.

Jeff Greene — Feb 01, 08 5428

To follow up on Dirk's question:
Does anyone know of a closed-source app other than those in the huge suites (Office, Creative Suite) that has a proper Mac UI?

Commercial software tends to be either originally developed for Windows and ported to Mac OS X using Carbon, or written to be cross-platform from the start. Usually the latter is written in Java. Mac OS X with Cocoa offers many unique features that are available solely for Mac OS X. It is hard to write a native Mac OS X application without writing it from the ground-up.

The only cross-platform commercial software that is written in Cocoa that I can think of is Skype. Skype did something similar to Transmission and uses the Skype framework as the back-end to the native Cocoa application.

Scott Stevenson — Feb 01, 08 5429 Scotty the Leopard

@Dirk Stoop: Does anyone know of a closed-source app other than those in the huge suites (Office, Creative Suite) that has a proper Mac UI?

Does World of Warcraft count? Anyway, it looks like Quicken is heading that way.

Rob Keniger — Feb 01, 08 5430

I'm actually surprised that Microsoft, Adobe and the other big cross-platform companies don't do this with their software. If you think about Photoshop for example, it's basically just a UI on top of a lot of matrix math. It seems especially short-sighted because Apple has been essentially deprecating Carbon for a while and at the last WWDC did so officially.

It would seem to be straightforward to make the UI platform-specific and the underlying image processing code cross-platform. That way you'd have an app that looks and works great on Mac and Windows, the platform-specific teams could make use of platform-specific niceties and yet the application itself would be the same underneath. It's not like Adobe and Microsoft don't have enough programmers to be able to do this.

I did notice that Adobe Lightroom has a Cocoa wrapper around Lua guts and so obviously some parts of the company are moving this way.

George Sudarkoff — Feb 01, 08 5431

@Rob Keniger: You underestimate the amount of code that goes into something like Photoshop. It'll take them a few years to rewrite everything.

VMware Fusion has a proper Cocoa UI. Skype on the other hand is written with QT.

Jussi — Feb 01, 08 5432

This is exactly what I have been advocating for a long time. A *native* GUI and portable backend.

It's the only way to go if a good UI is a priority (and it usually should be). Cross platform toolkits usually make the UI look and feel non native on *all* platforms.

Sure making the UI natively on all platforms may seem like a waste of developer resources and money, but I would argue it is not. Even with cross platform toolkits serious tweaking is needed if good UI is needed and the UI is the most important thing for the user and will increase sales

Fabio Mancinelli — Feb 01, 08 5434

This is a good application of the MVC pattern, pushed to a higher level...

The model il the internet and the BitTorrent "space". The controller is the libtorrent and the view is the UI (for Mac, Win, Linux, Whatever)

Not an easy thing to do though! :)
So kudos for the great design.

jjgod — Feb 01, 08 5435

@George Sudarkoff: Do you have any proof to say that Skype on Mac is written with Qt? I checked the bundled executables of Skype.app, but seemed unable to find any traces.

j o a r — Feb 01, 08 5436

Skype is a Cocoa app, something you can tell immediately from just using it, but also verify by checking the binary (using "nm").

Vincent Murphy — Feb 01, 08 5437

I recall an interview with a member of the team that ported MindManager to Mac and he said they did the same thing; their Windows version had a seperate backend.

Jeff Greene — Feb 01, 08 5438

@George Sudarkoff: Skype on the other hand is written with QT.

The Mac OS X version of Skype is written in Cocoa, however you are right that Skype is written in Qt if you are talking about the Linux version.

Erik — Feb 02, 08 5440

Is it just me or does there appear to be a bug in the snippet code? "onState" and "offState" are initialized to NO, and then in an if/else statement one of them will be set to YES. But only one of them. Then there is a check to see if they are both YES, which doesn't seem like it could ever be true, even with multiple threads, since the values being tested are stack variables.

Erik — Feb 02, 08 5441

Oh, sorry. I just noticed that this is happening in a loop, so of course it's possible for both to get set to YES. Please disregard my ignorance.




 

Comments Temporarily Disabled

I had to temporarily disable comments due to spam. I'll re-enable them soon.





Copyright © Scott Stevenson 2004-2015