/* ***********************IMPORTANT *********************************************
 *  Copyright (C) 2004-2007 Thierry Lagarde <tlagarde@users.sourceforge.net>
 *  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.
 *
 *
 *                      ********************
 *
 *
 *  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 Library General Public License for more details.
 *
 *
 *                      ********************
 *
 *
 * You are highly encouraged to send your changes to <tlagarde@users.sourceforge.net>
 * for possible incorporation into the main distribution.
 * By sending these changes to <tlagarde@users.sourceforge.net>,
 * it is assumed that you are offering <tlagarde@users.sourceforge.net>
 * the unlimited, non-exclusive right to reuse, modify, and relicense the code.
 *
 *
 *                      ********************
 *
 *  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.
 **************************************************************************************/
#ifdef         __EGGTRAYICON_ENABLE


#include "eggtrayicon.h"
#include "Applet.h"
#include "Declaration_Constante.h"
#include "Interface/Root_Interface.h"
#include "Gconf.h"


static gboolean tray_icon_release (GtkWidget * widget, GdkEventButton * event)
{

	return TRUE;
}


static gboolean tray_icon_press (GtkWidget * widget, GdkEventButton * event)
{
	if ((event->button == 3) || (event->button == 2) || (event->button == 1)) {
		if (Root_Afficher)
			gtk_widget_hide (window_root);
		else
			gtk_widget_show (window_root);
		Root_Afficher = !Root_Afficher;
		return TRUE;
	}
	return FALSE;
}



void creation_applet_icone (void)
{
	tray_icon_Afficher = FALSE;
	if (Lecture_Gconf_Boolean (BOOL_MINIMIZED_TRAY_ICON)) {
		Root_Afficher = !Lecture_Gconf_Boolean (BOOL_START_MINIMIZED);
		tray_icon_Afficher = TRUE;
		tray_icon = egg_tray_icon_new (VERSION_AUTOSCAN);
	
		image = gtk_image_new_from_file (PATH_ICONE "/AutoScan.png");
#ifdef         __GNOME_ENABLE
		tray_icon_tooltip = gtk_tooltips_new ();
		gtk_tooltips_set_tip (tray_icon_tooltip, GTK_WIDGET (tray_icon), VERSION_AUTOSCAN, NULL);
#endif 
		evbox = gtk_event_box_new ();
		gtk_container_add (GTK_CONTAINER (evbox), image);
		gtk_container_add (GTK_CONTAINER (tray_icon), evbox);
		gtk_widget_show_all (GTK_WIDGET (tray_icon));
		g_signal_connect (G_OBJECT (evbox), "button_press_event", G_CALLBACK (tray_icon_press), window_root);
		g_signal_connect (G_OBJECT (evbox), "button_release_event", G_CALLBACK (tray_icon_release), window_root);
	}
}


void destruction_applet_icone (void)
{
	if (tray_icon_Afficher)
		gtk_widget_unrealize (GTK_WIDGET (tray_icon));
}


#endif
