← Back to team overview

ubuntu-accomplishments-contributors team mailing list archive

Accomplishments in Ubuntu SDK apps

 

Now that there's an Ubuntu SDK for writing QML apps, it'd be cool if it were possible to handle accomplishments from inside those; I imagine there'll be lots and lots and lots of QML apps written now that the SDK exists, and if Accomplishments were available in there from the beginning, there's a good chance that it could become the "default" system for Ubuntu apps which want to do some sort of achievements thing.

The API I'd propose (as a starting point for discussion) would look kinda like this (you'll want to understand a bit about QML for this):

-------8<------ myapp.qml

import QtQuick 2.0
import Ubuntu.Accomplishments 1.0

Rectangle {
    width: units.gu <http://units.gu>(30)
    height: units.gu <http://units.gu>(20)

    Label {
        text: "Click me to accomplish something :)"
        anchors.top: parent.top
        anchors.horizontalCenter: parent.horizontalCenter
        MouseArea {
            anchors.fill: parent
            onClicked: {
                accomplishmentsModel.accomplis
h("first-click")
            }
        }
    }

    ListView {
        id: stuffYouHaveAccomplishedAlready
        height: parent.height / 2
        anchors.bottom: parent.bottom
        width: parent.width
        model: accomplishmentsModel
        delegate: Label {
            text: name
            visible: accomplished
        }
    }

    Accomplishments {
        id: accomplishmentsModel
        collection: "myapp"
    }
}
-------8<------ myapp.qml

(bear in mind that I've just written this straight into an email; it isn't tested)

So, the Accomplishments object is a ListModel with ListElements for each accomplishment in the named collection (assuming that the app has its own collection, which it will have), and each ListElement has name, accomplished (a boolean), description, etc attributes. That makes it The Accomplishments object also has an accomplish(acc_id) method which lets you accomplish an accomplishment by ID (this isn't on the ListElement because there's no way to find a ListElement by ID other than by iterating the whole list).

Make sense? I really think there's a chance that if this gets into people's heads early then everyone will just routinely start using it, which could be a massive boost to the Accomplishments project's popularity. Building a little Python wrapper to test this should be trivial (creating a ListModel in Python and inserting it into QML is really easy), although the Real Version ought to be C++ of course so that people can use it in non-Python apps (I am expecting that quite a lot of apps written with the SDK will be pure QML with no other code at all).

sil