~elementary-os/elementaryos/os-patch-file-roller-bionic-old

« back to all changes in this revision

Viewing changes to src/dlg-password.c

  • Committer: RabbitBot
  • Date: 2018-02-05 12:55:45 UTC
  • Revision ID: rabbitbot@elementary.io-20180205125545-nmwn0wosptxjg5ei
Initial import, version 3.26.2-3ubuntu1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
 
 
3
/*
 
4
 *  File-Roller
 
5
 *
 
6
 *  Copyright (C) 2001 The Free Software Foundation, Inc.
 
7
 *
 
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.
 
12
 *
 
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.
 
17
 *
 
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/>.
 
20
 */
 
21
 
 
22
#include <config.h>
 
23
#include <string.h>
 
24
#include <gtk/gtk.h>
 
25
#include "fr-window.h"
 
26
#include "gtk-utils.h"
 
27
#include "glib-utils.h"
 
28
#include "preferences.h"
 
29
#include "dlg-password.h"
 
30
 
 
31
 
 
32
#define GET_WIDGET(x) (_gtk_builder_get_widget (data->builder, (x)))
 
33
 
 
34
 
 
35
typedef struct {
 
36
        GtkBuilder *builder;
 
37
        FrWindow   *window;
 
38
        GtkWidget  *dialog;
 
39
} DialogData;
 
40
 
 
41
 
 
42
/* called when the main dialog is closed. */
 
43
static void
 
44
destroy_cb (GtkWidget  *widget,
 
45
            DialogData *data)
 
46
{
 
47
        g_object_unref (data->builder);
 
48
        g_free (data);
 
49
}
 
50
 
 
51
 
 
52
static void
 
53
response_cb (GtkWidget  *dialog,
 
54
             int         response_id,
 
55
             DialogData *data)
 
56
{
 
57
        if (response_id == GTK_RESPONSE_OK) {
 
58
                char      *password;
 
59
                gboolean   encrypt_header;
 
60
 
 
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);
 
64
 
 
65
                g_free (password);
 
66
        }
 
67
 
 
68
        gtk_widget_destroy (data->dialog);
 
69
}
 
70
 
 
71
 
 
72
void
 
73
dlg_password (GtkWidget *widget,
 
74
              gpointer   callback_data)
 
75
{
 
76
        FrWindow   *window = callback_data;
 
77
        DialogData *data;
 
78
        GtkWidget  *content_area;
 
79
        char       *basename;
 
80
        char       *title;
 
81
 
 
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) {
 
86
                g_free (data);
 
87
                return;
 
88
        }
 
89
 
 
90
        /* Set widgets data. */
 
91
 
 
92
        data->dialog = g_object_new (GTK_TYPE_DIALOG,
 
93
                                     "transient-for", GTK_WINDOW (window),
 
94
                                     "modal", TRUE,
 
95
                                     "use-header-bar", _gtk_settings_get_dialogs_use_header (),
 
96
                                     NULL);
 
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,
 
103
                                NULL);
 
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);
 
107
 
 
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);
 
111
 
 
112
        g_free (title);
 
113
        g_free (basename);
 
114
 
 
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));
 
120
 
 
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);
 
124
        }
 
125
 
 
126
        /* Set the signals handlers. */
 
127
 
 
128
        g_signal_connect ((data->dialog),
 
129
                          "destroy",
 
130
                          G_CALLBACK (destroy_cb),
 
131
                          data);
 
132
        g_signal_connect ((data->dialog),
 
133
                          "response",
 
134
                          G_CALLBACK (response_cb),
 
135
                          data);
 
136
 
 
137
        /* Run dialog. */
 
138
 
 
139
        gtk_widget_grab_focus (GET_WIDGET ("password_entry"));
 
140
        gtk_widget_show (data->dialog);
 
141
}