cordova.qt.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright 2011 Wolfgang Koller - http://www.gofg.at/
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. Cordova.Qt = {};
  17. /**
  18. * Execute a call to a plugin function
  19. * @return bool true on success, false on error (e.g. function doesn't exist)
  20. */
  21. Cordova.Qt.exec = function( successCallback, errorCallback, pluginName, functionName, parameters ) {
  22. // Check if plugin is enabled
  23. if( Cordova.plugins[pluginName] !== true ) {
  24. return false;
  25. }
  26. // Store a reference to the callback functions
  27. var scId = Cordova.callbacks.length;
  28. var ecId = scId + 1;
  29. Cordova.callbacks[scId] = successCallback;
  30. Cordova.callbacks[ecId] = errorCallback;
  31. parameters.unshift( ecId );
  32. parameters.unshift( scId );
  33. window.qmlWrapper.callPluginFunction(pluginName, functionName, JSON.stringify(parameters))
  34. return true;
  35. }
  36. /**
  37. * Function which is called from the native bridge in order to register the QtWebKit bridge objects
  38. */
  39. Cordova.Qt.objects = {};
  40. Cordova.Qt.registerObject = function( pluginName, pluginObject ) {
  41. Cordova.Qt.objects[pluginName] = pluginObject;
  42. }
  43. Cordova.exec = Cordova.Qt.exec;