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
| #include "mainwindow.h"
#include "ui_mainwindow.h"
mainWindow::mainWindow(QWidget *parent) : QWidget(parent), ui(new Ui::mainWindow){
ui->setupUi(this);
ui->progressBar->setRange(0,100);
}
mainWindow::~mainWindow(){
delete ui;
}
void mainWindow::browse_audio(){
QString chemin_audio = QFileDialog::getOpenFileName(this,"Ouvrir un fichier","C:\\Users","MP3 (*.mp3)");
ui->path_audio->setText(chemin_audio);
}
void mainWindow::browse_image(){
QString chemin_image = QFileDialog::getOpenFileName(this,"Ouvrir un fichier","C:\\Users","IMAGE (*.jpg *.png *.jpeg)");
ui->path_image->setText(chemin_image);
}
QString mainWindow::regex(QString texte){
texte = texte.toLower();
texte.replace("\"", "_");
texte.replace("'", "_");
texte.replace(" ","_");
texte.replace("ç", "c");
texte.replace("à","a");
texte.replace("â","a");
texte.replace("ä","a");
texte.replace("á","a");
texte.replace("é","e");
texte.replace("è","e");
texte.replace("ê","e");
texte.replace("ë","e");
texte.replace("ï","i");
texte.replace("î","i");
texte.replace("ì","i");
texte.replace("í","i");
texte.replace("ò","o");
texte.replace("ô","o");
texte.replace("ö","o");
texte.replace("ó","o");
texte.replace("ù","u");
texte.replace("û","u");
texte.replace("ü","u");
texte.replace("ú","u");
texte.replace("ÿ","y");
return texte;
}
void mainWindow::updateProgressBar(qint64 done, qint64 total){
double percent;
percent = (done*100)/total;
ui->progressBar->setValue(percent);
}
void mainWindow::uploadDone(QNetworkReply::NetworkError r){
qDebug() << r;
}
void mainWindow::requestFinished(QNetworkReply* r){
qDebug() << "Finished: " << r->error();
}
int mainWindow::create_file(){
QString data;
file = new QFile(QCoreApplication::applicationDirPath() + "\\template.html", this);
if(file->open(QIODevice::ReadOnly | QIODevice::Text)){
QTextStream in(file);
in.setCodec("UTF-8");
while(!in.atEnd()){
data += in.readLine();
}
file->close();
data.replace("$title$", ui->title->text());
QString audio(QFileInfo(ui->path_audio->text()).fileName());
data.replace("$audio$", "rcf_" + audio);
QString image(QFileInfo(ui->path_image->text()).fileName());
data.replace("$image$", "rcf_" + image);
QFile html(QCoreApplication::applicationDirPath() + "\\rcf_" + mainWindow::regex(ui->title->text()) + ".html");
if(html.open(QIODevice::WriteOnly | QIODevice::Text)){
QTextStream out(&html);
out.setCodec("UTF-8");
out << data;
html.close();
}else{
QMessageBox::warning(this, "Erreur d'écriture !", "Impossible de créer le fichier" + mainWindow::regex(ui->title->text()) + ".html");
return 1;
}
}else{
QMessageBox::warning(this, "Erreur de lecture !", "Impossible de trouver template.html");
return 1;
}
return 0;
}
void mainWindow::send(){
unsigned char err = 0;
if(ui->title->text() == ""){
err += 0b1;
ui->titre->setForegroundRole(QPalette::Light);
}else{
ui->titre->setForegroundRole(QPalette::WindowText);
}
if(ui->path_audio->text() == ""){
err += 0b10;
ui->audio->setForegroundRole(QPalette::Light);
}else{
ui->audio->setForegroundRole(QPalette::WindowText);
}
if(ui->path_image->text() == ""){
err += 0b100;
ui->image->setForegroundRole(QPalette::Light);
}else{
ui->image->setForegroundRole(QPalette::WindowText);
}
if(err == 0){
if(!create_file()){
ui->progressBar->setValue(0);
bool ok;
QString password(QInputDialog::getText(this, "Mot de passe FTP", "Entrez le mot de passe de connexion au serveur.",QLineEdit::Password,"",&ok));
if(ok && !password.isEmpty()){
Ftp upload1(password,this,this);
upload1.ftpUpload(QCoreApplication::applicationDirPath() + "\\rcf_" + mainWindow::regex(ui->title->text()) + ".html",
"public_html/rcf_" + mainWindow::regex(ui->title->text()) + ".html");
ui->link->setText(QString("http://adresse-de-mon-site.fr/rcf_" + mainWindow::regex(ui->title->text()) + ".html"));
QPalette *palette = new QPalette();
palette->setColor(QPalette::Text,Qt::green);
ui->link->setPalette(*palette);
}else{
QMessageBox::warning(this,"Attention","Veuillez saisir un mot de pass !");
}
}else{
QMessageBox::critical(this, "Erreur !", "Impossible de générer le fichier HTML !");
}
}else{
QMessageBox::warning(this, "Attention !", "Tout les champs ne sont pas complétés");
}
}
void mainWindow::copy_link(){
ui->link->setFocus();
ui->link->selectAll();
ui->link->copy();
} |
Partager