/*-
 * Copyright (c) 2003 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    <gtk/gtkstatusbar.h>

#include    <string.h>
#include    <assert.h>

#include    <xmk-gtk.h>

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

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

struct portsman_data
{
    GtkWindow		    *pd_app;
    GtkDialog		    *pd_about_dlg;
    guint		    pd_status_ctx;
    struct refresh_data	    *pd_rdatap;
};

struct portsman_data	*pdatap;

GType
pm_port_state_type_get_type(void)
{
    static GType    etype;

    if (!etype)
    {
	static const GEnumValue	values[] =
	{
	    {PSTATE_INST, "PSTATE_INST", "installed"},
	    {PSTATE_STALE, "PSTATE_STALE", "stale"},
	    {PSTATE_UNINST, "PSTATE_UNINST", "uninstalled"},
	    {PSTATE_ORPHAN, "PSTATE_ORPHAN", "orphan"},
	    {0, NULL, NULL}
	};

	etype = g_enum_register_static("PMPortStateType", values);
    }
    return etype;
}

struct portsman_data *
portsman_init(void)
{
    static struct portsman_data	pdata;
    GtkLabel			*version_lbl; 

    pdata.pd_app = GTK_WINDOW(create_app());
    pdata.pd_about_dlg = GTK_DIALOG(create_about_dlg());
    gtk_window_set_transient_for(GTK_WINDOW(pdata.pd_about_dlg),
	    pdata.pd_app);
    gtk_window_set_position(GTK_WINDOW(pdata.pd_about_dlg),
	    GTK_WIN_POS_CENTER_ON_PARENT);

    version_lbl = GTK_LABEL(lookup_widget(GTK_WIDGET(pdata.pd_about_dlg),
		"version_lbl"));
    gtk_label_set_markup(version_lbl,
	    "<span size=\"xx-large\" weight=\"bold\">"
	    PACKAGE "-" VERSION
	    "</span>");

    pdata.pd_rdatap = refresh_init(pdata.pd_app, &pdata);

    /* XXX */
    gtk_paned_set_position(GTK_PANED(lookup_widget(GTK_WIDGET(pdata.pd_app),
		    "vpaned1")),
	    332);

    gtk_widget_show(GTK_WIDGET(pdata.pd_app));

#ifndef DEBUG
    if (strstr(VERSION, "*ALPHA*") || strstr(VERSION, "*BETA*"))
	xmk_warning(pdata.pd_app,
		FALSE,
		_("WARNING: This is a development version of\n"
		"Ports Manipulator, it is not meant for use on\n"
		"production systems."));
#endif /* !DEBUG */

    return (pdatap = &pdata);
}

void
portsman_fini(struct portsman_data *pdp)
{
    refresh_fini(pdp->pd_rdatap);

    gtk_widget_destroy(GTK_WIDGET(pdp->pd_app));
}

const gchar *
portsman_state_desc(enum port_state ps)
{
    switch (ps)
    {
	case PSTATE_INST: return _("Installed");
	case PSTATE_STALE: return _("Stale");
	case PSTATE_UNINST: return _("Uninstalled");
	case PSTATE_ORPHAN: return _("Orphan");
	default:
	    assert(0);
	    return NULL;
    }
}

void
portsman_about(struct portsman_data *pdp)
{
    gtk_window_present(GTK_WINDOW(pdp->pd_about_dlg));
}

