#include "afficher_parking2.h"
#include "ui_afficher_parking2.h"
#include"parking.h"
afficher_parking2::afficher_parking2(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::afficher_parking2)
{
    ui->setupUi(this);

   // ui->lcdNumber->display("-----");
          // serial="";
           int ret=A.connect_arduino(); // lancer la connexion à arduino

           switch(ret){
           case(0):{qDebug()<< "arduino is available and connected to : "<< A.getarduino_port_name();
               }
               break;
           case(1):qDebug() << "arduino is available but not connected to :" <<A.getarduino_port_name();

               break;

           case(-1):qDebug() << "arduino is not available";
           }

            QObject::connect(A.getserial(),SIGNAL(readyRead()),this,SLOT(update_label())); // permet de lancer
            //le slot update_label suite à la reception du signal readyRead (reception des données).
}

afficher_parking2::~afficher_parking2()
{
    delete ui;
}

void afficher_parking2::on_pushButton_clicked()
{
    ui->tab_parking->setModel(tmparking->afficher());
}


void afficher_parking2::update_label()
{
/*QStringList buffersplit= serial.split(",");
if(buffersplit.length()< 3)
   {
    data=A.read_from_arduino();
    serial+=QString::fromStdString(data.toStdString());
   }
else

{    qDebug()<<buffersplit;
    ui->lcdNumber->display(buffersplit[0]);
    ui->humidite->display(buffersplit[1]);
      serial="";
}
*/
data1=A.read_from_arduino();
    qDebug()<< data1.toInt() ;

    if(data1.toInt()==1)
    {        //QPixmap p(40,40);
        notifier = new QSystemTrayIcon(this);
        notifier->setIcon(QIcon("notification.png"));
        notifier->show();
        notifier->showMessage("Succés","une caisse a été modifier avec succés",QSystemTrayIcon::Warning,10000);
        hide();
       if (tmparking->modifier_etat(5))
       {
           qDebug()<< "modifie";
       }
       else if (data1.toInt()==0)
       {
           qDebug() <<"ereur de modification";        /*QPixmap pix("C:/Users/abdel/Documents/appsecurity/interface/mouvement1.png");

        ui->label_5->setPixmap(pix);*/



    }
    }
    //else if (data.toInt()==0)
    //{//qDebug()<<"someone is noooooooot STEAAALINGGG";



        /*QPixmap pix1("C:/Users/abdel/Documents/appsecurity/interface/mouvement.png");

          ui->label_5->setPixmap(pix1);*/
          /*QPixmap p1(32,32);
                 p1.load ("C:/Users/abdel/Documents/appsecurity/interface/mouvement.png");

                 QIcon icon(p1);
                 QSystemTrayIcon n1(icon);
                 n1.setVisible(true);
                 n1.showMessage("all clear","no one is stealing",icon,3000);*/
    }



