checkpoint: manage parsing, persistence, mainwindow structure

This commit is contained in:
talksik
2026-02-01 12:40:53 -08:00
parent 55374630b9
commit 0a3b315652
13 changed files with 1075 additions and 6 deletions
+82
View File
@@ -0,0 +1,82 @@
#ifndef SERVICE_H
#define SERVICE_H
#include <QList>
#include <QObject>
#include <QDateTime>
#include <QString>
#include <QFileInfo>
#include <optional>
struct Session
{
enum Result {
UNSPECIFIED = 0,
WIN,
LOSS,
NEUTRAL
};
// Becomes the file name
QString id;
// Stored in the frontmatter under 'Oneliner' key
QString oneliner;
// Stored in the frontmatter
int durationMs;
// After the --- onwards, serves as general scratchpad
QString content;
// Stored in the frontmatter under 'Result' key
Result result;
QDateTime lastModifiedAt;
QDateTime createdAt;
bool isComplete() const;
};
class Service : public QObject {
Q_OBJECT
public:
explicit Service(QObject *parent = nullptr);
~Service();
QList<Session> sessions() const;
QString vaultDirectory() const;
int sessionCount() const;
int completedSessionCount() const;
int totalWins() const;
int totalLosses() const;
int totalNeutrals() const;
public slots:
/// @brief sets the directory from which to read/write sessions
/// Fails silently if not a valid path
/// Loads sessions from this path
void setVaultDirectory(const QString &path);
/// @brief creates the session and stores in sessions list
/// @returns the newly created session
Session createSession(const QString &oneliner, const QString &content);
/// @brief updates the session
/// Updates session in the sessions list, and the file associated
void updateSession(const Session &session);
void deleteSession(const QString &sessionId);
signals:
void sessionsChanged();
private:
QString m_vaultDirectory;
QList<Session> m_sessions;
/// @returns null Session if not a valid session markdown document
std::optional<Session> parseFile(const QFileInfo &fileInfo);
Session::Result parseResult(const QString &resultStr);
void overwriteSessionFile(const Session &session);
};
#endif //SERVICE_H