#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gtk/gtk.h>

#include "callbacks.h"
#include "interface.h"
#include "support.h"

extern  GtkWidget *window;
extern  GtkWidget *notebook;

extern  GtkWidget *all_files_radiobutton;
extern  GtkWidget *settings_only_radiobutton;
extern  GtkWidget *system_admin_backup_radiobutton;
extern  GtkWidget *newfiles_only_checkbox_button;

extern  GtkWidget *cd_medium_radiobutton;
extern  GtkWidget *usb_medium_radiobutton;
extern  GtkWidget *email_medium_radiobutton;
extern  GtkWidget *ftp_medium_radiobutton;
extern  GtkWidget *home_directory_radiobutton;

extern  GtkWidget *backup_name_entry;

extern  GtkWidget *email_address_entry;

extern  GtkWidget *ftp_server_entry;
extern  GtkWidget *ftp_username_entry;
extern  GtkWidget *ftp_password_entry;
extern  GtkWidget *ftp_anonymous_login_checkbutton;

extern  GtkWidget *admin_home_backup_checkbutton;
extern  GtkWidget *admin_etc_backup_checkbutton;
extern  GtkWidget *admin_var_backup_checkbutton;

extern  GtkWidget *zip_compression_radiobutton;
extern  GtkWidget *tar_bz2_compression_radiobutton;
extern  GtkWidget *tar_gz_compression_radiobutton;

char *ftp_server_address;
char *ftp_server_username_entry;
char *ftp_server_password_entry;

char *backup_label_name;
char *email_address_entry_input;


void
on_window_destroy                      (GtkObject       *object,
                                        gpointer         user_data)
{
g_print("exit_signal\n");
gtk_main_quit();
}


void
on_page0_cancel_button_clicked         (GtkButton       *button,
                                        gpointer         user_data)
{
g_print("exit_signal\n");
gtk_main_quit();
}

void
on_page0_next_button_clicked           (GtkButton       *button,
                                        gpointer         user_data)
{
notebook = lookup_widget(GTK_WIDGET(window), "notebook");
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 1);
}


void
on_page1_back_button_clicked           (GtkButton       *button,
                                        gpointer         user_data)
{
notebook = lookup_widget(GTK_WIDGET(window), "notebook");
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 0);
}


void
on_page1_next_button_clicked           (GtkButton       *button,
                                        gpointer         user_data)
{
get_radiobutton_choice_for_navigating_page1 ();
}


void
on_page2_back_button_clicked           (GtkButton       *button,
                                        gpointer         user_data)
{
get_radiobutton_choice_for_navigating_page2_back ();
}


void
on_page2_next_button_clicked           (GtkButton       *button,
                                        gpointer         user_data)
{
get_radiobutton_choice_for_navigating_page2 ();
}


void
on_page3_back_button_clicked           (GtkButton       *button,
                                        gpointer         user_data)
{
notebook = lookup_widget(GTK_WIDGET(window), "notebook");
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 1);
}


void
on_page3_next_button_clicked           (GtkButton       *button,
                                        gpointer         user_data)
{
notebook = lookup_widget(GTK_WIDGET(window), "notebook");
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 2);
}


void
on_page4_back_button_clicked           (GtkButton       *button,
                                        gpointer         user_data)
{
notebook = lookup_widget(GTK_WIDGET(window), "notebook");
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 1);
}


void
on_page4_next_button_clicked           (GtkButton       *button,
                                        gpointer         user_data)
{
notebook = lookup_widget(GTK_WIDGET(window), "notebook");
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 2);
}


void
on_page5_back_button_clicked           (GtkButton       *button,
                                        gpointer         user_data)
{
notebook = lookup_widget(GTK_WIDGET(window), "notebook");
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 2);
}


void
on_page5_next_button_clicked           (GtkButton       *button,
                                        gpointer         user_data)
{
notebook = lookup_widget(GTK_WIDGET(window), "notebook");
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 6);
}


void
on_page6_back_button_clicked           (GtkButton       *button,
                                        gpointer         user_data)
{
get_radiobutton_choice_for_navigating_page6_back ();
}


void
on_page6_next_button_clicked           (GtkButton       *button,
                                        gpointer         user_data)
{
notebook = lookup_widget(GTK_WIDGET(window), "notebook");
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 7);
}


void
on_page7_back_button_clicked           (GtkButton       *button,
                                        gpointer         user_data)
{
notebook = lookup_widget(GTK_WIDGET(window), "notebook");
gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 6);
}


void
on_page7_record_button_clicked         (GtkButton       *button,
                                        gpointer         user_data)
{
get_radiobutton_choice_page0 ();
get_radiobutton_choice_page1 ();
get_backup_entry_name_page2 ();
get_checkbox_choice_page6 ();

get_email_entry_address_page3 ();
get_ftp_server_entry_page4 ();

get_checkbox_choice_page5 ();

gtk_main_quit();
}


void get_radiobutton_choice_page0 ()
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (all_files_radiobutton))) 
  {
     g_print("Backup all files\n");
  } 
 
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (settings_only_radiobutton))) 
  {
     g_print("Backup all user settings\n");
  }

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (system_admin_backup_radiobutton))) 
  {
     g_print("Administrator backup\n");
  }

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (newfiles_only_checkbox_button))) 
  {
g_print("Backup new files only\n");
  } else {
           g_print("Backup new files and old files\n");
         }

}


void get_radiobutton_choice_for_navigating_page2 ()
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (all_files_radiobutton))) 
  {
    notebook = lookup_widget(GTK_WIDGET(window), "notebook");
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 6);
  } 
 
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (settings_only_radiobutton))) 
  {
    notebook = lookup_widget(GTK_WIDGET(window), "notebook");
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 6);
  }

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (system_admin_backup_radiobutton))) 
  {
    notebook = lookup_widget(GTK_WIDGET(window), "notebook");
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 5);
  }

}


void get_radiobutton_choice_for_navigating_page6_back ()
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (all_files_radiobutton))) 
  {
    notebook = lookup_widget(GTK_WIDGET(window), "notebook");
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 2);
  } 
 
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (settings_only_radiobutton))) 
  {
    notebook = lookup_widget(GTK_WIDGET(window), "notebook");
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 2);
  }

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (system_admin_backup_radiobutton))) 
  {
    notebook = lookup_widget(GTK_WIDGET(window), "notebook");
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 5);
  }

}


void get_radiobutton_choice_page1 ()
{

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cd_medium_radiobutton))) 
  {
     g_print("Burn to a cd-r or cd-rewritable\n");
  } 
 
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (usb_medium_radiobutton))) 
  {
     g_print("Copy to usb disk\n");
  }

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (email_medium_radiobutton))) 
  {
     g_print("Send as attachment to email\n");
  }

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ftp_medium_radiobutton))) 
  {
     g_print("Send to an ftp server\n");
  }

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (home_directory_radiobutton))) 
  {
     g_print("Copy to home directory\n");
  }

}


void get_radiobutton_choice_for_navigating_page1 ()
{

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cd_medium_radiobutton))) 
  {
    notebook = lookup_widget(GTK_WIDGET(window), "notebook");
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 2);
  } 
 
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (usb_medium_radiobutton))) 
  {
    notebook = lookup_widget(GTK_WIDGET(window), "notebook");
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 2);
  }

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (email_medium_radiobutton))) 
  {
    notebook = lookup_widget(GTK_WIDGET(window), "notebook");
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 3);
  }

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ftp_medium_radiobutton))) 
  {
    notebook = lookup_widget(GTK_WIDGET(window), "notebook");
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 4);
  }

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (home_directory_radiobutton))) 
  {
    notebook = lookup_widget(GTK_WIDGET(window), "notebook");
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 2);
  }

}


void get_radiobutton_choice_for_navigating_page2_back ()
{

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (cd_medium_radiobutton))) 
  {
    notebook = lookup_widget(GTK_WIDGET(window), "notebook");
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 1);
  } 
 
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (usb_medium_radiobutton))) 
  {
    notebook = lookup_widget(GTK_WIDGET(window), "notebook");
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 1);
  }

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (email_medium_radiobutton))) 
  {
    notebook = lookup_widget(GTK_WIDGET(window), "notebook");
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 3);
  }

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ftp_medium_radiobutton))) 
  {
    notebook = lookup_widget(GTK_WIDGET(window), "notebook");
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 4);
  }

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (home_directory_radiobutton))) 
  {
    notebook = lookup_widget(GTK_WIDGET(window), "notebook");
    gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), 1);
  }

}


void get_backup_entry_name_page2 ()
{
backup_label_name = gtk_entry_get_text(GTK_ENTRY(backup_name_entry));
puts(backup_label_name);
}


void get_email_entry_address_page3 ()
{

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (email_medium_radiobutton))) 
  {
    email_address_entry_input = gtk_entry_get_text(GTK_ENTRY(email_address_entry));
    puts(email_address_entry_input);
  } else {
      g_print("E-mail method not used\n");
         }
}


void get_ftp_server_entry_page4 ()
{
ftp_server_address = gtk_entry_get_text(GTK_ENTRY(ftp_server_entry));
ftp_server_username_entry = gtk_entry_get_text(GTK_ENTRY(ftp_username_entry));
ftp_server_password_entry = gtk_entry_get_text(GTK_ENTRY(ftp_password_entry));

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ftp_medium_radiobutton))) 
  {

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (ftp_anonymous_login_checkbutton))) 
  {
    g_print("Use anonymous login\n");
    puts(ftp_server_address);
    g_print("N/A\n");
    g_print("N/A\n");
  } else {
           g_print("Use ftp server authentication\n");
           puts(ftp_server_address);
           puts(ftp_server_username_entry);
           puts(ftp_server_password_entry);
         }
  } else {
           g_print("N/A\n");
           g_print("N/A\n");
           g_print("N/A\n");
         }
}


void get_checkbox_choice_page6 ()
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tar_gz_compression_radiobutton))) 
  {
     g_print("tar gzip compression\n");
  } 
 
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (zip_compression_radiobutton))) 
  {
     g_print("zip compression\n");
  }

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tar_bz2_compression_radiobutton))) 
  {
     g_print("tar bzip2 compression\n");
  }
}


void get_checkbox_choice_page5 ()
{

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (system_admin_backup_radiobutton))) 
  {

if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (admin_home_backup_checkbutton))) 
  {
     g_print("Backup all home directory\n");
  } else {
       g_print("Not selected\n");
         }
 
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (admin_etc_backup_checkbutton))) 
  {
     g_print("Backup all system-wide settings\n");
  } else {
       g_print("Not selected\n");
         }
 
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (admin_var_backup_checkbutton))) 
  {
     g_print("Backup all system variable files\n");
  } else {
       g_print("Not selected\n");
         }
 
  } else {
       g_print("N/A\n");
       g_print("N/A\n");
       g_print("N/A\n");
         }

}

