Skip to content

Commit

Permalink
https://github.com/StephaneCouturier/Katalog/issues/553
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneCouturier committed Sep 14, 2024
1 parent b1ea619 commit a366abe
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -8030,7 +8030,7 @@ background: url(:/images/link-h.png) repeat-x center;</string>
<item>
<widget class="QPushButton" name="Settings_pushButton_ExportToSQLitFile">
<property name="toolTip">
<string>Open the collection folder</string>
<string>Export to convert and open the collection in &quot;File&quot; mode.</string>
</property>
<property name="text">
<string>Export to SQLite file</string>
Expand Down
60 changes: 27 additions & 33 deletions src/mainwindow_tab_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
settings.setValue("Settings/databaseUserName", ui->Settings_lineEdit_DataMode_Hosted_UserName->text());
settings.setValue("Settings/databasePassword", ui->Settings_lineEdit_DataMode_Hosted_Password->text());
}
//Enable and highlight restart button
//Restart
QProcess::startDetached(QApplication::applicationFilePath(), QApplication::arguments());
QApplication::exit();
}
Expand Down Expand Up @@ -169,7 +169,7 @@
//Folder and file name selection

//Default folder and file name
QString backupFilePath = collection->folder + "/backup.db"; // Path to the output file
QString backupFilePath = collection->folder + "/export.db"; // Path to the output file

//Open a dialog for the user to select the directory of the collection where catalog files are stored.
QString selectedBackupFilePath = QFileDialog::getSaveFileName(this, tr("Select the directory and file name for his export."),
Expand All @@ -178,17 +178,10 @@
//Unless the selection was cancelled, set the new collection folder, and refresh all data
if ( selectedBackupFilePath !=""){
QFile newBackupFile(selectedBackupFilePath);
if( !newBackupFile.exists())
backupFilePath = selectedBackupFilePath;
else{
msgBox.setText(QCoreApplication::translate("MainWindow",
"Katalog cannot export to an existing file.<br/>"
"Selected existing file: <br/><b>%1</b><br/>"
"Select a new file name.<br/>"
).arg( selectedBackupFilePath ));
msgBox.exec();
return;
}
if( newBackupFile.exists())
newBackupFile.moveToTrash();

backupFilePath = selectedBackupFilePath;
}

//Load all Catalogs indexes into memory
Expand All @@ -198,49 +191,50 @@
QMutex tempMutex;
bool tempStopRequested = false;

// Get the number of devices to be processed
QSqlQuery countQuery(QSqlDatabase::database("defaultConnection"));
QString countQuerySQL = QLatin1String(R"(
SELECT COUNT(*)
// Get the total number of files for all devices
QSqlQuery fileCountQuery(QSqlDatabase::database("defaultConnection"));
QString fileCountQuerySQL = QLatin1String(R"(
SELECT SUM(device_total_file_count)
FROM device
WHERE device_type ="Catalog"
)");
countQuery.prepare(countQuerySQL);
countQuery.exec();
countQuery.next();
int deviceCount = countQuery.value(0).toInt();
fileCountQuery.prepare(fileCountQuerySQL);
fileCountQuery.exec();
fileCountQuery.next();
qint64 totalFileCount = fileCountQuery.value(0).toInt();

// Create the progress dialog
QProgressDialog progress("Loading devices...", "Cancel", 0, deviceCount, this);
QProgressDialog progress("Loading devices...", "Cancel", 0, totalFileCount, this);
progress.setWindowModality(Qt::WindowModal);
int i = 0;
qint64 filesLoaded = 0;

// List all Catalogs indexes to be loaded into memory
QSqlQuery query(QSqlDatabase::database("defaultConnection"));
QString querySQL = QLatin1String(R"(
SELECT device_id, device_name
SELECT device_id, device_name, device_total_file_count
FROM device
WHERE device_type ="Catalog"
)");
query.prepare(querySQL);
query.exec();

while(query.next()){
progress.setValue(i);
progress.setLabelText(QString("Loading device: %1").arg(query.value(1).toString()));
int deviceId = query.value(0).toInt();
QString deviceName = query.value(1).toString();
qint64 deviceFileCount = query.value(2).toInt();

if (progress.wasCanceled()){
return;
}
progress.setLabelText(QString("Loading catalog prior to export<br/> %1 <br/><br/> %2 files loaded out of %3" ).arg(deviceName, QLocale().toString(filesLoaded), QLocale().toString(totalFileCount)) );

tempCatalogDevice.ID = query.value(0).toInt();
tempCatalogDevice.ID = deviceId;
tempCatalogDevice.loadDevice("defaultConnection");
tempCatalogDevice.catalog->loadCatalogFileListToTable("defaultConnection", tempMutex, tempStopRequested);

i++;
}
filesLoaded += deviceFileCount;
progress.setValue(filesLoaded);

progress.setValue(deviceCount);
if (progress.wasCanceled())
return;
}

//Dump all the database in Memory to the sql File
if (!backupMemoryDatabaseToFile("defaultConnection", backupFilePath)) {
Expand Down

0 comments on commit a366abe

Please sign in to comment.