/* Licensed to Stichting The Commons Conservancy (TCC) under one or more * contributor license agreements. See the AUTHORS file distributed with * this work for additional information regarding copyright ownership. * TCC licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include "signtext.h" GQuark rst_core_error_quark (void) { static GQuark quark; if (!quark) { quark = g_quark_from_static_string ("rst-core-error-quark"); } return quark; } SignTextData *signtext_data_new() { SignTextData *signtext = g_new (SignTextData, 1); memset(signtext, 0, sizeof(SignTextData)); signtext->incoming = gcr_simple_collection_new(); signtext->certificates = gcr_simple_collection_new(); return signtext; } void signtext_data_free(SignTextData *data) { if (data) { if (data->incoming) g_object_unref(data->incoming); if (data->certificates) g_object_unref(data->certificates); if (data->modules) gck_list_unref_free(data->modules); if (data->slots) gck_list_unref_free(data->slots); } g_free(data); } SignTextToken *signtext_token_new() { SignTextToken *token = g_new (SignTextToken, 1); memset(token, 0, sizeof(SignTextToken)); return token; } void signtext_token_free(SignTextToken *signtext_token) { if (signtext_token->token_info) gck_token_info_free(signtext_token->token_info); g_free(signtext_token); } SignTextInstance *signtext_instance_new(SignTextData *signtext, gint64 id, const gchar *uuid, GUri *uri) { SignTextInstance *instance = g_new (SignTextInstance, 1); memset(instance, 0, sizeof(SignTextInstance)); instance->signtext = signtext; g_uri_ref(uri); instance->id = id; instance->uuid = g_strdup(uuid); instance->uri = uri; instance->detached = TRUE; instance->progress = GTK_PROGRESS_BAR(gtk_progress_bar_new()); gtk_widget_set_visible(GTK_WIDGET(instance->progress), FALSE); instance->label = GTK_LABEL(gtk_label_new (NULL)); instance->label_text = g_markup_printf_escaped("The site %s has requested you sign the following text message.", g_uri_get_host(instance->uri)); gtk_label_set_markup(instance->label, instance->label_text); gtk_label_set_justify(instance->label, GTK_JUSTIFY_LEFT); gtk_label_set_line_wrap(instance->label, TRUE); gtk_label_set_line_wrap_mode(instance->label, PANGO_WRAP_WORD_CHAR); gtk_label_set_selectable(instance->label, TRUE); instance->buffer = gtk_text_buffer_new (gtk_text_tag_table_new ()); instance->textview = GTK_TEXT_VIEW (gtk_text_view_new_with_buffer(instance->buffer)); gtk_text_view_set_editable(instance->textview, FALSE); gtk_text_view_set_cursor_visible(instance->textview, FALSE); gtk_text_view_set_wrap_mode(instance->textview, GTK_WRAP_WORD_CHAR); instance->label_agree = GTK_LABEL(gtk_label_new (NULL)); gtk_label_set_markup(instance->label_agree, "If you agree with the text message above, and are happy with the identity of the site, select a certificate and enter your PIN."); gtk_label_set_justify(instance->label_agree, GTK_JUSTIFY_LEFT); gtk_label_set_line_wrap(instance->label_agree, TRUE); gtk_label_set_line_wrap_mode(instance->label_agree, PANGO_WRAP_WORD_CHAR); gtk_label_set_selectable(instance->label_agree, TRUE); instance->pin_buffer = gcr_secure_entry_buffer_new(); instance->pin = GTK_ENTRY(gtk_entry_new_with_buffer(instance->pin_buffer)); gtk_entry_set_visibility(GTK_ENTRY(instance->pin), FALSE); // gtk_entry_set_icon_from_icon_name(instance->pin, GTK_ENTRY_ICON_PRIMARY, "dialog-password-symbolic"); instance->buttons = GTK_BUTTON_BOX(gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL)); gtk_button_box_set_layout(instance->buttons, GTK_BUTTONBOX_EXPAND); instance->cancel = GTK_BUTTON(gtk_button_new_with_label("Cancel")); instance->sign = GTK_BUTTON(gtk_button_new_with_label("Sign")); gtk_widget_set_sensitive(GTK_WIDGET(instance->sign), FALSE); #ifdef HAVE_GTK_BOX_APPEND gtk_box_append (GTK_BOX(instance->buttons), GTK_WIDGET(instance->cancel)); gtk_box_append (GTK_BOX(instance->buttons), GTK_WIDGET(instance->sign)); #else gtk_box_pack_start (GTK_BOX(instance->buttons), GTK_WIDGET(instance->cancel), TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX(instance->buttons), GTK_WIDGET(instance->sign), TRUE, TRUE, 0); #endif return instance; } void signtext_instance_free(SignTextInstance *instance) { if (instance) { GList *pages; #ifdef HAVE_GTK_STACK_REMOVE gtk_stack_remove(instance->signtext->stack, GTK_WIDGET (instance->box)); #else gtk_container_remove(GTK_CONTAINER(instance->stack), GTK_WIDGET(instance->box)); #endif g_object_steal_data(G_OBJECT (instance->signtext->stack), instance->uuid); pages = gtk_container_get_children(GTK_CONTAINER(instance->stack)); if (!g_list_length(pages)) { gtk_widget_destroy(instance->signtext->window); } g_list_free(pages); if (instance->uuid) g_free(instance->uuid); if (instance->uri) g_uri_unref(instance->uri); // if (instance->label) g_object_unref(instance->label); if (instance->label_text) g_free(instance->label_text); // if (instance->textview) g_object_unref(instance->textview); // if (instance->label_agree) g_object_unref(instance->label_agree); // if (instance->buffer) g_object_unref(instance->buffer); // if (instance->pin) g_object_unref(instance->pin); // if (instance->buttons) g_object_unref(instance->buttons); // if (instance->cancel) g_object_unref(instance->cancel); // if (instance->sign) g_object_unref(instance->sign); // if (instance->box) g_object_unref(instance->box); // if (instance->certificate) g_object_unref(instance->certificate); if (instance->w) { ksba_writer_release(instance->w); } if (instance->cas) { g_list_foreach(instance->cas, (GFunc)g_bytes_unref, NULL); g_list_free (instance->cas); } } g_free(instance); } /* * Display the error dialog. * * Switch off the progress bar, if it is running. */ void signtext_error(SignTextInstance *instance, GError *gerror) { GtkWidget* dialog; if (instance) { gtk_widget_set_visible(GTK_WIDGET(instance->progress), FALSE); gtk_widget_set_sensitive(GTK_WIDGET(instance->selector), TRUE); gtk_widget_set_sensitive(GTK_WIDGET(instance->sign), TRUE); } dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "%s", ("Redwax SignText - Error")); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), ("Error: %s"), gerror->message); gtk_widget_show (dialog); }