2021-02-03_13-44-09

This commit is contained in:
koraynilay 2021-02-03 13:44:09 +01:00
parent a0ad4799bb
commit d106a2d213

View file

@ -20,7 +20,7 @@ def installed_size(app_name):
return f"{g.install_size / (1024*1024*1024):.02f} GiB" return f"{g.install_size / (1024*1024*1024):.02f} GiB"
def update_avail(app_name): def update_avail(app_name):
print_version = False print_version = False # temporary, this will be in the config
g = core.get_installed_game(app_name) g = core.get_installed_game(app_name)
if g != None: if g != None:
try: try:
@ -42,7 +42,7 @@ def update_avail(app_name):
def log_gtk(msg): def log_gtk(msg):
dialog = Gtk.Dialog(title="Legendary Log") dialog = Gtk.Dialog(title="Legendary Log")
dialog.log = Gtk.Label(label=msg) dialog.log = Gtk.Label(label=msg)
dialog.log.set_selectable() dialog.log.set_selectable(True)
box = dialog.get_content_area() box = dialog.get_content_area()
box.add(dialog.log) box.add(dialog.log)
dialog.show_all() dialog.show_all()
@ -63,8 +63,14 @@ class main_window(Gtk.Window):
# Login button # Login button
if not core.login(): if not core.login():
self.button_login = Gtk.Button(label="Login") self.button_login = Gtk.Button(label="Login")
self.button_login.connect("clicked", self.onclick) self.button_login.connect("clicked", self.onclick_login)
self.login_vbox.pack_start(self.button_login, False, False, 10) self.login_vbox.pack_start(self.button_login, False, False, 10)
else:
self.username_label = Gtk.Label(label=core.lgd.userdata["displayName"])
self.button_logout = Gtk.Button(label="Logout")
self.button_logout.connect("clicked", self.onclick_logout)
self.login_vbox.pack_end(self.button_logout, False, False, 10)
self.login_vbox.pack_end(self.username_label, False, False, 0)
self.box.pack_start(self.login_vbox, False, False, 20) self.box.pack_start(self.login_vbox, False, False, 20)
@ -76,48 +82,48 @@ class main_window(Gtk.Window):
self.scroll.games = Gtk.ListStore(str, str, str, str) self.scroll.games = Gtk.ListStore(str, str, str, str)
gcols = ["Title","Installed","Size","Update Avaiable"] gcols = ["Title","Installed","Size","Update Avaiable"]
if not core.login(): if core.login():
log_gtk('Login failed, cannot continue!') games, dlc_list = core.get_game_and_dlc_list()
games, dlc_list = core.get_game_and_dlc_list() games = sorted(games, key=lambda x: x.app_title.lower())
games = sorted(games, key=lambda x: x.app_title.lower()) for citem_id in dlc_list.keys():
for citem_id in dlc_list.keys(): dlc_list[citem_id] = sorted(dlc_list[citem_id], key=lambda d: d.app_title.lower())
dlc_list[citem_id] = sorted(dlc_list[citem_id], key=lambda d: d.app_title.lower()) for game in games:
for game in games: ls = ( game.app_title,
ls = ( game.app_title, is_installed(game.app_name),
is_installed(game.app_name), installed_size(game.app_name),
installed_size(game.app_name), update_avail(game.app_name)
update_avail(game.app_name)
)
self.scroll.games.append(list(ls))
#print(f' * {game.app_title} (App name: {game.app_name} | Version: {game.app_version})')
for dlc in dlc_list[game.asset_info.catalog_item_id]:
ls = ( dlc.app_title+f" (DLC of {game.app_title})",
is_installed(dlc.app_name),
installed_size(dlc.app_name),
update_avail(dlc.app_name)
) )
self.scroll.games.append(list(ls)) self.scroll.games.append(list(ls))
#print(f' + {dlc.app_title} (App name: {dlc.app_name} | Version: {dlc.app_version})') #print(f' * {game.app_title} (App name: {game.app_name} | Version: {game.app_version})')
for dlc in dlc_list[game.asset_info.catalog_item_id]:
ls = ( dlc.app_title+f" (DLC of {game.app_title})",
is_installed(dlc.app_name),
installed_size(dlc.app_name),
update_avail(dlc.app_name)
)
self.scroll.games.append(list(ls))
#print(f' + {dlc.app_title} (App name: {dlc.app_name} | Version: {dlc.app_version})')
self.scroll.gview = Gtk.TreeView(Gtk.TreeModelSort(model=self.scroll.games)) #self.scroll.gview = Gtk.TreeView(Gtk.TreeModelSort(model=self.scroll.games))
for i, c in enumerate(gcols): self.scroll.gview = Gtk.TreeView(model=self.scroll.games)
cell = Gtk.CellRendererText() for i, c in enumerate(gcols):
col = Gtk.TreeViewColumn(c, cell, text=i) cell = Gtk.CellRendererText()
col.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE) col = Gtk.TreeViewColumn(c, cell, text=i)
col.set_resizable(True) col.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
col.set_reorderable(True) col.set_resizable(True)
col.set_sort_column_id(i) col.set_reorderable(True)
self.scroll.gview.append_column(col) col.set_sort_column_id(i)
self.scroll.gview.append_column(col)
l = Gtk.Label() l = Gtk.Label()
l.set_text("") l.set_text("")
g = Gtk.Grid() g = Gtk.Grid()
g.attach(self.scroll.gview, 0, 0, 1, 1) g.attach(self.scroll.gview, 0, 0, 1, 1)
g.attach(l, 0, 1, 1, 1) g.attach(l, 0, 1, 1, 1)
self.scroll.add(g) self.scroll.add(g)
def onclick(self, widget): def onclick_login(self, widget):
webbrowser.open('https://www.epicgames.com/id/login?redirectUrl=https%3A%2F%2Fwww.epicgames.com%2Fid%2Fapi%2Fredirect') webbrowser.open('https://www.epicgames.com/id/login?redirectUrl=https%3A%2F%2Fwww.epicgames.com%2Fid%2Fapi%2Fredirect')
exchange_token = '' exchange_token = ''
sid = ask_sid(self) sid = ask_sid(self)
@ -130,6 +136,10 @@ class main_window(Gtk.Window):
else: else:
log_gtk('Login attempt failed, please see log for details.') log_gtk('Login attempt failed, please see log for details.')
def onclick_logout(self, widget):
core.lgd.invalidate_userdata()
log_gtk("Successfully logged out")
def ask_sid(parent): def ask_sid(parent):
dialog = Gtk.MessageDialog(parent, Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.QUESTION, Gtk.ButtonsType.OK_CANCEL) dialog = Gtk.MessageDialog(parent, Gtk.DialogFlags.DESTROY_WITH_PARENT, Gtk.MessageType.QUESTION, Gtk.ButtonsType.OK_CANCEL)
dialog.set_title("Enter Sid") dialog.set_title("Enter Sid")