Exemple #1
0
void GeolocationClient::startUpdating()
{
    ASSERT(!m_geoclueClient);

    GRefPtr<GeoclueMaster> master = adoptGRef(geoclue_master_get_default());
    GRefPtr<GeoclueMasterClient> client = adoptGRef(geoclue_master_create_client(master.get(), 0, 0));
    if (!client) {
        errorOccured(_("Could not connect to location provider."));
        return;
    }

    GOwnPtr<GError> error;
    GeoclueAccuracyLevel accuracyLevel = m_enableHighAccuracy ? GEOCLUE_ACCURACY_LEVEL_DETAILED : GEOCLUE_ACCURACY_LEVEL_LOCALITY;
    if (!geoclue_master_client_set_requirements(client.get(), accuracyLevel, 0,
                                                false, GEOCLUE_RESOURCE_ALL, &error.outPtr())) {
        errorOccured(error->message);
        return;
    }

    m_geocluePosition = adoptGRef(geoclue_master_client_create_position(client.get(), &error.outPtr()));
    if (!m_geocluePosition) {
        errorOccured(error->message);
        return;
    }

    m_geoclueClient = client;
    geoclue_position_get_position_async(m_geocluePosition.get(), reinterpret_cast<GeocluePositionCallback>(getPositionCallback), this);
    g_signal_connect(G_OBJECT(m_geocluePosition.get()), "position-changed",
                     G_CALLBACK(positionChangedCallback), this);

    m_isUpdating = true;
}
Exemple #2
0
int
main (int    argc,
      char **argv)
{
	GError *error = NULL;
	GMainLoop *mainloop;
	GeoclueMaster *master;
	GeoclueMasterClient *client;
	GeocluePosition *position;
	
	g_type_init ();
	
	master = geoclue_master_get_default ();
	client = geoclue_master_create_client (master, NULL, NULL);
	g_object_unref (master);
	
	g_signal_connect (G_OBJECT (client), "position-provider-changed",
	                  G_CALLBACK (provider_changed_cb), NULL);
	
	/* We want provider that has detailed accuracy and emits signals.
	 * The provider is allowed to use any resources available. */
	if (!geoclue_master_client_set_requirements (client, 
	                                             GEOCLUE_ACCURACY_LEVEL_LOCALITY,
	                                             0, TRUE,
	                                             GEOCLUE_RESOURCE_ALL,
	                                             NULL)){
		g_printerr ("Setting requirements failed");
		g_object_unref (client);
		return 1;
	}
	
	position = geoclue_master_client_create_position (client, &error);
	if (!position) {
		g_warning ("Creating GeocluePosition failed: %s", error->message);
		g_error_free (error);
		g_object_unref (client);
		return 1;
	}
	
	g_signal_connect (G_OBJECT (position), "position-changed",
			  G_CALLBACK (position_changed_cb), NULL);

	geoclue_position_get_position_async (position, 
	                                     (GeocluePositionCallback) position_callback,
	                                     NULL);
    
	mainloop = g_main_loop_new (NULL, FALSE);
	g_main_loop_run (mainloop);
	
	g_main_loop_unref (mainloop);
	g_object_unref (client);
	g_object_unref (position);
	
	return 0;
}
Exemple #3
0
int
location_geoclue_start(location_geoclue_state_t *state)
{
        if (state->provider && state->provider_path) {
		state->position = geoclue_position_new(state->provider,
						       state->provider_path);
        } else {
                GError *error = NULL;
                GeoclueMaster *master = geoclue_master_get_default();
                GeoclueMasterClient *client = geoclue_master_create_client(master,
                                                                           NULL, &error);
		g_object_unref(master);

                if (client == NULL) {
                        g_printerr(_("Unable to obtain master client: %s\n"),
				   error->message);
			g_error_free(error);
                        return -1;
                }

		if (!geoclue_master_client_set_requirements(client,
							    GEOCLUE_ACCURACY_LEVEL_REGION,
							    0, FALSE,
							    GEOCLUE_RESOURCE_NETWORK,
							    &error)) {
			g_printerr(_("Can't set requirements for master: %s\n"),
				   error->message);
			g_error_free(error);
			g_object_unref(client);

			return -1;
		}

		state->position = geoclue_master_client_create_position(client, NULL);

                g_object_unref(client);
	}

	gchar *name = NULL;

	if (geoclue_provider_get_provider_info(GEOCLUE_PROVIDER(state->position),
					       &name, NULL, NULL)) {
		fprintf(stdout, _("Started Geoclue provider `%s'.\n"), name);
		g_free(name);
	} else {
		fputs(_("Could not find a usable Geoclue provider.\n"), stderr);
		fputs(_("Try setting name and path to specify which to use.\n"), stderr);
		return -1;
	}

	return 0;
}
Exemple #4
0
//
// 1.) Initialize Geoclue with our requirements
// 2.) Try to get a GeocluePosition
// 3.) Update the Information and get the current position
//
// TODO: Also get GeoclueVelocity but there is no master client
//       API for that.
//
bool GeolocationServiceGtk::startUpdating(PositionOptions* options)
{
    ASSERT(!m_geoclueClient);

    m_lastPosition = 0;
    m_lastError = 0;

    GOwnPtr<GError> error;
    GeoclueMaster* master = geoclue_master_get_default();
    GeoclueMasterClient* client = geoclue_master_create_client(master, 0, 0);
    g_object_unref(master);

    if (!client) {
        setError(PositionError::POSITION_UNAVAILABLE, "Could not connect to location provider.");
        return false;
    }

    GeoclueAccuracyLevel accuracyLevel = GEOCLUE_ACCURACY_LEVEL_LOCALITY;
    int timeout = 0;
    if (options) {
        accuracyLevel = options->enableHighAccuracy() ? GEOCLUE_ACCURACY_LEVEL_DETAILED : GEOCLUE_ACCURACY_LEVEL_LOCALITY;
        if (options->hasTimeout())
            timeout = options->timeout();
    }

    gboolean result = geoclue_master_client_set_requirements(client, accuracyLevel, timeout,
                                                             false, GEOCLUE_RESOURCE_ALL, &error.outPtr());

    if (!result) {
        setError(PositionError::POSITION_UNAVAILABLE, error->message);
        g_object_unref(client);
        return false;
    }

    m_geocluePosition = geoclue_master_client_create_position(client, &error.outPtr());
    if (!m_geocluePosition) {
        setError(PositionError::POSITION_UNAVAILABLE, error->message);
        g_object_unref(client);
        return false;
    }

    m_geoclueClient = client;

    geoclue_position_get_position_async(m_geocluePosition, (GeocluePositionCallback)getPositionCallback, this);

    g_signal_connect(G_OBJECT(m_geocluePosition), "position-changed",
                     G_CALLBACK(position_changed), this);

    return true;
}
Exemple #5
0
void GeolocationClient::setEnableHighAccuracy(bool enable)
{
    m_enableHighAccuracy = enable;

    // If we're already updating we should report the new requirements in order
    // to change to a more suitable provider if needed. If not, return.
    if (!m_isUpdating)
        return;

    GOwnPtr<GError> error;
    GeoclueAccuracyLevel accuracyLevel = m_enableHighAccuracy ? GEOCLUE_ACCURACY_LEVEL_DETAILED : GEOCLUE_ACCURACY_LEVEL_LOCALITY;
    if (!geoclue_master_client_set_requirements(m_geoclueClient.get(), accuracyLevel, 0,
                                                false, GEOCLUE_RESOURCE_ALL, &error.outPtr())) {
        errorOccured(error->message);
        stopUpdating();
    }
}
Exemple #6
0
static void
emerillon_window_init (EmerillonWindow *self)
{
  GdkGeometry geometry;
  GeoclueMaster *master = NULL;
  GError *error = NULL;

  gint width, height;

  self->priv = EMERILLON_WINDOW_GET_PRIVATE (self);


  self->priv->position_auto_update = FALSE;

  /* GSettings. */
  self->priv->settings_ui = g_settings_new (EMERILLON_SCHEMA_UI);

  /* Extension setup */
  self->priv->ext_set = peas_extension_set_new (peas_engine_get_default (),
                                                PEAS_TYPE_ACTIVATABLE,
                                                NULL);

  peas_extension_set_call (self->priv->ext_set, "activate");

  g_signal_connect (self->priv->ext_set, "extension-added", G_CALLBACK (on_extension_added), self);
  g_signal_connect (self->priv->ext_set, "extension-removed", G_CALLBACK (on_extension_removed), self);
  
  /* Window setup. */
  geometry.min_width = 400;
  geometry.min_height = 350;
  gtk_window_set_geometry_hints (GTK_WINDOW (self), GTK_WIDGET (self),
      &geometry,GDK_HINT_MIN_SIZE);

  /* Set the window size */
  width = g_settings_get_int (self->priv->settings_ui,
      EMERILLON_CONF_UI_WINDOW_WIDTH);
  height = g_settings_get_int (self->priv->settings_ui,
      EMERILLON_CONF_UI_WINDOW_HEIGHT);

  if (width > 0 && height > 0)
    gtk_window_set_default_size (GTK_WINDOW (self), width, height);
  else
    gtk_window_set_default_size (GTK_WINDOW (self), 640, 450);

  /* Current position. */
  master = geoclue_master_get_default ();
  self->priv->geoclue_client = geoclue_master_create_client (master, NULL, &error);
  if (!self->priv->geoclue_client)
    {
       g_warning ("Creating Geoclue Master client failed: %s", error->message);
       g_error_free (error);
       g_object_unref (master);
       return;
    }
  g_object_unref (master);

  geoclue_master_client_set_requirements (self->priv->geoclue_client,
                                          GEOCLUE_ACCURACY_LEVEL_COUNTRY, 0, FALSE, GEOCLUE_RESOURCE_ALL, NULL);
  self->priv->geoclue_position = geoclue_master_client_create_position (self->priv->geoclue_client, &error);
  if (self->priv->geoclue_position)
  {
    g_object_set_data (G_OBJECT (self->priv->geoclue_position), "client", self->priv->geoclue_client);
    g_signal_connect(self->priv->geoclue_position, "position-changed",
                     G_CALLBACK(position_changed_cb), NULL);
  }
  else
  {
    g_warning ("Getting Geoclue Position Failed: %s", error->message);
    g_error_free (error);
    if (self->priv->geoclue_client)
      g_object_unref (self->priv->geoclue_client);
  }

}