Skip to content

Commit

Permalink
WIP Part 15: Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Vysp3r committed Oct 4, 2024
1 parent 7318035 commit 2b97f39
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 100 deletions.
2 changes: 1 addition & 1 deletion src/models/runners/basic.vala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ namespace ProtonPlus.Models.Runners {

public abstract string get_directory_name (string release_name);

public abstract string get_directory_name_reverse (string release_name);
public abstract string get_directory_name_reverse (string directory_name);
}
}
2 changes: 1 addition & 1 deletion src/widgets/application.vala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace ProtonPlus.Widgets {
public class Application : Adw.Application {
public static Window window;
public static Window window { get; set; }

construct {
application_id = Constants.APP_ID;
Expand Down
12 changes: 7 additions & 5 deletions src/widgets/description-dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace ProtonPlus.Widgets {

Adw.ToolbarView toolbar_view { get; set; }
Adw.WindowTitle window_title { get; set; }
Adw.ButtonContent web_button_content { get; set; }
Gtk.Button web_button { get; set; }
Adw.HeaderBar header_bar { get; set; }
Gtk.ScrolledWindow scrolled_window { get; set; }
Expand All @@ -12,7 +13,12 @@ namespace ProtonPlus.Widgets {
construct {
window_title = new Adw.WindowTitle (_("More information"), "");

web_button = new Gtk.Button.from_icon_name ("world-www-symbolic");
web_button_content = new Adw.ButtonContent ();
web_button_content.set_icon_name ("world-www-symbolic");
web_button_content.set_label (_("Open"));

web_button = new Gtk.Button ();
web_button.set_child (web_button_content);
web_button.set_tooltip_text (_("Open in your web browser"));
web_button.clicked.connect (web_button_clicked);

Expand Down Expand Up @@ -42,15 +48,11 @@ namespace ProtonPlus.Widgets {
set_content (toolbar_view);
set_transient_for (Application.window);
set_modal (true);

notify["release"].connect (release_changed);
}

public DescriptionDialog (Models.Release release) {
this.release = release;
}

void release_changed () {
window_title.set_subtitle (release.displayed_title);
description_label.set_label (release.description);
}
Expand Down
17 changes: 0 additions & 17 deletions src/widgets/info-box.vala
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
namespace ProtonPlus.Widgets {
public class InfoBox : Gtk.Box {
public bool installed_only { get; set; }

public Gtk.Button sidebar_button { get; set; }
Menu menu_model { get; set; }
Gtk.MenuButton menu_button { get; set; }
Expand Down Expand Up @@ -39,8 +37,6 @@ namespace ProtonPlus.Widgets {

launcher_boxes = new List<Widgets.LauncherBox> ();

notify["installed-only"].connect (installed_only_changed);

append (toolbar_view);
}

Expand All @@ -55,18 +51,5 @@ namespace ProtonPlus.Widgets {
launcher_boxes.append (launcher_box);
}
}

void installed_only_changed () {
foreach (var box in launcher_boxes) {
foreach (var group in box.group_rows) {
foreach (var runner in group.runner_rows) {
runner.load_more_row.set_visible (!installed_only);
foreach (var release in runner.release_rows) {
release.show_installed_only (installed_only);
}
}
}
}
}
}
}
9 changes: 3 additions & 6 deletions src/widgets/launcher-box.vala
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
namespace ProtonPlus.Widgets {
public class LauncherBox : Gtk.Widget {
Models.Launcher launcher { get; set; }
Gtk.BinLayout bin_layout { get; set; }
Gtk.Box content { get; set; }
Adw.Clamp clamp { get; set; }
Gtk.ScrolledWindow scrolled_window { get; set; }
public List<RunnerGroup> group_rows;

public LauncherBox (Models.Launcher launcher) {
this.launcher = launcher;

group_rows = new List<RunnerGroup> ();

var bin = new Gtk.BinLayout ();
set_layout_manager (bin);
bin_layout = new Gtk.BinLayout ();
set_layout_manager (bin_layout);

content = new Gtk.Box (Gtk.Orientation.VERTICAL, 15);

Expand All @@ -28,7 +26,6 @@ namespace ProtonPlus.Widgets {

foreach (var group in launcher.groups) {
var runner_group = new RunnerGroup (group);
group_rows.append (runner_group);
content.append (runner_group);
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/widgets/release-row.vala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,5 @@ namespace ProtonPlus.Widgets {
protected abstract void remove_button_clicked ();

protected abstract void info_button_clicked ();

public abstract void show_installed_only (bool installed_only);
}
}
4 changes: 0 additions & 4 deletions src/widgets/release-rows/basic.vala
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@ namespace ProtonPlus.Widgets.ReleaseRows {
description_dialog.present ();
}

public override void show_installed_only (bool installed_only) {
set_visible (installed_only ? release.state == Models.Release.State.UP_TO_DATE || release.state == Models.Release.State.UPDATE_AVAILABLE : true);
}

void release_displayed_title_changed () {
set_title (release.displayed_title);
}
Expand Down
8 changes: 0 additions & 8 deletions src/widgets/release-rows/steamtinkerlaunch.vala
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,11 @@ namespace ProtonPlus.Widgets.ReleaseRows {
upgrade_button.clicked.connect (upgrade_button_clicked);

input_box.append (upgrade_button);

notify["release"].connect (release_changed);
}

public SteamTinkerLaunch (Models.Releases.SteamTinkerLaunch release) {
this.release = release;
}

void release_changed () {
install_dialog.initialize (release);
remove_dialog.initialize (release);
upgrade_dialog.initialize (release);
Expand Down Expand Up @@ -200,10 +196,6 @@ namespace ProtonPlus.Widgets.ReleaseRows {
}
}

public override void show_installed_only (bool installed_only) {
set_visible (installed_only ? release.state == Models.Release.State.UP_TO_DATE || release.state == Models.Release.State.UPDATE_AVAILABLE : true);
}

void release_displayed_title_changed () {
set_title (release.displayed_title);
}
Expand Down
5 changes: 0 additions & 5 deletions src/widgets/runner-group.vala
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
namespace ProtonPlus.Widgets {
public class RunnerGroup : Adw.PreferencesGroup {
public List<RunnerRow> runner_rows;

public RunnerGroup (Models.Group group) {
runner_rows = new List<RunnerRow> ();

set_title (group.title);
set_description (group.description);

foreach (var runner in group.runners) {
var runner_row = new RunnerRow (runner);
runner_rows.append (runner_row);
add (runner_row);
}
}
Expand Down
7 changes: 1 addition & 6 deletions src/widgets/runner-row.vala
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ namespace ProtonPlus.Widgets {
public class RunnerRow : Adw.ExpanderRow {
Models.Runner runner { get; set; }
Gtk.Spinner spinner { get; set; }
public LoadMoreRow load_more_row { get; set; }
public List<ReleaseRow> release_rows;
LoadMoreRow load_more_row { get; set; }

public RunnerRow (Models.Runner runner) {
this.runner = runner;

release_rows = new List<ReleaseRow> ();

load_more_row = new LoadMoreRow ();
load_more_row.activated.connect (load_more_row_activated);

Expand All @@ -33,11 +30,9 @@ namespace ProtonPlus.Widgets {
foreach (var release in releases) {
if (release is Models.Releases.Basic || release is Models.Releases.GitHubAction) {
var row = new Widgets.ReleaseRows.Basic ((Models.Releases.Basic) release);
release_rows.append (row);
add_row (row);
} else if (release is Models.Releases.SteamTinkerLaunch) {
var row = new Widgets.ReleaseRows.SteamTinkerLaunch ((Models.Releases.SteamTinkerLaunch) release);
release_rows.append (row);
add_row (row);
}
}
Expand Down
52 changes: 17 additions & 35 deletions src/widgets/sidebar.vala
Original file line number Diff line number Diff line change
@@ -1,55 +1,33 @@
namespace ProtonPlus.Widgets {
public class Sidebar : Gtk.Box {
public Gtk.Button sidebar_button { get; set; }
public Gtk.Switch installed_only_switch { get; set; }

Gtk.ListBox list_box;
Adw.ToolbarView toolbar_view { get; set; }
Adw.WindowTitle window_title { get; set; }
Adw.HeaderBar header_bar { get; set; }
Gtk.ListBox list_box { get; set; }

construct {
sidebar_button = new Gtk.Button.from_icon_name ("layout-sidebar-symbolic");
sidebar_button.set_tooltip_text (_("Toggle Sidebar"));

var window_title = new Adw.WindowTitle ("ProtonPlus", "");
window_title = new Adw.WindowTitle ("ProtonPlus", "");

var header = new Adw.HeaderBar ();
header.set_title_widget (window_title);
header.pack_start (sidebar_button);
header_bar = new Adw.HeaderBar ();
header_bar.set_title_widget (window_title);
header_bar.pack_start (sidebar_button);

list_box = new Gtk.ListBox ();
list_box.set_activate_on_single_click (true);
list_box.set_selection_mode (Gtk.SelectionMode.SINGLE);
list_box.add_css_class ("navigation-sidebar");
list_box.set_hexpand (true);
list_box.row_selected.connect ((row) => {
this.activate_action_variant ("win.load-info-box", row.get_index ());
});

installed_only_switch = new Gtk.Switch ();
installed_only_switch.set_tooltip_text (_("Only display the runners that are currently installed on your system"));

var installed_only_label = new Gtk.Label (_("Only Installed"));
installed_only_label.set_hexpand (true);
installed_only_label.set_halign (Gtk.Align.START);

var installed_only_box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 5);
installed_only_box.set_margin_bottom (15);
installed_only_box.set_margin_top (15);
installed_only_box.set_margin_start (20);
installed_only_box.set_margin_end (20);
installed_only_box.set_vexpand (true);
installed_only_box.set_valign (Gtk.Align.END);
installed_only_box.append (installed_only_label);
installed_only_box.append (installed_only_switch);
list_box.row_selected.connect (list_box_row_selected);

var content = new Gtk.Box (Gtk.Orientation.VERTICAL, 5);
content.append (list_box);
content.append (installed_only_box);
toolbar_view = new Adw.ToolbarView ();
toolbar_view.add_top_bar (header_bar);
toolbar_view.set_content (list_box);

var toolbar_view = new Adw.ToolbarView ();
toolbar_view.add_top_bar (header);
toolbar_view.set_content (content);

this.append (toolbar_view);
append (toolbar_view);
}

public void initialize (List<Models.Launcher> launchers) {
Expand All @@ -64,5 +42,9 @@ namespace ProtonPlus.Widgets {
list_box.select_row (list_box.get_row_at_index (0));
}
}

void list_box_row_selected (Gtk.ListBoxRow? row) {
activate_action_variant ("win.load-info-box", row.get_index ());
}
}
}
12 changes: 7 additions & 5 deletions src/widgets/status-box.vala
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
namespace ProtonPlus.Widgets {
public class StatusBox : Gtk.Box {
Adw.ToolbarView toolbar_view { get; set; }
Adw.HeaderBar header_bar { get; set; }
Adw.StatusPage status_page { get; set; }

construct {
var header = new Adw.HeaderBar ();
header.add_css_class ("flat");
header_bar = new Adw.HeaderBar ();
header_bar.add_css_class ("flat");

status_page = new Adw.StatusPage ();
status_page.set_vexpand (true);
status_page.set_hexpand (true);

var toolbar_view = new Adw.ToolbarView ();
toolbar_view.add_top_bar (header);
toolbar_view = new Adw.ToolbarView ();
toolbar_view.add_top_bar (header_bar);
toolbar_view.set_content (status_page);

this.append (toolbar_view);
append (toolbar_view);
}

public void initialize (string? icon_name, string title, string description) {
Expand Down
11 changes: 6 additions & 5 deletions src/widgets/window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ namespace ProtonPlus.Widgets {
int tasks { get; set; }

Adw.OverlaySplitView overlay_split_view { get; set; }
Adw.NavigationPage info_page { get; set; }
Adw.NavigationPage sidebar_page { get; set; }
Widgets.StatusBox status_box { get; set; }
Widgets.InfoBox info_box { get; set; }
Widgets.Sidebar sidebar { get; set; }
Adw.Breakpoint breakpoint { get; set; }

construct {
set_application ((Adw.Application) GLib.Application.get_default ());
Expand All @@ -23,11 +26,9 @@ namespace ProtonPlus.Widgets {

status_box = new Widgets.StatusBox ();

var info_page = new Adw.NavigationPage.with_tag (info_box = new Widgets.InfoBox (), "InfoBox", "main");
info_page = new Adw.NavigationPage.with_tag (info_box = new Widgets.InfoBox (), "InfoBox", "main");

var sidebar_page = new Adw.NavigationPage.with_tag (sidebar = new Widgets.Sidebar (), "Sidebar", "sidebar");

sidebar.installed_only_switch.notify["active"].connect (() => info_box.installed_only = sidebar.installed_only_switch.active);
sidebar_page = new Adw.NavigationPage.with_tag (sidebar = new Widgets.Sidebar (), "Sidebar", "sidebar");

overlay_split_view = new Adw.OverlaySplitView ();
overlay_split_view.set_sidebar (sidebar_page);
Expand All @@ -41,7 +42,7 @@ namespace ProtonPlus.Widgets {

info_box.sidebar_button.clicked.connect (() => overlay_split_view.set_show_sidebar (!overlay_split_view.get_show_sidebar ()));

var breakpoint = new Adw.Breakpoint (Adw.BreakpointCondition.parse ("max-width: 625px"));
breakpoint = new Adw.Breakpoint (Adw.BreakpointCondition.parse ("max-width: 625px"));
breakpoint.add_setter (overlay_split_view, "collapsed", true);

add_breakpoint (breakpoint);
Expand Down

0 comments on commit 2b97f39

Please sign in to comment.