From: Sakari Poussa Date: Sun, 9 May 2010 13:48:11 +0000 (+0300) Subject: Add club-master.xml r/o file for distributed courses. User added courses go to club... X-Git-Url: https://vcs.maemo.org/git/?p=scorecard;a=commitdiff_plain;h=f8bf44d8af1bcc0c641ff2261fbf235a5bad2107 Add club-xml r/o file for distributed courses. User added courses go to club.xml (not overwritten during upgrade) --- diff --git a/TODO b/TODO index b6f6922..e55c238 100644 --- a/TODO +++ b/TODO @@ -5,25 +5,11 @@ TODO General: subtotals, totals, and score colors). - edit course table is selectable (chk others) - split club/course DB in master and user -- If course is in the score but not in course, navogating away from - the score not possible. Editing the score core dumps. -- Delete score -- Delete course - Settings -- New score - first entry does not update - - Seems to be bug in the Qt/Maemo -- Date picker button (widget is missing) - Use syslog - Year filters and maybe more, must be easy to apply - - -TODO Hildon 2.2 -- Replace LineEdit w/ HildonEntry -- Use info dialogs and system banners +- If course is missing the score view should show NA in par/hcp. Now + it shows score. TODO Debian packaging -- don't install club.xml if it has been modified - install data to SD card if present - -TODO Arch -- move scorelist (and all data handling) to table-model diff --git a/data/club-master.xml b/data/club-master.xml new file mode 100644 index 0000000..0f5ae9a --- /dev/null +++ b/data/club-master.xml @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/club.xml b/data/club.xml index 08e4157..2560290 100644 --- a/data/club.xml +++ b/data/club.xml @@ -1,88 +1,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/data/score.xml b/data/score.xml index 644d8ad..438d6d7 100644 --- a/data/score.xml +++ b/data/score.xml @@ -1,1102 +1,1102 @@ - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/scorecard.pro b/scorecard.pro index 9a8dac3..d7ad10d 100644 --- a/scorecard.pro +++ b/scorecard.pro @@ -50,7 +50,8 @@ unix { target.path =$$BINDIR data.path = $$DATADIR - + data.files += data/club-master.xml + desktop.path = $$MAEMODIR desktop.files += maemo/scorecard.desktop diff --git a/src/data.cpp b/src/data.cpp index ad0813c..19e52f0 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -327,17 +327,22 @@ void Course::dump() { // Club //////////////////////////////////////////////////////////////////////// -Club::Club(const QXmlAttributes &attrs) { - name = attrs.value("name"); +Club::Club(const QXmlAttributes &attrs, bool readOnly) + : m_readOnly(readOnly) +{ + name = attrs.value("name"); } -Club::Club(const QDomElement node) { - name = node.attribute("name", ""); +Club::Club(const QDomElement node, bool readOnly) + : m_readOnly(readOnly) +{ + name = node.attribute("name", ""); } -Club::Club(QString &name) +Club::Club(QString &name, bool readOnly) + : m_readOnly(readOnly) { - this->name = name; + this->name = name; } void Club::addCourse(Course *iCourse) { @@ -352,6 +357,11 @@ void Club::delCourse(Course * course) { courseList.removeAt(index); } +bool Club::isReadOnly() +{ + return m_readOnly; +} + bool Club::isEmpty() { bool rc = false; diff --git a/src/data.h b/src/data.h index 4ab4e61..01d01ef 100644 --- a/src/data.h +++ b/src/data.h @@ -19,102 +19,101 @@ enum { TotalOut, TotalIn, Total }; class Hole { - public: - Hole(const QXmlAttributes &attrs); - Hole(const QDomElement node); - Hole(int num, QString &shots); - Hole(int num, QString &par, QString &hcp); - QDomElement toElement(QDomDocument doc); - QString getShots(); - void setShots(QString& shots); - QString getHcp(); - void setHcp(QString& shots); - QString getPar(); - void setPar(QString& shots); - void dump(); - - private: - QString num, shots, putts, hcp, length, par; +public: + Hole(const QXmlAttributes &attrs); + Hole(const QDomElement node); + Hole(int num, QString &shots); + Hole(int num, QString &par, QString &hcp); + QDomElement toElement(QDomDocument doc); + QString getShots(); + void setShots(QString& shots); + QString getHcp(); + void setHcp(QString& shots); + QString getPar(); + void setPar(QString& shots); + void dump(); + +private: + QString num, shots, putts, hcp, length, par; }; class Score { - public: - - Score(const QXmlAttributes &attrs); - Score(QString &iClub, QString &iCourse, QString &iDate); - Score(const QDomElement node); - Score(QVector scores, QString &club, QString &course, QString &date); - - bool operator< (const Score& val) const - { - return date < val.getDate(); - } - - bool operator> (const Score& val) const - { - return date > val.getDate(); - } - - QDomElement toElement(QDomDocument doc); - int update(QVector &scores); - void addHole(Hole *iHole); - QString getScore(int i) const; - QString getTotal(int what) const; - const QString& getClubName() const; - const QString& getCourseName() const; - const QString& getDate() const; - void dump(); - - private: - QList holeList; - QString club, course, date; +public: + Score(const QXmlAttributes &attrs); + Score(QString &iClub, QString &iCourse, QString &iDate); + Score(const QDomElement node); + Score(QVector scores, QString &club, QString &course, QString &date); + + bool operator< (const Score& val) const + { + return date < val.getDate(); + } + + bool operator> (const Score& val) const + { + return date > val.getDate(); + } + + QDomElement toElement(QDomDocument doc); + int update(QVector &scores); + void addHole(Hole *iHole); + QString getScore(int i) const; + QString getTotal(int what) const; + const QString& getClubName() const; + const QString& getCourseName() const; + const QString& getDate() const; + void dump(); + +private: + QList holeList; + QString club, course, date; }; class Club; class Course { - public: - Course(const QXmlAttributes &attrs); - Course(const QDomElement node, Club * parent = 0); - Course(QString &name, QVector &, QVector &); - QDomElement toElement(QDomDocument doc); - int update(QVector &, QVector &, QVector &); - void addHole(Hole *iHole); - QString getPar(int i); - QString getHcp(int i); - QString& getName(); - QString getTotal(int what); - void dump(); - Club * parent(); - void setParent(Club *parent); - - private: - QList holeList; - QString name; - Club *club; +public: + Course(const QXmlAttributes &attrs); + Course(const QDomElement node, Club * parent = 0); + Course(QString &name, QVector &, QVector &); + QDomElement toElement(QDomDocument doc); + int update(QVector &, QVector &, QVector &); + void addHole(Hole *iHole); + QString getPar(int i); + QString getHcp(int i); + QString& getName(); + QString getTotal(int what); + void dump(); + Club * parent(); + void setParent(Club *parent); + +private: + QList holeList; + QString name; + Club *club; }; class Club { - public: - - Club(const QXmlAttributes &attrs); - Club(const QDomElement node); - Club(QString &name); - - QDomElement toElement(QDomDocument doc); - void addCourse(Course *iCourse); - void delCourse(Course *iCourse); - void dump(); - QString& getName(); - Course *getCourse(int pos); - Course *getCourse(const QString &courseName); - bool isEmpty(); - - QList getCourseList() { return courseList; } // HACK: fixme - - private: - QList courseList; - QString name; - +public: + Club(const QXmlAttributes &attrs, bool readOnly = false); + Club(const QDomElement node, bool readOnly = false); + Club(QString &name, bool readOnly = false); + + QDomElement toElement(QDomDocument doc); + void addCourse(Course *iCourse); + void delCourse(Course *iCourse); + void dump(); + QString& getName(); + Course *getCourse(int pos); + Course *getCourse(const QString &courseName); + bool isEmpty(); + bool isReadOnly(); + + QList getCourseList() { return courseList; } // HACK: fixme + +private: + bool m_readOnly; + QList courseList; + QString name; }; #endif diff --git a/src/main-window.cpp b/src/main-window.cpp index deda9ef..1481e23 100644 --- a/src/main-window.cpp +++ b/src/main-window.cpp @@ -28,6 +28,8 @@ QString scoreFileName("score.xml"); QString scoreFile; QString clubFileName("club.xml"); QString clubFile; +QString masterFileName("club-master.xml"); +QString masterFile; QString logFile("/tmp/scorecard.log"); QString titleScores("ScoreCard - Scores"); QString titleCourses("ScoreCard - Courses"); @@ -117,6 +119,7 @@ MainWindow::MainWindow(QMainWindow *parent): QMainWindow(parent) setCentralWidget(centralWidget); loadScoreFile(scoreFile, scoreList); + loadClubFile(masterFile, clubList, true); loadClubFile(clubFile, clubList); // Sort the scores based on dates @@ -152,6 +155,7 @@ void MainWindow::loadSettings(void) #endif scoreFile = dataDir + "/" + scoreFileName; clubFile = dataDir + "/" + clubFileName; + masterFile = dataDir + "/" + masterFileName; QDir dir(dataDir); if (!dir.exists()) @@ -628,11 +632,11 @@ void MainWindow::saveScoreFile(QString &fileName, QList &list) qWarning() << "Unable to save:" << fileName; } -void MainWindow::loadClubFile(QString &fileName, QList &list) +void MainWindow::loadClubFile(QString &fileName, QList &list, bool readOnly) { ClubXmlHandler handler(list); - if (handler.parse(fileName)) + if (handler.parse(fileName, readOnly)) qDebug() << "File loaded:" << fileName << " entries:" << list.size(); } diff --git a/src/main-window.h b/src/main-window.h index c552f2d..aac1845 100644 --- a/src/main-window.h +++ b/src/main-window.h @@ -33,7 +33,7 @@ public: void createListView(QList &, QList &); void updateTitleBar(QString & msg); void loadScoreFile(QString &fileName, QList &scoreList); - void loadClubFile(QString &fileName, QList &clubList); + void loadClubFile(QString &fileName, QList &clubList, bool readOnly = false); void saveScoreFile(QString &fileName, QList &scoreList); void saveClubFile(QString &fileName, QList &clubList); diff --git a/src/xml-dom-parser.cpp b/src/xml-dom-parser.cpp index bc8b7e9..a8ecde5 100644 --- a/src/xml-dom-parser.cpp +++ b/src/xml-dom-parser.cpp @@ -79,7 +79,7 @@ ClubXmlHandler::ClubXmlHandler(QList &list) : list(list) { } -int ClubXmlHandler::parse(QString &fileName) +int ClubXmlHandler::parse(QString &fileName, bool readOnly) { QFile file(fileName); @@ -102,7 +102,7 @@ int ClubXmlHandler::parse(QString &fileName) QDomElement clubElement = root.firstChildElement("club"); while (!clubElement.isNull()) { - Club *club = new Club(clubElement); + Club *club = new Club(clubElement, readOnly); QDomElement courseElement = clubElement.firstChildElement("course"); while (!courseElement.isNull()) { @@ -134,7 +134,8 @@ int ClubXmlHandler::save(QString &fileName) for (int i = 0; i < list.size(); i++) { Club *club = list.at(i); - root.appendChild(club->toElement(doc)); + if (!club->isReadOnly()) + root.appendChild(club->toElement(doc)); } if (!file.open(QFile::WriteOnly)) diff --git a/src/xml-dom-parser.h b/src/xml-dom-parser.h index f02299e..2230066 100644 --- a/src/xml-dom-parser.h +++ b/src/xml-dom-parser.h @@ -14,28 +14,28 @@ class ScoreXmlHandler { - public: - ScoreXmlHandler(QList &list); - int parse(QString &fileName); - int save(QString &fileName); +public: + ScoreXmlHandler(QList &list); + int parse(QString &fileName); + int save(QString &fileName); - private: - QDomDocument doc; - QDomElement root; - QList &list; +private: + QDomDocument doc; + QDomElement root; + QList &list; }; class ClubXmlHandler { - public: - ClubXmlHandler(QList &list); - int parse(QString &fileName); - int save(QString &fileName); +public: + ClubXmlHandler(QList &list); + int parse(QString &fileName, bool readOnly = false); + int save(QString &fileName); - private: - QDomDocument doc; - QDomElement root; - QList &list; +private: + QDomDocument doc; + QDomElement root; + QList &list; }; #endif