/** * a: the first #SeahorseObject * b: the second #SeahorseObject * * Compares the locations of the two objects * * Returns 0 if a==b, -1 or 1 on difference **/ static gint sort_by_location (gconstpointer a, gconstpointer b) { guint aloc, bloc; g_assert (SEAHORSE_IS_OBJECT (a)); g_assert (SEAHORSE_IS_OBJECT (b)); aloc = seahorse_object_get_location (SEAHORSE_OBJECT (a)); bloc = seahorse_object_get_location (SEAHORSE_OBJECT (b)); if (aloc == bloc) return 0; return aloc > bloc ? -1 : 1; }
/** * seahorse_context_find_object: * @sctx: The #SeahorseContext to work with (can be NULL) * @id: The id to look for * @location: The location to look for (at least) * * Finds the object with the id @id at location @location or better. * Local is better than remote... * * Returns: the matching #SeahorseObject or NULL if none is found */ SeahorseObject* seahorse_context_find_object (SeahorseContext *sctx, GQuark id, SeahorseLocation location) { SeahorseObject *sobj; if (!sctx) sctx = seahorse_context_for_app (); g_return_val_if_fail (SEAHORSE_IS_CONTEXT (sctx), NULL); sobj = (SeahorseObject*)g_hash_table_lookup (sctx->pv->objects_by_type, GUINT_TO_POINTER (id)); while (sobj) { /* If at the end and no more objects in list, return */ if (location == SEAHORSE_LOCATION_INVALID && !seahorse_object_get_preferred (sobj)) return sobj; if (location >= seahorse_object_get_location (sobj)) return sobj; /* Look down the list for this location */ sobj = seahorse_object_get_preferred (sobj); } return NULL; }
/** * seahorse_object_get_property: * @obj: The object to get the property for * @prop_id: The property requested * @value: out - the value as #GValue * @pspec: a #GParamSpec for the warning * * Returns: The property of the object @obj defined by the id @prop_id in @value. * */ static void seahorse_object_get_property (GObject *obj, guint prop_id, GValue *value, GParamSpec *pspec) { SeahorseObject *self = SEAHORSE_OBJECT (obj); switch (prop_id) { case PROP_CONTEXT: g_value_set_object (value, seahorse_object_get_context (self)); break; case PROP_SOURCE: g_value_set_object (value, seahorse_object_get_source (self)); break; case PROP_PREFERRED: g_value_set_object (value, seahorse_object_get_preferred (self)); break; case PROP_PARENT: g_value_set_object (value, seahorse_object_get_parent (self)); break; case PROP_ID: g_value_set_uint (value, seahorse_object_get_id (self)); break; case PROP_TAG: g_value_set_uint (value, seahorse_object_get_tag (self)); break; case PROP_LABEL: g_value_set_string (value, seahorse_object_get_label (self)); break; case PROP_NICKNAME: g_value_set_string (value, seahorse_object_get_nickname (self)); break; case PROP_MARKUP: g_value_set_string (value, seahorse_object_get_markup (self)); break; case PROP_DESCRIPTION: g_value_set_string (value, seahorse_object_get_description (self)); break; case PROP_ICON: g_value_set_string (value, seahorse_object_get_icon (self)); break; case PROP_IDENTIFIER: g_value_set_string (value, seahorse_object_get_identifier (self)); break; case PROP_LOCATION: g_value_set_enum (value, seahorse_object_get_location (self)); break; case PROP_USAGE: g_value_set_enum (value, seahorse_object_get_usage (self)); break; case PROP_FLAGS: g_value_set_uint (value, seahorse_object_get_flags (self)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec); break; } }
/** * seahorse_context_discover_objects: * @sctx: the context to work with (can be NULL) * @ktype: the type of key to discover * @rawids: a list of ids to discover * * Downloads a list of keys from the keyserver * * Returns: The imported keys */ GList* seahorse_context_discover_objects (SeahorseContext *sctx, GQuark ktype, GSList *rawids) { SeahorseOperation *op = NULL; GList *robjects = NULL; GQuark id = 0; GSList *todiscover = NULL; GList *toimport = NULL; SeahorseSource *sksrc; SeahorseObject* sobj; SeahorseLocation loc; GSList *l; if (!sctx) sctx = seahorse_context_for_app (); g_return_val_if_fail (SEAHORSE_IS_CONTEXT (sctx), NULL); /* Check all the ids */ for (l = rawids; l; l = g_slist_next (l)) { id = seahorse_context_canonize_id (ktype, (gchar*)l->data); if (!id) { /* TODO: Try and match this partial id */ g_warning ("invalid id: %s", (gchar*)l->data); continue; } /* Do we know about this object? */ sobj = seahorse_context_find_object (sctx, id, SEAHORSE_LOCATION_INVALID); /* No such object anywhere, discover it */ if (!sobj) { todiscover = g_slist_prepend (todiscover, GUINT_TO_POINTER (id)); id = 0; continue; } /* Our return value */ robjects = g_list_prepend (robjects, sobj); /* We know about this object, check where it is */ loc = seahorse_object_get_location (sobj); g_assert (loc != SEAHORSE_LOCATION_INVALID); /* Do nothing for local objects */ if (loc >= SEAHORSE_LOCATION_LOCAL) continue; /* Remote objects get imported */ else if (loc >= SEAHORSE_LOCATION_REMOTE) toimport = g_list_prepend (toimport, sobj); /* Searching objects are ignored */ else if (loc >= SEAHORSE_LOCATION_SEARCHING) continue; /* TODO: Should we try SEAHORSE_LOCATION_MISSING objects again? */ } /* Start an import process on all toimport */ if (toimport) { op = seahorse_context_transfer_objects (sctx, toimport, NULL); g_list_free (toimport); /* Running operations ref themselves */ g_object_unref (op); } /* Start a discover process on all todiscover */ if (seahorse_gconf_get_boolean (AUTORETRIEVE_KEY) && todiscover) { op = seahorse_context_retrieve_objects (sctx, ktype, todiscover, NULL); /* Running operations ref themselves */ g_object_unref (op); } /* Add unknown objects for all these */ sksrc = seahorse_context_find_source (sctx, ktype, SEAHORSE_LOCATION_MISSING); for (l = todiscover; l; l = g_slist_next (l)) { if (sksrc) { sobj = seahorse_unknown_source_add_object (SEAHORSE_UNKNOWN_SOURCE (sksrc), GPOINTER_TO_UINT (l->data), op); robjects = g_list_prepend (robjects, sobj); } } g_slist_free (todiscover); return robjects; }