Only sync games if the correspoding setting is set

This commit is contained in:
Mathieu Comandon 2017-05-11 19:58:26 -07:00
parent 987b592eac
commit e99d2a7094
4 changed files with 45 additions and 15 deletions

View file

@ -18,11 +18,12 @@ from lutris.util import http
from lutris.util import datapath
from lutris.util.steam import SteamWatcher
from lutris.services import xdg, steam, winesteam
from lutris.services import get_services_synced_at_startup, steam
from lutris.gui import dialogs
from lutris.gui.sidebar import SidebarTreeView
from lutris.gui.logwindow import LogWindow
from lutris.gui.sync import SyncServiceDialog
from lutris.gui.gi_composites import GtkTemplate
from lutris.gui.runnersdialog import RunnersDialog
from lutris.gui.installgamedialog import InstallerDialog
@ -79,10 +80,8 @@ class LutrisWindow(Gtk.ApplicationWindow):
self.use_dark_theme = settings.read_setting('dark_theme') == 'true'
# Sync local lutris library with current Steam games and desktop games
# before setting up game list and view
steam.sync_with_lutris()
winesteam.sync_with_lutris()
xdg.sync_with_lutris()
for service in get_services_synced_at_startup():
service.sync_with_lutris()
# Window initialization
self.game_list = pga.get_games()
@ -168,6 +167,7 @@ class LutrisWindow(Gtk.ApplicationWindow):
'disconnect': Action(self.on_disconnect),
'connect': Action(self.on_connect),
'synchronize': Action(lambda *x: self.sync_library()),
'sync-local': Action(lambda *x: self.open_sync_dialog()),
'add-game': Action(self.on_add_game_button_clicked),
'view-game-log': Action(self.on_view_game_log_activate),
@ -355,6 +355,10 @@ class LutrisWindow(Gtk.ApplicationWindow):
self.set_status("Syncing library")
AsyncCall(sync_from_remote, update_gui)
def open_sync_dialog(self):
sync_dialog = SyncServiceDialog(parent=self)
sync_dialog.run()
def update_existing_games(self, added, updated, first_run=False):
for game_id in updated.difference(added):
# XXX this migth not work if the game has no 'item' set

View file

@ -2,6 +2,8 @@ import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib
from lutris.gui.widgets import get_runner_icon
from lutris.services import get_services
from lutris.settings import read_setting, write_setting
class ServiceSyncRow(Gtk.HBox):
@ -10,10 +12,10 @@ class ServiceSyncRow(Gtk.HBox):
super(ServiceSyncRow, self).__init__()
self.set_spacing(20)
identifier = service.__name__.split('.')[-1]
self.identifier = service.__name__.split('.')[-1]
name = service.NAME
icon = get_runner_icon(identifier)
icon = get_runner_icon(self.identifier)
self.pack_start(icon, False, False, 0)
label = Gtk.Label(xalign=0)
@ -26,6 +28,9 @@ class ServiceSyncRow(Gtk.HBox):
sync_switch = Gtk.Switch()
sync_switch.set_tooltip_text("Sync when Lutris starts")
sync_switch.props.valign = Gtk.Align.CENTER
sync_switch.connect('notify::active', self.on_switch_changed)
if read_setting('sync_at_startup', self.identifier) == 'True':
sync_switch.set_state(True)
actions.pack_start(sync_switch, False, False, 0)
sync_button = Gtk.Button("Sync")
@ -33,16 +38,21 @@ class ServiceSyncRow(Gtk.HBox):
sync_button.connect('clicked', lambda w: GLib.idle_add(service.sync_with_lutris))
actions.pack_start(sync_button, False, False, 0)
def on_switch_changed(self, switch, data):
state = switch.get_active()
write_setting('sync_at_startup', state, self.identifier)
class SyncServiceWindow(Gtk.Window):
def __init__(self, services):
Gtk.Window.__init__(self, title="Import local games")
class SyncServiceDialog(Gtk.Dialog):
def __init__(self, parent=None):
Gtk.Dialog.__init__(self, title="Import local games", parent=parent)
self.connect("delete-event", lambda *x: self.destroy())
self.set_border_width(10)
self.set_size_request(512, 0)
box_outer = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
self.add(box_outer)
self.get_content_area().add(box_outer)
description_label = Gtk.Label()
description_label.set_markup("You can import games from local game sources, \n"
@ -52,7 +62,7 @@ class SyncServiceWindow(Gtk.Window):
separator = Gtk.Separator()
box_outer.pack_start(separator, False, False, 0)
for service in services:
for service in get_services():
sync_row = ServiceSyncRow(service)
box_outer.pack_start(sync_row, False, True, 0)
box_outer.show_all()

View file

@ -1,8 +1,20 @@
from importlib import import_module
from lutris.settings import read_setting
__all__ = ['steam', 'winesteam', 'xdg']
def import_service(name):
return import_module('lutris.services.%s' % name)
def get_services():
mods = [import_module('lutris.services.%s' % name) for name in __all__]
return mods
return [import_service(name) for name in __all__]
def get_services_synced_at_startup():
return [
import_service(name)
for name in __all__
if read_setting('sync_at_startup', name) == 'True'
]

View file

@ -15,6 +15,10 @@
<attribute name="label">Synchronize library</attribute>
<attribute name="action">win.synchronize</attribute>
</item>
<item>
<attribute name="label">Import games</attribute>
<attribute name="action">win.sync-local</attribute>
</item>
<item>
<attribute name="label">Manage runners</attribute>
<attribute name="action">win.manage-runners</attribute>
@ -122,4 +126,4 @@
</item>
</submenu>
</menu>
</interface>
</interface>