Пример #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;
}
Пример #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;
}
Пример #3
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;
}
Пример #4
0
static void
emerillon_window_set_property (GObject      *object,
                               guint         property_id,
                               const GValue *value,
                               GParamSpec   *pspec)
{
  EmerillonWindow *self = EMERILLON_WINDOW (object);
  switch (property_id)
  {
    case PROP_AUTO_UPDATE:
      self->priv->position_auto_update = g_value_get_boolean(value);
      if (self->priv->geoclue_position != NULL)
        geoclue_position_get_position_async (self->priv->geoclue_position,
                                             (GeocluePositionCallback)position_changed_cb, self);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
      break;
  }
}
Пример #5
0
static void
mnp_world_clock_construct (MnpWorldClock *world_clock)
{
    ClutterActor *entry, *box, *stage;
    MxBoxLayout *table = (MxBoxLayout *)world_clock;
    gfloat width, height;
    MnpWorldClockPrivate *priv = GET_PRIVATE (world_clock);

    stage = priv->stage;
    priv->location_tile = FALSE;

    mx_box_layout_set_orientation ((MxBoxLayout *)world_clock, MX_ORIENTATION_VERTICAL);
    mx_box_layout_set_spacing ((MxBoxLayout *)world_clock, 0);
    clutter_actor_set_name (CLUTTER_ACTOR(world_clock), "TimePane");

    construct_heading_and_top_area (world_clock);

    priv->completion_timeout = 0;

    /* Search Entry */

    box = mx_box_layout_new ();
    mx_box_layout_set_enable_animations ((MxBoxLayout *)box, TRUE);
    mx_box_layout_set_orientation ((MxBoxLayout *)box, MX_ORIENTATION_HORIZONTAL);
    mx_box_layout_set_spacing ((MxBoxLayout *)box, 4);

    priv->entry_box = box;
    mx_stylable_set_style_class (MX_STYLABLE(box), "ZoneSearchEntryBox");

    entry = mx_entry_new ();
    mx_stylable_set_style_class (MX_STYLABLE (entry), "ZoneSearchEntry");

    priv->search_location = (MxEntry *)entry;
    mx_entry_set_hint_text (MX_ENTRY (entry), _("Enter a country or city"));
    mx_entry_set_secondary_icon_from_file (MX_ENTRY (entry),
                                           THEMEDIR"/edit-clear.png");
    g_signal_connect (entry, "secondary-icon-clicked",
                      G_CALLBACK (clear_btn_clicked_cb), world_clock);

    g_signal_connect (G_OBJECT (entry),
                      "notify::text", G_CALLBACK (text_changed_cb), world_clock);

    clutter_actor_get_size (entry, &width, &height);
    clutter_actor_set_size (entry, width+10, -1);

    mx_box_layout_add_actor ((MxBoxLayout *)box, entry, 0);
    clutter_container_child_set (CLUTTER_CONTAINER (box),
                                 entry,
                                 "expand", FALSE,
                                 "y-fill", FALSE,
                                 "x-fill", FALSE,
                                 "y-align", MX_ALIGN_MIDDLE,
                                 "x-align", MX_ALIGN_START,
                                 NULL);

    priv->add_location = mx_button_new ();
    mx_button_set_label ((MxButton *)priv->add_location, _("Add"));
    mx_stylable_set_style_class (MX_STYLABLE(priv->add_location), "ZoneSearchEntryAddButton");

    /* mx_box_layout_add_actor ((MxBoxLayout *)box, priv->add_location, 1); */
    /* g_signal_connect (priv->add_location, "clicked",
                    	G_CALLBACK (add_location_clicked_cb), world_clock); */
    /*clutter_container_child_set (CLUTTER_CONTAINER (box),
                               priv->add_location,
                               "expand", FALSE,
    		       "y-fill", FALSE,
    		       "y-align", MX_ALIGN_MIDDLE,
                               NULL);*/


    mx_box_layout_add_actor (MX_BOX_LAYOUT(priv->widget_box), box, -1);
    clutter_container_child_set (CLUTTER_CONTAINER (priv->widget_box),
                                 box,
                                 "expand", FALSE,
                                 "y-fill", FALSE,
                                 "x-fill", FALSE,
                                 "x-align",  MX_ALIGN_START,
                                 NULL);

    /* Prep GeoClue */
    priv->geo_position = geoclue_position_new ("org.freedesktop.Geoclue.Providers.Hostip",
                         "/org/freedesktop/Geoclue/Providers/Hostip");

    priv->geo_geocode = geoclue_geocode_new ("org.freedesktop.Geoclue.Providers.Yahoo",
                        "/org/freedesktop/Geoclue/Providers/Yahoo");

    priv->geo_reverse_geocode = geoclue_reverse_geocode_new ("org.freedesktop.Geoclue.Providers.Nominatim",
                                "/org/freedesktop/Geoclue/Providers/Nominatim");

    geoclue_position_get_position_async (priv->geo_position,
                                         mnp_wc_get_position_cb,
                                         world_clock);

    /* Clock Area */

    priv->area = mnp_clock_area_new ();
    g_signal_connect (priv->area, "time-changed", G_CALLBACK(time_changed), world_clock);
    clutter_actor_set_size ((ClutterActor *)priv->area, 300, -1);

    clutter_actor_set_reactive ((ClutterActor *)priv->area, TRUE);
    clutter_actor_set_name ((ClutterActor *)priv->area, "WorldClockArea");

    clutter_container_add_actor ((ClutterContainer *)stage, (ClutterActor *)priv->area);

    clutter_actor_lower_bottom ((ClutterActor *)priv->area);
    mx_droppable_enable ((MxDroppable *)priv->area);
    g_object_ref ((GObject *)priv->area);
    clutter_container_remove_actor ((ClutterContainer *)stage, (ClutterActor *)priv->area);
    mx_box_layout_add_actor ((MxBoxLayout *) table, (ClutterActor *)priv->area, -1);
    clutter_container_child_set (CLUTTER_CONTAINER (table),
                                 (ClutterActor *)priv->area,
                                 "expand", TRUE,
                                 "y-fill", TRUE,
                                 "x-fill", TRUE,
                                 NULL);


    priv->zones = mnp_load_zones ();
    mnp_clock_area_refresh_time (priv->area, TRUE);
    mnp_clock_area_set_zone_remove_cb (priv->area, (ZoneRemovedFunc) zone_removed_cb, (gpointer)world_clock);
    mnp_clock_area_set_zone_reordered_cb (priv->area, (ClockZoneReorderedFunc) zone_reordered_cb, (gpointer)world_clock);

    if (priv->zones->len) {
        int i=0;

        for (i=0; i<priv->zones->len; i++) {
            MnpZoneLocation *loc = (MnpZoneLocation *)priv->zones->pdata[i];
            loc->local = FALSE;
            MnpClockTile *tile = mnp_clock_tile_new (loc, mnp_clock_area_get_time(priv->area), FALSE);
            mnp_clock_area_add_tile (priv->area, tile);
        }
        if (priv->zones->len >= 4)
            clutter_actor_hide (priv->entry_box);
    }

    /*	div = clutter_texture_new_from_file (SINGLE_DIV_LINE, NULL);
    	mx_box_layout_add_actor (MX_BOX_LAYOUT(world_clock), div, -1);
    */
    box = mx_box_layout_new ();
    clutter_actor_set_name (box, "DateTimeLauncherBox");
    priv->launcher_box = box;
    mx_box_layout_set_orientation ((MxBoxLayout *)box, MX_ORIENTATION_VERTICAL);
    mx_box_layout_set_spacing ((MxBoxLayout *)box, 6);

    priv->launcher = mx_button_new ();
    mx_button_set_label ((MxButton *) priv->launcher, _("Set Time & Date"));
    mx_stylable_set_style_class (MX_STYLABLE(priv->launcher), "DateTimeLauncherButton");

    mx_box_layout_add_actor ((MxBoxLayout *)box, priv->launcher, -1);
    clutter_container_child_set (CLUTTER_CONTAINER (box),
                                 (ClutterActor *)priv->launcher,
                                 "expand", FALSE,
                                 "y-fill", FALSE,
                                 "x-fill", FALSE,
                                 "x-align", MX_ALIGN_END,
                                 NULL);


    mx_box_layout_add_actor ((MxBoxLayout *)world_clock, box, -1);
}