From 0cbe9c574df31eee338a4954805debff72c33619 Mon Sep 17 00:00:00 2001 From: Norbert Moutarde Date: Sun, 16 Mar 2014 18:08:19 +0100 Subject: [PATCH] I've added restoreDB() but It won't work ... --- README.md | 2 +- mainwindow.cpp | 24 ++++++++++++++++++++---- mainwindow.h | 1 + 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 269befd..866f389 100644 --- a/README.md +++ b/README.md @@ -14,4 +14,4 @@ ftp://[user]:[pass]@[hostname]/[filename] todo : -connect to postgresql server, edit button on the fly, and ... +connect to postgresql server, edit button on the fly, restore DB from url, and ... diff --git a/mainwindow.cpp b/mainwindow.cpp index 18ad436..a86abc1 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -145,7 +145,8 @@ void MainWindow::createMenuBar(){ FileMenu->addAction(trUtf8("&Start..."), this, SLOT(start()),QKeySequence(trUtf8("Ctrl+S", "File|Start"))); FileMenu->addAction(trUtf8("&Back"), this, SLOT(back()),QKeySequence(trUtf8("Ctrl+B", "File|Back"))); FileMenu->addAction(trUtf8("&Download"), this, SLOT(updateUi()),QKeySequence(trUtf8("Ctrl+W", "File|Downlad"))); - FileMenu->addAction(trUtf8("Up&load"), this, SLOT(sendDB()),QKeySequence(trUtf8("Ctrl+L", "File|Upload"))); + FileMenu->addAction(trUtf8("BackUp"), this, SLOT(sendDB()),QKeySequence(trUtf8("Ctrl+L", "File|Upload"))); + FileMenu->addAction(trUtf8("Rest&ore"), this, SLOT(restoreDB()),QKeySequence(trUtf8("Ctrl+O", "File|Restore"))); FileMenu->addAction(trUtf8("Reset Ui"), this, SLOT(resetUi()), QKeySequence(trUtf8("Ctrl+Z", "File|ResetUi"))); FileMenu->addAction(trUtf8("&Quit..."), this, SLOT(quit()),QKeySequence(trUtf8("Ctrl+Q", "File|Quit"))); menuBar()->addMenu(FileMenu); @@ -240,8 +241,9 @@ void MainWindow::firstrun(){ conf->setValue(QString("menu"), QVariant(1)); conf->setValue(QString("download"), QVariant("https://raw.github.com/Nothing2Do/diary-mobile-android/master/ui.sql")); conf->setValue(QString("upload"), QVariant("ftp://:@/")); + conf->setValue(QString("restore"), QVariant("http://www.xxx.com/db")); conf->setValue(QString("start"), QVariant("begin")); - conf->setValue(QString("db"), QVariant("/data/data/eu.nothing2do.diarymobile/db")); + conf->setValue(QString("db"), QVariant("/data/data/eu.nothing2do.diarymobile/files/db")); } QString &MainWindow::get(int row, int column){ q->seek(row); @@ -359,16 +361,18 @@ void MainWindow::updateUi(){ connect(m, SIGNAL(downloaded()), SLOT(writeUpdate())); } void MainWindow::sendDB(){ + system("su"); qDebug()<<"sendDB() : "<value(QString("upload")).toString(); QUrl upload(conf->value(QString("upload")).toString()); net=new QNetworkAccessManager(this); QFile b(conf->value(QString("db")).toString()); b.open(QIODevice::ReadOnly); - //QDataStream c(b.readAll()); - rep=net->put(QNetworkRequest(upload), b.readAll()); + QByteArray c(b.readAll()); + rep=net->put(QNetworkRequest(upload), c); qDebug()<<"net->put : "<put(QNetworkRequest(upload),data); connect(rep, SIGNAL(finished()), this, SLOT(datasend())); + system("exit"); } void MainWindow::back(){ if(way.size()-1>0){ @@ -465,3 +469,15 @@ void MainWindow::resetUi(){ exec(QList({"delete from ui;"})); } +void MainWindow::restoreDB(){ + system("su"); + qDebug()<<"restoreDB() : "<value(QString("restore")).toString(); + QUrl download(conf->value(QString("restore")).toString()); + net=new QNetworkAccessManager(this); + QFile b(conf->value(QString("db")).toString()); + b.open(QIODevice::WriteOnly); + rep=net->get(QNetworkRequest(download)); + // to be finished ... + b.write(rep->readAll()); + system("exit"); +} diff --git a/mainwindow.h b/mainwindow.h index 84c61fb..132c058 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -121,6 +121,7 @@ private slots: //void savButtons(); void readButtons(const QByteArray &); void resetUi(); + void restoreDB(); public slots: signals: -- 2.45.1