/***************************************************************************
                         SP Mail project : Simple Powerful Mail
                          main.cpp  -  description
                             -------------------
    begin                : Sun Jun 22 2003
    copyright            : (C) 2003 by Alexey Parshin
    email                : alexeyp@m7.tts-sf.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/


#ifdef __BORLANDC__
#include <vcl.h>
#pragma hdrstop
#endif

#include <FL/Fl.h>
#include <FL/Fl_Pixmap.h>
#include <FL/fl_ask.h>
#include <stdio.h>

#include <sptk/CWindow.h>
#include <sptk/CMenuBar.h>
#include <sptk/CProgressBar.h>
#include <sptk/CEditor.h>
#include <sptk/CException.h>
#include <sptk/CTreeControl.h>

#include "CMailAccounts.h"
#include "CImapFolders.h"

CRegistry      registry("sp-mail.ini");
CImapFolders  *imapFolders;

void quit_cb(Fl_Widget *w,void *) {
   w->window()->hide();
}

void accounts_cb(Fl_Widget *,void *) {
   CMailAccounts dialog(&registry);

   dialog.exec();
}

void test_accounts_cb(Fl_Widget *,void *) {
   imapFolders->loadAccounts();
}

void mailbox_cb(Fl_Widget *,void *) {
   CString fullName = imapFolders->selectedPath();
   puts(fullName);
}

Fl_Menu_Item menuTable[] = {
   {"&File",0,0,0,FL_SUBMENU},
   {"&Test",   FL_ALT+'t', test_accounts_cb},
   {"&Quit",   FL_ALT+'q', quit_cb},
   {0},
   {"&Settings",0,0,0,FL_SUBMENU},
   {"&Accounts",FL_SHIFT+'a',accounts_cb},
   {0},
   {0}
};

int main(int argc,char *argv[]) {
   try {
      registry.load();
   }
   catch (...) {}

   CWindow w(500,400);
   w.layoutSpacing(2);

   CMenuBar menuBar;
   menuBar.box(FL_FLAT_BOX);
   menuBar.menu(menuTable);

   CGroup statusBar("",5,SP_ALIGN_BOTTOM);
   statusBar.layoutSpacing(0);

   CBox statusBox("",100,SP_ALIGN_CLIENT);
   statusBox.data("Ready");
   statusBox.textSize(10);
   statusBox.box(FL_DOWN_BOX);

   CProgressBar progressBar("",100,SP_ALIGN_RIGHT);

   statusBar.end();

   CImapFolders folders(registry);
   imapFolders = &folders;
   imapFolders->callback(mailbox_cb);

   CListView messageList("",150,SP_ALIGN_TOP);
   CEditor messageEdit(10,SP_ALIGN_CLIENT);

   w.end();
   w.resizable(&w);

   w.show(argc,argv);

   imapFolders->loadAccounts();

   return Fl::run();
}
