]> git.nothing2do.fr Git - diary-mobile.git/commitdiff
long time far away, attempt to be multi-threaded (1 main and 1 SQL). master
authorNothing2Do.fr <root@nothing2do.fr>
Mon, 11 Oct 2021 19:08:23 +0000 (21:08 +0200)
committergaby <gaby@nothing2do.fr>
Mon, 11 Oct 2021 19:08:58 +0000 (21:08 +0200)
README.md
android/AndroidManifest.xml
android/build.gradle
diary-mobile.pro
mainwindow.cpp
mainwindow.h

index 05e87feb7ee479102802469c2abfcc3aa44056d0..512ca641998091736cbadc0fcba92fcc18f9949b 100755 (executable)
--- a/README.md
+++ b/README.md
@@ -12,3 +12,4 @@ ftp://[user]:[pass]@[hostname]/[filename]
 todo :
 
 add autoupdate feature, and ...
+
index c99d68311f24ce992e7e773e9d022906db4d3b06..2117b9935bf8b835c1ddd3396fac8512e6c2052d 100755 (executable)
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
-<manifest package="fr.nothing2do.diarymobile" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="cookie" android:versionCode="0.2" android:installLocation="auto">
-    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28"/>
+<manifest package="fr.nothing2do.diarymobile" xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="cookie" android:versionCode="03" android:installLocation="auto">
+    <uses-sdk android:minSdkVersion="23" android:targetSdkVersion="29"/>
 
     <!-- The following comment will be replaced upon deployment with default permissions based on the dependencies of the application.
          Remove the comment if you do not require these default permissions. -->
                 <action android:name="android.intent.action.MAIN"/>
                 <category android:name="android.intent.category.LAUNCHER"/>
             </intent-filter>
-
             <!-- Application arguments -->
             <!-- meta-data android:name="android.app.arguments" android:value="arg1 arg2 arg3"/ -->
             <!-- Application arguments -->
-
             <meta-data android:name="android.app.lib_name" android:value="diary-mobile"/>
             <meta-data android:name="android.app.qt_sources_resource_id" android:resource="@array/qt_sources"/>
             <meta-data android:name="android.app.repository" android:value="default"/>
             <meta-data android:value="@string/fatal_error_msg" android:name="android.app.fatal_error_msg"/>
             <meta-data android:value="@string/unsupported_android_version" android:name="android.app.unsupported_android_version"/>
             <!--  Messages maps -->
-
             <!-- Splash screen -->
             <!-- meta-data android:name="android.app.splash_screen_drawable" android:resource="@drawable/logo"/ -->
             <!-- meta-data android:name="android.app.splash_screen_sticky" android:value="true"/ -->
             <!-- Splash screen -->
-
             <!-- Background running -->
             <!-- Warning: changing this value to true may cause unexpected crashes if the
                           application still try to draw after
                           signal is sent! -->
             <meta-data android:name="android.app.background_running" android:value="false"/>
             <!-- Background running -->
-
             <!-- auto screen scale factor -->
             <meta-data android:name="android.app.auto_screen_scale_factor" android:value="false"/>
             <!-- auto screen scale factor -->
-
             <!-- extract android style -->
             <!-- available android:values :
                 * default - In most cases this will be the same as "full", but it can also be something else if needed, e.g., for compatibility reasons
                 -->
             <meta-data android:name="android.app.extract_android_style" android:value="default"/>
             <!-- extract android style -->
-    </activity>
-
-    <!-- For adding service(s) please check: https://wiki.qt.io/AndroidServices -->
-
+        </activity>
+        <!-- For adding service(s) please check: https://wiki.qt.io/AndroidServices -->
     </application>
 
 </manifest>
index 989d0792cf032d2c3f869bdc332c632013679911..a997029aaf7d5491400dbbc6d945287957346430 100755 (executable)
@@ -2,6 +2,7 @@ buildscript {
     repositories {
         google()
         jcenter()
+        //maven { url "http://jcenter.bintray.com"}
     }
 
     dependencies {
index 4edd30f338620dcdf98cc8b61a7dff2a8b9278c1..b3e6e3c107fa8f4f165eb70ec39f39b3b2b0c7c2 100755 (executable)
@@ -28,7 +28,7 @@ MOBILITY =
 QMAKE_CXXFLAGS += -fpermissive -Wswitch
 TRANSLATIONS = diary-mobile_fr_FR.ts diary-mobile_en_EN.ts
 ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
-
+DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x050F00
 OTHER_FILES += \
     android/AndroidManifest.xml \
     ui.sql \
index ad716cac011fd9a4ca1b4ff887c6d5ab100b7cc6..5e56d8eb416df86ff0f0f5c7a7bd52498e7b1916 100755 (executable)
 #include <QScrollArea>
 #include <QSslConfiguration>
 #include <QTime>
+#include <QSettings>
 
 MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
 {
     qDebug()<<"begin of MainWindows";
-    qDebug()<< QSslSocket::supportsSsl()<<"!\n";
+    qDebug()<<"SSL support : "<< QSslSocket::supportsSsl()<<"!\n";
     conf=new QSettings(QString("FwF"), QString("diary-mobile"), this);
     orienta=1;
     if(conf->allKeys().size()==0){
@@ -58,35 +59,36 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
     page=0;
     np=0;
     //currenttype=conf->value(QString("currenttype"), QString("buttons")).toString();
+    Worker *wk = new Worker;
+    wk->moveToThread(&thread);
     screen=new QWidget(this);
     screen->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
     grid=new QGridLayout(screen);
     grid->setSizeConstraint(QLayout::SetMinAndMaxSize);
-    //signalmap=new QSignalMapper(this);
-    //shell=new QProcess(this);a desperated attempt to get the output of my cmd, i've try Qprocess (but don't get it)
     valeur=new QMap<QString, QString>;
-    qDebug()<<"1' connect : "<<connect(signalmap, SIGNAL(mapped(const QString &)), this, SLOT(action(const QString &)));
-    qDebug()<<"2' connect : "<<connect(this, SIGNAL(datafilled()), this, SLOT(start()));
-    //qDebug()<<"3' connect : "<<connect(CLabel, SIGNAL(longpress()), MainWindow, SLOT(action(QString("edit "+id))););
-    //a desperated attempt to get the output of my cmd, i've try Qprocess (but don't get it)
-    //qDebug()<<"3' connect : "<<connect(shell, SIGNAL(readyReadStandardOutput()), this, SLOT(shellReady()));
+    connect(&thread, &QThread::finished, wk, &QObject::deleteLater);
+    connect(&m, &FileDownloader::downloaded, wk, &MainWindow::doSQL);
+
+    qDebug()<<"connect writed() : "<<connect(this, SIGNAL(resultReady()), this, SLOT(start()));
+    db=QSqlDatabase();
     label=new QLabel;
     setCentralWidget(screen);
     createMenuBar();
-    connectDB();
+    qDebug()<<"77, connectDB() : "<<connectDB();
     showExpanded();
     if((conf->value(QString("first")).toInt()==1)){
         qDebug()<<"second";
         bool ok;
-        QString ser=QInputDialog::getText(this, tr("init file"), tr("Enter the URL to download the init file"), QLineEdit::Normal, conf->value(QString("init")).toString(), &ok);
-        conf->setValue(QString("init"), ser);
-        downSQL(ser);
+        QString ser=QInputDialog::getText(this, tr("init file"), tr("Enter the URL to download the init file (SQL one)"), QLineEdit::Normal, conf->value(QString("init")).toString(), &ok);
+        if(ok){conf->setValue(QString("init"), ser);
+        downSQL(ser);}
+        d.lock();
         conf->setValue(QString("first"), 2);
     }
     statusBar()->addPermanentWidget(label);
     menuBar()->setVisible(conf->value(QString("menu")).toBool());
     //menuBar()->setVisible(true);
-    d.lock();
+    
     start();
 }
 void MainWindow::start(){
@@ -94,9 +96,12 @@ void MainWindow::start(){
     way=conf->value(QString("start"), conf->value(QString("startdefault"))).toStringList();
     QString b=way.last();
     way.removeLast();
-    qDebug()<<"a="<<a<<" b="<<b;
+    qDebug()<<"start() : a="<<a<<" b="<<b;
     //lastprint=b;
     //get(a, b);
+    QString tt="quit";
+    CLabel *tmp=new CLabel(QString("box quit"), *conf, tt);
+    addWidget(*&tt, *&tmp);
     action(b);
 
 
@@ -159,8 +164,8 @@ void MainWindow::showExpanded()
 }
 void MainWindow::quit(){
     qDebug()<<"quit() way.last()="<<way.last();
-    q->finish();
-    qq->finish();
+    q.finish();
+    qq.finish();
     //if(way.size())conf->setValue(QString("start"), way);
     //savButtons();
     db.commit();
@@ -175,8 +180,13 @@ int unsigned MainWindow::addWidget(QString &key, CLabel *a){
     }
     int c=grid->count(), maxc=conf->value(QString("maxcolumn")).toInt(), maxl=conf->value(QString("maxline")).toInt();
     grid->addWidget(a, c/maxc, c%maxc, 1, 1, Qt::AlignJustify| Qt::AlignVCenter | Qt::AlignHCenter);
-    QObject::connect(a, SIGNAL(released()), signalmap, SLOT(map()));
-    signalmap->setMapping(a, key);
+    //QObject::connect(a, SIGNAL(released()), signalmap, SLOT(map()));
+    //QObject::connect(a, a->released(key), this, action(&key.toStdString()));
+    //QObject::connect(a, SIGNAL(released()), this, SLOT(action(&key)));
+    connect(a, &CLabel::released, [this, key] {action(key); });
+//connect(a, &A::foo, b, [a, b]{});
+
+    //signalmap->setMapping(a, key); useless, it seems
     if(c==(maxc*maxl)-2)return 1;
 
     //(p-1)*(ml*mc)+c nombre de boutons en tout osef,
@@ -273,7 +283,7 @@ void MainWindow::action(const QString &a){
         a desperated attempt to get the output of my cmd, i've try Qprocess (but don't get it)*/
     }
     else if(b[0]==QString("sav")){
-        Msav.lock();
+        //Msav.lock();
         sav(c);
 
     }
@@ -297,16 +307,16 @@ void MainWindow::action(const QString &a){
         //int t=grid->count();
         flush();
         int max=conf->value(QString("maxcolumn")).toInt()*conf->value(QString("maxline")).toInt();
-        if(!page)tmp=q->seek(0);
-        else tmp=q->seek(page*(max-2));
+        if(!page)tmp=q.seek(0);
+        else tmp=q.seek(page*(max-2));
         //if(deb)QMessageBox::information(this, tr("result", "box title to debug prevpage"), int(tmp));
-        printItem(*q);
+        printItem(q);
 
     }
     else if(b[0]==QString("nextpage")){
         page++;
         flush();
-        printItem(*q);
+        printItem(q);
     }
     else if(b[0]==QString("setfile")){
         bool ok=0;
@@ -412,10 +422,10 @@ void MainWindow::action(const QString &a){
         lastprint=QString("-hist");
         for(int i=0; i<way.size(); i++){
             wi=way[i];
-            addWidget(wi, new CLabel(wi, *conf));
+            addWidget(wi, new CLabel(wi, *conf, wi));
             QString tmp("rm %1");
             tmp=tmp.arg(i);
-            addWidget(tmp, new CLabel(QString("del"), *conf));
+            //addWidget(tmp, new CLabel(QString("del"), *conf, QString("del421")));
 
         }
     }
@@ -473,14 +483,14 @@ void MainWindow::action(const QString &a){
                 flush(); 
                 for(int a=0;a<valeur->size();a++){
                     QString tmp("box "+tmpvalues[a]+"#");
-                    addWidget(tmp, new CLabel(tmpkeys[a], *conf));
+                    //addWidget(tmp, new CLabel(tmpkeys[a], *conf, tmpvalues[a]));
                     //if(deb)QMessageBox::information(this, QString("val"), QString(tmpkeys[a]+"=="+tmpvalues[a]));
                 }
             }else if(b[1]==QString("edit")){
                 flush();
                 for(int a=0;a<valeur->size();a++){
                     QString tmp("val "+tmpkeys[a]+"#");
-                    addWidget(tmp, new CLabel(tmpkeys[a], *conf));
+                    addWidget(tmp, new CLabel(tmpkeys[a], *conf, tmpvalues[a]));
                     //if(deb)QMessageBox::information(this, QString("val"), QString(tmpkeys[a]+"=="+tmpvalues[a]));
                 }
             }else if(bs==2){
@@ -583,10 +593,11 @@ void MainWindow::flush(){
     }
     //widget.clear();
 }
-CLabel::CLabel( const QString& text, QSettings & set, int tmpid, QWidget * parent ) : QLabel(parent)
+CLabel::CLabel( const QString& text, QSettings & set, const QString& act, int tmpid, QWidget * parent ) : QLabel(parent)
 {
     QString a=set.value(QString("currenttype")).toString();
     m_style=set.value(a).toString();
+    action=act;
     setText(text);
     setWordWrap(true);
     setLineWidth(5);
@@ -599,6 +610,9 @@ CLabel::CLabel( const QString& text, QSettings & set, int tmpid, QWidget * paren
 CLabel::~CLabel()
 {
 }
+QString CLabel::getAction(){
+    return action;
+}
 void CLabel::mousePressEvent (QMouseEvent * event )
 {
     //t.currentTime();
@@ -632,33 +646,44 @@ QSettings * CLabel::getSettings(){
     return settings;
 }
 /*void MainWindow::debug(int col){
-    q->first();
-    while(q->isValid()){
-        int k=q->at();
+    q.first();
+    while(q.isValid()){
+        int k=q.at();
         qDebug()<<"n°"<<k<<"="<<get(col);
-        q->next();
+        q.next();
     }
 }*/
-void MainWindow::connectDB(){
-    db = QSqlDatabase::addDatabase("QSQLITE");
-    //db = QSqlDatabase::addDatabase("QPSQL");
-    db.setHostName(conf->value(QString("host")).toString());
-    db.setDatabaseName(conf->value(QString("database")).toString());
-    db.setUserName(conf->value(QString("user")).toString());
-    db.setPassword(conf->value(QString("password")).toString());
+int MainWindow::connectDB(){
+    qDebug()<<"connectDB() with "<<conf->value(QString("sqldbtype")).toString()<<"->"<<conf->value(QString("sqluser")).toString()<<":"<<conf->value(QString("sqlpassword")).toString()<<"@"<<conf->value(QString("sqlhost")).toString()<<"/"<<conf->value(QString("sqlname")).toString();
+    //db = QSqlDatabase::addDatabase(conf->value(QString("sqldbtype")).toString());
+    db.addDatabase(conf->value(QString("sqldatabase")).toString());
+    db.setDatabaseName(conf->value(QString("sqlname")).toString());
+    db.setHostName(conf->value(QString("sqlhost")).toString());
+    db.setUserName(conf->value(QString("sqluser")).toString());
+    db.setPassword(conf->value(QString("sqlpassword")).toString());
     db.setConnectOptions(conf->value(QString("SQLsettings")).toString());//10sec,
-    qDebug()<<"db.open() ? "<<db.open()<< ". database : "<<db.databaseName();
-    q=new QSqlQuery(db);
-    qq=new QSqlQuery(db);
+    bool status=db.open();
+    if(!status){
+        qDebug()<<"connectDB() -> error connection SQL : "<<db.lastError()<<"\n";
+    }else{
+        qDebug()<<"connectDB() -> database : "<<db.databaseName()<<", sqldbtype : "<<conf->value(QString("sqldbtype")).toString();
+    }
+
+    //q=new QSqlQuery(db);
+    QSqlQuery q(db);
+    //qq=new QSqlQuery(db);
+    QSqlQuery qq(db);
+    return status;
 }
 void MainWindow::firstrun(){
     qDebug()<<"firstrun()";
-    conf->setValue(QString("host"), QVariant("127.0.0.1"));
+    conf->setValue(QString("sqlhost"), QVariant("127.0.0.1"));
     conf->setValue(QString("port"),QVariant(5432));
-    conf->setValue(QString("user"), QVariant("user"));
+    conf->setValue(QString("sqluser"), QVariant("user"));
     conf->setValue(QString("servercert"), QVariant("a.pem"));
-    conf->setValue(QString("database"), QVariant("db.db"));
-    conf->setValue(QString("password"), QVariant("pass"));
+    conf->setValue(QString("sqldatabase"), QVariant("db.db"));
+    conf->setValue(QString("sqlpassword"), QVariant("pass"));
+    conf->setValue(QString("sqlname"), QVariant("database"));
     conf->setValue(QString("fileraw"), QVariant("raw"));
     conf->setValue(QString("filebuttons"), QVariant("ui.sql+"));
     conf->setValue(QString("maxcolumn"), QVariant(3));
@@ -671,7 +696,7 @@ void MainWindow::firstrun(){
     conf->setValue(QString("download"), QVariant("http://<server>/<dir>/"+conf->value(QString("filebuttons")).toString()));
     conf->setValue(QString("downloaduser"), QVariant("<user>"));
     conf->setValue(QString("downloadpass"), QVariant("<pass>"));
-
+    conf->setValue(QString("sqldbtype"), QVariant("QSQLITE"));
     conf->setValue(QString("init"), QVariant("http://www.nothing2do.fr/init"));
     conf->setValue(QString("userftp"), QVariant("<userftp>"));
     conf->setValue(QString("hostftp"), QVariant("<hostftp>"));
@@ -707,42 +732,43 @@ void MainWindow::firstrun(){
     conf->setValue(QString("startdefault"), QVariant("begin"));
     conf->setValue(QString("actionmenu"), QVariant("<actionmenu>"));
     //conf->setValue(QString("process"), QVariant(0));
-    d.unlock();
+    //d.unlock();
     qDebug()<<"firstrun() finished";
 }
 QString MainWindow::get(int column){
-    return q->value(column).toString();
+    return q.value(column).toString();
 }
 QString MainWindow::get2(int column){
-    return qq->value(column).toString();
+    return qq.value(column).toString();
 }
 int MainWindow::exec(const QList<QString> & a){
-    qDebug()<<"exec("<<a[0]<<") size="<<a.size()<<", q->prepare: "<<q->prepare(a.at(0));
+    qDebug()<<"exec("<<a[0]<<") size="<<a.size()<<", q.prepare: "<<q.prepare(a.at(0));
     for (int j=1; j<a.size(); j++){
-        q->bindValue(j-1, a.at(j));
+        q.bindValue(j-1, a.at(j));
         qDebug()<<"bind "<<j-1<<" and "<<a.at(j);
     }
-    qDebug()<<"exec():"<<q->exec();
-    QSqlError b=q->lastError();
+    qDebug()<<"q.exec(a[0]):"<<q.exec();
+    QSqlError b=q.lastError();
     db.commit();
+    q.first();
     if (b.isValid()){qDebug()<<"SQL error :"<<b.text();}
-    if(q->isSelect())return q->size();
-    else if(q->isValid()) return 0;
+    if(q.isSelect())return q.size();
+    else if(q.isValid()) return 0;
     return -1;
 }
 int MainWindow::exec2(const QList<QString> & a){
-    qDebug()<<"exec("<<a[0]<<") size="<<a.size()<<", q->prepare: "<<qq->prepare(a[0]);
-    qq->prepare(a[0]);
+    qDebug()<<"exec("<<a[0]<<") size="<<a.size()<<", q.prepare: "<<qq.prepare(a[0]);
+    qq.prepare(a[0]);
     for (int j=1; j<a.size(); j++){
-        qq->bindValue(j-1, a[j]);
+        qq.bindValue(j-1, a[j]);
         qDebug()<<"bind "<<j-1<<" and"<<a[j];
     }
-    qDebug()<<"exec():"<<qq->exec();
-    QSqlError b=qq->lastError();
+    qDebug()<<"exec():"<<qq.exec();
+    QSqlError b=qq.lastError();
     db.commit();
     if (b.isValid())qDebug()<<"SQL error :"<<b.text();
-    if(q->isSelect())return qq->size();
-    else if (qq->isValid()) return 0;
+    if(q.isSelect())return qq.size();
+    else if (qq.isValid()) return 0;
     else return -1;
 }
 void MainWindow::entry(const QString &a){
@@ -770,8 +796,8 @@ void MainWindow::entry(const QString &a){
     else c=context+", "+a+" : "+entry;
     QList<QString> d({conf->value(QString("addraw")).toString(), time, c});
     if(!exec2(d))qDebug()<<"exec don't works (entry(QString))";
-    QSqlError b=q->lastError();
-    if (b.isValid())qDebug()<<"q->lastError():"<<b.text();
+    QSqlError b=q.lastError();
+    if (b.isValid())qDebug()<<"q.lastError():"<<b.text();
 }
 void MainWindow::entry(){
     entry(QString(""));
@@ -814,8 +840,8 @@ void MainWindow::get(const QString & d, const QString &b){
     label->setText(a);
     exec(tmp);
     page=0;
-    //while(q->next()){
-         printItem(*q);
+    //while(q.next()){
+         printItem(q);
     //}
     showExpanded();
 }
@@ -831,9 +857,9 @@ void MainWindow::chooseDB(const QString & b){
     flush();
     QString c="%"+b+"%", a="buttons";
     qDebug()<<"exec()="<<exec(QList<QString>({conf->value(QString("choose"+a)).toString(), c}));
-    while (q->next()) {
-        QString action="edit "+q->value(0).toString();
-        addWidget(action, new CLabel(q->value(1).toString(), *conf));
+    while (q.next()) {
+        QString action="edit "+q.value(0).toString();
+        addWidget(action, new CLabel(q.value(1).toString(), *conf, *&action));
     }
 }
 void MainWindow::chooseDB(const QString & a,const QString & b){
@@ -841,9 +867,9 @@ void MainWindow::chooseDB(const QString & a,const QString & b){
     QString c="%"+b+"%";
     qDebug()<<"exec()="<<exec(QList<QString>({conf->value(QString("choose"+a)).toString(), c}));
 
-    while (q->next()) {
-        QString action="edit "+q->value(0).toString();
-        addWidget(action, new CLabel(q->value(1).toString(), *conf));
+    while (q.next()) {
+        QString action="edit "+q.value(0).toString();
+        addWidget(action, new CLabel(q.value(1).toString(), *conf, *&action));
     }
 }
 void MainWindow::editDB(const QString & a, const QString & b){
@@ -852,11 +878,11 @@ void MainWindow::editDB(const QString & a, const QString & b){
     if(deb)QMessageBox::information(this, tr("EditDB", "box title to debug editDB"), txt);
 
     exec(QList<QString>({tmp, b}));
-    if(q->isSelect())q->first();
+    if(q.isSelect())q.first();
     bool ok;
-    QString keyword=q->value(1).toString();
-    QString label=q->value(2).toString();
-    QString action=q->value(3).toString();
+    QString keyword=q.value(1).toString();
+    QString label=q.value(2).toString();
+    QString action=q.value(3).toString();
     QString tmpkeyword, tmplabel, tmpaction;
     if(conf->value(QString("multiline")).toBool())tmpkeyword=QInputDialog::getMultiLineText(this, tr("keyword", "Title of box where ask for button's keyword"), tr("new keyword", "question to get new button's keyword"), keyword, &ok);
     else tmpkeyword=QInputDialog::getText(this, tr("keyword", "Title of box where ask for button's keyword"), tr("new keyword", "question to get new button's keyword"), QLineEdit::Normal, keyword, &ok);
@@ -902,13 +928,13 @@ void MainWindow::sendRAW(){
     a.open(QIODevice::WriteOnly/*|QIODevice::Text*/);
     QTextStream b(&a);
     //int c=conf->value(QString("columnraw")).toInt()-1;
-    int c=q->record().count()-1;
+    int c=q.record().count()-1;
     QString sep=conf->value(QString("sepcolraw")).toString();
-    while (q->next()) {
+    while (q.next()) {
         for (int i=0; i<c; i++){
-            b<<q->value(i).toString()<<sep;
+            b<<q.value(i).toString()<<sep;
         }
-        b<<q->value(c).toString()<<"\n";
+        b<<q.value(c).toString()<<"\n";
     }
     a.close();
     qDebug()<<"a.open()="<<a.open(QIODevice::ReadOnly | QIODevice::Text);
@@ -1020,21 +1046,21 @@ QByteArray FileDownloader::downloadedData() const
 }
 void MainWindow::read(const QString &a, const QByteArray &in){
     qDebug()<<"read : "<<a;
-    q->exec("PRAGMA foreign_keys=OFF;");
-    q->exec("BEGIN TRANSACTION;");// these 2 line is SQLite specific
+    q.exec("PRAGMA foreign_keys=OFF;");
+    q.exec("BEGIN TRANSACTION;");// these 2 line is SQLite specific
     int b=in.count('\n');
     QString d=conf->value(QString("sql")+a).toString(), sep=conf->value(QString("sepcol")+a).toString();
     qDebug()<<"sql"<<a<<" = "<<d<<" sep="<<sep<<" b(hm line)="<<b;
     for(int i=0; i<b; i++){
-        q->prepare(d);
+        q.prepare(d);
         int c=QString(in.split('\n').at(i)).count(sep);
         qDebug()<<i<<"th line, "<<c<<" delimiter";
         for(int j=0; j<=c; j++){
             QString tmp=QString(QString(in.split('\n').at(i)).split(sep).at(j));
-            q->bindValue(j, tmp);
+            q.bindValue(j, tmp);
             qDebug()<<"bind "<<j<<" and "<< tmp;
         }
-        qDebug()<<"q->exec() : "<<q->exec()<<" lastError()="<<q->lastError();
+        qDebug()<<"q.exec() : "<<q.exec()<<" lastError()="<<q.lastError();
 
     }
     db.commit();
@@ -1087,13 +1113,13 @@ void MainWindow::sav(const QString & a){
     b.open(QIODevice::WriteOnly);
     QTextStream c(&b);
     //int d=conf->value(QString("column")+a).toInt()-1;
-    int d=q->record().count()-1;
+    int d=q.record().count()-1;
     QString sep=conf->value(QString("sepcol")+a).toString();
-    while (q->next()) {
+    while (q.next()) {
         for (int i=0; i<d; i++){
-            c<<q->value(i).toString()<<sep;
+            c<<q.value(i).toString()<<sep;
         }
-        c<<q->value(d).toString()<<"\n";
+        c<<q.value(d).toString()<<"\n";
     }
     b.close();
     QUrl upload(QString("ftp://")+conf->value(QString("userftp")).toString()+QString(":")+conf->value(QString("passftp")).toString()+QString("@")+conf->value(QString("hostftp")).toString()+QString("/")+conf->value(QString("file")+a).toString());
@@ -1103,7 +1129,7 @@ void MainWindow::sav(const QString & a){
     QSslConfiguration ssl;
     ssl.setProtocol(QSsl::TlsV1_3);
     rq->setSslConfiguration(ssl);
-    //rq->setSslConfiguration(QSslConfiguration::defaultConfiguration());
+    //rq.setSslConfiguration(QSslConfiguration::defaultConfiguration());
     rep=net->put(*rq, b.readAll());
     b.close();
     qDebug()<<"net->put : "<<rep<< " upload : "<<upload.url();
@@ -1111,7 +1137,7 @@ void MainWindow::sav(const QString & a){
 }
 void MainWindow::Uisent(){
     qDebug()<<"Uisent";
-    Msav.unlock();
+    //Msav.unlock();
     QMessageBox::information(this, tr("Uisent", "pop-up title when data has been sent"), tr(QString("sav finish of "+savtitle).toStdString().c_str(), "pop-up text when data has been sent"));
 }
 void MainWindow::resetRAW(){
@@ -1127,13 +1153,13 @@ void MainWindow::insert(const QString & type, const QString & keyword, const QSt
     tmp.append(label);
     tmp.append(action);
     exec(tmp);
-    q->first();
+    q.first();
     //int count=0;
-    QString key=q->value(1).toString();
-    QVariant id=q->value(0);
-    while(q->next()){
+    QString key=q.value(1).toString();
+    QVariant id=q.value(0);
+    while(q.next()){
         //count++;
-        key=q->value(1).toString()+" "+key;
+        key=q.value(1).toString()+" "+key;
     }
     if(!key.contains(keyword)){// it isn't possible to have 2 buttons with same label and action
         key=key+" "+keyword;
@@ -1154,13 +1180,13 @@ void MainWindow::remove(const QString & type, const QString & keyword, const QSt
     tmp.append(action);
     qDebug()<<"tmp.size()="<<tmp.size()<<" tmp[0]="<<tmp[0];
     exec(tmp);
-    q->first();
+    q.first();
     //int count=1;
-    QString key=q->value(1).toString(), cur;
-    QVariant id=q->value(0);
-    while(q->next()){//la boucle ne sert que si il y a plusieurs entré avec les même label et action or insert nous l'interdit !
+    QString key=q.value(1).toString(), cur;
+    QVariant id=q.value(0);
+    while(q.next()){//la boucle ne sert que si il y a plusieurs entré avec les même label et action or insert nous l'interdit !
         //count++;
-        cur=q->value(1).toString();
+        cur=q.value(1).toString();
         key=key+" "+cur;
     }
     qDebug()<<"key="<<key<<" keyword="<<keyword;
@@ -1179,7 +1205,7 @@ void MainWindow::writeTr(){
     tmp.open(QIODevice::WriteOnly);
     tmp.write(m->downloadedData());
     tmp.close();
-    d.unlock();
+    //d.unlock();
 }
 void MainWindow::writeFile(){
     QFile tmp(file);
@@ -1189,7 +1215,7 @@ void MainWindow::writeFile(){
     emit writed();
     QMessageBox::information(this, tr("writeFile", "pop-up title when file has been written"), tr("File written : "+file.toLocal8Bit(), "pop-up text when file has been written"));
     m->disconnect();
-    d.unlock();
+    //d.unlock();
 }
 /*void MainWindow::addMedia(const QString & a){
     if((video)&&(playlist)){
@@ -1251,13 +1277,13 @@ void MainWindow::action(){
 void MainWindow::mass(const QString & type, const QString & column, const QString & before, const QString & after){
     exec(QList<QString>({conf->value(QString("change")+type).toString(), column}));
     QString key;
-    while(q->next()){
-        int n=q->record().indexOf(column);
+    while(q.next()){
+        int n=q.record().indexOf(column);
         key=get(n);
         if(key.contains(before)){
             key.replace(before, after);
             QList<QString> tmp({conf->value(QString("update")+type).toString()});
-            for(int t=0;t<q->record().count();t++){
+            for(int t=0;t<q.record().count();t++){
                 if(t==n)tmp.append(key);
                 else tmp.append(get(t));
             }
@@ -1277,19 +1303,21 @@ QSettings & MainWindow::getSettings(){
 }
 void MainWindow::downSQL(const QString & a){
     download(a);
+    //wk->doWork(a);
     connect(m, SIGNAL(downloaded()), SLOT(readSQL()));
 }
 void MainWindow::readSQL(){
     disconnect(m, SIGNAL(downloaded()));
     qDebug()<<"readSQL";
     QByteArray in=m->downloadedData();
-    q->exec("PRAGMA foreign_keys=OFF;");
-    q->exec("BEGIN TRANSACTION;");// these 2 line is SQLite specific
-    int b=in.count('\n');
+    q.exec("PRAGMA foreign_keys=OFF;");
+    q.exec("BEGIN TRANSACTION;");// these 2 line is SQLite specific
+    long long int b=in.count('\n');
     for(int i=0;i<b;i++){
-        q->exec(in.split('\n').at(i));
+        //q.exec(in.split('\n').at(i));
+        doSQL(in.split('\n').at(i));
     }
-    emit datafilled();
+
 }
 void MainWindow::debug(){
     if(deb)deb=0;
@@ -1319,24 +1347,23 @@ bool MainWindow::printItem(QSqlQuery & a){
     qDebug()<<"printItem()";
     if(page){
         QString tmp("prevpage");
-        addWidget(tmp, new CLabel(tr("Prev"), *conf));
+        addWidget(tmp, new CLabel(tr("Prev"), *conf, tmp));
 
     }
     bool t;
     do{
-        int tmp=0;
+        unsigned int tmp=0;
         QString tmp4=a.value(actCol).toString();
-        if(a.isValid())tmp=addWidget(tmp4, new CLabel(a.value(labCol).toString(), *conf, a.value(idcol).toInt()));
+        if(a.isValid())tmp=addWidget(tmp4, new CLabel(a.value(labCol).toString(), *conf, tmp4, a.value(idcol).toInt()));
         if(tmp==1){
             QString tmp3("nextpage");
-            addWidget(tmp3, new CLabel(tr("Next"), *conf));
+            addWidget(tmp3, new CLabel(tr("Next"), *conf, QString("next")));
             return 1;
         }
         i++;
         t=a.next();
     }while(t);
     qDebug()<<"end printItem : "<<i<<" button(s) way.size()"<<way.size()<<" page : "<<page;
-    //showExpanded();
     return 0;
 }
 void MainWindow::get2(const QString & d, const QString &b){
@@ -1346,7 +1373,7 @@ void MainWindow::get2(const QString & d, const QString &b){
     else a.remove(0, 1);
     qDebug()<<"get"<<d<<"("<<a<<") way.size()"<<way.size();
     if(b[0]!='+')flush();
-    if(updatelocker.tryLock(60000))updatelocker.unlock();
+    //if(updatelocker.tryLock(60000))updatelocker.unlock();
     else{qDebug()<<"updatelocker is locked more than 1mn";}
     QString t=QString("get"+d);
     QString c="%"+a+"%", x=conf->value(t).toString();
@@ -1355,10 +1382,14 @@ void MainWindow::get2(const QString & d, const QString &b){
     label->setText(a);
     exec2(tmp);
     page=0;
-    //while(q->next()){
-         printItem(*qq);
+    //while(q.next()){
+         printItem(qq);
     //}
 }
 /*void MainWindow::shellReady(){
     QMessageBox::information(this, QString("shell"), QString("shell ready"));
 }*/
+void MainWindow::doSQL(const QString & a){
+    q.exec(a);
+    emit SQLdone();
+}
index 5649d300a012b7948cf61793b18e326524e59a6b..01b622bffdea8ec8d2cfde4599e4d265db3191f2 100755 (executable)
@@ -63,8 +63,6 @@
 
 #ifndef FILEDOWNLOADER_H
 #define FILEDOWNLOADER_H
-
-
 class FileDownloader : public QObject
 {
     Q_OBJECT
@@ -82,19 +80,29 @@ private:
 };
 #endif // FILEDOWNLOADER_H
 
+class Worker : public QObject
+{
+    Q_OBJECT
+public slots:
+    void doWork(const QString &);
+signals:
+    void resultReady(const QString &);
+};
+
 class CLabel : public QLabel
 {
 Q_OBJECT
-    QString m_style;
+    QString m_style, action;
     QSettings * settings;
     QTime t;
     int id;
     QWidget * parents;
 public:
-    explicit CLabel(const QString&, QSettings &, int=0, QWidget * parent = 0 );
+    explicit CLabel(const QString&, QSettings &, const QString&, int=0, QWidget * parent = 0 );
     ~CLabel();
     void SetTextToLabel(const QString &);
     QSettings * getSettings();
+    QString getAction();
 signals:
     void clicked();
     void pressed();
@@ -131,7 +139,8 @@ public:
     void mass(const QString &, const QString &, const QString &, const  QString &);
     void downSQL(const QString &);
     void debug();
-private slots:
+protected slots:
+    void doSQL(const QString &);
     void readSQL();
     void tmpdown();
     void readData();
@@ -148,7 +157,7 @@ private slots:
     void createMenuBar();
     void toggleMenu();
     void flush();
-    void connectDB();
+    int connectDB();
     void firstrun();
     QString get(int);
     QString get2(int);
@@ -188,6 +197,7 @@ public slots:
 signals:
     void datafilled();
     void writed();
+    void SQLdone();
 private:
     //sax2 xml;
     //QsKineticScroller * ks;
@@ -202,11 +212,14 @@ private:
     QSettings *conf;
     QString tmp, tmp2, file, lastprint, currenttype, savtitle, beforekey, beforeactionmenu, beforekeyback, beforevolumedown, beforevolumeup;//host, user, tmp, password, servercert,database;
     QMenu *FileMenu, *EditMenu, *HackMenu;
-    QSignalMapper *signalmap;
+    //QSignalMapper *signalmap;
     QStringList way;
     QSqlDatabase db;
-    QSqlQuery *q, *qq;
+    QSqlQuery q, qq;
     QSqlRecord r;
+    Worker * wk;
+    QThread thread;
+    QString dbsql;
     FileDownloader * m;
     QNetworkAccessManager *net;
     QNetworkReply * rep;
@@ -217,6 +230,5 @@ private:
     QMap<QString, QString> * valeur;
 };
 
-
 #endif // MAINWINDOW_H