Add reindex action
This commit is contained in:
+80
-53
@@ -139,6 +139,28 @@ void Database::indexDir(const QDir &dir, QProgressDialog *progress)
|
|||||||
database.rollback();
|
database.rollback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Database::reindex(QProgressDialog *progress)
|
||||||
|
{
|
||||||
|
QVariantList deleteids;
|
||||||
|
QSqlDatabase database = QSqlDatabase::database();
|
||||||
|
QSqlQuery files = database.exec("SELECT id,file,mtime FROM fits_files");
|
||||||
|
progress->setMaximum(files.size());
|
||||||
|
int i = 0;
|
||||||
|
while(files.next())
|
||||||
|
{
|
||||||
|
QString path = files.value(1).toString();
|
||||||
|
QFileInfo file(path);
|
||||||
|
if(file.exists() && file.fileTime(QFileDevice::FileModificationTime).toUTC().toString(Qt::ISODate) != files.value(2).toString())
|
||||||
|
indexFile(file);
|
||||||
|
if(!file.exists())
|
||||||
|
deleteids.append(files.value(0));
|
||||||
|
progress->setValue(i++);
|
||||||
|
}
|
||||||
|
QSqlQuery deleteFiles("DELETE FROM fits_files WHERE id = ?", database);
|
||||||
|
deleteFiles.bindValue(0, deleteids);
|
||||||
|
deleteFiles.execBatch();
|
||||||
|
}
|
||||||
|
|
||||||
QStringList Database::getFitsKeywords()
|
QStringList Database::getFitsKeywords()
|
||||||
{
|
{
|
||||||
m_headerKeywords.exec();
|
m_headerKeywords.exec();
|
||||||
@@ -161,63 +183,68 @@ bool Database::indexDir2(const QDir &dir, QProgressDialog *progress)
|
|||||||
if(!indexDir2(dir.filePath(d), progress))
|
if(!indexDir2(dir.filePath(d), progress))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ImageInfoData info;
|
|
||||||
for(const QFileInfo &file : files)
|
for(const QFileInfo &file : files)
|
||||||
{
|
{
|
||||||
progress->setValue(m_progress++);
|
progress->setValue(m_progress++);
|
||||||
if(progress->wasCanceled())return false;
|
if(progress->wasCanceled())return false;
|
||||||
QString filePath = file.absoluteFilePath();
|
if(!indexFile(file))return false;
|
||||||
QString mtime = file.fileTime(QFileDevice::FileModificationTime).toUTC().toString(Qt::ISODate);
|
|
||||||
m_checkFile.bindValue(0, filePath);
|
|
||||||
m_checkFile.exec();
|
|
||||||
if(m_checkFile.next())
|
|
||||||
{
|
|
||||||
if(m_checkFile.value(1).toString() == mtime)
|
|
||||||
continue;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_deleteFile.bindValue(0, m_checkFile.value(0).toLongLong());
|
|
||||||
m_deleteFile.exec();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ok;
|
|
||||||
if(filePath.endsWith(".xisf", Qt::CaseInsensitive))
|
|
||||||
ok = readXISFHeader(filePath, info);
|
|
||||||
else
|
|
||||||
ok = readFITSHeader(filePath, info);
|
|
||||||
|
|
||||||
qlonglong last_id = -1;
|
|
||||||
if(ok)
|
|
||||||
{
|
|
||||||
m_insertFile.bindValue(0, filePath);
|
|
||||||
m_insertFile.bindValue(1, mtime);
|
|
||||||
if(!m_insertFile.exec())
|
|
||||||
{
|
|
||||||
qDebug() << m_insertFile.lastError();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
last_id = m_insertFile.lastInsertId().toLongLong();
|
|
||||||
QVariantList file_id, keys, values, comments;
|
|
||||||
for(auto &record : info.fitsHeader)
|
|
||||||
{
|
|
||||||
file_id << last_id;
|
|
||||||
keys << QString(record.key);
|
|
||||||
values << record.value.toString();
|
|
||||||
comments << QString(record.comment);
|
|
||||||
}
|
|
||||||
m_insertFitsHeader.bindValue(0, file_id);
|
|
||||||
m_insertFitsHeader.bindValue(1, keys);
|
|
||||||
m_insertFitsHeader.bindValue(2, values);
|
|
||||||
m_insertFitsHeader.bindValue(3, comments);
|
|
||||||
if(!m_insertFitsHeader.execBatch())
|
|
||||||
{
|
|
||||||
qDebug() << m_insertFitsHeader.lastError();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
qDebug() << filePath << last_id;
|
|
||||||
info.fitsHeader.clear();
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Database::indexFile(const QFileInfo &file)
|
||||||
|
{
|
||||||
|
ImageInfoData info;
|
||||||
|
QString filePath = file.absoluteFilePath();
|
||||||
|
QString mtime = file.fileTime(QFileDevice::FileModificationTime).toUTC().toString(Qt::ISODate);
|
||||||
|
m_checkFile.bindValue(0, filePath);
|
||||||
|
m_checkFile.exec();
|
||||||
|
if(m_checkFile.next())
|
||||||
|
{
|
||||||
|
if(m_checkFile.value(1).toString() == mtime)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_deleteFile.bindValue(0, m_checkFile.value(0).toLongLong());
|
||||||
|
m_deleteFile.exec();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ok;
|
||||||
|
if(filePath.endsWith(".xisf", Qt::CaseInsensitive))
|
||||||
|
ok = readXISFHeader(filePath, info);
|
||||||
|
else
|
||||||
|
ok = readFITSHeader(filePath, info);
|
||||||
|
|
||||||
|
qlonglong last_id = -1;
|
||||||
|
if(ok)
|
||||||
|
{
|
||||||
|
m_insertFile.bindValue(0, filePath);
|
||||||
|
m_insertFile.bindValue(1, mtime);
|
||||||
|
if(!m_insertFile.exec())
|
||||||
|
{
|
||||||
|
qDebug() << m_insertFile.lastError();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
last_id = m_insertFile.lastInsertId().toLongLong();
|
||||||
|
QVariantList file_id, keys, values, comments;
|
||||||
|
for(auto &record : info.fitsHeader)
|
||||||
|
{
|
||||||
|
file_id << last_id;
|
||||||
|
keys << QString(record.key);
|
||||||
|
values << record.value.toString();
|
||||||
|
comments << QString(record.comment);
|
||||||
|
}
|
||||||
|
m_insertFitsHeader.bindValue(0, file_id);
|
||||||
|
m_insertFitsHeader.bindValue(1, keys);
|
||||||
|
m_insertFitsHeader.bindValue(2, values);
|
||||||
|
m_insertFitsHeader.bindValue(3, comments);
|
||||||
|
if(!m_insertFitsHeader.execBatch())
|
||||||
|
{
|
||||||
|
qDebug() << m_insertFitsHeader.lastError();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
qDebug() << filePath << last_id;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
@@ -31,9 +31,11 @@ public:
|
|||||||
void clearMarkedFiles();
|
void clearMarkedFiles();
|
||||||
|
|
||||||
void indexDir(const QDir &dir, QProgressDialog *progress);
|
void indexDir(const QDir &dir, QProgressDialog *progress);
|
||||||
|
void reindex(QProgressDialog *progress);
|
||||||
QStringList getFitsKeywords();
|
QStringList getFitsKeywords();
|
||||||
protected:
|
protected:
|
||||||
bool indexDir2(const QDir &dir, QProgressDialog *progress);
|
bool indexDir2(const QDir &dir, QProgressDialog *progress);
|
||||||
|
bool indexFile(const QFileInfo &file);
|
||||||
bool checkError(QSqlQuery &query);
|
bool checkError(QSqlQuery &query);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
|
|||||||
fileMenu->addAction(tr("Move marked files"), this, SLOT(moveMarked()));
|
fileMenu->addAction(tr("Move marked files"), this, SLOT(moveMarked()));
|
||||||
fileMenu->addAction(tr("Save as"), this, SLOT(saveAs()), QKeySequence("Ctrl+S"));
|
fileMenu->addAction(tr("Save as"), this, SLOT(saveAs()), QKeySequence("Ctrl+S"));
|
||||||
fileMenu->addAction(tr("Index directory"), this, SLOT(indexDir()));
|
fileMenu->addAction(tr("Index directory"), this, SLOT(indexDir()));
|
||||||
|
fileMenu->addAction(tr("Reindex files"), this, SLOT(reindex()));
|
||||||
QAction *liveModeAction = fileMenu->addAction(tr("Live mode"), this, SLOT(liveMode(bool)));
|
QAction *liveModeAction = fileMenu->addAction(tr("Live mode"), this, SLOT(liveMode(bool)));
|
||||||
liveModeAction->setCheckable(true);
|
liveModeAction->setCheckable(true);
|
||||||
fileMenu->addAction(tr("Exit"), this, SLOT(close()));
|
fileMenu->addAction(tr("Exit"), this, SLOT(close()));
|
||||||
@@ -358,6 +359,13 @@ void MainWindow::indexDir()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::reindex()
|
||||||
|
{
|
||||||
|
QProgressDialog progressDialog(tr("Indexing FITS files"), tr("Cancel"), 0, 1, this);
|
||||||
|
progressDialog.setModal(true);
|
||||||
|
m_database->reindex(&progressDialog);
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::saveAs()
|
void MainWindow::saveAs()
|
||||||
{
|
{
|
||||||
QString selectedFilter;
|
QString selectedFilter;
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ protected slots:
|
|||||||
void loadFile(const QString &path);
|
void loadFile(const QString &path);
|
||||||
void loadFile(int row);
|
void loadFile(int row);
|
||||||
void indexDir();
|
void indexDir();
|
||||||
|
void reindex();
|
||||||
void saveAs();
|
void saveAs();
|
||||||
void convert(const QString &outfile);
|
void convert(const QString &outfile);
|
||||||
void markImage();
|
void markImage();
|
||||||
|
|||||||
Reference in New Issue
Block a user