/* 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 #include #include #include #include "signtext.h" #include "crypto.h" #include "message.h" void sign_clicked(GtkButton *button, gpointer user_data) { SignTextData *signtext = user_data; #if 0 g_printerr("sign_clicked\n"); #endif crypto_sign(signtext); } void cancel_clicked(GtkButton *button, gpointer user_data) { SignTextData *signtext = user_data; #if 0 g_printerr("cancel_clicked\n"); #endif message_cancel(signtext); } /* * The activate signal is fired at the end of the command line handler. At this * point we set ourselves up with our windows, and we trigger the first task to * read a single message from stdin. */ static void activate (GtkApplication *app, gpointer user_data) { SignTextData *signtext = user_data; #if 0 g_printerr ("activate\n"); #endif signtext->cancellable = g_cancellable_new(); signtext->stack = ADW_VIEW_STACK(adw_view_stack_new ()); // gtk_widget_set_vexpand (GTK_WIDGET(signtext->stack), 1); gtk_widget_set_valign (GTK_WIDGET(signtext->stack), GTK_ALIGN_FILL); gtk_widget_set_visible (GTK_WIDGET(signtext->stack), 1); signtext->switcher = ADW_VIEW_SWITCHER(adw_view_switcher_new ()); adw_view_switcher_set_stack (signtext->switcher, signtext->stack); gtk_widget_set_visible (GTK_WIDGET(signtext->switcher), 1); // signtext->box = GTK_BOX(gtk_box_new(GTK_ORIENTATION_VERTICAL, 6)); // gtk_box_append (signtext->box, GTK_WIDGET(signtext->switcher)); // gtk_box_append (signtext->box, GTK_WIDGET(signtext->stack)); // gtk_widget_set_vexpand (GTK_WIDGET(signtext->box), 1); // gtk_widget_set_visible (GTK_WIDGET(signtext->box), 1); // signtext->pin = ADW_PASSWORD_ENTRY_ROW(adw_password_entry_row_new()); signtext->actionbar = GTK_ACTION_BAR(gtk_action_bar_new()); signtext->cancel = GTK_BUTTON(gtk_button_new_with_label("Cancel")); gtk_widget_set_hexpand (GTK_WIDGET(signtext->cancel), 1); gtk_widget_set_halign (GTK_WIDGET(signtext->cancel), GTK_ALIGN_FILL); signtext->sign = GTK_BUTTON(gtk_button_new_with_label("Sign")); gtk_widget_set_hexpand (GTK_WIDGET(signtext->sign), 1); gtk_widget_set_halign (GTK_WIDGET(signtext->sign), GTK_ALIGN_FILL); gtk_widget_set_sensitive(GTK_WIDGET(signtext->sign), FALSE); gtk_action_bar_pack_start (GTK_ACTION_BAR(signtext->actionbar), GTK_WIDGET(signtext->cancel)); gtk_action_bar_pack_end (GTK_ACTION_BAR(signtext->actionbar), GTK_WIDGET(signtext->sign)); signtext->toolbar = ADW_TOOLBAR_VIEW(adw_toolbar_view_new()); adw_toolbar_view_add_top_bar (ADW_TOOLBAR_VIEW(signtext->toolbar), GTK_WIDGET(signtext->switcher)); adw_toolbar_view_set_content (ADW_TOOLBAR_VIEW(signtext->toolbar), GTK_WIDGET(signtext->stack)); adw_toolbar_view_add_bottom_bar (ADW_TOOLBAR_VIEW(signtext->toolbar), GTK_WIDGET(signtext->actionbar)); signtext->window = adw_application_window_new (app); gtk_window_set_title (GTK_WINDOW (signtext->window), "Redwax SignText"); gtk_window_set_default_size (GTK_WINDOW (signtext->window), -1, -1); adw_application_window_set_content (ADW_APPLICATION_WINDOW(signtext->window), GTK_WIDGET(signtext->toolbar)); g_signal_connect(signtext->cancel, "clicked", (GCallback)cancel_clicked, signtext); g_signal_connect(signtext->sign, "clicked", (GCallback)sign_clicked, signtext); /* go fetch our smartcards */ crypto_start(signtext); /* go fetch our first instruction from stdin */ message_receive(signtext); } /* * The command line signal is fired first, and we process the command line options * ourselves because we're not a typical app that opens files. */ static gint command_line ( GApplication *app, GApplicationCommandLine* cmdline, gpointer user_data ) { gchar **argv; gint argc; #if 0 gint i; #endif #if 0 g_printerr ("command_line\n"); #endif // g_application_hold(app); argv = g_application_command_line_get_arguments (cmdline, &argc); #if 0 for (i = 0; i < argc; i++) { g_printerr ("argument %d: %s\n", i, argv[i]); } #endif g_strfreev (argv); // g_application_command_line_set_exit_status (cmdline, 0); /* fire off the activation */ g_application_activate(app); return 0; } int main (int argc, char **argv) { AdwApplication *app; int status; SignTextData *signtext = signtext_data_new(); app = adw_application_new("eu.redwax.signtext", G_APPLICATION_NON_UNIQUE | G_APPLICATION_HANDLES_COMMAND_LINE); g_signal_connect(app, "activate", G_CALLBACK (activate), signtext); g_signal_connect(app, "command-line", G_CALLBACK (command_line), signtext); status = g_application_run(G_APPLICATION (app), argc, argv); g_object_unref(app); signtext_data_free(signtext); return status; }