1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
6
* Copyright (C) 2001 The Free Software Foundation, Inc.
8
* This program is free software; you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License as published by
10
* the Free Software Foundation; either version 2 of the License, or
11
* (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
18
* You should have received a copy of the GNU General Public License
19
* along with this program. If not, see <http://www.gnu.org/licenses/>.
25
#include "fr-window.h"
26
#include "gtk-utils.h"
27
#include "glib-utils.h"
28
#include "preferences.h"
29
#include "dlg-password.h"
32
#define GET_WIDGET(x) (_gtk_builder_get_widget (data->builder, (x)))
42
/* called when the main dialog is closed. */
44
destroy_cb (GtkWidget *widget,
47
g_object_unref (data->builder);
53
response_cb (GtkWidget *dialog,
57
if (response_id == GTK_RESPONSE_OK) {
59
gboolean encrypt_header;
61
password = _gtk_entry_get_locale_text (GTK_ENTRY (GET_WIDGET ("password_entry")));
62
encrypt_header = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("encrypt_header_checkbutton")));
63
fr_window_archive_encrypt (data->window, password, encrypt_header);
68
gtk_widget_destroy (data->dialog);
73
dlg_password (GtkWidget *widget,
74
gpointer callback_data)
76
FrWindow *window = callback_data;
78
GtkWidget *content_area;
82
data = g_new0 (DialogData, 1);
83
data->window = window;
84
data->builder = _gtk_builder_new_from_resource ("password.ui");
85
if (data->builder == NULL) {
90
/* Set widgets data. */
92
data->dialog = g_object_new (GTK_TYPE_DIALOG,
93
"transient-for", GTK_WINDOW (window),
95
"use-header-bar", _gtk_settings_get_dialogs_use_header (),
97
content_area = gtk_dialog_get_content_area (GTK_DIALOG (data->dialog));
98
gtk_container_add (GTK_CONTAINER (content_area),
99
GET_WIDGET ("password_vbox"));
100
gtk_dialog_add_buttons (GTK_DIALOG (data->dialog),
101
_GTK_LABEL_CANCEL, GTK_RESPONSE_CANCEL,
102
_GTK_LABEL_SAVE, GTK_RESPONSE_OK,
104
gtk_dialog_set_default_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK);
105
gtk_style_context_add_class (gtk_widget_get_style_context (gtk_dialog_get_widget_for_response (GTK_DIALOG (data->dialog), GTK_RESPONSE_OK)),
106
GTK_STYLE_CLASS_SUGGESTED_ACTION);
108
basename = _g_file_get_display_basename (fr_archive_get_file (window->archive));
109
title = g_strdup_printf (_("Enter a password for “%s”"), basename);
110
gtk_label_set_text (GTK_LABEL (GET_WIDGET ("title_label")), title);
115
_gtk_entry_use_as_password_entry (GTK_ENTRY (GET_WIDGET ("password_entry")));
116
_gtk_entry_set_locale_text (GTK_ENTRY (GET_WIDGET ("password_entry")),
117
fr_window_get_password (window));
118
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (GET_WIDGET ("encrypt_header_checkbutton")),
119
fr_window_get_encrypt_header (window));
121
if (! fr_archive_is_capable_of (window->archive, FR_ARCHIVE_CAN_ENCRYPT_HEADER)) {
122
gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (GET_WIDGET ("encrypt_header_checkbutton")), TRUE);
123
gtk_widget_set_sensitive (GET_WIDGET ("encrypt_header_checkbutton"), FALSE);
126
/* Set the signals handlers. */
128
g_signal_connect ((data->dialog),
130
G_CALLBACK (destroy_cb),
132
g_signal_connect ((data->dialog),
134
G_CALLBACK (response_cb),
139
gtk_widget_grab_focus (GET_WIDGET ("password_entry"));
140
gtk_widget_show (data->dialog);