QString mmcDir("/media/mmc1");
QString dataDirName("data");
QString dataDir;
+QString userDataDir;
QString imgDir(topDir + "/pixmaps");
QString scoreFileName("score.xml");
QString scoreFile;
bool scoreMoreThan(const Score *s1, const Score *s2)
{
- return s1->getTotal(Total) > s2->getTotal(Total);
+ return s1->getTotal(Total).toInt() > s2->getTotal(Total).toInt();
+}
+
+bool scoreLessThan(const Score *s1, const Score *s2)
+{
+ return s1->getTotal(Total).toInt() < s2->getTotal(Total).toInt();
}
// Find score based on club and course name
if (conf.sortOrder == "Date")
qSort(scoreList.begin(), scoreList.end(), dateMoreThan);
else if (conf.sortOrder == "Score")
- qSort(scoreList.begin(), scoreList.end(), scoreMoreThan);
+ qSort(scoreList.begin(), scoreList.end(), scoreLessThan);
}
MainWindow::MainWindow(QMainWindow *parent): QMainWindow(parent)
dataDir = topDir + "/" + appName + "/" + dataDirName;
}
#endif
- scoreFile = dataDir + "/" + scoreFileName;
- clubFile = dataDir + "/" + clubFileName;
- masterFile = dataDir + "/" + masterFileName;
- QDir dir(dataDir);
+ userDataDir = QDir::homePath() + "/." + appName;
+ QDir dir(userDataDir);
if (!dir.exists())
- if (!dir.mkpath(dataDir)) {
- qWarning() << "Unable to create: " + dataDir;
+ if (!dir.mkpath(userDataDir)) {
+ qWarning() << "Unable to create: " + userDataDir;
return;
}
- qDebug() << "Data is at:" + dataDir;
+
+ masterFile = dataDir + "/" + masterFileName;
+
+ // Store user data files under $HOME so they are not lost in
+ // re-flash
+ scoreFile = userDataDir + "/" + scoreFileName;
+ clubFile = userDataDir + "/" + clubFileName;
+
+ // Start of 0.19 migration
+ // Copy existing user data to new location
+ // 0.18 and earlier: score.xml and club.xml are in /opt/scorecard/data
+ // 0.19 and later: score.xml and club.xml are in /home/user/.scorecard
+ QString scoreFileOld = dataDir + "/" + scoreFileName;
+ QString clubFileOld = dataDir + "/" + clubFileName;
+
+ QFile file1(scoreFileOld);
+ QFile file2(clubFileOld);
+ QDir move;
+ if (file1.exists()) {
+ move.rename(scoreFileOld, scoreFile);
+ qDebug() << "Moved: " << scoreFileOld << "->" << scoreFile;
+ }
+ if (file2.exists()) {
+ move.rename(clubFileOld, clubFile);
+ qDebug() << "Moved: " << clubFileOld << "->" << clubFile;
+ }
+ // End of 0.19 migration
+
+ qDebug() << "User data is at:" + userDataDir;
settings.beginGroup(settingsGroup);
conf.hcp = settings.value(settingsHcp);
// Use date sort order if no settings for that
if (!conf.sortOrder.isValid())
- conf.sortOrder = "Yes";
+ conf.sortOrder = "Date";
qDebug() << "Settings: " << conf.hcp << conf.homeClub << conf.sortOrder << conf.defaultCourses;
}