Network status aware apps

Am I online or not?

There is a summary at the end for the quick readers.

It is in many modern applications important to be able to more or less gracefully handle if the application user is online or not. For example, there is no need to try to fetch emails if the device (computer, phone, tablet, laptop, …) doesn’t have network (wifi, cable, umts, ip over avian carriers, ..).

KDE has of course made nice functionality for this, and here I will try to describe how to make your app network status aware and what to be aware of in the process.

Solid background

All this is going on in Solid, using two parts of Solid and a bit of KDE’s infrastructure:

  • libsolid
  • networkstatus KDED module

The networkstatus KDED module is trying it best to gather information from the computer to see if one is connected or not. It has the possibility to gather information from various sources, and handle changes and such.

The as of writing available sources that the networkstatus module gathers information from is

  • Network Manager
  • wicd
  • asking the linux kernel thru the abstraction layers ntrack and libnl
  • …connman might be work in progress

Collecting from different sources is important, because some people might have configurations like “Manage wireless thru wicd”, “manage umts dongle with Network Manager” and “manage wired network with /etc/network/interfaces” and all of it needs to be combined.

Solid reports, if wicd thinks “online”, and network manager thinks “offline” that the user is Connected..

Solid States

There is a enum with 5 values in Solid to describe the current state of the network:

enum Status {
Unknown,
Unconnected,
Disconnecting,
Connecting,
Connected
};

Connected is the easy state. Here, Solid knows that you are having some kind of connection according to at least one of the sources. But it might just be a local network connection, and not actually a internet connection. So one here should handle connection failures gracefully.

Unconnected is a similar easy state. Here, Solid knows that you don’t have any internet connection according to the sources it knows about. One should here not try to do any networking.

Connecting and Disconnecting is that a state change is happening, so that you can prepare to react on it.

Solid also has the state of Unknown, used for cases where Solid doesn’t have the required data to actually know it. A example could be a system without any of the data providers. You should here probably try to connect, and be able to handle failures gracefully. Also described as ‘Proceed with caution’.

The bright reader might here notice that one both in the Unknown and Connected case actually should do the same.

Querying for network status

At any given time:

Solid::Networking::Status currentStatus = Solid::Networking::status();
if(currentStatus==Connected || currentStatus==Unknown) {
//try to do networking things
} else {
//mark application as offline.
}

Here, we first query Solid for current status, and then if the state is Connected OR Unknown, then we proceed.

Getting notified

Maybe you don’t want the roundtrip of asking (resulting in a dbus rountrip each time) when you need to know the state changes. Then you of course can get notified.

class MyNetworkAwareClass : public QObject {
Q_OBJECT
public:
MyNetworkAwareClass();
void doNetworkActivity();
private Q_SLOTS:
void networkStatusChanged(Solid::Networking::Status newstatus);
private:
Solid::Networking::Status m_current_state
};

MyNetworkAwareClass::MyNetworkAwareClass : m_current_state(Solid::Networking::Status()) {
connect(Solid::Networking::notifier(), SIGNAL(statusChanged(Solid::Networking::Status),this,SLOT(networkStatusChanged(Solid::Networking::Status)));
}
void MyNetworkAwareClass::networkStatusChanged(Solid::Networking::Status newstate) {
m_current_state = newstate;
}

void MyNetworkAwareClass::doNetworkActivity() {
if(m_current_state == Unknown || m_current_state == Connected) {
//try to do network activity
}
}

I guess this should be pretty self explaining.

Summary

  • Ask Solid::Networking::status() for network status
  • Connect to statusChanged(Solid::Networking::Status) from Solid::Networking::Notifier to be aware of changes
  • Treat the states Unknown and Connected the same way.

Oh. And I’m out looking for a job.

Posted in english, kde

First Plasma Active experience

John Layt recently blogged about his adventure with having children use Plasma Active with quite some success.

The task

I was this evening out at a board meeting in my local scout group, and for such a event you of course need the following

  • Agenda
  • Treasures report
  • Minutes from last meeting
  • Various other papers

I’ve heard from various people that an iPad is great for such meetings, and produces much less paper waste, so of course, I wanted to try with my brand new Plasma Active tablet.

Before meeting

So before meeting: Charge tablet & fetch needed documents.
Possible issues: Everything was on a my imap server. Minutes was a plain text file, Agenda was a docx file, treasures report was a xls spreadsheet, and the various other papers were pdf files.

For fetching, I’ve heard a lot about Kontact Touch and everything using Akonadi. Besides me not being fully able to properly enter my password in the first 10 tries, and a sometimes flaky internet connection, everything here was a breeze.

To the three first documents, the answer was ‘Calligra Mobile’. Rendered even the docx file better than libreoffice did. And Calligra Mobile was nice and touch friendly and worked pretty well for this. There is also something called ‘Calligra Active’, which is supposed to be way cooler, but still misses at least one essential feature to be used for a touchscreen only. It can only open documents passed to it on command line. And I’m not yet very comfortable with a onscreen keyboard.

For the last, there was Okular. The desktop edition of Okular. I was impressed by *how* usable Okular were for a touch screen device. A quick and dirty edition of a mobile Okular could probably be done with ‘remove all toolbars and menubars and such’ and ‘if no file is passed on command line, then open a file selector window and open selected file’, which shouldn’t take a person knowing the Okular code much time. But that’s still just the ‘Quick and dirty edition’

During…

And during the meeting, everything worked flawlessly, except the internet on site, so I was happy I had prepared in advance. As a extra bonus, Plasma Active offered the nice KDE Games, as John Layt also mentioned, for the parts of the meeting where it was a bit boring.

So. At least for me and in this case, Plasma Active did its job, at least to a A. And it is still described as Alpha software.

Issues

There is, though, a few important usability issues:

For QWidget based applications, oxygen’s nice desktop feature of being able to move the application by dragging it from almost everywhere is just completely useless on a touch screen device when you are only using full screen applications. Luckily, oxygen-settings can disable this.

Update: People tells me that this has already been fixed.

The Network Manager Plasma Widget, in case of ‘no network’, is very hard to ‘activate’ in order to select a network. A bit larger touch area here would be very nice. Currently, it feels like it is only slightly larger than a dot:·.

Future

Oh boy, I’m looking forward for Plasma Active getting to Beta or RC status. Or Final!

And btw, I’m looking for a job.

Posted in english, kde

Desktopsummit, jobs, prison and such

It’s been a while since I last blogged, and some things has happened.

Jobs
I’m out looking for a job. Preferably KDE/Qt or Debian related. Or at least opensource related. Feel free to contact me if you know of anything. sune AT vuorela DOT dk

Desktop Summit

I’ve been at Desktop Summit, awesome as usual to see all these great people, except monday morning. I think intel is partly to blame here :-).

  • I got to a set of exciting talks, including one about a toaster.
  • I got to meet some nice people, both old and new
  • I hacked a bit on libprison
  • I walked along the Berlin Wall, sat and enjoyed Brandenburger Tor and other parts of Berlin
  • Learned to feel ‘home’ in Berlin public transportation

Prison and such
The upcoming release of Prison will at least have a couple of new features, beside a couple of bugfixes:

  • It is now possible to set the colors to be used for the barcodes. That’s going to be nice in some cases.
  • I have a patch in my mailbox adding EAN13-support from a brand new contributor. It just needs a bit of polishing and then ready to go

I’ve also started to enjoy -Werror=unused-but-set-variable in GCC and killed some of those in KDE land.

end

There is more to come later, hopefully things about the ExoPC I gotborrowed at Desktop Summit, which is now running Plasma Active & Contour.

Things about a new librison release, and maybe more places to use libprison.

Oh. And yes, I’m out looking for a job.

Posted in debian, english, kde

Daemon slaying

I’ve gotten a couple of complaints on the amount of daemons that is launched by default by any app built upon the KDE Frameworks, so I investigated one of them a bit.

The knotify daemon currently seems to do two things:

  1. Keeping some dependencies out of KDE Framework libraries
  2. Recieve messages from dbus, parse them, encode differently and send them on to other places over dbus

In the past, the knotify daemon was also responsible of showing popup-messages.

So, I did a quick experiment here in Switzerland to try kill off that daemon and merged the code from the daemon into the KNotification part of kdeui.

As a proof of concept it works, and if I can cut out some of the newly introduced dependencies it can end up being really nice. There is much less need for a separate daemon these days where knotify doesn’t actually paint the popups itself, but rather passes them on to a galago-spec implementing part of the workspace (on linux) or to growl for various non-free platforms.

Posted in english, kde

Five is a four letter word

and it starts with f…

While looking at the future of the KDE Platform Frameworks here in Randa, Switzerland, a lot of interesting things has been found in kdelibs and kdepimlibs

  • KSortableList
  • KTypeList
  • KAscii

that no one knew what was there for.

On the good side, there is also lots of cool stuff, that of course most people knows about and uses

  • A real nice job based api
  • Nice library for figuring out when there is holidays and special dates in different countries
  • IMAP library
  • Compression library
  • Hardware access library

And a lot of great larger solutions for solving different real life problems

  • Akonadi
  • KIO
  • KParts

And lots of other cool stuff

  • I really like the KDE plugin framework
  • KIO slaves are great
  • Kontact master is great
  • Aaron is wearing pink
  • Plasma Active seems cool
  • The chefs are making good food, even though sometimes lacking a bit of meat

And we have currently nice things in the ‘required runtime components for every app built using kdelibs’

  • Finger KIO slave
  • Floppy KIO slave
  • Weird cornercase user tools, some of them broken
Posted in english, kde

Barcodes, Weather and other nice things

Long time no blogging.

Earlier, I wrote a blog post about transporting data to mobile phones. I have since then extracted the Data Matrix code I wrote there into a separate library, prison and added support for QR Code as well. So from KDE’s next feature release, versioned 4.7 arriving around first of august, you have DataMatrix and QRCode support in Klipper.

While on a barcode spree, I also added barcode support to the KDE Addressbooks for easy transfer of contacts. Also using libprison. Also available from 4.7 onwards.

Few minutes ago, libprison 1.0 was tagged and hopefully soon, the KDE Sysadmins will publish my tarball.

And about the weather. Some nice people wrote Debian Weather which in simple ways shows if it is unsafe to upgrade. Quite recently there have been thunderstorms and heavy rain in Debian Unstable. Perl rain.
I have recently added support for Debian Weather in the Plasma Dataengine for weather. Also available from 4.7 onwards.

Last but not least, after spending a couple of hours on trying to understand Q3PtrList and how it was used in KHelpCenter, it is now, as the last component in KDE-Runtime, free of Qt3Support.

All for now. Next up. Platform_11

Posted in debian, english, kde

Håndværkere

Hvorfor er det så svært at finde en maler der har tid til at lave noget for mig i København NV?

“Kalenderen fuld ind til december”

Posted in danish

Previous weekend in Debian KDE land

3 interesting small things happened in the weekend.

Due to the hard work of mostly Florian Reinhard and George Kiagiadakis, Bluedevil is now available. Bluedevil is a new and improved bluetooth handling thing targetted the KDE Workspaces.

The Debconf people have uploaded the Qt Debconf frontend that I blogged about a while ago, so now it should be available.

Last, but not least, applications now has more accurate data for if they are online or not, by using the ntrack library. This was especially problematic for people having some interfaces defined in /etc/network/interfaces, and other interfaces managed by NetworkManager.
This feature will be committed to upstream KDE whenever Will gets around to do it.

As a added bonus, KDEBindings in Debian has seen a release critical bugfix (python plugins, e.g. plasma widgets, related), and the brokenness of Konsole (libkpty) on the kFreeBSD-arches have been tracked down to a libc issue and a patch has been made.

All of this is expected to be part of next stable Debian release, codename Squeeze.

Posted in debian, english, kde

Transport data easily to mobile phones

I guess we all have the challenge of how to easily get a link or a phone number or some other strings of data from the computer to the mobile phone.

With the help of mobile barcodes and klipper, this is now possible in KDE Trunk to do easily. Place some data in clipboard, click on klipper and select Show barcode.

show barcode option in klipper menu

Mobile barcode in klipper

To read it, open the barcode app in your phone (mBarcode on n900 for example) and point it to your monitor.

Posted in english, kde

debconf kde frontend

I wrote another blog post a while back talking about Debconf kde frontend.

I spend some days at akademy looking at it, and then refined it a bit when I got home.
Results:

  • perlqt is in unstable and soon in testing.
  • debconf kde frontend works.
  • object oriented perl is weird

debconf kde frontend in action.

hopefully, the debconf people will accept it soon.

Posted in debian, english, kde