|
5 | 5 | #include "duqf-app/app-version.h" |
6 | 6 | #include "duqf-utils/utils.h" |
7 | 7 | #include "progressmanager.h" |
| 8 | +#include "statemanager.h" |
8 | 9 | #include "ramuser.h" |
9 | 10 | #include "ramses.h" |
10 | 11 |
|
@@ -371,6 +372,19 @@ bool LocalDataInterface::isRemoved(QString uuid, QString table) |
371 | 372 | return true; |
372 | 373 | } |
373 | 374 |
|
| 375 | +QString LocalDataInterface::modificationDate(QString uuid, QString table) |
| 376 | +{ |
| 377 | + QString q = "SELECT modified FROM %1 WHERE uuid = '%2';"; |
| 378 | + QSqlQuery qry = query( q.arg(table, uuid) ); |
| 379 | + |
| 380 | + if (qry.first()) |
| 381 | + { |
| 382 | + return qry.value(0).toString(); |
| 383 | + } |
| 384 | + |
| 385 | + return "1818-05-05 00:00:00"; |
| 386 | +} |
| 387 | + |
374 | 388 | void LocalDataInterface::setUsername(QString uuid, QString username) |
375 | 389 | { |
376 | 390 | username.replace("'", "''"); |
@@ -490,16 +504,25 @@ const QString &LocalDataInterface::dataFile() const |
490 | 504 |
|
491 | 505 | ServerConfig LocalDataInterface::setDataFile(const QString &file) |
492 | 506 | { |
| 507 | + QElapsedTimer timer; |
| 508 | + timer.start(); |
| 509 | + |
| 510 | + qDebug() << ">> Opening local file..."; |
| 511 | + |
493 | 512 | // Clear all cache |
494 | 513 | m_uuids.clear(); |
495 | 514 | m_uuidsWithoutRemoved.clear(); |
496 | 515 |
|
| 516 | + qDebug() << ">> Cleared cache: " << timer.elapsed()/1000 << " seconds."; |
| 517 | + |
497 | 518 | ProgressManager *pm = ProgressManager::instance(); |
498 | 519 | pm->addToMaximum(2); |
499 | 520 |
|
500 | 521 | QSqlDatabase db = QSqlDatabase::database("localdata"); |
501 | 522 | openDB(db, file); |
502 | 523 |
|
| 524 | + qDebug() << ">> Opened file: " << timer.elapsed()/1000 << " seconds."; |
| 525 | + |
503 | 526 | pm->increment(); |
504 | 527 | pm->setText(tr("Loading data...")); |
505 | 528 |
|
@@ -542,6 +565,8 @@ ServerConfig LocalDataInterface::setDataFile(const QString &file) |
542 | 565 |
|
543 | 566 | pm->increment(); |
544 | 567 |
|
| 568 | + qDebug() << ">> Local data ready! " << timer.elapsed()/1000 << " seconds."; |
| 569 | + |
545 | 570 | return serverConfig(); |
546 | 571 | } |
547 | 572 |
|
@@ -623,6 +648,9 @@ SyncData LocalDataInterface::getSync(bool fullSync) |
623 | 648 |
|
624 | 649 | void LocalDataInterface::saveSync(SyncData syncData) |
625 | 650 | { |
| 651 | + StateManager::State previousState = StateManager::i()->state(); |
| 652 | + StateManager::i()->setState(StateManager::WritingDataBase); |
| 653 | + |
626 | 654 | QHash<QString, QSet<TableRow>> tables = syncData.tables; |
627 | 655 |
|
628 | 656 | ProgressManager *pm = ProgressManager::instance(); |
@@ -706,11 +734,14 @@ void LocalDataInterface::saveSync(SyncData syncData) |
706 | 734 | query( q ); |
707 | 735 |
|
708 | 736 | // Emit insertions |
| 737 | + StateManager::i()->setState(StateManager::LoadingDataBase); |
709 | 738 | foreach(QStringList io, insertedObjects ) { |
710 | 739 | emit inserted( io.at(0), io.at(1), io.at(2) ); |
711 | 740 | } |
712 | 741 | } |
713 | 742 |
|
| 743 | + StateManager::i()->setState(StateManager::WritingDataBase); |
| 744 | + |
714 | 745 | // Updates |
715 | 746 | i.toFront(); |
716 | 747 | while (i.hasNext()) { |
@@ -795,12 +826,15 @@ void LocalDataInterface::saveSync(SyncData syncData) |
795 | 826 | query( q ); |
796 | 827 |
|
797 | 828 | // Emit |
| 829 | + StateManager::i()->setState(StateManager::LoadingDataBase); |
798 | 830 | foreach(QStringList cu, changedUuids) { |
799 | 831 | emit dataChanged(cu.first(), cu.last(), tableName); |
800 | 832 | } |
801 | 833 | } |
802 | 834 |
|
803 | 835 | emit syncFinished(); |
| 836 | + |
| 837 | + StateManager::i()->setState(previousState); |
804 | 838 | } |
805 | 839 |
|
806 | 840 | void LocalDataInterface::deleteData(SyncData syncData) |
@@ -930,6 +964,9 @@ QVector<QStringList> LocalDataInterface::users() |
930 | 964 |
|
931 | 965 | QString LocalDataInterface::cleanDataBase(int deleteDataOlderThan) |
932 | 966 | { |
| 967 | + StateManager::State previousState = StateManager::i()->state(); |
| 968 | + StateManager::i()->setState(StateManager::WritingDataBase); |
| 969 | + |
933 | 970 | QString report = ""; |
934 | 971 |
|
935 | 972 | // Backup the DB File |
@@ -1030,6 +1067,8 @@ QString LocalDataInterface::cleanDataBase(int deleteDataOlderThan) |
1030 | 1067 |
|
1031 | 1068 | qDebug() << "Finished clean."; |
1032 | 1069 |
|
| 1070 | + StateManager::i()->setState(previousState); |
| 1071 | + |
1033 | 1072 | return report; |
1034 | 1073 | } |
1035 | 1074 |
|
@@ -1081,7 +1120,7 @@ LocalDataInterface::LocalDataInterface(): |
1081 | 1120 | } |
1082 | 1121 |
|
1083 | 1122 | bool LocalDataInterface::openDB(QSqlDatabase db, const QString &dbFile) |
1084 | | -{ |
| 1123 | +{ |
1085 | 1124 | ProgressManager *pm = ProgressManager::instance(); |
1086 | 1125 | pm->addToMaximum(2); |
1087 | 1126 | pm->setText(tr("Opening database...")); |
@@ -1230,6 +1269,9 @@ void LocalDataInterface::autoCleanDB(QSqlDatabase db) |
1230 | 1269 | if ( !db.open() ) return; |
1231 | 1270 | } |
1232 | 1271 |
|
| 1272 | + StateManager::State previousState = StateManager::i()->state(); |
| 1273 | + StateManager::i()->setState(StateManager::WritingDataBase); |
| 1274 | + |
1233 | 1275 | // === Delete removed statuses === |
1234 | 1276 |
|
1235 | 1277 | qry.exec("DELETE FROM RamStatus WHERE `removed` = 1 ;"); |
@@ -1442,6 +1484,8 @@ void LocalDataInterface::autoCleanDB(QSqlDatabase db) |
1442 | 1484 | // === Vacuum === |
1443 | 1485 |
|
1444 | 1486 | qry.exec("VACUUM;"); |
| 1487 | + |
| 1488 | + StateManager::i()->setState(previousState); |
1445 | 1489 | } |
1446 | 1490 |
|
1447 | 1491 | QSqlQuery LocalDataInterface::query(QString q) const |
|
0 commit comments