Ejemplo n.º 1
0
 void APIBinding::_CreateKList(const ValueList& args, KValueRef result)
 {
     args.VerifyException("createKList", "?l");
     if (args.size() <= 0)
     {
         result->SetList(new StaticBoundList());
     }
     else
     {
         KListRef wrapped = args.GetList(0);
         result->SetList(new KListWrapper(wrapped));
     }
 }
Ejemplo n.º 2
0
    void Clipboard::_GetData(const ValueList& args, KValueRef result)
    {
        args.VerifyException("getData", "s");

        std::string mimeType(args.GetString(0));
        DataType type = MimeTypeToDataType(mimeType);
        if (type == URI_LIST)
        {
            std::vector<std::string>& list = this->GetURIList();
            if (mimeType == "url")
            {
                std::string url;
                if (list.size() > 0)
                    url = list.at(0);

                result->SetString(url.c_str());
            }
            else
            {
                result->SetList(StaticBoundList::FromStringVector(list));
            }
        }
        else if (type == IMAGE)
        {
            result->SetObject(this->GetImage(mimeType));
        }
        else 
        {
            result->SetString(this->GetText());
        }
    }
	void ApplicationBinding::_GetAvailableModules(const ValueList& args, KValueRef result)
	{
		std::vector<SharedComponent> components;
		this->application->GetAvailableComponents(components);
		KListRef componentList = APIBinding::ComponentVectorToKList(components, MODULE);
		result->SetList(componentList);
	}
	void ApplicationBinding::_GetBundledRuntimes(const ValueList& args, KValueRef result)
	{
		std::vector<SharedComponent> components;
		this->application->GetAvailableComponents(components, true);
		KListRef componentList = APIBinding::ComponentVectorToKList(components, RUNTIME);
		result->SetList(componentList);
	}
Ejemplo n.º 5
0
	void Bytes::_Split(const ValueList& args, KValueRef result)
	{
		// This method now follows the spec located at:
		// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/String/split
		// Except support for regular expressions
		args.VerifyException("Bytes.split", "?s,i");

		KListRef list = new StaticBoundList();
		result->SetList(list);

		std::string target = "";
		if (this->size > 0)
		{
			target = this->buffer;
		}
		else
		{
			list->Append(Value::NewString(target));
			return;
		}

		if (args.size() <= 0)
		{
			list->Append(Value::NewString(target));
			return;
		}

		std::string separator = args.GetString(0);

		int limit = args.GetInt(1, INT_MAX);

		// We could use Poco's tokenizer here, but it doesn't split strings
		// like "abc,def,," -> ['abc', 'def', '', ''] correctly. It produces
		// ['abc', 'def', ''] which is a different behavior than the JS split.
		// So we roll our own for now -- it's not very efficient right now, but
		// it should be correct.
		size_t next = target.find(separator);
		while (target.size() > 0 && next != std::string::npos)
		{
			std::string token;
			if (separator.size() == 0)
			{
				token = target.substr(0, 1);
			}
			else
			{
				token = target.substr(0, next);
			}
			target = target.substr(next + 1);
			next = target.find(separator);

			if ((int) list->Size() >= limit)
				return;

			list->Append(Value::NewString(token));
		}

		if ((int) list->Size() < limit && separator.size() != 0)
			list->Append(Value::NewString(target));
	}
	void ApplicationBinding::_GetManifest(const ValueList& args, KValueRef result)
	{
		vector<pair<string, string> > manifest =
			BootUtils::ReadManifestFile(this->application->manifestPath);

		KListRef manifestList = APIBinding::ManifestToKList(manifest);
		result->SetList(manifestList);
	}
Ejemplo n.º 7
0
 void APIBinding::_GetInstalledComponentsImpl(
     KComponentType type, const ValueList& args, KValueRef result)
 {
     bool force = args.GetBool(0, false);
     vector<SharedComponent>& components = BootUtils::GetInstalledComponents(force);
     KListRef componentList = ComponentVectorToKList(components, type);
     result->SetList(componentList);
 }
Ejemplo n.º 8
0
	void UIBinding::_GetOpenWindows(const ValueList& args, KValueRef result)
	{
		KListRef list = new StaticBoundList();
		std::vector<AutoUserWindow>::iterator w = openWindows.begin();
		while (w != openWindows.end()) {
			list->Append(Value::NewObject(*w++));
		}
		result->SetList(list);
	}
Ejemplo n.º 9
0
void HostBinding::GetAliases(const ValueList& args, KValueRef result)
{
    KListRef list = new StaticBoundList();
    std::vector<std::string> aliases = this->host.aliases();
    std::vector<std::string>::iterator iter = aliases.begin();
    while (iter!=aliases.end())
    {
        std::string alias = (*iter++);
        list->Append(Value::NewString(alias));
    }
    result->SetList(list);
}
Ejemplo n.º 10
0
	void AppBinding::GetArguments(const ValueList& args, KValueRef result)
	{
		static KListRef argList(0);
		if (argList.isNull())
		{
			// Skip the first argument which is the filename to the executable
			argList = new StaticBoundList();
			for (int i = 1; i < host->GetCommandLineArgCount(); i++)
				argList->Append(Value::NewString(host->GetCommandLineArg(i)));
		}

		result->SetList(argList);
	}
Ejemplo n.º 11
0
void HostBinding::GetAddresses(const ValueList& args, KValueRef result)
{
    KListRef list = new StaticBoundList();
    std::vector<IPAddress> addresses = this->host.addresses();
    std::vector<IPAddress>::iterator iter = addresses.begin();
    while (iter!=addresses.end())
    {
        IPAddress address = (*iter++);
        KObjectRef obj = new IPAddressBinding(address);
        KValueRef addr = Value::NewObject(obj);
        list->Append(addr);
    }
    result->SetList(list);
}
Ejemplo n.º 12
0
	void AppBinding::GetArguments(const ValueList& args, KValueRef result)
	{
		static KListRef argList(0);
		if (argList.isNull())
		{
			// Skip the first argument which is the filename of the executable.
			std::vector<std::string>& args = host->GetApplication()->GetArguments();
			argList = new StaticBoundList();
			for (size_t i = 1; i < args.size(); i++)
				argList->Append(Value::NewString(args.at(i)));
		}

		result->SetList(argList);
	}
Ejemplo n.º 13
0
void Properties::ListProperties(const ValueList& args, KValueRef result)
{
    std::vector<std::string> keys;
    config->keys(keys);

    KListRef property_list = new StaticBoundList();
    for (size_t i = 0; i < keys.size(); i++)
    {
        std::string property_name = keys.at(i);
        KValueRef name_value = Value::NewString(property_name.c_str());
        property_list->Append(name_value);
    }
    result->SetList(property_list);
}
Ejemplo n.º 14
0
	void ApplicationBinding::_GetComponents(const ValueList& args, KValueRef result)
	{
		// Do not use a reference here, because we don't want to modify the
		// application's modules list.
		std::vector<SharedComponent> components = this->application->modules;

		if (!this->application->runtime.isNull())
		{
			components.push_back(this->application->runtime);
		}

		for (size_t i = 0; i < this->application->sdks.size(); i++)
		{
			components.push_back(this->application->sdks[i]);
		}
		KListRef componentList = APIBinding::ComponentVectorToKList(components);
		result->SetList(componentList);
	}
	void PropertiesBinding::GetList(const ValueList& args, KValueRef result)
	{
		KValueRef stringValue = Value::Null;
		GetString(args, stringValue);

		if (!stringValue->IsNull())
		{
			KListRef list = new StaticBoundList();
			std::string string = stringValue->ToString();
			Poco::StringTokenizer t(string, ",", Poco::StringTokenizer::TOK_TRIM);
			for (size_t i = 0; i < t.count(); i++)
			{
				KValueRef token = Value::NewString(t[i].c_str());
				list->Append(token);
			}

			KListRef list2 = list;
			result->SetList(list2);
		}
	}
	void FilesystemBinding::GetRootDirectories(const ValueList& args, KValueRef result)
	{
		try
		{
			Poco::Path path;
			std::vector<std::string> roots;
			path.listRoots(roots);

			KListRef rootList = new StaticBoundList();
			for(size_t i = 0; i < roots.size(); i++)
			{
				ti::File* file = new ti::File(roots.at(i));
				KValueRef value = Value::NewObject((KObjectRef) file);
				rootList->Append(value);
			}

			KListRef list = rootList;
			result->SetList(list);
		}
		catch (Poco::Exception& exc)
		{
			throw ValueException::FromString(exc.displayText());
		}
	}
Ejemplo n.º 17
0
 void APIBinding::_GetComponentSearchPaths(const ValueList& args, KValueRef result)
 {
     vector<string>& paths = BootUtils::GetComponentSearchPaths();
     KListRef pathList = StaticBoundList::FromStringVector(paths);
     result->SetList(pathList);
 }
Ejemplo n.º 18
0
	void Process::_GetArguments(const ValueList& args, KValueRef result)
	{
		result->SetList(this->args);
	}
Ejemplo n.º 19
0
	void ApplicationBinding::_GetModules(const ValueList& args, KValueRef result)
	{
		std::vector<SharedComponent>& components = this->application->modules;
		KListRef componentList = APIBinding::ComponentVectorToKList(components);
		result->SetList(componentList);
	}
Ejemplo n.º 20
0
	void ApplicationBinding::_ResolveDependencies(const ValueList& args, KValueRef result)
	{
		std::vector<SharedDependency> unresolved = this->application->ResolveDependencies();
		result->SetList(APIBinding::DependencyVectorToKList(unresolved));
	}
Ejemplo n.º 21
0
	void ApplicationBinding::_GetDependencies(const ValueList& args, KValueRef result)
	{
		result->SetList(APIBinding::DependencyVectorToKList(
			this->application->dependencies));
	}
Ejemplo n.º 22
0
	void ApplicationBinding::_GetArguments(const ValueList& args, KValueRef result)
	{
		std::vector<std::string> arguments = this->application->GetArguments();
		KListRef argumentList = StaticBoundList::FromStringVector(arguments);
		result->SetList(argumentList);
	}
Ejemplo n.º 23
0
void Network::_GetInterfaces(const ValueList& args, KValueRef result)
{
    result->SetList(interfaceList);
}