"Fossies" - the Fresh Open Source Software Archive

Member "seahorse-3.34/pgp/seahorse-unknown-source.c" (1 Oct 2019, 8492 Bytes) of package /linux/privat/seahorse-3.34.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "seahorse-unknown-source.c" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes reports: 3.31.91_vs_3.32 or 3.30.1.1_vs_3.32.

    1 /*
    2  * Seahorse
    3  *
    4  * Copyright (C) 2006 Stefan Walter
    5  * Copyright (C) 2011 Collabora Ltd.
    6  *
    7  * This program is free software; you can redistribute it and/or modify
    8  * it under the terms of the GNU General Public License as published by
    9  * the Free Software Foundation; either version 2 of the License, or
   10  * (at your option) any later version.
   11  *
   12  * This program is distributed in the hope that it will be useful,
   13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
   15  * See the GNU General Public License for more details.
   16  * You should have received a copy of the GNU General Public License
   17  * along with this program; if not, see
   18  * <http://www.gnu.org/licenses/>.
   19  */
   20 
   21 #include "config.h"
   22 
   23 #include "seahorse-unknown-source.h"
   24 
   25 #include "seahorse-pgp-key.h"
   26 #include "seahorse-unknown.h"
   27 
   28 #include <gcr/gcr-base.h>
   29 
   30 #include <glib/gi18n.h>
   31 
   32 enum {
   33     PROP_0,
   34     PROP_LABEL,
   35     PROP_DESCRIPTION,
   36     PROP_ICON,
   37     PROP_URI,
   38     PROP_ACTIONS,
   39     PROP_ACTION_PREFIX,
   40     PROP_MENU_MODEL
   41 };
   42 
   43 struct _SeahorseUnknownSource {
   44     GObject parent;
   45     GHashTable *keys;
   46 };
   47 
   48 struct _SeahorseUnknownSourceClass {
   49     GObjectClass parent_class;
   50 };
   51 
   52 static void      seahorse_unknown_source_collection_iface      (GcrCollectionIface *iface);
   53 
   54 static void      seahorse_unknown_source_place_iface           (SeahorsePlaceIface *iface);
   55 
   56 G_DEFINE_TYPE_WITH_CODE (SeahorseUnknownSource, seahorse_unknown_source, G_TYPE_OBJECT,
   57                          G_IMPLEMENT_INTERFACE (GCR_TYPE_COLLECTION, seahorse_unknown_source_collection_iface);
   58                          G_IMPLEMENT_INTERFACE (SEAHORSE_TYPE_PLACE, seahorse_unknown_source_place_iface);
   59 );
   60 
   61 static void
   62 seahorse_unknown_source_init (SeahorseUnknownSource *self)
   63 {
   64     self->keys = g_hash_table_new_full (seahorse_pgp_keyid_hash,
   65                                         seahorse_pgp_keyid_equal,
   66                                         g_free, g_object_unref);
   67 }
   68 
   69 static void
   70 seahorse_unknown_source_load (SeahorsePlace *self,
   71                               GCancellable *cancellable,
   72                               GAsyncReadyCallback callback,
   73                               gpointer user_data)
   74 {
   75     g_return_if_reached ();
   76 }
   77 
   78 static gboolean
   79 seahorse_unknown_source_load_finish (SeahorsePlace *self,
   80                                      GAsyncResult *res,
   81                                      GError **error)
   82 {
   83     g_return_val_if_reached (FALSE);
   84 }
   85 
   86 static gchar *
   87 seahorse_unknown_source_get_label (SeahorsePlace* self)
   88 {
   89     return g_strdup ("");
   90 }
   91 
   92 static void
   93 seahorse_unknown_source_set_label (SeahorsePlace *self, const char *label)
   94 {
   95 }
   96 
   97 static gchar *
   98 seahorse_unknown_source_get_description (SeahorsePlace* self)
   99 {
  100     return NULL;
  101 }
  102 
  103 static gchar *
  104 seahorse_unknown_source_get_uri (SeahorsePlace* self)
  105 {
  106     return NULL;
  107 }
  108 
  109 static GIcon *
  110 seahorse_unknown_source_get_icon (SeahorsePlace* self)
  111 {
  112     return NULL;
  113 }
  114 
  115 static GActionGroup *
  116 seahorse_unknown_source_get_actions (SeahorsePlace* self)
  117 {
  118     return NULL;
  119 }
  120 
  121 static const gchar *
  122 seahorse_unknown_source_get_action_prefix (SeahorsePlace* self)
  123 {
  124     return NULL;
  125 }
  126 
  127 static GMenuModel *
  128 seahorse_unknown_source_get_menu_model (SeahorsePlace* self)
  129 {
  130     return NULL;
  131 }
  132 
  133 static void
  134 seahorse_unknown_source_get_property (GObject *obj,
  135                                       guint prop_id,
  136                                       GValue *value,
  137                                       GParamSpec *pspec)
  138 {
  139     SeahorsePlace *place = SEAHORSE_PLACE (obj);
  140 
  141     switch (prop_id) {
  142     case PROP_LABEL:
  143         g_value_take_string (value, seahorse_unknown_source_get_label (place));
  144         break;
  145     case PROP_DESCRIPTION:
  146         g_value_take_string (value, seahorse_unknown_source_get_description (place));
  147         break;
  148     case PROP_URI:
  149         g_value_take_string (value, seahorse_unknown_source_get_uri (place));
  150         break;
  151     case PROP_ICON:
  152         g_value_take_object (value, seahorse_unknown_source_get_icon (place));
  153         break;
  154     case PROP_ACTIONS:
  155         g_value_take_object (value, seahorse_unknown_source_get_actions (place));
  156         break;
  157     case PROP_ACTION_PREFIX:
  158         g_value_set_string (value, seahorse_unknown_source_get_action_prefix (place));
  159         break;
  160     case PROP_MENU_MODEL:
  161         g_value_take_object (value, seahorse_unknown_source_get_menu_model (place));
  162         break;
  163     default:
  164         G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
  165         break;
  166     }
  167 }
  168 
  169 static void
  170 seahorse_unknown_source_set_property (GObject *obj,
  171                                       guint prop_id,
  172                                       const GValue *value,
  173                                       GParamSpec *pspec)
  174 {
  175     SeahorsePlace *place = SEAHORSE_PLACE (obj);
  176 
  177     switch (prop_id) {
  178     case PROP_LABEL:
  179         seahorse_unknown_source_set_label (place, g_value_get_boxed (value));
  180         break;
  181     default:
  182         G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, prop_id, pspec);
  183         break;
  184     }
  185 }
  186 
  187 static void
  188 seahorse_unknown_source_finalize (GObject *obj)
  189 {
  190     SeahorseUnknownSource *self = SEAHORSE_UNKNOWN_SOURCE (obj);
  191 
  192     g_hash_table_destroy (self->keys);
  193 
  194     G_OBJECT_CLASS (seahorse_unknown_source_parent_class)->finalize (obj);
  195 }
  196 
  197 static void
  198 seahorse_unknown_source_class_init (SeahorseUnknownSourceClass *klass)
  199 {
  200     GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
  201 
  202     gobject_class->get_property = seahorse_unknown_source_get_property;
  203     gobject_class->set_property = seahorse_unknown_source_set_property;
  204     gobject_class->finalize = seahorse_unknown_source_finalize;
  205 
  206     g_object_class_override_property (gobject_class, PROP_LABEL, "label");
  207     g_object_class_override_property (gobject_class, PROP_DESCRIPTION, "description");
  208     g_object_class_override_property (gobject_class, PROP_ICON, "icon");
  209     g_object_class_override_property (gobject_class, PROP_ACTIONS, "actions");
  210     g_object_class_override_property (gobject_class, PROP_ACTION_PREFIX, "action-prefix");
  211     g_object_class_override_property (gobject_class, PROP_MENU_MODEL, "menu-model");
  212     g_object_class_override_property (gobject_class, PROP_URI, "uri");
  213 }
  214 
  215 static guint
  216 seahorse_unknown_source_get_length (GcrCollection *collection)
  217 {
  218     SeahorseUnknownSource *self = SEAHORSE_UNKNOWN_SOURCE (collection);
  219     return g_hash_table_size (self->keys);
  220 }
  221 
  222 static GList *
  223 seahorse_unknown_source_get_objects (GcrCollection *collection)
  224 {
  225     SeahorseUnknownSource *self = SEAHORSE_UNKNOWN_SOURCE (collection);
  226     return g_hash_table_get_values (self->keys);
  227 }
  228 
  229 static gboolean
  230 seahorse_unknown_source_contains (GcrCollection *collection,
  231                                   GObject *object)
  232 {
  233     SeahorseUnknownSource *self = SEAHORSE_UNKNOWN_SOURCE (collection);
  234     const gchar *identifier = seahorse_object_get_identifier (SEAHORSE_OBJECT (object));
  235     return g_hash_table_lookup (self->keys, identifier) == object;
  236 }
  237 
  238 static void
  239 seahorse_unknown_source_collection_iface (GcrCollectionIface *iface)
  240 {
  241     iface->contains = seahorse_unknown_source_contains;
  242     iface->get_length = seahorse_unknown_source_get_length;
  243     iface->get_objects = seahorse_unknown_source_get_objects;
  244 }
  245 
  246 static void
  247 seahorse_unknown_source_place_iface (SeahorsePlaceIface *iface)
  248 {
  249     iface->load = seahorse_unknown_source_load;
  250     iface->load_finish = seahorse_unknown_source_load_finish;
  251     iface->get_actions = seahorse_unknown_source_get_actions;
  252     iface->get_menu_model = seahorse_unknown_source_get_menu_model;
  253     iface->get_description = seahorse_unknown_source_get_description;
  254     iface->get_icon = seahorse_unknown_source_get_icon;
  255     iface->get_label = seahorse_unknown_source_get_label;
  256     iface->set_label = seahorse_unknown_source_set_label;
  257     iface->get_uri = seahorse_unknown_source_get_uri;
  258 }
  259 
  260 SeahorseUnknownSource*
  261 seahorse_unknown_source_new (void)
  262 {
  263     return g_object_new (SEAHORSE_TYPE_UNKNOWN_SOURCE, NULL);
  264 }
  265 
  266 static void
  267 on_cancellable_gone (gpointer user_data,
  268                      GObject *where_the_object_was)
  269 {
  270     /* TODO: Change the icon */
  271 }
  272 
  273 SeahorseObject *
  274 seahorse_unknown_source_add_object (SeahorseUnknownSource *self,
  275                                     const gchar *keyid,
  276                                     GCancellable *cancellable)
  277 {
  278     SeahorseObject *object;
  279 
  280     g_return_val_if_fail (keyid != NULL, NULL);
  281     g_return_val_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable), NULL);
  282 
  283     object = g_hash_table_lookup (self->keys, keyid);
  284     if (object == NULL) {
  285         object = SEAHORSE_OBJECT (seahorse_unknown_new (self, keyid, NULL));
  286         g_hash_table_insert (self->keys, g_strdup (keyid), object);
  287     }
  288 
  289     if (cancellable)
  290         g_object_weak_ref (G_OBJECT (cancellable), on_cancellable_gone, object);
  291 
  292     return object;
  293 }