-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtohtmldialog.cpp
159 lines (133 loc) · 5.63 KB
/
tohtmldialog.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include "tohtmldialog.h"
#include "ui_tohtmldialog.h"
#include <QtSql>
#include <QtGui>
#include <QFile>
ToHtmlDialog::ToHtmlDialog(QWidget *parent, QSqlDatabase db) :
QDialog(parent),
ui(new Ui::ToHtmlDialog)
{
ui->setupUi(this);
SQliteDb = db;
ui->radioButton->setChecked(true);
ui->comboBox->setEnabled(false);
ui->widget->hide();
query_sqlitedb = new QSqlQuery(SQliteDb);
if (SQliteDb.open())
{
query_sqlitedb->clear();
query_sqlitedb->prepare("SELECT * FROM madrid_chat;");
if (query_sqlitedb->exec())
{
while(query_sqlitedb->next())
{
QVariant test2 = query_sqlitedb->value(5);
ui->comboBox->addItem(test2.toString());
}
}
else
{
QMessageBox::information(this, "Erreur", "Une erreur s'est produite, le fichier est peut etre endomage \n" + query_sqlitedb->lastError().text());
}
}
else
{
QMessageBox::information(this, "Erreur", "Une erreur s'est produite, le fichier est peut etre endomage \n" + query_sqlitedb->lastError().text());
}
SQliteDb.close();
}
ToHtmlDialog::~ToHtmlDialog()
{
delete ui;
}
void ToHtmlDialog::on_Btn_cancell_clicked()
{
ToHtmlDialog::close();
}
void ToHtmlDialog::on_Btn_export_clicked()
{
QFile htmlFile("test.html"), filetoremove("test.html");
filetoremove.remove();
filetoremove.close();
if (htmlFile.open(QIODevice::WriteOnly))
{
if (ui->radioButton->isChecked())
{
}
else
{
if (SQliteDb.open())
{
ui->widget->show();
query_sqlitedb->clear();
query_sqlitedb->prepare("SELECT COUNT(*) AS nb_field FROM message WHERE madrid_handle = ?");
query_sqlitedb->addBindValue(ui->comboBox->currentText());
int testintforhqdfbsdf = 0;
if (query_sqlitedb->exec())
{
while(query_sqlitedb->next())
{
testintforhqdfbsdf = query_sqlitedb->record().value("nb_field").toInt();
qDebug() << query_sqlitedb->record().value("nb_field");
}
}
ui->Progress->setMinimum(0);
ui->Progress->setMaximum(testintforhqdfbsdf);
query_sqlitedb->clear();
query_sqlitedb->prepare("SELECT * FROM message WHERE madrid_handle = ? ORDER BY ROWID");
query_sqlitedb->addBindValue(ui->comboBox->currentText());
if (query_sqlitedb->exec())
{
int iteratorcanevol = 0;
QString FullLine = "<!DOCTYPE html><html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/><title>Liste des conversations</title><style>.top{background-image: url('imgs/haut-message-rec.png');width: 298px;height: 40px;margin-left: 9px;}.middle{background-image: url('imgs/haut-millieu-rec.png');margin-left: 9px;width: 298px;}.bas{background-image: url('imgs/haut-ba-rec.png');height: 40px;width: 307px;}.top-up{background-image: url('imgs/haut-message-send.png');width: 298px;height: 40px;}.bas-up{background-image: url('imgs/haut-ba-send.png');height: 40px;width: 307px;margin-left: 1px;}.midle-up{background-image: url('imgs/haut-millieu-send.png');width: 298px;}.sender{text-align: right; margin-left: 60%;position: relative;}</style></head><body>";
int x = 3;
int x2 = 31;
int totallines = 0;
while(query_sqlitedb->next())
{
if ( query_sqlitedb->value(x2) == "0")
{
QString toAppend = "<div><div class='top'></div><div class='middle'><div style='margin-left: 20px;margin-right:10px ;'>" + query_sqlitedb->value(x).toString() + "</div></div><div class='bas'></div></div>";
qDebug() << "deux :" << query_sqlitedb->value(x).toString() ;
FullLine += toAppend;
iteratorcanevol++;
totallines++;
}
else
{
QString ToAppend = "<div class='sender'><div class='top-up'></div><div class='midle-up'><div style='margin-right: 20px;margin-left:10px ;'>"+ query_sqlitedb->value(x).toString() + "</div></div><div class='bas-up'></div></div>";
qDebug() << query_sqlitedb->value(x).toString() ;
FullLine += ToAppend;
iteratorcanevol++;
totallines++;
}
ui->Progress->setValue(iteratorcanevol);
}
FullLine += "</body></html>";
ui->widget->hide();
qDebug() << totallines;
QTextStream outstream(&htmlFile);
outstream << FullLine;
}
else
{
QMessageBox::critical(this, "Erreur", "Impossile d'ourvire la base ... querry \n" + query_sqlitedb->lastError().text());
}
}
}
}
else
{
QMessageBox::critical(this, "Erreur", "Une Erreur s'est produit lors de l'exportation");
}
htmlFile.flush();
htmlFile.close();
}
void ToHtmlDialog::on_radioButton_2_clicked()
{
ui->comboBox->setEnabled(true);
}
void ToHtmlDialog::on_radioButton_clicked()
{
ui->comboBox->setEnabled(false);
}