In the last days I have been trying to figure out how to "enable" Mobile Broadband modems by default. By "enable" I mean make the modem powers up when it is attached to the computer. NetworkManager and ModemManager require the modem to be "enabled" before using it.
I have always thought it should be something simple like modem = Solid::Control::ModemManager::findModemInterface(...); modem->enable(true). Actually that sample code works... for root only. ModemManager protects most of its DBus interface through policy-kit, so I had to figure out how to do it for normal users without asking for a password. As you probably know, Plasma NM run as normal user, not root. Time to take a look at how nm-applet does that.
After some digging in nm-applet source code I found this function nm_client_wwan_set_enabled. I have never seen that "wwan" interface in NetworkManager specification, the public specification did not mention it some days ago. In the end I figured out wwan is a synonym for mobile broadband. Today I have looked at the specification site again and now there is a 0.9 specification that mentions wwan, although NetworkManager 0.8 supports wwan but the 0.8 specification does not mention that, cool, huh?
Anyway, now that I know those functions are there, I have updated Solid::Control::NetworkManager to make use of them. The changes are already in kde://kde-workspace and kde://networkmanagement, they are going to be available in KDE SC 4.7. The visual changes in Plasma NM are very small, just a new checkbox called "Enable mobile broadband". The checkbox is visible only when there is at least one Gsm/Cdma modem attached. Following the same idea, I have changed the "Enable wireless" checkbox to also be visible only when there is at least one wireless card attached.
When you attach a modem to your computer ModemManager disables it by default. NetworkManager disables wwan if all modems are disabled, which means everytime you attach a modem NM will disable wwan. Even worse, if you have two modems, attach the first, enable wwan, attach the second modem, NM will disable wwan because the last modem is disabled. Nm-applet also demonstrates the same behavior in my tests. I think that explains why sometimes when my notebook is connected through 3G and I attach my cellphone in "PCSuite mode" to my notebook the 3G connection drops. To workaround the enable/disable problem I am using a QTimer::singleShot(...) to enable wwan after NM disables it if the mobile broadband checkbox is checked. Seems to work.
Now that I can enable/disable wwan the next thing to implement is saving the plasmoid configuration. Plasma NM is splitted into two parts, one plasmoid and a kded module. The kded module already saves its configuration, it is responsible to talk to NetworkManager and ModemManager and manages all interfaces. Of course the plasmoid is the user interface, it does not save its configuration yet, that is why everytime you resume from ram or disk the wireless state is on, it is on because your computer's BIOS set it to on, not Plasma NM. Plasma NM just reads the wireless state from NetworkManager.
The plasmoid state is just those three checkbox (Networking, Wireless and Mobile Broadband). I plan to save those three state to a configuration file and restore them when Plasma NM is started or resumes from ram/disk. So if the user set wwan to enable and attaches a modem to his/her computer, the modem will be be enabled after a short flux of DBus calls. Use dbus-monitor to see what I am talking about :-)