Corner case handling. Copyright update
[scorecard] / src / main-window.cpp
index 67a47e4..98351e2 100644 (file)
@@ -58,30 +58,33 @@ void MainWindow::loadSettings(void)
 {
   bool external = false;
 
-#ifndef Q_WS_HILDON
-  topDir = ".";
-#endif
-
   QDir mmc(mmcDir);
   if (mmc.exists())
     external = true;
 
+  // TODO: make via user option, automatic will never work
+  external = false;
+
+#ifndef Q_WS_HILDON
+  dataDir = "./" + dataDirName;
+#else
   if (external) {
     dataDir = mmcDir + "/" + appName + "/" + dataDirName;
   }
   else {
     dataDir = topDir + "/" + appName + "/" + dataDirName;
   }
+#endif
   scoreFile = dataDir + "/" + scoreFileName;
   clubFile = dataDir + "/" + clubFileName;
 
   QDir dir(dataDir);
   if (!dir.exists())
     if (!dir.mkpath(dataDir)) {
-      qDebug() << "Unable to create: " + dataDir;
+      qWarning() << "Unable to create: " + dataDir;
       return;
     }
-  qDebug() << "Data is at: " + dataDir;
+  qDebug() << "Data is at:" + dataDir;
 }
 
 void MainWindow::createLayout(QWidget *parent)
@@ -100,7 +103,7 @@ void MainWindow::createLayout(QWidget *parent)
   QHBoxLayout *mainLayout = new QHBoxLayout(parent);
   mainLayout->addLayout(tableLayout);
   mainLayout->addLayout(buttonLayout);
-  setLayout(mainLayout);
+  parent->setLayout(mainLayout);
 }
 
 // Setup 'score' tab view
@@ -132,6 +135,7 @@ void MainWindow::createTableView(QList<Score *> &scoreList, QList <Club *> &club
   // Fill out all the space with the tables
   table->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
   table->verticalHeader()->setResizeMode(QHeaderView::Stretch);
+  table->verticalHeader()->setAutoFillBackground(true);
   table->horizontalHeader()->hide();
 }
 
@@ -228,7 +232,7 @@ void MainWindow::createActions()
 
 void MainWindow::createMenus()
 {
-  menu = menuBar()->addMenu(tr("fremantle"));
+  menu = menuBar()->addMenu("");
 #if 0
   menu->addAction(viewScoreAct);
   menu->addAction(viewCourseAct);
@@ -341,6 +345,11 @@ void MainWindow::editCourse()
 {
   Course *course = scoreTableModel->getCourse();
 
+  if (!course) {
+    qWarning() << "No course on edit";
+    return;
+  }
+
   CourseDialog *courseDialog = new CourseDialog(this);
   courseDialog->init(course);
 
@@ -380,12 +389,12 @@ void MainWindow::newScore()
 
     Club *club = findClub(clubName);
     if (!club) {
-      qDebug() << "Error: no such club: " << clubName;
+      qWarning() << "Error: no such club:" << clubName;
       return;
     }
     Course *course = club->getCourse(courseName);
     if (!course) {
-      qDebug() << "Error: no such course: " << courseName;
+      qWarning() << "Error: no such course:" << courseName;
       return;
     }
     scoreDialog->init(course);
@@ -447,7 +456,7 @@ void MainWindow::loadScoreFile(QString &fileName, QList<Score *> &list)
   ScoreXmlHandler handler(list);
 
   if (handler.parse(fileName))
-    qDebug() << "File loaded: " << fileName << " entries: " << list.size();
+    qDebug() << "File loaded:" << fileName << " entries:" << list.size();
 }
 
 void MainWindow::saveScoreFile(QString &fileName, QList<Score *> &list)
@@ -456,9 +465,9 @@ void MainWindow::saveScoreFile(QString &fileName, QList<Score *> &list)
 
   if (handler.save(fileName))
     // TODO: banner
-    qDebug() << "File saved: " << fileName << " entries: " << list.size();
+    qDebug() << "File saved:" << fileName << " entries:" << list.size();
   else
-    qDebug() << "Unable to save: " << fileName;
+    qWarning() << "Unable to save:" << fileName;
 }
 
 void MainWindow::loadClubFile(QString &fileName, QList<Club *> &list)
@@ -466,7 +475,7 @@ void MainWindow::loadClubFile(QString &fileName, QList<Club *> &list)
   ClubXmlHandler handler(list);
 
   if (handler.parse(fileName))
-    qDebug() << "File loaded: " << fileName << " entries: " << list.size();
+    qDebug() << "File loaded:" << fileName << " entries:" << list.size();
 }
 
 void MainWindow::saveClubFile(QString &fileName, QList<Club *> &list)
@@ -475,8 +484,8 @@ void MainWindow::saveClubFile(QString &fileName, QList<Club *> &list)
 
   if (handler.save(fileName))
     // TODO: banner
-    qDebug() << "File saved: " << fileName << " entries: " << list.size();
+    qDebug() << "File saved:" << fileName << " entries:" << list.size();
   else
-    qDebug() << "Unable to save: " << fileName;
+    qWarning() << "Unable to save:" << fileName;
 
 }