]> git.nothing2do.fr Git - diary-mobile.git/commitdiff
I've added the update ability ... (download a file and execute on
authorNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Sat, 28 Dec 2013 01:17:44 +0000 (02:17 +0100)
committerNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Sat, 28 Dec 2013 01:17:44 +0000 (02:17 +0100)
database)

mainwindow.cpp
mainwindow.h
ui.sql

index 24e11a4a8f0a0aabe77701e1e350a0e347a1343c..461ef16af881f66a55ebb5c3f6784dda81b50abb 100644 (file)
@@ -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("<<a<<")";
-
-    flush();
     if (a.split(QString(" "))[0]==QString("set")){
         conf->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 : "<<a;
     QList<QString> 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<QString> tmp({"select label,action from ui where keyword like :word;", a});;
+    qDebug()<<"getButtons("<<a<<")";
+    flush();
+    QList<QString> 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 : "<<a;
     }else return;
@@ -429,7 +426,12 @@ QByteArray FileDownloader::downloadedData() const
     return m_DownloadedData;
 }
 void MainWindow::writeUpdate(){
-    qDebug()<<"downloaded :"<<m->downloadedData();
+    qDebug()<<"downloaded : "<<m->downloadedData().size()<<" byte";
     /* put newly downloaded sql file into database */
-
+    //int nb=m->downloadedData().count(";");
+    int a=m->downloadedData().count(';');
+    for(int i=0; i<a; i++){
+        qDebug()<<"q->prepare("<<i<<") : "<< q->prepare(m->downloadedData().split(';').at(i));
+        q->exec();
+    }
 }
index 91a0da2b56ca64bd7319c8494b16eef0039b76c6..27640a13113caa3f34be5fe87630f27b7685e228 100644 (file)
@@ -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 7092444d6967c93761089b5f451fd933ea81ff11..306ca3750d0e20955ff987866cb47c606bc90cea 100644 (file)
--- 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;