/** * Implementation of standard API exposed to JavaScript * This function is used to detect different messages from JavaScript * and call the respective function in MoSync. * * @return true if stream was handled, false if not. */ bool ResourceMessageHandler::handleMessage(Wormhole::MessageStream& stream) { char buffer[512]; const char * action = stream.getNext(); if (0 == strcmp("loadImage", action)) { const char* imagePath = stream.getNext(); const char* imageID = stream.getNext(); // Load the Image resource. MAHandle imageHandle = loadImageResource(imagePath); if (imageHandle > 0) { sprintf(buffer, "mosync.resource.imageLoaded(\"%s\", %d)", imageID, imageHandle); mWebView->callJS(buffer); } else { // TODO: Better way to inform about the error? // Call JS function with error code? // mosync.resource.imageLoaded(<imageID>, -1) ?? char errorMessage[1024]; sprintf(errorMessage, "@@@ MoSync: ResourceMessageHandler could not load image: %s", imagePath); maWriteLog(errorMessage, strlen(errorMessage)); } } else if (0 == strcmp("loadRemoteImage", action)) { const char* imageURL = stream.getNext(); const char* imageID = stream.getNext(); MAHandle imageHandle = maCreatePlaceholder(); mImageDownloader->beginDownloading(imageURL,imageHandle); sprintf(buffer, "mosync.resource.imageDownloadStarted(\"%s\", %d)", imageID, imageHandle); mWebView->callJS(buffer); } else if (0 == strcmp("DestroyPlaceholder", action)) { MAHandle handle = stringToInteger(stream.getNext()); maDestroyPlaceholder(handle); } else if (0 == strcmp("sendRemoteLogMessage", action)) { const char* url = stream.getNext(); const char* message = stream.getNext(); sendRemoteLogMessage(message, url); } return true; }
/* Python entry */ PyMODINIT_FUNC initImageGui() { if (!Gui::Application::Instance) { PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application."); return; } (void) ImageGui::initModule(); Base::Console().Log("Loading GUI of Image module... done\n"); // instantiating the commands CreateImageCommands(); ImageGui::ViewProviderImagePlane::init(); ImageGui::Workbench::init(); // add resources and reloads the translators loadImageResource(); }