Beispiel #1
0
	AppBinding::AppBinding(Host *host,SharedBoundObject global) : host(host),global(global)
	{
		this->SetMethod("getID", &AppBinding::GetID);
		this->SetMethod("getName", &AppBinding::GetName);
		this->SetMethod("getVersion", &AppBinding::GetVersion);
		this->SetMethod("getUpdateURL", &AppBinding::GetUpdateURL);
		this->SetMethod("getGUID", &AppBinding::GetGUID);
		this->SetMethod("appURLToPath", &AppBinding::AppURLToPath);

		// FIXME: for now this version is hardcoded
		SharedValue version = Value::NewDouble(PRODUCT_VERSION);
		global->Set("version", version);

		// platform
		SharedValue platform = Value::NewString(host->GetPlatform());
		global->Set("platform",platform);

		SharedBoundList argList = new StaticBoundList();
		for (int i = 0; i < Host::GetInstance()->GetCommandLineArgCount(); i++) {
			argList->Append(Value::NewString(Host::GetInstance()->GetCommandLineArg(i)));
		}
		SharedValue arguments = Value::NewList(argList);
		Set("arguments", arguments);

		this->SetMethod("exit",&AppBinding::Exit);
		this->SetMethod("loadProperties", &AppBinding::LoadProperties);
	}
Beispiel #2
0
	void HostBinding::GetAliases(const ValueList& args, SharedValue result)
	{
		SharedBoundList 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);
	}
Beispiel #3
0
	void HostBinding::GetAddresses(const ValueList& args, SharedValue result)
	{
		SharedBoundList list = new StaticBoundList();
		std::vector<IPAddress> addresses = this->host.addresses();
		std::vector<IPAddress>::iterator iter = addresses.begin();
		while (iter!=addresses.end())
		{
			IPAddress address = (*iter++);
			SharedBoundObject obj = new IPAddressBinding(address);
			SharedValue addr = Value::NewObject(obj);
			list->Append(addr);
		}
		result->SetList(list);
	}
Beispiel #4
0
SharedBoundList Win32UserWindow::SelectDirectory(bool multiple,
		std::string& path, std::string& file) {
	SharedBoundList results = new StaticBoundList();

	BROWSEINFO bi = { 0 };
	//std::string title("Select a directory");
	//bi.lpszTitle = title.c_str();
	bi.hwndOwner = this->window_handle;
	LPITEMIDLIST pidl = SHBrowseForFolder(&bi);

	if (pidl != 0) {
		// get folder name
		TCHAR in_path[MAX_PATH];
		if (SHGetPathFromIDList(pidl, in_path)) {
			results->Append(Value::NewString(std::string(in_path)));
		}
	}
	return results;
}
Beispiel #5
0
void GtkUserWindow::_OpenFilesWork(const ValueList& args, SharedValue lresult)
{
	void* data = args.at(0)->ToVoidPtr();
	OpenFilesJob* job = reinterpret_cast<OpenFilesJob*>(data);
	SharedBoundList results = new StaticBoundList();

	std::string text = "Select File";
	GtkFileChooserAction a = GTK_FILE_CHOOSER_ACTION_OPEN;
	if (job->directories)
	{
		text = "Select Directory";
		a = GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER;
	}

	GtkWidget* chooser = gtk_file_chooser_dialog_new(
		text.c_str(),
		job->window,
		a,
		GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
		GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
		NULL);

	std::string path = this->openFilesDirectory;
	if (!job->path.empty())
		path = job->path;
	if (!path.empty())
		gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(chooser), path.c_str());

	gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(chooser), job->multiple);

	if (job->types.size() > 0)
	{
		GtkFileFilter* f = gtk_file_filter_new();
		for (size_t fi = 0; fi < job->types.size(); fi++)
		{
			std::string filter = std::string("*.") + job->types.at(fi);
			gtk_file_filter_add_pattern(f, filter.c_str());
		}
		gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(chooser), f);
	}

	int result = gtk_dialog_run(GTK_DIALOG(chooser));
	if (result == GTK_RESPONSE_ACCEPT && job->multiple)
	{
		GSList* files = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(chooser));
		for (size_t i = 0; i < g_slist_length(files); i++)
		{
			char* f = (char*) g_slist_nth_data(files, i);
			results->Append(Value::NewString(f));
			g_free(f);
		}
		g_slist_free(files);
	}
	else if (result == GTK_RESPONSE_ACCEPT)
	{
		char *f = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser));
		results->Append(Value::NewString(f));
		g_free(f);
	}

	this->openFilesDirectory =
		 gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(chooser));
	gtk_widget_destroy(chooser);

	ValueList cargs;
	cargs.push_back(Value::NewList(results));
	try
	{
		job->callback->Call(cargs);
	}
	catch (ValueException &e)
	{
		SharedString ss = e.GetValue()->DisplayString();
		std::cerr << "openFiles callback failed: " << *ss << std::endl;
	}
}
Beispiel #6
0
SharedBoundList Win32UserWindow::SelectFile(SharedBoundMethod callback,
		bool multiple, std::string& path, std::string& file, std::vector<
				std::string>& types) {
	//std::string filterName = props->GetString("typesDescription", "Filtered Files");
	std::string filterName = "Filtered Files";
	std::string filter;

	if (types.size() > 0) {
		//"All\0*.*\0Test\0*.TXT\0";
		filter.append(filterName);
		filter.push_back('\0');

		for (int i = 0; i < types.size(); i++) {
			std::string type = types.at(i);

			//multiple filters: "*.TXT;*.DOC;*.BAK"
			size_t found = type.find("*.");
			if (found != 0) {
				filter.append("*.");
			}
			filter.append(type);
			filter.append(";");
		}

		filter.push_back('\0');
	}

	OPENFILENAME ofn;
	char filen[8192];

	ZeroMemory(&filen, sizeof(filen));

	if (file.size() == 0) {
		filen[0] = '\0';
	} else {
		strcpy(filen, file.c_str());
	}

	// init OPENFILE
	ZeroMemory(&ofn, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = this->window_handle;
	ofn.lpstrFile = filen;
	ofn.nMaxFile = sizeof(filen);
	ofn.lpstrFilter = (filter.length() == 0 ? NULL : filter.c_str());
	ofn.nFilterIndex = 1;
	ofn.lpstrFileTitle = NULL;
	ofn.nMaxFileTitle = 0;
	ofn.lpstrInitialDir = (path.length() == 0 ? NULL : path.c_str());
	ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER;

	if (multiple)
		ofn.Flags |= OFN_ALLOWMULTISELECT;

	SharedBoundList results = new StaticBoundList();
	// display the open dialog box
	BOOL result = GetOpenFileName(&ofn);

	if (result) {
		// if the user selected multiple files, ofn.lpstrFile is a NULL-separated list of filenames
		// if the user only selected one file, ofn.lpstrFile is a normal string

		std::vector<std::string> tokens;
		ParseStringNullSeparated(ofn.lpstrFile, tokens);

		if (tokens.size() == 1) {
			results->Append(Value::NewString(tokens.at(0)));
		} else if (tokens.size() > 1) {
			std::string directory(tokens.at(0));
			for (int i = 1; i < tokens.size(); i++) {
				std::string n;
				n.append(directory.c_str());
				n.append("\\");
				n.append(tokens.at(i).c_str());
				results->Append(Value::NewString(n));
			}
		}
	}
	else {
		DWORD error = CommDlgExtendedError();
		printf("Error when opening files: %d\n", error);
		switch(error) {
			case CDERR_DIALOGFAILURE: printf("CDERR_DIALOGFAILURE\n"); break;
			case CDERR_FINDRESFAILURE: printf("CDERR_FINDRESFAILURE\n"); break;
			case CDERR_NOHINSTANCE: printf("CDERR_NOHINSTANCE\n"); break;
			case CDERR_INITIALIZATION: printf("CDERR_INITIALIZATION\n"); break;
			case CDERR_NOHOOK: printf("CDERR_NOHOOK\n"); break;
			case CDERR_LOCKRESFAILURE: printf("CDERR_LOCKRESFAILURE\n"); break;
			case CDERR_NOTEMPLATE: printf("CDERR_NOTEMPLATE\n"); break;
			case CDERR_LOADRESFAILURE: printf("CDERR_LOADRESFAILURE\n"); break;
			case CDERR_STRUCTSIZE: printf("CDERR_STRUCTSIZE\n"); break;
			case CDERR_LOADSTRFAILURE: printf("CDERR_LOADSTRFAILURE\n"); break;
			case FNERR_BUFFERTOOSMALL: printf("FNERR_BUFFERTOOSMALL\n"); break;
			case CDERR_MEMALLOCFAILURE: printf("CDERR_MEMALLOCFAILURE\n"); break;
			case FNERR_INVALIDFILENAME: printf("FNERR_INVALIDFILENAME\n"); break;
			case CDERR_MEMLOCKFAILURE: printf("CDERR_MEMLOCKFAILURE\n"); break;
			case FNERR_SUBCLASSFAILURE: printf("FNERR_SUBCLASSFAILURE\n"); break;
		}
	}
	return results;
}