extern crate gtk;

use gtk::prelude::*;

use std::error::Error;
use std::io::prelude::*;
use std::fs::File;
use std::path::Path;
use std::env;

fn main() {
    gtk::init().expect("Failed to initialize GTK.");

    let window = gtk::Window::new(gtk::WindowType::Toplevel);

    window.set_title("mpv-rice");
    window.set_border_width(10);
    // window.set_window_position(gtk::WindowPosition::Center);
    window.set_default_size(350, 70);

    window.connect_delete_event(|_, _| {
        gtk::main_quit();
        Inhibit(true)
    });

    let button = gtk::Button::new_with_label("Write config");
    button.connect_clicked(move |_| {
       let args: Vec<String> = env::args().collect();
       let path = Path::new(&args[1]);
       let display = path.display();

        let mut file = match File::create(&path) {
        Err(why) => panic!("couldn't create {}: {}",
                           display,
                           Error::description(&why)),
        Ok(file) => file,
        };
        let _ = file.write_all(b"# generated by mpv-rice\n");
        let _ = file.write_all(b"profile=opengl-hq\n");
    });
    window.add(&button);

    window.show_all();
    gtk::main();
}
