From 9e9d1ba0485b98e96cc9d3371c66b039aa1e4a6a Mon Sep 17 00:00:00 2001 From: Norbert Moutarde Date: Sat, 28 Dec 2013 02:17:44 +0100 Subject: [PATCH] I've added the update ability ... (download a file and execute on database) --- mainwindow.cpp | 38 ++++++++++++++++++++------------------ mainwindow.h | 2 +- ui.sql | 19 ++++++++++--------- 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 24e11a4..461ef16 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -43,7 +43,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) start(); } void MainWindow::start(){ - flush(); way.clear(); getButtons("begin"); } @@ -115,7 +114,7 @@ void MainWindow::lsconfig(){ void MainWindow::quit(){ qDebug()<<"quit()"; conf->setValue(QString("menu"), menuBar()->isVisible()); - conf->sync(); + //conf->sync(); db.commit(); db.close(); qApp->quit(); @@ -132,8 +131,6 @@ CLabel* MainWindow::addWidget(const QString &key, CLabel * a){ } void MainWindow::action(const QString &a){ qDebug()<<"action("<setValue(QString(a.split(QString(" "))[1]), a.split(QString(" "))[2]); getButtons(way.last()); @@ -143,7 +140,7 @@ void MainWindow::action(const QString &a){ getButtons(way.last()); } else if(a.split(QString(" "))[0]==QString("setint")){ - conf->setValue(a.split(QString(" "))[1], QInputDialog::getInt(this, "setInt", a.split(QString(" "))[2] , conf->value(QString(a.split(QString(" "))[3])).toInt())); + conf->setValue(a.split(QString(" "))[1], QInputDialog::getInt(this, "setInt", a.split(QString(" "))[2] , conf->value(QString(a.split(QString(" "))[1])).toInt())); getButtons(way.last()); } else if(a.split(QString(" "))[0]=="new"){ @@ -194,12 +191,12 @@ void MainWindow::flush(){ } //widget.clear(); } -CLabel::CLabel( const QString& text, QWidget * parent ) : QLabel(parent) +CLabel::CLabel( const QString& text, const QString & style, QWidget * parent ) : QLabel(parent) { setText(text); setWordWrap(true); setLineWidth(5); - setStyleSheet("background-color: red;border-style: outset;border-width: 7px;border-radius: 10px;border-color: beige;font: bold 15px;padding: 6px;"); + setStyleSheet(style); setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding); setScaledContents(1); } @@ -299,16 +296,15 @@ int MainWindow::alias(const QString & a){ } void MainWindow::entry(const QString &a){ QString time=QDateTime::currentDateTime().toString(QString("yyyy-MM-dd hh:mm:ss")), entry=""; - entry=QInputDialog::getText(this, QString("nouvelle entrée"), time, QLineEdit::Normal, a); - if(entry=="") - getButtons(way.last()); + bool ok=0; + entry=QInputDialog::getText(this, QString("nouvelle entrée"), time, QLineEdit::Normal, a, &ok); + if((entry=="")||(ok==0))getButtons(way.last()); QString c=time+" "+entry; QFile fichier(conf->value(QString("file")).toString()); fichier.open(QIODevice::Append | QIODevice::Text); QTextStream flux(&fichier); flux << c << endl; fichier.close(); - qDebug()<<"content added into file : "< d({"INSERT INTO raw (date, texte) VALUES (:date, :txt);"}); d.append(time); d.append(entry); @@ -336,14 +332,16 @@ void MainWindow::addButtonDB(){ cmd.append(view); cmd.append(key); cmd.append(action); - flush(); - getButtons(way.last()); + exec(cmd); + getButtons(way[way.size()-1]); } void MainWindow::getButtons(const QString &a){ - qDebug()<<"getButtons()"; - QList tmp({"select label,action from ui where keyword like :word;", a});; + qDebug()<<"getButtons("< tmp({"select label,action from ui where keyword like :word;"});; label->setText(QString::number(way.size())); way.append(a); + tmp.append(a); exec(tmp); int labCol = 0;//r.indexOf("label"); int actCol = 1;//r.indexOf("action"); @@ -377,7 +375,6 @@ void MainWindow::back(){ bool ok; int a=QInputDialog::getInt(this, QString("back()"), QString("Quel page ?"), way.size()-2, 0, way.size()-2, 1, &ok); if(ok){ - flush(); getButtons(way[a]); qDebug()<<"retour : "<downloadedData(); + qDebug()<<"downloaded : "<downloadedData().size()<<" byte"; /* put newly downloaded sql file into database */ - + //int nb=m->downloadedData().count(";"); + int a=m->downloadedData().count(';'); + for(int i=0; iprepare("<prepare(m->downloadedData().split(';').at(i)); + q->exec(); + } } diff --git a/mainwindow.h b/mainwindow.h index 91a0da2..27640a1 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -63,7 +63,7 @@ Q_OBJECT public: - explicit CLabel( const QString& text ="default", QWidget * parent = 0 ); + explicit CLabel(const QString& text ="default", const QString &style="background-color: red;border-style: outset;border-width: 7px;border-radius: 10px;border-color: beige;font: bold 15px;padding: 6px;", QWidget * parent = 0 ); ~CLabel(); signals: void clicked(); diff --git a/ui.sql b/ui.sql index 7092444..306ca37 100644 --- a/ui.sql +++ b/ui.sql @@ -5,7 +5,7 @@ INSERT INTO "ui" (keyword, label, action) VALUES('fille','aurelie','f-aurelie'); INSERT INTO "ui" (keyword, label, action) VALUES('fill-aurelie','discours','f-a-discours'); INSERT INTO "ui" (keyword, label, action) VALUES('fill-aureli-discours','discours un peu plus long que la moyenne pour voir se qui va se passer','begin'); INSERT INTO "ui" (keyword, label, action) VALUES('fille','audrey','f-audrey'); -INSERT INTO "ui" (keyword, label, action) VALUES('fill-audrey','elle se moque de moi, méchante ;-)','begin'); +INSERT INTO "ui" (keyword, label, action) VALUES('fill-audrey','elle se moque de moi, méchante %-)','begin'); INSERT INTO "ui" (keyword, label, action) VALUES('begin','lieu','lieu'); INSERT INTO "ui" (keyword, label, action) VALUES('lieu','odysseum','lie-odysseum'); INSERT INTO "ui" (keyword, label, action) VALUES('lie-odysseum','subway','lieu-odysseu-subway'); @@ -19,15 +19,16 @@ INSERT INTO "ui" (keyword, label, action) VALUES('begi-olive-audrey','Pourquoi v INSERT INTO "ui" (keyword, label, action) VALUES('begi-olive-audre-perver','"On ne te prends pas pour un perver."','begi-olive-audre-perve-non'); INSERT INTO "ui" (keyword, label, action) VALUES('begi-olive-audre-perve-non','Pourquoi vous refusez qu''on se voit hors d''ici alors ?','begi-olive-audre-perve-non-hors'); INSERT INTO "ui" (keyword, label, action) VALUES('begin','config','config'); -INSERT INTO "ui" (keyword, label, action) VALUES('config','max column','setint maxc maxcolumn 3'); -INSERT INTO "ui" (keyword, label, action) VALUES('config','host','settext host 127.0.0.1'); -INSERT INTO "ui" (keyword, label, action) VALUES('config','port','setint port port 5432'); -INSERT INTO "ui" (keyword, label, action) VALUES('config','user','settext user root'); +INSERT INTO "ui" (keyword, label, action) VALUES('config','max column','setint maxc'); +INSERT INTO "ui" (keyword, label, action) VALUES('config','host','settext host '); +INSERT INTO "ui" (keyword, label, action) VALUES('config','port','setint port'); +INSERT INTO "ui" (keyword, label, action) VALUES('config','user','settext user'); INSERT INTO "ui" (keyword, label, action) VALUES('config','password','settext pass'); INSERT INTO "ui" (keyword, label, action) VALUES('config','database','settext db'); INSERT INTO "ui" (keyword, label, action) VALUES('config','filesave','settext file'); -INSERT INTO "ui" (keyword, label, action) VALUES('config','SQLsettings', 'settext SQLsettings requiressl=1 connect_timeout=10000'); -INSERT INTO "ui" (keyword, label, action) VALUES('config','button', 'settext button background-color: red;border-style: outset;border-width: 7px;border-radius: 10px;border-color: beige;font: bold 15px;padding: 6px;'); -INSERT INTO "ui" (keyword, label, action) VALUES('config','fichier SQL', 'settext sqlfile ui.sql'); -INSERT INTO "ui" (keyword, label, action) VALUES('config','getSQL', 'settext getsql wget --no-check-certificate https://github.com/Nothing2Do/diary-mobile-android/raw/master/ui.sql'); +INSERT INTO "ui" (keyword, label, action) VALUES('config','SQLsettings', 'settext SQLsettings'); +INSERT INTO "ui" (keyword, label, action) VALUES('config','button', 'settext button'); +INSERT INTO "ui" (keyword, label, action) VALUES('config','fichier SQL', 'settext sqlfile'); +INSERT INTO "ui" (keyword, label, action) VALUES('config','getSQL', 'settext getsql'); +INSERT INTO "ui" (keyword, label, action) VALUES('config','update', 'settext update'); COMMIT; -- 2.45.1