/** * unregister_child: * @self: The parent * @child: child to remove * * * removes @child from the children list in @self */ static void unregister_child (SeahorseObject* self, SeahorseObject* child) { g_assert (SEAHORSE_IS_OBJECT (self)); g_assert (SEAHORSE_IS_OBJECT (child)); g_assert (self != child); g_assert (child->pv->parent == self); child->pv->parent = NULL; self->pv->children = g_list_remove (self->pv->children, child); }
/** * 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_object_predicate_match: * @self: the object to test * @obj: The predicate to match * * matches a seahorse object and a predicate * * Returns: FALSE if predicate does not match the #SeahorseObject, TRUE else */ gboolean seahorse_object_predicate_match (SeahorseObjectPredicate *self, SeahorseObject* obj) { SeahorseObjectPrivate *pv; g_return_val_if_fail (SEAHORSE_IS_OBJECT (obj), FALSE); pv = obj->pv; seahorse_object_realize (obj); /* Check all the fields */ if (self->tag != 0 && self->tag != pv->tag) return FALSE; if (self->id != 0 && self->id != pv->id) return FALSE; if (self->type != 0 && self->type != G_OBJECT_TYPE (obj)) return FALSE; if (self->location != 0 && self->location != pv->location) return FALSE; if (self->usage != 0 && self->usage != pv->usage) return FALSE; if (self->flags != 0 && (self->flags & pv->flags) == 0) return FALSE; if (self->nflags != 0 && (self->nflags & pv->flags) != 0) return FALSE; if (self->source != NULL && self->source != pv->source) return FALSE; /* And any custom stuff */ if (self->custom != NULL && !self->custom (obj, self->custom_target)) return FALSE; return TRUE; }
/** * seahorse_object_get_children: * @self: Object * * Returns: the children of the object @self */ GList* seahorse_object_get_children (SeahorseObject *self) { g_return_val_if_fail (SEAHORSE_IS_OBJECT (self), NULL); seahorse_object_realize (self); return g_list_copy (self->pv->children); }
/** * seahorse_object_get_markup: * @self: Object * * Returns: the markup of the object @self */ const gchar* seahorse_object_get_markup (SeahorseObject *self) { g_return_val_if_fail (SEAHORSE_IS_OBJECT (self), NULL); seahorse_object_realize (self); return self->pv->markup; }
/** * sort_objects_by_source: * @k1: the first seahorse object * @k2: The second seahorse object * * Sorts the seahorse objects by their source * * Returns: if source of k1<k2 it returns -1, * 1 will be returned if k1>k2. If the sources are equal it returns 0 */ static gint sort_objects_by_source (SeahorseObject *k1, SeahorseObject *k2) { SeahorseSource *sk1, *sk2; g_assert (SEAHORSE_IS_OBJECT (k1)); g_assert (SEAHORSE_IS_OBJECT (k2)); sk1 = seahorse_object_get_source (k1); sk2 = seahorse_object_get_source (k2); if (sk1 == sk2) return 0; return sk1 < sk2 ? -1 : 1; }
/** * seahorse_object_get_flags: * @self: Object * * Returns: the flags of the object @self */ guint seahorse_object_get_flags (SeahorseObject *self) { g_return_val_if_fail (SEAHORSE_IS_OBJECT (self), 0); seahorse_object_realize (self); return self->pv->flags; }
/** * seahorse_object_get_identifier: * @self: Object * * Returns: the identifier of the object @self */ const gchar* seahorse_object_get_identifier (SeahorseObject *self) { g_return_val_if_fail (SEAHORSE_IS_OBJECT (self), NULL); seahorse_object_realize (self); return self->pv->identifier; }
/** * seahorse_object_get_description: * @self: Object * * Returns: the description of the object @self */ const gchar* seahorse_object_get_description (SeahorseObject *self) { g_return_val_if_fail (SEAHORSE_IS_OBJECT (self), NULL); seahorse_object_realize (self); return self->pv->description; }
/** * seahorse_util_objects_splice: * @objects: A #GList of #SeahorseObject. Must be sorted * * Splices the list at the source disconuity * * Returns: The second part of the list. */ GList* seahorse_util_objects_splice (GList *objects) { SeahorseSource *psk = NULL; SeahorseSource *sk; GList *prev = NULL; /* Note that the objects must be sorted */ for ( ; objects; objects = g_list_next (objects)) { g_return_val_if_fail (SEAHORSE_IS_OBJECT (objects->data), NULL); sk = seahorse_object_get_source (SEAHORSE_OBJECT (objects->data)); /* Found a disconuity */ if (psk && sk != psk) { g_assert (prev != NULL); /* Break the list */ prev->next = NULL; /* And return the new list */ return objects; } psk = sk; prev = objects; } return NULL; }
/** * seahorse_context_take_object: * @sctx: The #SeahorseContext context to add an object to * @sobj: The #SeahorseObject object to add * * Adds @sobj to @sctx. If a similar object exists, it will be overwritten. * Emits the "added" signal. */ void seahorse_context_take_object (SeahorseContext *sctx, SeahorseObject *sobj) { gpointer ks; if (!sctx) sctx = seahorse_context_for_app (); g_return_if_fail (SEAHORSE_IS_CONTEXT (sctx)); g_return_if_fail (SEAHORSE_IS_OBJECT (sobj)); g_return_if_fail (seahorse_object_get_id (sobj) != 0); ks = hashkey_by_source (seahorse_object_get_source (sobj), seahorse_object_get_id (sobj)); g_return_if_fail (!g_hash_table_lookup (sctx->pv->objects_by_source, ks)); g_object_ref (sobj); g_object_set (sobj, "context", sctx, NULL); g_hash_table_replace (sctx->pv->objects_by_source, ks, sobj); setup_objects_by_type (sctx, sobj, TRUE); g_signal_emit (sctx, signals[ADDED], 0, sobj); g_object_unref (sobj); g_signal_connect (sobj, "notify", G_CALLBACK (object_notify), sctx); }
/** * seahorse_context_remove_object: * @sctx: The #SeahorseContext (can be NULL) * @sobj: The #SeahorseObject to remove * * Removes the object from the context * */ void seahorse_context_remove_object (SeahorseContext *sctx, SeahorseObject *sobj) { gconstpointer k; if (!sctx) sctx = seahorse_context_for_app (); g_return_if_fail (SEAHORSE_IS_CONTEXT (sctx)); g_return_if_fail (SEAHORSE_IS_OBJECT (sobj)); g_return_if_fail (seahorse_object_get_id (sobj) != 0); k = hashkey_by_source (seahorse_object_get_source (sobj), seahorse_object_get_id (sobj)); if (g_hash_table_lookup (sctx->pv->objects_by_source, k)) { g_return_if_fail (seahorse_object_get_context (sobj) == sctx); g_object_ref (sobj); g_signal_handlers_disconnect_by_func (sobj, object_notify, sctx); g_object_set (sobj, "context", NULL, NULL); g_hash_table_remove (sctx->pv->objects_by_source, k); setup_objects_by_type (sctx, sobj, FALSE); g_signal_emit (sctx, signals[REMOVED], 0, sobj); g_object_unref (sobj); } }
/** * seahorse_object_get_usage: * @self: Object * * Returns: the usage of the object @self */ SeahorseUsage seahorse_object_get_usage (SeahorseObject *self) { g_return_val_if_fail (SEAHORSE_IS_OBJECT (self), SEAHORSE_USAGE_NONE); if (self->pv->usage == SEAHORSE_USAGE_NONE) seahorse_object_realize (self); return self->pv->usage; }
/** * seahorse_object_get_location: * @self: Object * * Returns: the location of the object @self */ SeahorseLocation seahorse_object_get_location (SeahorseObject *self) { g_return_val_if_fail (SEAHORSE_IS_OBJECT (self), SEAHORSE_LOCATION_INVALID); if (self->pv->location == SEAHORSE_LOCATION_INVALID) seahorse_object_realize (self); return self->pv->location; }
/** * seahorse_object_get_tag: * @self: Object * * Returns: the tag of the object @self */ GQuark seahorse_object_get_tag (SeahorseObject *self) { g_return_val_if_fail (SEAHORSE_IS_OBJECT (self), 0); if (!self->pv->tag) seahorse_object_realize (self); return self->pv->tag; }
/** * seahorse_object_refresh: * @self: object to refresh * * calls the class refresh function * */ void seahorse_object_refresh (SeahorseObject *self) { SeahorseObjectClass *klass; g_return_if_fail (SEAHORSE_IS_OBJECT (self)); klass = SEAHORSE_OBJECT_GET_CLASS (self); g_return_if_fail (klass->refresh); (klass->refresh) (self); }
/** * key: a pointer to a key to verify (hashkey) * value: a seahorse object * user_data: ignored * * Asserts that the @key is the same as the one stored in @value * **/ static void verify_each_object (gpointer key, gpointer value, gpointer user_data) { gpointer k; g_assert (SEAHORSE_IS_OBJECT (value)); k = hashkey_by_source (seahorse_object_get_source (value), seahorse_object_get_id (value)); g_assert (k == key); }
/** * seahorse_object_dispose: * @obj: A #SeahorseObject to dispose * * Before this object is disposed, all it's children get new parents * */ static void seahorse_object_dispose (GObject *obj) { SeahorseObject *self = SEAHORSE_OBJECT (obj); SeahorseObject *parent; GList *l, *children; if (self->pv->context != NULL) { seahorse_context_remove_object (self->pv->context, self); g_assert (self->pv->context == NULL); } if (self->pv->source != NULL) { g_object_remove_weak_pointer (G_OBJECT (self->pv->source), (gpointer*)&self->pv->source); self->pv->source = NULL; } if (self->pv->preferred != NULL) { g_object_remove_weak_pointer (G_OBJECT (self->pv->source), (gpointer*)&self->pv->preferred); self->pv->preferred = NULL; } /* * When an object is destroyed, we reparent all * children to this objects parent. If no parent * of this object, all children become root objects. */ parent = self->pv->parent; if (parent) g_object_ref (parent); children = g_list_copy (self->pv->children); for (l = children; l; l = g_list_next (l)) { g_return_if_fail (SEAHORSE_IS_OBJECT (l->data)); seahorse_object_set_parent (l->data, parent); } g_list_free (children); if (parent) g_object_unref (parent); g_assert (self->pv->children == NULL); /* Now remove this object from its parent */ seahorse_object_set_parent (self, NULL); G_OBJECT_CLASS (seahorse_object_parent_class)->dispose (obj); }
static void seahorse_gkr_keyring_commands_show_properties (SeahorseCommands* base, SeahorseObject* object) { GtkWindow *window; g_return_if_fail (SEAHORSE_IS_OBJECT (object)); g_return_if_fail (seahorse_object_get_tag (object) == SEAHORSE_GKR_TYPE); window = seahorse_view_get_window (seahorse_commands_get_view (base)); if (G_OBJECT_TYPE (object) == SEAHORSE_TYPE_GKR_KEYRING) seahorse_gkr_keyring_properties_show (SEAHORSE_GKR_KEYRING (object), window); else g_return_if_reached (); }
/** * seahorse_object_realize: * @self: the object to realize * * * Realizes an object. Calls the klass method */ void seahorse_object_realize (SeahorseObject *self) { SeahorseObjectClass *klass; g_return_if_fail (SEAHORSE_IS_OBJECT (self)); if (self->pv->realized) return; if (self->pv->realizing) return; klass = SEAHORSE_OBJECT_GET_CLASS (self); g_return_if_fail (klass->realize); self->pv->realizing = TRUE; (klass->realize) (self); self->pv->realizing = FALSE; }
/** * seahorse_object_set_preferred: * @self: the object to set the preferred object for * @value: the preferred object * * */ void seahorse_object_set_preferred (SeahorseObject *self, SeahorseObject *value) { g_return_if_fail (SEAHORSE_IS_OBJECT (self)); if (self->pv->preferred == value) return; if (self->pv->preferred) g_object_remove_weak_pointer (G_OBJECT (self->pv->preferred), (gpointer*)&self->pv->preferred); self->pv->preferred = value; if (self->pv->preferred != NULL) g_object_add_weak_pointer (G_OBJECT (self->pv->preferred), (gpointer*)&self->pv->preferred); g_object_notify (G_OBJECT (self), "preferred"); }
/** * seahorse_object_set_source: * @self: The object to set a new source for * @value: The source to set * * sets the source for the object */ void seahorse_object_set_source (SeahorseObject *self, SeahorseSource *value) { g_return_if_fail (SEAHORSE_IS_OBJECT (self)); if (value == self->pv->source) return; if (self->pv->source) g_object_remove_weak_pointer (G_OBJECT (self->pv->source), (gpointer*)&self->pv->source); self->pv->source = value; if (self->pv->source != NULL) g_object_add_weak_pointer (G_OBJECT (self->pv->source), (gpointer*)&self->pv->source); g_object_notify (G_OBJECT (self), "source"); }
/** * seahorse_object_lookup_property: * @self: the object to look up the property * @field: the field to lookup * @value: the returned value * * Looks up the property @field in the object @self and returns it in @value * * Returns: TRUE if a property was found */ gboolean seahorse_object_lookup_property (SeahorseObject *self, const gchar *field, GValue *value) { GParamSpec *spec; g_return_val_if_fail (SEAHORSE_IS_OBJECT (self), FALSE); g_return_val_if_fail (field, FALSE); g_return_val_if_fail (value, FALSE); spec = g_object_class_find_property (G_OBJECT_GET_CLASS (self), field); if (!spec) { /* Some name mapping to new style names */ if (g_str_equal (field, "simple-name")) field = "nickname"; else if (g_str_equal (field, "key-id")) field = "identifier"; else if (g_str_equal (field, "display-name")) field = "label"; else if (g_str_equal (field, "key-desc")) field = "description"; else if (g_str_equal (field, "ktype")) field = "tag"; else if (g_str_equal (field, "etype")) field = "usage"; else if (g_str_equal (field, "display-id")) field = "identifier"; else if (g_str_equal (field, "stock-id")) field = "icon"; else if (g_str_equal (field, "raw-id")) field = "identifier"; else return FALSE; /* Try again */ spec = g_object_class_find_property (G_OBJECT_GET_CLASS (self), field); if (!spec) return FALSE; } g_value_init (value, spec->value_type); g_object_get_property (G_OBJECT (self), field, value); return TRUE; }
/** * seahorse_object_set_parent: * @self: the child * @value: the parent * * register @value as the parent of @self: */ void seahorse_object_set_parent (SeahorseObject *self, SeahorseObject *value) { g_return_if_fail (SEAHORSE_IS_OBJECT (self)); g_return_if_fail (self->pv->parent != self); g_return_if_fail (value != self); if (value == self->pv->parent) return; /* Set the new parent/child relationship */ if (self->pv->parent != NULL) unregister_child (self->pv->parent, self); if (value != NULL) register_child (value, self); g_assert (self->pv->parent == value); g_object_notify (G_OBJECT (self), "parent"); }
static gboolean on_filter_objects (SeahorseObject *obj, SeahorseKeyserverResults *self) { const gchar *match; gboolean ret = FALSE; gchar* value; gsize n_value, n_match; g_return_val_if_fail (SEAHORSE_IS_KEYSERVER_RESULTS (self), FALSE); g_return_val_if_fail (SEAHORSE_IS_OBJECT (obj), FALSE); match = self->pv->search_string; if (g_utf8_strlen (match, -1) == 0) ret = TRUE; /* Match against the label */ if (ret != TRUE) { value = g_utf8_casefold (seahorse_object_get_label (obj), -1); ret = strstr (value, match) != NULL; g_free (value); } /* Match against the key identifier */ if (ret != TRUE) { if (strncmp (match, "0x", 2) == 0) match += 2; value = g_utf8_casefold (seahorse_object_get_identifier (obj), -1); /* Only compare as many bytes as exist in the key id */ n_value = strlen (value); n_match = strlen (match); if (n_value > n_match) match += (n_value - n_match); ret = strstr (value, match) != NULL; g_free (value); } return ret; }
/** * seahorse_util_filename_for_objects: * @objects: A list of objects * * If the single object has a nickname, this will be returned (with .asc attached) * If there are multiple objects, "Multiple Keys.asc" will be returned. * Single objects default to "Key Data.asc". * Results are internationalized * * Returns: NULL on error, the filename else. The returned string should be * freed with #g_free when no longer needed. */ gchar* seahorse_util_filename_for_objects (GList *objects) { SeahorseObject *object; const gchar *name; gchar *filename; g_return_val_if_fail (g_list_length (objects) > 0, NULL); if (g_list_length (objects) == 1) { g_return_val_if_fail (SEAHORSE_IS_OBJECT (objects->data), NULL); object = SEAHORSE_OBJECT (objects->data); name = seahorse_object_get_nickname (object); if (name == NULL) name = _("Key Data"); } else { name = _("Multiple Keys"); } filename = g_strconcat (name, SEAHORSE_EXT_ASC, NULL); g_strstrip (filename); g_strdelimit (filename, bad_filename_chars, '_'); return filename; }
/** * seahorse_object_get_nth_child: * @self: Object * @index: the number of the child to return * * Returns: the child number @index */ SeahorseObject* seahorse_object_get_nth_child (SeahorseObject *self, guint index) { g_return_val_if_fail (SEAHORSE_IS_OBJECT (self), NULL); return SEAHORSE_OBJECT (g_list_nth_data (self->pv->children, index)); }
/** * seahorse_object_get_parent: * @self: Object * * Returns: the parent of the object @self */ SeahorseObject* seahorse_object_get_parent (SeahorseObject *self) { g_return_val_if_fail (SEAHORSE_IS_OBJECT (self), NULL); return self->pv->parent; }
/** * seahorse_object_get_preferred: * @self: Object * * Returns: the preferred of the object @self */ SeahorseObject* seahorse_object_get_preferred (SeahorseObject *self) { g_return_val_if_fail (SEAHORSE_IS_OBJECT (self), NULL); return self->pv->preferred; }
/** * seahorse_object_get_context: * @self: Object * * Returns: the context of the object @self */ SeahorseContext* seahorse_object_get_context (SeahorseObject *self) { g_return_val_if_fail (SEAHORSE_IS_OBJECT (self), NULL); return self->pv->context; }