Skip to content

Commit

Permalink
Tweaks: fixes for global options and default values (#355)
Browse files Browse the repository at this point in the history
GameInstallDialog/InstallTask: support install_dir import
  • Loading branch information
tkashkin committed Aug 15, 2020
1 parent 32c0717 commit 748c4f7
Show file tree
Hide file tree
Showing 12 changed files with 176 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/data/runnables/Game.vala
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ namespace GameHub.Data.Runnables
public virtual async void install(InstallTask.Mode install_mode=InstallTask.Mode.INTERACTIVE)
{
if(status.state != Game.State.UNINSTALLED || !is_installable) return;
var task = new InstallTask(this, installers, source.game_dirs, install_mode);
var task = new InstallTask(this, installers, source.game_dirs, install_mode, true);
yield task.start();
}

Expand Down
33 changes: 30 additions & 3 deletions src/data/runnables/tasks/install/InstallTask.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ namespace GameHub.Data.Runnables.Tasks.Install
public ArrayList<CompatTool>? compat_tools { get; set; default = null; }
public CompatTool? selected_compat_tool { get; set; default = null; }

public InstallTask(Runnable? runnable, ArrayList<Installer>? installers, ArrayList<File>? install_dirs, InstallTask.Mode install_mode=InstallTask.Mode.INTERACTIVE)
public bool can_import_install_dir { get; construct set; default = false; }
private bool install_dir_imported = false;

public InstallTask(Runnable? runnable, ArrayList<Installer>? installers, ArrayList<File>? install_dirs, InstallTask.Mode install_mode=InstallTask.Mode.INTERACTIVE, bool allow_install_dir_import=true)
{
Object(runnable: runnable, installers: installers, install_dirs: install_dirs, install_mode: install_mode);
Object(runnable: runnable, installers: installers, install_dirs: install_dirs, install_mode: install_mode, can_import_install_dir: allow_install_dir_import);
}

private void init()
Expand Down Expand Up @@ -138,6 +141,11 @@ namespace GameHub.Data.Runnables.Tasks.Install

public async void install()
{
if(install_dir_imported)
{
warning("[InstallTask.install] Installation directory was imported, skipping installation");
return;
}
if(selected_installer == null)
{
warning("[InstallTask.install] No installer selected");
Expand All @@ -158,6 +166,25 @@ namespace GameHub.Data.Runnables.Tasks.Install
yield selected_installer.install(this);
}

public void import_install_dir(File? dir)
{
if(dir != null && dir.query_exists())
{
install_dir = dir;
info("[InstallTask.import_install_dir] Importing install_dir of %s; install_dir: `%s`", runnable != null ? runnable.full_id : "(null)", install_dir.get_path());
if(runnable != null)
{
runnable.install_dir = dir;
runnable.save();
runnable.update_status();
}
install_dir_imported = true;
config_step_last_change_direction = ConfigStepChangeDirection.NEXT;
config_step = ConfigStep.FINISH;
finish();
}
}

public void finish()
{
info("[InstallTask.finish] Finishing installation of %s", runnable != null ? runnable.full_id : "(null)");
Expand Down Expand Up @@ -198,7 +225,7 @@ namespace GameHub.Data.Runnables.Tasks.Install
});
});

if(selected_installer.version != null)
if(selected_installer != null && selected_installer.version != null)
{
runnable.cast<Game>(game => game.version = selected_installer.version);
}
Expand Down
2 changes: 1 addition & 1 deletion src/data/sources/gog/GOGGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ namespace GameHub.Data.Sources.GOG
string? d = null;
if(game is DLC)
{
g = ((DLC) this).game.name;
g = ((DLC) game).game.name;
d = game.name;
}
installers_dir = FS.file(Settings.Paths.Collection.GOG.expand_installers(g, d, platform));
Expand Down
9 changes: 9 additions & 0 deletions src/data/tweaks/Option.vala
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,15 @@ namespace GameHub.Data.Tweaks
return null;
}

public string default_value
{
get
{
if(presets != null && presets.size >= 1) return presets.first().value;
return "";
}
}

public Json.Node? to_json()
{
var node = new Json.Node(Json.NodeType.OBJECT);
Expand Down
8 changes: 7 additions & 1 deletion src/data/tweaks/TweakOptions.vala
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,16 @@ namespace GameHub.Data.Tweaks
{
foreach(var option_props in properties)
{
var option_value = option_props.value;
result = result.replace("${option:%s}".printf(option_props.option.id), option_props.value);
}
}
if(tweak.options != null && tweak.options.size > 0)
{
foreach(var option in tweak.options)
{
result = result.replace("${option:%s}".printf(option.id), option.default_value);
}
}
return result;
}

Expand Down
11 changes: 11 additions & 0 deletions src/data/tweaks/TweakSet.vala
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ namespace GameHub.Data.Tweaks
return global;
}

public TweakOptions get_options_or_use_global(Tweak tweak)
{
if(is_global)
{
return get_or_create_options(tweak);
}
var local = get_options_for_tweak(tweak);
if(local != null && local.properties.size > 0) return local;
return get_or_create_global_options(tweak);
}

public bool is_enabled(string tweak_id)
{
var opts = get_options_for_id(tweak_id);
Expand Down
12 changes: 11 additions & 1 deletion src/ui/dialogs/GamePropertiesDialog/tabs/Executable.vala
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,25 @@ namespace GameHub.UI.Dialogs.GamePropertiesDialog.Tabs

construct
{
var install_dir_path = game.install_dir != null ? game.install_dir.get_path() : null;

var sgrp_executable = new SettingsGroup();
var executable_setting = sgrp_executable.add_setting(
new FileSetting(
_("Executable"), _("Game's main executable file"),
InlineWidgets.file_chooser(_("Select the main executable file of the game"), FileChooserAction.OPEN, false, null, false, true),
InlineWidgets.file_chooser(_("Select the main executable file of the game"), FileChooserAction.OPEN, false, null, false, true, install_dir_path),
game.executable != null ? game.executable.get_path() : null
)
);
executable_setting.chooser.file_set.connect(() => game.executable = executable_setting.chooser.file);
var work_dir_setting = sgrp_executable.add_setting(
new FileSetting(
_("Working directory"), _("Directory the executable is launched from"),
InlineWidgets.file_chooser(_("Select working directory of the game"), FileChooserAction.SELECT_FOLDER, false, null, false, false, install_dir_path),
game.work_dir != null ? game.work_dir.get_path() : null
)
);
work_dir_setting.chooser.file_set.connect(() => game.work_dir = work_dir_setting.chooser.file);
sgrp_executable.add_setting(
new EntrySetting.bind(
_("Arguments"), _("Command line arguments passed to the executable"),
Expand Down
32 changes: 29 additions & 3 deletions src/ui/dialogs/InstallDialog/steps/InstallerStep.vala
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ namespace GameHub.UI.Dialogs.InstallDialog.Steps
sgrp_installers.settings.selection_mode = SelectionMode.SINGLE;
sgrp_installers.settings.expand = true;

scroll.add(sgrp_installers);
add(scroll);

sgrp_installers.settings.row_selected.connect(row => {
if(row != null)
{
Expand All @@ -74,6 +71,35 @@ namespace GameHub.UI.Dialogs.InstallDialog.Steps
}
});

if(task.can_import_install_dir)
{
var sgrp_import = new SettingsGroup();
var import_setting = sgrp_import.add_setting(new ButtonLabelSetting(_("Import installation directory if game is already installed"), _("Import")));

var scroll_vbox = new Box(Orientation.VERTICAL, 0);
scroll_vbox.add(sgrp_installers);
scroll_vbox.add(sgrp_import);
scroll.add(scroll_vbox);

#if GTK_3_22
var install_dir_chooser = new FileChooserNative(_("Select installation directory"), GameHub.UI.Windows.MainWindow.instance, FileChooserAction.SELECT_FOLDER, _("Import"), _("Cancel"));
#else
var install_dir_chooser = new FileChooserDialog(_("Select installation directory"), GameHub.UI.Windows.MainWindow.instance, FileChooserAction.SELECT_FOLDER, _("Import"), ResponseType.ACCEPT, _("Cancel"), ResponseType.CANCEL);
#endif

import_setting.button.clicked.connect(() => {
if(install_dir_chooser.run() == ResponseType.ACCEPT)
{
task.import_install_dir(install_dir_chooser.get_file());
}
});
}
else
{
scroll.add(sgrp_installers);
}

add(scroll);
show_all();
update();
}
Expand Down
41 changes: 25 additions & 16 deletions src/ui/views/GamesView/grid/GameCard.vala
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ namespace GameHub.UI.Views.GamesView.Grid
private Label status_label;

private Box src_icons;
private Image src_icon;
private Box platform_icons;

private Image favorite_icon;
private Image updated_icon;

private Box platform_icons;

private Frame progress_bar;

private Image no_image_indicator;
Expand Down Expand Up @@ -119,9 +117,6 @@ namespace GameHub.UI.Views.GamesView.Grid
platform_icons.margin = 8;
platform_icons.set_events(0);

src_icon = new Image();
src_icon.icon_size = IconSize.LARGE_TOOLBAR;

label = new Label("");
label.xpad = 8;
label.ypad = 4;
Expand Down Expand Up @@ -229,10 +224,12 @@ namespace GameHub.UI.Views.GamesView.Grid
return false;
});

show_all();
favorite_icon.no_show_all = true;
updated_icon.no_show_all = true;
src_icons.no_show_all = true;
platform_icons.no_show_all = true;
info.no_show_all = true;
show_all();

Settings.UI.Appearance.instance.notify["grid-titles"].connect(update_appearance);
Settings.UI.Appearance.instance.notify["grid-platform-icons"].connect(update_appearance);
Expand Down Expand Up @@ -319,10 +316,9 @@ namespace GameHub.UI.Views.GamesView.Grid

Idle.add(() => {
label.label = game.name;
src_icon.icon_name = game.source.icon;

src_icons.foreach(w => w.destroy());
src_icons.add(src_icon);
add_src_icon(game.source.icon);

if(game != _game)
{
Expand All @@ -336,7 +332,6 @@ namespace GameHub.UI.Views.GamesView.Grid
add_src_icon(g.source.icon);
}
}
src_icons.show_all();

platform_icons.foreach(w => w.destroy());
Platform[] platforms = {};
Expand Down Expand Up @@ -368,7 +363,6 @@ namespace GameHub.UI.Views.GamesView.Grid
icon.icon_size = IconSize.LARGE_TOOLBAR;
platform_icons.add(icon);
}
platform_icons.show_all();

update_appearance();

Expand Down Expand Up @@ -474,11 +468,26 @@ namespace GameHub.UI.Views.GamesView.Grid

private void update_appearance()
{
Idle.add(() => {
info.visible = Settings.UI.Appearance.instance.grid_titles;
src_icons.visible = platform_icons.visible = Settings.UI.Appearance.instance.grid_platform_icons;
return Source.REMOVE;
}, Priority.LOW);
info.no_show_all = !Settings.UI.Appearance.instance.grid_titles;
if(Settings.UI.Appearance.instance.grid_titles)
{
info.show_all();
}
else
{
info.hide();
}
src_icons.no_show_all = platform_icons.no_show_all = !Settings.UI.Appearance.instance.grid_platform_icons;
if(Settings.UI.Appearance.instance.grid_platform_icons)
{
src_icons.show_all();
platform_icons.show_all();
}
else
{
src_icons.hide();
platform_icons.hide();
}
}

private void update_image_constraints()
Expand Down
19 changes: 16 additions & 3 deletions src/ui/widgets/FileChooserEntry.vala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace GameHub.UI.Widgets
public FileChooserAction action { get; construct; }
public bool allow_url { get; construct; }
public bool allow_executable { get; construct; }
public string? root_dir_prefix { get; set; }

public FileChooser chooser { get; protected set; }

Expand All @@ -44,9 +45,9 @@ namespace GameHub.UI.Widgets
set { select_file_path(value); }
}

public FileChooserEntry(string? title, FileChooserAction action, string? icon=null, string? hint=null, bool allow_url=false, bool allow_executable=false)
public FileChooserEntry(string? title, FileChooserAction action, string? icon=null, string? hint=null, bool allow_url=false, bool allow_executable=false, string? root_dir_prefix=null)
{
Object(title: title, action: action, allow_url: allow_url, allow_executable: allow_executable);
Object(title: title, action: action, allow_url: allow_url, allow_executable: allow_executable, root_dir_prefix: root_dir_prefix);
placeholder_text = primary_icon_tooltip_text = hint;
primary_icon_name = icon ?? (directory_mode ? "folder" : "application-x-executable");
primary_icon_activatable = false;
Expand Down Expand Up @@ -110,6 +111,11 @@ namespace GameHub.UI.Widgets
file = FS.file(path);
uri = file.get_uri();
}
else if(root_dir_prefix != null && (path == "." || path.has_prefix("./")))
{
select_file_path(Utils.replace_prefix(path, ".", root_dir_prefix));
return;
}
else if(allow_executable && path.length > 0)
{
var executable = Utils.find_executable(path);
Expand Down Expand Up @@ -143,7 +149,14 @@ namespace GameHub.UI.Widgets
{
chooser.unselect_all();
}
text = file.get_path();
if(root_dir_prefix != null && file.get_path().has_prefix(root_dir_prefix))
{
text = file.get_path().replace(root_dir_prefix, ".");
}
else
{
text = file.get_path();
}
}

if(allow_url)
Expand Down
Loading

0 comments on commit 748c4f7

Please sign in to comment.