Skip to content

Commit

Permalink
https://github.com/StephaneCouturier/Katalog/issues/550
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneCouturier committed Sep 28, 2024
1 parent 0ef9263 commit 4aacdd0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 32 deletions.
12 changes: 6 additions & 6 deletions src/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,16 +783,16 @@ void Device::updateActive(QString connectionName)
active = false;
}

QSqlQuery query(QSqlDatabase::database(connectionName));
QString querySQL = QLatin1String(R"(
QSqlQuery queryUpdateActive(QSqlDatabase::database(connectionName));
QString queryUpdateActiveSQL = QLatin1String(R"(
UPDATE device
SET device_active =:device_active
WHERE device_id =:device_id
)");
query.prepare(querySQL);
query.bindValue(":device_active", active);
query.bindValue(":device_id", ID);
query.exec();
queryUpdateActive.prepare(queryUpdateActiveSQL);
queryUpdateActive.bindValue(":device_active", active);
queryUpdateActive.bindValue(":device_id", ID);
queryUpdateActive.exec();
}

void Device::saveStatistics(QDateTime dateTime, QString requestSource)
Expand Down
39 changes: 15 additions & 24 deletions src/searchprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

#include "searchprocess.h"
#include "device.h"
#include "src/filesview.h"
#include <QApplication>
#include <QMessageBox>
#include <QSqlQuery>
Expand Down Expand Up @@ -32,6 +31,14 @@ void SearchProcess::run()
return;
}

//Clear search results
mainWindow->newSearch->fileNames.clear();
mainWindow->newSearch->filePaths.clear();
mainWindow->newSearch->fileSizes.clear();
mainWindow->newSearch->fileDateTimes.clear();
mainWindow->newSearch->fileCatalogs.clear();
mainWindow->newSearch->fileCatalogIDs.clear();

//Process the SEARCH in CATALOGS or DIRECTORY ------------------------------

//Prepare the SEARCH -------------------------------
Expand Down Expand Up @@ -587,6 +594,7 @@ void SearchProcess::searchFilesInDirectory(const QString &sourceDirectory)
mainWindow->newSearch->fileSizes.append(lineFileSize);
mainWindow->newSearch->fileDateTimes.append(lineFileDatetime);
mainWindow->newSearch->fileCatalogs.append(sourceDirectory);
mainWindow->newSearch->fileCatalogIDs.append(0);
}
}
else{
Expand All @@ -611,6 +619,7 @@ void SearchProcess::searchFilesInDirectory(const QString &sourceDirectory)
mainWindow->newSearch->fileSizes.append(lineFileSize);
mainWindow->newSearch->fileDateTimes.append(lineFileDatetime);
mainWindow->newSearch->fileCatalogs.append(sourceDirectory);
mainWindow->newSearch->fileCatalogIDs.append(0);
}
}
}
Expand Down Expand Up @@ -697,21 +706,6 @@ void SearchProcess::processSearchResults()
mainWindow->newSearch->fileSizes.append(0);
mainWindow->newSearch->fileDateTimes.append("");
}

// Populate model with data
fileViewModel->caseSensitive = mainWindow->fileSortCaseSensitive;
fileViewModel->setSourceModel(mainWindow->newSearch);
}

//Populate model with Files (if the Folder option is not selected)
else
{
// Populate model with data
fileViewModel->caseSensitive = mainWindow->fileSortCaseSensitive;
fileViewModel->setSourceModel(mainWindow->newSearch);
if (mainWindow->newSearch->searchInConnectedChecked == true){
fileViewModel->setHeaderData(3, Qt::Horizontal, QCoreApplication::translate("MainWindow", "Search Directory"));
}
}

//Process DUPLICATES -------------------------------
Expand Down Expand Up @@ -748,11 +742,9 @@ void SearchProcess::processSearchResults()
insertQuery.prepare(insertSQL);

//loop through the result list and populate database

int rows = mainWindow->newSearch->rowCount();

for (int i=0; i<rows; i++) {

//Append data to the database
insertQuery.bindValue(":file_name", mainWindow->newSearch->index(i,0).data().toString());
insertQuery.bindValue(":file_size", mainWindow->newSearch->index(i,1).data().toString());
Expand Down Expand Up @@ -824,9 +816,6 @@ void SearchProcess::processSearchResults()
mainWindow->newSearch->fileCatalogs.append(duplicatesQuery.value(4).toString());
mainWindow->newSearch->fileCatalogIDs.append(duplicatesQuery.value(5).toInt());
}

//Update search statistics
mainWindow->newSearch->filesFoundNumber = fileViewModel->rowCount();
}

//Process DIFFERENCES -------------------------------
Expand All @@ -838,6 +827,9 @@ void SearchProcess::processSearchResults()
or mainWindow->newSearch->differencesOnDate == true)){

//Load Search results into the database
QSqlQuery transactionQuery(QSqlDatabase::database(connectionName));
transactionQuery.exec("BEGIN TRANSACTION");

//Clear database
QSqlQuery deleteQuery(QSqlDatabase::database(connectionName));
deleteQuery.exec("DELETE FROM filetemp");
Expand Down Expand Up @@ -992,6 +984,8 @@ void SearchProcess::processSearchResults()
if (!differencesQuery.exec())
qDebug() << "DEBUG: differencesQuery failed:" << differencesQuery.lastError();

transactionQuery.exec("COMMIT");

//Recapture file results for Stats
mainWindow->newSearch->fileNames.clear();
mainWindow->newSearch->fileSizes.clear();
Expand All @@ -1018,9 +1012,6 @@ void SearchProcess::processSearchResults()
mainWindow->newSearch->filesFoundMinDate = "";
mainWindow->newSearch->filesFoundMaxDate = "";

//Number of files found
mainWindow->newSearch->filesFoundNumber = fileViewModel->rowCount();

//Total size of files found
qint64 sizeItem;
mainWindow->newSearch->filesFoundTotalSize = 0;
Expand Down
2 changes: 0 additions & 2 deletions src/searchprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <QObject>
#include <QThread>
#include "mainwindow.h"
#include "filesview.h"

class SearchProcess : public QThread
{
Expand All @@ -13,7 +12,6 @@ class SearchProcess : public QThread
public:
explicit SearchProcess(MainWindow *mainWindow, QString databaseMode, QObject *parent = nullptr);
void stop();
FilesView *fileViewModel = new FilesView(this);
QString databaseMode;
QString connectionName;

Expand Down

0 comments on commit 4aacdd0

Please sign in to comment.