// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 

// Copyright Liam Girdwood 2003

#include "config.h"
#include "import.hh"
#include "splash.hh"
#include "library.hh"

namespace GUI
{

/*! \fn Splash::Splash () : Gtk::Window (Gtk::WINDOW_TOPLEVEL)
*
* Create the Nova splash
*/
Splash::Splash () : Gtk::Window (Gtk::WINDOW_TOPLEVEL)
{
	// display splash screen and load default catalog
	Glib::ustring logo_path(NOVA_PIXMAP_DIR);
	logo_path+="/nova_logo.png";
	vbox = Gtk::manage(new Gtk::VBox(false,3));
	Glib::ustring title = "Nova I.O.E. Version ";
	title += VERSION;
	splash_label = Gtk::manage(new Gtk::Label(title));
	progress = Gtk::manage(new Gtk::ProgressBar());
	logo = Gtk::manage (new Gtk::Image (logo_path));
	hbox = Gtk::manage (new Gtk::HBox(false, 3));
	cat_label = Gtk::manage (new Gtk::Label("Loading catalogs "));
	status_label = Gtk::manage (new Gtk::Label(""));
	
	set_resizable(false);
	set_decorated(false);
	set_position(Gtk::WIN_POS_CENTER);
	
	hbox->pack_start(*cat_label);
	hbox->pack_start(*status_label);
	hbox->pack_start(*progress);
	vbox->pack_start(*logo);
	vbox->pack_start(*splash_label);
	vbox->pack_start(*hbox);
	vbox->set_spacing(5);
	vbox->set_border_width(5);
	
	add(*vbox);
	show_all();

	// Connect to the cross-thread signal.
  	nova_signal.connect(SigC::slot(*this, &Splash::progress_increment));
}

Splash::~Splash()
{
}	

/*! \fn void Splash::progress_increment()
*
* Increment the progress indicator.
*/
void Splash::progress_increment()
{
	double fraction = Pollux::Library::get_library()->get_progress();
	if (fraction >= 0 && fraction <= 1)
		progress->set_fraction(fraction);
}


/*! \fn void Splash::init_import(void)
*
* Create import update thread_resume
*/
void Splash::init_import(void)
{
	// Create a non-joinable thread -- it's deleted automatically on thread exit.
  	Glib::Thread::create(SigC::slot(*this, &Splash::import_default), false);
}


/*! \fn void Splash::import_default (void)
*
* Import Nova's default astro catalogs
* Sky2000, PGC
*/
void Splash::import_default (void)
{
	Pollux::Library* lib = Pollux::Library::get_library();
	std::string cat_name("default");
	status_label->set_label("Sky2000");
	if (lib->get_catalog (cat_name, &nova_signal) == 0) {
		std::cerr << __FILE__ << " " << __LINE__ 
			<< " Error: could not load default catalog " 
			<< cat_name << std::endl;
		std::cerr << "Please install " << cat_name << " with the same --prefix as nova"
			<< std::endl;
		m_import_status = false;
		Gtk::Main::quit();
		return;
	}		
	
	cat_name = "pgc";
	status_label->set_label(cat_name);
	lib->get_catalog (cat_name, &nova_signal);
	m_import_status = true;
	Gtk::Main::quit();
} 

bool Splash::import_status(void)
{
	return m_import_status;
}

}


syntax highlighted by Code2HTML, v. 0.9.1