/*
 * MainWindow.vala
 *
 * Copyright 2013 Tony George <teejee2008@gmail.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 *
 *
 */

using Gtk;
using Gee;

using TeeJee.Logging;
using TeeJee.FileSystem;
using TeeJee.DiskPartition;
using TeeJee.JSON;
using TeeJee.ProcessManagement;
using TeeJee.GtkHelper;
using TeeJee.Multimedia;
using TeeJee.System;
using TeeJee.Misc;

public class RestoreWindow : Gtk.Dialog{
	private Box vbox_main;
	private Box hbox_action;
	private Notebook notebook;

	//actions
	private Button btn_cancel;
	private Button btn_restore;

	public RestoreWindow () {
		this.title = _("Restore");
        this.window_position = WindowPosition.CENTER_ON_PARENT;
        this.set_destroy_with_parent (true);
		this.set_modal (true);
        this.set_default_size (550, 500);
		this.skip_taskbar_hint = true;
		this.icon = get_app_icon(16);

	    //vbox_main
        vbox_main = get_content_area ();

		//notebook
		notebook = new Notebook ();
		notebook.margin = 6;
		vbox_main.pack_start (notebook, true, true, 0);

		//target device tab -------------------------------------------------

		//lbl_exclude
		Label lbl_exclude = new Label (_("Target"));

        //vbox_target
        Box vbox_target = new Box (Orientation.VERTICAL, 6);
        vbox_target.margin = 6;
        notebook.append_page (vbox_target, lbl_exclude);

        //hbox_device
        Box hbox_device = new Box (Orientation.HORIZONTAL, 6);
		vbox_target.add(hbox_device);

		//Actions ----------------------------------------------

		//hbox_action
        hbox_action = (Box) get_action_area ();

        //btn_restore
        btn_restore = new Button();
        hbox_action.add(btn_restore);

        btn_restore.set_label (" " + _("Restore"));
        btn_restore.set_tooltip_text (_("Restore"));
        Gtk.Image img_restore = new Image.from_stock("gtk-go-forward", Gtk.IconSize.BUTTON);
		btn_restore.set_image(img_restore);
        btn_restore.clicked.connect (btn_restore_clicked);

        //btn_cancel
        btn_cancel = new Button();
        hbox_action.add(btn_cancel);

        btn_cancel.set_label (" " + _("Cancel"));
        btn_cancel.set_tooltip_text (_("Cancel"));
        Gtk.Image img_cancel = new Image.from_stock("gtk-cancel", Gtk.IconSize.BUTTON);
		btn_cancel.set_image(img_cancel);
        btn_cancel.clicked.connect (btn_cancel_clicked);
	}

	private void btn_restore_clicked(){
		//check if backup device is online
		if (!check_backup_device_online()) { return; }

		//last option to quit - show disclaimer ------------

		if (show_disclaimer() == Gtk.ResponseType.YES){
			this.response(Gtk.ResponseType.OK);
		}
		else{
			this.response(Gtk.ResponseType.CANCEL);
		}
	}

	private bool check_backup_device_online(){
		if (!App.backup_device_online()){
			gtk_messagebox(_("Device Offline"),_("Backup device is not available"), null, true);
			return false;
		}
		else{
			return true;
		}
	}



	private void btn_cancel_clicked(){
		this.response(Gtk.ResponseType.CANCEL);
		return;
	}

}
