static char *copyright = "{\n\
Copyright (c) 1997 Jean-Marc Zucconi\n\
All rights reserved.\n\
\n\
Redistribution and use in source and binary forms, with or without\n\
modification, are permitted provided that the following conditions\n\
are met:\n\
1. Redistributions of source code must retain the above copyright\n\
   notice, this list of conditions and the following disclaimer\n\
   in this position and unchanged.\n\
2. Redistributions in binary form must reproduce the above copyright\n\
   notice, this list of conditions and the following disclaimer in the\n\
   documentation and/or other materials provided with the distribution.\n\
3. The name of the author may not be used to endorse or promote products\n\
   derived from this software without specific prior written permission\n\
\n\
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\n\
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\n\
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\n\
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\n\
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\n\
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n\
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n\
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n\
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n\
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\
}";

#include <stdio.h>
#include <unistd.h>
#include <c++tk.h>

#include "cd-write.h"

#include "cdrom.h"
#include "pixmaps.h"
#include "version.h"

static ButtonBox b;
static Label l;

static char *label_0 = VERSION;
static char *label_copy = "{Select and extract audio or data tracks from a CD}";
static char *label_image = "{Create a data track on disk from a directory tree}";
static char *label_master_tao = "{Burn a CD,  Track At Once method}";
static char *label_master_dao = "{Burn a CD,  Disk At Once method (audio only)}";
static char *label_quit = "{Select another game}";

static void quit (int, char **), setlabel (int, char **);

int w_active = 0;

main (int argc, char **argv)
{
    Balloon balloon = tixBalloon (".balloon -initwait 500");
    char tmp[] = "/tmp/temp.XXXXXX.gif";
    FILE *f;
    if (mkstemp (tmp)) {
        f = fopen (tmp, "w");
        fwrite (cdrom, sizeof (cdrom), 1, f);
        fclose (f);
    } else
        f = 0;
    TkWm ("title .", "{CD Write}");
    TkImage ("create", "photo cdrom -file", tmp);
    TkLabel (".cdrom -image cdrom");
    b  = tixButtonBox (".buttons -orientation horizontal");
    b.add ("copy", "-highlightbackground black -text {Copy CD}"); 
    b.add ("image", "-highlightbackground black -text {Create ISO 9660 Image}"); 
    b.add ("master_tao", "-highlightbackground black -text {Master CD\n(Track at Once)}"); 
    b.add ("master_dao", "-highlightbackground black -text {Master CD\n(Disk at Once)}"); 
    b.add ("quit", "-highlightbackground black -text Quit"); 
    b.subwidget ("quit")->command (quit);
    b.subwidget ("copy")->command (copy_cd);
    b.subwidget ("image")->command (create_iso9660);
    b.subwidget ("master_tao")->command (write_cd, "TAO");
    b.subwidget ("master_dao")->command (write_cd, "DAO");
    TkBind (b.subwidget ("copy", ""), "<Motion>", setlabel, "c");
    TkBind (b.subwidget ("copy", ""), "<Leave>", setlabel, "0");
    TkBind (b.subwidget ("image", ""), "<Motion>", setlabel, "i");
    TkBind (b.subwidget ("image", ""), "<Leave>", setlabel, "0");
    TkBind (b.subwidget ("master_tao", ""), "<Motion>", setlabel, "t");
    TkBind (b.subwidget ("master_tao", ""), "<Leave>", setlabel, "0");
    TkBind (b.subwidget ("master_dao", ""), "<Motion>", setlabel, "d");
    TkBind (b.subwidget ("master_dao", ""), "<Leave>", setlabel, "0");
    TkBind (b.subwidget ("quit", ""), "<Motion>", setlabel, "q");
    TkBind (b.subwidget ("quit", ""), "<Leave>", setlabel, "0");
    l = TkLabel (".l", "-text", label_0);
    balloon.bind (".l -balloonmsg", copyright);
    TkPack (".buttons .cdrom", "-side top -fill x -pady 2m");
    TkPack (".l", "-side top -fill x");
    TkWm ("resizable", ". 0 0");
    if (f)
	unlink (tmp);

    TkImage ("create pixmap data -data", data_xpm);
    TkImage ("create pixmap note -data", note_xpm);
    TkImage ("create pixmap note_p -data", note_p_xpm);
    TkImage ("create pixmap qm -data", qm_xpm);

    TkMainLoop ();
}

static void 
setlabel (int a, char **b)
{
    char *p;

    switch (**b) {
    case 'c': p = label_copy; break;
    case 't': p = label_master_tao; break;
    case 'd': p = label_master_dao; break;
    case 'i': p = label_image; break;
    case 'q': p = label_quit; break;
    default: p = label_0;
    }
    l.configure ("-text", p);
}
static void 
quit (int a, char **b)
{
    if (w_active == 0)
	exit (0);
    l.configure ("-text", "{Stop the running process first!}");
}
