[Tux4kids-commits] r1451 - tux4kids-admin/trunk/tux4kids-admin/src
Michał Świtakowski
swistakers-guest at alioth.debian.org
Sun Aug 16 23:25:04 UTC 2009
Author: swistakers-guest
Date: 2009-08-16 23:25:04 +0000 (Sun, 16 Aug 2009)
New Revision: 1451
Modified:
tux4kids-admin/trunk/tux4kids-admin/src/main.cpp
tux4kids-admin/trunk/tux4kids-admin/src/mainController.cpp
tux4kids-admin/trunk/tux4kids-admin/src/mainController.h
Log:
basic parsing of command line arguments
Modified: tux4kids-admin/trunk/tux4kids-admin/src/main.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/main.cpp 2009-08-16 20:09:33 UTC (rev 1450)
+++ tux4kids-admin/trunk/tux4kids-admin/src/main.cpp 2009-08-16 23:25:04 UTC (rev 1451)
@@ -16,7 +16,11 @@
app.installTranslator(&translator);
MainController controller;
- MainWindow mainWindow(&controller);
- mainWindow.show();
- return app.exec();
+ if (controller.status() == MainController::NoError) {
+ MainWindow mainWindow(&controller);
+ mainWindow.show();
+ return app.exec();
+ } else {
+ return 1;
+ }
}
Modified: tux4kids-admin/trunk/tux4kids-admin/src/mainController.cpp
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/mainController.cpp 2009-08-16 20:09:33 UTC (rev 1450)
+++ tux4kids-admin/trunk/tux4kids-admin/src/mainController.cpp 2009-08-16 23:25:04 UTC (rev 1451)
@@ -1,14 +1,57 @@
#include <QDebug>
#include <QApplication>
#include <QDir>
+#include <QTextStream>
#include "mainController.h"
#include "schoolData.h"
#include "profileDirFactory.h"
+#include <getopt.h>
MainController::MainController(QObject *parent)
- : QObject(parent)
+ : QObject(parent),
+ m_status(NoError)
{
+ QString schoolDataPath;
+
+ int c;
+ while (1) {
+ static struct option long_options[] =
+ {
+ {"school_data_path", required_argument, 0, 'a'},
+ {0, 0, 0, 0}
+ };
+
+ int option_index = 0;
+ c = getopt_long(qApp->argc(), qApp->argv(), "a:", long_options, &option_index);
+ if (c == -1) {
+ break;
+ }
+
+ switch (c)
+ {
+ case 'a':
+ if (optarg) {
+ schoolDataPath = QString(optarg);
+ } else {
+ m_status = InitializtionError;
+ }
+ break;
+
+ case '?':
+ /* getopt_long already printed an error message.*/
+ m_status = InitializtionError;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if (m_status != NoError) {
+ return;
+ }
+
m_pluginManager.setPluginsPath(qApp->applicationDirPath() + "/plugins");
m_pluginManager.loadPlugins();
@@ -16,7 +59,7 @@
qDebug() << tr("Failed to load plugins");
}
- m_schoolData = new SchoolData(QDir::homePath() + "/school_data");
+ m_schoolData = new SchoolData(schoolDataPath);
m_studentTableModel.setSchoolData(m_schoolData);
m_classTableModel.setSchoolDatabase(m_schoolData->schoolDatabase());
m_teacherTableModel.setSchoolDatabase(m_schoolData->schoolDatabase());
@@ -34,6 +77,11 @@
delete m_schoolData;
}
+MainController::Status MainController::status() const
+{
+ return m_status;
+}
+
PluginManager *MainController::pluginManager()
{
return &m_pluginManager;
Modified: tux4kids-admin/trunk/tux4kids-admin/src/mainController.h
===================================================================
--- tux4kids-admin/trunk/tux4kids-admin/src/mainController.h 2009-08-16 20:09:33 UTC (rev 1450)
+++ tux4kids-admin/trunk/tux4kids-admin/src/mainController.h 2009-08-16 23:25:04 UTC (rev 1451)
@@ -19,11 +19,17 @@
MainController(QObject *parent = 0);
~MainController();
+ enum Status {
+ NoError,
+ InitializtionError
+ };
+
PluginManager *pluginManager();
SchoolData *schoolData();
StudentTableModel *studentTableModel();
ClassTableModel *classTableModel();
TeacherTableModel *teacherTableModel();
+ Status status() const;
private:
@@ -32,6 +38,7 @@
ClassTableModel m_classTableModel;
TeacherTableModel m_teacherTableModel;
QPointer<SchoolData> m_schoolData;
+ mutable Status m_status;
};
More information about the Tux4kids-commits
mailing list