// generated by Fast Light User Interface Designer (fluid) version 2.0100

#include "edeLogin.h"
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static int wdm_fd = 1;

#include <fltk/run.h>

int main (int argc, char **argv) {

  int c;
  EdeLogin *login = new EdeLogin();
  
  while((c = getopt(argc, argv, "asb:d:h:l:uw:c:x:f:")) != -1) {
  
      switch(c) {
          case 'f':
              /* wdm daemon's file descriptor */
              wdm_fd = strtol(optarg, NULL, 0);
              if(wdm_fd < 1) wdm_fd = 1;
              printf("wdm_fd: %d\n", wdm_fd);
              break;
      }
  
  
  }
  return  fltk::run();
}

#include <fltk/SharedImage.h>

EdeLogin::EdeLogin() {
  fltk::Window* w;
   {fltk::Window* o = new fltk::Window(800, 600, "EDE Login");
    w = o;
    o->image(fltk::jpegImage::get("os-tux-800x600.jpg"));
    o->box(fltk::NO_BOX);
    o->user_data((void*)(this));
    o->begin();
     {fltk::Group* o = new fltk::Group(205, 205, 395, 195, "Welcome to stxbox");
      o->labelcolor((fltk::Color)0xffffff00);
      o->labelsize(31);
      o->align(fltk::ALIGN_TOP|fltk::ALIGN_INSIDE);
      o->begin();
       {fltk::Input* o = new fltk::Input(140, 55, 175, 20, "Username:   ");
        o->box(fltk::BORDER_BOX);
        o->labelcolor((fltk::Color)0xffffff00);
      }
       {fltk::SecretInput* o = new fltk::SecretInput(140, 90, 175, 20, "Password:   ");
        o->type(3);
        o->box(fltk::BORDER_BOX);
        o->labelcolor((fltk::Color)0xffffff00);
      }
       {fltk::Button* o = new fltk::Button(240, 125, 75, 25, "Login");
        o->box(fltk::BORDER_BOX);
        o->buttonbox(fltk::FLAT_BOX);
        o->buttoncolor((fltk::Color)0xffffff00);
        o->highlight_color((fltk::Color)0x35bcc600);
        o->callback((fltk::Callback*)Login);
      }
       {fltk::Button* o = new fltk::Button(10, 160, 75, 25, "Shutdown");
        o->box(fltk::BORDER_BOX);
        o->buttonbox(fltk::FLAT_BOX);
        o->buttoncolor((fltk::Color)0xffffff00);
        o->highlight_color((fltk::Color)0x35bcc600);
      }
       {fltk::Button* o = new fltk::Button(100, 160, 75, 25, "Restart");
        o->box(fltk::BORDER_BOX);
        o->buttonbox(fltk::FLAT_BOX);
        o->buttoncolor((fltk::Color)0xffffff00);
        o->highlight_color((fltk::Color)0x35bcc600);
      }
      o->end();
    }
    o->end();
    o->show();
  }
}

void EdeLogin::OutputAuth(char *user, char *pass) {
  writestring(wdm_fd, user ? user : "");
  writestring(wdm_fd, pass ? pass: "");
  
  writeuc(wdm_fd, 0); /* end of data */
}

void EdeLogin::Login(fltk::Widget *widget, void *data) {
  printf("Logging in...\n");
  OutputAuth("root", "root");
}

void writeuc(int fd, unsigned char c) {
  // From out.c by Tom Rothamel (GPL) - via wdm
  write(fd, &c, sizeof(unsigned char));
}

void writestring(int fd, char *string) {
  int len;
  
  len = strlen(string);
  if(len > 255) {
      len = 255;
  }
  
  writeuc(fd, (unsigned char) len);
  write(fd, string, len);
}
