Commit a877cea1 authored by Jon Kåre Hellan's avatar Jon Kåre Hellan

Pass filename to cmd_context_get_password.

* plugins/excel/ms-excel-read.c (excel_read_workbook): Pass filename to
cmd_context_get_password.

* src/dialogs/Makefile.am (base_files): Add dialog-password.c

* src/dialogs/dialog-password.c: Add.
(cb_accept_password): Moved from workbook-control-gui.c.
(dialog_get_password): New function with material taken from
wbcg_get_password in workbook-control-gui.c.

* src/application.c (gnumeric_application_setup_icons): Add
Gnumeric_Protection_Yes_Dialog.

* src/pixmaps/protection_yes_48.png: Add.

* src/pixmaps/Makefile.am:  Add protection_yes_48.png.

* src/workbook-control-gui.c (cb_accept_password): Move to
dialogs/dialog-password.c.
(wbcg_get_password): Most of it moved to dialog_get_password in
dialogs/dialog-password.c.

* src/io-context-gtk.c (icg_get_password): New function which
implements CommandContext::get_password.
(icg_class_init): Connect icg_get_password.

* src/command-context-priv.h (CommandContextClass.get_password):
Ditto.

* src/command-context-stderr.c (ccs_get_password): Ditto.

* src/workbook-control-component.c (wbcc_get_password): Ditto.

* src/io-context.c (ioc_get_password): Ditto.
parent f4aefbcb
......@@ -597,6 +597,7 @@ gnumeric_application_setup_icons (void)
{ gnm_pivottable_24, gnm_pivottable_16, "Gnumeric_PivotTable" },
{ gnm_protection_yes, NULL, "Gnumeric_Protection_Yes" },
{ gnm_protection_no, NULL, "Gnumeric_Protection_No" },
{ gnm_protection_yes_48, NULL, "Gnumeric_Protection_Yes_Dialog" },
{ gnm_link_add_24, gnm_link_add_16, "Gnumeric_Link_Add" },
{ NULL, gnm_link_delete_16, "Gnumeric_Link_Delete" },
......
......@@ -10,8 +10,10 @@ struct _CommandContext {
typedef struct {
GObjectClass g_object_class;
char * (*get_password) (CommandContext *cc, char const *msg);
void (*set_sensitive) (CommandContext *cc, gboolean sensitive);
char * (*get_password) (CommandContext *cc,
char const *filename);
void (*set_sensitive) (CommandContext *cc,
gboolean sensitive);
void (*progress_set) (CommandContext *cc, gfloat val);
void (*progress_message_set) (CommandContext *cc, gchar const *msg);
struct {
......
......@@ -79,7 +79,7 @@ ccs_init (CommandContextStderr *ccs)
static char *
ccs_get_password (G_GNUC_UNUSED CommandContext *cc,
G_GNUC_UNUSED char const* msg)
G_GNUC_UNUSED char const* filename)
{
return NULL;
}
......
......@@ -161,11 +161,11 @@ cmd_context_progress_message_set (CommandContext *context, gchar const *msg)
}
char *
cmd_context_get_password (CommandContext *cc, char const *msg)
cmd_context_get_password (CommandContext *cc, char const *filename)
{
g_return_val_if_fail (IS_COMMAND_CONTEXT (cc), NULL);
return CC_CLASS (cc)->get_password (cc, msg);
return CC_CLASS (cc)->get_password (cc, filename);
}
void
......
......@@ -11,7 +11,7 @@
GType command_context_get_type (void);
void cmd_context_error (CommandContext *cc, GError *err);
char *cmd_context_get_password (CommandContext *cc, char const *msg);
char *cmd_context_get_password (CommandContext *cc, char const *filename);
void cmd_context_set_sensitive (CommandContext *cc, gboolean sensitive);
/* utility routines for common errors */
......
2002-12-30 Jon K Hellan <hellan@acm.org>
* Makefile.am (base_files): Add dialog-password.c
* dialog-password.c: Add.
(cb_accept_password): Moved from workbook-control-gui.c.
(dialog_get_password): New function with material taken from
wbcg_get_password in workbook-control-gui.c.
2002-12-24 Jody Goldberg <jody@gnome.org>
* dialog-workbook-attr.c : clean up includes
......
......@@ -48,6 +48,7 @@ base_files = \
dialog-define-names.c \
dialog-delete-cells.c \
dialog-merge.c \
dialog-password.c \
dialog-paste-special.c \
dialog-pivottable.c \
dialog-plugin-manager.c \
......
#include <gnumeric-config.h>
#include <gtk/gtkdialog.h>
#include <gtk/gtkentry.h>
#include <gtk/gtkenums.h>
#include <gtk/gtkimage.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkstock.h>
#include <gtk/gtkvbox.h>
#include <gnumeric-i18n.h>
#include "dialogs.h"
static void
cb_accept_password (GtkWidget *IGNORED, GtkDialog *d)
{
gtk_dialog_response (d, GTK_RESPONSE_ACCEPT);
}
char *
dialog_get_password (GtkWindow *parent, const char *filename)
{
char *res = NULL;
char *str;
char *basename;
char *primary;
char *secondary;
GtkWidget *d, *hb, *vb, *pwb, *image, *label, *entry;
basename = g_path_get_basename (filename);
primary = g_strdup_printf (_("%s is encrypted"), basename);
g_free (basename);
secondary = _("Encrypted files require a password\nbefore they can be opened.");
label = gtk_label_new (NULL);
str = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">"
"%s</span>\n\n%s", primary, secondary);
gtk_label_set_markup (GTK_LABEL (label), str);
g_free (primary);
g_free (str);
gtk_label_set_selectable (GTK_LABEL (label), TRUE);
d = gtk_dialog_new_with_buttons ("", parent,
GTK_DIALOG_DESTROY_WITH_PARENT |
GTK_DIALOG_NO_SEPARATOR,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL);
gtk_window_set_resizable (GTK_WINDOW (d), FALSE);
hb = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (d)->vbox), hb,
TRUE, TRUE, 8);
image = gtk_image_new_from_stock ("Gnumeric_Protection_Yes_Dialog",
GTK_ICON_SIZE_DIALOG);
gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
gtk_box_pack_start (GTK_BOX (hb), image, FALSE, FALSE, 0);
vb = gtk_vbox_new (FALSE, 8);
gtk_box_pack_start (GTK_BOX (hb), vb, TRUE, TRUE, 6);
gtk_box_pack_start_defaults (GTK_BOX (vb), label);
pwb = gtk_hbox_new (FALSE, 8);
/* Strange width so that width of primary/secondary text will win. */
entry = g_object_new (GTK_TYPE_ENTRY,
"visibility", FALSE,
"width_request", 1, NULL);
gtk_box_pack_start (GTK_BOX (pwb), gtk_label_new (_("Password :")),
FALSE, FALSE, 0);
gtk_box_pack_start_defaults (GTK_BOX (pwb), entry);
gtk_box_pack_start (GTK_BOX (vb), pwb, FALSE, FALSE, 0);
gtk_widget_show_all (d);
g_signal_connect (G_OBJECT (entry),
"activate",
G_CALLBACK (cb_accept_password), d);
if (gtk_dialog_run (GTK_DIALOG (d)) == GTK_RESPONSE_ACCEPT)
res = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
gtk_widget_destroy (d);
return res;
}
......@@ -98,6 +98,7 @@ typedef enum {
} ttest_type;
int dialog_ttest_tool (WorkbookControlGUI *wbcg, Sheet *sheet, ttest_type test);
char *dialog_get_password (GtkWindow *parent, const char *filename);
/* Modeless dialogs */
void dialog_summary_update (WorkbookControlGUI *wbcg, gboolean open_dialogs);
......
......@@ -16,6 +16,7 @@
#include "io-context-gtk.h"
#include "io-context-priv.h"
#include "libgnumeric.h"
#include "dialogs.h"
#include <gsf/gsf-impl-utils.h>
#include <gtk/gtkdialog.h>
#include <gtk/gtklabel.h>
......@@ -153,6 +154,13 @@ icg_user_is_impatient (IOContextGtk *icg)
return g_timer_elapsed (icg->timer, NULL) > ICG_POPUP_DELAY;
}
static char *
icg_get_password (CommandContext *cc, char const *filename)
{
IOContextGtk *icg = IO_CONTEXT_GTK (cc);
return dialog_get_password (icg->window, filename);
}
static void
icg_progress_set (CommandContext *cc, gfloat val)
{
......@@ -235,6 +243,7 @@ icg_class_init (IOContextGtkClass *klass)
G_OBJECT_CLASS (klass)->finalize = icg_finalize;
cc_class->get_password = icg_get_password;
cc_class->progress_set = icg_progress_set;
cc_class->progress_message_set = icg_progress_message_set;
cc_class->error.error_info = icg_error_error_info;
......
......@@ -64,10 +64,10 @@ ioc_finalize (GObject *obj)
}
static char *
ioc_get_password (CommandContext *cc, char const *msg)
ioc_get_password (CommandContext *cc, char const *filename)
{
IOContext *ioc = (IOContext *)cc;
return cmd_context_get_password (ioc->impl, msg);
return cmd_context_get_password (ioc->impl, filename);
}
static void
......
......@@ -71,6 +71,7 @@ IMAGES = @STRIP_BEGIN@ \
pivottable_16.png pivottable_24.png \
protection_no_24.png \
protection_yes_24.png \
protection_yes_48.png \
\
link_add_16.png link_add_24.png \
link_delete_16.png \
......@@ -178,6 +179,7 @@ VARIABLES = @STRIP_BEGIN@ \
gnm_pivottable_24 $(srcdir)/pivottable_24.png \
gnm_protection_no $(srcdir)/protection_no_24.png \
gnm_protection_yes $(srcdir)/protection_yes_24.png \
gnm_protection_yes_48 $(srcdir)/protection_yes_48.png \
\
gnm_link_add_16 $(srcdir)/link_add_16.png \
gnm_link_add_24 $(srcdir)/link_add_24.png \
......
......@@ -15,7 +15,7 @@
#include "workbook-edit.h"
static char *
wbcc_get_password (CommandContext *cc, char const* msg) { return NULL; }
wbcc_get_password (CommandContext *cc, char const* filename) { return NULL; }
static void
wbcc_set_sensitive (CommandContext *wbc, gboolean sensitive) {}
......
......@@ -1461,42 +1461,12 @@ wbcg_claim_selection (WorkbookControl *wbc)
return x_claim_clipboard ((WorkbookControlGUI *)wbc);
}
static void
cb_accept_password (GtkWidget *IGNORED, GtkDialog *d)
{
gtk_dialog_response (d, GTK_RESPONSE_ACCEPT);
}
static char *
wbcg_get_password (CommandContext *cc, char const* msg)
wbcg_get_password (CommandContext *cc, char const* filename)
{
char *res = NULL;
WorkbookControlGUI *wbcg = WORKBOOK_CONTROL_GUI (cc);
GtkWidget *d = gtk_message_dialog_new (wbcg_toplevel (wbcg),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_CANCEL,
msg);
GtkWidget *box = gtk_hbox_new (FALSE, 5);
GtkWidget *entry = g_object_new (GTK_TYPE_ENTRY,
"visibility", FALSE,
NULL);
gtk_box_pack_start_defaults (GTK_BOX (box), gtk_label_new (_("Password :")));
gtk_box_pack_start_defaults (GTK_BOX (box), entry);
gtk_widget_show_all (entry);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (d)->vbox), box,
FALSE, TRUE, 0);
gtk_widget_show_all (d);
g_signal_connect (G_OBJECT (entry),
"activate",
G_CALLBACK (cb_accept_password), d);
gtk_dialog_set_has_separator (GTK_DIALOG (d), TRUE);
gnumeric_set_transient (wbcg, GTK_WINDOW (d));
if (gtk_dialog_run (GTK_DIALOG (d)) == GTK_RESPONSE_ACCEPT)
res = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));
gtk_widget_destroy (d);
return res;
return dialog_get_password (wbcg_toplevel (wbcg), filename);
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment