[network-manager-applet/aleksander/mm1-applet: 3/10] applet: make the saving/deleting PIN in keyring a helper method
- From: Aleksander Morgado <aleksm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [network-manager-applet/aleksander/mm1-applet: 3/10] applet: make the saving/deleting PIN in keyring a helper method
- Date: Tue, 15 Jan 2013 10:28:20 +0000 (UTC)
commit 312044472330a3cc6ab41cf635f32c6539b21651
Author: Aleksander Morgado <aleksander lanedo com>
Date: Fri Dec 14 12:29:16 2012 +0100
applet: make the saving/deleting PIN in keyring a helper method
We'll use it not only for 'gsm' devices, but also for the new 'broadband' ones.
src/applet-device-gsm.c | 87 +---------------------------------------------
src/mobile-helpers.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++
src/mobile-helpers.h | 5 +++
3 files changed, 93 insertions(+), 85 deletions(-)
---
diff --git a/src/applet-device-gsm.c b/src/applet-device-gsm.c
index f522b67..0f0153e 100644
--- a/src/applet-device-gsm.c
+++ b/src/applet-device-gsm.c
@@ -675,89 +675,6 @@ gsm_get_secrets (SecretsRequest *req, GError **error)
/********************************************************************/
static void
-save_pin_cb (GnomeKeyringResult result, guint32 val, gpointer user_data)
-{
- if (result != GNOME_KEYRING_RESULT_OK)
- g_warning ("%s: result %d", (const char *) user_data, result);
-}
-
-static void
-set_pin_in_keyring (const char *devid,
- const char *simid,
- const char *pin)
-{
- GnomeKeyringAttributeList *attributes;
- GnomeKeyringAttribute attr;
- const char *name;
- char *error_msg;
-
- name = g_strdup_printf (_("PIN code for SIM card '%s' on '%s'"),
- simid ? simid : "unknown",
- devid);
-
- attributes = gnome_keyring_attribute_list_new ();
- attr.name = g_strdup ("devid");
- attr.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
- attr.value.string = g_strdup (devid);
- g_array_append_val (attributes, attr);
-
- if (simid) {
- attr.name = g_strdup ("simid");
- attr.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
- attr.value.string = g_strdup (simid);
- g_array_append_val (attributes, attr);
- }
-
- error_msg = g_strdup_printf ("Saving PIN code in keyring for devid:%s simid:%s failed",
- devid, simid ? simid : "(unknown)");
-
- gnome_keyring_item_create (NULL,
- GNOME_KEYRING_ITEM_GENERIC_SECRET,
- name,
- attributes,
- pin,
- TRUE,
- save_pin_cb,
- error_msg,
- (GDestroyNotify) g_free);
-
- gnome_keyring_attribute_list_free (attributes);
-}
-
-static void
-delete_pin_cb (GnomeKeyringResult result, gpointer user_data)
-{
- /* nothing to do */
-}
-
-static void
-delete_pins_find_cb (GnomeKeyringResult result, GList *list, gpointer user_data)
-{
- GList *iter;
-
- if (result == GNOME_KEYRING_RESULT_OK) {
- for (iter = list; iter; iter = g_list_next (iter)) {
- GnomeKeyringFound *found = iter->data;
-
- gnome_keyring_item_delete (found->keyring, found->item_id, delete_pin_cb, NULL, NULL);
- }
- }
-}
-
-static void
-delete_pins_in_keyring (const char *devid)
-{
- gnome_keyring_find_itemsv (GNOME_KEYRING_ITEM_GENERIC_SECRET,
- delete_pins_find_cb,
- NULL,
- NULL,
- "devid",
- GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
- devid,
- NULL);
-}
-
-static void
unlock_dialog_destroy (GsmDeviceInfo *info)
{
gtk_widget_destroy (info->dialog);
@@ -774,9 +691,9 @@ unlock_pin_reply (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
if (dbus_g_proxy_end_call (proxy, call, &error, G_TYPE_INVALID)) {
if (applet_mobile_pin_dialog_get_auto_unlock (info->dialog)) {
code1 = applet_mobile_pin_dialog_get_entry1 (info->dialog);
- set_pin_in_keyring (info->devid, info->simid, code1);
+ mobile_helper_save_pin_in_keyring (info->devid, info->simid, code1);
} else
- delete_pins_in_keyring (info->devid);
+ mobile_helper_delete_pin_in_keyring (info->devid);
unlock_dialog_destroy (info);
return;
}
diff --git a/src/mobile-helpers.c b/src/mobile-helpers.c
index 46aa2ef..9459002 100644
--- a/src/mobile-helpers.c
+++ b/src/mobile-helpers.c
@@ -22,6 +22,7 @@
#include <glib/gi18n.h>
#include <nm-utils.h>
+#include <gnome-keyring.h>
#include "utils.h"
#include "mobile-helpers.h"
@@ -272,3 +273,88 @@ mobile_helper_wizard (NMDeviceModemCapabilities capabilities,
return TRUE;
}
+
+/********************************************************************/
+
+static void
+save_pin_cb (GnomeKeyringResult result, guint32 val, gpointer user_data)
+{
+ if (result != GNOME_KEYRING_RESULT_OK)
+ g_warning ("%s: result %d", (const char *) user_data, result);
+}
+
+void
+mobile_helper_save_pin_in_keyring (const char *devid,
+ const char *simid,
+ const char *pin)
+{
+ GnomeKeyringAttributeList *attributes;
+ GnomeKeyringAttribute attr;
+ const char *name;
+ char *error_msg;
+
+ name = g_strdup_printf (_("PIN code for SIM card '%s' on '%s'"),
+ simid ? simid : "unknown",
+ devid);
+
+ attributes = gnome_keyring_attribute_list_new ();
+ attr.name = g_strdup ("devid");
+ attr.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
+ attr.value.string = g_strdup (devid);
+ g_array_append_val (attributes, attr);
+
+ if (simid) {
+ attr.name = g_strdup ("simid");
+ attr.type = GNOME_KEYRING_ATTRIBUTE_TYPE_STRING;
+ attr.value.string = g_strdup (simid);
+ g_array_append_val (attributes, attr);
+ }
+
+ error_msg = g_strdup_printf ("Saving PIN code in keyring for devid:%s simid:%s failed",
+ devid, simid ? simid : "(unknown)");
+
+ gnome_keyring_item_create (NULL,
+ GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ name,
+ attributes,
+ pin,
+ TRUE,
+ save_pin_cb,
+ error_msg,
+ (GDestroyNotify) g_free);
+
+ gnome_keyring_attribute_list_free (attributes);
+}
+
+static void
+delete_pin_cb (GnomeKeyringResult result, gpointer user_data)
+{
+ /* nothing to do */
+}
+
+static void
+delete_pins_find_cb (GnomeKeyringResult result, GList *list, gpointer user_data)
+{
+ GList *iter;
+
+ if (result == GNOME_KEYRING_RESULT_OK) {
+ for (iter = list; iter; iter = g_list_next (iter)) {
+ GnomeKeyringFound *found = iter->data;
+
+ gnome_keyring_item_delete (found->keyring, found->item_id, delete_pin_cb, NULL, NULL);
+ }
+ }
+}
+
+void
+mobile_helper_delete_pin_in_keyring (const char *devid)
+{
+ gnome_keyring_find_itemsv (GNOME_KEYRING_ITEM_GENERIC_SECRET,
+ delete_pins_find_cb,
+ NULL,
+ NULL,
+ "devid",
+ GNOME_KEYRING_ATTRIBUTE_TYPE_STRING,
+ devid,
+ NULL);
+}
diff --git a/src/mobile-helpers.h b/src/mobile-helpers.h
index 7c5d060..09efd4c 100644
--- a/src/mobile-helpers.h
+++ b/src/mobile-helpers.h
@@ -67,4 +67,9 @@ gboolean mobile_helper_wizard (NMDeviceModemCapabilities capabilities,
AppletNewAutoConnectionCallback callback,
gpointer callback_data);
+void mobile_helper_save_pin_in_keyring (const char *devid,
+ const char *simid,
+ const char *pin);
+void mobile_helper_delete_pin_in_keyring (const char *devid);
+
#endif /* APPLET_MOBILE_HELPERS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]