summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Zeuthen <davidz@redhat.com>2011-05-20 18:32:47 -0400
committerDavid Zeuthen <davidz@redhat.com>2011-05-20 18:32:47 -0400
commit21374619064eb50c1cee8adf6d43d0b4be66c624 (patch)
tree3bdb9245ac489dbb7f09acbffd9c6e36f4d3eaf7
parent074ed2f39d1cf9f08fde02f262ced8355599a4ef (diff)
Add check buttons and headings
Signed-off-by: David Zeuthen <davidz@redhat.com>
-rw-r--r--src/goabackend/goagenericmailprovider.c15
-rw-r--r--src/goabackend/goaprovider.c185
-rw-r--r--src/goabackend/goaprovider.h13
3 files changed, 209 insertions, 4 deletions
diff --git a/src/goabackend/goagenericmailprovider.c b/src/goabackend/goagenericmailprovider.c
index d7845c6..c4cf486 100644
--- a/src/goabackend/goagenericmailprovider.c
+++ b/src/goabackend/goagenericmailprovider.c
@@ -827,8 +827,23 @@ show_account (GoaProvider *provider,
/* Chain up */
GOA_PROVIDER_CLASS (goa_generic_mail_provider_parent_class)->show_account (provider, client, object, vbox, table);
+ /* TODO: passwords */
+
goa_util_add_row_editable_label_from_keyfile (table, object, _("Email Address"), "EmailAddress", FALSE);
+
+ goa_util_add_heading (table, _("Receiving Mail"));
+
goa_util_add_row_editable_label_from_keyfile (table, object, _("IMAP Server"), "ImapHost", TRUE);
+ goa_util_add_row_editable_label_from_keyfile (table, object, _("User Name"), "ImapUserName", TRUE);
+ goa_util_add_row_check_button_from_keyfile (table, object, NULL, "ImapUseTls", _("Use s_ecure connection"));
+ goa_util_add_row_check_button_from_keyfile (table, object, NULL, "ImapIgnoreBadTls", _("_Don't check certificates"));
+
+ goa_util_add_heading (table, _("Sending Mail"));
+
+ goa_util_add_row_editable_label_from_keyfile (table, object, _("SMTP Server"), "SmtpHost", TRUE);
+ goa_util_add_row_editable_label_from_keyfile (table, object, _("User Name"), "SmtpUserName", TRUE);
+ goa_util_add_row_check_button_from_keyfile (table, object, NULL, "SmtpUseTls", _("Use s_ecure connection"));
+ goa_util_add_row_check_button_from_keyfile (table, object, NULL, "SmtpIgnoreBadTls", _("_Don't check certificates"));
}
/* ---------------------------------------------------------------------------------------------------- */
diff --git a/src/goabackend/goaprovider.c b/src/goabackend/goaprovider.c
index 44159df..4cfe2ab 100644
--- a/src/goabackend/goaprovider.c
+++ b/src/goabackend/goaprovider.c
@@ -1074,11 +1074,11 @@ keyfile_switch_on_notify_active (GObject *object,
* @label_text: (allow-none): The text to insert on the left side or %NULL for no label.
* @key: The key in the key-value file for @object to look up.
*
- * Adds a #GoaEditableLabel to @table that reads its value from the
- * key-value file for @object using @key. If it's edited, the new
- * value is written back to the key-value file.
+ * Adds a #GtkSwitch to @table that reads its #GtkSwitch:active value
+ * from the key-value file for @object using @key. If it's switched,
+ * the new value is written back to the key-value file.
*
- * Returns: (transfer none): The #GoaEditableLabel that was inserted.
+ * Returns: (transfer none): The #GtkSwitch that was inserted.
*/
GtkWidget *
goa_util_add_row_switch_from_keyfile (GtkTable *table,
@@ -1145,3 +1145,180 @@ goa_util_add_row_switch_from_keyfile (GtkTable *table,
}
/* ---------------------------------------------------------------------------------------------------- */
+
+static void
+keyfile_check_button_on_notify_active (GObject *object,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ KeyFileEditableData *data = user_data;
+ GoaAccount *account;
+ GError *error;
+ GKeyFile *key_file;
+ gchar *contents;
+ gsize length;
+
+ account = goa_object_peek_account (data->object);
+
+ key_file = g_key_file_new ();
+ error = NULL;
+ if (!g_key_file_load_from_file (key_file,
+ goa_account_get_keyfile_path (account),
+ G_KEY_FILE_KEEP_COMMENTS | G_KEY_FILE_KEEP_TRANSLATIONS,
+ &error))
+ {
+ goa_warning ("Error loading keyfile %s: %s (%s, %d)",
+ goa_account_get_keyfile_path (account),
+ error->message, g_quark_to_string (error->domain), error->code);
+ g_error_free (error);
+ goto out;
+ }
+
+ g_key_file_set_boolean (key_file,
+ goa_account_get_keyfile_group (account),
+ data->key,
+ gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (object)));
+
+ error = NULL;
+ contents = g_key_file_to_data (key_file,
+ &length,
+ &error);
+ if (contents == NULL)
+ {
+ g_prefix_error (&error,
+ "Error generating key-value-file %s: ",
+ goa_account_get_keyfile_path (account));
+ goa_warning ("%s (%s, %d)",
+ error->message, g_quark_to_string (error->domain), error->code);
+ g_error_free (error);
+ goto out;
+ }
+
+ error = NULL;
+ if (!g_file_set_contents (goa_account_get_keyfile_path (account),
+ contents,
+ length,
+ &error))
+ {
+ g_prefix_error (&error,
+ "Error writing key-value-file %s: ",
+ goa_account_get_keyfile_path (account));
+ goa_warning ("%s (%s, %d)",
+ error->message, g_quark_to_string (error->domain), error->code);
+ g_error_free (error);
+ goto out;
+ }
+
+ out:
+ g_key_file_free (key_file);
+}
+
+/**
+ * goa_util_add_row_check_button_from_keyfile:
+ * @table: A #GtkTable.
+ * @object: A #GoaObject for an account.
+ * @label_text: (allow-none): The text to insert on the left side or %NULL for no label.
+ * @key: The key in the key-value file for @object to look up.
+ * @value_mnemonic: The mnemonic text to use for the check button.
+ *
+ * Adds a #GtkCheckButton to @table that reads its value from the
+ * key-value file for @object using @key. If it's toggled, the new
+ * value is written back to the key-value file.
+ *
+ * Returns: (transfer none): The #GtkCheckButton that was inserted.
+ */
+GtkWidget *
+goa_util_add_row_check_button_from_keyfile (GtkTable *table,
+ GoaObject *object,
+ const gchar *label_text,
+ const gchar *key,
+ const gchar *value_mnemonic)
+{
+ GoaAccount *account;
+ GtkWidget *check_button;
+ GKeyFile *key_file;
+ GError *error;
+ gboolean value;
+
+ key_file = NULL;
+
+ account = goa_object_peek_account (object);
+ check_button = gtk_check_button_new_with_mnemonic (value_mnemonic);
+
+ key_file = g_key_file_new ();
+ error = NULL;
+ if (!g_key_file_load_from_file (key_file,
+ goa_account_get_keyfile_path (account),
+ G_KEY_FILE_NONE,
+ &error))
+ {
+ goa_warning ("Error loading keyfile %s: %s (%s, %d)",
+ goa_account_get_keyfile_path (account),
+ error->message, g_quark_to_string (error->domain), error->code);
+ g_error_free (error);
+ goto out;
+ }
+ value = g_key_file_get_boolean (key_file,
+ goa_account_get_keyfile_group (account),
+ key,
+ &error);
+ if (error != NULL)
+ {
+ /* this is not fatal (think upgrade-path) */
+ goa_debug ("Error getting boolean value for key %s from keyfile %s: %s (%s, %d)",
+ key,
+ goa_account_get_keyfile_path (account),
+ error->message, g_quark_to_string (error->domain), error->code);
+ g_error_free (error);
+ goto out;
+ }
+
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button), value);
+
+ out:
+ g_signal_connect_data (check_button,
+ "notify::active",
+ G_CALLBACK (keyfile_check_button_on_notify_active),
+ keyfile_editable_data_new (object, key),
+ (GClosureNotify) keyfile_editable_data_free,
+ 0); /* GConnectFlags */
+ if (key_file != NULL)
+ g_key_file_free (key_file);
+
+ return goa_util_add_row_widget (table, label_text, check_button);
+}
+
+/* ---------------------------------------------------------------------------------------------------- */
+
+/**
+ * goa_util_add_heading:
+ * @table: A #GtkTable.
+ * @heading_text: The text for the heading.
+ *
+ * Utility function to add a heading to @table.
+ *
+ * Returns: (transfer none): The #GtkWidget that was inserted.
+ */
+GtkWidget *
+goa_util_add_heading (GtkTable *table,
+ const gchar *heading_text)
+{
+ GtkWidget *label;
+ guint num_rows;
+ gchar *s;
+
+ gtk_table_get_size (table, &num_rows, NULL);
+ s = g_strdup_printf ("<b>%s</b>", heading_text);
+ label = gtk_label_new (NULL);
+ gtk_label_set_markup (GTK_LABEL (label), s);
+ gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
+ gtk_widget_set_margin_top (label, 6);
+ gtk_widget_set_margin_bottom (label, 6);
+ gtk_table_attach (table, label,
+ 0, 1,
+ num_rows, num_rows + 1,
+ GTK_FILL, GTK_FILL, 0, 0);
+ g_free (s);
+
+ return label;
+}
diff --git a/src/goabackend/goaprovider.h b/src/goabackend/goaprovider.h
index e83fc9f..7db7737 100644
--- a/src/goabackend/goaprovider.h
+++ b/src/goabackend/goaprovider.h
@@ -163,6 +163,11 @@ gboolean goa_provider_ensure_credentials_sync (GoaProvider *provid
GList *goa_provider_get_all (void);
GoaProvider *goa_provider_get_for_provider_type (const gchar *provider_type);
+/* ---------------------------------------------------------------------------------------------------- */
+
+GtkWidget *goa_util_add_heading (GtkTable *table,
+ const gchar *heading_text);
+
GtkWidget *goa_util_add_row_widget (GtkTable *table,
const gchar *label_text,
GtkWidget *widget);
@@ -181,6 +186,14 @@ GtkWidget *goa_util_add_row_switch_from_keyfile (GtkTable *table,
const gchar *label_text,
const gchar *key);
+GtkWidget *
+goa_util_add_row_check_button_from_keyfile (GtkTable *table,
+ GoaObject *object,
+ const gchar *label_text,
+ const gchar *key,
+ const gchar *value_mnemonic);
+
+
G_END_DECLS
#endif /* __GOA_PROVIDER_H__ */