[Development] Platform Content Selection

Alan Alpert 416365416c at gmail.com
Tue Jan 8 02:03:05 CET 2013


With the new cross-platform focus, we need some way for QML to load
platform specific content at runtime. I've put the in-depth "why"
essay on my blog (http://alan.imagin-itis.net/?p=416) - most people
have been telling me this for years and thus need no convincing. But I
think that as a cross-platform feature, this will probably work better
inside Qt than implemented per platform (like they are now).

What I suggest is a path based swap-out like Plasma has, but a little
more generic than being tied into the Plasma Package format. Here's
the basic algorithm for swapping, where platformSelectors is an
ordered list of selectors specified for the platform (e.g. for the
BB10 dev alpha it might be "dev_alpha bb10 phone touch")

inPath = "/path/to/"
inFile = "file"
def platformSelectedPath(inPath, inFile, platformSelectors):
    foreach selector in platform-selectors:
        prospectivePath = inPath + "/" + selector + "/"
        prospectiveSubPath = platfomSelectedPath(prospectivePath,
inFile, platformSelectors - selector)
        prospectivePath += inFile
        if prospectiveSubPath != prospectivePath
            return prospectiveSubPath
        if fileExists(prospectivePath)
            return prospectivePath
    return inPath + inFile

Here's an example directory structure

main.qml
Chrome.qml
Content.qml
settings.js
android/Chrome.qml
android/phone/settings.js
android/tablet/settings.js
phone/settings.js
tablet/settings.js

Key differences from the Plasma approach is the recursing, the
directories being local to the content, and imagining a wider range of
generic selector strings. I imagine the selector strings will just be
any alpha-numeric words, and leave it to later convention to determine
what 'buckets' work best.

Qt Feature:

This would presumably mean adding a feature to Qt, likely QtCore, with
an API looking roughly like this
static QUrl platformSelectedPath(const QUrl& basePath, const QUrl&
selectedPath);
with platformSelectors coming from the configuration/mkspec or an
environment variable (variable takes precedence). basePath and
selectedPath are inPath, inFile respectively from the pseudocode (but
the algorithm doesn't force inFile to be just a file and not a
sub-path, that's a QML choice).

QML Feature:

The QML engine could then optionally (if a flag is set) use this
function for all local file resolution, probably by inserting it into
the string->url parsing. It would always have just the file as the
selectedPath, and would leave the recorded directory of the file to
always be that of the base file, no selectors, so that further type
selection is unaffected by the swap-out.

Note this isn't the same problem as where the main.qml file is on
various platforms, this all works relative to a QML file URL that the
engine already got.

Feedback?

It's really Qt that's cross-platform focused now, not me. I just want
this so that SameGame runs beautifully on BB10 :) . So while I'd
welcome feedback from any source, I *need* to hear it from people
interested in other platforms (or even just cross-platform
development!).

--
Alan Alpert



More information about the Development mailing list