diff --git a/.github/workflows/codacy.yml b/.github/workflows/codacy.yml index 0b061851..0730af9b 100644 --- a/.github/workflows/codacy.yml +++ b/.github/workflows/codacy.yml @@ -53,13 +53,17 @@ jobs: # This will handover control about PR rejection to the GitHub side max-allowed-issues: 2147483647 - - name: Filter out MISRA + # Filter out MISRA and potentially reduce the number of runs in the SARIF output + - name: Filter and Reduce SARIF run: | pip install globber - python3 scripts/filter_sarif.py --input results.sarif --output filtered.sarif --split-lines -- "-**/*.*:cppcheck_misra*" + python3 scripts/filter_and_reduce_sarif.py --input results.sarif --output filtered_and_reduced.sarif + env: + PYTHONUNBUFFERED: 1 - # Upload the SARIF file generated in the previous step + + # Upload the SARIF file generated in the previous step - name: Upload SARIF results file uses: github/codeql-action/upload-sarif@v3 with: - sarif_file: filtered.sarif + sarif_file: filtered_and_reduced.sarif \ No newline at end of file diff --git a/avogadro/mainwindow.cpp b/avogadro/mainwindow.cpp index 4118820d..c019f0fc 100644 --- a/avogadro/mainwindow.cpp +++ b/avogadro/mainwindow.cpp @@ -1979,6 +1979,46 @@ void MainWindow::buildMenu() m_menuBuilder->addAction(path, action, 960); m_fileToolBar->addAction(action); connect(action, SIGNAL(triggered()), SLOT(saveFileAs())); + // Initialize autosave feature + m_autosaveInterval = 5; // Autosave interval in minutes + m_autosaveTimer = new QTimer(this); + connect(m_autosaveTimer, &QTimer::timeout, this, + &MainWindow::autosaveDocument); + m_autosaveTimer->start(m_autosaveInterval * + 60000); // Convert minutes to milliseconds + + void MainWindow::autosaveDocument() + { + if (!m_molecule || !m_moleculeDirty) { + return; // No molecule loaded or no changes made since the last save. + } + + QString autosaveDirPath = + QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + + "/autosave"; + QDir autosaveDir(autosaveDirPath); + if (!autosaveDir.exists()) { + autosaveDir.mkpath("."); + } + + // Construct autosave file name + QString autosaveFilename; + if (m_molecule->hasData("fileName")) { + QFileInfo fileInfo(m_molecule->data("fileName").toString().c_str()); + autosaveFilename = fileInfo.baseName() + "_autosave.cjson"; + } else { + autosaveFilename = "unsaved_autosave.cjson"; + } + QString autosaveFilePath = autosaveDirPath + "/" + autosaveFilename; + + // Use CJSON format for autosaving + Io::CjsonFormat writer; + if (!writer.writeFile(autosaveFilePath, *m_molecule)) { + qWarning() << "Failed to autosave the document to" << autosaveFilePath; + } else { + qDebug() << "Document autosaved to" << autosaveFilePath; + } + } // Export action for menu QStringList exportPath = path; @@ -2635,4 +2675,4 @@ bool MainWindow::handleCommand(const QString& command, return false; } -} // End of Avogadro namespace +} // End of Avogadro namespace \ No newline at end of file diff --git a/avogadro/mainwindow.h b/avogadro/mainwindow.h index 3dadf613..a33b06ae 100644 --- a/avogadro/mainwindow.h +++ b/avogadro/mainwindow.h @@ -69,7 +69,7 @@ class MainWindow : public QMainWindow public slots: void setMolecule(Avogadro::QtGui::Molecule* molecule); - + void autosaveDocument(); // line to declare the autosave slot /** * Update internal state to reflect that the molecule has been modified. */ @@ -398,7 +398,8 @@ private slots: QtGui::ScenePlugin* m_activeScenePlugin; bool m_queuedFilesStarted; QStringList m_queuedFiles; - + QTimer* m_autosaveTimer; // for the autosave timer + int m_autosaveInterval; // for autosave interval in minutes QStringList m_recentFiles; QList m_actionRecentFiles; @@ -502,4 +503,4 @@ private slots: } // End Avogadro namespace -#endif +#endif \ No newline at end of file