/*-
 * Copyright (c) 2003-2004 Seth Kingsley.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgment:
 *    This product includes software developed by Seth Kingsley and
 *    contributors.
 * 4. Neither the author's name, nor any of the contributors names may be
 *    used to endorse or promote products derived from this software without
 *    specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include    <sys/cdefs.h>

#include    <gtk/gtkwidget.h>
#include    <gdk/gdkkeysyms.h>

#include    "bpm-gui.h"
#include    "support.h"
#include    "portsman.h"
#include    "refresh.h"
#include    "catlist.h"
#include    "portlist.h"
#include    "install.h"
#include    "log.h"
#include    "callbacks.h"

#include    <xmk-gtk.h>

__RCSID("$Id: callbacks.c,v 1.34 2004/08/24 02:40:08 sethk Exp $");

extern struct portsman_data *pdatap;
extern struct refresh_data  *rdatap;
extern struct catlist_data  *cdatap;
extern struct portlist_data *pldatap;
extern struct descview_data *ddatap;
extern struct install_data  *idatap;
extern struct log_data	    *ldatap;

/*
 * portsman.c
 */
void
on_about(GtkMenuItem *menuitem, gpointer user_data)
{
    portsman_about(pdatap);
}


/*
 * refresh.c
 */
void
on_refresh(GtkWidget *widget, gpointer user_data)
{
    refresh_all(rdatap);
}

void
on_console(GtkWidget *widget, gpointer user_data)
{
    refresh_console(rdatap);
}

void
on_search(GtkWidget *widget, gpointer user_data)
{
    refresh_search(rdatap);
}

void
on_search_prompt(GtkMenuItem *menu_item, gpointer user_data)
{
    refresh_search_dialog(rdatap);
}

void
on_search_dialog_response(GtkDialog * dialog,
	gint response_id,
	gpointer user_data)
{
    refresh_search_dialog_response(rdatap, response_id);
}

void
on_search_clear(GtkWidget *widget, gpointer user_data)
{
    refresh_search_clear(rdatap);
}


/*
 * catlist.c
 */
void
on_catlist_select_row(GtkCList *clist,
	gint row,
	gint column,
	GdkEvent *event,
	gpointer user_data)
{
    catlist_select_row(cdatap, row);
}


/*
 * portlist.c
 */
void
on_portlist_select_row(GtkCList *clist,
	gint row,
	gint column,
	GdkEvent *event,
	gpointer user_data)
{
    portlist_select_row(pldatap, row, event);
}

gboolean
on_portlist_button_press_event(GtkWidget *widget,
	GdkEventButton *event,
	gpointer user_data)
{
    if (event->button == 3)
    {
	portlist_popup(widget, event, pldatap);
	return TRUE;
    }

    return FALSE;
}

void
on_action(GtkButton *button, gpointer user_data)
{
    portlist_action(pldatap, INSTACT_CURRENT);
}

gboolean
on_portlist_key_press_event(GtkWidget *widget,
	GdkEventKey *event,
	gpointer user_data)
{
    if (event->keyval == GDK_Return)
    {
	portlist_action(pldatap, INSTACT_CURRENT);
	return TRUE;
    }

    return FALSE;
}

void
on_portlist_click_column(GtkCList *clist, gint column, gpointer user_data)
{
    portlist_resort(pldatap);
}


/*
 * install.c
 */
void
on_action_details_toggled(GtkToggleButton *togglebutton,
	gpointer user_data)
{
    install_details_show(idatap, gtk_toggle_button_get_active(togglebutton));
}

gboolean
on_action_cancel(GtkWidget *widget,
	GdkEvent *event,
	gpointer user_data)
{
    install_action_cancel(idatap);

    return TRUE;
}

void
on_action_sbar_realize(GtkStatusbar *sbar, gpointer user_data)
{
    gtk_statusbar_push(sbar, 0, _("Ready"));
}

void
on_action_run(GtkButton *button, gpointer user_data)
{
    install_action_run(idatap);
}

/*
 * descview.c
 */
gboolean
on_descview_motion_notify_event(GtkWidget *widget,
	GdkEventMotion *event,
	gpointer user_data)
{
    descview_motion(ddatap, event);

    return FALSE;
}

gboolean
on_descview_button_press_event(GtkWidget *widget,
	GdkEventButton *event,
	gpointer user_data)
{
    if (event->button != 1)
	return FALSE;

    return descview_button(ddatap, event);
}


/*
 * log.c
 */
void
on_log_view(GtkMenuItem *menuitem, gpointer user_data)
{
    log_show(ldatap);
}

void
on_log_clear(GtkButton *button, gpointer user_data)
{
    log_clear(ldatap);
}

