Skip to content

Commit

Permalink
Games can be sorted by last launch time
Browse files Browse the repository at this point in the history
Imported tags can be disabled (#47)
Experimental flatpak changes (#15)
  • Loading branch information
tkashkin committed Oct 19, 2018
1 parent 8dfd66a commit cb4c384
Show file tree
Hide file tree
Showing 21 changed files with 210 additions and 32 deletions.
11 changes: 11 additions & 0 deletions data/com.github.tkashkin.gamehub.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
<value nick="List" value="1" />
</enum>

<enum id="com.github.tkashkin.gamehub.games-sort-mode">
<value nick="Name" value="0" />
<value nick="Last launch" value="1" />
</enum>

<schema path="/com/github/tkashkin/gamehub/saved-state/" id="com.github.tkashkin.gamehub.saved-state" gettext-domain="com.github.tkashkin.gamehub">
<key name="window-state" enum="com.github.tkashkin.gamehub.window-states">
<default>"Normal"</default>
Expand All @@ -31,6 +36,9 @@
<key name="games-view" enum="com.github.tkashkin.gamehub.games-view">
<default>"Grid"</default>
</key>
<key name="sort-mode" enum="com.github.tkashkin.gamehub.games-sort-mode">
<default>"Name"</default>
</key>
</schema>

<schema path="/com/github/tkashkin/gamehub/ui/" id="com.github.tkashkin.gamehub.ui" gettext-domain="com.github.tkashkin.gamehub">
Expand All @@ -49,6 +57,9 @@
<key name="use-compat" type="b">
<default>true</default>
</key>
<key name="use-imported-tags" type="b">
<default>true</default>
</key>
</schema>

<schema path="/com/github/tkashkin/gamehub/auth/steam/" id="com.github.tkashkin.gamehub.auth.steam" gettext-domain="com.github.tkashkin.gamehub">
Expand Down
3 changes: 2 additions & 1 deletion flatpak/com.github.tkashkin.gamehub.json.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"--talk-name=org.gnome.SettingsDaemon",
"--talk-name=org.freedesktop.NetworkManager",
"--talk-name=org.kde.StatusNotifierWatcher",
"--talk-name=org.freedesktop.Flatpak",
"--socket=session-bus",

"--persist=.",
Expand Down Expand Up @@ -49,7 +50,7 @@

"--filesystem=host",
"--filesystem=home",
"--filesystem=~/.var/app/com.valvesoftware.Steam:ro"
"--filesystem=~/.var/app/com.valvesoftware.Steam"
],
"cleanup": [
"/include",
Expand Down
16 changes: 15 additions & 1 deletion flatpak/libs/libs.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,25 @@
],

"modules": [
/* disable libs
"steamrt/steamrt.json",

"shared/udev/udev-175.json",
"shared/glu/glu-9.0.0.json",
*/

{
"name": "manette",
"buildsystem": "meson",
"config-opts": ["--libdir=lib"],
"sources": [
{
"type": "git",
"url": "https://gitlab.gnome.org/aplazas/libmanette.git"
}
]
}
/*,
{
"name": "libopenal",
"buildsystem": "cmake-ninja",
Expand Down Expand Up @@ -69,6 +83,6 @@
"sha256": "128b467c4ed03264c187405172a4e83049342cc8cc2f655f53a2d0ee9d3772f4"
}
]
}
}*/
]
}
4 changes: 4 additions & 0 deletions src/data/Game.vala
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ namespace GameHub.Data
public File install_dir { get; protected set; }
public string? store_page { get; protected set; default = null; }

public int64 last_launch { get; protected set; default = 0; }

public abstract async void install();
public abstract async void uninstall();

Expand All @@ -145,6 +147,8 @@ namespace GameHub.Data
}
}

last_launch = get_real_time() / 1000;
save();
yield Utils.run_thread(cmd, executable.get_parent().get_path(), null, true);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/data/db/Database.vala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace GameHub.Data.DB
{
public class Database
{
public const int VERSION = 2;
public const int VERSION = 3;
public static Table[] TABLES;

public static Database instance;
Expand Down
12 changes: 10 additions & 2 deletions src/data/db/tables/Games.vala
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace GameHub.Data.DB.Tables
public static Table.Field COMPAT_TOOL;
public static Table.Field COMPAT_TOOL_SETTINGS;
public static Table.Field ARGUMENTS;
public static Table.Field LAST_LAUNCH;

public Games()
{
Expand All @@ -65,6 +66,7 @@ namespace GameHub.Data.DB.Tables
COMPAT_TOOL = f(11);
COMPAT_TOOL_SETTINGS = f(12);
ARGUMENTS = f(13);
LAST_LAUNCH = f(14);
}

public override void migrate(Sqlite.Database db, int version)
Expand Down Expand Up @@ -94,6 +96,10 @@ namespace GameHub.Data.DB.Tables
case 1:
db.exec("ALTER TABLE `games` ADD `arguments` string");
break;

case 2:
db.exec("ALTER TABLE `games` ADD `last_launch` integer not null default 0");
break;
}
}
}
Expand All @@ -120,8 +126,9 @@ namespace GameHub.Data.DB.Tables
`platforms`,
`compat_tool`,
`compat_tool_settings`,
`arguments`)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", -1, out s);
`arguments`,
`last_launch`)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", -1, out s);

if(res != Sqlite.OK)
{
Expand Down Expand Up @@ -158,6 +165,7 @@ namespace GameHub.Data.DB.Tables
COMPAT_TOOL.bind(s, game.compat_tool);
COMPAT_TOOL_SETTINGS.bind(s, game.compat_tool_settings);
ARGUMENTS.bind(s, game.arguments);
LAST_LAUNCH.bind_int64(s, game.last_launch);

res = s.step();

Expand Down
23 changes: 20 additions & 3 deletions src/data/db/tables/Tags.vala
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,18 @@ namespace GameHub.Data.DB.Tables
DYNAMIC_TAGS.add(BUILTIN_UNINSTALLED);
DYNAMIC_TAGS.add(BUILTIN_INSTALLED);

tags_updated();
var ui_settings = GameHub.Settings.UI.get_instance();
ui_settings.notify["use-imported-tags"].connect(() => {
foreach(var tag in TAGS)
{
if(tag.id.has_prefix(Tag.IMPORTED_GOG_PREFIX))
{
tag.enabled = ui_settings.use_imported_tags;
}
}
tags_updated();
});
ui_settings.notify_property("use-imported-tags");
}

public static bool add(Tag tag, bool replace=false)
Expand All @@ -136,6 +147,10 @@ namespace GameHub.Data.DB.Tables
if(!TAGS.contains(tag))
{
TAGS.add(tag);
if(tag.id.has_prefix(Tag.IMPORTED_GOG_PREFIX))
{
tag.enabled = GameHub.Settings.UI.get_instance().use_imported_tags;
}
instance.tags_updated();
}

Expand All @@ -150,8 +165,9 @@ namespace GameHub.Data.DB.Tables

public class Tag: Object
{
public const string BUILTIN_PREFIX = "builtin:";
public const string USER_PREFIX = "user:";
public const string BUILTIN_PREFIX = "builtin:";
public const string USER_PREFIX = "user:";
public const string IMPORTED_GOG_PREFIX = "gog:";

public enum Builtin
{
Expand Down Expand Up @@ -198,6 +214,7 @@ namespace GameHub.Data.DB.Tables
public string? name { get; construct set; }
public string icon { get; construct set; }
public bool selected { get; construct set; default = true; }
public bool enabled { get; construct set; default = true; }

public Tag(string? id, string? name, string icon="gh-tag-symbolic", bool selected=true)
{
Expand Down
1 change: 1 addition & 0 deletions src/data/sources/gog/GOGGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ namespace GameHub.Data.Sources.GOG
compat_tool = Tables.Games.COMPAT_TOOL.get(s);
compat_tool_settings = Tables.Games.COMPAT_TOOL_SETTINGS.get(s);
arguments = Tables.Games.ARGUMENTS.get(s);
last_launch = Tables.Games.LAST_LAUNCH.get_int64(s);

platforms.clear();
var pls = Tables.Games.PLATFORMS.get(s).split(",");
Expand Down
1 change: 1 addition & 0 deletions src/data/sources/humble/HumbleGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ namespace GameHub.Data.Sources.Humble
compat_tool = Tables.Games.COMPAT_TOOL.get(s);
compat_tool_settings = Tables.Games.COMPAT_TOOL_SETTINGS.get(s);
arguments = Tables.Games.ARGUMENTS.get(s);
last_launch = Tables.Games.LAST_LAUNCH.get_int64(s);

platforms.clear();
var pls = Tables.Games.PLATFORMS.get(s).split(",");
Expand Down
3 changes: 3 additions & 0 deletions src/data/sources/steam/SteamGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ namespace GameHub.Data.Sources.Steam
compat_tool = Tables.Games.COMPAT_TOOL.get(s);
compat_tool_settings = Tables.Games.COMPAT_TOOL_SETTINGS.get(s);
arguments = Tables.Games.ARGUMENTS.get(s);
last_launch = Tables.Games.LAST_LAUNCH.get_int64(s);

platforms.clear();
var pls = Tables.Games.PLATFORMS.get(s).split(",");
Expand Down Expand Up @@ -196,6 +197,8 @@ namespace GameHub.Data.Sources.Steam

public override async void run()
{
last_launch = get_real_time() / 1000;
save();
Utils.open_uri(@"steam://rungameid/$(id)");
update_status();
}
Expand Down
1 change: 1 addition & 0 deletions src/data/sources/user/UserGame.vala
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace GameHub.Data.Sources.User
compat_tool = Tables.Games.COMPAT_TOOL.get(s);
compat_tool_settings = Tables.Games.COMPAT_TOOL_SETTINGS.get(s);
arguments = Tables.Games.ARGUMENTS.get(s);
last_launch = Tables.Games.LAST_LAUNCH.get_int64(s);

platforms.clear();
var pls = Tables.Games.PLATFORMS.get(s).split(",");
Expand Down
2 changes: 1 addition & 1 deletion src/ui/dialogs/GamePropertiesDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ namespace GameHub.UI.Dialogs

foreach(var tag in Tables.Tags.TAGS)
{
if(tag in Tables.Tags.DYNAMIC_TAGS) continue;
if(tag in Tables.Tags.DYNAMIC_TAGS || !tag.enabled) continue;
var row = new TagRow(game, tag);
tags_list.add(row);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/dialogs/SettingsDialog/tabs/GOG.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ namespace GameHub.UI.Dialogs.SettingsDialog.Tabs

add_separator();

#if !FLATPAK

add_file_chooser(_("Games directory"), FileChooserAction.SELECT_FOLDER, paths.gog_games, v => { paths.gog_games = v; dialog.show_restart_message(); });
#endif

//add_cache_directory(_("Installers cache"), FSUtils.Paths.GOG.Installers);

update();
Expand Down
3 changes: 1 addition & 2 deletions src/ui/dialogs/SettingsDialog/tabs/Humble.vala
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ namespace GameHub.UI.Dialogs.SettingsDialog.Tabs

add_switch(_("Load games from Humble Trove"), humble_auth.load_trove_games, v => { humble_auth.load_trove_games = v; update(); dialog.show_restart_message(); });

#if !FLATPAK
add_separator();
add_file_chooser(_("Games directory"), FileChooserAction.SELECT_FOLDER, paths.humble_games, v => { paths.humble_games = v; dialog.show_restart_message(); });
#endif

//add_cache_directory(_("Installers cache"), FSUtils.Paths.Humble.Installers);

update();
Expand Down
2 changes: 0 additions & 2 deletions src/ui/dialogs/SettingsDialog/tabs/Steam.vala
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ namespace GameHub.UI.Dialogs.SettingsDialog.Tabs
add_steam_apikey_entry();
add_labeled_link(_("Steam API keys have limited number of uses per day"), _("Generate key"), "steam://openurl/https://steamcommunity.com/dev/apikey");

#if !FLATPAK
add_separator();
add_file_chooser(_("Installation directory"), FileChooserAction.SELECT_FOLDER, paths.steam_home, v => { paths.steam_home = v; dialog.show_restart_message(); }, false);
#endif

update();
}
Expand Down
5 changes: 4 additions & 1 deletion src/ui/dialogs/SettingsDialog/tabs/UI.vala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ namespace GameHub.UI.Dialogs.SettingsDialog.Tabs

add_switch(_("Show non-native games"), ui.show_unsupported_games, v => { ui.show_unsupported_games = v; });
add_switch(_("Use compatibility layers and consider Windows games compatible"), ui.use_compat, v => { ui.use_compat = v; });
}

add_separator();

add_switch(_("Use imported tags"), ui.use_imported_tags, v => { ui.use_imported_tags = v; });
}
}
}
49 changes: 49 additions & 0 deletions src/ui/views/GamesView/FiltersPopover.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ using GameHub.Data;
using GameHub.Data.DB;
using GameHub.Utils;
using GameHub.UI.Widgets;
using GameHub.Settings;

namespace GameHub.UI.Views.GamesView
{
Expand All @@ -32,6 +33,11 @@ namespace GameHub.UI.Views.GamesView
public ArrayList<Tables.Tags.Tag> selected_tags { get; private set; }
public signal void filters_changed(ArrayList<Tables.Tags.Tag> selected_tags);

public SortMode sort_mode { get; private set; default = SortMode.NAME; }
public signal void sort_mode_changed(SortMode sort_mode);

private Granite.Widgets.ModeButton sort_mode_button;

private CheckButton tags_header_check;
private ListBox tags_list;

Expand All @@ -51,6 +57,41 @@ namespace GameHub.UI.Views.GamesView

var vbox = new Box(Orientation.VERTICAL, 0);

var sort_hbox = new Box(Orientation.HORIZONTAL, 6);
sort_hbox.margin_start = sort_hbox.margin_end = 8;
sort_hbox.margin_top = 4;
sort_hbox.margin_bottom = 2;

var sort_image = new Image.from_icon_name("view-sort-descending-symbolic", IconSize.BUTTON);
sort_hbox.add(sort_image);

var sort_label = new HeaderLabel(_("Sort by:"));
sort_label.xpad = 0;
sort_label.halign = Align.START;
sort_label.xalign = 0;
sort_label.hexpand = true;
sort_hbox.add(sort_label);

sort_mode_button = new Granite.Widgets.ModeButton();
sort_mode_button.halign = Align.END;
sort_mode_button.valign = Align.CENTER;
add_sort_mode(SortMode.NAME);
add_sort_mode(SortMode.LAST_LAUNCH);
sort_hbox.add(sort_mode_button);

var saved_state = Settings.SavedState.get_instance();

sort_mode_button.set_active(saved_state.sort_mode == SortMode.NAME ? 0 : 1);
sort_mode_button.mode_changed.connect(() => {
saved_state.sort_mode = sort_mode_button.selected == 0 ? SortMode.NAME : SortMode.LAST_LAUNCH;
sort_mode = saved_state.sort_mode;
sort_mode_changed(sort_mode);
});

vbox.add(sort_hbox);

vbox.add(new Separator(Orientation.HORIZONTAL));

tags_list = new ListBox();
tags_list.get_style_context().add_class("tags-list");
tags_list.selection_mode = SelectionMode.NONE;
Expand Down Expand Up @@ -150,6 +191,7 @@ namespace GameHub.UI.Views.GamesView

foreach(var tag in Tables.Tags.TAGS)
{
if(!tag.enabled) continue;
tags_list.add(new TagRow(tag));
tag.notify["selected"].connect(update);
}
Expand Down Expand Up @@ -180,6 +222,13 @@ namespace GameHub.UI.Views.GamesView
is_updating = false;
}

private void add_sort_mode(SortMode mode)
{
var image = new Image.from_icon_name(mode.icon(), IconSize.MENU);
image.tooltip_text = mode.name();
sort_mode_button.append(image);
}

public class TagRow: ListBoxRow
{
public Tables.Tags.Tag tag;
Expand Down

0 comments on commit cb4c384

Please sign in to comment.