浏览代码

initial commit

Nicole Portas 2 周之前
父节点
当前提交
6ed3b5deee
共有 5 个文件被更改,包括 283 次插入0 次删除
  1. 166 0
      MainWindow.cpp
  2. 37 0
      MainWindow.hpp
  3. 19 0
      Makefile
  4. 52 0
      configure
  5. 9 0
      main.cpp

+ 166 - 0
MainWindow.cpp

@@ -0,0 +1,166 @@
+#include "MainWindow.hpp"
+#include <iostream>
+#include <filesystem>
+#include <archive.h>
+#include <archive_entry.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <cstdlib>
+
+namespace fs = std::filesystem;
+
+MainWindow::MainWindow()
+: m_MainLayout(Gtk::ORIENTATION_VERTICAL, 0),
+  m_VBoxBackup(Gtk::ORIENTATION_VERTICAL, 15),
+  m_LabelBackupInstruction("<span size='large' weight='bold'>Select what to backup:</span>"),
+  m_CheckThemesBackup("GTK Themes (~/.themes)"),
+  m_CheckIconsBackup("Icons (~/.icons)"),
+  m_CheckDconfBackup("GNOME Settings (dconf dump)"),
+  m_ButtonBackup("Start Backup"),
+  m_VBoxRestore(Gtk::ORIENTATION_VERTICAL, 15),
+  m_LabelRestoreInstruction("<span size='large' weight='bold'>Select what to restore:</span>"),
+  m_CheckThemesRestore("GTK Themes"),
+  m_CheckIconsRestore("Icons"),
+  m_CheckDconfRestore("GNOME Settings"),
+  m_ButtonRestore("Start Restore")
+{
+    // --- Force Dark Theme ---
+    auto settings = Gtk::Settings::get_default();
+    if (settings) {
+        settings->property_gtk_application_prefer_dark_theme() = true;
+    }
+
+    set_default_size(550, 450);
+    set_border_width(0); // Removing window border to let layout handle it
+
+    // --- HeaderBar Setup (Modern GNOME look) ---
+    m_HeaderBar.set_title("Gnome-Vault");
+    m_HeaderBar.set_subtitle("System State Manager");
+    m_HeaderBar.set_show_close_button(true);
+    set_titlebar(m_HeaderBar);
+
+    // Allow markup in the instruction labels
+    m_LabelBackupInstruction.set_use_markup(true);
+    m_LabelBackupInstruction.set_halign(Gtk::ALIGN_START);
+    m_LabelRestoreInstruction.set_use_markup(true);
+    m_LabelRestoreInstruction.set_halign(Gtk::ALIGN_START);
+
+    // --- Backup Page Setup ---
+    m_VBoxBackup.set_border_width(20);
+    m_VBoxBackup.pack_start(m_LabelBackupInstruction, Gtk::PACK_SHRINK);
+    m_VBoxBackup.pack_start(m_CheckThemesBackup, Gtk::PACK_SHRINK);
+    m_VBoxBackup.pack_start(m_CheckIconsBackup, Gtk::PACK_SHRINK);
+    m_VBoxBackup.pack_start(m_CheckDconfBackup, Gtk::PACK_SHRINK);
+    
+    m_CheckThemesBackup.set_active(true);
+
+    // Make the button chunkier
+    m_ButtonBackup.set_size_request(-1, 45);
+    m_ButtonBackup.signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::on_button_backup_clicked));
+    m_VBoxBackup.pack_end(m_ButtonBackup, Gtk::PACK_SHRINK);
+
+    // --- Restore Page Setup ---
+    m_VBoxRestore.set_border_width(20);
+    m_VBoxRestore.pack_start(m_LabelRestoreInstruction, Gtk::PACK_SHRINK);
+    m_VBoxRestore.pack_start(m_CheckThemesRestore, Gtk::PACK_SHRINK);
+    m_VBoxRestore.pack_start(m_CheckIconsRestore, Gtk::PACK_SHRINK);
+    m_VBoxRestore.pack_start(m_CheckDconfRestore, Gtk::PACK_SHRINK);
+
+    m_ButtonRestore.set_size_request(-1, 45);
+    m_ButtonRestore.signal_clicked().connect(sigc::mem_fun(*this, &MainWindow::on_button_restore_clicked));
+    m_VBoxRestore.pack_end(m_ButtonRestore, Gtk::PACK_SHRINK);
+
+    // --- Notebook (Tabs) Setup ---
+    m_Notebook.append_page(m_VBoxBackup, "Backup");
+    m_Notebook.append_page(m_VBoxRestore, "Restore");
+
+    // --- Status Label Setup ---
+    m_StatusLabel.set_text("Ready.");
+    m_StatusLabel.set_halign(Gtk::ALIGN_START);
+    m_StatusLabel.set_margin_top(10);
+    m_StatusLabel.set_margin_bottom(10);
+    m_StatusLabel.set_margin_start(10);
+
+    // --- Main Layout Assembly ---
+    m_MainLayout.pack_start(m_Notebook, Gtk::PACK_EXPAND_WIDGET);
+    m_MainLayout.pack_end(m_StatusLabel, Gtk::PACK_SHRINK);
+
+    add(m_MainLayout);
+    show_all_children();
+}
+
+MainWindow::~MainWindow() {}
+
+bool MainWindow::create_tar_archive(const std::string& source_dir, const std::string& out_filename) {
+    struct archive *a;
+    struct archive *disk;
+    struct archive_entry *entry;
+    char buff[8192];
+    int len;
+    int fd;
+
+    a = archive_write_new();
+    archive_write_add_filter_gzip(a);
+    archive_write_set_format_pax_restricted(a);
+    archive_write_open_filename(a, out_filename.c_str());
+
+    disk = archive_read_disk_new();
+    archive_read_disk_set_standard_lookup(disk);
+
+    for (const auto& dirEntry : fs::recursive_directory_iterator(source_dir)) {
+        std::string path = dirEntry.path().string();
+        entry = archive_entry_new();
+        archive_entry_copy_pathname(entry, path.c_str());
+        archive_read_disk_entry_from_file(disk, entry, -1, nullptr);
+        archive_write_header(a, entry);
+
+        if (fs::is_regular_file(dirEntry)) {
+            fd = ::open(path.c_str(), O_RDONLY);
+            if (fd >= 0) {
+                len = ::read(fd, buff, sizeof(buff));
+                while (len > 0) {
+                    archive_write_data(a, buff, len);
+                    len = ::read(fd, buff, sizeof(buff));
+                }
+                ::close(fd);
+            }
+        }
+        archive_entry_free(entry);
+    }
+    archive_read_free(disk);
+    archive_write_close(a);
+    archive_write_free(a);
+    return true;
+}
+
+void MainWindow::on_button_backup_clicked() {
+    m_StatusLabel.set_text("Initializing Backup Sequence...");
+    // Keep the cout for the terminal debugger
+    std::cout << ">>> Initializing Backup Sequence..." << std::endl; 
+    
+    std::string home_dir = getenv("HOME");
+    
+    if (m_CheckThemesBackup.get_active()) {
+        std::string target = home_dir + "/.themes";
+        std::string out = home_dir + "/gnome_themes_backup.tar.gz";
+        
+        if (fs::exists(target)) {
+            m_StatusLabel.set_text("Packing Themes into archive...");
+            create_tar_archive(target, out);
+            m_StatusLabel.set_text("Success: Packed ~/.themes into gnome_themes_backup.tar.gz");
+        } else {
+            m_StatusLabel.set_text("Warning: ~/.themes doesn't exist. Skipped.");
+        }
+    }
+    
+    if (m_CheckIconsBackup.get_active()) std::cout << " [x] Queuing Icons (TODO)..." << std::endl;
+    if (m_CheckDconfBackup.get_active()) std::cout << " [x] Queuing Dconf (TODO)..." << std::endl;
+}
+
+void MainWindow::on_button_restore_clicked() {
+    m_StatusLabel.set_text("Initializing Restore Sequence...");
+    std::cout << ">>> Initializing Restore Sequence..." << std::endl;
+    if (m_CheckThemesRestore.get_active()) std::cout << " [x] Preparing to overwrite Themes..." << std::endl;
+    if (m_CheckIconsRestore.get_active()) std::cout << " [x] Preparing to overwrite Icons..." << std::endl;
+    if (m_CheckDconfRestore.get_active()) std::cout << " [x] Preparing to inject Dconf..." << std::endl;
+}

+ 37 - 0
MainWindow.hpp

@@ -0,0 +1,37 @@
+#pragma once
+#include <gtkmm.h>
+#include <string>
+
+class MainWindow : public Gtk::Window {
+public:
+    MainWindow();
+    virtual ~MainWindow();
+
+private:
+    // Core Layout
+    Gtk::HeaderBar m_HeaderBar;
+    Gtk::Box m_MainLayout;
+    Gtk::Notebook m_Notebook;
+    Gtk::Label m_StatusLabel;
+
+    // --- Backup Page Elements ---
+    Gtk::Box m_VBoxBackup;
+    Gtk::Label m_LabelBackupInstruction;
+    Gtk::CheckButton m_CheckThemesBackup;
+    Gtk::CheckButton m_CheckIconsBackup;
+    Gtk::CheckButton m_CheckDconfBackup;
+    Gtk::Button m_ButtonBackup;
+
+    // --- Restore Page Elements ---
+    Gtk::Box m_VBoxRestore;
+    Gtk::Label m_LabelRestoreInstruction;
+    Gtk::CheckButton m_CheckThemesRestore;
+    Gtk::CheckButton m_CheckIconsRestore;
+    Gtk::CheckButton m_CheckDconfRestore;
+    Gtk::Button m_ButtonRestore;
+
+    // --- Signal Handlers and Logic ---
+    void on_button_backup_clicked();
+    void on_button_restore_clicked();
+    bool create_tar_archive(const std::string& source_dir, const std::string& out_filename);
+};

+ 19 - 0
Makefile

@@ -0,0 +1,19 @@
+# Auto-generated Makefile
+CXX = g++
+CXXFLAGS = -std=c++17 -Wall -I/usr/include/gtkmm-3.0 -I/usr/lib/x86_64-linux-gnu/gtkmm-3.0/include -I/usr/include/giomm-2.4 -I/usr/lib/x86_64-linux-gnu/giomm-2.4/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glibmm-2.4 -I/usr/lib/x86_64-linux-gnu/glibmm-2.4/include -I/usr/include/sigc++-2.0 -I/usr/lib/x86_64-linux-gnu/sigc++-2.0/include -I/usr/include/gtk-3.0 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/fribidi -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/x86_64-linux-gnu -I/usr/include/gio-unix-2.0 -I/usr/include/atk-1.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/cairomm-1.0 -I/usr/lib/x86_64-linux-gnu/cairomm-1.0/include -I/usr/include/pangomm-1.4 -I/usr/lib/x86_64-linux-gnu/pangomm-1.4/include -I/usr/include/atkmm-1.6 -I/usr/lib/x86_64-linux-gnu/atkmm-1.6/include -I/usr/include/gtk-3.0/unix-print -I/usr/include/gdkmm-3.0 -I/usr/lib/x86_64-linux-gnu/gdkmm-3.0/include -pthread  
+LDFLAGS = -lgtkmm-3.0 -latkmm-1.6 -lgdkmm-3.0 -lgiomm-2.4 -lgtk-3 -lgdk-3 -lz -latk-1.0 -lcairo-gobject -lgio-2.0 -lpangomm-1.4 -lglibmm-2.4 -lcairomm-1.0 -lsigc-2.0 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -lcairo -lgdk_pixbuf-2.0 -lgobject-2.0 -lglib-2.0  -larchive 
+
+SOURCES = main.cpp MainWindow.cpp
+OBJECTS = $(SOURCES:.cpp=.o)
+EXECUTABLE = gnome-vault
+
+all: $(EXECUTABLE)
+
+$(EXECUTABLE): $(OBJECTS)
+	$(CXX) $(OBJECTS) -o $@ $(LDFLAGS)
+
+%.o: %.cpp
+	$(CXX) $(CXXFLAGS) -c $< -o $@
+
+clean:
+	rm -f $(OBJECTS) $(EXECUTABLE)

+ 52 - 0
configure

@@ -0,0 +1,52 @@
+#!/bin/bash
+# A bloody simple, hand-rolled configure script
+
+echo "Checking for pkg-config..."
+if ! command -v pkg-config &> /dev/null; then
+    echo "Error: pkg-config is not installed. Fucking install it first."
+    exit 1
+fi
+
+echo "Checking for gtkmm-3.0..."
+if ! pkg-config --exists gtkmm-3.0; then
+    echo "Error: gtkmm-3.0 not found. Install libgtkmm-3.0-dev."
+    exit 1
+fi
+
+echo "Checking for libarchive..."
+if ! pkg-config --exists libarchive; then
+    echo "Error: libarchive not found. Install libarchive-dev."
+    exit 1
+fi
+
+# Grab the flags
+GTKMM_CFLAGS=$(pkg-config --cflags gtkmm-3.0)
+GTKMM_LIBS=$(pkg-config --libs gtkmm-3.0)
+ARCHIVE_CFLAGS=$(pkg-config --cflags libarchive)
+ARCHIVE_LIBS=$(pkg-config --libs libarchive)
+
+echo "Writing Makefile..."
+
+cat <<EOF > Makefile
+# Auto-generated Makefile
+CXX = g++
+CXXFLAGS = -std=c++17 -Wall $GTKMM_CFLAGS $ARCHIVE_CFLAGS
+LDFLAGS = $GTKMM_LIBS $ARCHIVE_LIBS
+
+SOURCES = main.cpp MainWindow.cpp
+OBJECTS = \$(SOURCES:.cpp=.o)
+EXECUTABLE = gnome-vault
+
+all: \$(EXECUTABLE)
+
+\$(EXECUTABLE): \$(OBJECTS)
+	\$(CXX) \$(OBJECTS) -o \$@ \$(LDFLAGS)
+
+%.o: %.cpp
+	\$(CXX) \$(CXXFLAGS) -c \$< -o \$@
+
+clean:
+	rm -f \$(OBJECTS) \$(EXECUTABLE)
+EOF
+
+echo "Fucking done. You can now run 'make'."

+ 9 - 0
main.cpp

@@ -0,0 +1,9 @@
+#include "MainWindow.hpp"
+#include <gtkmm/application.h>
+
+int main(int argc, char *argv[]) {
+    // org.gnome.vault is our application ID
+    auto app = Gtk::Application::create(argc, argv, "org.gnome.vault");
+    MainWindow window;
+    return app->run(window);
+}