kee

Offline IOU signer with QR as transport
git clone git://holbrook.no/kee-gtk4.git
Info | Log | Files | Refs | README | LICENSE

ui.c (4266B)


      1 #include <string.h>
      2 
      3 #include <gtk/gtk.h>
      4 #include <gst/gst.h>
      5 
      6 #include "ui.h"
      7 #include "err.h"
      8 #include "scan.h"
      9 #include "settings.h"
     10 #include "context.h"
     11 #include "state.h"
     12 //#include "view.h"
     13 #include "menu.h"
     14 #include "kee-import.h"
     15 #include "kee-entry-list.h"
     16 #include "kee-entry-store.h"
     17 #include "kee-menu.h"
     18 #include "kee-key.h"
     19 #include "kee-transport.h"
     20 #include "transport.h"
     21 #include "debug.h"
     22 
     23 
     24 static void ui_handle_unlock(KeeKey *o, KeeMenu *menu) {
     25 	kee_state_t state_delta;
     26 	char fingerprint[41];
     27 
     28 	kee_state_zero(&state_delta);
     29 	kee_key_get_fingerprint(o, fingerprint);
     30 	gtk_window_set_title(GTK_WINDOW(menu), fingerprint);
     31 	
     32 	g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "key is unlocked");
     33 	kee_menu_prev(menu, 1);
     34 }
     35 
     36 //static void ui_handle_import(KeeImport *import, GString *v, KeeMenu *menu) {
     37 //	//GtkWidget *widget;
     38 //	int r;
     39 //	struct kee_transport_t trans;
     40 //	char *s;
     41 //
     42 //	s = (char*)v->str;
     43 //	r = kee_transport_import(&trans, KEE_TRANSPORT_BASE64, s, strlen(s) + 1);
     44 //	if (r) {
     45 //		debug_log(DEBUG_INFO, "invalid input for transport");
     46 //		return;
     47 //	}
     48 //	//kee_transport_read(&trans);
     49 //
     50 //	//switch(kee_transport_cmd(&trans)) {
     51 //	//	case KEE_CMD_DELTA:
     52 //	//		widget = kee_menu_next("item");
     53 //	//}
     54 //
     55 //}
     56 
     57 //static GtkWidget* ui_build_view(KeeMenu *menu) {
     58 //	GtkListItemFactory *factory;
     59 //	GtkSelectionModel *sel;
     60 //	GListModel *front_list;
     61 //	GtkListView *front_view;
     62 //
     63 //	factory = gtk_signal_list_item_factory_new();
     64 //	g_signal_connect(factory, "setup", G_CALLBACK(new_item), NULL);
     65 //	
     66 //	front_list = G_LIST_MODEL(gtk_string_list_new(NULL));
     67 //
     68 //	sel = GTK_SELECTION_MODEL(gtk_single_selection_new(front_list));
     69 //	front_view = GTK_LIST_VIEW(gtk_list_view_new(GTK_SELECTION_MODEL(sel), factory));
     70 //
     71 //	return GTK_WIDGET(front_view);
     72 //}
     73 
     74 
     75 void ui_build(GtkApplication *gapp, struct kee_context *ctx) {
     76 	KeeTransport *trans;
     77 	GSimpleAction *act;
     78 	GtkWidget *widget;
     79 	KeeMenu *win;
     80 	KeeImport *import;
     81 
     82 	win = kee_menu_new(gapp, ctx);
     83 	if (!win) {
     84 		debug_log(DEBUG_CRITICAL, "menu init fail");
     85 	}
     86 
     87 	widget = GTK_WIDGET(kee_key_new(&ctx->gpg));
     88 	//kee_menu_add(win, "unlock", widget);
     89 	kee_menu_add(win, beamenu_dst_r[BEAMENU_DST_KEY], widget);
     90 	g_signal_connect (widget, "unlock", G_CALLBACK(ui_handle_unlock), win);
     91 
     92 	widget = kee_entry_list_new(G_LIST_MODEL(ctx->entry_store), win);
     93 	//kee_menu_add(win, "view", widget);
     94 	kee_menu_add(win, beamenu_dst_r[BEAMENU_DST_LIST], widget);
     95 
     96 	//kee_menu_next(win, "view");
     97 	kee_menu_next(win, BEAMENU_DST_LIST);
     98 	kee_menu_next(win, BEAMENU_DST_KEY);
     99 
    100 	import = kee_import_new(win);
    101 	//kee_menu_add(win, "import", GTK_WIDGET(import));
    102 	kee_menu_add(win, beamenu_dst_r[BEAMENU_DST_IMPORT], GTK_WIDGET(import));
    103 	//g_signal_connect(import, "data_available", G_CALLBACK(ui_handle_import), win);
    104 
    105 	widget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
    106 	//kee_menu_add(win, "entry", widget);
    107 	kee_menu_add(win, beamenu_dst_r[BEAMENU_DST_NEW], widget);
    108 
    109 	trans = g_object_new(KEE_TYPE_TRANSPORT, "orientation", GTK_ORIENTATION_VERTICAL, NULL);
    110 	//kee_menu_add(win, "transport", GTK_WIDGET(trans));
    111 	kee_menu_add(win, beamenu_dst_r[BEAMENU_DST_TRANSPORT], GTK_WIDGET(trans));
    112 
    113 	/// \todo make kee-entry action map/group?
    114 	act = g_simple_action_new("qr", G_VARIANT_TYPE_STRING);
    115 	g_action_map_add_action(G_ACTION_MAP(gapp), G_ACTION(act));
    116 	g_signal_connect(act, "activate", G_CALLBACK(kee_transport_handle_qr), trans);
    117 
    118 	act = g_simple_action_new("commit", G_VARIANT_TYPE_STRING);
    119 	g_action_map_add_action(G_ACTION_MAP(gapp), G_ACTION(act));
    120 	g_signal_connect(act, "activate", G_CALLBACK(kee_transport_handle_qr), trans);
    121 
    122 	gtk_window_present(GTK_WINDOW (win));
    123 }
    124 
    125 //void ui_build_from_resource(GtkApplication *app, struct ui_container *ui) {
    126 //	GtkBuilder *build;
    127 //	GtkWidget *unlock;
    128 //
    129 //	build = gtk_builder_new_from_resource("/org/defalsify/Kee/main.ui");
    130 //	//ui->view = GTK_WINDOW(gtk_builder_get_object(build, "keechoose"));
    131 //	unlock = GTK_WINDOW(gtk_builder_get_object(build, "keeunlock"));
    132 //	if (!unlock) {
    133 //		g_log(G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, "unlock widget could not load");
    134 //	}
    135 //
    136 //	ui->win = GTK_APPLICATION_WINDOW(gtk_application_window_new (app));
    137 //	gtk_window_set_child(GTK_WINDOW(ui->win), GTK_WIDGET(unlock));
    138 //
    139 //	gtk_window_present(GTK_WINDOW (ui->win));
    140 //}