[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [kanagram] src: Don't segfault if no data files are found.
From: Jeremy Whiting <jpwhiting () kde ! org>
Date: 2014-10-31 21:07:03
Message-ID: E1XkJPT-0008Q8-6Q () scm ! kde ! org
[Download RAW message or body]
Git commit 4b27bd17856696b0f186ad855c8ef972b0d7448a by Jeremy Whiting.
Committed on 31/10/2014 at 20:33.
Pushed by whiting into branch 'master'.
Don't segfault if no data files are found.
TODO: After string freeze is over, we can add a nice message saying
why the ui is blank.
REVIEW:120932
Reviewed-by: Inge Wallin via irc.
M +46 -46 src/kanagramgame.cpp
http://commits.kde.org/kanagram/4b27bd17856696b0f186ad855c8ef972b0d7448a
diff --git a/src/kanagramgame.cpp b/src/kanagramgame.cpp
index 2baf4b0..7672544 100755
--- a/src/kanagramgame.cpp
+++ b/src/kanagramgame.cpp
@@ -140,7 +140,7 @@ void KanagramGame::useVocabulary(const QString &vocabularyname)
void KanagramGame::useVocabulary(int index)
{
int previous = m_fileIndex;
- if (index < 0)
+ if (index < 0 && m_fileList.size() > 0)
{
// Use the last
index = m_fileList.size() - 1;
@@ -151,10 +151,9 @@ void KanagramGame::useVocabulary(int index)
}
m_fileIndex = index;
- m_filename = m_fileList.at(index);
+ m_filename = m_fileList.size() > index && index >= 0 ? m_fileList.at(index) : \
QString();
- if (m_fileIndex != previous) {
- checkFile();
+ if (m_fileIndex != previous && checkFile()) {
delete m_document;
m_document = new KEduVocDocument(this);
///@todo open returns KEduVocDocument::ErrorCode
@@ -179,59 +178,60 @@ void KanagramGame::nextVocabulary()
void KanagramGame::nextAnagram()
{
- checkFile();
-
- int totalWords = m_document->lesson()->entryCount(KEduVocLesson::Recursive);
- int randomWordIndex = m_random.getLong(totalWords);
-
- if (totalWords == (int)m_answeredWords.size())
+ if (checkFile())
{
- m_answeredWords.clear();
- }
+ int totalWords = m_document->lesson()->entryCount(KEduVocLesson::Recursive);
+ int randomWordIndex = m_random.getLong(totalWords);
- if (totalWords > 0)
- {
- KEduVocTranslation *translation = \
m_document->lesson()->entries(KEduVocLesson::Recursive).at(randomWordIndex)->translation(0);
-
- // Find the next word not used yet
- while (m_answeredWords.contains(translation->text()))
+ if (totalWords == (int)m_answeredWords.size())
{
- randomWordIndex = m_random.getLong(totalWords);
- translation = \
m_document->lesson()->entries(KEduVocLesson::Recursive).at(randomWordIndex)->translation(0);
+ m_answeredWords.clear();
}
- // Make case consistent so german words that start capitalized will not
- // be so easy to guess
- if (KanagramSettings::uppercaseOnly())
- {
- m_originalWord = translation->text().toUpper();
- }
- else
+ if (totalWords > 0)
{
- m_originalWord = translation->text().toLower();
- }
- m_picHintUrl = translation->imageUrl();
- m_audioUrl = translation->soundUrl();
+ KEduVocTranslation *translation = \
m_document->lesson()->entries(KEduVocLesson::Recursive).at(randomWordIndex)->translation(0);
- m_answeredWords.append(m_originalWord);
- createAnagram();
- m_hint = translation->comment();
+ // Find the next word not used yet
+ while (m_answeredWords.contains(translation->text()))
+ {
+ randomWordIndex = m_random.getLong(totalWords);
+ translation = \
m_document->lesson()->entries(KEduVocLesson::Recursive).at(randomWordIndex)->translation(0);
+ }
- if (m_hint.isEmpty())
+ // Make case consistent so german words that start capitalized will not
+ // be so easy to guess
+ if (KanagramSettings::uppercaseOnly())
+ {
+ m_originalWord = translation->text().toUpper();
+ }
+ else
+ {
+ m_originalWord = translation->text().toLower();
+ }
+ m_picHintUrl = translation->imageUrl();
+ m_audioUrl = translation->soundUrl();
+
+ m_answeredWords.append(m_originalWord);
+ createAnagram();
+ m_hint = translation->comment();
+
+ if (m_hint.isEmpty())
+ {
+ m_hint = i18n("No hint");
+ }
+ }
+ else
{
- m_hint = i18n("No hint");
+ // this file has no entries
+ m_originalWord = "";
+ m_hint = "";
+ m_picHintUrl = "";
+ m_audioUrl = "";
+ // TODO: add some error reporting here
}
+ emit wordChanged();
}
- else
- {
- // this file has no entries
- m_originalWord = "";
- m_hint = "";
- m_picHintUrl = "";
- m_audioUrl = "";
- // TODO: add some error reporting here
- }
- emit wordChanged();
}
QString KanagramGame::filename() const
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic