コード例 #1
0
	void UIBinding::_GetOpenWindows(const ValueList& args, SharedValue result)
	{
		SharedKList list = new StaticBoundList();
		std::vector<AutoUserWindow>::iterator w = openWindows.begin();
		while (w != openWindows.end()) {
			list->Append(Value::NewObject(*w++));
		}
		result->SetList(list);
	}
コード例 #2
0
ファイル: host_binding.cpp プロジェクト: cfs051059/titanium
	void HostBinding::GetAliases(const ValueList& args, SharedValue result)
	{
		SharedKList 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);
	}
コード例 #3
0
	void AppBinding::GetArguments(const ValueList& args, SharedValue result)
	{
		static SharedKList 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);
	}
コード例 #4
0
ファイル: host_binding.cpp プロジェクト: cfs051059/titanium
	void HostBinding::GetAddresses(const ValueList& args, SharedValue result)
	{
		SharedKList list = new StaticBoundList();
		std::vector<IPAddress> addresses = this->host.addresses();
		std::vector<IPAddress>::iterator iter = addresses.begin();
		while (iter!=addresses.end())
		{
			IPAddress address = (*iter++);
			SharedKObject obj = new IPAddressBinding(address);
			SharedValue addr = Value::NewObject(obj);
			list->Append(addr);
		}
		result->SetList(list);
	}
コード例 #5
0
	void IRCClientBinding::GetUsers(const ValueList& args, SharedValue result)
	{
		const char *channel = args.at(0)->ToString();
		SharedKList list = new StaticBoundList();
		channel_user* cu = irc.get_users();
		while(cu)
		{
			if (!strcmp(cu->channel,(char*)channel) && cu->nick && strlen(cu->nick)>0)
			{
				SharedKObject entry = new StaticBoundObject();
				entry->Set("name",Value::NewString(cu->nick));
				entry->Set("operator",Value::NewBool(cu->flags & IRC_USER_OP));
				entry->Set("voice",Value::NewBool(cu->flags & IRC_USER_VOICE));
				list->Append(Value::NewObject(entry));
			}
			cu = cu->next;
		}
		result->SetList(list);
	}
コード例 #6
0
ファイル: blob.cpp プロジェクト: jonnymind/kroll
	void Blob::Split(const ValueList& args, SharedValue 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("Blob.split", "?s,i");

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

		std::string target = "";
		if (this->length > 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 = INT_MAX;
		if (args.size() > 1)
		{
			limit = args.GetInt(1);
		}

		// 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));
	}
コード例 #7
0
	AppBinding::AppBinding(Host *host, SharedKObject global) : host(host), global(global)
	{
		/**
		 * @tiapi(method=True,immutable=True,name=App.getID,since=0.2) Returns the application id
		 * @tiresult(for=App.getID,type=string) returns the id
		 */
		this->SetMethod("getID", &AppBinding::GetID);
		/**
		 * @tiapi(method=True,immutable=True,name=App.getName,since=0.2) Returns the application name
		 * @tiresult(for=App.getName,type=string) returns the name
		 */
		this->SetMethod("getName", &AppBinding::GetName);
		/**
		 * @tiapi(method=True,immutable=True,name=App.getVersion,since=0.2) Returns the application version
		 * @tiresult(for=App.getVersion,type=string) returns the version
		 */
		this->SetMethod("getVersion", &AppBinding::GetVersion);
		/**
		 * @tiapi(method=True,immutable=True,name=App.getPublisher,since=0.4) Returns the application publisher
		 * @tiresult(for=App.getPublisher,type=string) returns the publisher
		 */
		this->SetMethod("getPublisher", &AppBinding::GetPublisher);
		/**
		 * @tiapi(method=True,immutable=True,name=App.getURL,since=0.4) Returns the application url
		 * @tiresult(for=App.getURL,type=string) returns the url for the app
		 */
		this->SetMethod("getURL", &AppBinding::GetURL);
		/**
		 * @tiapi(method=True,immutable=True,name=App.getDescription,since=0.4) Returns the application description
		 * @tiresult(for=App.getDescription,type=string) returns the description for the app
		 */
		this->SetMethod("getDescription", &AppBinding::GetDescription);
		/**
		 * @tiapi(method=True,immutable=True,name=App.getCopyright,since=0.4) Returns the application copyright information
		 * @tiresult(for=App.getCopyright,type=string) returns the copyright for the app
		 */
		this->SetMethod("getCopyright", &AppBinding::GetCopyright);
		/**
		 * @tiapi(method=True,immutable=True,name=App.getGUID,since=0.2) Returns the application globally unique id
		 * @tiresult(for=App.getGUID,type=string) returns the unique id
		 */
		this->SetMethod("getGUID", &AppBinding::GetGUID);
		/**
		 * @tiapi(method=True,immutable=True,name=App.getStreamURL,since=0.4) Returns the application stream URL for the update channel
		 * @tiresult(for=App.getStreamURL,type=string) returns the stream URL
		 */
		this->SetMethod("getStreamURL", &AppBinding::GetStreamURL);

		
		/**
		 * @tiapi(method=True,immutable=True,name=App.appURLToPath,since=0.2) Returns the full path equivalent of an app: protocol path
		 * @tiresult(for=App.appURLToPath,type=string) returns the path
		 */
		this->SetMethod("appURLToPath", &AppBinding::AppURLToPath);
		
		/**
		 * @tiapi(property=True,immutable=True,type=string,name=App.path,since=0.2) Returns the full path to the application
		 */
		this->Set("path",Value::NewString(host->GetCommandLineArg(0)));

		/**
		 * @tiapi(property=True,immutable=True,type=string,name=App.home,since=0.4) Returns the full path to the application home directory
		 */
		this->Set("home",Value::NewString(host->GetApplicationHomePath()));


		/**
		 * @tiapi(property=True,immutable=True,type=string,name=App.version,since=0.2) The Titanium product version
		 */
		SharedValue version = Value::NewString(STRING(PRODUCT_VERSION));
		global->Set("version", version);

		/**
		 * @tiapi(property=True,immutable=True,type=string,name=App.platform,since=0.2) The Titanium platform
		 */
		SharedValue platform = Value::NewString(host->GetPlatform());
		global->Set("platform",platform);

		// skip the first argument which is the filepath to the
		// executable
		SharedKList argList = new StaticBoundList();
		for (int i = 1; i < Host::GetInstance()->GetCommandLineArgCount(); i++) {
			argList->Append(Value::NewString(Host::GetInstance()->GetCommandLineArg(i)));
		}
		SharedValue arguments = Value::NewList(argList);
		/**
		 * @tiapi(property=True,immutable=True,type=list,name=App.arguments,since=0.2) The command line arguments
		 */
		Set("arguments", arguments);

		/**
		 * @tiapi(method=True,immutable=True,name=App.exit,since=0.2) Exits the application
		 */
		this->SetMethod("exit",&AppBinding::Exit);

		/**
		 * @tiapi(method=True,name=App.loadProperties,since=0.2) Loads a properties list from a file path
		 * @tiarg(for=App.loadProperties,type=string,name=path) path to properties file
		 * @tiresult(for=App.loadProperties,type=list) returns the properties as a list
		 */
		this->SetMethod("loadProperties", &AppBinding::LoadProperties);

		/**
		 * @tiapi(method=True,name=App.stdout,since=0.4) Writes to stdout
		 * @tiarg(for=App.stdout,type=string,name=data) data to write
		 */
		this->SetMethod("stdout", &AppBinding::StdOut);
		/**
		 * @tiapi(method=True,name=App.stderr,since=0.4) Writes to stderr
		 * @tiarg(for=App.stderr,type=string,name=data) data to write
		 */
		this->SetMethod("stderr", &AppBinding::StdErr);
		
		/**
		 * @tiapi(method=True,name=App.getSystemProperties,since=0.4) get the system properties defined in tiapp.xml
		 * @tiresult(for=App.getSystemProperties,type=Properties) returns the system properties object (see Titanium.App.Properties)
		 */
		this->SetMethod("getSystemProperties", &AppBinding::GetSystemProperties);

		/**
		 * @tiapi(method=True,name=App.getIcon,since=0.4) Returns the application icon
		 * @tiresult(for=App.getIcon,type=string) returns the icon path
		 */
		this->SetMethod("getIcon", &AppBinding::GetIcon);
	}