[Development] Proposal: expose the OS/platform in QML

Rutledge Shawn Shawn.Rutledge at digia.com
Wed Jan 16 11:22:18 CET 2013


On 16 Jan 2013, at 8:21 AM, Bache-Wiig Jens wrote:

> True. It is exactly what we would use to implement the platform selector. But it can also be more powerful than that because it makes it possible to implement your own platform selectors if you disagree with whatever mechanism we come up with. (i.e you can create a loader that takes dpi, os, orientation and resolution into account)
> 
> I wonder how useful it is to know the platform plugin though. I.e I don't really care if I am on wayland or x11 or when writing QML. If I did, I would probably we writing a C++ extension.
> 
> What I primarily care about is if I am on "mac", "windows", "linux", "android" or "iOS". This is information I would use quite often and only exposing that would be a good start.

Where should we put that information?  Orientation, resolution etc. will be in Screen.  I wonder if this gives us another reason to rename the Window module to something more inclusive like System or Device.  Then it will make sense to expose all the device-specific stuff in the same module.  I want to rename it anyway to avoid having the present situation that you import QtQuick.Window in order to create a Window (and get some other stuff that comes along for the ride).

> Second, it would be useful to know if I am on a "phone", "tablet" or "desktop" platform. ( can already guess by the resolution but perhaps it would be convenient to abstract it a bit.

That's a short-term classification, and anyway other types of devices are coming.  In a couple of years it will probably seem quite anachronistic to make a distinction between just those three.  What's a Galaxy Note, a phone or a tablet?  It's both.  The trend is that even laptops are getting touchscreens and touch UIs, and desktop machines without touch are being minimized.  What's more important is the physical size of the screen, how many physical pixels are in a virtual pixel (although I still think that's a dubious concept), whether you have multiple touch support, and if so, how many fingers.  Finding out about the touch support needs to be in this System/Device/whatever module too (probably as a property of the Screen).  Likewise I plan to add the orientation from the accelerometer soon.

OTOH we need to encourage app authors to write as generic code as possible to make them as portable as possible.  We can expose more information, but using it to customize the UI should really be discouraged.  Otherwise it could turn out like the web javascript nightmare, having to customize for different browsers, especially before HTML 5.  So from that perspective maybe exposing too much is wrong, because it will enable this scenario.

> And eventually I might want to know even more. Such as the desktop environment I am using on linux,

Yeah we already have that info, we can easily expose it.

> +1 for the idea from me. But not exactly as proposed.
> 
> I think we can start with just the "os" part and add other things later. And I think we need might need a different set of attributes from each platform. What if we make it possible to query the platform plugin for platform specific details, i.e like:
> 
> I.e  if (Platform.os == "iOS" && 
>          Platform.property("deviceType") == "iphone" && 
>          Platform.property("deviceVersion") == "3G") ...
> 
> This way the platform plugins could add all the platform dependent properties in a clean fashion. There are plenty of things like the current GNOME theme and such that could be added which it would not really make sense to pollute the API with. 

Yes dynamic properties seem like a good idea for things that will not always be there.




More information about the Development mailing list