]> git.nothing2do.fr Git - diary-mobile.git/commitdiff
now, action("set") and action("setint") check the number of given value
authorNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Mon, 9 Jun 2014 15:37:04 +0000 (17:37 +0200)
committerNorbert Moutarde <norbert.moutarde@nothing2do.eu>
Mon, 9 Jun 2014 15:37:04 +0000 (17:37 +0200)
(and ask for it otherwise)

mainwindow.cpp

index 9717e5d97da17b9947d2d7183dcc2c8f94127233..c02dfc8e505049da179942c989c3228931b82e4c 100644 (file)
@@ -156,6 +156,7 @@ void MainWindow::action(const QString &a){
     QStringList b=a.split(QString(" "));
     QString c=a;
     c.remove(0,4);
+    int bs=b.size();
     int part=a.count(conf->value(QString("sepcmd")).toString());
     if(part){
         for(int d=0; d<=part; d++){
@@ -163,17 +164,49 @@ void MainWindow::action(const QString &a){
         }
     }
     else if(b[0]==QString("set")){
-        conf->setValue(b[1], b[2]);
-    }
-    else if(b[0]==QString("settext")){
+        QString d, e;
         bool ok;
-        QString e=QInputDialog::getText(this, "setText", b[1], QLineEdit::Normal, conf->value(b[1]).toString(), &ok);
-        if(ok)conf->setValue(b[1], e);
+        if(bs==1){
+            d=QInputDialog::getText(this, "set", trUtf8("Variable's name ?", "text to ask value's name before changing it (set)"), QLineEdit::Normal, QString(""), &ok);
+            if(!ok)return;
+            e=QInputDialog::getText(this, "set", d, QLineEdit::Normal, conf->value(d).toString(), &ok);
+            if(!ok)return;
+        }else if(bs==2){
+            d=b[1];
+            e=QInputDialog::getText(this, "set", d, QLineEdit::Normal, conf->value(d).toString(), &ok);
+            if(!ok)return;
+        }else if(bs==3){
+            d=b[1];
+            e=b[2];
+        }else{
+            QMessageBox::critical(this, trUtf8("Error","title if action(\"set\") has too much value"), trUtf8("Too much value in button's action", "text if action(\"set\") has too much value"));
+            return;
+        }
+        QMessageBox::information(this, trUtf8("variable text change", "title to warn about variable content change"), trUtf8(d+" will be changed to "+e, "text to warn about variable content change"));
+        conf->setValue(d, e);
     }
     else if(b[0]==QString("setint")){
         bool ok;
-        int e=QInputDialog::getInt(this, "setInt", b[1] , conf->value(QString(b[1])).toInt(), 0, 100, 1, &ok);
-        if(ok)conf->setValue(b[1], e);
+        int e;
+        QString d;
+        if(bs==1){
+            d=QInputDialog::getText(this, "setInt", trUtf8("Variable's name ?", "text to ask value's name before changing it (setint)") , QString(""), 0, 100, 1, &ok);
+            if(!ok)return;
+            e=QInputDialog::getInt(this, "setInt", d, QLineEdit::Normal, conf->value(d).toInt(), &ok);
+            if(!ok)return;
+        }else if(bs==2){
+            d=b[1];
+            e=QInputDialog::getInt(this, "setInt", b[1] , conf->value(QString(d)).toInt(), 0, 100, 1, &ok);
+            if(!ok)return;
+        }else if(bs==3){
+            d=b[1];
+            e=b[2].toInt();
+        }else{
+            QMessageBox::critical(this, trUtf8("Error","title if action(\"set\") has too much value"), trUtf8("Too much value in button's action", "text if action(\"set\") has too much value"));
+            return;
+        }
+        QMessageBox::information(this, trUtf8("variable integer change", "title to warn about variable content change"), trUtf8(d+" will be changed to "+e, "text to warn about variable content change"));
+        conf->setValue(d, e);
     }
     else if(b[0]==QString("start")){
         start();
@@ -194,8 +227,20 @@ void MainWindow::action(const QString &a){
     } 
     else if(b[0]==QString("setfile")){
         bool ok=0;
-        QString e=QFileDialog::getSaveFileName(this, trUtf8("get file", "title to ask file"), conf->value(b[1]).toString());
-        if(ok)conf->setValue(b[1], e);
+        QString d, e;
+        if(bs==1){
+            d=QInputDialog::getText(this, "setInt", trUtf8("Variable's name ?", "text to ask value's name before changing it (setint)") , QString(""), 0, 100, 1, &ok);
+            if(!ok)return;
+            e=QFileDialog::getSaveFileName(this, trUtf8("get file", "title to ask file"), conf->value(d).toString());
+        }else if(bs==2){
+            d=b[1];
+            e=QFileDialog::getSaveFileName(this, trUtf8("get file", "title to ask file"), conf->value(d).toString());
+        }else if(bs==3){
+            d=b[1];
+            e=b[2];
+        }
+        QMessageBox::information(this, trUtf8("variable file change", "title to warn about variable content change"), trUtf8(d+" will be changed to "+e, "text to warn about variable content change"));
+        conf->setValue(d, e);
     }
     else if(b[0]==QString("box")){
         QMessageBox::information(this, trUtf8("box", "box title to show a text"), c);
@@ -223,11 +268,18 @@ void MainWindow::action(const QString &a){
     else if(b[0]==QString("edit")){
         QString e;
         bool ok;
-        if(b.size()<=1){
+        if(bs==1){
             e=QInputDialog::getText(this, QString("ID"), trUtf8("Enter ID of button to edit"), QLineEdit::Normal, QString(""), &ok);
-            if(ok)editButtonDB(e);
+            if(!ok)return;
             }
-        else editButtonDB(b[1]);
+        else if(bs==2){
+            e=b[1];
+        }
+        else{
+            QMessageBox::critical(this, trUtf8("Error","title if action(\"edit\") has too much value"), trUtf8("Too much value in button's action", "text if action(\"edit\") has too much value"));
+            return;
+        }
+        editButtonDB(e);
 
     }
     else if(b[0]==QString("but")){
@@ -275,9 +327,13 @@ void MainWindow::action(const QString &a){
         way.removeAt(b[1].toInt());
     }
     else if(b[0]==QString("read")){
-        QFile a(b[1]);
-        a.open(QIODevice::ReadOnly);
-        readData(a.readAll());
+        if(bs==2){
+            QFile a(b[1]);
+            a.open(QIODevice::ReadOnly);
+            readData(a.readAll());
+        }else{
+            QMessageBox::warning(this, trUtf8("Error", "title of box if action(\"read\" hasn't too much value"));
+        }
     }
     else {
         getButtons(a);