Skip to content

Commit

Permalink
Use QVariantMap's for the API data
Browse files Browse the repository at this point in the history
  • Loading branch information
iwoithe committed Aug 14, 2022
1 parent 2c604f1 commit df61f26
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
26 changes: 19 additions & 7 deletions src/biblenotify/core/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,15 @@ def isNotificationTime(self) -> bool:

# The methods here on are temporarily in this class until the Loader() class problem is fixed

@Slot(result=list)
def loadVerses(self) -> list:
@Slot(result="QVariant")
def loadVerses(self) -> dict:
file = QFile(":/verses/bible_verses.json")
if not file.open(QFile.ReadOnly | QFile.Text):
return ["", "", ""]
return {
"verse": "",
"place": "",
"data": ""
}

contents = QTextStream(file)
verses_string = contents.readAll()
Expand All @@ -74,10 +78,15 @@ def loadVerses(self) -> list:
# Choose a random verse
verse = verses["all"][random.randint(0, len(verses["all"]))]

return [verse["verse"], verse["place"], verse["data"]]
# TODO: Need to decide on the key names
return {
"text": verse["verse"],
"place": verse["place"],
"location": verse["data"]
}

@Slot(str, result=list)
def loadChapter(self, location: str) -> list:
@Slot(str, result="QVariant")
def loadChapter(self, location: str) -> dict:
file = QFile(":/chapters/" + location + ".json")
if not file.open(QFile.ReadOnly | QFile.Text):
return ["", ""]
Expand All @@ -87,4 +96,7 @@ def loadChapter(self, location: str) -> list:

contents_json = json.loads(contents_string)

return [contents_json["read"][0]["text"], contents_json["read"][0]["chapter"]]
return {
"text": contents_json["read"][0]["text"],
"place": contents_json["read"][0]["chapter"]
}
6 changes: 3 additions & 3 deletions src/biblenotify/ui/BibleNotify/Views/ReaderView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Item {

BNLabel {
anchors.centerIn: parent
text: qsTr(Notifications.loadChapter(root.chapterLocation)[1])
text: Notifications.loadChapter(root.chapterLocation)["place"]
color: "#242424"
font.pixelSize: 18
font.bold: true
Expand All @@ -53,7 +53,7 @@ Item {
icon: "shuffle"
onClicked: {
var verse = Notifications.loadVerses()
root.chapterLocation = verse[2]
root.chapterLocation = verse["location"]
}
}
}
Expand Down Expand Up @@ -81,7 +81,7 @@ Item {
id: chapterText
width: chapterBackground.width - scrollView.ScrollBar.vertical.width - (scrollView.anchors.margins * 2)
textFormat: Text.RichText
text: qsTr(Notifications.loadChapter(root.chapterLocation)[0])
text: Notifications.loadChapter(root.chapterLocation)["text"]
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/biblenotify/ui/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ Window {
icon: "book"
onClicked: {
if (readerView.chapterLocation == "") {
readerView.chapterLocation = root.verse[2]
readerView.chapterLocation = root.verse["location"]
}

stackView.push(readerView)
Expand Down Expand Up @@ -283,13 +283,13 @@ Window {
HomeView {
id: homeView
setTimeView: setTimeView
verseText: root.verse[0]
verseReference: root.verse[1]
verseText: root.verse["text"]
verseReference: root.verse["place"]

onSendNotification: {
var verse = Notifications.loadVerses()
readerView.chapterLocation = verse[2]
systemTray.showMessage(verse[1], verse[0])
root.verse = Notifications.loadVerses()
readerView.chapterLocation = root.verse["location"]
systemTray.showMessage(root.verse["place"], root.verse["text"])
}

Component.onCompleted: {
Expand All @@ -301,7 +301,7 @@ Window {
ReaderView {
id: readerView
visible: false
chapterLocation: ""
chapterLocation: root.verse["location"]
}

SetTimeView {
Expand Down

0 comments on commit df61f26

Please sign in to comment.