#!/usr/bin/env python3
"""
Adwaita Lite Settings - GUI Control Panel
Simple settings for normal users - NO command line needed!
"""

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk
import subprocess
import os

class LiteSettings(Gtk.Window):
    def __init__(self):
        super().__init__(title="Adwaita Lite Settings")
        self.set_default_size(600, 500)
        self.set_position(Gtk.WindowPosition.CENTER)
        
        # Header bar
        hb = Gtk.HeaderBar()
        hb.set_title("Adwaita Lite Settings")
        hb.set_subtitle("Optimize your computer")
        self.set_titlebar(hb)
        
        # Main box
        box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=10)
        box.set_property("margin", 20)
        self.add(box)
        
        # Notebook with tabs
        notebook = Gtk.Notebook()
        box.pack_start(notebook, True, True, 0)
        
        # === TAB 1: Services ===
        page1 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=15)
        page1.set_property("margin", 15)
        
        lbl = Gtk.Label()
        lbl.set_markup("<b>Enable/Disable Features</b>\n\n"
                      "Turn on features you need:")
        lbl.set_alignment(0, 0)
        page1.pack_start(lbl, False, False, 0)
        
        # Service toggles
        self.toggles = {}
        
        services = [
            (" Printing (CUPS)", "cups", "🖨️"),
            (" Bluetooth", "bluetooth", "📶"),
            (" Scanner (SANE)", "sane", "📷"),
            (" Mobile Data (Modem)", "ModemManager", "📱"),
            (" Cloud Storage (Dropbox/etc)", "dropbox", "☁️"),
            (" Virtualization (Docker/LXC)", "docker", "📦"),
        ]
        
        for label, pkg, icon in services:
            row = Gtk.Box(spacing=10)
            
            sw = Gtk.Switch()
            sw.connect("notify::active", self.toggle_service, pkg)
            self.toggles[pkg] = sw
            
            ico = Gtk.Label(icon)
            ico.set_size_request(30, -1)
            
            l = Gtk.Label(label)
            l.set_alignment(0, 0.5)
            
            row.pack_start(ico, False, False, 0)
            row.pack_start(l, True, True, 0)
            row.pack_start(sw, False, False, 0)
            
            page1.pack_start(row, False, False, 0)
        
        notebook.append_page(page1, Gtk.Label("Features"))
        
        # === TAB 2: Performance ===
        page2 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=15)
        page2.set_property("margin", 15)
        
        lbl2 = Gtk.Label()
        lbl2.set_markup("<b>Performance Settings</b>\n\n"
                        "Adjust how fast your computer runs:")
        lbl2.set_alignment(0, 0)
        page2.pack_start(lbl2, False, False, 0)
        
        # Animation toggle
        anim_row = Gtk.Box(spacing=10)
        l_anim = Gtk.Label("Disable animations")
        l_anim.set_alignment(0, 0.5)
        self.sw_anim = Gtk.Switch()
        self.sw_anim.set_active(True)
        self.sw_anim.connect("notify::active", self.set_animation)
        anim_row.pack_start(l_anim, True, True, 0)
        anim_row.pack_start(self.sw_anim, False, False, 0)
        page2.pack_start(anim_row, False, False, 0)
        
        # Desktop icons toggle
        icons_row = Gtk.Box(spacing=10)
        l_icons = Gtk.Label("Show desktop icons")
        l_icons.set_alignment(0, 0.5)
        self.sw_icons = Gtk.Switch()
        self.sw_icons.set_active(False)
        self.sw_icons.connect("notify::active", self.set_desktop_icons)
        icons_row.pack_start(l_icons, True, True, 0)
        icons_row.pack_start(self.sw_icons, False, False, 0)
        page2.pack_start(icons_row, False, False, 0)
        
        # Visual effects toggle
        effects_row = Gtk.Box(spacing=10)
        l_effects = Gtk.Label("Disable visual effects")
        l_effects.set_alignment(0, 0.5)
        self.sw_effects = Gtk.Switch()
        self.sw_effects.set_active(True)
        self.sw_effects.connect("notify::active", self.set_effects)
        effects_row.pack_start(l_effects, True, True, 0)
        effects_row.pack_start(self.sw_effects, False, False, 0)
        page2.pack_start(effects_row, False, False, 0)
        
        notebook.append_page(page2, Gtk.Label("Performance"))
        
        # === TAB 3: Apps ===
        page3 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=15)
        page3.set_property("margin", 15)
        
        lbl3 = Gtk.Label()
        lbl3.set_markup("<b>Install Faster Apps</b>\n\n"
                        "Replace heavy apps with lighter alternatives:")
        lbl3.set_alignment(0, 0)
        page3.pack_start(lbl3, False, False, 0)
        
        apps = [
            ("🌙 Pale Moon - Fast browser", "palemoon"),
            ("📁 Thunar - Fast file manager", "thunar"),
            ("📝 Mousepad - Fast text editor", "mousepad"),
            ("📄 Qpdfview - Fast PDF viewer", "qpdfview"),
            ("⚡ St - Ultra-fast terminal", "st"),
            ("🎵 Audacious - Fast music player", "audacious"),
        ]
        
        for label, pkg in apps:
            btn = Gtk.Button(label=label)
            btn.connect("clicked", self.install_app, pkg)
            page3.pack_start(btn, False, False, 0)
        
        notebook.append_page(page3, Gtk.Label("Apps"))
        
        # === TAB 4: About ===
        page4 = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=15)
        page4.set_property("margin", 15)
        
        about = Gtk.Label()
        about.set_markup("""
<b>Adwaita Lite Settings</b>

Version 1.0

Optimized for older computers with less than 2GB RAM.

Made with ❤️ by the Adwaita Team
https://acreetionos.org

---
Questions? Visit our support page or ask in our community.
        """)
        about.set_alignment(0.5, 0.5)
        page4.pack_start(about, True, True, 0)
        
        notebook.append_page(page4, Gtk.Label("About"))
        
    def toggle_service(self, switch, gparam, pkg):
        if switch.get_active():
            self.show_install_dialog(pkg)
        else:
            self.show_disable_warning(pkg)
    
    def show_install_dialog(self, pkg):
        dlg = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
            Gtk.ButtonsType.OK, f"To install {pkg}:\n\n"
            "1. Click Menu → Software\n"
            f"2. Search for '{pkg}'\n"
            "3. Click Install\n\n"
            f"Or in Terminal: sudo pacman -S {pkg}")
        dlg.run()
        dlg.destroy()
    
    def show_disable_warning(self, pkg):
        dlg = Gtk.MessageDialog(self, 0, Gtk.MessageType.WARNING,
            Gtk.ButtonsType.OK, f"Disabling {pkg} requires terminal.\n\n"
            "For full control, use:\n"
            f"sudo systemctl stop {pkg}\n"
            f"sudo systemctl disable {pkg}")
        dlg.run()
        dlg.destroy()
    
    def set_animation(self, switch, gparam):
        val = "false" if switch.get_active() else "true"
        os.system(f"gsettings set org.cinnamon enable-animations {val}")
    
    def set_desktop_icons(self, switch, gparam):
        val = "true" if switch.get_active() else "false"
        os.system(f"gsettings set org.nemo.desktop show-desktop-icons {val}")
        is_active = "true" if switch.get_active() else "false"
        os.system(f"gsettings set org.nemo.desktop desktop-layout '{is_active}'")
    
    def set_effects(self, switch, gparam):
        val = "false" if switch.get_active() else "true"
        os.system(f"gsettings set org.cinnamon.desktop-effects enabled {val}")
    
    def install_app(self, btn, pkg):
        dlg = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
            Gtk.ButtonsType.OK, f"To install {pkg}:\n\n"
            "1. Click Menu → Software\n"
            f"2. Search for '{pkg}'\n"
            "3. Click Install\n\n"
            f"Or: sudo pacman -S {pkg}")
        dlg.run()
        dlg.destroy()

# End of LiteSettings class
}

def main():
    win = LiteSettings()
    win.run()

if __name__ == "__main__":
    main()
