Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option or change Avatar storage to .cache permanently #1615

Open
Earthw0rmJ1m opened this issue Aug 28, 2024 · 0 comments
Open

Add option or change Avatar storage to .cache permanently #1615

Earthw0rmJ1m opened this issue Aug 28, 2024 · 0 comments

Comments

@Earthw0rmJ1m
Copy link

Either change the avatar storage permantly to .cache or add option in GUI for user to do so.
Reasoning for privacy or distro specific like using Dino on TailsOS. Or for users that have .cache mounted to tmpfs. Most XMPP client aplications stores avatars in .cache.

Step 1: Modify avatar_manager.vala

public class AvatarManager {
    private string avatar_directory;

    public AvatarManager() {
        // Change the path to store avatars in .cache instead of .local/share
        avatar_directory = GLib.get_home_dir() + "/.cache/dino/avatars";
        // Ensure the directory exists
        GLib.file_test(avatar_directory, GLib.FileTest.IS_DIR) || GLib.mkdir(avatar_directory, 0755);
    }

    public void save_avatar(string user_id, Image avatar) {
        string avatar_path = avatar_directory + "/" + user_id + ".png";
        // Save the avatar image to the new path
        avatar.save(avatar_path);
    }

    public Image load_avatar(string user_id) {
        string avatar_path = avatar_directory + "/" + user_id + ".png";
        // Load the avatar image from the new path
        return Image.load(avatar_path);
    }
}

Step 2: Update GUI Options settings.vala

public class SettingsWindow : Gtk.Window {
    private Gtk.CheckButton cache_option;
    private bool use_cache;

    public SettingsWindow() {
        // Initialize the settings window
        this.title = "Settings";
        this.set_default_size(400, 300);
        
        // Create a vertical box to hold the settings
        var vbox = new Gtk.Box(Gtk.Orientation.VERTICAL, 10);
        this.add(vbox);

        // Create a checkbox for the cache option
        cache_option = new Gtk.CheckButton.with_label("Store avatars in .cache");
        
        // Load the current setting (default to false if not set)
        use_cache = load_use_cache_setting();
        cache_option.set_active(use_cache);

        // Connect the toggle signal to update the storage path
        cache_option.signal_toggled().connect(() => {
            use_cache = cache_option.get_active();
            update_avatar_storage_path(use_cache);
            save_use_cache_setting(use_cache);
        });

        // Add the checkbox to the settings window
        vbox.append(cache_option);

        // Add a button to close the settings window
        var close_button = new Gtk.Button.with_label("Close");
        close_button.signal_clicked().connect(() => {
            this.close();
        });
        vbox.append(close_button);
    }

    private bool load_use_cache_setting() {
        // Load the setting from a configuration file or use a default value
        // This is a placeholder; implement actual loading logic
        return false; // Default to false (not using cache)
    }

    private void save_use_cache_setting(bool use_cache) {
        // Save the setting to a configuration file
        // This is a placeholder; implement actual saving logic
    }

    private void update_avatar_storage_path(bool use_cache) {
        if (use_cache) {
            AvatarManager.set_storage_path(GLib.get_home_dir() + "/.cache/dino/avatars");
        } else {
            AvatarManager.set_storage_path(GLib.get_home_dir() + "/.local/share/dino/avatars");
        }
    }
}

(or like this):

public class SettingsWindow : Gtk.Window {
    private Gtk.CheckButton cache_option;

    public SettingsWindow() {
        // Create a checkbox for the cache option
        cache_option = new Gtk.CheckButton.with_label("Store avatars in .cache");
        cache_option.set_active(true); // Default to true

        // Connect the toggle signal to update the storage path
        cache_option.signal_toggled().connect(() => {
            if (cache_option.get_active()) {
                // Update the avatar manager to use .cache
                AvatarManager.set_storage_path(GLib.get_home_dir() + "/.cache/dino/avatars");
            } else {
                // Revert to the default path
                AvatarManager.set_storage_path(GLib.get_home_dir() + "/.local/share/dino/avatars");
            }
        });

        // Add the checkbox to the settings window
        this.add(cache_option);
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant