Skip to content

Commit

Permalink
https://github.com/StephaneCouturier/Katalog/issues/496
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneCouturier committed Apr 13, 2024
1 parent 369fb65 commit af03c44
Show file tree
Hide file tree
Showing 12 changed files with 174 additions and 98 deletions.
44 changes: 35 additions & 9 deletions src/collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,47 @@

void Collection::generateCollectionFilesPaths()
{
searchHistoryFilePath = collectionFolder + "/" + "search_history.csv";
storageFilePath = collectionFolder + "/" + "storage.csv";
deviceFilePath = collectionFolder + "/" + "device.csv";
searchHistoryFilePath = folder + "/" + "search_history.csv";
storageFilePath = folder + "/" + "storage.csv";
deviceFilePath = folder + "/" + "device.csv";
statisticsDeviceFileName = "statistics.csv";
statisticsDeviceFilePath = collectionFolder + "/" + statisticsDeviceFileName;
excludeFilePath = collectionFolder + "/" + "exclude.csv";
statisticsDeviceFilePath = folder + "/" + statisticsDeviceFileName;
excludeFilePath = folder + "/" + "exclude.csv";

//v1.22 files
deviceCatalogFilePath = collectionFolder + "/" + "device_catalog.csv";
deviceCatalogFilePath = folder + "/" + "device_catalog.csv";
statisticsCatalogFileName = "statistics_catalog.csv";
statisticsCatalogFilePath = collectionFolder + "/" + statisticsCatalogFileName;
statisticsCatalogFilePath = folder + "/" + statisticsCatalogFileName;
statisticsStorageFileName = "statistics_storage.csv";
statisticsStorageFilePath = collectionFolder + "/" + statisticsStorageFileName;
statisticsStorageFilePath = folder + "/" + statisticsStorageFileName;

}

void Collection::generateCollectionFiles()
{
if(databaseMode=="Memory"){
QFile deviceFile(deviceFilePath);
if (!deviceFile.exists()) {
// Create the necessary directories
//QFileInfo fileInfo(deviceFile);
//QString path = fileInfo.absolutePath();
//QDir dir;
//if (!dir.mkpath(path)) {
// qDebug() << "DEBUG Failed to create directories:";
//}
//}
//else {
//Create an empty CSV file
if (deviceFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
//File opened successfully, no need to write anything
deviceFile.close(); // Close the file after creating it
} else {
qDebug() << "DEBUG Failed to create file:" << deviceFile.errorString();
}
}
}
}

//----------------------------------------------------------------------
void Collection::loadAllCatalogFiles()
{//Load all catalog files to memory
Expand Down Expand Up @@ -243,7 +269,7 @@ void Collection::loadCatalogFilesToTable()
QStringList catalogFileExtensions;
catalogFileExtensions << "*.idx";

QDirIterator iterator(collectionFolder, catalogFileExtensions, QDir::Files, QDirIterator::Subdirectories);
QDirIterator iterator(folder, catalogFileExtensions, QDir::Files, QDirIterator::Subdirectories);
while (iterator.hasNext()){

// Iterate to the next file
Expand Down
6 changes: 4 additions & 2 deletions src/collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <QAbstractTableModel>
#include <QFile>
#include <QSqlQuery>
#include <QSqlError>>
#include <QSqlError>
#include <QSqlRecord>
#include <QMessageBox>
#include <QCoreApplication>
Expand All @@ -48,7 +48,8 @@ class Collection
public:

//Main attributes
QString collectionFolder;
QString version;
QString folder;
QString settingsFilePath;

//Database management
Expand All @@ -74,6 +75,7 @@ class Collection
QString excludeFilePath;
QString tagsFilePath;
void generateCollectionFilesPaths();
void generateCollectionFiles();

//File loading
void loadAllCatalogFiles();
Expand Down
14 changes: 7 additions & 7 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
{
//Set current version, release date, and development mode
currentVersion = "2.0";
releaseDate = "2024-03-31";
releaseDate = "2024-04-13";
developmentMode = false;

//Prepare paths, user setting file, check version
Expand Down Expand Up @@ -146,10 +146,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
openCatalogToExplore();
}

//Preload last selected catalogs contents to memory
if(ui->Settings_checkBox_PreloadCatalogs->isChecked()==true){
preloadCatalogs();
}
//Preload last selected catalogs contents to memory
if(ui->Settings_checkBox_PreloadCatalogs->isChecked()==true){
preloadCatalogs();
}

//Setup tabs

Expand All @@ -172,7 +172,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi

//Setup tab: Settings
//Load path of last collection used
ui->Settings_lineEdit_CollectionFolder->setText(collection->collectionFolder);
ui->Settings_lineEdit_CollectionFolder->setText(collection->folder);

//Apply databaseMode in Settings tab
QMap<QString, QString> databaseModeTranslations = {
Expand Down Expand Up @@ -307,7 +307,7 @@ msgBox.setWindowTitle("Katalog");
msgBox.setText(tr("anyVariable")+": <br/>" + QVariant(anyVariable).toString());
msgBox.setText(QCoreApplication::translate("MainWindow",
"Text<br/>"
"<br/> Text with first parameter<br/><b>%2</b><br/>"
"<br/> Text with first parameter<br/><b>%1</b><br/>"
"<br/> Text with first parameter<br/><b>%2</b><br/>"
).arg( parameter1, tempText.toUtf8() ));
msgBox.setIcon(QMessageBox::Information);
Expand Down
1 change: 1 addition & 0 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ class MainWindow : public QMainWindow
int countTreeLevels(const QMap<int, QList<int>>& deviceTree, int parentId);

//Migration 1.22 to 2.0
void migrateCollection();
void importVirtualToDevices();
void importStorageToDevices();
void importCatalogsToDevices();
Expand Down
34 changes: 17 additions & 17 deletions src/mainwindow_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@
if (!settingsFile.exists())
firstRun =true;

collection->collectionFolder = settings.value("LastCollectionFolder").toString();
collection->folder = settings.value("LastCollectionFolder").toString();

if (collection->collectionFolder == "")
if (collection->folder == "")
firstRun =true;

if (firstRun == true){
Expand Down Expand Up @@ -252,17 +252,17 @@

//Collection folder choice
//Open a dialog for the user to select the directory of the collection where catalog files are stored.
collection->collectionFolder = QFileDialog::getExistingDirectory(this, tr("Select the directory for this collection"),
collection->collectionFolder,
collection->folder = QFileDialog::getExistingDirectory(this, tr("Select the directory for this collection"),
collection->folder,
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);

//set the location of the application as a default value if a folder was not provided
if (collection->collectionFolder =="")
collection->collectionFolder = QApplication::applicationDirPath();
if (collection->folder =="")
collection->folder = QApplication::applicationDirPath();

//save setting
settings.setValue("LastCollectionFolder", collection->collectionFolder);
settings.setValue("LastCollectionFolder", collection->folder);

//Go to Create screen
QMessageBox msgBox2;
Expand All @@ -279,7 +279,7 @@

//Collection folder
if (firstRun != true){
collection->collectionFolder = settings.value("LastCollectionFolder").toString();
collection->folder = settings.value("LastCollectionFolder").toString();
}

selectedDevice->ID = settings.value("Selection/SelectedDeviceID").toInt();
Expand Down Expand Up @@ -413,19 +413,19 @@

//Filter

//Devices
ui->Devices_pushButton_TreeExpandCollapse->hide();
ui->Devices_widget_Import->hide();

//Search
//Search
//hide Krename if not linux
#ifndef Q_OS_LINUX
ui->Search_comboBox_SelectProcess->removeItem(2);
ui->Search_comboBox_SelectProcess->removeItem(2);
#endif

//Catalogs
//DEV: preparing catalog-device relation
ui->Catalogs_checkBox_isFullDevice->hide();
//Devices
ui->Devices_pushButton_TreeExpandCollapse->hide();
ui->Devices_widget_Import->hide();

//Catalogs
//DEV: preparing catalog-device relation
ui->Catalogs_checkBox_isFullDevice->hide();

//Create
//DEV: the option to include symblinks is not working yet
Expand Down
8 changes: 4 additions & 4 deletions src/mainwindow_tab_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@
newDevice->insertDevice();

//Get inputs and set values of the newCatalog
newDevice->catalog->filePath = collection->collectionFolder + "/" + newDevice->name + ".idx";
newDevice->catalog->filePath = collection->folder + "/" + newDevice->name + ".idx";
newDevice->catalog->sourcePath = ui->Create_lineEdit_NewCatalogPath->text();
newDevice->catalog->includeHidden = ui->Create_checkBox_IncludeHidden->isChecked();
newDevice->catalog->storageName = ui->Create_comboBox_StorageSelection->currentText();
Expand Down Expand Up @@ -256,7 +256,7 @@
newDevice->updateDevice("create",
collection->databaseMode,
false,
collection->collectionFolder,
collection->folder,
true),
"create");

Expand All @@ -265,8 +265,8 @@

//Save data to files
collection->saveDeviceTableToFile();
newDevice->catalog->saveCatalogToFile(collection->databaseMode, collection->collectionFolder);
newDevice->catalog->saveFoldersToFile(collection->databaseMode, collection->collectionFolder);
newDevice->catalog->saveCatalogToFile(collection->databaseMode, collection->folder);
newDevice->catalog->saveFoldersToFile(collection->databaseMode, collection->folder);

//Update the new catalog loadedversion to indicate that files are already in memory
QDateTime emptyDateTime = *new QDateTime;
Expand Down
Loading

0 comments on commit af03c44

Please sign in to comment.