void KEventObject::_RemoveEventListener(const ValueList& args, KValueRef result) { args.VerifyException("removeEventListener", "s m"); std::string event(args.GetString(0)); this->RemoveEventListener(event, args.GetMethod(1)); }
/*static*/ KValueRef Codec::ExtractZipAsync(const ValueList& args) { std::string zipFile = args.GetString(0); std::string directory = args.GetString(1); AutoPtr<AsyncJob> job = args.GetObject(2).cast<AsyncJob>(); KMethodRef callback = 0; if (args.size() > 3) { callback = args.GetMethod(3); } std::ifstream stream(UTF8ToSystem(zipFile).c_str(), std::ios::binary); Poco::Zip::Decompress decompressor(stream, directory); try { decompressor.decompressAllFiles(); } catch (std::exception& e) { Logger::Get("Codec")->Error("exception decompressing: %s", e.what()); throw ValueException::FromFormat("Exception during extraction: %s", e.what()); } stream.close(); if (!callback.isNull()) { ValueList args; args.push_back(Value::NewString(directory)); RunOnMainThread(callback, args, true); } return Value::Undefined; }
void UIBinding::_AddTray(const ValueList& args, KValueRef result) { args.VerifyException("createTrayIcon", "s,?m"); std::string iconURL = args.GetString(0); KMethodRef cbSingleClick = args.GetMethod(1, NULL); AutoTrayItem item = this->AddTray(iconURL, cbSingleClick); this->trayItems.push_back(item); result->SetObject(item); }
void KEventObject::_AddEventListener(const ValueList& args, KValueRef result) { unsigned int listenerId; if (args.size() > 1 && args.at(0)->IsString() && args.at(1)->IsMethod()) { std::string eventName(args.GetString(0)); listenerId = this->AddEventListener(eventName, args.GetMethod(1)); } else if (args.size() > 0 && args.at(0)->IsMethod()) { listenerId = this->AddEventListenerForAllEvents(args.GetMethod(0)); } else { throw ValueException::FromString("Incorrect arguments passed to addEventListener"); } result->SetDouble((double) listenerId); }
AutoMenuItem UIBinding::__CreateCheckMenuItem(const ValueList& args) { args.VerifyException("createCheckMenuItem", "?s m|0"); std::string label = args.GetString(0, ""); KMethodRef eventListener = args.GetMethod(1, NULL); AutoMenuItem item = this->CreateCheckMenuItem(); if (!label.empty()) item->SetLabel(label); if (!eventListener.isNull()) item->AddEventListener(Event::CLICKED, eventListener); return item; }
void KEventObject::_RemoveEventListener(const ValueList& args, KValueRef result) { args.VerifyException("removeEventListener", "s n|m"); std::string eventName(args.GetString(0)); if (args.at(1)->IsMethod()) { this->RemoveEventListener(eventName, args.GetMethod(1)); } else { this->RemoveEventListener(eventName, args.GetInt(1)); } }
void KEventObject::_AddEventListener(const ValueList& args, KValueRef result) { std::string event; KMethodRef callback; if (args.size() > 1 && args.at(0)->IsString() && args.at(1)->IsMethod()) { event = args.GetString(0); callback = args.GetMethod(1); } else if (args.size() > 0 && args.at(0)->IsMethod()) { event = Event::ALL; callback = args.GetMethod(0); } else { throw ValueException::FromString("Incorrect arguments passed to addEventListener"); } this->AddEventListener(event, callback); result->SetMethod(callback); }
void APIBinding::_RunOnMainThreadAsync(const ValueList& args, KValueRef result) { if (!args.at(0)->IsMethod()) { throw ValueException::FromString( "First argument to runOnMainThread was not a function"); } else { ValueList outArgs; for (size_t i = 1; i < args.size(); i++) outArgs.push_back(args.at(i)); RunOnMainThread(args.GetMethod(0), outArgs, false); } }
void APIBinding::_InstallDependencies(const ValueList& args, KValueRef result) { args.VerifyException("installDependencies", "l,m"); KListRef dependenciesList = args.GetList(0); KMethodRef callback = args.GetMethod(1, 0); vector<SharedDependency> dependencies; for (unsigned int i = 0; i < dependenciesList->Size(); i++) { if (!dependenciesList->At(i)->IsObject()) { continue; } AutoPtr<DependencyBinding> d = dependenciesList->At(i)->ToObject().cast<DependencyBinding>(); if (!d.isNull()) { dependencies.push_back(d->GetDependency()); } } if (dependencies.size() > 0) { if (!this->installerMutex.tryLock()) { throw ValueException::FromString( "Tried to launch more than one instance of the installer"); } if (this->installerThread) { delete this->installerThread; } this->installerDependencies = dependencies; this->installerCallback = callback; this->installerThread = new Poco::Thread(); this->installerThread->start(*this->installerThreadAdapter); } }
/*static*/ KValueRef Codec::CreateZipAsync(const ValueList& args) { std::string directory = args.GetString(0); std::string zipFile = args.GetString(1); AutoPtr<AsyncJob> job = args.GetObject(2).cast<AsyncJob>(); KMethodRef callback = 0; if (args.size() > 3) { callback = args.GetMethod(3); } Poco::Path path(directory); path.makeDirectory(); std::ofstream stream(UTF8ToSystem(zipFile).c_str(), std::ios::binary | std::ios::trunc); Poco::Zip::Compress compressor(stream, true); try { compressor.addRecursive(path); } catch (std::exception& e) { Logger::Get("Codec")->Error("exception compressing: %s", e.what()); throw ValueException::FromFormat("Exception during zip: %s", e.what()); } compressor.close(); stream.close(); if (!callback.isNull()) { ValueList args; args.push_back(Value::NewString(zipFile)); RunOnMainThread(callback, args, true); } return Value::Undefined; }
void Sound::SetOnComplete(const ValueList& args, KValueRef result) { args.VerifyException("onComplete", "m|0"); this->SetOnComplete(args.GetMethod(0, 0)); }
void Process::_SetOnExit(const ValueList& args, KValueRef result) { args.VerifyException("setOnExit", "m"); this->SetOnExit(args.GetMethod(0)); }
void TCPSocket::_OnTimeout(const ValueList& args, KValueRef result) { args.VerifyException("onTimeout", "m"); AddEventListener("timeout", args.GetMethod(0)); }
void TCPSocket::_OnError(const ValueList& args, KValueRef result) { args.VerifyException("onError", "m"); AddEventListener("error", args.GetMethod(0)); }
void TCPSocket::_OnReadComplete(const ValueList& args, KValueRef result) { args.VerifyException("onReadComplete", "m"); AddEventListener("end", args.GetMethod(0)); }
void APIBinding::_CreateKMethod(const ValueList& args, KValueRef result) { args.VerifyException("createKMethod", "m"); KMethodRef wrapped = args.GetMethod(0); result->SetMethod(new KMethodWrapper(args.GetMethod(0))); }
void Notification::_SetCallback(const ValueList& args, KValueRef result) { args.VerifyException("setCallback", "m"); this->clickedCallback = args.GetMethod(0); }