MainWindow.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. #include <gtkmm.h>
  3. #include <string>
  4. #include <fstream>
  5. #include <thread>
  6. #include <mutex>
  7. #include <queue>
  8. #include <atomic>
  9. struct JobConfig {
  10. bool themes;
  11. bool icons;
  12. bool wallpapers;
  13. bool extensions;
  14. bool dconf;
  15. bool dry_run;
  16. };
  17. class MainWindow : public Gtk::Window {
  18. public:
  19. MainWindow();
  20. virtual ~MainWindow();
  21. private:
  22. // Core Layout
  23. Gtk::HeaderBar m_HeaderBar;
  24. Gtk::Box m_MainLayout;
  25. Gtk::Notebook m_Notebook;
  26. // Logging UI
  27. Gtk::ScrolledWindow m_ScrolledWindow;
  28. Gtk::TextView m_LogView;
  29. Glib::RefPtr<Gtk::TextBuffer> m_RefTextBuffer;
  30. Gtk::Label m_StatusLabel;
  31. // --- Backup Page Elements ---
  32. Gtk::Box m_VBoxBackup;
  33. Gtk::Label m_LabelBackupInstruction;
  34. Gtk::CheckButton m_CheckThemesBackup;
  35. Gtk::CheckButton m_CheckIconsBackup;
  36. Gtk::CheckButton m_CheckWallpapersBackup;
  37. Gtk::CheckButton m_CheckExtensionsBackup;
  38. Gtk::CheckButton m_CheckDconfBackup;
  39. Gtk::Button m_ButtonBackup;
  40. // --- Restore Page Elements ---
  41. Gtk::Box m_VBoxRestore;
  42. Gtk::Label m_LabelRestoreInstruction;
  43. Gtk::CheckButton m_CheckThemesRestore;
  44. Gtk::CheckButton m_CheckIconsRestore;
  45. Gtk::CheckButton m_CheckWallpapersRestore;
  46. Gtk::CheckButton m_CheckExtensionsRestore;
  47. Gtk::CheckButton m_CheckDconfRestore;
  48. Gtk::CheckButton m_CheckDryRunRestore;
  49. Gtk::Button m_ButtonRestore;
  50. // --- Threading & Concurrency ---
  51. Glib::Dispatcher m_Dispatcher;
  52. std::mutex m_LogMutex;
  53. std::queue<std::string> m_LogQueue;
  54. std::atomic<bool> m_WorkerRunning;
  55. std::ofstream m_LogFile;
  56. // --- Signal Handlers and Logic ---
  57. void on_button_backup_clicked();
  58. void on_button_restore_clicked();
  59. // --- UI Thread Functions ---
  60. void on_dispatcher_ping();
  61. void add_log_ui(const std::string& message);
  62. void set_ui_locked(bool locked);
  63. // --- Worker Thread Functions ---
  64. void queue_log(const std::string& message);
  65. void run_backup_job(JobConfig config, std::string home_dir, std::string wallpaper_dir);
  66. void run_restore_job(JobConfig config, std::string home_dir);
  67. bool create_tar_archive(const std::string& source_dir, const std::string& out_filename);
  68. bool extract_tar_archive(const std::string& archive_path, bool dry_run);
  69. std::string get_wallpaper_directory();
  70. };