-
Notifications
You must be signed in to change notification settings - Fork 6
/
update.cpp
89 lines (72 loc) · 2.6 KB
/
update.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "update.h"
#include "ui_update.h"
Update::Update(QWidget *parent) :
QDialog(parent),
ui(new Ui::Update)
{
ui->setupUi(this);
}
Update::~Update()
{
delete ui;
}
void Update::on_UpdateButton_clicked()
{
ui->UpdateButton->setEnabled(false);
ui->UpdateButton->setText(tr("Checking..."));
QNetworkAccessManager *manager = new QNetworkAccessManager();
connect(manager, SIGNAL ( finished ( QNetworkReply* )),
this, SLOT(xmlDownloadFinished(QNetworkReply*)));
manager->get(QNetworkRequest(QUrl("http://Bilama.com/FactureFacile/version.xml")));
}
void Update::xmlDownloadFinished(QNetworkReply *reply)
{
if(reply->error() != QNetworkReply::NoError )
{
QMessageBox::information(this, "hi", "Serveur pas trouvé, vérifier votre connexion internet!");
ui->UpdateButton->setText(tr("Revérifier les mises à jours"));
return;
}
QFile file("version.xml");
if (!file.open(QIODevice::WriteOnly))
return;
file.write(reply->readAll());
file.close();
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QMessageBox::critical(this,
"QXSRExample::parseXML",
tr("Couldn't open example.xml"),
QMessageBox::Ok);
return;
}
QXmlStreamReader xmlFile(&file);
QString version;
while(!xmlFile.atEnd() && !xmlFile.hasError())
{
QXmlStreamReader::TokenType token = xmlFile.readNext();
if(token == QXmlStreamReader::StartDocument) {
continue;
}
if(token == QXmlStreamReader::StartElement) {
if(xmlFile.name() == "FactureFacile") {
continue;
}
if(xmlFile.name() == "Version") {
version = xmlFile.readElementText();
}
}
}
if(xmlFile.hasError()) {
QMessageBox::critical(this,
tr("Erreur"), xmlFile.errorString(),
QMessageBox::Ok);
return;
}
if(version.toInt() > 1)
QMessageBox::information(this, tr("Mise à jour dispinible!"), "Une nouvelle version (v "+ version + ") est disponible!");
else QMessageBox::information(this, tr("Pas de mise à jour"), "Vous avez la dernière version du programme!"
"\n pas de mise à jour disponible pour le moment.");
file.remove();
ui->UpdateButton->setText(tr("Vérifier les mises à jours"));
ui->UpdateButton->setEnabled(true);
}