Behave correctly if score contains unknown course
[scorecard] / src / main-window.cpp
index c3c3f01..ad85c04 100644 (file)
@@ -141,37 +141,52 @@ void MainWindow::flushReadOnlyItems()
     }
 }
 
+void MainWindow::markHomeClub()
+{
+    TRACE;
+    QListIterator<Club *> i(clubList);
+    Club *c;
+
+    while (i.hasNext()) {
+        c = i.next();
+        if (c->getName() == conf.homeClub)
+            c->setHomeClub(true);
+        else
+            c->setHomeClub(false);
+    }
+}
 
 MainWindow::MainWindow(QMainWindow *parent): QMainWindow(parent)
 {
-  resize(800, 480);
+    resize(800, 480);
 
 #ifdef Q_WS_MAEMO_5
-  setAttribute(Qt::WA_Maemo5StackedWindow);
+    setAttribute(Qt::WA_Maemo5StackedWindow);
 #endif
 
-  loadSettings();
+    loadSettings();
 
-  centralWidget = new QWidget(this);
+    centralWidget = new QWidget(this);
 
-  setCentralWidget(centralWidget);
+    setCentralWidget(centralWidget);
 
-  loadScoreFile(scoreFile, scoreList);
-  if (conf.defaultCourses == "Yes")
-      loadClubFile(masterFile, clubList, true);
-  loadClubFile(clubFile, clubList);
+    loadScoreFile(scoreFile, scoreList);
+    if (conf.defaultCourses == "Yes")
+        loadClubFile(masterFile, clubList, true);
+    loadClubFile(clubFile, clubList);
+    markHomeClub();
 
-  // Sort the scores based on dates
-  qSort(scoreList.begin(), scoreList.end(), dateMoreThan); 
-  createActions();
-  createMenus();
+    // Sort the scores based on dates
+    qSort(scoreList.begin(), scoreList.end(), dateMoreThan); 
+    createActions();
+    createMenus();
 
-  createListView(scoreList, clubList);
+    createListView(scoreList, clubList);
 
-  createLayoutList(centralWidget);
+    createLayoutList(centralWidget);
 
-  scoreWindow = new ScoreWindow(this);
-  courseWindow = new CourseWindow(this);
+    scoreWindow = new ScoreWindow(this);
+    courseWindow = new CourseWindow(this);
 }
 
 void MainWindow::loadSettings(void)
@@ -371,6 +386,7 @@ void MainWindow::clickedList(const QModelIndex &index)
 void MainWindow::viewScore(Score * score, Course * course)
 {
     TRACE;
+    qDebug() << score << course;
     scoreWindow->setup(score, course);
     scoreWindow->show();
 }
@@ -660,8 +676,6 @@ void MainWindow::viewSettings()
         QString newValue = conf.defaultCourses.toString();
         saveSettings();
 
-        qDebug() << "Settings:" << oldValue << "->" << newValue;
-
         // Reload club list, or drop r/o courses from list
         if (oldValue == "Yes" && newValue == "No") {
             flushReadOnlyItems();
@@ -673,6 +687,7 @@ void MainWindow::viewSettings()
             courseListModel->update(clubList);
             list->update();
         }
+        markHomeClub();
     }
 }