/////////////////////////////////////////////////////////////////////////////
// Name:        KeyDlg.cpp
// Purpose:     Key dialog
// Author:      Alex Thuering
// Created:     18.05.2007
// RCS-ID:      $Id: KeyDlg.cpp,v 1.3 2008/02/10 16:47:54 ntalex Exp $
// Copyright:  (c) Alex Thuering
// Licence:     GPL
/////////////////////////////////////////////////////////////////////////////

#include "KeyDlg.h"
#include "hyperlink.h"
#include "Config.h"
#include <wxVillaLib/utils.h>
#include <wx/statline.h>

#define KEY_URL wxT("http://www.dvdstyler.de/key.html")

enum
{
  RESET_BT_ID = 7830,
};

KeyDlg::KeyDlg(wxWindow* parent): wxPropDlg(parent)
{
  SetTitle(_("DVDStyler Registration"));
  Create(false);
  SetSize(400,-1);
}

void KeyDlg::CreatePropPanel(wxSizer* sizer)
{
  AddText(sizer, _("To continue using of DVDStyler you need to enter the registration key."));
  sizer->Add(0, 6);
  AddText(sizer, _("You can get FREE KEY at:"));
  sizer->Add(0, 6);
  myHyperLink* website = new myHyperLink(this, -1, KEY_URL);
  website->SetURL(KEY_URL);
  sizer->Add(website, 0, wxALIGN_CENTER);
  
  wxFlexGridSizer* grid = sizer ? new wxFlexGridSizer(2, 1, 16) : NULL;
  grid->AddGrowableCol(1);
  sizer->Add(grid, 0, wxEXPAND|wxALL, 6);
  AddTextProp(grid, _("Key:"), wxT(""));
}

void KeyDlg::CreateButtonPane(wxSizer* sizer, bool resetButton)
{
  wxBoxSizer* buttonPane = new wxBoxSizer(wxHORIZONTAL);
  buttonPane->Add(10, 10, 1, wxEXPAND);
  wxButton* okBt = new wxButton(this, wxID_OK, _("OK"));
  okBt->SetDefault();
  buttonPane->Add(okBt, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL);
  buttonPane->Add(8, 0);
  wxButton* cancelBt = new wxButton(this, wxID_CANCEL, _("Cancel"));
  buttonPane->Add(cancelBt, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL);
  buttonPane->Add(8, 0);
  wxButton* resetBt = new wxButton(this, RESET_BT_ID, _("Later"));
  buttonPane->Add(resetBt, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL);
  buttonPane->Add(10, 10, 1, wxEXPAND);
  sizer->Add(buttonPane, 0, wxEXPAND|wxLEFT|wxRIGHT|wxBOTTOM, 10);
}

bool KeyDlg::SetValues()
{
  long key;
  GetString(0).ToLong(&key);
  if (key != 4224) {
    wxMessageBox(_("The entered key is not valid.\nPlease try again."),
       _("DVDStyler"), wxOK|wxICON_ERROR, this);
    return false;
  }
  s_config.SetKey(key);
  return true;
}

void KeyDlg::Reset()
{
  EndModal(wxID_OK);
}

int KeyDlg::ShowModal() {
    if (s_config.GetKey() < 4 || s_config.GetKey() == 4224)
       return wxID_OK;
    return wxPropDlg::ShowModal();
}
