]> git.nothing2do.fr Git - diary-mobile.git/commitdiff
getButtons now wait for updateUi finish to populate database
authorNothing2Do <gabypiot@yahoo.fr>
Tue, 7 Jan 2014 12:16:32 +0000 (13:16 +0100)
committerNothing2Do <gabypiot@yahoo.fr>
Tue, 7 Jan 2014 12:16:32 +0000 (13:16 +0100)
mainwindow.cpp
mainwindow.h

index ec14f85668e1991092e0c5e9146af21c67c3858b..1addb7fe336a6fa25b2b188cc1a5f13ee6eb8b13 100644 (file)
@@ -32,11 +32,15 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
     if(conf->value(QString("first")).toInt()==1){
         qDebug()<<"second";
         createDB();
-        updateUi();
         conf->setValue(QString("first"), 2);
     };
     QFile sav(conf->value(QString("buttonfile")).toString());
-    if(sav.exists())data=sav.readAll();
+    if(sav.exists()){
+        sav.open(QIODevice::ReadWrite|QIODevice::Text);
+        data=sav.readAll();
+    }else{
+        updateUi();
+    }
     statusBar()->addPermanentWidget(label);
     menuBar()->setVisible(conf->value(QString("menu")).toBool());
     start();
@@ -113,7 +117,7 @@ void MainWindow::lsconfig(){
 void MainWindow::quit(){
     qDebug()<<"quit()";
     conf->setValue(QString("menu"), menuBar()->isVisible());
-    //conf->sync();
+    savButtons();
     db.commit();
     db.close();
     qApp->quit();
@@ -337,6 +341,8 @@ void MainWindow::addButtonDB(){
 void MainWindow::getButtons(const QString &a){
     qDebug()<<"getButtons("<<a<<")";
     flush();
+    updatelocker.tryLock(10000);
+    updatelocker.unlock();
     way.append(a);
     QString b="%"+a+"%";
     QList<QString> tmp({"select label,action from ui where keyword like ?;", b});
@@ -368,11 +374,14 @@ void MainWindow::editButtonDB(){
     }*/
 }
 void MainWindow::updateUi(){
-    updatelocker.lock();
+    /*qDebug()<<"updatelocker.lock()";
+    updatelocker.lock();*/
     qDebug()<<"updateUi() : "<<conf->value(QString("download")).toString();
     QUrl update(conf->value(QString("download")).toString());
     m = new FileDownloader(update, this);
     connect(m, SIGNAL(downloaded()), SLOT(writeUpdate()));
+    qDebug()<<"updatelocker unlocked";
+
 }
 void MainWindow::sendUi(){
     qDebug()<<"sendUi() : "<<conf->value(QString("upload")).toString();
@@ -440,13 +449,13 @@ void MainWindow::writeUpdate(){
     q->exec("PRAGMA foreign_keys=OFF;");
     q->exec("BEGIN TRANSACTION;");
     readButtons(m->downloadedData());
-    savButtons(m->downloadedData());
-    updatelocker.unlock();
-    qDebug()<<"updatelocker unlocked";
-    getButtons(conf->value(QString("start"), QVariant("begin")).toString());
+    //updateUi();
+    savButtons();
+    //getButtons(conf->value(QString("start"), QVariant("begin")).toString());
 
 }
-void MainWindow::savButtons(const QByteArray & data){
+void MainWindow::savButtons(){
+    qDebug()<<"savButtons";
     QFile b(conf->value(QString("buttonfile")).toString());
     b.open(QIODevice::WriteOnly);
     b.write(data);
index 15bd91c6a0f3da63dd3df3cebb017d3ab585c9d3..4c4559bbf5033b5bfaf70e41aa45682bc37c47e0 100644 (file)
@@ -117,7 +117,7 @@ private slots:
     void updateUi();
     void writeUpdate();
     void sendUi();
-    void savButtons(const QByteArray &);
+    void savButtons();
     void readButtons(const QByteArray &);
 public slots: