Skip to content

Commit

Permalink
Enhancements for #83
Browse files Browse the repository at this point in the history
Former-commit-id: fc62026
  • Loading branch information
tkashkin committed Sep 25, 2018
1 parent 33ca891 commit 5acf271
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 32 deletions.
15 changes: 10 additions & 5 deletions src/data/Game.vala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace GameHub.Data
public GameSource source { get; protected set; }

public string id { get; protected set; }
public string name { get; protected set; }
public string name { get; set; }
public string description { get; protected set; }

public string icon { get; set; }
Expand Down Expand Up @@ -61,7 +61,7 @@ namespace GameHub.Data
}
if(!(tag in Tables.Tags.DYNAMIC_TAGS))
{
Tables.Games.add(this);
save();
status_change(_status);
tags_update();
}
Expand All @@ -74,7 +74,7 @@ namespace GameHub.Data
}
if(!(tag in Tables.Tags.DYNAMIC_TAGS))
{
Tables.Games.add(this);
save();
status_change(_status);
tags_update();
}
Expand All @@ -91,6 +91,11 @@ namespace GameHub.Data
}
}

public virtual void save()
{
Tables.Games.add(this);
}

public bool is_installable { get; protected set; default = false; }

public File executable { get; protected set; }
Expand Down Expand Up @@ -174,7 +179,7 @@ namespace GameHub.Data
if(update)
{
update_status();
Tables.Games.add(this);
save();
}
}

Expand Down Expand Up @@ -243,7 +248,7 @@ namespace GameHub.Data
if(update)
{
update_status();
Tables.Games.add(this);
save();
}
}

Expand Down
28 changes: 28 additions & 0 deletions src/data/db/tables/Games.vala
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,34 @@ namespace GameHub.Data.DB.Tables
return true;
}

public static bool remove(Game game)
{
unowned Sqlite.Database? db = Database.instance.db;
if(db == null) return false;

Statement s;
int res = db.prepare_v2("DELETE FROM `games` WHERE `source` = ? AND `id` = ?", -1, out s);

if(res != Sqlite.OK)
{
warning("[Database.Games.remove] Can't prepare DELETE query (%d): %s", db.errcode(), db.errmsg());
return false;
}

res = s.bind_text(1, game.source.id);
res = s.bind_text(2, game.id);

res = s.step();

if(res != Sqlite.DONE)
{
warning("[Database.Games.remove] Error (%d): %s", db.errcode(), db.errmsg());
return false;
}

return true;
}

public static new Game? get(string src, string id)
{
if(src == null || id == null) return null;
Expand Down
4 changes: 2 additions & 2 deletions src/data/sources/gog/GOGGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ namespace GameHub.Data.Sources.GOG
}
}

Tables.Games.add(this);
save();

update_status();

Expand Down Expand Up @@ -285,7 +285,7 @@ namespace GameHub.Data.Sources.GOG
{
install_dir = FSUtils.file(FSUtils.Paths.GOG.Games, escaped_name);
executable = FSUtils.file(install_dir.get_path(), "start.sh");
Tables.Games.add(this);
save();
update_status();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/data/sources/humble/HumbleGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ namespace GameHub.Data.Sources.Humble
}
}

Tables.Games.add(this);
save();

update_status();

Expand Down Expand Up @@ -271,7 +271,7 @@ namespace GameHub.Data.Sources.Humble
{
install_dir = FSUtils.file(FSUtils.Paths.GOG.Games, escaped_name);
executable = FSUtils.file(install_dir.get_path(), "start.sh");
Tables.Games.add(this);
save();
update_status();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/data/sources/steam/SteamGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ namespace GameHub.Data.Sources.Steam
{
debug("[Steam:%s] No platform support data, %d tries failed, assuming Windows support", id, metadata_tries);
platforms.add(Platform.WINDOWS);
Tables.Games.add(this);
save();
game_info_updated = true;
return;
}
Expand All @@ -150,7 +150,7 @@ namespace GameHub.Data.Sources.Steam
}
}

Tables.Games.add(this);
save();

game_info_updated = true;
update_status();
Expand Down
3 changes: 3 additions & 0 deletions src/data/sources/user/User.vala
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ namespace GameHub.Data.Sources.User
{
Idle.add(() => { game_loaded(g, true); return Source.REMOVE; });
}
((UserGame) g).removed.connect(() => {
_games.remove(g);
});
}
games_count++;
}
Expand Down
27 changes: 24 additions & 3 deletions src/data/sources/user/UserGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ namespace GameHub.Data.Sources.User
{
public class UserGame: Game
{
private bool is_removed = false;
public signal void removed();

public UserGame(string name, File dir, File exec, string args)
{
source = User.instance;

this.id = Utils.md5(name);
this.id = Utils.md5(name + Random.next_int().to_string());
this.name = name;

platforms.clear();
Expand Down Expand Up @@ -71,12 +74,30 @@ namespace GameHub.Data.Sources.User
public override async void update_game_info()
{
update_status();
Tables.Games.add(this);
save();
}

public override async void install(){}

public override async void uninstall(){}
public override async void uninstall()
{
remove();
}

public void remove()
{
is_removed = true;
removed();
Tables.Games.remove(this);
}

public override void save()
{
if(!is_removed)
{
base.save();
}
}

public override void update_status()
{
Expand Down
26 changes: 23 additions & 3 deletions src/ui/dialogs/GamePropertiesDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace GameHub.UI.Dialogs
private ScrolledWindow tags_scrolled;
private Entry new_entry;

private Entry name_entry;
private AutoSizeImage image_view;
private AutoSizeImage icon_view;
private Entry image_entry;
Expand Down Expand Up @@ -108,6 +109,25 @@ namespace GameHub.UI.Dialogs

properties_box = new Box(Orientation.VERTICAL, 0);

var name_header = new HeaderLabel(_("Name"));
name_header.xpad = 8;
properties_box.add(name_header);

name_entry = new Entry();
name_entry.placeholder_text = name_entry.primary_icon_tooltip_text = _("Name");
name_entry.primary_icon_name = "insert-text-symbolic";
name_entry.primary_icon_activatable = false;
name_entry.margin = 4;
name_entry.margin_top = 0;
properties_box.add(name_entry);

name_entry.text = game.name;
name_entry.changed.connect(() => {
game.name = name_entry.text.strip();
game.update_status();
game.save();
});

var images_header = new HeaderLabel(_("Images"));
images_header.xpad = 8;
properties_box.add(images_header);
Expand Down Expand Up @@ -223,7 +243,7 @@ namespace GameHub.UI.Dialogs
properties_box.add(executable_picker);

var args_entry = new Entry();
args_entry.text = game.arguments;
args_entry.text = game.arguments ?? "";
args_entry.placeholder_text = args_entry.primary_icon_tooltip_text = _("Arguments");
args_entry.primary_icon_name = "utilities-terminal-symbolic";
args_entry.primary_icon_activatable = false;
Expand All @@ -232,7 +252,7 @@ namespace GameHub.UI.Dialogs
args_entry.changed.connect(() => {
game.arguments = args_entry.text.strip();
game.update_status();
Tables.Games.add(game);
game.save();
});

properties_box.add(args_entry);
Expand Down Expand Up @@ -269,7 +289,7 @@ namespace GameHub.UI.Dialogs
delete_event.connect(() => {
set_image_url(true);
set_icon_url(true);
Tables.Games.add(game);
game.save();
destroy();
});

Expand Down
3 changes: 2 additions & 1 deletion src/ui/dialogs/SettingsDialog/SettingsDialogTab.vala
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace GameHub.UI.Dialogs.SettingsDialog
{
var chooser = new FileChooserButton(text, mode);
chooser.create_folders = create;
chooser.show_hidden = true;
chooser.select_filename(FSUtils.expand(val));
chooser.file_set.connect(() => { action(chooser.get_filename()); });
chooser.set_size_request(280, -1);
Expand Down Expand Up @@ -210,4 +211,4 @@ namespace GameHub.UI.Dialogs.SettingsDialog
protected delegate void EntryAction(string val);
protected delegate void ButtonAction();
}
}
}
2 changes: 1 addition & 1 deletion src/ui/views/GameDetailsView/GameDetailsPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ namespace GameHub.UI.Views.GameDetailsView
action_properties = add_action("system-run", null, _("Game properties"), game_properties);
action_open_directory = add_action("folder", null, _("Open installation directory"), open_game_directory);
action_open_store_page = add_action("web-browser", null, _("Open store page"), open_game_store_page);
action_uninstall = add_action("edit-delete", null, _("Uninstall"), uninstall_game);
action_uninstall = add_action("edit-delete", null, (game is Sources.User.UserGame) ? _("Remove") : _("Uninstall"), uninstall_game);

action_cancel.clicked.connect(() => {
if(download != null) download.cancel();
Expand Down
21 changes: 14 additions & 7 deletions src/ui/views/GamesView/AddGamePopover.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ namespace GameHub.UI.Views.GamesView
grid = new Grid();
grid.margin = 8;
grid.row_spacing = 4;
grid.column_spacing = 12;
grid.column_spacing = 4;

name = add_entry(_("Name"), "insert-text-symbolic");
gamedir = add_filechooser(_("Directory"), _("Select game directory"), FileChooserAction.SELECT_FOLDER);
executable = add_filechooser(_("Executable"), _("Select game executable"));
gamedir = add_filechooser(_("Directory"), _("Select game directory"), FileChooserAction.SELECT_FOLDER);
arguments = add_entry(_("Arguments"), "utilities-terminal-symbolic");

add = new Button.with_label(_("Add game"));
Expand All @@ -49,8 +49,8 @@ namespace GameHub.UI.Views.GamesView
grid.attach(add, 0, rows, 2, 1);

name.changed.connect(update);
gamedir.file_set.connect(update);
executable.file_set.connect(update);
gamedir.file_set.connect(update);
arguments.changed.connect(update);

update();
Expand All @@ -64,19 +64,24 @@ namespace GameHub.UI.Views.GamesView
private void update()
{
add.sensitive = name.text.strip().length > 0
&& gamedir.get_file() != null && gamedir.get_file().query_exists()
&& executable.get_file() != null && executable.get_file().query_exists();
&& executable.get_file() != null && executable.get_file().query_exists()
&& gamedir.get_file() != null && gamedir.get_file().query_exists();

if(executable.get_file() != null && gamedir.get_file() == null)
{
gamedir.select_file(executable.get_file().get_parent());
}
}

private void add_game()
{
var game = new UserGame(name.text.strip(), gamedir.get_file(), executable.get_file(), arguments.text.strip());
name.text = "";
gamedir.unselect_all();
executable.unselect_all();
gamedir.unselect_all();
arguments.text = "";
update();
Tables.Games.add(game);
game.save();
game_added(game);
#if GTK_3_22
popdown();
Expand All @@ -90,6 +95,7 @@ namespace GameHub.UI.Views.GamesView
var label = new Label(text);
label.halign = Align.END;
label.xalign = 1;
label.margin = 4;
var entry = new Entry();
entry.primary_icon_name = icon;
entry.primary_icon_activatable = false;
Expand All @@ -105,6 +111,7 @@ namespace GameHub.UI.Views.GamesView
var label = new Label(text);
label.halign = Align.END;
label.xalign = 1;
label.margin = 4;
var button = new FileChooserButton(title, action);
button.set_size_request(220, -1);
grid.attach(label, 0, rows);
Expand Down
2 changes: 1 addition & 1 deletion src/ui/views/GamesView/GameCard.vala
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ namespace GameHub.UI.Views.GamesView
break;

case 3:
new GameContextMenu(game).open(this, e);
new GameContextMenu(game, this).open(e);
break;
}
return true;
Expand Down
Loading

0 comments on commit 5acf271

Please sign in to comment.