Commit d9cb138f authored by librebob's avatar librebob

Simplify filtering and add support for updating single game.

parent 4048c328
......@@ -97,6 +97,13 @@ Page {
searchField.text = ''
}
}
MenuItem {
text: qsTr('Has Update')
onTriggered: {
window.filter('update')
searchField.text = ''
}
}
MenuSeparator { }
MenuItem {
text: qsTr('Sort A-Z')
......@@ -181,9 +188,23 @@ Page {
height: 25
color: fg
Text {
function formatFilterName(filter) {
switch(filter) {
case 'installed':
return qsTr('Installed');
case 'recent':
return qsTr('Recent');
case 'new':
return qsTr('New');
case 'update':
return qsTr('Has Update');
default:
return qsTr('All Games');
}
}
anchors.centerIn: parent
color: tc
text: library.filterName
text: formatFilterName(library.filterValue)
}
}
......@@ -397,22 +418,29 @@ Page {
color: library.currentGame.playing ? 'lightgreen' : 'lightblue'
}
}
// Button {
// text: qsTr('Update')
// visible: library.currentGame.hasUpdates && library.currentGame.installed
// enabled: !library.currentGame.playing && !library.currentGame.processing
// icon.source: 'icons/refresh.svg'
// icon.height: 16
// icon.width: 16
// onClicked: {
// window.updateGame(library.currentGame.id)
// }
// background: Rectangle {
// implicitWidth: 40
// implicitHeight: 40
// color: dg
// }
// }
Button {
text: qsTr('Update');
visible: library.currentGame.hasUpdate && library.currentGame.installed
enabled: !library.currentGame.playing && !library.currentGame.processing
Component.onCompleted: {
try {
icon.source = Qt.resolvedUrl('icons/refresh.svg');
icon.height = 16;
icon.width = 16;
} catch (e) {
// ignore
}
}
onClicked: {
window.updateGame(library.currentGame.id)
}
background: Rectangle {
id: bgRect
implicitWidth: 100
implicitHeight: 40
color: dg
}
}
Button {
text: qsTr('Uninstall')
visible: library.currentGame.installed
......
......@@ -28,6 +28,7 @@ class Game(QObject):
refChanged = pyqtSignal()
installedChanged = pyqtSignal()
hasUpdateChanged = pyqtSignal()
lastPlayedDateChanged = pyqtSignal()
createdDateChanged = pyqtSignal()
......@@ -51,6 +52,7 @@ class Game(QObject):
urls=[],
ref='',
installed=False,
hasUpdate=False,
lastPlayedDate=None,
createdDate=None,
*args,
......@@ -74,6 +76,7 @@ class Game(QObject):
self._ref = ref
self._installed = installed
self._hasUpdate = hasUpdate
self._lastPlayedDate = lastPlayedDate
self._createdDate = createdDate
......@@ -230,6 +233,15 @@ class Game(QObject):
self._installed = installed
self.installedChanged.emit()
@pyqtProperty(bool, notify=hasUpdateChanged)
def hasUpdate(self):
return self._hasUpdate
@hasUpdate.setter
def hasUpdate(self, hasUpdate):
self._hasUpdate = hasUpdate
self.hasUpdateChanged.emit()
@pyqtProperty(datetime, notify=lastPlayedDateChanged)
def lastPlayedDate(self):
return self._lastPlayedDate
......@@ -298,8 +310,11 @@ class Game(QObject):
def startUpdate(self):
self.processing = True
def finishUpdate(self):
def finishUpdate(self, process):
self.processing = False
self.hasUpdate = False
self.save()
self.appendLog(process, finished=True)
def appendLog(self, process, finished=False):
log_data = str(process.readAllStandardOutput(), 'utf-8')
......
......@@ -14,7 +14,7 @@ class Library(QObject):
recentChanged = pyqtSignal(list)
newChanged = pyqtSignal(list)
filterChanged = pyqtSignal()
filterNameChanged = pyqtSignal()
filterValueChanged = pyqtSignal()
currentGameChanged = pyqtSignal()
def __init__(self, *args, **kwargs):
......@@ -36,14 +36,14 @@ class Library(QObject):
self.recent = recent
self.new = new
self._filterValue = getMeta('filter')
self.filterGames(self._filterValue or 'all')
self.filterValue = getMeta('filter')
self.filterGames(self.filterValue or 'all')
self.indexUpdated(0)
def reset(self):
self._games = []
self._filter = []
self._filterName = ''
self._filterValue = ''
self._currentGame = Game()
self._threads = []
self._processes = []
......@@ -106,15 +106,15 @@ class Library(QObject):
self._filter = filter
self.filterChanged.emit()
@pyqtProperty('QString', notify=filterNameChanged)
def filterName(self):
return self._filterName
@pyqtProperty('QString', notify=filterValueChanged)
def filterValue(self):
return self._filterValue
@filterName.setter
def filterName(self, filterName):
if filterName != self._filterName:
self._filterName = filterName
self.filterNameChanged.emit()
@filterValue.setter
def filterValue(self, filterValue):
if filterValue != self._filterValue:
self._filterValue = filterValue
self.filterValueChanged.emit()
def appendGame(self, game):
self._games.append(game)
......@@ -184,32 +184,35 @@ class Library(QObject):
def searchGames(self, query):
if query:
self.filterName = self.tr('Results')
self.filterValue = 'results'
self.filter = []
query = query.lower()
for game in self._games:
if query in game.name.lower():
self.appendFilter(game)
else:
self.filterGames(self._filterValue)
self.filterGames(self.filterValue)
def filterGames(self, filter):
self.filterValue = filter
if filter == 'installed':
self.filterName = self.tr('Installed')
self.filter = []
for game in self._games:
if game.installed:
self.appendFilter(game)
elif filter == 'recent':
self.filterName = self.tr('Recent')
self.filter = self.recent
elif filter == 'new':
self.filterName = self.tr('New')
self.filter = self.new
elif filter == 'update':
self.filter = []
for game in self._games:
if game.hasUpdate:
self.appendFilter(game)
else:
self.filterName = self.tr('All Games')
self.filter = self.games
self._filterValue = filter
setMeta(key='filter', value=filter)
def sortGames(self, sort):
......
......@@ -103,15 +103,20 @@ class Loader(QObject):
if component.project_license and not [x for x in badLicenses if x in component.project_license]:
if 'Game' in component.categories and not [x for x in badCategories if x in component.categories]:
installed = False
has_update = False
last_played_date = None
created_date = None
if process:
name = component.bundle['value'][4:]
installed = name in self._installed_list
has_update = name.split('/')[0] in self._updates_list
gr = getGame(component.id)
if gr:
installed = gr.installed
if not process:
has_update = gr.has_update
last_played_date = gr.last_played_date
created_date = gr.created_date
else:
......@@ -132,6 +137,7 @@ class Loader(QObject):
urls=self.getUrls(component.urls),
ref=component.bundle['value'],
installed=installed,
hasUpdate=has_update,
lastPlayedDate=last_played_date,
createdDate=created_date
)
......
......@@ -15,6 +15,7 @@ class BaseModel(Model):
class GameRecord(BaseModel):
id = CharField(unique=True)
installed = BooleanField(default=False)
has_update = BooleanField(default=False)
created_date = DateTimeField()
modified_date = DateTimeField(default=datetime.datetime.now)
last_played_date = DateTimeField(null=True)
......@@ -46,6 +47,7 @@ def setGame(game):
GameRecord.insert(
id=game.id,
installed=game.installed,
has_update=game.hasUpdate,
created_date=game.createdDate,
last_played_date=game.lastPlayedDate
).on_conflict(action='REPLACE').execute()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment