/*
 * main.c:
 *
 * Copyright (c) 2000 James McKenzie <james@fishsoup.dhs.org>,
 * All rights reserved.
 *
 */

static char rcsid[] = "$Id: main.c,v 1.9 2001/10/12 13:51:19 root Exp root $";

/*
 * $Log: main.c,v $
 * Revision 1.9  2001/10/12 13:51:19  root
 * #
 *
 * Revision 1.8  2001/01/30 06:16:33  root
 * #
 *
 * Revision 1.7  2000/12/01 04:42:23  root
 * #
 *
 * Revision 1.6  2000/12/01 04:13:55  root
 * #
 *
 * Revision 1.5  2000/11/23 23:45:30  root
 * #
 *
 * Revision 1.4  2000/10/07 18:30:11  root
 * #
 *
 * Revision 1.3  2000/10/07 16:41:53  root
 * #
 *
 * Revision 1.2  2000/10/06 19:52:46  root
 * #
 *
 * Revision 1.1  2000/10/06 06:21:36  root
 * #
 *
 */

#include "project.h"

Frame frame;
Panel panel;

int tunerunit, cdunit, mpegunit, waveunit, pcmunit, systemunit, clockunit,
  clientunit,oggunit;

Panel panels[NUM_TABS];

void *msglib;

Notify_value
msg_dispatch (client, fd) Notify_client client;
     int fd;
{
  hifi_dispatch ();

  return NOTIFY_DONE;
}

Notify_value
msg_iexist ( /*Unused */ )
{
  hifi_send (msglib, "fish", 4);
  return NOTIFY_DONE;
}


static void
change_panel (Panel_item p, int j)
{
  int i;

  for (i = 0; i < NUM_TABS; ++i)
    {
      xv_set (panels[i], XV_SHOW, (i == j) ? TRUE : FALSE, 0);
    }


}



int
main (int argc, char *argv[])
{
  Notify_client base_client = (Notify_client) 1;
  struct itimerval timer;
  int x, y;
  int i;

  clientunit = hifi_getunit ("client");
  tunerunit = hifi_getunit ("tuner");
  cdunit = hifi_getunit ("cd");
  mpegunit = hifi_getunit ("mpeg");
  waveunit = hifi_getunit ("wave");
  pcmunit = hifi_getunit ("pcm");
  systemunit = hifi_getunit ("system");
  clockunit = hifi_getunit ("clock");
  oggunit = hifi_getunit ("ogg");
  msglib = hifi_open (HIFI_CLASS_DISPLAY, clientunit);

  notify_set_input_func (base_client, msg_dispatch, hifimsg_fd (msglib));

  timer.it_value.tv_usec = 0;
  timer.it_value.tv_sec = 5;
  timer.it_interval.tv_usec = 0;
  timer.it_interval.tv_sec = 5;



  notify_set_itimer_func (base_client, msg_iexist, ITIMER_REAL, &timer, NULL);

  msg_iexist ();

  frame = xv_create (0, FRAME, FRAME_LABEL, rcsid, 0);

  panel = xv_create (frame, PANEL, XV_WIDTH, WIDTH, 0);

  xv_create (panel, PANEL_CYCLE,
             PANEL_LABEL_STRING, "Show:",
             PANEL_CHOICE_STRINGS,
             "System", "Tuner", "Cd", "MPEG", "Wave", "Ogg","Prefs", 0,
             PANEL_NOTIFY_PROC, change_panel, 0);

  window_fit_height (panel);

  y = xv_get (panel, XV_HEIGHT);

  for (i = 0; i < NUM_TABS; ++i)
    {
      panels[i] = xv_create (frame, PANEL,
                             WIN_BELOW, panel,
                             XV_X, 0,
                             XV_HEIGHT, HEIGHT,
                             XV_WIDTH, WIDTH, XV_SHOW, TRUE, 0);
    }

  system_makepanel (panels[TAB_SYSTEM]);
  tuner_makepanel (panels[TAB_TUNER]);
  cd_makepanel (panels[TAB_CD]);
  mpeg_makepanel (panels[TAB_MPEG]);
  wave_makepanel (panels[TAB_WAVE]);
  ogg_makepanel (panels[TAB_OGG]);
  prefs_makepanel (panels[TAB_PREFS]);
  


  window_fit (frame);
  for (i = 0; i < NUM_TABS; ++i)
    {
      xv_set (panels[i], XV_SHOW, FALSE, 0);
    }
  xv_set (panels[TAB_SYSTEM], XV_SHOW, TRUE, 0);

  xv_main_loop (frame);

  return 0;
}
