seahorse-prefs.c 5.21 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
/*
 * Seahorse
 *
 * Copyright (C) 2004-2005 Stefan Walter
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the
 * Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330,
 * Boston, MA 02111-1307, USA.
 */
#include "config.h"

#include <gtk/gtk.h>
#include <glib/gi18n.h>

#include <cryptui.h>
#include <cryptui-key-combo.h>
#include <cryptui-key-store.h>

#include "seahorse-prefs.h"
#include "seahorse-util.h"
#include "seahorse-check-button-control.h"
#include "seahorse-gconf.h"
#include "seahorse-gtkstock.h"
35
#include "seahorse-secure-buffer.h"
36
#include "seahorse-widget.h"
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92

/* From seahorse-prefs-cache.c */
void seahorse_prefs_cache (SeahorseWidget *widget);

/* From sehorse-prefs-keyrings.c */
void seahorse_prefs_keyrings (SeahorseWidget *widget);

/* -------------------------------------------------------------------------- */

static void
default_key_changed (GtkComboBox *combo, gpointer *data)
{
    const gchar *key = cryptui_key_combo_get_key (combo);
    seahorse_gconf_set_string (SEAHORSE_DEFAULT_KEY, key == 0 ? "" : key);
}

static void
gconf_notification (GConfClient *gclient, guint id, GConfEntry *entry, 
                    GtkComboBox *combo)
{
    const gchar *key = gconf_value_get_string (gconf_entry_get_value (entry));
    cryptui_key_combo_set_key (combo, key);
}

static void
remove_gconf_notification (GObject *obj, gpointer data)
{
    guint gconf_id = GPOINTER_TO_INT (data);
    seahorse_gconf_unnotify (gconf_id);
}

static gboolean 
signer_filter (CryptUIKeyset *ckset, const gchar *key, gpointer user_data)
{
    guint flags = cryptui_keyset_key_flags (ckset, key);
    return flags & CRYPTUI_FLAG_CAN_SIGN;
}

/**
 * seahorse_prefs_new
 * 
 * Create a new preferences window.
 * 
 * Returns: The preferences window.
 **/
SeahorseWidget *
seahorse_prefs_new (GtkWindow *parent)
{
    SeahorseWidget *swidget;
    CryptUIKeyset* keyset;
    CryptUIKeyStore* ckstore;
    GtkWidget *widget;
    guint gconf_id;
    
    swidget = seahorse_widget_new ("prefs", parent);
    
93
    widget = GTK_WIDGET (seahorse_widget_get_widget (swidget, "encrypt-self"));
94 95
    seahorse_check_button_gconf_attach (GTK_CHECK_BUTTON (widget), ENCRYPTSELF_KEY);
    
96
    widget = GTK_WIDGET (seahorse_widget_get_widget (swidget, "signer-select"));
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
    g_return_val_if_fail (widget != NULL, NULL);

    /* The Sign combo */
    keyset = cryptui_keyset_new ("openpgp", FALSE);
    ckstore = cryptui_key_store_new (keyset, FALSE, _("None. Prompt for a key."));
    cryptui_key_store_set_filter (ckstore, signer_filter, NULL);
    cryptui_key_combo_setup (GTK_COMBO_BOX (widget), ckstore);
    g_object_unref (ckstore);
    g_object_unref (keyset);

    cryptui_key_combo_set_key (GTK_COMBO_BOX (widget), seahorse_gconf_get_string (SEAHORSE_DEFAULT_KEY));
    g_signal_connect (widget, "changed", G_CALLBACK (default_key_changed), NULL);

    gconf_id = seahorse_gconf_notify (SEAHORSE_DEFAULT_KEY, 
                                      (GConfClientNotifyFunc)gconf_notification, GTK_COMBO_BOX (widget));
    g_signal_connect (widget, "destroy", G_CALLBACK (remove_gconf_notification), GINT_TO_POINTER (gconf_id));
    
#ifdef WITH_AGENT   
    seahorse_prefs_cache (swidget);
#else
117
    widget = GTK_WIDGET (seahorse_widget_get_widget (swidget, "cache-tab"));
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    g_return_val_if_fail (GTK_IS_WIDGET (widget), swidget);
    seahorse_prefs_remove_tab (swidget, widget);
#endif

    seahorse_widget_show (swidget);
    return swidget;
}

/**
 * seahorse_prefs_add_tab
 * @swidget: The preferences window
 * 
 * Add a tab to the preferences window
 **/
void                
seahorse_prefs_add_tab (SeahorseWidget *swidget, GtkWidget *label, GtkWidget *tab)
{
    GtkWidget *widget;
136
    widget = GTK_WIDGET (seahorse_widget_get_widget (swidget, "notebook"));
137 138 139 140 141 142 143 144 145 146 147 148
    gtk_widget_show (label);
    gtk_notebook_prepend_page (GTK_NOTEBOOK (widget), tab, label);
}

void                
seahorse_prefs_select_tab (SeahorseWidget *swidget, GtkWidget *tab)
{
    GtkWidget *tabs;
    gint pos;
    
    g_return_if_fail (GTK_IS_WIDGET (tab));
    
149
    tabs = GTK_WIDGET (seahorse_widget_get_widget (swidget, "notebook"));
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
    g_return_if_fail (GTK_IS_NOTEBOOK (tabs));
    
    pos = gtk_notebook_page_num (GTK_NOTEBOOK (tabs), tab);
    if (pos != -1)
        gtk_notebook_set_current_page (GTK_NOTEBOOK (tabs), pos);
}    

void 
seahorse_prefs_remove_tab (SeahorseWidget *swidget, GtkWidget *tab)
{
    GtkWidget *tabs;
    gint pos;
    
    g_return_if_fail (GTK_IS_WIDGET (tab));
    
165
    tabs = GTK_WIDGET (seahorse_widget_get_widget (swidget, "notebook"));
166 167 168 169 170 171
    g_return_if_fail (GTK_IS_NOTEBOOK (tabs));
    
    pos = gtk_notebook_page_num (GTK_NOTEBOOK (tabs), tab);
    if (pos != -1)
        gtk_notebook_remove_page (GTK_NOTEBOOK (tabs), pos);
}