Beispiel #1
0
void
Accelerometer::Run(const String& command) {
	if (!command.IsEmpty()) {
		Uri commandUri;
		commandUri.SetUri(command);
		String method = commandUri.GetHost();
		StringTokenizer strTok(commandUri.GetPath(), L"/");
		if(strTok.GetTokenCount() == 1) {
			strTok.GetNextToken(callbackId);
			AppLogDebug("Method %S, CallbackId: %S", method.GetPointer(), callbackId.GetPointer());
		}
		if(method == L"com.cordova.Accelerometer.watchAcceleration" && !callbackId.IsEmpty() && !IsStarted()) {
			StartSensor();
		}
		if(method == L"com.cordova.Accelerometer.clearWatch" && IsStarted()) {
			StopSensor();
		}
		if(method == L"com.cordova.Accelerometer.getCurrentAcceleration" && !callbackId.IsEmpty() && !IsStarted()) {
			GetLastAcceleration();
		}
		AppLogDebug("Acceleration command %S completed", command.GetPointer());
	} else {
		AppLogDebug("Can't run empty command");
	}
}
Beispiel #2
0
void
GeoLocation::Run(const String& command) {
	if(!command.IsEmpty()) {
		Uri commandUri;
		commandUri.SetUri(command);
		String method = commandUri.GetHost();
		StringTokenizer strTok(commandUri.GetPath(), L"/");
		if(strTok.GetTokenCount() > 1) {
			strTok.GetNextToken(callbackId);
			AppLogDebug("Method %S, CallbackId: %S", method.GetPointer(), callbackId.GetPointer());
		}
		AppLogDebug("Method %S, Callback: %S", method.GetPointer(), callbackId.GetPointer());
		// used to determine callback ID
		if(method == L"com.phonegap.Geolocation.watchPosition" && !callbackId.IsEmpty() && !IsWatching()) {
			AppLogDebug("watching position...");
			StartWatching();
		}
		if(method == L"com.phonegap.Geolocation.stop" && IsWatching()) {
			AppLogDebug("stop watching position...");
			StopWatching();
		}
		if(method == L"com.phonegap.Geolocation.getCurrentPosition" && !callbackId.IsEmpty() && !IsWatching()) {
			AppLogDebug("getting current position...");
			GetLastKnownLocation();
		}
		AppLogDebug("GeoLocation command %S completed", command.GetPointer());
	}
}
Beispiel #3
0
bool
Consent::PromptUserFor (MoonConsentType consent)
{
	Surface *surface = Deployment::GetCurrent ()->GetSurface ();
	const char *source = surface->GetSourceLocation ();

	Uri *uri = new Uri ();
	uri->Parse (source);

	char *website = ((uri->GetPort () > 0)
			 ? g_strdup_printf ("%s://%s:%d",
					    uri->GetScheme(),
					    uri->GetHost(),
					    uri->GetPort())
			 : g_strdup_printf ("%s://%s",
					    uri->GetScheme(),
					    uri->GetHost()));

	const char *question, *detail;

	switch (consent) {
	case MOON_CONSENT_CLIPBOARD:
		question = "Do you want to allow this application to access your clipboard?";
		detail = "If you allow this, the application can copy data to and from the Clipboard as long as the application is running.";
		break;
	case MOON_CONSENT_FULLSCREEN_PINNING:
		question = "[fullscreen question here]"; // FIXME
		detail = "[fullscreen detail here]"; // FIXME
		break;
	case MOON_CONSENT_CAPTURE:
		question = "Do you want to allow this application to access your webcam and microphone?";
		detail = "If you allow this, the application can capture video and audio as long as the application is running.";
		break;
	case MOON_CONSENT_LAST:
		// should't be reached...
		question = detail = NULL;
		break;
	}

	return PromptUserFor (consent, question, detail, website);
}
Beispiel #4
0
void
Notification::Run(const String& command) {
	if(!command.IsEmpty()) {
		Uri commandUri;
		commandUri.SetUri(command);
		String method = commandUri.GetHost();
		StringTokenizer strTok(commandUri.GetPath(), L"/");
		if(strTok.GetTokenCount() < 1) {
			AppLogException("Not enough params");
			return;
		}
		if((method == L"com.phonegap.Notification.alert" || method == L"com.phonegap.Notification.confirm")) {
			strTok.GetNextToken(callbackId);
			AppLogDebug("%S %S", method.GetPointer(), callbackId.GetPointer());
			if(!callbackId.IsEmpty()) {
				Dialog();
			}
		} else if(method == L"com.phonegap.Notification.vibrate") {
			long duration;
			String durationStr;

			strTok.GetNextToken(durationStr);
			AppLogDebug("%S %S", method.GetPointer(), durationStr.GetPointer());
			// Parsing duration
			result r = Long::Parse(durationStr, duration);
			if(IsFailed(r)) {
				AppLogException("Could not parse duration");
				return;
			}
			Vibrate(duration);
		} else if(method == L"com.phonegap.Notification.beep") {
			int count;
			String countStr;

			strTok.GetNextToken(countStr);
			AppLogDebug("%S %S", method.GetPointer(), countStr.GetPointer());
			// Parsing count
			result r = Integer::Parse(countStr, count);
			if(IsFailed(r)) {
				AppLogException("Could not parse count");
				return;
			}

			Beep(count);
		}
	}
}
Beispiel #5
0
void
Kamera::Run(const String& command) {
	if(!command.IsEmpty()) {
		Uri commandUri;
		commandUri.SetUri(command);
		String method = commandUri.GetHost();
		StringTokenizer strTok(commandUri.GetPath(), L"/");
		if(strTok.GetTokenCount() < 1) {
			AppLogException("Not enough params");
			return;
		}
		strTok.GetNextToken(callbackId);
		if(method == "com.phonegap.Camera.getPicture" && !callbackId.IsEmpty()) {
			GetPicture();
		}
	}
}
Beispiel #6
0
static MoonWindow*
create_window (Deployment *deployment, const char *app_id)
{
	MoonAppRecord *app;
	OutOfBrowserSettings *oob;
	WindowSettings *settings;
	MoonWindow *moon_window;
	Surface *surface;

	/* fetch the app record */
	if (!(app = installer->GetAppRecord (app_id))) {
		g_warning ("Could not find application: %s", app_id);
		return NULL;
	}

	/* create the moonlight widget */
	moon_window = winsys->CreateWindow (MoonWindowType_Desktop, 0, 0);
	surface = new Surface (moon_window);
	deployment->SetSurface (surface);
	moon_window->SetSurface (surface);

	if (!load_app (deployment, installer->GetBaseInstallDir (), app))
		return NULL;
	
	surface->AddXamlHandler (Surface::ErrorEvent, error_handler, NULL);
	
	if ((oob = deployment->GetOutOfBrowserSettings ())) {
		load_window_icons (moon_window, deployment, oob->GetIcons ());
		settings = oob->GetWindowSettings ();
	} else
		settings = NULL;
	
	if (settings != NULL) {
		Uri *uri;
		const char *hostname = NULL;

		uri = Uri::Create (app->origin);
		if (uri != NULL)
			hostname = uri->GetHost ();

		if (!hostname || !*hostname)
			hostname = "localhost";

		char *window_title = g_strdup_printf ("%s - %s",
						      settings->GetTitle(),
						      hostname);

		delete uri;

		moon_window->SetTitle (window_title);

		g_free (window_title);

		moon_window->Resize (settings->GetWidth (), settings->GetHeight());
			
		if (settings->GetWindowStartupLocation () == WindowStartupLocationManual) {
			// FIXME: this should really use a MoonWindow::Move
			moon_window->SetLeft (settings->GetLeft ());
			moon_window->SetTop (settings->GetTop ());
		}

		moon_window->SetStyle (settings->GetWindowStyle ());

	} else if (oob != NULL) {
		moon_window->SetTitle (oob->GetShortName ());
	} else {
		moon_window->SetTitle ("Moonlight");
	}
	
	delete app;

	return moon_window;
}