#include "modifierrayon.h"
#include "ui_modifierrayon.h"
#include <QSystemTrayIcon>
#include "rayon.h"
#include "smtp.h"

modifierrayon::modifierrayon(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::modifierrayon)
{
    ui->setupUi(this);
}

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


void modifierrayon::on_horizontalSlider_H_valueChanged(int humidite)
{
    ui->progressBar->setValue(humidite);
}

void modifierrayon::on_horizontalSlider_L_valueChanged(int luminositee)
{
    ui->progressBar_2->setValue(luminositee);
}

void modifierrayon::on_horizontalSlider_T_valueChanged(int temperature)
{
    ui->progressBar_3->setValue(temperature);
}



void modifierrayon::on_pushButton_clicked()
{
    int id = ui->lineEdit->text().toInt();
    int etat = ui->lineEdit_2->text().toInt();
    int humidite = ui->progressBar->value();
    int luminosite = ui->progressBar_2->value();
    int temperature = ui->progressBar_3->value();
    QString type;
    rayon e(id,etat,humidite,luminosite,temperature);
    bool test=e.modifier(id,etat,humidite,luminosite,temperature);
      if(test)
      {
          Smtp* s = new Smtp( "hajmoussa2368@gmail.com", "Hm123456", "smtp.gmail.com", 465 );
          s->sendMail("hajmoussa2368@gmail.com","kais.kasmi@esprit.tn","un rayon a été modifier avec succés","Mr Kais");
          notifier = new QSystemTrayIcon(this);
          notifier->setIcon(QIcon("notification.png"));
          notifier->show();
          notifier->showMessage("Succés","le rayon a été modifier avec succés",QSystemTrayIcon::Warning,10000);
          hide();

      }
      else
      {
          notifier = new QSystemTrayIcon(this);
          notifier->setIcon(QIcon("notification.png"));
          notifier->show();
          notifier->showMessage("Echec!","Le rayon n'a pas pu etre modifié",QSystemTrayIcon::Warning,10000);
      }

}





