using GLib; using Gtk; using GnomeKeyring; public class Application : Gtk.Builder { Gtk.ListStore store; Gtk.TreeView treeview_keys; Gtk.Notebook notebook; Gtk.Label label_secret; public bool create_widgets () { /* TODO: move to constructor */ try { add_from_file ("secrets.ui"); Gtk.Widget window = (Gtk.Widget)get_object ("window_main"); treeview_keys = (Gtk.TreeView)get_object ("treeview_keys"); setup_treeview (treeview_keys); window.show_all (); window.destroy += Gtk.main_quit; Gtk.Button button_unlock = (Gtk.Button)get_object ("button_unlock"); button_unlock.clicked += unlock; notebook = (Gtk.Notebook)get_object ("notebook"); label_secret = (Gtk.Label)get_object ("label_secret"); } catch (GLib.Error err) { new Gtk.MessageDialog (null, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.CANCEL, "Failed to load UI\n" + err.message).run(); return false; } return true; } private void unlock (Gtk.Button button) { Gtk.TreeIter iter; uint item_id; if (!treeview_keys.get_selection ().get_selected (null, out iter)) return; store.get(iter, 0, &item_id, -1); GnomeKeyring.ItemInfo info; GnomeKeyring.item_get_info_sync ("passwords", item_id, out info); notebook.set_current_page (1); label_secret.set_text (info.get_secret ()); } public void setup_treeview (Gtk.TreeView view) { store = new Gtk.ListStore (2, typeof (uint), typeof (string)); view.set_model (store); view.insert_column_with_attributes (-1, "Name", new Gtk.CellRendererText (), "text", 1, null); GLib.List ids; GnomeKeyring.list_item_ids_sync ("passwords", out ids); foreach (uint item_id in ids) { Gtk.TreeIter iter; GnomeKeyring.ItemInfo info; GnomeKeyring.item_get_info_full_sync ("passwords", item_id, GnomeKeyring.ItemInfoFlags.BASICS, out info); store.append (out iter); store.set (iter, 0, item_id, 1, info.get_display_name (), -1); } } static int main (string[] args) { Gtk.init (ref args); Environment.set_application_name ("Secrets"); var mainapp = new Application (); if (mainapp.create_widgets ()) Gtk.main (); return 0; } }