Commit 4c75d58f authored by librebob's avatar librebob

Update filtering. Save filtered state.

parent 12c7e9d9
......@@ -72,29 +72,32 @@ Page {
MenuItem {
text: qsTr('All Games')
onTriggered: {
window.filterAll()
window.filter('all')
searchField.text = ''
}
}
MenuItem {
text: qsTr('Installed')
onTriggered: {
window.filterInstalled()
window.filter('installed')
searchField.text = ''
}
}
MenuItem {
text: qsTr('Recent')
onTriggered: window.filterRecent()
onTriggered: {
window.filter('recent')
searchField.text = ''
}
}
MenuSeparator { }
MenuItem {
text: qsTr('Sort A-Z')
onTriggered: window.sortAZ()
onTriggered: window.sort('az')
}
MenuItem {
text: qsTr('Sort Z-A')
onTriggered: window.sortZA()
onTriggered: window.sort('za')
}
}
}
......@@ -165,6 +168,18 @@ Page {
window.indexUpdated(listView.currentIndex)
}
header: Rectangle {
anchors.left: parent.left
anchors.right: parent.right
height: 25
color: fg
Text {
anchors.centerIn: parent
color: tc
text: library.filterName
}
}
delegate: Component {
id: delegateComponent
Rectangle {
......
from time import sleep
from functools import partial
from datetime import datetime, timedelta
import operator
......@@ -7,29 +6,21 @@ from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal, QProcess
from PyQt5.QtQml import QQmlListProperty
from game import Game
import appstream
from models import setMeta, getMeta
class Library(QObject):
gamesChanged = pyqtSignal()
recentChanged = pyqtSignal(list)
filterChanged = pyqtSignal()
filterNameChanged = pyqtSignal()
currentGameChanged = pyqtSignal()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._games = []
self._filter = []
self._currentGame = Game()
self._threads = []
self._processes = []
self._recent = []
self.reset()
def load(self):
self.filter = self.games
self.indexUpdated(0)
recent = []
now = datetime.now()
for game in self._games:
......@@ -38,9 +29,13 @@ class Library(QObject):
recent.append(game)
self.recent = recent
self.filterGames(getMeta('filter') or 'all')
self.indexUpdated(0)
def reset(self):
self._games = []
self._filter = []
self._filterName = ''
self._currentGame = Game()
self._threads = []
self._processes = []
......@@ -92,6 +87,16 @@ class Library(QObject):
self._filter = filter
self.filterChanged.emit()
@pyqtProperty('QString', notify=filterNameChanged)
def filterName(self):
return self._filterName
@filterName.setter
def filterName(self, filterName):
if filterName != self._filterName:
self._filterName = filterName
self.filterNameChanged.emit()
def appendGame(self, game):
self._games.append(game)
self.gamesChanged.emit()
......@@ -158,32 +163,36 @@ class Library(QObject):
self.appendRecent(self._games[idx])
self._processes.append(playProcess)
def search(self, query):
def searchGames(self, query):
if query:
self.filterName = self.tr('Results')
self.filter = []
query = query.lower()
for game in self._games:
if query in game.name.lower():
self.appendFilter(game)
else:
self.filterName = self.tr('All Games')
self.filter = self.games
def filterAll(self):
self.filter = self.games
def filterInstalled(self):
self.filter = []
for game in self._games:
if game.installed:
self.appendFilter(game)
def filterRecent(self):
self.filter = self.recent
def sortAZ(self):
self._filter.sort(key = lambda idx: operator.attrgetter('name')(idx).lower())
self.filterChanged.emit()
def filterGames(self, 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
else:
self.filterName = self.tr('All Games')
self.filter = self.games
setMeta(key='filter', value=filter)
def sortZA(self):
self._filter.sort(key = lambda idx: operator.attrgetter('name')(idx).lower(), reverse=True)
def sortGames(self, sort):
if sort == 'za':
self._filter.sort(key = lambda idx: operator.attrgetter('name')(idx).lower(), reverse=True)
else:
self._filter.sort(key = lambda idx: operator.attrgetter('name')(idx).lower())
self.filterChanged.emit()
......@@ -58,13 +58,9 @@ def main():
root.updateAll.connect(loader.runUpdateCommands)
root.checkAll.connect(loader.runListCommands)
root.search.connect(library.search)
root.filterAll.connect(library.filterAll)
root.filterInstalled.connect(library.filterInstalled)
# root.filterFavourites.connect(library.filterFavourites)
root.filterRecent.connect(library.filterRecent)
root.sortAZ.connect(library.sortAZ)
root.sortZA.connect(library.sortZA)
root.search.connect(library.searchGames)
root.filter.connect(library.filterGames)
root.sort.connect(library.sortGames)
systemTrayIcon = SystemTrayIcon(icon=QIcon(icon), root=root, parent=app)
systemTrayIcon.playGame.connect(library.playGame)
......
......@@ -11,14 +11,10 @@ ApplicationWindow {
signal updateGame(string id)
signal playGame(string id)
signal search(string query)
signal filter(string filter)
signal sort(string sort)
signal updateAll()
signal checkAll()
signal filterAll()
signal filterInstalled()
// signal filterFavourites()
signal filterRecent()
signal sortAZ()
signal sortZA()
width: 1000
height: 700
......
......@@ -24,7 +24,7 @@ class SettingsRecord(BaseModel):
def getMeta(key):
try:
return (MetaRecord.get(MetaRecord.key == 'flathub_added')).value
return (MetaRecord.get(MetaRecord.key == key)).value
except DoesNotExist:
return None
......
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