4

I can share an item easily using an InvokeActionItem in a Page but I need to be able to call it in a listview item. I've managed to trigger an invoke, but I cannot figure out how to add data when triggering it. I keep getting an error message of

InvocationPrivate::setQuery: you are not allowed to change InvokeQuery object

Note: I am trying to do this in purely QML, I will do it via c++ if necessary but QML would be preferable.

Code that works inside a Page object:

actions: [
    InvokeActionItem {
        ActionBar.placement: ActionBarPlacement.OnBar
        title: "Share"   
        query {
            mimeType: "text/plain"
            invokeActionId: "bb.action.SHARE"
        }

        onTriggered: {
            //myTextProperty is a string variable property for the page.
            data = myTextProperty;                
        }
    }
]

The code I've tried to use in the other item is as follows, but does NOT work:

Container {
gestureHandlers: [
    TapHandler {
    LongPressHandler {
        onLongPressed: {
            console.log("Longpress");                

            invokeQuery.setData("test");

            invokeShare.trigger("bb.action.SHARE");
        }            
    }        

]

attachedObjects: [
    Invocation {
       id: invokeShare
       query: InvokeQuery {
           id:invokeQuery
           mimeType: "text/plain"         
       }   
    }
]
}

Is there a way to change the data for an invoke purely with QML or do I need to just run it through c++ instead?

hyarion
  • 2,251
  • 2
  • 17
  • 28

3 Answers3

11

After a fair amount of browsing forums and testing various methods, I have finally found one that works.

Add the following in your attachedObjects:

attachedObjects: [      
    Invocation {
       id: invokeShare
       query: InvokeQuery {
           id:invokeQuery
           mimeType: "text/plain"                        
       }
       onArmed: {
           if (invokeQuery.data != "") {
               trigger("bb.action.SHARE");
           }
       }             
    }
]

Then wherever you need to call the invocation do the following:

invokeQuery.mimeType = "text/plain"
invokeQuery.data = "mytext";
invokeQuery.updateQuery();

Note that if you do not do a check in the onArmed for data it will automatically call the invocation on creation - in the case of a listview this can result in 20+ screens asking you to share on bbm... ;)

hyarion
  • 2,251
  • 2
  • 17
  • 28
  • Working for me - thanks for posting. Where was this documented? – JeffAtStepUp Feb 07 '13 at 23:58
  • 1
    I'm afraid I don't remember, I searched through many threads on the blackberry forums, let alone blogs and such, tried many many variations and options, none of which worked for me, eventually one of the forum posts had this as a snippet but I never bookmarked that page. – hyarion Feb 11 '13 at 13:04
  • I still get a `InvocationPrivate::setQuery: you are not allowed to change InvokeQuery object` message in the logs, but everything works. – JeffAtStepUp Feb 11 '13 at 18:03
1

You can actually use the InvokeActionItem, you just have to call updateQuery to retrigger the invokeQuery. When the ListItemData changes, the binding will cause the values to update.

InvokeActionItem {
      enabled: recordItem.ListItem.data.videoId != undefined

      id: invokeAction
      query{ 
            uri: "http://www.youtube.com/watch?v=" + recordItem.ListItem.data.videoId
            onQueryChanged: {
                  updateQuery()
            }
      }

}
sbirksted
  • 62
  • 2
  • Thank you, that's very useful to know! At the time of posting the original question the qml for bb10 was much more limited and your solution might not have worked. – hyarion Oct 09 '13 at 07:32
1

For remove "InvocationPrivate::setQuery: you are not allowed to change InvokeQuery object" message I use this:

attachedObjects: [      
    Invocation {
        id: invoke
        query {
            mimeType: "text/plain"
            invokeTargetId: "sys.bbm.sharehandler"
            onDataChanged: {
                console.log("change data")
            }                   
        }
        onArmed: {
            if (invoke.query.data != "") {
                invoke.trigger("bb.action.SHARE");
            }
        } 
    }
]

function shareBBM(){
    invoke.query.setData("TEXT TO SHARE");
    invoke.query.updateQuery();
}
NoblinkDev
  • 11
  • 1