Submit A Tip Alternative Tip Form

Contractor brings seamless file sharing between apps to the Linux desktop

My chief complaint when it comes to the general schmaltzy “feel” of the Linux desktop concerns the disparate experience one encounters between various desktop applications.

This is to be expected: after all most applications are developed by different teams, in different places with different ideas and agendas.

Nevertheless you need only look at Ubuntu for proof that bridging these varying gulfs, dips and holes in user experience can benefit users. From indicator-applets to consistent menus: Ubuntu has strived to make the user-experience a cohesive and expectant one – its pole position as distro grandé is proof positive of this.

But it could be better, and that’s where Contractor comes in.

Removing the need for file management one app at a time

Contractor is new ‘sharing service’ developed by Allen Lowe for the elementary project. It allows applications to push/send data/files to other applications without the applications needing to be hard-coded to do so. Think of it as a middle man that relieves both applications of having to work with each other – they just need to work with Contractor.

Dan Rabbit put it succinctly when he told me that ‘It’s a way for applications to talk to each other without really knowing who they have to talk to.’

‘Let me do that for you’

Allen Lowe, the developer tour de force behind Contractor, shares an example: -

“Say you receive an image attachment via e-mail in Postler (elementary’s e-mail application) that you decide you like so much you want to upload it to your Facebook account. How do you do it currently? You save the image to disk, open your browser or Facebook app and upload the saved file manually.

…upload that email attachment to Facebook in one click instead of 20.

With Contractor it’s much simpler. The Facebook application can register itself with Contractor and say “I can handle images.” Postler can then ask Contractor “What apps handle images?”. Contractor returns a list, of which the Facebook application in our example would be in, letting you upload the email attachment to Facebook in one click instead of 20.”

The possibilities are varied, too. As long as an application is registered with Contractor to handle/use a specific file type it can be ‘shared’.

“If I want to email a vCard, I just choose the contact in Dexter, click the share menu, and choose email with Postler. ”

And this ‘action’ doesn’t result in the whole of the destination application opening either, just the part needed – in this case Postler’s ‘Compose’ window with the vCard pre-attached ready for sending.

It does more than just opening another app

For example, when you choose “Send by email” for the Postler contract, the entire Postler application doesn’t open. Only the “Compose” window with your attachment opens. And when you’re done sending that mail, the compose window is gone, Postler is closed, and it’s like you never even left your original app in the first place.

Android users will already be familiar with how such a service works – just press the menu button next time you’re viewing a picture ;)

So how does Contractor work?

First “links” are created between Contractor and ‘destination’ apps. These ‘links’ are called ‘contracts’.

“I thought of Contractor just like a building contractor: I come to you and say “build this” and then you figure out who will do what. So an app signs a ‘contract’ with Contractor stating that it can handle THISTYPE of data.”

Contractor then reads its directory of .contract files, parses them into a big dictionary and then uses that to return either a full list, or filtered list based on mimetype, to the ‘source’ application.

s1tVT4xRkN4sWMU2Lir13Dw

“It sends that data over dbus and the app just executes the given command.”

How hard is it for developers to add contractor support to their applications?

Neat solution – but is it a slog to achieve? I asked Allen how difficult it would be for an application developer to add Contractor support to their own application.

“To add contractor support to an app is easy. I wrote a PyGTK Tool menu that has a simple API. We will also write a Vala one. All you need to make a contract is a command line interface for that app, and the .contract file.

Once the .contract file has been made just drop it into in /usr/share/contractor.

Allen does state that ‘the library for the menu is part of Dexter, but it is VERY easy to separate’ and that ‘anyone interested in adding it to their app already they should just come talk to me in #elementary on freenode.”

Current application support

It may be early days for the service but elementary contacts app Dexter is already making use of it, letting you quickly e-mail vCards via Postler.

What about other apps? Dan Rabbit gave me a heads up on that score: -

“We may provide some contracts for other 3rd party apps also like Brasero and Empathy. We’d love to see Shotwell add it, too. That would be a huge win for the desktop as they already have a way to interface with Facebook, Flickr, etc.”

Download

A stable release of Contractor, along with Dexter which makes use of the service, can be installed from the Dexter PPA @ launchpad.net/~lallenlowe/+archive/dexter-ppa

Thanks to Allen Lowe
Fabian Thomas for the super neat infographic