/*
 * scbus utils to switch card settings.
 *
 * Copyright (C) 2011 Otvos Attila oattila@onebithq.com
 *
 * This 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.
 *
 * This is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef __MAIN_WIN_H__
#define __MAIN_WIN_H__

#include <QMainWindow>
#include <QCloseEvent>
#include <QDrag>
#include <QGraphicsScene>
#include <QPushButton>
#include <QLayout>
#include <QCheckBox>
#include <QStyleOptionGraphicsItem>
#include <QAbstractGraphicsShapeItem>
#include <QSettings>
#include <qdom.h>

#include <QVBoxLayout>
#include <QTextEdit>
#include <QTableWidget>

#include "rs485class.h"
#include "ledstatus.h"
#include "devicedialog.h"
#include "filedialog.h"
#include "configdialog.h"

//#include "libshmem/libshmem.h"

class QAction;
class QMenu;
class QTextEdit;
class QDragEnterEvent;
class QDropEvent;

typedef struct deviceTime {
    double time;
    bool flag;
} deviceTime;

class MainWindow:public QMainWindow
{
      Q_OBJECT

public:
    MainWindow();
    ~MainWindow();

public slots:
    void setDeviceModify(bool m);
    void setConfigModify(int id, bool m);
    void setDeviceID(int deviceid);
    void changeDeviceID(int deviceid);
    void cellActivated(int row, int column);
    void configAccept(int deviceid, int output, RS485Config config);
    void loadFile(QString fname);
    void saveFile(QString fname);
    void resetAll(void);
    void acceptAll(void);
    void selectDevice(int index);
    void selectBaud(int index);
    void reinitRS485(void);

private:

    void rebuildStatusmap(void);
    void listSerial(void);

    QSettings*     settings;
    QStringList    serialDevices;
    QString        serialDeviceValue;
    int            serialBaudValue;
    QList<int>     serialDevIDs;
    QMenuBar*      mainMenu;
    QGridLayout *  l;
    QComboBox *    serialDevice;
    QComboBox *    serialBaud;
    QCheckBox *    raw;

    QTextEdit *    tail;
    QTableWidget * tstatus;
    DeviceTab *    dconf;
    FileTab *      fconf;
    ConfigTab *    tconf[6];

    QTabWidget *   tab;

    unsigned char *vdata[32];
    QMap<int,int> statusmap;
    QMap<int,deviceTime> timemap;

    RS485Thread* rs485thread;
    QList<int> devices;
    QMap<int,RS485Status> status_config;


private slots:
    void menuExit(void);
    void showAbout(void);
    void checkDevices(void);
    void rs485Data(void);
    void rs485Status(int);
    void rs485Config(int,int);
    void rawState(int state);
};

#endif

