From 1683c8a090c3efc51c43107d5ede0dcd5d506e3b Mon Sep 17 00:00:00 2001
From: Ferenc Szontágh <szf@fsociety.hu>
Date: Sun, 04 Feb 2024 20:45:08 +0000
Subject: [PATCH] added better queue manager, some clean-up and new feature: model management (wip), progressbar

---
 ui/QueueManager.h |   37 +++++++++++++++++++++++++------------
 1 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/ui/QueueManager.h b/ui/QueueManager.h
index baaf7fb..f0fe264 100644
--- a/ui/QueueManager.h
+++ b/ui/QueueManager.h
@@ -1,6 +1,7 @@
 #ifndef __SD_GUI_QUEUE_MANAGER
 #define __SD_GUI_QUEUE_MANAGER
 
+#include <fstream>
 #include <map>
 #include <chrono>
 #include <nlohmann/json.hpp>
@@ -27,8 +28,7 @@
         "paused",
         "failed",
         "model loading...",
-        "finished"
-        };
+        "finished"};
 
     enum QueueEvents
     {
@@ -44,7 +44,7 @@
         QueueItem() = default;
         QueueItem(const QueueItem &other)
             : id(other.id), created_at(other.created_at), updated_at(other.updated_at),
-              finished_at(other.finished_at), params(other.params), status(other.status), images(other.images) {}
+              finished_at(other.finished_at), params(other.params), status(other.status), images(other.images), step(other.step), steps(other.steps), time(other.time), model(other.model) {}
 
         QueueItem &operator=(const QueueItem &other)
         {
@@ -55,18 +55,22 @@
                 updated_at = other.updated_at;
                 finished_at = other.finished_at;
                 images = other.images;
-                // Másolatot készítünk a params referenciáról
-                // Ha a params referenciához tartozó SDParams objektum módosulna,
-                // akkor ebben az esetben másolatban marad az eredeti QueueItem-ben
                 params = other.params;
                 status = other.status;
+                step = other.step;
+                steps = other.steps;
+                time = other.time;
+                model = other.model;
             }
             return *this;
         }
-        int id, created_at = 0, updated_at = 0, finished_at = 0;
+        int id = 0, created_at = 0, updated_at = 0, finished_at = 0;
+        int step = 0, steps = 0;
+        float time = 0;
         sd_gui_utils::SDParams params;
         QM::QueueStatus status = QM::QueueStatus::PENDING;
         std::vector<std::string> images;
+        std::string model;
     };
 
     inline void to_json(nlohmann::json &j, const QueueItem &p)
@@ -77,8 +81,11 @@
             {"updated_at", p.updated_at},
             {"finished_at", p.finished_at},
             {"images", p.images},
-            //   {"params", p.params},
-            {"status", (int)p.status}};
+            {"status", (int)p.status},
+            {"model", p.model},
+            {"params", p.params},
+
+        };
     }
 
     inline void from_json(const nlohmann::json &j, QueueItem &p)
@@ -88,7 +95,8 @@
         j.at("updated_at").get_to(p.updated_at);
         j.at("images").get_to(p.images);
         j.at("finished_at").get_to(p.finished_at);
-        //  j.at("params").get_to(p.params);
+        j.at("model").get_to(p.model);
+        j.at("params").get_to(p.params);
         p.status = j.at("status").get<QM::QueueStatus>();
     }
 
@@ -96,6 +104,7 @@
     {
     public:
         QueueManager(wxEvtHandler *eventHandler, std::string jobsdir);
+        ~QueueManager();
         int AddItem(QM::QueueItem item);
         int AddItem(sd_gui_utils::SDParams *params);
         int AddItem(sd_gui_utils::SDParams params);
@@ -108,14 +117,18 @@
         void PauseAll();
         void SendEventToMainWindow(QM::QueueEvents eventType, QM::QueueItem item = QM::QueueItem());
         void OnThreadMessage(wxThreadEvent &e);
+        void SaveJobToFile(int id);
+        void SaveJobToFile(QM::QueueItem item);
 
     private:
         int GetCurrentUnixTimestamp();
+        void LoadJobListFromDir();
         std::string jobsDir;
+        int lastId = 0;
+        int GetAnId();
         // thread events handler, toupdate main window data table
         void onItemAdded(QM::QueueItem item);
-        void LodJobsFromFile();
-        void SaveJobsToFile();
+
         // @brief check if something is running or not
         bool isRunning = false;
 

--
Gitblit v1.9.3