|
1 | | -import os |
2 | | -import gi |
3 | | -gi.require_version('Gtk', '4.0') |
4 | | -gi.require_version('Adw', '1') |
5 | | -from gi.repository import Gtk, Adw, GdkPixbuf |
6 | | - |
7 | | -def build_ui(window): |
8 | | - # HeaderBar dla profesjonalnego wyglądu |
9 | | - header_bar = Adw.HeaderBar() |
10 | | - header_bar.set_show_end_title_buttons(True) |
11 | | - |
12 | | - # Box dla title widget z logo i tytułem |
13 | | - title_box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=10) |
14 | | - |
15 | | - # Logo (mniejsze dla headera) |
16 | | - logo_path = "/usr/share/HackerOS/ICONS/Plymouth-Icons/watermark.png" |
17 | | - if os.path.exists(logo_path): |
18 | | - pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(logo_path, 32, 32) |
19 | | - logo_image = Gtk.Image.new_from_pixbuf(pixbuf) |
20 | | - else: |
21 | | - logo_image = Gtk.Image() # Puste jeśli nie znaleziono |
22 | | - title_box.append(logo_image) |
23 | | - |
24 | | - # Tytuł (mniejszy font dla headera) |
25 | | - title_label = Gtk.Label(label="Witaj w HackerOS!") |
26 | | - title_label.set_markup("<span font='Arial bold 20'>Witaj w HackerOS!</span>") |
27 | | - title_box.append(title_label) |
28 | | - |
29 | | - header_bar.set_title_widget(title_box) |
30 | | - |
31 | | - # Content box |
32 | | - content_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=15) |
33 | | - content_box.set_margin_top(20) |
34 | | - content_box.set_margin_start(20) |
35 | | - content_box.set_margin_end(20) |
36 | | - content_box.set_margin_bottom(20) |
37 | | - |
38 | | - # Podtytuł (używany też do feedbacku) |
39 | | - window.subtitle_label = Gtk.Label(label="Twój system do Gier i Etycznego Hakowania") |
40 | | - window.subtitle_label.set_markup("<span font='Arial 18'>Twój system do Gier i Etycznego Hakowania</span>") |
41 | | - window.subtitle_label.set_halign(Gtk.Align.CENTER) |
42 | | - window.subtitle_label.get_style_context().add_class("subtitle") |
43 | | - content_box.append(window.subtitle_label) |
44 | | - |
45 | | - # Separator |
46 | | - separator = Gtk.Separator(orientation=Gtk.Orientation.HORIZONTAL) |
47 | | - separator.set_margin_start(10) |
48 | | - separator.set_margin_end(10) |
49 | | - content_box.append(separator) |
50 | | - |
51 | | - # ScrolledWindow dla przycisków, aby było scrollowalne jeśli potrzeba |
52 | | - scrolled_window = Gtk.ScrolledWindow() |
53 | | - scrolled_window.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) |
54 | | - scrolled_window.set_hexpand(True) |
55 | | - scrolled_window.set_vexpand(True) |
56 | | - content_box.append(scrolled_window) |
57 | | - |
58 | | - # Layout przycisków - FlowBox dla dynamicznego układu |
59 | | - flow_box = Gtk.FlowBox() |
60 | | - flow_box.set_column_spacing(15) |
61 | | - flow_box.set_row_spacing(15) |
62 | | - flow_box.set_margin_start(10) |
63 | | - flow_box.set_margin_end(10) |
64 | | - flow_box.set_margin_bottom(20) |
65 | | - flow_box.set_homogeneous(True) |
66 | | - flow_box.set_min_children_per_line(2) |
67 | | - flow_box.set_max_children_per_line(3) |
68 | | - scrolled_window.set_child(flow_box) |
69 | | - |
70 | | - # Pozostałe przyciski (usunięto wskazane) |
71 | | - buttons = [ |
72 | | - ("Otwórz stronę HackerOS", window.actions.open_website), |
73 | | - ("Otwórz X", window.actions.open_x), |
74 | | - ("Otwórz sklep z aplikacjami", window.actions.open_software), |
75 | | - ("Changelog", window.actions.open_changelog), |
76 | | - ("Informacje o systemie", window.actions.open_system_info), |
77 | | - ("Zgłoś błąd", window.actions.report_bug), |
78 | | - ("Forum dyskusyjne", window.actions.open_forum), |
79 | | - ("Zaktualizuj system", window.actions.update_system), |
80 | | - ("Uruchom HackerOS Games", lambda: window.actions.run_command_with_feedback("/usr/share/HackerOS/Scripts/Bin/HackerOS-Games.sh")), |
81 | | - ("Hacker Launcher", lambda: window.actions.run_command_with_feedback("/usr/share/HackerOS/Scripts/HackerOS-Apps/Hacker_Launcher")) |
82 | | - ] |
83 | | - for text, action in buttons: |
84 | | - btn = Gtk.Button(label=text) |
85 | | - btn.connect("clicked", lambda widget, act=action: act()) |
86 | | - flow_box.append(btn) |
87 | | - |
88 | | - # Footer |
89 | | - footer_label = Gtk.Label(label="© 2025 HackerOS Team | All rights reserved") |
90 | | - footer_label.set_halign(Gtk.Align.CENTER) |
91 | | - footer_label.get_style_context().add_class("footer") |
92 | | - content_box.append(footer_label) |
93 | | - |
94 | | - # ToolbarView do integracji headera i contentu |
95 | | - toolbar_view = Adw.ToolbarView() |
96 | | - toolbar_view.add_top_bar(header_bar) |
97 | | - toolbar_view.set_content(content_box) |
98 | | - |
99 | | - # Ustaw content okna |
100 | | - window.set_content(toolbar_view) |
| 1 | +// src/ui.rs |
| 2 | +use adw::prelude::*; |
| 3 | +use adw::{HeaderBar, ToolbarView}; |
| 4 | +use gtk::prelude::*; |
| 5 | +use gtk::{Align, Box as GtkBox, Button, FlowBox, Image, Label, Orientation, PolicyType, ScrolledWindow, Separator}; |
| 6 | +use glib::clone; |
| 7 | +use std::cell::RefCell; |
| 8 | +use std::path::Path; |
| 9 | +use std::rc::Rc; |
| 10 | +use gdk_pixbuf::Pixbuf; |
| 11 | +use crate::actions::Actions; |
| 12 | + |
| 13 | +pub fn build_ui(window: &adw::ApplicationWindow, actions: Rc<RefCell<Actions>>) { |
| 14 | + // HeaderBar |
| 15 | + let header_bar = HeaderBar::builder() |
| 16 | + .show_end_title_buttons(true) |
| 17 | + .build(); |
| 18 | + |
| 19 | + // Title widget with logo and title |
| 20 | + let title_box = GtkBox::builder() |
| 21 | + .orientation(Orientation::Horizontal) |
| 22 | + .spacing(10) |
| 23 | + .build(); |
| 24 | + |
| 25 | + // Logo |
| 26 | + let logo_path = "/usr/share/HackerOS/ICONS/Plymouth-Icons/watermark.png"; |
| 27 | + let logo_image = if Path::new(logo_path).exists() { |
| 28 | + let pixbuf = Pixbuf::from_file_at_scale(logo_path, 32, 32, true).ok(); |
| 29 | + Image::from_pixbuf(pixbuf.as_ref()) |
| 30 | + } else { |
| 31 | + Image::new() |
| 32 | + }; |
| 33 | + title_box.append(&logo_image); |
| 34 | + |
| 35 | + // Title label |
| 36 | + let title_label = Label::builder() |
| 37 | + .label("Witaj w HackerOS!") |
| 38 | + .use_markup(true) |
| 39 | + .build(); |
| 40 | + title_label.set_markup("<span font='Arial bold 20'>Witaj w HackerOS!</span>"); |
| 41 | + title_box.append(&title_label); |
| 42 | + |
| 43 | + header_bar.set_title_widget(Some(&title_box)); |
| 44 | + |
| 45 | + // Content box |
| 46 | + let content_box = GtkBox::builder() |
| 47 | + .orientation(Orientation::Vertical) |
| 48 | + .spacing(15) |
| 49 | + .margin_top(20) |
| 50 | + .margin_start(20) |
| 51 | + .margin_end(20) |
| 52 | + .margin_bottom(20) |
| 53 | + .build(); |
| 54 | + |
| 55 | + // Subtitle |
| 56 | + let subtitle_label = Label::builder() |
| 57 | + .label("Twój system do Gier i Etycznego Hakowania") |
| 58 | + .use_markup(true) |
| 59 | + .halign(Align::Center) |
| 60 | + .build(); |
| 61 | + subtitle_label.set_markup("<span font='Arial 18'>Twój system do Gier i Etycznego Hakowania</span>"); |
| 62 | + subtitle_label.style_context().add_class("subtitle"); |
| 63 | + content_box.append(&subtitle_label); |
| 64 | + |
| 65 | + actions.borrow_mut().subtitle_label = Some(subtitle_label.clone()); |
| 66 | + |
| 67 | + // Separator |
| 68 | + let separator = Separator::builder() |
| 69 | + .orientation(Orientation::Horizontal) |
| 70 | + .margin_start(10) |
| 71 | + .margin_end(10) |
| 72 | + .build(); |
| 73 | + content_box.append(&separator); |
| 74 | + |
| 75 | + // ScrolledWindow for buttons |
| 76 | + let scrolled_window = ScrolledWindow::builder() |
| 77 | + .hscrollbar_policy(PolicyType::Never) |
| 78 | + .vscrollbar_policy(PolicyType::Automatic) |
| 79 | + .hexpand(true) |
| 80 | + .vexpand(true) |
| 81 | + .build(); |
| 82 | + content_box.append(&scrolled_window); |
| 83 | + |
| 84 | + // FlowBox for buttons |
| 85 | + let flow_box = FlowBox::builder() |
| 86 | + .column_spacing(15) |
| 87 | + .row_spacing(15) |
| 88 | + .margin_start(10) |
| 89 | + .margin_end(10) |
| 90 | + .margin_bottom(20) |
| 91 | + .homogeneous(true) |
| 92 | + .min_children_per_line(2) |
| 93 | + .max_children_per_line(3) |
| 94 | + .build(); |
| 95 | + scrolled_window.set_child(Some(&flow_box)); |
| 96 | + |
| 97 | + // Buttons |
| 98 | + let buttons = vec![ |
| 99 | + ("Otwórz stronę HackerOS", clone!(@strong actions => move || actions.borrow().open_website())), |
| 100 | + ("Otwórz X", clone!(@strong actions => move || actions.borrow().open_x())), |
| 101 | + ("Otwórz sklep z aplikacjami", clone!(@strong actions => move || actions.borrow().open_software())), |
| 102 | + ("Changelog", clone!(@strong actions => move || actions.borrow().open_changelog())), |
| 103 | + ("Informacje o systemie", clone!(@strong actions => move || actions.borrow().open_system_info())), |
| 104 | + ("Zgłoś błąd", clone!(@strong actions => move || actions.borrow().report_bug())), |
| 105 | + ("Forum dyskusyjne", clone!(@strong actions => move || actions.borrow().open_forum())), |
| 106 | + ("Zaktualizuj system", clone!(@strong actions => move || actions.borrow().update_system())), |
| 107 | + ("Uruchom HackerOS Games", clone!(@strong actions => move || actions.borrow().run_command_with_feedback("/usr/share/HackerOS/Scripts/Bin/HackerOS-Games.sh"))), |
| 108 | + ("Hacker Launcher", clone!(@strong actions => move || actions.borrow().run_command_with_feedback("/usr/share/HackerOS/Scripts/HackerOS-Apps/Hacker_Launcher"))), |
| 109 | + ]; |
| 110 | + |
| 111 | + for (label, action) in buttons { |
| 112 | + let button = Button::builder() |
| 113 | + .label(label) |
| 114 | + .build(); |
| 115 | + button.connect_clicked(move |_| action()); |
| 116 | + flow_box.append(&button); |
| 117 | + } |
| 118 | + |
| 119 | + // Footer |
| 120 | + let footer_label = Label::builder() |
| 121 | + .label("© 2025 HackerOS Team | All rights reserved") |
| 122 | + .halign(Align::Center) |
| 123 | + .build(); |
| 124 | + footer_label.style_context().add_class("footer"); |
| 125 | + content_box.append(&footer_label); |
| 126 | + |
| 127 | + // ToolbarView to integrate header and content |
| 128 | + let toolbar_view = ToolbarView::new(); |
| 129 | + toolbar_view.add_top_bar(&header_bar); |
| 130 | + toolbar_view.set_content(Some(&content_box)); |
| 131 | + |
| 132 | + // Set window content |
| 133 | + window.set_content(Some(&toolbar_view)); |
| 134 | +} |
0 commit comments