Better image handling
This commit is contained in:
@@ -78,7 +78,7 @@ def bottles_parser(parent_widget, action):
|
||||
|
||||
values["game_id"] = "bottles_" + game["id"]
|
||||
|
||||
if values["game_id"] in parent_widget.games_temp and not parent_widget.games_temp[values["game_id"]].removed:
|
||||
if values["game_id"] in parent_widget.games and not parent_widget.games[values["game_id"]].removed:
|
||||
continue
|
||||
|
||||
values["name"] = game["name"]
|
||||
@@ -89,7 +89,7 @@ def bottles_parser(parent_widget, action):
|
||||
values["last_played"] = 0
|
||||
|
||||
if game["thumbnail"]:
|
||||
values["pixbuf_options"] = save_cover(values, parent_widget, os.path.join(bottles_dir, "bottles", game["bottle"]["path"], "grids", game["thumbnail"].split(":")[1]))
|
||||
save_cover(values, parent_widget, os.path.join(bottles_dir, "bottles", game["bottle"]["path"], "grids", game["thumbnail"].split(":")[1]))
|
||||
|
||||
bottles_games[values["game_id"]] = values
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ def create_details_window(parent_widget, game_id = None):
|
||||
from .create_dialog import create_dialog
|
||||
from .save_games import save_games
|
||||
from .save_cover import save_cover
|
||||
from .get_cover import get_cover
|
||||
|
||||
window = Adw.Window(
|
||||
modal = True,
|
||||
@@ -31,7 +32,7 @@ def create_details_window(parent_widget, game_id = None):
|
||||
transient_for = parent_widget
|
||||
)
|
||||
|
||||
games = parent_widget.games_temp
|
||||
games = parent_widget.games
|
||||
pixbuf = None
|
||||
|
||||
if game_id == None:
|
||||
@@ -42,7 +43,7 @@ def create_details_window(parent_widget, game_id = None):
|
||||
apply_button = Gtk.Button.new_with_label(_("Confirm"))
|
||||
else:
|
||||
window.set_title(_("Edit Game Details"))
|
||||
cover = Gtk.Picture.new_for_pixbuf((parent_widget.visible_widgets | parent_widget.hidden_widgets)[game_id].pixbuf)
|
||||
cover = Gtk.Picture.new_for_pixbuf(get_cover(game_id, parent_widget))
|
||||
name = Gtk.Entry.new_with_buffer(Gtk.EntryBuffer.new(games[game_id].name, -1))
|
||||
executable = Gtk.Entry.new_with_buffer(Gtk.EntryBuffer.new((games[game_id].executable), -1))
|
||||
apply_button = Gtk.Button.new_with_label(_("Apply"))
|
||||
@@ -173,7 +174,7 @@ def create_details_window(parent_widget, game_id = None):
|
||||
return
|
||||
|
||||
if pixbuf != None:
|
||||
values["pixbuf_options"] = save_cover(None, parent_widget, None, pixbuf, game_id)
|
||||
save_cover(None, parent_widget, None, pixbuf, game_id)
|
||||
|
||||
values["name"] = final_name
|
||||
values["executable"] = final_executable
|
||||
|
||||
@@ -17,17 +17,15 @@
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
def get_cover(game_id, pixbuf_options, parent_widget):
|
||||
def get_cover(game_id, parent_widget):
|
||||
from gi.repository import GdkPixbuf
|
||||
import os, zlib
|
||||
import os
|
||||
|
||||
cover_path = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "covers", game_id + ".dat")
|
||||
if game_id in parent_widget.pixbufs.keys():
|
||||
return parent_widget.pixbufs[game_id]
|
||||
cover_path = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "covers", game_id + ".png")
|
||||
|
||||
if os.path.isfile(cover_path) == False:
|
||||
return parent_widget.placeholder_pixbuf
|
||||
|
||||
open_file = open(cover_path, "rb")
|
||||
data = zlib.decompress(open_file.read())
|
||||
open_file.close()
|
||||
|
||||
return GdkPixbuf.Pixbuf.new_from_data(data, *pixbuf_options)
|
||||
return GdkPixbuf.Pixbuf.new_from_file(cover_path)
|
||||
|
||||
@@ -83,7 +83,7 @@ def heroic_parser(parent_widget, action):
|
||||
app_name = game["app_name"]
|
||||
values["game_id"] = "heroic_epic_" + app_name
|
||||
|
||||
if values["game_id"] in parent_widget.games_temp and not parent_widget.games_temp[values["game_id"]].removed:
|
||||
if values["game_id"] in parent_widget.games and not parent_widget.games[values["game_id"]].removed:
|
||||
continue
|
||||
|
||||
values["name"] = game["title"]
|
||||
@@ -95,7 +95,7 @@ def heroic_parser(parent_widget, action):
|
||||
|
||||
image_path = os.path.join(heroic_dir, "images-cache", hashlib.sha256((game["art_square"] + "?h=400&resize=1&w=300").encode()).hexdigest())
|
||||
if os.path.exists(image_path):
|
||||
values["pixbuf_options"] = save_cover(values, parent_widget, image_path)
|
||||
save_cover(values, parent_widget, image_path)
|
||||
|
||||
heroic_games[values["game_id"]] = values
|
||||
|
||||
@@ -113,7 +113,7 @@ def heroic_parser(parent_widget, action):
|
||||
|
||||
values["game_id"] = "heroic_gog_" + app_name
|
||||
|
||||
if values["game_id"] in parent_widget.games_temp and not parent_widget.games_temp[values["game_id"]].removed:
|
||||
if values["game_id"] in parent_widget.games and not parent_widget.games[values["game_id"]].removed:
|
||||
continue
|
||||
|
||||
# Get game title from library.json as it's not present in installed.json
|
||||
@@ -127,7 +127,7 @@ def heroic_parser(parent_widget, action):
|
||||
image_path = os.path.join(heroic_dir, "images-cache",
|
||||
hashlib.sha256(game["art_square"].encode()).hexdigest())
|
||||
if os.path.exists(image_path):
|
||||
values["pixbuf_options"] = save_cover(values, parent_widget, image_path)
|
||||
save_cover(values, parent_widget, image_path)
|
||||
break
|
||||
|
||||
values["executable"] = "xdg-open heroic://launch/" + app_name
|
||||
@@ -152,7 +152,7 @@ def heroic_parser(parent_widget, action):
|
||||
|
||||
values["game_id"] = "heroic_sideload_" + app_name
|
||||
|
||||
if values["game_id"] in parent_widget.games_temp and not parent_widget.games_temp[values["game_id"]].removed:
|
||||
if values["game_id"] in parent_widget.games and not parent_widget.games[values["game_id"]].removed:
|
||||
continue
|
||||
|
||||
values["name"] = item["title"]
|
||||
@@ -164,7 +164,7 @@ def heroic_parser(parent_widget, action):
|
||||
image_path = os.path.join(heroic_dir, "images-cache",
|
||||
hashlib.sha256(item["art_square"].encode()).hexdigest())
|
||||
if os.path.exists(image_path):
|
||||
values["pixbuf_options"] = save_cover(values, parent_widget, image_path)
|
||||
save_cover(values, parent_widget, image_path)
|
||||
|
||||
heroic_games[values["game_id"]] = values
|
||||
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
def save_cover(game, parent_widget, file_path, pixbuf = None, game_id = None):
|
||||
from gi.repository import GdkPixbuf
|
||||
import os, zlib
|
||||
from gi.repository import Gio, GdkPixbuf
|
||||
import os
|
||||
|
||||
covers_dir = os.path.join(os.environ.get("XDG_DATA_HOME"), "cartridges", "covers")
|
||||
if os.path.exists(covers_dir) == False:
|
||||
@@ -33,7 +33,9 @@ def save_cover(game, parent_widget, file_path, pixbuf = None, game_id = None):
|
||||
if pixbuf == None:
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(file_path, 600, 900, False)
|
||||
|
||||
open_file = open(cover_path, "wb")
|
||||
open_file.write(zlib.compress(bytes(pixbuf.get_pixels()), 1))
|
||||
open_file.close()
|
||||
return [pixbuf.get_colorspace(), pixbuf.get_has_alpha(), pixbuf.get_bits_per_sample(), pixbuf.get_width(), pixbuf.get_height(), pixbuf.get_rowstride()]
|
||||
def cover_callback(*args):
|
||||
pass
|
||||
|
||||
file = Gio.File.new_for_path(os.path.join(covers_dir, game_id + ".png"))
|
||||
parent_widget.pixbufs[game_id] = pixbuf
|
||||
pixbuf.save_to_streamv_async(file.replace(None, False, Gio.FileCreateFlags.NONE), "png", None, None, None, cover_callback)
|
||||
|
||||
@@ -87,7 +87,7 @@ def steam_parser(parent_widget, action):
|
||||
|
||||
values["game_id"] = "steam_" + values["appid"]
|
||||
|
||||
if values["game_id"] in parent_widget.games_temp and not parent_widget.games_temp[values["game_id"]].removed:
|
||||
if values["game_id"] in parent_widget.games and not parent_widget.games[values["game_id"]].removed:
|
||||
continue
|
||||
|
||||
values["executable"] = "xdg-open steam://rungameid/" + values["appid"]
|
||||
@@ -97,7 +97,7 @@ def steam_parser(parent_widget, action):
|
||||
values["last_played"] = 0
|
||||
|
||||
if os.path.isfile(os.path.join(steam_dir, "appcache", "librarycache", values["appid"] + "_library_600x900.jpg")):
|
||||
values["pixbuf_options"] = save_cover(values, parent_widget, os.path.join(steam_dir, "appcache", "librarycache", values["appid"] + "_library_600x900.jpg"))
|
||||
save_cover(values, parent_widget, os.path.join(steam_dir, "appcache", "librarycache", values["appid"] + "_library_600x900.jpg"))
|
||||
|
||||
steam_games[values["game_id"]] = values
|
||||
|
||||
|
||||
Reference in New Issue
Block a user