diff --git a/Cargo.toml b/Cargo.toml index 393f9ef..39c3d96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ gobject-sys = "^0.4.0" gtk-sys = "^0.4.0" libpijul = "^0.7.3" log = "^0.3.8" +base64 = "^0.6.0" [dependencies.gdk] features = [ diff --git a/data/ui/window.glade b/data/ui/window.glade index 0e922fc..9795474 100644 --- a/data/ui/window.glade +++ b/data/ui/window.glade @@ -5,6 +5,8 @@ False Pigui + 440 + 440 True @@ -15,11 +17,18 @@ True False - + True True - - + in + + + True + True + + + + @@ -29,11 +38,18 @@ - + True True - - + in + + + True + True + + + + diff --git a/src/main.rs b/src/main.rs index 8936731..603a6c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,8 @@ extern crate glib_sys; extern crate gobject_sys; extern crate gtk; extern crate gtk_sys; +extern crate libpijul; +extern crate base64; extern crate flexi_logger; #[macro_use] diff --git a/src/ui/entry.rs b/src/ui/entry.rs index 0b12d64..9ee8bf6 100644 --- a/src/ui/entry.rs +++ b/src/ui/entry.rs @@ -1,6 +1,9 @@ use gtk; +use gtk::prelude::*; use std::rc::Rc; use gtk::WidgetExt; +use libpijul; +use std::path::Path; pub struct AppS { @@ -23,7 +26,9 @@ impl AppS { pub struct Gui { _cant_construct: (), - pub window: gtk::Window + pub window: gtk::Window, + pub branch_tree: gtk::TreeView, + pub patch_tree: gtk::TreeView, } impl Gui { @@ -31,12 +36,91 @@ impl Gui { return Gui { _cant_construct: (), window: builder.get_object("main").unwrap(), + branch_tree: builder.get_object("branch_tree").unwrap(), + patch_tree: builder.get_object("patch_tree").unwrap(), } } } pub fn init(appstate: Rc) { + { + let ls = gtk::ListStore::new(&[gtk::Type::String]); + + let branches = get_branches("/home/hasufell/git/pijul/.pijul/pristine"); + + for branch in branches { + ls.insert_with_values(None, &[0], &[&branch.as_str()]); + } + + + let renderer = gtk::CellRendererText::new(); + let col = gtk::TreeViewColumn::new(); + col.set_title("Branch"); + col.set_resizable(true); + col.pack_start(&renderer, true); + col.add_attribute(&renderer, "text", 0); + col.set_clickable(true); + col.set_sort_column_id(0); + + appstate.gui.branch_tree.append_column(&col); + appstate.gui.branch_tree.set_model(Some(&ls)); + } + + { + let ls = gtk::ListStore::new(&[gtk::Type::String]); + let patches = get_patches("/home/hasufell/git/pijul/.pijul/pristine", + "master"); + for patch in patches { + ls.insert_with_values(None, &[0], &[&patch.as_str()]); + } + + let renderer = gtk::CellRendererText::new(); + let col = gtk::TreeViewColumn::new(); + col.set_title("Patch"); + col.set_resizable(true); + col.pack_start(&renderer, true); + col.add_attribute(&renderer, "text", 0); + col.set_clickable(true); + col.set_sort_column_id(0); + + appstate.gui.patch_tree.append_column(&col); + appstate.gui.patch_tree.set_model(Some(&ls)); + } + appstate.gui.window.show_all(); } + + +fn get_branches(path: &str) -> Vec { + let mut vec = Vec::new(); + + let repo = libpijul::Repository::open(path, None).unwrap(); + let txn = repo.txn_begin().unwrap(); + + let branches = txn.iter_branches(None).map(|x| String::from(x.name.as_str())); + + vec.extend(branches); + return vec; +} + + +fn get_patches(path: &str, branch: &str) -> Vec { + let mut vec = Vec::new(); + + let repo = libpijul::Repository::open(path, None).unwrap(); + let txn = repo.txn_begin().unwrap(); + + let branch = txn.get_branch(branch).unwrap(); + + let patches = txn.iter_patches(&branch, None).map(|x| { + let p = libpijul::fs_representation::read_patch(Path::new("/home/hasufell/git/pijul"), + txn.external_hash(x.0)).unwrap(); + p.header().name.clone() + }); + + vec.extend(patches); + + return vec; +}